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

kate

  • kate
  • app
katesession.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "katesession.h"
20 #include "katesession.moc"
21 
22 #include "kateapp.h"
23 #include "katemainwindow.h"
24 #include "katedocmanager.h"
25 
26 #include <kstandarddirs.h>
27 #include <tdelocale.h>
28 #include <kdebug.h>
29 #include <kdirwatch.h>
30 #include <tdelistview.h>
31 #include <kinputdialog.h>
32 #include <kiconloader.h>
33 #include <tdemessagebox.h>
34 #include <kmdcodec.h>
35 #include <kstdguiitem.h>
36 #include <kpushbutton.h>
37 #include <tdepopupmenu.h>
38 
39 #include <tqdir.h>
40 #include <tqlabel.h>
41 #include <tqlayout.h>
42 #include <tqvbox.h>
43 #include <tqhbox.h>
44 #include <tqcheckbox.h>
45 #include <tqdatetime.h>
46 #include <tqmap.h>
47 
48 #include <unistd.h>
49 #include <time.h>
50 
51 bool operator<( const KateSession::Ptr& a, const KateSession::Ptr& b )
52 {
53  return a->sessionName().lower() < b->sessionName().lower();
54 }
55 
56 KateSession::KateSession (KateSessionManager *manager, const TQString &fileName, const TQString &name)
57  : m_sessionFileRel (fileName)
58  , m_sessionName (name)
59  , m_documents (0)
60  , m_manager (manager)
61  , m_readConfig (0)
62  , m_writeConfig (0)
63 {
64  init ();
65 }
66 
67 void KateSession::init ()
68 {
69  // given file exists, use it to load some stuff ;)
70  if (!m_sessionFileRel.isEmpty() && TDEGlobal::dirs()->exists(sessionFile ()))
71  {
72  KSimpleConfig config (sessionFile (), true);
73 
74  if (m_sessionName.isEmpty())
75  {
76  // get the name out of the file
77  if (m_sessionFileRel == "default.katesession")
78  m_sessionName = i18n("Default Session");
79  else
80  {
81  config.setGroup ("General");
82  m_sessionName = config.readEntry ("Name", i18n ("Unnamed Session"));
83  }
84  }
85 
86  // get the document count
87  config.setGroup ("Open Documents");
88  m_documents = config.readUnsignedNumEntry("Count", 0);
89 
90  return;
91  }
92 
93  // filename not empty, create the file
94  // anders: When will this ever happen???
95  if (!m_sessionFileRel.isEmpty())
96  {
97  kdDebug(13001)<<"Kate::Session: initializing unexisting file!"<<endl;
98  // uhh, no name given
99  if (m_sessionName.isEmpty())
100  {
101  if (m_sessionFileRel == "default.katesession")
102  m_sessionName = i18n("Default Session");
103  else
104  m_sessionName = i18n("Session (%1)").arg(TQTime::currentTime().toString(Qt::LocalDate));
105  }
106 
107  // create the file, write name to it!
108  KSimpleConfig config (sessionFile ());
109  config.setGroup ("General");
110  config.writeEntry ("Name", m_sessionName);
111 
112  config.sync ();
113  }
114 }
115 
116 KateSession::~KateSession ()
117 {
118  delete m_readConfig;
119  delete m_writeConfig;
120 }
121 
122 TQString KateSession::sessionFile () const
123 {
124  return m_manager->sessionsDir() + "/" + m_sessionFileRel;
125 }
126 
127 bool KateSession::create (const TQString &name, bool force)
128 {
129  if (!force && (name.isEmpty() || !m_sessionFileRel.isEmpty()))
130  return false;
131 
132  delete m_writeConfig;
133  m_writeConfig = 0;
134 
135  delete m_readConfig;
136  m_readConfig = 0;
137 
138  m_sessionName = name;
139 
140  // get a usable filename
141  int s = time(0);
142  TQCString tname;
143  while (true)
144  {
145  tname.setNum (s++);
146  KMD5 md5 (tname);
147  m_sessionFileRel = TQString ("%1.katesession").arg (md5.hexDigest().data());
148 
149  if (!TDEGlobal::dirs()->exists(sessionFile ()))
150  break;
151  }
152 
153  // create the file, write name to it!
154  KSimpleConfig config (sessionFile ());
155  config.setGroup ("General");
156  config.writeEntry ("Name", m_sessionName);
157  config.sync ();
158 
159  // reinit ourselfs ;)
160  init ();
161 
162  return true;
163 }
164 
165 bool KateSession::rename (const TQString &name)
166 {
167  if (name.isEmpty () || m_sessionFileRel.isEmpty() || m_sessionFileRel == "default.katesession")
168  return false;
169 
170  m_sessionName = name;
171 
172  TDEConfig config (sessionFile (), false, false);
173  config.setGroup ("General");
174  config.writeEntry ("Name", m_sessionName);
175  config.sync ();
176 
177  return true;
178 }
179 
180 TDEConfig *KateSession::configRead ()
181 {
182  if (m_sessionFileRel.isEmpty())
183  return 0;
184 
185  if (m_readConfig)
186  return m_readConfig;
187 
188  return m_readConfig = new KSimpleConfig (sessionFile (), true);
189 }
190 
191 TDEConfig *KateSession::configWrite ()
192 {
193  if (m_sessionFileRel.isEmpty())
194  return 0;
195 
196  if (m_writeConfig)
197  return m_writeConfig;
198 
199  m_writeConfig = new KSimpleConfig (sessionFile ());
200  m_writeConfig->setGroup ("General");
201  m_writeConfig->writeEntry ("Name", m_sessionName);
202 
203  return m_writeConfig;
204 }
205 
206 KateSessionManager::KateSessionManager (TQObject *parent)
207  : TQObject (parent)
208  , m_sessionsDir (locateLocal( "data", "kate/sessions"))
209  , m_activeSession (new KateSession (this, "", ""))
210 {
211  kdDebug() << "LOCAL SESSION DIR: " << m_sessionsDir << endl;
212 
213  // create dir if needed
214  TDEGlobal::dirs()->makeDir (m_sessionsDir);
215 }
216 
217 KateSessionManager::~KateSessionManager()
218 {
219 }
220 
221 KateSessionManager *KateSessionManager::self()
222 {
223  return KateApp::self()->sessionManager ();
224 }
225 
226 void KateSessionManager::dirty (const TQString &)
227 {
228  updateSessionList ();
229 }
230 
231 void KateSessionManager::updateSessionList ()
232 {
233  m_sessionList.clear ();
234 
235  // Let's get a list of all session we have atm
236  TQDir dir (m_sessionsDir, "*.katesession");
237 
238  bool foundDefault = false;
239  for (unsigned int i=0; i < dir.count(); ++i)
240  {
241  KateSession *session = new KateSession (this, dir[i], "");
242  m_sessionList.append (session);
243 
244  kdDebug () << "FOUND SESSION: " << session->sessionName() << " FILE: " << session->sessionFile() << endl;
245 
246  if (!foundDefault && (dir[i] == "default.katesession"))
247  foundDefault = true;
248  }
249 
250  // add default session, if not there
251  if (!foundDefault)
252  m_sessionList.append (new KateSession (this, "default.katesession", i18n("Default Session")));
253 
254  qHeapSort(m_sessionList);
255 }
256 
257 void KateSessionManager::activateSession (KateSession::Ptr session, bool closeLast, bool saveLast, bool loadNew)
258 {
259  // don't reload.
260  // ### comparing the pointers directly is b0rk3d :(
261  if ( ! session->sessionName().isEmpty() && session->sessionName() == m_activeSession->sessionName() )
262  return;
263  // try to close last session
264  if (closeLast)
265  {
266  if (KateApp::self()->activeMainWindow())
267  {
268  if (!KateApp::self()->activeMainWindow()->queryClose_internal())
269  return;
270  }
271  }
272 
273  // save last session or not?
274  if (saveLast)
275  saveActiveSession (true);
276 
277  // really close last
278  if (closeLast)
279  {
280  KateDocManager::self()->closeAllDocuments ();
281  }
282 
283  // set the new session
284  m_activeSession = session;
285 
286  if (loadNew)
287  {
288  // open the new session
289  Kate::Document::setOpenErrorDialogsActivated (false);
290 
291  TDEConfig *sc = activeSession()->configRead();
292 
293  if (sc)
294  KateApp::self()->documentManager()->restoreDocumentList (sc);
295 
296  // if we have no session config object, try to load the default
297  // (anonymous/unnamed sessions)
298  if ( ! sc )
299  sc = new KSimpleConfig( sessionsDir() + "/default.katesession" );
300 
301  // window config
302  if (sc)
303  {
304  TDEConfig *c = KateApp::self()->config();
305  c->setGroup("General");
306 
307  if (c->readBoolEntry("Restore Window Configuration", true))
308  {
309  // a new, named session, read settings of the default session.
310  if ( ! sc->hasGroup("Open MainWindows") )
311  sc = new KSimpleConfig( sessionsDir() + "/default.katesession" );
312 
313  sc->setGroup ("Open MainWindows");
314  unsigned int wCount = sc->readUnsignedNumEntry("Count", 1);
315 
316  for (unsigned int i=0; i < wCount; ++i)
317  {
318  if (i >= KateApp::self()->mainWindows())
319  {
320  KateApp::self()->newMainWindow(sc, TQString ("MainWindow%1").arg(i));
321  }
322  else
323  {
324  sc->setGroup(TQString ("MainWindow%1").arg(i));
325  KateApp::self()->mainWindow(i)->readProperties (sc);
326  }
327  }
328 
329  if (wCount > 0)
330  {
331  while (wCount < KateApp::self()->mainWindows())
332  {
333  KateMainWindow *w = KateApp::self()->mainWindow(KateApp::self()->mainWindows()-1);
334  KateApp::self()->removeMainWindow (w);
335  delete w;
336  }
337  }
338  }
339  }
340 
341  Kate::Document::setOpenErrorDialogsActivated (true);
342  }
343 }
344 
345 KateSession::Ptr KateSessionManager::createSession (const TQString &name)
346 {
347  KateSession::Ptr s = new KateSession (this, "", "");
348  s->create (name);
349 
350  return s;
351 }
352 
353 KateSession::Ptr KateSessionManager::giveSession (const TQString &name)
354 {
355  if (name.isEmpty())
356  return new KateSession (this, "", "");
357 
358  updateSessionList();
359 
360  for (unsigned int i=0; i < m_sessionList.count(); ++i)
361  {
362  if (m_sessionList[i]->sessionName() == name)
363  return m_sessionList[i];
364  }
365 
366  return createSession (name);
367 }
368 
369 bool KateSessionManager::saveActiveSession (bool tryAsk, bool rememberAsLast)
370 {
371  if (tryAsk)
372  {
373  // app config
374  TDEConfig *c = KateApp::self()->config();
375  c->setGroup("General");
376 
377  TQString sesExit (c->readEntry ("Session Exit", "save"));
378 
379  if (sesExit == "discard")
380  return true;
381 
382  if (sesExit == "ask")
383  {
384  KDialogBase* dlg = new KDialogBase(i18n ("Save Session?")
385  , KDialogBase::Yes | KDialogBase::No
386  , KDialogBase::Yes, KDialogBase::No
387  );
388 
389  bool dontAgain = false;
390  int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Question,
391  i18n("Save current session?"), TQStringList(),
392  i18n("Do not ask again"), &dontAgain, KMessageBox::Notify);
393 
394  // remember to not ask again with right setting
395  if (dontAgain)
396  {
397  c->setGroup("General");
398 
399  if (res == KDialogBase::No)
400  c->writeEntry ("Session Exit", "discard");
401  else
402  c->writeEntry ("Session Exit", "save");
403  }
404 
405  if (res == KDialogBase::No)
406  return true;
407  }
408  }
409 
410  TDEConfig *sc = activeSession()->configWrite();
411 
412  if (!sc)
413  return false;
414 
415  KateDocManager::self()->saveDocumentList (sc);
416 
417  sc->setGroup ("Open MainWindows");
418  sc->writeEntry ("Count", KateApp::self()->mainWindows ());
419 
420  // save config for all windows around ;)
421  for (unsigned int i=0; i < KateApp::self()->mainWindows (); ++i )
422  {
423  sc->setGroup(TQString ("MainWindow%1").arg(i));
424  KateApp::self()->mainWindow(i)->saveProperties (sc);
425  }
426 
427  sc->sync();
428 
429  if (rememberAsLast)
430  {
431  TDEConfig *c = KateApp::self()->config();
432  c->setGroup("General");
433  c->writeEntry ("Last Session", activeSession()->sessionFileRelative());
434  c->sync ();
435  }
436 
437  return true;
438 }
439 
440 bool KateSessionManager::chooseSession ()
441 {
442  bool success = true;
443 
444  // app config
445  TDEConfig *c = KateApp::self()->config();
446  c->setGroup("General");
447 
448  // get last used session, default to default session
449  TQString lastSession (c->readEntry ("Last Session", "default.katesession"));
450  TQString sesStart (c->readEntry ("Startup Session", "manual"));
451 
452  // uhh, just open last used session, show no chooser
453  if (sesStart == "last")
454  {
455  activateSession (new KateSession (this, lastSession, ""), false, false);
456  return success;
457  }
458 
459  // start with empty new session
460  if (sesStart == "new")
461  {
462  activateSession (new KateSession (this, "", ""), false, false);
463  return success;
464  }
465 
466  KateSessionChooser *chooser = new KateSessionChooser (0, lastSession);
467 
468  bool retry = true;
469  int res = 0;
470  while (retry)
471  {
472  res = chooser->exec ();
473 
474  switch (res)
475  {
476  case KateSessionChooser::resultOpen:
477  {
478  KateSession::Ptr s = chooser->selectedSession ();
479 
480  if (!s)
481  {
482  KMessageBox::error (chooser, i18n("No session selected to open."), i18n ("No Session Selected"));
483  break;
484  }
485 
486  activateSession (s, false, false);
487  retry = false;
488  break;
489  }
490 
491  // exit the app lateron
492  case KateSessionChooser::resultQuit:
493  success = false;
494  retry = false;
495  break;
496 
497  default:
498  activateSession (new KateSession (this, "", ""), false, false);
499  retry = false;
500  break;
501  }
502  }
503 
504  // write back our nice boolean :)
505  if (success && chooser->reopenLastSession ())
506  {
507  c->setGroup("General");
508 
509  if (res == KateSessionChooser::resultOpen)
510  c->writeEntry ("Startup Session", "last");
511  else if (res == KateSessionChooser::resultNew)
512  c->writeEntry ("Startup Session", "new");
513 
514  c->sync ();
515  }
516 
517  delete chooser;
518 
519  return success;
520 }
521 
522 void KateSessionManager::sessionNew ()
523 {
524  activateSession (new KateSession (this, "", ""));
525 }
526 
527 void KateSessionManager::sessionOpen ()
528 {
529  KateSessionOpenDialog *chooser = new KateSessionOpenDialog (0);
530 
531  int res = chooser->exec ();
532 
533  if (res == KateSessionOpenDialog::resultCancel)
534  {
535  delete chooser;
536  return;
537  }
538 
539  KateSession::Ptr s = chooser->selectedSession ();
540 
541  if (s)
542  activateSession (s);
543 
544  delete chooser;
545 }
546 
547 void KateSessionManager::sessionSave ()
548 {
549  // if the active session is valid, just save it :)
550  if (saveActiveSession ())
551  return;
552 
553  bool ok = false;
554  TQString name = KInputDialog::getText (i18n("Specify Name for Current Session"), i18n("Session name:"), "", &ok);
555 
556  if (!ok)
557  return;
558 
559  if (name.isEmpty())
560  {
561  KMessageBox::error (0, i18n("To save a new session, you must specify a name."), i18n ("Missing Session Name"));
562  return;
563  }
564 
565  activeSession()->create (name);
566  saveActiveSession ();
567 }
568 
569 void KateSessionManager::sessionSaveAs ()
570 {
571  bool ok = false;
572  TQString name = KInputDialog::getText (i18n("Specify New Name for Current Session"), i18n("Session name:"), "", &ok);
573 
574  if (!ok)
575  return;
576 
577  if (name.isEmpty())
578  {
579  KMessageBox::error (0, i18n("To save a session, you must specify a name."), i18n ("Missing Session Name"));
580  return;
581  }
582 
583  activeSession()->create (name, true);
584  saveActiveSession ();
585 }
586 
587 
588 void KateSessionManager::sessionManage ()
589 {
590  KateSessionManageDialog *dlg = new KateSessionManageDialog (0);
591 
592  dlg->exec ();
593 
594  delete dlg;
595 }
596 
597 //BEGIN CHOOSER DIALOG
598 
599 class KateSessionChooserItem : public TQListViewItem
600 {
601  public:
602  KateSessionChooserItem (TDEListView *lv, KateSession::Ptr s)
603  : TQListViewItem (lv, s->sessionName())
604  , session (s)
605  {
606  TQString docs;
607  docs.setNum (s->documents());
608  setText (1, docs);
609  }
610 
611  KateSession::Ptr session;
612 };
613 
614 KateSessionChooser::KateSessionChooser (TQWidget *parent, const TQString &lastSession)
615  : KDialogBase ( parent
616  , ""
617  , true
618  , i18n ("Session Chooser")
619  , KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3
620  , KDialogBase::User2
621  , true
622  , KStdGuiItem::quit ()
623  , KGuiItem (i18n ("Open Session"), "document-open")
624  , KGuiItem (i18n ("New Session"), "document-new")
625  )
626 {
627  TQHBox *page = new TQHBox (this);
628  page->setMinimumSize (400, 200);
629  setMainWidget(page);
630 
631  TQHBox *hb = new TQHBox (page);
632  hb->setSpacing (KDialog::spacingHint());
633 
634  TQLabel *label = new TQLabel (hb);
635  label->setPixmap (UserIcon("sessionchooser"));
636  label->setFrameStyle (TQFrame::Panel | TQFrame::Sunken);
637 
638  TQVBox *vb = new TQVBox (hb);
639  vb->setSpacing (KDialog::spacingHint());
640 
641  m_sessions = new TDEListView (vb);
642  m_sessions->addColumn (i18n("Session Name"));
643  m_sessions->addColumn (i18n("Open Documents"));
644  m_sessions->setResizeMode (TQListView::AllColumns);
645  m_sessions->setSelectionMode (TQListView::Single);
646  m_sessions->setAllColumnsShowFocus (true);
647 
648  connect (m_sessions, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged()));
649  connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2()));
650 
651  KateSessionList &slist (KateSessionManager::self()->sessionList());
652  for (unsigned int i=0; i < slist.count(); ++i)
653  {
654  KateSessionChooserItem *item = new KateSessionChooserItem (m_sessions, slist[i]);
655 
656  if (slist[i]->sessionFileRelative() == lastSession)
657  m_sessions->setSelected (item, true);
658  }
659 
660  m_useLast = new TQCheckBox (i18n ("&Always use this choice"), vb);
661 
662  setResult (resultNone);
663 
664  // trigger action update
665  selectionChanged ();
666 }
667 
668 KateSessionChooser::~KateSessionChooser ()
669 {
670 }
671 
672 KateSession::Ptr KateSessionChooser::selectedSession ()
673 {
674  KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem ();
675 
676  if (!item)
677  return 0;
678 
679  return item->session;
680 }
681 
682 bool KateSessionChooser::reopenLastSession ()
683 {
684  return m_useLast->isChecked ();
685 }
686 
687 void KateSessionChooser::slotUser2 ()
688 {
689  done (resultOpen);
690 }
691 
692 void KateSessionChooser::slotUser3 ()
693 {
694  done (resultNew);
695 }
696 
697 void KateSessionChooser::slotUser1 ()
698 {
699  done (resultQuit);
700 }
701 
702 void KateSessionChooser::selectionChanged ()
703 {
704  enableButton (KDialogBase::User2, m_sessions->selectedItem ());
705 }
706 
707 //END CHOOSER DIALOG
708 
709 //BEGIN OPEN DIALOG
710 
711 KateSessionOpenDialog::KateSessionOpenDialog (TQWidget *parent)
712  : KDialogBase ( parent
713  , ""
714  , true
715  , i18n ("Open Session")
716  , KDialogBase::User1 | KDialogBase::User2
717  , KDialogBase::User2
718  , false
719  , KStdGuiItem::cancel ()
720  , KGuiItem( i18n("&Open"), "document-open")
721  )
722 {
723  TQHBox *page = new TQHBox (this);
724  page->setMinimumSize (400, 200);
725  setMainWidget(page);
726 
727  TQHBox *hb = new TQHBox (page);
728 
729  TQVBox *vb = new TQVBox (hb);
730 
731  m_sessions = new TDEListView (vb);
732  m_sessions->addColumn (i18n("Session Name"));
733  m_sessions->addColumn (i18n("Open Documents"));
734  m_sessions->setResizeMode (TQListView::AllColumns);
735  m_sessions->setSelectionMode (TQListView::Single);
736  m_sessions->setAllColumnsShowFocus (true);
737 
738  connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2()));
739 
740  KateSessionList &slist (KateSessionManager::self()->sessionList());
741  for (unsigned int i=0; i < slist.count(); ++i)
742  {
743  new KateSessionChooserItem (m_sessions, slist[i]);
744  }
745 
746  setResult (resultCancel);
747 }
748 
749 KateSessionOpenDialog::~KateSessionOpenDialog ()
750 {
751 }
752 
753 KateSession::Ptr KateSessionOpenDialog::selectedSession ()
754 {
755  KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem ();
756 
757  if (!item)
758  return 0;
759 
760  return item->session;
761 }
762 
763 void KateSessionOpenDialog::slotUser1 ()
764 {
765  done (resultCancel);
766 }
767 
768 void KateSessionOpenDialog::slotUser2 ()
769 {
770  done (resultOk);
771 }
772 
773 //END OPEN DIALOG
774 
775 //BEGIN MANAGE DIALOG
776 
777 KateSessionManageDialog::KateSessionManageDialog (TQWidget *parent)
778  : KDialogBase ( parent
779  , ""
780  , true
781  , i18n ("Manage Sessions")
782  , KDialogBase::User1
783  , KDialogBase::User1
784  , false
785  , KStdGuiItem::close ()
786  )
787 {
788  TQHBox *page = new TQHBox (this);
789  page->setMinimumSize (400, 200);
790  setMainWidget(page);
791 
792  TQHBox *hb = new TQHBox (page);
793  hb->setSpacing (KDialog::spacingHint());
794 
795  m_sessions = new TDEListView (hb);
796  m_sessions->addColumn (i18n("Session Name"));
797  m_sessions->addColumn (i18n("Open Documents"));
798  m_sessions->setResizeMode (TQListView::AllColumns);
799  m_sessions->setSelectionMode (TQListView::Single);
800  m_sessions->setAllColumnsShowFocus (true);
801 
802  connect (m_sessions, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged()));
803 
804  updateSessionList ();
805 
806  TQWidget *vb = new TQWidget (hb);
807  TQVBoxLayout *vbl = new TQVBoxLayout (vb);
808  vbl->setSpacing (KDialog::spacingHint());
809 
810  m_rename = new KPushButton (i18n("&Rename..."), vb);
811  connect (m_rename, TQT_SIGNAL(clicked()), this, TQT_SLOT(rename()));
812  vbl->addWidget (m_rename);
813 
814  m_del = new KPushButton (KStdGuiItem::del (), vb);
815  connect (m_del, TQT_SIGNAL(clicked()), this, TQT_SLOT(del()));
816  vbl->addWidget (m_del);
817 
818  vbl->addStretch ();
819 
820  // trigger action update
821  selectionChanged ();
822 }
823 
824 KateSessionManageDialog::~KateSessionManageDialog ()
825 {
826 }
827 
828 void KateSessionManageDialog::slotUser1 ()
829 {
830  done (0);
831 }
832 
833 
834 void KateSessionManageDialog::selectionChanged ()
835 {
836  KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem ();
837 
838  m_rename->setEnabled (item && item->session->sessionFileRelative() != "default.katesession");
839  m_del->setEnabled (item && item->session->sessionFileRelative() != "default.katesession");
840 }
841 
842 void KateSessionManageDialog::rename ()
843 {
844  KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem ();
845 
846  if (!item || item->session->sessionFileRelative() == "default.katesession")
847  return;
848 
849  bool ok = false;
850  TQString name = KInputDialog::getText (i18n("Specify New Name for Session"), i18n("Session name:"), item->session->sessionName(), &ok);
851 
852  if (!ok)
853  return;
854 
855  if (name.isEmpty())
856  {
857  KMessageBox::error (0, i18n("To save a session, you must specify a name."), i18n ("Missing Session Name"));
858  return;
859  }
860 
861  item->session->rename (name);
862  updateSessionList ();
863 }
864 
865 void KateSessionManageDialog::del ()
866 {
867  KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem ();
868 
869  if (!item || item->session->sessionFileRelative() == "default.katesession")
870  return;
871 
872  TQFile::remove (item->session->sessionFile());
873  KateSessionManager::self()->updateSessionList ();
874  updateSessionList ();
875 }
876 
877 void KateSessionManageDialog::updateSessionList ()
878 {
879  m_sessions->clear ();
880 
881  KateSessionList &slist (KateSessionManager::self()->sessionList());
882  for (unsigned int i=0; i < slist.count(); ++i)
883  {
884  new KateSessionChooserItem (m_sessions, slist[i]);
885  }
886 }
887 
888 //END MANAGE DIALOG
889 
890 
891 KateSessionsAction::KateSessionsAction(const TQString& text, TQObject* parent, const char* name )
892  : TDEActionMenu(text, parent, name)
893 {
894  connect(popupMenu(),TQT_SIGNAL(aboutToShow()),this,TQT_SLOT(slotAboutToShow()));
895 }
896 
897 void KateSessionsAction::slotAboutToShow()
898 {
899  popupMenu()->clear ();
900 
901  KateSessionList &slist (KateSessionManager::self()->sessionList());
902  for (unsigned int i=0; i < slist.count(); ++i)
903  {
904  popupMenu()->insertItem (
905  slist[i]->sessionName(),
906  this, TQT_SLOT (openSession (int)), 0,
907  i );
908  }
909 }
910 
911 void KateSessionsAction::openSession (int i)
912 {
913  KateSessionList &slist (KateSessionManager::self()->sessionList());
914 
915  if ((uint)i >= slist.count())
916  return;
917 
918  KateSessionManager::self()->activateSession(slist[(uint)i]);
919 }

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.8.1.2
This website is maintained by Timothy Pearson.