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

kate

  • kate
  • app
katesessionpanel.cpp
1 /*
2  This file is part of the TDE project
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 "katesessionpanel.h"
20 #include "katesessionpanel.moc"
21 
22 #include "kateapp.h"
23 #include "katemainwindow.h"
24 #include "kateviewmanager.h"
25 #include "katesession.h"
26 
27 #include <kiconloader.h>
28 #include <tdelocale.h>
29 #include <tdemessagebox.h>
30 #include <tqlistview.h>
31 #include <tqlabel.h>
32 
33 
34 namespace
35 {
36  const char *KS_UNNAMED = "Unnamed";
37 };
38 
39 
40 //BEGIN KateSessionNameChooser
41 //-------------------------------------------
42 KateSessionNameChooser::KateSessionNameChooser(TQWidget *parent, bool showSwitchTo)
43  : KDialogBase(parent, "", true, i18n("Session Name Chooser"), KDialogBase::User1 | KDialogBase::User2,
44  KDialogBase::User2, true, KStdGuiItem::cancel(), KGuiItem(i18n("Continue"), "document-new")),
45  m_showSwitchTo(showSwitchTo)
46 {
47  TQHBox *page = new TQHBox(this);
48  //page->setMinimumSize(300, 100);
49  setMainWidget(page);
50 
51  TQVBox *vb = new TQVBox(page);
52  vb->setSpacing(KDialog::spacingHint());
53 
54  TQLabel *label = new TQLabel(vb);
55  label->setText("Please type the new session name:");
56 
57  m_sessionNameLE = new TQLineEdit(vb);
58  m_sessionNameLE->setText(i18n(KS_UNNAMED));
59  m_sessionNameLE->setFocus();
60 
61  if (m_showSwitchTo)
62  {
63  m_activateCB = new TQCheckBox(i18n("Switch to the new session"), vb, NULL);
64  m_activateCB->setChecked(true);
65  }
66 
67  connect(m_sessionNameLE, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(slotTextChanged()));
68  slotTextChanged(); // update button status
69 }
70 
71 //-------------------------------------------
72 TQString KateSessionNameChooser::getSessionName()
73 {
74  return m_sessionNameLE->text();
75 }
76 
77 //-------------------------------------------
78 bool KateSessionNameChooser::getActivateFlag()
79 {
80  if (m_showSwitchTo)
81  {
82  return m_activateCB->isChecked();
83  }
84  return false;
85 }
86 
87 //-------------------------------------------
88 void KateSessionNameChooser::slotUser1()
89 {
90  reject();
91 }
92 
93 //-------------------------------------------
94 void KateSessionNameChooser::slotUser2()
95 {
96  accept();
97 }
98 
99 //-------------------------------------------
100 void KateSessionNameChooser::slotTextChanged()
101 {
102  enableButton(KDialogBase::User2, !m_sessionNameLE->text().isEmpty());
103 }
104 //END KateSessionNameChooser
105 
106 
107 //BEGIN KateSessionPanelToolBarParent
108 void KateSessionPanelToolBarParent::setToolBar(TDEToolBar *tbar)
109 {
110  m_tbar = tbar;
111 }
112 
113 //-------------------------------------------
114 void KateSessionPanelToolBarParent::resizeEvent (TQResizeEvent*)
115 {
116  if (m_tbar)
117  {
118  setMinimumHeight(m_tbar->sizeHint().height());
119  m_tbar->resize(width(),height());
120  }
121 }
122 //END KateSessionPanelToolBarParent
123 
124 
125 //BEGIN KateSessionPanel
126 //-------------------------------------------
127 KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *viewManager,
128  TQWidget *parent, const char *name)
129  : TQVBox(parent, name), m_sessionManager(KateSessionManager::self()),
130  m_actionCollection(new TDEActionCollection(this)), m_columnName(-1), m_columnPixmap(-1)
131 {
132  // Toolbar
133  setup_toolbar();
134 
135  // Listview
136  m_listview = new TDEListView(this);
137  m_listview->header()->hide();
138  m_columnName = m_listview->addColumn("Session name");
139  m_columnPixmap = m_listview->addColumn("Pixmap", 24);
140  m_listview->addColumn("Dummy", 1); // Dummy column, only for nice resizing
141  m_listview->header()->setResizeEnabled(false, m_columnPixmap);
142  m_listview->setColumnAlignment(m_columnPixmap, TQt::AlignCenter);
143  m_listview->setMinimumWidth(m_listview->sizeHint().width());
144  m_listview->setSorting(-1);
145  m_listview->setResizeMode(TQListView::LastColumn);
146  //m_listview->setRootIsDecorated(true); // FIXME disabled until doc list software is developed
147 
148 
149  connect(m_listview, TQ_SIGNAL(selectionChanged()),
150  this, TQ_SLOT(slotSelectionChanged()));
151  connect(m_listview, TQ_SIGNAL(executed(TQListViewItem*)),
152  this, TQ_SLOT(slotItemExecuted(TQListViewItem*)));
153  connect(m_listview, TQ_SIGNAL(returnPressed(TQListViewItem*)),
154  this, TQ_SLOT(slotItemExecuted(TQListViewItem*)));
155  connect(KateApp::self(), TQ_SIGNAL(optionsChanged()),
156  this, TQ_SLOT(slotSelectionChanged()));
157  connect(m_sessionManager, TQ_SIGNAL(switchOptionChanged()),
158  this, TQ_SLOT(slotSelectionChanged()));
159  connect(m_sessionManager, TQ_SIGNAL(sessionActivated(int, int)),
160  this, TQ_SLOT(slotSessionActivated(int, int)));
161  connect(m_sessionManager, TQ_SIGNAL(sessionCreated(int)),
162  this, TQ_SLOT(slotSessionCreated(int)));
163  connect(m_sessionManager, TQ_SIGNAL(sessionDeleted(int)),
164  this, TQ_SLOT(slotSessionDeleted(int)));
165  connect(m_sessionManager, TQ_SIGNAL(sessionsSwapped(int, int)),
166  this, TQ_SLOT(slotSessionsSwapped(int, int)));
167  connect(m_sessionManager, TQ_SIGNAL(sessionRenamed(int)),
168  this, TQ_SLOT(slotSessionRenamed(int)));
169  connect(m_listview, TQ_SIGNAL(itemRenamed(TQListViewItem*)),
170  this, TQ_SLOT(slotLVSessionRenamed(TQListViewItem*)));
171 
172  TQPtrList<KateSession>& sessions = m_sessionManager->getSessionsList();
173  for (int idx = sessions.count() - 1; idx >= 0; --idx)
174  {
175  new KateSessionPanelItem(m_listview, sessions[idx]->getSessionName(), idx);
176  if (idx == m_sessionManager->getActiveSessionId())
177  {
178  m_listview->setSelected(m_listview->firstChild(), true);
179  m_listview->firstChild()->setPixmap(m_columnPixmap, SmallIcon("ok"));
180  }
181  }
182 
183 }
184 
185 //-------------------------------------------
186 void KateSessionPanel::setup_toolbar()
187 {
188  // Toolbar widget and frame
189  KateSessionPanelToolBarParent *tbarParent = new KateSessionPanelToolBarParent(this);
190  m_toolbar = new TDEToolBar(tbarParent, "Kate Session Panel Toolbar", true);
191  tbarParent->setToolBar(m_toolbar);
192  m_toolbar->setMovingEnabled(false);
193  m_toolbar->setFlat(true);
194  m_toolbar->setIconText(TDEToolBar::IconOnly);
195  m_toolbar->setIconSize(16);
196  m_toolbar->setEnableContextMenu(false);
197 
198  // Toolbar actions
199  TDEAction *a;
200 
201  a = new TDEAction(i18n("New"), SmallIcon("list-add"), 0,
202  this, TQ_SLOT(slotNewSession()), m_actionCollection, "session_new");
203  a->setWhatsThis(i18n("Create a new session and switch to it."));
204  a->plug(m_toolbar);
205 
206  a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0,
207  this, TQ_SLOT(slotSaveSession()), m_actionCollection, "session_save");
208  a->setWhatsThis(i18n("Save the selected session."));
209  a->plug(m_toolbar);
210 
211  a = new TDEAction(i18n("Save as..."), SmallIcon("document-save-as"), 0,
212  this, TQ_SLOT(slotSaveSessionAs()), m_actionCollection, "session_save_as");
213  a->setWhatsThis(i18n("Save an unsaved session with a new name or clone an already saved session "
214  "into a new session."));
215  a->plug(m_toolbar);
216 
217  a = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0,
218  this, TQ_SLOT(slotRenameSession()), m_actionCollection, "session_rename");
219  a->setWhatsThis(i18n("Rename the selected session."));
220  a->plug(m_toolbar);
221 
222  a = new TDEAction(i18n("Delete"), SmallIcon("edit-delete"), 0,
223  this, TQ_SLOT(slotDeleteSession()), m_actionCollection, "session_delete");
224  a->setWhatsThis(i18n("Delete the selected session."));
225  a->plug(m_toolbar);
226 
227  a = new TDEAction(i18n("Reload"), SmallIcon("reload"), 0,
228  this, TQ_SLOT(slotReloadSession()), m_actionCollection, "session_reload");
229  a->setWhatsThis(i18n("Reload the last saved state of the selected session."));
230  a->plug(m_toolbar);
231 
232  m_toolbar->insertLineSeparator();
233 
234  a = new TDEAction(i18n("Activate"), SmallIcon("forward"), 0,
235  this, TQ_SLOT(slotActivateSession()), m_actionCollection, "session_activate");
236  a->setWhatsThis(i18n("Activate the selected session."));
237  a->plug(m_toolbar);
238 
239  TDEToggleAction *tglA = new TDEToggleAction(i18n("Toggle read only"), SmallIcon("encrypted"), 0,
240  this, TQ_SLOT(slotSessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only");
241  tglA->setWhatsThis(i18n("Toggle read only status for the selected session.<p>"
242  "In a read only session, you can work as usual but the list of documents in the session "
243  "will not be saved when you exit Kate or switch to another session.<p>"
244  "You can use this option to create template sessions that you wish to keep unchanged over time."));
245  tglA->plug(m_toolbar);
246 
247  a = new TDEAction(i18n("Move Up"), SmallIcon("go-up"), 0,
248  this, TQ_SLOT(slotSessionMoveUp()), m_actionCollection, "session_move_up");
249  a->setWhatsThis(i18n("Move up the selected session."));
250  a->plug(m_toolbar);
251 
252  a = new TDEAction(i18n("Move Down"), SmallIcon("go-down"), 0,
253  this, TQ_SLOT(slotSessionMoveDown()), m_actionCollection, "session_move_down");
254  a->setWhatsThis(i18n("Move down the selected session."));
255  a->plug(m_toolbar);
256 }
257 
258 //-------------------------------------------
259 void KateSessionPanel::slotNewSession()
260 {
261  KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, false);
262  int result = nameChooser->exec();
263  if (result == TQDialog::Accepted)
264  {
265  int res = handleSessionSwitch();
266  if (res == KMessageBox::Cancel)
267  {
268  return;
269  }
270  else
271  {
272  m_sessionManager->newSession(nameChooser->getSessionName(), res == KMessageBox::Yes);
273  }
274  }
275 }
276 
277 //-------------------------------------------
278 void KateSessionPanel::slotSaveSession()
279 {
280  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
281  if (!sessionItem)
282  {
283  return;
284  }
285 
286  int sessId = sessionItem->getSessionId();
287  const KateSession *ks = m_sessionManager->getSessionFromId(sessId);
288  if (!ks)
289  {
290  return;
291  }
292 
293  if (ks->isStillVolatile())
294  {
295  // Session has never been saved before. Ask user for a session name first
296  slotSaveSessionAs();
297  }
298  else
299  {
300  m_sessionManager->saveSession(sessId);
301  slotSelectionChanged(); // Update the toolbar button status
302  }
303 }
304 
305 //-------------------------------------------
306 void KateSessionPanel::slotSaveSessionAs()
307 {
308  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
309  if (!sessionItem)
310  {
311  return;
312  }
313  int sessId = sessionItem->getSessionId();
314  KateSession *ks = m_sessionManager->getSessionFromId(sessId);
315  if (!ks)
316  {
317  return;
318  }
319 
320  // If the session was never saved or named before, the session will be saved with a new name.
321  // Otherwise it will be cloned into a new session.
322  bool cloneSession = !ks->isStillVolatile();
323  // Get new session name
324  KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, cloneSession);
325  int result = nameChooser->exec();
326  if (result == TQDialog::Accepted)
327  {
328  if (!cloneSession)
329  {
330  // Save unsaved session
331  m_sessionManager->renameSession(sessId, nameChooser->getSessionName());
332  m_sessionManager->saveSession(sessId);
333  }
334  else
335  {
336  // Clone session
337  bool activate = nameChooser->getActivateFlag();
338  int activeSessionId = m_sessionManager->getActiveSessionId();
339  int res = KMessageBox::Yes;
340  if (activate && sessId != activeSessionId)
341  {
342  // Cloning another session and switching to it at the same time,
343  // handle session switch correctly
344  res = handleSessionSwitch();
345  if (res == KMessageBox::Cancel)
346  {
347  return;
348  }
349  }
350  m_sessionManager->cloneSession(sessId, nameChooser->getSessionName(), activate, res == KMessageBox::No);
351  }
352  }
353 
354  slotSelectionChanged(); // Update the toolbar button status
355 }
356 
357 //-------------------------------------------
358 void KateSessionPanel::slotRenameSession()
359 {
360  TQListViewItem *sessionItem = m_listview->selectedItem();
361  if (!sessionItem)
362  {
363  return;
364  }
365 
366  m_listview->rename(m_listview->selectedItem(), m_columnName);
367 }
368 
369 //-------------------------------------------
370 void KateSessionPanel::slotDeleteSession()
371 {
372  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
373  if (!sessionItem)
374  {
375  return;
376  }
377 
378  int result = KMessageBox::warningContinueCancel(this,
379  i18n("Do you really want to delete the session \"%1\"?").arg(sessionItem->text(0)),
380  i18n("Delete session"), KStdGuiItem::del());
381  if (result == KMessageBox::Continue)
382  {
383  int sessionId = sessionItem->getSessionId();
384  if (sessionId == m_sessionManager->getActiveSessionId())
385  {
386  // First check if all documents can be closed safely
387  if (KateApp::self()->activeMainWindow())
388  {
389  if (!KateApp::self()->activeMainWindow()->queryClose_internal())
390  return;
391  }
392  }
393  //FIXME add options to let user decide what to do when deleting the current session
394  //(open previous/next session, create new empty session)
395  m_sessionManager->deleteSession(sessionId, KateSessionManager::INVALID_SESSION);
396  }
397 }
398 
399 //-------------------------------------------
400 void KateSessionPanel::slotReloadSession()
401 {
402  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
403  if (!sessionItem)
404  {
405  return;
406  }
407  int sessId = sessionItem->getSessionId();
408  if (sessId != m_sessionManager->getActiveSessionId())
409  {
410  return;
411  }
412 
413  // Restore active session to the last saved state
414  m_sessionManager->reloadActiveSession();
415 }
416 
417 //-------------------------------------------
418 void KateSessionPanel::slotActivateSession()
419 {
420  KateSessionPanelItem *newSessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
421  if (!newSessionItem)
422  {
423  return;
424  }
425 
426  int currSessionId = m_sessionManager->getActiveSessionId();
427  int newSessionId = newSessionItem->getSessionId();
428  if (newSessionId != currSessionId)
429  {
430  int res = handleSessionSwitch();
431  if (res == KMessageBox::Cancel)
432  {
433  return;
434  }
435  else
436  {
437  m_sessionManager->activateSession(newSessionId, res == KMessageBox::Yes);
438  }
439  }
440 }
441 
442 //-------------------------------------------
443 void KateSessionPanel::slotSessionToggleReadOnly()
444 {
445  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
446  const KateSession *ks(NULL);
447  if (sessionItem)
448  {
449  ks = m_sessionManager->getSessionFromId(sessionItem->getSessionId());
450  }
451  if (!sessionItem || !ks)
452  {
453  return;
454  }
455 
456  m_sessionManager->setSessionReadOnlyStatus(sessionItem->getSessionId(), !ks->isReadOnly());
457  slotSelectionChanged(); // Update the toolbar button status
458 }
459 
460 //-------------------------------------------
461 void KateSessionPanel::slotSessionMoveUp()
462 {
463  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
464  if (!sessionItem)
465  {
466  return;
467  }
468 
469  m_sessionManager->moveSessionBackward(sessionItem->getSessionId());
470 }
471 
472 //-------------------------------------------
473 void KateSessionPanel::slotSessionMoveDown()
474 {
475  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
476  if (!sessionItem)
477  {
478  return;
479  }
480 
481  m_sessionManager->moveSessionForward(sessionItem->getSessionId());
482 }
483 
484 //-------------------------------------------
485 void KateSessionPanel::slotItemExecuted(TQListViewItem *item)
486 {
487  if (!item)
488  {
489  return;
490  }
491 
492  // First level items are sessions. Executing one, will switch to that session.
493  // This is only allow when the 'Activate' toolbar button is enabled
494  if (!item->parent() &&
495  m_actionCollection->action("session_activate")->isEnabled())
496  {
497  slotActivateSession();
498  return;
499  }
500 }
501 
502 //-------------------------------------------
503 void KateSessionPanel::slotSelectionChanged()
504 {
505  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
506  const KateSession *ks(NULL);
507  if (sessionItem)
508  {
509  ks = m_sessionManager->getSessionFromId(sessionItem->getSessionId());
510  }
511 
512  TDEToggleAction *readOnlyAction = dynamic_cast<TDEToggleAction*>(
513  m_actionCollection->action("session_toggle_read_only"));
514  if (!sessionItem || !ks ||
515  m_sessionManager->getSwitchOption() == KateSessionManager::SWITCH_DISCARD)
516  {
517  m_actionCollection->action("session_save")->setEnabled(false);
518  m_actionCollection->action("session_save_as")->setEnabled(false);
519  m_actionCollection->action("session_rename")->setEnabled(false);
520  m_actionCollection->action("session_delete")->setEnabled(false);
521  m_actionCollection->action("session_reload")->setEnabled(false);
522  m_actionCollection->action("session_activate")->setEnabled(false);
523  m_actionCollection->action("session_move_up")->setEnabled(false);
524  m_actionCollection->action("session_move_down")->setEnabled(false);
525  readOnlyAction->setEnabled(false);
526  readOnlyAction->setChecked(false);
527  }
528  else
529  {
530  if (ks->isReadOnly())
531  {
532  // Read only sessions can not be saved or renamed
533  m_actionCollection->action("session_save")->setEnabled(false);
534  m_actionCollection->action("session_rename")->setEnabled(false);
535  m_actionCollection->action("session_delete")->setEnabled(false);
536  }
537  else
538  {
539  m_actionCollection->action("session_save")->setEnabled(true);
540  m_actionCollection->action("session_rename")->setEnabled(true);
541  m_actionCollection->action("session_delete")->setEnabled(true);
542  }
543  if (ks->getSessionFilename().isEmpty())
544  {
545  // Unstored sessions can not be made readonly
546  readOnlyAction->setEnabled(false);
547  readOnlyAction->setChecked(false);
548  }
549  else
550  {
551  readOnlyAction->setEnabled(true);
552  readOnlyAction->setChecked(ks->isReadOnly());
553  }
554  int sessId = sessionItem->getSessionId();
555  int activeSessId = m_sessionManager->getActiveSessionId();
556  m_actionCollection->action("session_save_as")->setEnabled(true);
557  m_actionCollection->action("session_reload")->setEnabled(sessId == activeSessId);
558  m_actionCollection->action("session_activate")->setEnabled(sessId != activeSessId);
559  m_actionCollection->action("session_move_up")->setEnabled(sessId > 0);
560  m_actionCollection->action("session_move_down")->setEnabled(sessId < (m_sessionManager->getSessionCount() - 1));
561  }
562 
563  emit selectionChanged();
564 }
565 
566 //-------------------------------------------
567 void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId)
568 {
569  // Move the active session marker
570  TQListViewItem *item = NULL;
571  if (oldSessionId != KateSessionManager::INVALID_SESSION)
572  {
573  // Old volatile sessions may have already been deleted.
574  // Remove the marker only for valid sessions.
575  item = m_listview->firstChild();
576  for (int idx = 0; idx < oldSessionId; ++idx)
577  {
578  item = item->nextSibling();
579  }
580  item->setPixmap(m_columnPixmap, TQPixmap());
581  }
582 
583  item = m_listview->firstChild();
584  for (int idx = 0; idx < newSessionId; ++idx)
585  {
586  item = item->nextSibling();
587  }
588  item->setPixmap(m_columnPixmap, SmallIcon("ok"));
589  m_listview->setSelected(item, true);
590  slotSelectionChanged(); // Update the toolbar button status
591 }
592 
593 //-------------------------------------------
594 void KateSessionPanel::slotSessionCreated(int sessionId)
595 {
596  TQPtrList<KateSession>& sessions = m_sessionManager->getSessionsList();
597  new KateSessionPanelItem(m_listview, m_listview->lastItem(), sessions[sessionId]->getSessionName(),
598  sessionId);
599 }
600 
601 //-------------------------------------------
602 void KateSessionPanel::slotSessionDeleted(int sessionId)
603 {
604  // delete item from listview
605  TQListViewItem *item = m_listview->firstChild();
606  int idx = 0;
607  for (; idx < sessionId; ++idx)
608  {
609  item = item->nextSibling();
610  }
611  TQListViewItem *nextItem = item->nextSibling();
612  delete item;
613  // update session id of all following items
614  item = nextItem;
615  while (item)
616  {
617  dynamic_cast<KateSessionPanelItem*>(item)->setSessionId(idx++);
618  item = item->nextSibling();
619  }
620 }
621 
622 //-------------------------------------------
623 void KateSessionPanel::slotSessionsSwapped(int sessionIdMin, int sessionIdMax)
624 {
625  if (sessionIdMin == sessionIdMax)
626  {
627  return;
628  }
629 
630  if (sessionIdMin > sessionIdMax)
631  {
632  // this is not executed when the slot is connected to m_sessionManager's
633  // sessionsSwapped(int, int) signal
634  int tmp = sessionIdMin;
635  sessionIdMin = sessionIdMax;
636  sessionIdMax = tmp;
637  }
638 
639  TQListViewItem *selectedItem = m_listview->selectedItem();
640 
641  // Looks for the previous siblings of the two items
642  TQListViewItem *siblMin(NULL), *siblMax(NULL), *itemMin(NULL), *itemMax(NULL);
643  TQListViewItem *currItem = m_listview->firstChild();
644  TQListViewItem *nextItem(NULL);
645  while (currItem)
646  {
647  nextItem = currItem->nextSibling();
648  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(nextItem);
649  if (sessionItem->getSessionId() == sessionIdMin)
650  {
651  siblMin = currItem;
652  itemMin = nextItem;
653  }
654  else if (sessionItem->getSessionId() == sessionIdMax)
655  {
656  siblMax = currItem;
657  itemMax = nextItem;
658  break;
659  }
660  currItem = nextItem;
661  }
662  if (!itemMin)
663  {
664  // The sessionIdMin item was the first of the list
665  itemMin = m_listview->firstChild();
666  }
667  // Remove the two items and place them in their new positions
668  m_listview->takeItem(itemMax);
669  m_listview->takeItem(itemMin);
670  m_listview->insertItem(itemMin);
671  m_listview->insertItem(itemMax);
672  itemMax->moveItem(siblMin);
673  if (siblMax != itemMin)
674  {
675  itemMin->moveItem(siblMax);
676  }
677  else
678  {
679  itemMin->moveItem(itemMax);
680  }
681  // Update item's session id
682  (dynamic_cast<KateSessionPanelItem*>(itemMax))->setSessionId(sessionIdMin);
683  (dynamic_cast<KateSessionPanelItem*>(itemMin))->setSessionId(sessionIdMax);
684 
685  m_listview->setSelected(selectedItem, true);
686 }
687 
688 //-------------------------------------------
689 void KateSessionPanel::slotSessionRenamed(int sessionId)
690 {
691  TQListViewItem *item = m_listview->firstChild();
692  for (int idx = 0; idx < sessionId; ++idx)
693  {
694  item = item->nextSibling();
695  }
696  item->setText(m_columnName, m_sessionManager->getSessionName(sessionId));
697 }
698 
699 //-------------------------------------------
700 void KateSessionPanel::slotLVSessionRenamed(TQListViewItem *item)
701 {
702  KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(item);
703  if (!sessionItem)
704  {
705  return;
706  }
707 
708  m_sessionManager->renameSession(sessionItem->getSessionId(), sessionItem->text(m_columnName));
709 }
710 
711 //-------------------------------------------
712 int KateSessionPanel::handleSessionSwitch()
713 {
714  const KateSession *ks = m_sessionManager->getActiveSession();
715  int switchOption = m_sessionManager->getSwitchOption();
716  if (!ks || switchOption == KateSessionManager::SWITCH_DISCARD)
717  {
718  return KMessageBox::No;
719  }
720 
721  if (switchOption == KateSessionManager::SWITCH_ASK)
722  {
723  KDialogBase *dlg = new KDialogBase(i18n("Save Session"),
724  KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
725  KDialogBase::Cancel, KDialogBase::Cancel, NULL, NULL, true, false,
726  KStdGuiItem::save(), KStdGuiItem::del(), KStdGuiItem::cancel());
727  bool dontAgain = false;
728  int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Warning,
729  i18n("<p>Do you want to save the current session?<p>!!NOTE!!"
730  "<p>The session will be removed if you choose \"Delete\""), TQStringList(),
731  i18n("Do not ask again"), &dontAgain, KMessageBox::Notify);
732  if (res == KDialogBase::Cancel)
733  {
734  return KMessageBox::Cancel;
735  }
736  if (dontAgain)
737  {
738  if (res == KDialogBase::No)
739  {
740  m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_DISCARD);
741  }
742  else
743  {
744  m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_SAVE);
745  }
746  }
747  if (res == KDialogBase::No)
748  {
749  return KMessageBox::No;
750  }
751  }
752 
753  // At this point the session needs to be saved.
754  // Make sure to handle volatile sessions correctly.
755  if (ks->isStillVolatile())
756  {
757  KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, false);
758  int res = nameChooser->exec();
759  if (res == TQDialog::Accepted)
760  {
761  m_sessionManager->renameSession(m_sessionManager->getActiveSessionId(), nameChooser->getSessionName());
762  }
763  else
764  {
765  return KMessageBox::Cancel;
766  }
767  }
768 
769  return KMessageBox::Yes;
770 }
771 //END KateSessionPanel
KateApp::activeMainWindow
KateMainWindow * activeMainWindow()
give back current active main window can only be 0 at app start or exit
Definition: kateapp.cpp:457
KateSessionManager::switchOptionChanged
void switchOptionChanged()
Emitted when the session switch option has been set/changed.
KateSessionManager
The Kate session manager.
Definition: katesession.h:176
KateSessionManager::getSessionName
const TQString & getSessionName(int sessionId)
Definition: katesession.cpp:546
KateSession::isReadOnly
bool isReadOnly() const
Definition: katesession.h:86
KateSessionManager::self
static KateSessionManager * self()
get a pointer to the unique KateSessionManager instance.
Definition: katesession.cpp:321
KateSession
An object representing a Kate&#39;s session.
Definition: katesession.h:47
KateApp::self
static KateApp * self()
static accessor to avoid casting ;)
Definition: kateapp.cpp:114
KateSessionManager::sessionRenamed
void sessionRenamed(int sessionId)
Emitted once a session has been renamed.
KateSessionManager::cloneSession
int cloneSession(int sessionId, const TQString &sessionName=TQString::null, bool activate=true, bool deleteCurr=false)
Create a new session and activate it if required.
Definition: katesession.cpp:646
KateSessionManager::sessionActivated
void sessionActivated(int newSessionId, int oldSessionId)
Emitted once a session has been activated.
KateSession::getSessionFilename
const TQString & getSessionFilename() const
Definition: katesession.h:97
KateSessionManager::sessionsSwapped
void sessionsSwapped(int sessionIdMin, int sessionIdMax)
Emitted once the position of the two sessions have been swapped.
KateSessionManager::sessionCreated
void sessionCreated(int sessionId)
Emitted once a session has been created.
KateSession::isStillVolatile
bool isStillVolatile() const
Definition: katesession.cpp:126
KateSessionManager::sessionDeleted
void sessionDeleted(int sessionId)
Emitted once a session has been deleted.

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