22 #include "kateviewspacecontainer.h"
23 #include "kateviewspacecontainer.moc"
25 #include "katetabwidget.h"
26 #include "katemainwindow.h"
27 #include "katedocmanager.h"
28 #include "kateviewmanager.h"
29 #include "kateviewspace.h"
31 #include <dcopclient.h>
32 #include <tdeaction.h>
33 #include <tdecmdlineargs.h>
35 #include <tdediroperator.h>
36 #include <kdockwidget.h>
37 #include <kencodingfiledialog.h>
38 #include <kiconloader.h>
39 #include <tdeglobal.h>
40 #include <tdelocale.h>
41 #include <tdetoolbar.h>
42 #include <tdemessagebox.h>
43 #include <ksimpleconfig.h>
44 #include <kstdaction.h>
45 #include <kstandarddirs.h>
46 #include <tdeglobalsettings.h>
47 #include <kstringhandler.h>
49 #include <tdetexteditor/encodinginterface.h>
52 #include <tqobjectlist.h>
53 #include <tqstringlist.h>
56 #include <tqfileinfo.h>
60 KateViewSpaceContainer::KateViewSpaceContainer (TQWidget *parent, KateViewManager *viewManager)
62 , m_viewManager(viewManager)
63 , m_blockViewCreationAndActivation (false)
64 , m_activeViewRunning (false)
65 , m_pendingViewCreation(false)
68 m_viewList.setAutoDelete(
true);
69 m_viewSpaceList.setAutoDelete(
true);
71 KateViewSpace* vs =
new KateViewSpace(
this,
this );
72 connect(
this, TQ_SIGNAL(statusChanged(Kate::View *,
int,
int,
int,
bool,
int,
const TQString&)), vs, TQ_SLOT(slotStatusChanged(Kate::View *,
int,
int,
int,
bool,
int,
const TQString&)));
73 vs->setActive(
true );
74 m_viewSpaceList.append(vs);
75 connect(
this, TQ_SIGNAL(viewChanged()),
this, TQ_SLOT(slotViewChanged()) );
76 connect(KateDocManager::self(), TQ_SIGNAL(initialDocumentReplaced()),
this, TQ_SIGNAL(viewChanged()));
78 connect(KateDocManager::self(),TQ_SIGNAL(documentCreated(Kate::Document *)),
this,TQ_SLOT(documentCreated(Kate::Document *)));
79 connect(KateDocManager::self(),TQ_SIGNAL(documentDeleted(uint)),
this,TQ_SLOT(documentDeleted(uint)));
82 KateViewSpaceContainer::~KateViewSpaceContainer ()
84 m_viewList.setAutoDelete(
false);
85 m_viewSpaceList.setAutoDelete(
false);
88 void KateViewSpaceContainer::documentCreated (Kate::Document *doc)
90 if (m_blockViewCreationAndActivation)
return;
93 activateView (doc->documentNumber());
96 void KateViewSpaceContainer::documentDeleted (uint)
98 if (m_blockViewCreationAndActivation)
return;
102 if (!activeView() && (KateDocManager::self()->documents() > 0))
103 createView (KateDocManager::self()->document(KateDocManager::self()->documents()-1));
106 bool KateViewSpaceContainer::createView ( Kate::Document *doc )
108 if (m_blockViewCreationAndActivation)
return false;
112 doc = KateDocManager::self()->createDoc ();
115 Kate::View *view = (Kate::View *) doc->createView (
this, 0L);
117 m_viewList.append (view);
120 view->actionCollection()->remove (view->actionCollection()->action(
"set_confdlg" ));
123 view->installPopup ((TQPopupMenu*)(mainWindow()->factory()->container(
"tdetexteditor_popup", mainWindow())) );
125 connect(view->getDoc(),TQ_SIGNAL(nameChanged(Kate::Document *)),
this,TQ_SLOT(statusMsg()));
126 connect(view,TQ_SIGNAL(cursorPositionChanged()),
this,TQ_SLOT(statusMsg()));
127 connect(view,TQ_SIGNAL(newStatus()),
this,TQ_SLOT(statusMsg()));
128 connect(view->getDoc(), TQ_SIGNAL(undoChanged()),
this, TQ_SLOT(statusMsg()));
129 connect(view,TQ_SIGNAL(dropEventPass(TQDropEvent *)), mainWindow(),TQ_SLOT(slotDropEvent(TQDropEvent *)));
130 connect(view,TQ_SIGNAL(gotFocus(Kate::View *)),
this,TQ_SLOT(activateSpace(Kate::View *)));
132 activeViewSpace()->addView( view );
133 activateView( view );
134 connect( doc, TQ_SIGNAL(modifiedOnDisc(Kate::Document *,
bool,
unsigned char)),
135 activeViewSpace(), TQ_SLOT(modifiedOnDisc(Kate::Document *,
bool,
unsigned char)) );
140 bool KateViewSpaceContainer::deleteView (Kate::View *view,
bool delViewSpace)
142 if (!view)
return true;
144 KateViewSpace *viewspace = (KateViewSpace *)view->parentWidget()->parentWidget();
146 viewspace->removeView (view);
148 mainWindow()->guiFactory ()->removeClient (view);
151 m_viewList.remove (view);
154 if ( viewspace->viewCount() == 0 )
155 removeViewSpace( viewspace );
160 KateViewSpace* KateViewSpaceContainer::activeViewSpace ()
162 TQPtrListIterator<KateViewSpace> it(m_viewSpaceList);
164 for (; it.current(); ++it)
166 if ( it.current()->isActiveSpace() )
170 if (m_viewSpaceList.count() > 0)
172 m_viewSpaceList.first()->setActive(
true );
173 return m_viewSpaceList.first();
179 Kate::View* KateViewSpaceContainer::activeView ()
181 if (m_activeViewRunning)
184 m_activeViewRunning =
true;
186 for (TQPtrListIterator<Kate::View> it(m_viewList); it.current(); ++it)
188 if ( it.current()->isActive() )
190 m_activeViewRunning =
false;
198 if ( (vs = activeViewSpace()) )
200 if ( vs->currentView() )
202 activateView (vs->currentView());
204 m_activeViewRunning =
false;
205 return vs->currentView();
210 if (m_viewList.count() > 0)
212 activateView (m_viewList.first());
214 m_activeViewRunning =
false;
215 return m_viewList.first();
218 m_activeViewRunning =
false;
224 void KateViewSpaceContainer::setActiveSpace ( KateViewSpace* vs )
226 if (activeViewSpace())
227 activeViewSpace()->setActive(
false );
229 vs->setActive(
true, viewSpaceCount() > 1 );
232 void KateViewSpaceContainer::setActiveView ( Kate::View* view )
235 activeView()->setActive(
false );
237 view->setActive(
true );
240 void KateViewSpaceContainer::activateSpace (Kate::View* v)
244 KateViewSpace* vs = (KateViewSpace*)v->parentWidget()->parentWidget();
246 if (!vs->isActiveSpace()) {
252 void KateViewSpaceContainer::reactivateActiveView() {
253 Kate::View *view=activeView();
255 view->setActive(
false);
257 }
else if (m_pendingViewCreation) {
258 m_pendingViewCreation=
false;
259 disconnect(m_pendingDocument,TQ_SIGNAL(nameChanged(Kate::Document *)),
this,TQ_SLOT(slotPendingDocumentNameChanged()));
260 createView(m_pendingDocument);
264 void KateViewSpaceContainer::activateView ( Kate::View *view )
268 if (!view->isActive())
270 if ( !activeViewSpace()->showView (view) )
273 createView ( view->getDoc() );
277 setActiveView (view);
278 m_viewList.findRef (view);
280 mainWindow()->toolBar ()->setUpdatesEnabled (
false);
282 if (m_viewManager->guiMergedView)
283 mainWindow()->guiFactory()->removeClient (m_viewManager->guiMergedView );
285 m_viewManager->guiMergedView = view;
287 if (!m_blockViewCreationAndActivation)
288 mainWindow()->guiFactory ()->addClient( view );
290 mainWindow()->toolBar ()->setUpdatesEnabled (
true);
297 KateDocManager::self()->setActiveDocument(view->getDoc());
300 void KateViewSpaceContainer::activateView( uint documentNumber )
302 if ( activeViewSpace()->showView(documentNumber) ) {
303 activateView( activeViewSpace()->currentView() );
307 TQPtrListIterator<Kate::View> it(m_viewList);
308 for ( ;it.current(); ++it)
310 if ( it.current()->getDoc()->documentNumber() == documentNumber )
312 createView( it.current()->getDoc() );
317 Kate::Document *d = (Kate::Document *)KateDocManager::self()->documentWithID(documentNumber);
322 uint KateViewSpaceContainer::viewCount ()
324 return m_viewList.count();
327 uint KateViewSpaceContainer::viewSpaceCount ()
329 return m_viewSpaceList.count();
332 void KateViewSpaceContainer::slotViewChanged()
334 if ( activeView() && !activeView()->hasFocus())
335 activeView()->setFocus();
338 void KateViewSpaceContainer::activateNextView()
340 uint i = m_viewSpaceList.find (activeViewSpace())+1;
342 if (i >= m_viewSpaceList.count())
345 setActiveSpace (m_viewSpaceList.at(i));
346 activateView(m_viewSpaceList.at(i)->currentView());
349 void KateViewSpaceContainer::activatePrevView()
351 int i = m_viewSpaceList.find (activeViewSpace())-1;
354 i=m_viewSpaceList.count()-1;
356 setActiveSpace (m_viewSpaceList.at(i));
357 activateView(m_viewSpaceList.at(i)->currentView());
360 void KateViewSpaceContainer::closeViews(uint documentNumber)
362 TQPtrList<Kate::View> closeList;
364 for (uint z=0 ; z < m_viewList.count(); z++)
366 Kate::View* current = m_viewList.at(z);
367 if ( current->getDoc()->documentNumber() == documentNumber )
369 closeList.append (current);
373 while ( !closeList.isEmpty() )
375 Kate::View *view = closeList.first();
376 deleteView (view,
true);
377 closeList.removeFirst();
380 if (m_blockViewCreationAndActivation)
return;
381 TQTimer::singleShot(0,
this,TQ_SIGNAL(viewChanged()));
385 void KateViewSpaceContainer::slotPendingDocumentNameChanged() {
387 if (m_pendingDocument->url().isEmpty() || (!showFullPath))
389 c = m_pendingDocument->docName();
393 c = m_pendingDocument->url().prettyURL();
395 setCaption(KStringHandler::lsqueeze(c,32));
398 void KateViewSpaceContainer::statusMsg ()
400 if (!activeView())
return;
402 Kate::View* v = activeView();
404 bool readOnly = !v->getDoc()->isReadWrite();
405 uint config = v->getDoc()->configFlags();
412 if (config & Kate::Document::cfOvr)
422 int mod = (int)v->getDoc()->isModified();
423 bool block=v->getDoc()->blockSelectionMode();
426 if (v->getDoc()->url().isEmpty() || (!showFullPath))
428 c = v->getDoc()->docName();
432 c = v->getDoc()->url().pathOrURL();
435 m_viewManager->mainWindow()->tabWidget()->changeTab (
this, KStringHandler::lsqueeze(c,32));
436 emit statusChanged (v, v->cursorLine(), v->cursorColumn(), ovr,block, mod, KStringHandler::lsqueeze(c,64));
440 void KateViewSpaceContainer::splitViewSpace( KateViewSpace* vs,
446 if (!activeView())
return;
447 if (!vs) vs = activeViewSpace();
449 bool isFirstTime = vs->parentWidget() ==
this;
451 TQValueList<int> psizes;
453 if ( TQSplitter *ps =
static_cast<TQSplitter*
>(vs->parentWidget()->tqt_cast(
"TQSplitter")) )
454 psizes = ps->sizes();
456 TQt::Orientation o = isHoriz ? TQt::Vertical : TQt::Horizontal;
458 s->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
467 vs->reparent( s, 0, TQPoint(), true );
468 KateViewSpace* vsNew =
new KateViewSpace(
this, s );
471 s->moveToFirst( vsNew );
474 if (TQSplitter *ps =
static_cast<TQSplitter*
>(s->parentWidget()->tqt_cast(
"TQSplitter")) )
475 ps->setSizes( psizes );
479 TQValueList<int> sizes;
481 sizes << space << space;
482 s->setSizes( sizes );
484 connect(
this, TQ_SIGNAL(statusChanged(Kate::View *,
int,
int,
int,
bool,
int,
const TQString &)), vsNew, TQ_SLOT(slotStatusChanged(Kate::View *,
int,
int,
int,
bool,
int,
const TQString &)));
485 m_viewSpaceList.append( vsNew );
486 activeViewSpace()->setActive(
false );
487 vsNew->setActive(
true,
true );
490 createView (activeView()->getDoc());
492 if (
this == m_viewManager->activeContainer())
493 m_viewManager->updateViewSpaceActions ();
498 void KateViewSpaceContainer::removeViewSpace (KateViewSpace *viewspace)
501 if (!viewspace)
return;
504 if (m_viewSpaceList.count() < 2)
return;
510 bool pIsFirst =
false;
514 TQValueList<int> ppsizes;
515 if (m_viewSpaceList.count() > 2 && p->parentWidget() !=
this)
518 ppsizes = pp->sizes();
524 if (m_viewSpaceList.find(viewspace) == 0)
525 next = m_viewSpaceList.next();
527 next = m_viewSpaceList.prev();
530 int vsvc = viewspace->viewCount();
533 if (viewspace->currentView())
535 Kate::View* v = viewspace->currentView();
539 viewspace->removeView(v);
540 next->addView( v,
false );
544 deleteView( v,
false );
547 vsvc = viewspace->viewCount();
550 m_viewSpaceList.remove( viewspace );
553 while (!p->childrenListObject().isEmpty())
555 TQWidget* other = ((TQWidget *)(( TQPtrList<TQObject>)p->childrenListObject()).first());
557 other->reparent( p->parentWidget(), 0, TQPoint(), true );
561 if ( other->isA(
"KateViewSpace") ) {
562 setActiveSpace( (KateViewSpace*)other );
565 TQObjectList* l = other->queryList(
"KateViewSpace" );
566 if ( l->first() != 0 ) {
567 setActiveSpace( (KateViewSpace*)l->first() );
575 if (!ppsizes.isEmpty())
576 pp->setSizes( ppsizes );
579 Kate::View* v = activeViewSpace()->currentView();
583 if (
this == m_viewManager->activeContainer())
584 m_viewManager->updateViewSpaceActions ();
589 void KateViewSpaceContainer::slotCloseCurrentViewSpace()
591 removeViewSpace(activeViewSpace());
594 void KateViewSpaceContainer::setShowFullPath(
bool enable )
596 showFullPath = enable;
605 void KateViewSpaceContainer::saveViewConfiguration(TDEConfig *config,
const TQString& group)
607 bool weHaveSplittersAlive (viewSpaceCount() > 1);
609 config->setGroup (group);
610 config->writeEntry (
"Splitters", weHaveSplittersAlive);
613 if (!weHaveSplittersAlive)
615 config->writeEntry(
"Active Viewspace", 0);
616 m_viewSpaceList.first()->saveConfig ( config, 0,group );
623 TQObjectList *l = queryList(
"KateMDI::Splitter", 0,
false,
false);
624 TQObjectListIt it( *l );
627 saveSplitterConfig( s, 0, config , group);
632 void KateViewSpaceContainer::restoreViewConfiguration (TDEConfig *config,
const TQString& group)
634 config->setGroup(group);
638 if (!config->readBoolEntry (
"Splitters"))
641 m_viewSpaceList.first ()->restoreConfig (
this, config, TQString(group+
"-ViewSpace 0"));
646 for (uint i=0; i < m_viewList.count(); i++)
647 mainWindow()->guiFactory ()->removeClient (m_viewList.at(i));
652 m_viewSpaceList.clear();
655 restoreSplitter( config, TQString(group+
"-Splitter 0"),
this,group );
659 config->setGroup (group);
668 void KateViewSpaceContainer::saveSplitterConfig(
KateMDI::Splitter* s,
int idx, TDEConfig* config,
const TQString& viewConfGrp )
670 TQString grp = TQString(viewConfGrp+
"-Splitter %1").arg(idx);
671 config->setGroup(grp);
674 config->writeEntry(
"Sizes", s->sizes() );
675 config->writeEntry(
"Orientation", s->orientation() );
677 TQStringList childList;
679 const TQObjectList l = s->childrenListObject();
680 TQObjectListIt it( l );
682 for (; it.current(); ++it) {
686 if ( obj->isA(
"KateViewSpace") ) {
687 n = TQString(viewConfGrp+
"-ViewSpace %1").arg( m_viewSpaceList.find((KateViewSpace*)obj) );
688 ((KateViewSpace*)obj)->saveConfig ( config, m_viewSpaceList.find((KateViewSpace*)obj), viewConfGrp);
690 if ( ((KateViewSpace*)obj)->isActiveSpace() ) {
691 config->setGroup(viewConfGrp);
692 config->writeEntry(
"Active Viewspace", m_viewSpaceList.find((KateViewSpace*)obj) );
696 else if ( obj->isA(
"KateMDI::Splitter") ) {
699 n = TQString(viewConfGrp+
"-Splitter %1").arg( idx );
703 if ( childList.count() > 0 && ! s->
isLastChild( (TQWidget*)obj ) )
704 childList.prepend( n );
706 childList.append( n );
711 config->setGroup(grp);
712 config->writeEntry(
"Children", childList);
715 void KateViewSpaceContainer::restoreSplitter( TDEConfig* config,
const TQString &group, TQWidget* parent,
const TQString& viewConfGrp)
717 config->setGroup( group );
721 TQStringList children = config->readListEntry(
"Children" );
722 for (TQStringList::Iterator it=children.begin(); it!=children.end(); ++it)
725 if ( (*it).startsWith(viewConfGrp+
"-ViewSpace") )
727 KateViewSpace* vs =
new KateViewSpace(
this, s );
729 connect(
this, TQ_SIGNAL(statusChanged(Kate::View *,
int,
int,
int,
bool,
int,
const TQString &)), vs, TQ_SLOT(slotStatusChanged(Kate::View *,
int,
int,
int,
bool,
int,
const TQString &)));
731 if (m_viewSpaceList.isEmpty())
732 vs->setActive (
true);
734 m_viewSpaceList.append( vs );
737 setActiveSpace( vs );
739 vs->restoreConfig (
this, config, *it);
744 restoreSplitter( config, TQString(*it), s, viewConfGrp );
749 config->setGroup( group );
750 s->setSizes( config->readIntListEntry(
"Sizes") );
754 KateMainWindow *KateViewSpaceContainer::mainWindow() {
755 return m_viewManager->mainWindow();
This class is needed because TQSplitter cant return an index for a widget.
bool isLastChild(TQWidget *w) const
Since there is supposed to be only 2 childs of a katesplitter, any child other than the last is the f...