• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • app
katemdi.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org>
4 
5  GUIClient partly based on tdetoolbarhandler.cpp: Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "katemdi.h"
24 #include "katemdi.moc"
25 
26 #include <tdeaction.h>
27 #include <kdebug.h>
28 #include <tdeglobal.h>
29 #include <tdeglobalsettings.h>
30 #include <tdeapplication.h>
31 #include <tdelocale.h>
32 #include <tdeconfig.h>
33 #include <kiconloader.h>
34 #include <tdepopupmenu.h>
35 #include <tdemessagebox.h>
36 
37 #include <tqvbox.h>
38 #include <tqhbox.h>
39 #include <tqevent.h>
40 
41 namespace KateMDI {
42 
43 //BEGIN SPLITTER
44 
45 Splitter::Splitter(Orientation o, TQWidget* parent, const char* name)
46  : TQSplitter(o, parent, name)
47 {
48 }
49 
50 Splitter::~Splitter()
51 {
52 }
53 
54 bool Splitter::isLastChild(TQWidget* w) const
55 {
56  return ( idAfter( w ) == 0 );
57 }
58 
59 int Splitter::idAfter ( TQWidget * w ) const
60 {
61  return TQSplitter::idAfter (w);
62 }
63 
64 //END SPLITTER
65 
66 
67 //BEGIN TOGGLETOOLVIEWACTION
68 
69 ToggleToolViewAction::ToggleToolViewAction ( const TQString& text, const TDEShortcut& cut, ToolView *tv,
70  TQObject* parent, const char* name )
71  : TDEToggleAction(text,cut,parent,name)
72  , m_tv(tv)
73 {
74  connect(this,TQ_SIGNAL(toggled(bool)),this,TQ_SLOT(slotToggled(bool)));
75  connect(m_tv,TQ_SIGNAL(visibleChanged(bool)),this,TQ_SLOT(visibleChanged(bool)));
76 
77  setChecked(m_tv->visible());
78 }
79 
80 ToggleToolViewAction::~ToggleToolViewAction()
81 {
82  unplugAll();
83 }
84 
85 void ToggleToolViewAction::visibleChanged(bool)
86 {
87  if (isChecked() != m_tv->visible())
88  setChecked (m_tv->visible());
89 }
90 
91 void ToggleToolViewAction::slotToggled(bool t)
92 {
93  if (t)
94  {
95  m_tv->mainWindow()->showToolView (m_tv);
96  m_tv->setFocus ();
97  }
98  else
99  {
100  m_tv->mainWindow()->hideToolView (m_tv);
101  m_tv->mainWindow()->centralWidget()->setFocus ();
102  }
103 }
104 
105 //END TOGGLETOOLVIEWACTION
106 
107 
108 //BEGIN GUICLIENT
109 
110 static const char *actionListName = "kate_mdi_window_actions";
111 
112 static const char *guiDescription = ""
113  "<!DOCTYPE kpartgui><kpartgui name=\"kate_mdi_window_actions\">"
114  "<MenuBar>"
115  " <Menu name=\"window\">"
116  " <ActionList name=\"%1\" />"
117  " </Menu>"
118  "</MenuBar>"
119  "</kpartgui>";
120 
121 GUIClient::GUIClient ( MainWindow *mw )
122  : TQObject ( mw )
123  , KXMLGUIClient ( mw )
124  , m_mw (mw)
125 {
126  connect( m_mw->guiFactory(), TQ_SIGNAL( clientAdded( KXMLGUIClient * ) ),
127  this, TQ_SLOT( clientAdded( KXMLGUIClient * ) ) );
128 
129  if ( domDocument().documentElement().isNull() )
130  {
131  TQString completeDescription = TQString::fromLatin1( guiDescription )
132  .arg( actionListName );
133 
134  setXML( completeDescription, false /*merge*/ );
135  }
136 
137  if (actionCollection()->tdeaccel()==0)
138  actionCollection()->setWidget(m_mw);
139 
140  m_toolMenu = new TDEActionMenu(i18n("Tool &Views"),actionCollection(),"kate_mdi_toolview_menu");
141  m_showSidebarsAction = new TDEToggleAction( i18n("Show Side&bars"),
142  CTRL|ALT|SHIFT|Key_F, actionCollection(), "kate_mdi_sidebar_visibility" );
143  m_showSidebarsAction->setCheckedState(i18n("Hide Side&bars"));
144  m_showSidebarsAction->setChecked( m_mw->sidebarsVisible() );
145  connect( m_showSidebarsAction, TQ_SIGNAL( toggled( bool ) ),
146  m_mw, TQ_SLOT( setSidebarsVisible( bool ) ) );
147 
148  m_toolMenu->insert( m_showSidebarsAction );
149  m_toolMenu->insert( new TDEActionSeparator( m_toolMenu ) );
150 
151  // read shortcuts
152  actionCollection()->readShortcutSettings( "Shortcuts", kapp->config() );
153 }
154 
155 GUIClient::~GUIClient()
156 {
157 }
158 
159 void GUIClient::updateSidebarsVisibleAction()
160 {
161  m_showSidebarsAction->setChecked( m_mw->sidebarsVisible() );
162 }
163 
164 void GUIClient::registerToolView (ToolView *tv)
165 {
166  TQString aname = TQString("kate_mdi_toolview_") + tv->id;
167 
168  // try to read the action shortcut
169  TDEShortcut sc;
170  TDEConfig *cfg = kapp->config();
171  TQString _grp = cfg->group();
172  cfg->setGroup("Shortcuts");
173  sc = TDEShortcut( cfg->readEntry( aname, "" ) );
174  cfg->setGroup( _grp );
175 
176  TDEToggleAction *a = new ToggleToolViewAction(i18n("Show %1").arg(tv->text),
177  sc,tv, actionCollection(), aname.latin1() );
178 
179  a->setCheckedState(TQString(i18n("Hide %1").arg(tv->text)));
180 
181  m_toolViewActions.append(a);
182  m_toolMenu->insert(a);
183 
184  m_toolToAction.insert (tv, a);
185 
186  updateActions();
187 }
188 
189 void GUIClient::unregisterToolView (ToolView *tv)
190 {
191  TDEAction *a = m_toolToAction[tv];
192 
193  if (!a)
194  return;
195 
196  m_toolViewActions.remove(a);
197  delete a;
198 
199  m_toolToAction.remove (tv);
200 
201  updateActions();
202 }
203 
204 void GUIClient::clientAdded( KXMLGUIClient *client )
205 {
206  if ( client == this )
207  updateActions();
208 }
209 
210 void GUIClient::updateActions()
211 {
212  if ( !factory() )
213  return;
214 
215  unplugActionList( actionListName );
216 
217  TQPtrList<TDEAction> addList;
218  addList.append(m_toolMenu);
219 
220  plugActionList( actionListName, addList );
221 }
222 
223 //END GUICLIENT
224 
225 
226 //BEGIN TOOLVIEW
227 
228 ToolView::ToolView (MainWindow *mainwin, Sidebar *sidebar, TQWidget *parent)
229  : TQVBox (parent)
230  , m_mainWin (mainwin)
231  , m_sidebar (sidebar)
232  , m_visible (false)
233  , persistent (false)
234 {
235 }
236 
237 ToolView::~ToolView ()
238 {
239  m_mainWin->toolViewDeleted (this);
240 }
241 
242 void ToolView::setVisible (bool vis)
243 {
244  if (m_visible == vis)
245  return;
246 
247  m_visible = vis;
248  emit visibleChanged (m_visible);
249 }
250 
251 bool ToolView::visible () const
252 {
253  return m_visible;
254 }
255 
256 void ToolView::childEvent ( TQChildEvent *ev )
257 {
258  // set the widget to be focus proxy if possible
259  if (ev->inserted() && ev->child() && ev->child()->tqt_cast("TQWidget")) {
260  setFocusProxy (::tqt_cast<TQWidget*>(ev->child()));
261 }
262 
263  TQVBox::childEvent (ev);
264 }
265 
266 //END TOOLVIEW
267 
268 
269 //BEGIN SIDEBAR
270 
271 Sidebar::Sidebar (KMultiTabBar::KMultiTabBarPosition pos, MainWindow *mainwin, TQWidget *parent)
272  : KMultiTabBar ((pos == KMultiTabBar::Top || pos == KMultiTabBar::Bottom) ? KMultiTabBar::Horizontal : KMultiTabBar::Vertical, parent)
273  , m_mainWin (mainwin)
274  , m_splitter (0)
275  , m_ownSplit (0)
276  , m_lastSize (0)
277 {
278  setPosition( pos );
279  hide ();
280 }
281 
282 Sidebar::~Sidebar ()
283 {
284 }
285 
286 void Sidebar::setSplitter (Splitter *sp)
287 {
288  m_splitter = sp;
289  m_ownSplit = new Splitter ((position() == KMultiTabBar::Top || position() == KMultiTabBar::Bottom) ? TQt::Horizontal : TQt::Vertical, m_splitter);
290  m_ownSplit->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
291  m_ownSplit->setChildrenCollapsible( false );
292  m_splitter->setResizeMode( m_ownSplit, TQSplitter::KeepSize );
293  m_ownSplit->hide ();
294 }
295 
296 ToolView *Sidebar::addWidget (const TQPixmap &icon, const TQString &text, ToolView *widget)
297 {
298  static int id = 0;
299 
300  if (widget)
301  {
302  if (widget->sidebar() == this)
303  return widget;
304 
305  widget->sidebar()->removeWidget (widget);
306  }
307 
308  int newId = ++id;
309 
310  appendTab (icon, newId, text);
311 
312  if (!widget)
313  {
314  widget = new ToolView (m_mainWin, this, m_ownSplit);
315  widget->hide ();
316  widget->icon = icon;
317  widget->text = text;
318  }
319  else
320  {
321  widget->hide ();
322  widget->reparent (m_ownSplit, 0, TQPoint());
323  widget->m_sidebar = this;
324  }
325 
326  // save it's pos ;)
327  widget->persistent = false;
328 
329  m_idToWidget.insert (newId, widget);
330  m_widgetToId.insert (widget, newId);
331  m_toolviews.push_back (widget);
332 
333  show ();
334 
335  connect(tab(newId),TQ_SIGNAL(clicked(int)),this,TQ_SLOT(tabClicked(int)));
336  tab(newId)->installEventFilter(this);
337 
338  return widget;
339 }
340 
341 bool Sidebar::removeWidget (ToolView *widget)
342 {
343  if (!m_widgetToId.contains(widget))
344  return false;
345 
346  removeTab(m_widgetToId[widget]);
347 
348  m_idToWidget.remove (m_widgetToId[widget]);
349  m_widgetToId.remove (widget);
350  m_toolviews.remove (widget);
351 
352  bool anyVis = false;
353  TQIntDictIterator<ToolView> it( m_idToWidget );
354  for ( ; it.current(); ++it )
355  {
356  if (!anyVis)
357  anyVis = it.current()->isVisible();
358  }
359 
360  if (m_idToWidget.isEmpty())
361  {
362  m_ownSplit->hide ();
363  hide ();
364  }
365  else if (!anyVis)
366  m_ownSplit->hide ();
367 
368  return true;
369 }
370 
371 bool Sidebar::showWidget (ToolView *widget)
372 {
373  if (!m_widgetToId.contains(widget))
374  return false;
375 
376  // hide other non-persistent views
377  TQIntDictIterator<ToolView> it( m_idToWidget );
378  for ( ; it.current(); ++it )
379  if ((it.current() != widget) && !it.current()->persistent)
380  {
381  it.current()->hide();
382  setTab (it.currentKey(), false);
383  it.current()->setVisible(false);
384  }
385 
386  setTab (m_widgetToId[widget], true);
387 
388  m_ownSplit->show ();
389  widget->show ();
390 
391  widget->setVisible (true);
392 
393  return true;
394 }
395 
396 bool Sidebar::hideWidget (ToolView *widget)
397 {
398  if (!m_widgetToId.contains(widget))
399  return false;
400 
401  bool anyVis = false;
402 
403  updateLastSize ();
404 
405  for ( TQIntDictIterator<ToolView> it( m_idToWidget ); it.current(); ++it )
406  {
407  if (it.current() == widget)
408  {
409  it.current()->hide();
410  continue;
411  }
412 
413  if (!anyVis)
414  anyVis = it.current()->isVisible();
415  }
416 
417  // lower tab
418  setTab (m_widgetToId[widget], false);
419 
420  if (!anyVis)
421  m_ownSplit->hide ();
422 
423  widget->setVisible (false);
424 
425  return true;
426 }
427 
428 void Sidebar::tabClicked(int i)
429 {
430  ToolView *w = m_idToWidget[i];
431 
432  if (!w)
433  return;
434 
435  if (isTabRaised(i))
436  {
437  showWidget (w);
438  w->setFocus ();
439  }
440  else
441  {
442  hideWidget (w);
443  m_mainWin->centralWidget()->setFocus ();
444  }
445 }
446 
447 bool Sidebar::eventFilter(TQObject *obj, TQEvent *ev)
448 {
449  if (ev->type()==TQEvent::ContextMenu)
450  {
451  TQContextMenuEvent *e = (TQContextMenuEvent *) ev;
452  KMultiTabBarTab *bt = dynamic_cast<KMultiTabBarTab*>(obj);
453  if (bt)
454  {
455  kdDebug()<<"Request for popup"<<endl;
456 
457  m_popupButton = bt->id();
458 
459  ToolView *w = m_idToWidget[m_popupButton];
460 
461  if (w)
462  {
463  TDEPopupMenu *p = new TDEPopupMenu (this);
464 
465  p->insertTitle(SmallIcon("view_remove"), i18n("Behavior"), 50);
466 
467  p->insertItem(w->persistent ? SmallIconSet("view-restore") : SmallIconSet("view-fullscreen"), w->persistent ? i18n("Make Non-Persistent") : i18n("Make Persistent"), 10);
468 
469  p->insertTitle(SmallIcon("move"), i18n("Move To"), 51);
470 
471  if (position() != 0)
472  p->insertItem(SmallIconSet("back"), i18n("Left Sidebar"),0);
473 
474  if (position() != 1)
475  p->insertItem(SmallIconSet("forward"), i18n("Right Sidebar"),1);
476 
477  if (position() != 2)
478  p->insertItem(SmallIconSet("go-up"), i18n("Top Sidebar"),2);
479 
480  if (position() != 3)
481  p->insertItem(SmallIconSet("go-down"), i18n("Bottom Sidebar"),3);
482 
483  connect(p, TQ_SIGNAL(activated(int)),
484  this, TQ_SLOT(buttonPopupActivate(int)));
485 
486  p->exec(e->globalPos());
487  delete p;
488 
489  return true;
490  }
491  }
492  }
493 
494  return false;
495 }
496 
497 void Sidebar::show()
498 {
499  if (m_idToWidget.isEmpty() || !m_mainWin->sidebarsVisible() )
500  return;
501 
502  KMultiTabBar::show( );
503 }
504 
505 void Sidebar::buttonPopupActivate (int id)
506 {
507  ToolView *w = m_idToWidget[m_popupButton];
508 
509  if (!w)
510  return;
511 
512  // move ids
513  if (id < 4)
514  {
515  // move + show ;)
516  m_mainWin->moveToolView (w, (KMultiTabBar::KMultiTabBarPosition) id);
517  m_mainWin->showToolView (w);
518  }
519 
520  // toggle persistent
521  if (id == 10)
522  w->persistent = !w->persistent;
523 }
524 
525 void Sidebar::updateLastSize ()
526 {
527  TQValueList<int> s = m_splitter->sizes ();
528 
529  int i = 0;
530  if ((position() == KMultiTabBar::Right || position() == KMultiTabBar::Bottom))
531  i = 2;
532 
533  // little threshold
534  if (s[i] > 2)
535  m_lastSize = s[i];
536 }
537 
538 class TmpToolViewSorter
539 {
540  public:
541  ToolView *tv;
542  unsigned int pos;
543 };
544 
545 void Sidebar::restoreSession (TDEConfig *config)
546 {
547  // get the last correct placed toolview
548  unsigned int firstWrong = 0;
549  for ( ; firstWrong < m_toolviews.size(); ++firstWrong )
550  {
551  ToolView *tv = m_toolviews[firstWrong];
552 
553  unsigned int pos = config->readUnsignedNumEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), firstWrong);
554 
555  if (pos != firstWrong)
556  break;
557  }
558 
559  // we need to reshuffle, ahhh :(
560  if (firstWrong < m_toolviews.size())
561  {
562  // first: collect the items to reshuffle
563  TQValueList<TmpToolViewSorter> toSort;
564  for (unsigned int i=firstWrong; i < m_toolviews.size(); ++i)
565  {
566  TmpToolViewSorter s;
567  s.tv = m_toolviews[i];
568  s.pos = config->readUnsignedNumEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(m_toolviews[i]->id), i);
569  toSort.push_back (s);
570  }
571 
572  // now: sort the stuff we need to reshuffle
573  for (unsigned int m=0; m < toSort.size(); ++m)
574  for (unsigned int n=m+1; n < toSort.size(); ++n)
575  if (toSort[n].pos < toSort[m].pos)
576  {
577  TmpToolViewSorter tmp = toSort[n];
578  toSort[n] = toSort[m];
579  toSort[m] = tmp;
580  }
581 
582  // then: remove this items from the button bar
583  // do this backwards, to minimize the relayout efforts
584  for (int i=m_toolviews.size()-1; i >= (int)firstWrong; --i)
585  {
586  removeTab (m_widgetToId[m_toolviews[i]]);
587  }
588 
589  // insert the reshuffled things in order :)
590  for (unsigned int i=0; i < toSort.size(); ++i)
591  {
592  ToolView *tv = toSort[i].tv;
593 
594  m_toolviews[firstWrong+i] = tv;
595 
596  // readd the button
597  int newId = m_widgetToId[tv];
598  appendTab (tv->icon, newId, tv->text);
599  connect(tab(newId),TQ_SIGNAL(clicked(int)),this,TQ_SLOT(tabClicked(int)));
600  tab(newId)->installEventFilter(this);
601 
602  // reshuffle in splitter
603  m_ownSplit->moveToLast (tv);
604  }
605  }
606 
607  // update last size if needed
608  updateLastSize ();
609 
610  // restore the own splitter sizes
611  TQValueList<int> s = config->readIntListEntry (TQString ("Kate-MDI-Sidebar-%1-Splitter").arg(position()));
612  m_ownSplit->setSizes (s);
613 
614  // show only correct toolviews, remember persistent values ;)
615  bool anyVis = false;
616  for ( unsigned int i=0; i < m_toolviews.size(); ++i )
617  {
618  ToolView *tv = m_toolviews[i];
619 
620  tv->persistent = config->readBoolEntry (TQString ("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), false);
621  tv->setVisible (config->readBoolEntry (TQString ("Kate-MDI-ToolView-%1-Visible").arg(tv->id), false));
622 
623  if (!anyVis)
624  anyVis = tv->visible();
625 
626  setTab (m_widgetToId[tv],tv->visible());
627 
628  if (tv->visible())
629  tv->show();
630  else
631  tv->hide ();
632  }
633 
634  if (anyVis)
635  m_ownSplit->show();
636  else
637  m_ownSplit->hide();
638 }
639 
640 void Sidebar::saveSession (TDEConfig *config)
641 {
642  // store the own splitter sizes
643  TQValueList<int> s = m_ownSplit->sizes();
644  config->writeEntry (TQString ("Kate-MDI-Sidebar-%1-Splitter").arg(position()), s);
645 
646  // store the data about all toolviews in this sidebar ;)
647  for ( unsigned int i=0; i < m_toolviews.size(); ++i )
648  {
649  ToolView *tv = m_toolviews[i];
650 
651  config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(tv->id), tv->sidebar()->position());
652  config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Sidebar-Position").arg(tv->id), i);
653  config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Visible").arg(tv->id), tv->visible());
654  config->writeEntry (TQString ("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), tv->persistent);
655  }
656 }
657 
658 //END SIDEBAR
659 
660 
661 //BEGIN MAIN WINDOW
662 
663 MainWindow::MainWindow (TQWidget* parentWidget, const char* name)
664  : KParts::MainWindow( parentWidget, name)
665  , m_sidebarsVisible(true)
666  , m_restoreConfig (0)
667  , m_guiClient (new GUIClient (this))
668 {
669  // init the internal widgets
670  TQHBox *hb = new TQHBox (this);
671  setCentralWidget(hb);
672 
673  m_sidebars[KMultiTabBar::Left] = new Sidebar (KMultiTabBar::Left, this, hb);
674 
675  m_hSplitter = new Splitter (TQt::Horizontal, hb);
676  m_hSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
677 
678  m_sidebars[KMultiTabBar::Left]->setSplitter (m_hSplitter);
679 
680  TQVBox *vb = new TQVBox (m_hSplitter);
681  m_hSplitter->setCollapsible(vb, false);
682 
683  m_sidebars[KMultiTabBar::Top] = new Sidebar (KMultiTabBar::Top, this, vb);
684 
685  m_vSplitter = new Splitter (TQt::Vertical, vb);
686  m_vSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
687 
688  m_sidebars[KMultiTabBar::Top]->setSplitter (m_vSplitter);
689 
690  m_centralWidget = new TQVBox (m_vSplitter);
691  m_vSplitter->setCollapsible(m_centralWidget, false);
692 
693  m_sidebars[KMultiTabBar::Bottom] = new Sidebar (KMultiTabBar::Bottom, this, vb);
694  m_sidebars[KMultiTabBar::Bottom]->setSplitter (m_vSplitter);
695 
696  m_sidebars[KMultiTabBar::Right] = new Sidebar (KMultiTabBar::Right, this, hb);
697  m_sidebars[KMultiTabBar::Right]->setSplitter (m_hSplitter);
698 }
699 
700 MainWindow::~MainWindow ()
701 {
702  // cu toolviews
703  while (!m_toolviews.isEmpty())
704  delete m_toolviews[0];
705 
706  // seems like we really should delete this by hand ;)
707  delete m_centralWidget;
708 
709  for (unsigned int i=0; i < 4; ++i)
710  delete m_sidebars[i];
711 }
712 
713 TQWidget *MainWindow::centralWidget () const
714 {
715  return m_centralWidget;
716 }
717 
718 ToolView *MainWindow::createToolView (const TQString &identifier, KMultiTabBar::KMultiTabBarPosition pos, const TQPixmap &icon, const TQString &text)
719 {
720  if (m_idToWidget[identifier])
721  return 0;
722 
723  // try the restore config to figure out real pos
724  if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
725  {
726  m_restoreConfig->setGroup (m_restoreGroup);
727  pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(identifier), pos);
728  }
729 
730  ToolView *v = m_sidebars[pos]->addWidget (icon, text, 0);
731  v->id = identifier;
732 
733  m_idToWidget.insert (identifier, v);
734  m_toolviews.push_back (v);
735 
736  // register for menu stuff
737  m_guiClient->registerToolView (v);
738 
739  return v;
740 }
741 
742 ToolView *MainWindow::toolView (const TQString &identifier) const
743 {
744  return m_idToWidget[identifier];
745 }
746 
747 void MainWindow::toolViewDeleted (ToolView *widget)
748 {
749  if (!widget)
750  return;
751 
752  if (widget->mainWindow() != this)
753  return;
754 
755  // unregister from menu stuff
756  m_guiClient->unregisterToolView (widget);
757 
758  widget->sidebar()->removeWidget (widget);
759 
760  m_idToWidget.remove (widget->id);
761  m_toolviews.remove (widget);
762 }
763 
764 void MainWindow::setSidebarsVisible( bool visible )
765 {
766  m_sidebarsVisible = visible;
767 
768  m_sidebars[0]->setShown(visible);
769  m_sidebars[1]->setShown(visible);
770  m_sidebars[2]->setShown(visible);
771  m_sidebars[3]->setShown(visible);
772 
773  m_guiClient->updateSidebarsVisibleAction();
774 
775  // show information message box, if the users hides the sidebars
776  if( !m_sidebarsVisible )
777  {
778  KMessageBox::information( this,
779  i18n("<qt>You are about to hide the sidebars. With "
780  "hidden sidebars it is not possible to directly "
781  "access the tool views with the mouse anymore, "
782  "so if you need to access the sidebars again "
783  "invoke <b>Window &gt; Tool Views &gt; Show Sidebars</b> "
784  "in the menu. It is still possible to show/hide "
785  "the tool views with the assigned shortcuts.</qt>"),
786  TQString::null, "Kate hide sidebars notification message" );
787  }
788 }
789 
790 bool MainWindow::sidebarsVisible() const
791 {
792  return m_sidebarsVisible;
793 }
794 
795 void MainWindow::setToolViewStyle (KMultiTabBar::KMultiTabBarStyle style)
796 {
797  m_sidebars[0]->setStyle(style);
798  m_sidebars[1]->setStyle(style);
799  m_sidebars[2]->setStyle(style);
800  m_sidebars[3]->setStyle(style);
801 }
802 
803 KMultiTabBar::KMultiTabBarStyle MainWindow::toolViewStyle () const
804 {
805  // all sidebars have the same style, so just take Top
806  return m_sidebars[KMultiTabBar::Top]->tabStyle();
807 }
808 
809 bool MainWindow::moveToolView (ToolView *widget, KMultiTabBar::KMultiTabBarPosition pos)
810 {
811  if (!widget || widget->mainWindow() != this)
812  return false;
813 
814  // try the restore config to figure out real pos
815  if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
816  {
817  m_restoreConfig->setGroup (m_restoreGroup);
818  pos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(widget->id), pos);
819  }
820 
821  m_sidebars[pos]->addWidget (widget->icon, widget->text, widget);
822 
823  return true;
824 }
825 
826 bool MainWindow::showToolView (ToolView *widget)
827 {
828  if (!widget || widget->mainWindow() != this)
829  return false;
830 
831  // skip this if happens during restoring, or we will just see flicker
832  if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
833  return true;
834 
835  return widget->sidebar()->showWidget (widget);
836 }
837 
838 bool MainWindow::hideToolView (ToolView *widget)
839 {
840  if (!widget || widget->mainWindow() != this)
841  return false;
842 
843  // skip this if happens during restoring, or we will just see flicker
844  if (m_restoreConfig && m_restoreConfig->hasGroup (m_restoreGroup))
845  return true;
846 
847  return widget->sidebar()->hideWidget (widget);
848 }
849 
850 void MainWindow::startRestore (TDEConfig *config, const TQString &group)
851 {
852  // first save this stuff
853  m_restoreConfig = config;
854  m_restoreGroup = group;
855 
856  if (!m_restoreConfig || !m_restoreConfig->hasGroup (m_restoreGroup))
857  {
858  // set sane default sizes
859  TQValueList<int> hs;
860  hs << 200 << 100 << 200;
861  TQValueList<int> vs;
862  vs << 150 << 100 << 200;
863 
864  m_sidebars[0]->setLastSize (hs[0]);
865  m_sidebars[1]->setLastSize (hs[2]);
866  m_sidebars[2]->setLastSize (vs[0]);
867  m_sidebars[3]->setLastSize (vs[2]);
868 
869  m_hSplitter->setSizes(hs);
870  m_vSplitter->setSizes(vs);
871  return;
872  }
873 
874  // apply size once, to get sizes ready ;)
875  m_restoreConfig->setGroup (m_restoreGroup);
876  restoreWindowSize (m_restoreConfig);
877 
878  m_restoreConfig->setGroup (m_restoreGroup);
879 
880  // get main splitter sizes ;)
881  TQValueList<int> hs = m_restoreConfig->readIntListEntry ("Kate-MDI-H-Splitter");
882  TQValueList<int> vs = m_restoreConfig->readIntListEntry ("Kate-MDI-V-Splitter");
883 
884  m_sidebars[0]->setLastSize (hs[0]);
885  m_sidebars[1]->setLastSize (hs[2]);
886  m_sidebars[2]->setLastSize (vs[0]);
887  m_sidebars[3]->setLastSize (vs[2]);
888 
889  m_hSplitter->setSizes(hs);
890  m_vSplitter->setSizes(vs);
891 
892  setToolViewStyle( (KMultiTabBar::KMultiTabBarStyle)m_restoreConfig->readNumEntry ("Kate-MDI-Sidebar-Style", (int)toolViewStyle()) );
893 
894  // after reading m_sidebarsVisible, update the GUI toggle action
895  m_sidebarsVisible = m_restoreConfig->readBoolEntry ("Kate-MDI-Sidebar-Visible", true );
896  m_guiClient->updateSidebarsVisibleAction();
897 }
898 
899 void MainWindow::finishRestore ()
900 {
901  if (!m_restoreConfig)
902  return;
903 
904  if (m_restoreConfig->hasGroup (m_restoreGroup))
905  {
906  // apply all settings, like toolbar pos and more ;)
907  applyMainWindowSettings(m_restoreConfig, m_restoreGroup);
908 
909  // reshuffle toolviews only if needed
910  m_restoreConfig->setGroup (m_restoreGroup);
911  for ( unsigned int i=0; i < m_toolviews.size(); ++i )
912  {
913  KMultiTabBar::KMultiTabBarPosition newPos = (KMultiTabBar::KMultiTabBarPosition) m_restoreConfig->readNumEntry (TQString ("Kate-MDI-ToolView-%1-Position").arg(m_toolviews[i]->id), m_toolviews[i]->sidebar()->position());
914 
915  if (m_toolviews[i]->sidebar()->position() != newPos)
916  {
917  moveToolView (m_toolviews[i], newPos);
918  }
919  }
920 
921  // restore the sidebars
922  m_restoreConfig->setGroup (m_restoreGroup);
923  for (unsigned int i=0; i < 4; ++i)
924  m_sidebars[i]->restoreSession (m_restoreConfig);
925  }
926 
927  // clear this stuff, we are done ;)
928  m_restoreConfig = 0;
929  m_restoreGroup = "";
930 }
931 
932 void MainWindow::saveSession (TDEConfig *config, const TQString &group)
933 {
934  if (!config)
935  return;
936 
937  saveMainWindowSettings (config, group);
938 
939  config->setGroup (group);
940 
941  // save main splitter sizes ;)
942  TQValueList<int> hs = m_hSplitter->sizes();
943  TQValueList<int> vs = m_vSplitter->sizes();
944 
945  if (hs[0] <= 2 && !m_sidebars[0]->splitterVisible ())
946  hs[0] = m_sidebars[0]->lastSize();
947  if (hs[2] <= 2 && !m_sidebars[1]->splitterVisible ())
948  hs[2] = m_sidebars[1]->lastSize();
949  if (vs[0] <= 2 && !m_sidebars[2]->splitterVisible ())
950  vs[0] = m_sidebars[2]->lastSize();
951  if (vs[2] <= 2 && !m_sidebars[3]->splitterVisible ())
952  vs[2] = m_sidebars[3]->lastSize();
953 
954  config->writeEntry ("Kate-MDI-H-Splitter", hs);
955  config->writeEntry ("Kate-MDI-V-Splitter", vs);
956 
957  // save sidebar style
958  config->writeEntry ("Kate-MDI-Sidebar-Style", (int)toolViewStyle());
959  config->writeEntry ("Kate-MDI-Sidebar-Visible", m_sidebarsVisible );
960 
961  // save the sidebars
962  for (unsigned int i=0; i < 4; ++i)
963  m_sidebars[i]->saveSession (config);
964 }
965 
966 //END MAIN WINDOW
967 
968 } // namespace KateMDI

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kate

Skip menu "kate"
  • kate
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.9.1
This website is maintained by Timothy Pearson.