22 #include "kateviewmanager.h"
23 #include "kateviewmanager.moc"
25 #include "katemainwindow.h"
26 #include "katedocmanager.h"
27 #include "kateviewspacecontainer.h"
28 #include "katetabwidget.h"
30 #include <dcopclient.h>
31 #include <tdeaction.h>
32 #include <tdecmdlineargs.h>
34 #include <tdediroperator.h>
35 #include <kdockwidget.h>
36 #include <kencodingfiledialog.h>
37 #include <kiconloader.h>
38 #include <tdeglobal.h>
39 #include <tdelocale.h>
40 #include <tdetoolbar.h>
41 #include <tdemessagebox.h>
42 #include <ksimpleconfig.h>
43 #include <kstdaction.h>
44 #include <kstandarddirs.h>
45 #include <tdeglobalsettings.h>
46 #include <tdestdaccel.h>
48 #include <tdetexteditor/encodinginterface.h>
50 #include <tqobjectlist.h>
51 #include <tqstringlist.h>
52 #include <tqfileinfo.h>
53 #include <tqtoolbutton.h>
54 #include <tqtooltip.h>
57 KateViewManager::KateViewManager (KateMainWindow *parent)
59 showFullPath(false), m_mainWindow(parent)
65 m_mainWindow->tabWidget()->setTabReorderingEnabled(
true );
74 connect(m_mainWindow->tabWidget(),TQ_SIGNAL(currentChanged(TQWidget*)),
this,TQ_SLOT(tabChanged(TQWidget*)));
76 tabChanged(m_mainWindow->tabWidget()->currentPage());
79 m_viewSpaceContainerList.setAutoDelete(
true);
85 KateViewManager::~KateViewManager ()
87 m_viewSpaceContainerList.setAutoDelete(
false);
90 void KateViewManager::setupActions ()
97 a=
new TDEAction ( i18n(
"New Tab"),
"tab_new", 0,
this, TQ_SLOT(slotNewTab()),
98 m_mainWindow->actionCollection(),
"view_new_tab" );
100 m_closeTab =
new TDEAction ( i18n(
"Close Current Tab"),
"tab_remove",0,
this,TQ_SLOT(slotCloseTab()),
101 m_mainWindow->actionCollection(),
"view_close_tab");
104 =
new TDEAction( i18n(
"Activate Next Tab" ),
105 TQApplication::reverseLayout() ? TDEStdAccel::tabPrev() : TDEStdAccel::tabNext(),
106 this, TQ_SLOT( activateNextTab() ), m_mainWindow->actionCollection(),
"view_next_tab" );
109 =
new TDEAction( i18n(
"Activate Previous Tab" ),
110 TQApplication::reverseLayout() ? TDEStdAccel::tabNext() : TDEStdAccel::tabPrev(),
111 this, TQ_SLOT( activatePrevTab() ), m_mainWindow->actionCollection(),
"view_prev_tab" );
116 a=
new TDEAction ( i18n(
"Split Ve&rtical"),
"view_right", CTRL+SHIFT+Key_L,
this, TQ_SLOT(
117 slotSplitViewSpaceVert() ), m_mainWindow->actionCollection(),
"view_split_vert");
119 a->setWhatsThis(i18n(
"Split the currently active view vertically into two views."));
121 a=
new TDEAction ( i18n(
"Split &Horizontal"),
"view_bottom", CTRL+SHIFT+Key_T,
this, TQ_SLOT(
122 slotSplitViewSpaceHoriz() ), m_mainWindow->actionCollection(),
"view_split_horiz");
124 a->setWhatsThis(i18n(
"Split the currently active view horizontally into two views."));
126 m_closeView =
new TDEAction ( i18n(
"Cl&ose Current View"),
"view_remove", CTRL+SHIFT+Key_R,
this,
127 TQ_SLOT( slotCloseCurrentViewSpace() ), m_mainWindow->actionCollection(),
128 "view_close_current_space" );
130 m_closeView->setWhatsThis(i18n(
"Close the currently active splitted view"));
132 goNext=
new TDEAction(i18n(
"Next View"),Key_F8,
this,
133 TQ_SLOT(activateNextView()),m_mainWindow->actionCollection(),
"go_next");
135 goNext->setWhatsThis(i18n(
"Make the next split view the active one."));
137 goPrev=
new TDEAction(i18n(
"Previous View"),SHIFT+Key_F8,
this, TQ_SLOT(activatePrevView()),m_mainWindow->actionCollection(),
"go_prev");
139 goPrev->setWhatsThis(i18n(
"Make the previous split view the active one."));
144 TQToolButton *b =
new TQToolButton( m_mainWindow->tabWidget() );
145 connect( b, TQ_SIGNAL( clicked() ),
146 this, TQ_SLOT( slotNewTab() ) );
147 b->setIconSet( SmallIcon(
"tab_new" ) );
149 TQToolTip::add(b, i18n(
"Open a new tab"));
150 m_mainWindow->tabWidget()->setCornerWidget( b, TopLeft );
152 b = m_closeTabButton =
new TQToolButton( m_mainWindow->tabWidget() );
153 connect( b, TQ_SIGNAL( clicked() ),
154 this, TQ_SLOT( slotCloseTab() ) );
155 b->setIconSet( SmallIcon(
"tab_remove" ) );
157 TQToolTip::add(b, i18n(
"Close the current tab"));
158 m_mainWindow->tabWidget()->setCornerWidget( b, TopRight );
161 void KateViewManager::updateViewSpaceActions ()
163 if (!m_currentContainer)
return;
165 m_closeView->setEnabled (m_currentContainer->viewSpaceCount() > 1);
166 goNext->setEnabled (m_currentContainer->viewSpaceCount() > 1);
167 goPrev->setEnabled (m_currentContainer->viewSpaceCount() > 1);
170 void KateViewManager::tabChanged(TQWidget* widget) {
171 KateViewSpaceContainer *container=
static_cast<KateViewSpaceContainer*
>(widget->tqt_cast(
"KateViewSpaceContainer"));
173 m_currentContainer=container;
176 container->reactivateActiveView();
180 m_closeTab->setEnabled(m_mainWindow->tabWidget()->count() > 1);
181 m_activateNextTab->setEnabled(m_mainWindow->tabWidget()->count() > 1);
182 m_activatePrevTab->setEnabled(m_mainWindow->tabWidget()->count() > 1);
183 m_closeTabButton->setEnabled (m_mainWindow->tabWidget()->count() > 1);
185 updateViewSpaceActions ();
188 void KateViewManager::slotNewTab()
190 uint documentNumber=0;
192 if (m_currentContainer)
194 if (m_currentContainer->activeView())
195 documentNumber = m_currentContainer->activeView()->getDoc()->documentNumber();
198 KateViewSpaceContainer *container=
new KateViewSpaceContainer (m_mainWindow->tabWidget(),
this);
199 m_viewSpaceContainerList.append(container);
200 m_mainWindow->tabWidget()->addTab (container,
"");
202 connect(container,TQ_SIGNAL(viewChanged()),
this,TQ_SIGNAL(viewChanged()));
203 connect(container,TQ_SIGNAL(viewChanged()),m_viewManager,TQ_SIGNAL(viewChanged()));
207 container->activateView(documentNumber);
208 container->setShowFullPath(showFullPath);
209 m_mainWindow->slotWindowActivated ();
213 void KateViewManager::slotCloseTab()
215 if (m_viewSpaceContainerList.count() <= 1)
return;
216 if (!m_currentContainer)
return;
218 int pos = m_viewSpaceContainerList.find (m_currentContainer);
224 m_mainWindow->guiFactory()->removeClient (guiMergedView );
226 m_viewSpaceContainerList.remove (pos);
228 if ((uint)pos >= m_viewSpaceContainerList.count())
229 pos = m_viewSpaceContainerList.count()-1;
231 tabChanged(m_viewSpaceContainerList.at (pos));
234 void KateViewManager::activateNextTab()
236 if( m_mainWindow->tabWidget()->count() <= 1 )
return;
238 int iTab = m_mainWindow->tabWidget()->currentPageIndex();
242 if( iTab == m_mainWindow->tabWidget()->count() )
245 m_mainWindow->tabWidget()->setCurrentPage( iTab );
248 void KateViewManager::activatePrevTab()
250 if( m_mainWindow->tabWidget()->count() <= 1 )
return;
252 int iTab = m_mainWindow->tabWidget()->currentPageIndex();
257 iTab = m_mainWindow->tabWidget()->count() - 1;
259 m_mainWindow->tabWidget()->setCurrentPage( iTab );
262 void KateViewManager::activateSpace (Kate::View* v)
264 if (m_currentContainer) {
265 m_currentContainer->activateSpace(v);
269 void KateViewManager::activateView ( Kate::View *view ) {
270 if (m_currentContainer) {
271 m_currentContainer->activateView(view);
275 KateViewSpace* KateViewManager::activeViewSpace ()
277 if (m_currentContainer) {
278 return m_currentContainer->activeViewSpace();
283 Kate::View* KateViewManager::activeView ()
285 if (m_currentContainer) {
286 return m_currentContainer->activeView();
291 void KateViewManager::setActiveSpace ( KateViewSpace* vs )
293 if (m_currentContainer) {
294 m_currentContainer->setActiveSpace(vs);
299 void KateViewManager::setActiveView ( Kate::View* view )
301 if (m_currentContainer) {
302 m_currentContainer->setActiveView(view);
308 void KateViewManager::activateView( uint documentNumber )
310 if (m_currentContainer) {
311 m_currentContainer->activateView(documentNumber);
315 uint KateViewManager::viewCount ()
318 for (uint i=0;i<m_viewSpaceContainerList.count();i++) {
319 viewCount+=m_viewSpaceContainerList.at(i)->viewCount();
325 uint KateViewManager::viewSpaceCount ()
327 uint viewSpaceCount=0;
328 for (uint i=0;i<m_viewSpaceContainerList.count();i++) {
329 viewSpaceCount+=m_viewSpaceContainerList.at(i)->viewSpaceCount();
331 return viewSpaceCount;
334 void KateViewManager::setViewActivationBlocked (
bool block)
336 for (uint i=0;i<m_viewSpaceContainerList.count();i++)
337 m_viewSpaceContainerList.at(i)->m_blockViewCreationAndActivation=block;
340 void KateViewManager::activateNextView()
342 if (m_currentContainer) {
343 m_currentContainer->activateNextView();
347 void KateViewManager::activatePrevView()
349 if (m_currentContainer) {
350 m_currentContainer->activatePrevView();
354 void KateViewManager::closeViews(uint documentNumber)
356 for (uint i=0;i<m_viewSpaceContainerList.count();i++) {
357 m_viewSpaceContainerList.at(i)->closeViews(documentNumber);
359 tabChanged(m_currentContainer);
362 void KateViewManager::slotDocumentNew ()
364 if (m_currentContainer) m_currentContainer->createView ();
367 void KateViewManager::slotDocumentOpen ()
369 Kate::View *cv = activeView();
372 KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenURLsAndEncoding(
373 (cv ? KTextEditor::encodingInterface(cv->document())->encoding() : Kate::Document::defaultEncoding()),
374 (cv ? cv->document()->url().url() : TQString::null),
375 TQString::null,m_mainWindow,i18n(
"Open File"));
378 for (KURL::List::Iterator i=r.URLs.begin(); i != r.URLs.end(); ++i)
379 lastID = openURL( *i, r.encoding,
false );
382 activateView (lastID);
386 void KateViewManager::slotDocumentClose ()
389 if (!activeView())
return;
393 if ( (KateDocManager::self()->documents() == 1)
394 && !activeView()->getDoc()->isModified()
395 && activeView()->getDoc()->url().isEmpty()
396 && (activeView()->getDoc()->length() == 0) )
398 activeView()->getDoc()->closeURL();
403 KateDocManager::self()->closeDocument (activeView()->getDoc());
406 uint KateViewManager::openURL (
const KURL &url,
const TQString& encoding,
bool activate,
bool isTempFile )
409 Kate::Document *doc = KateDocManager::self()->openURL (url, encoding, &
id, isTempFile );
411 if (!doc->url().isEmpty())
412 m_mainWindow->fileOpenRecent->addURL( doc->url() );
420 void KateViewManager::openURL (
const KURL &url)
422 openURL (url, TQString::null);
425 void KateViewManager::removeViewSpace (KateViewSpace *viewspace)
427 if (m_currentContainer) {
428 m_currentContainer->removeViewSpace(viewspace);
432 void KateViewManager::slotCloseCurrentViewSpace()
434 if (m_currentContainer) {
435 m_currentContainer->slotCloseCurrentViewSpace();
439 void KateViewManager::slotSplitViewSpaceVert()
441 if (m_currentContainer) {
442 m_currentContainer->slotSplitViewSpaceVert();
446 void KateViewManager::slotSplitViewSpaceHoriz()
448 if (m_currentContainer) {
449 m_currentContainer->slotSplitViewSpaceHoriz();
453 void KateViewManager::setShowFullPath(
bool enable )
456 for (uint i=0;i<m_viewSpaceContainerList.count();i++) {
457 m_viewSpaceContainerList.at(i)->setShowFullPath(enable);
459 m_mainWindow->slotWindowActivated ();
465 void KateViewManager::saveViewConfiguration(TDEConfig *config,
const TQString& grp)
469 TQString group = grp;
471 int n = group.toInt( &ok );
473 group = TQString(
"MainWindow%1" ).arg( n-1 );
475 config->setGroup(group);
476 config->writeEntry(
"ViewSpaceContainers",m_viewSpaceContainerList.count());
477 config->writeEntry(
"Active ViewSpaceContainer", m_mainWindow->tabWidget()->currentPageIndex());
478 for (uint i=0;i<m_viewSpaceContainerList.count();i++) {
479 m_viewSpaceContainerList.at(i)->saveViewConfiguration(config,group+TQString(
":ViewSpaceContainer-%1:").arg(i));
483 void KateViewManager::restoreViewConfiguration (TDEConfig *config,
const TQString& grp)
487 TQString group = grp;
489 int n = group.toInt( &ok );
491 group = TQString(
"MainWindow%1" ).arg( n-1 );
493 config->setGroup(group);
494 uint tabCount=config->readNumEntry(
"ViewSpaceContainers",0);
495 int activeOne=config->readNumEntry(
"Active ViewSpaceContainer",0);
496 if (tabCount==0)
return;
497 m_viewSpaceContainerList.at(0)->restoreViewConfiguration(config,group+TQString(
":ViewSpaceContainer-0:"));
498 for (uint i=1;i<tabCount;i++) {
500 m_viewSpaceContainerList.at(i)->restoreViewConfiguration(config,group+TQString(
":ViewSpaceContainer-%1:").arg(i));
503 if (activeOne != m_mainWindow->tabWidget()->currentPageIndex())
504 m_mainWindow->tabWidget()->setCurrentPage (activeOne);
506 updateViewSpaceActions();
509 KateMainWindow *KateViewManager::mainWindow() {
Interface to the viewmanager.