diff options
Diffstat (limited to 'kate/app')
-rw-r--r-- | kate/app/katemainwindow.cpp | 99 | ||||
-rw-r--r-- | kate/app/katemainwindow.h | 50 | ||||
-rw-r--r-- | kate/app/katesession.cpp | 2 | ||||
-rw-r--r-- | kate/app/katesession.h | 5 | ||||
-rw-r--r-- | kate/app/katesessionpanel.cpp | 33 | ||||
-rw-r--r-- | kate/app/katesessionpanel.h | 14 |
6 files changed, 155 insertions, 48 deletions
diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index 4493eae12..1a021beb9 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -219,7 +219,7 @@ void KateMainWindow::setupMainWindow () connect(fileselector->dirOperator(),TQT_SIGNAL(fileSelected(const KFileItem*)),this,TQT_SLOT(fileSelected(const KFileItem*))); KateMDI::ToolView *st = createToolView("kate_sessionpanel", KMultiTabBar::Left, SmallIcon("view_choose"), i18n("Sessions")); - sessionpanel = new KateSessionPanel( this, m_viewManager, st, "sessionpanel"); + m_sessionpanel = new KateSessionPanel( this, m_viewManager, st, "sessionpanel"); // ONLY ALLOW SHELL ACCESS IF ALLOWED ;) if (KateApp::self()->authorize("shell_access")) @@ -305,17 +305,30 @@ void KateMainWindow::setupActions() slotWindowActivated (); -// FIXME to fix and enable again // session actions -/* new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); - new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); - new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); - new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); - new TDEAction(i18n("&Manage..."), "view_choose", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionManage()), actionCollection(), "sessions_manage"); - - // quick open menu ;) - new OldKateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list"); -*/ + new TDEAction(i18n("&New"), "list-add", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotNewSession()), actionCollection(), "session_new"); + new TDEAction(i18n("&Save"), "document-save", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSaveSession()), actionCollection(), "session_save"); + new TDEAction(i18n("Save &As..."), "document-save-as", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSaveSessionAs()), actionCollection(), "session_save_as"); + new TDEAction(i18n("&Rename"), "edit_user", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotRenameSession()), actionCollection(), "session_rename"); + new TDEAction(i18n("&Delete"), "edit-delete", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotDeleteSession()), actionCollection(), "session_delete"); + new TDEAction(i18n("Re&load"), "reload", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotReloadSession()), actionCollection(), "session_reload"); + new TDEAction(i18n("Acti&vate"), "forward", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotActivateSession()), actionCollection(), "session_activate"); + new TDEToggleAction(i18n("Toggle read &only"), "encrypted", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionToggleReadOnly()), actionCollection(), "session_toggle_read_only"); + new TDEAction(i18n("Move &Up"), "go-up", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionMoveUp()), actionCollection(), "session_move_up"); + new TDEAction(i18n("Move Do&wn"), "go-down", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionMoveDown()), actionCollection(), "session_move_down"); + new KateSessionListActionMenu(this, i18n("Sele&ct session"), actionCollection(), "session_list"); + + connect(m_sessionpanel, TQT_SIGNAL(selectionChanged()), TQT_TQOBJECT(this), TQT_SLOT(slotSelectionChanged())); } KateTabWidget *KateMainWindow::tabWidget () @@ -857,10 +870,68 @@ void KateMainWindow::readProperties(TDEConfig *config) config->setGroup(grp); } -void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) +//------------------------------------------- +void KateMainWindow::slotSelectionChanged() +{ + TDEActionCollection *mwac = actionCollection(); // Main Window Action Collection + TDEActionPtrList actionList = m_sessionpanel->m_actionCollection->actions(); + TDEActionPtrList::ConstIterator spa_it; + for (spa_it = actionList.begin(); spa_it != actionList.end(); ++spa_it) + { + TDEAction *a = mwac->action((*spa_it)->name()); + TDEToggleAction *ta = dynamic_cast<TDEToggleAction*>(a); + if (ta) + { + ta->setChecked((dynamic_cast<TDEToggleAction*>(*spa_it))->isChecked()); + } + if (a) + { + a->setEnabled((*spa_it)->isEnabled()); + } + } +} + +//------------------------------------------- +void KateMainWindow::activateSession(int sessionId) +{ + if (sessionId < 0 || sessionId == KateApp::self()->sessionManager()->getActiveSessionId()) + { + return; + } + + // Select the required session in the session panel's listview + TQListViewItem *item = m_sessionpanel->m_listview->firstChild(); + int idx = 0; + while (item && idx < sessionId) + { + item = item->nextSibling(); + ++idx; + } + if (idx == sessionId && item) + { + // Required session item found, switch session with consistent behavior + m_sessionpanel->m_listview->setSelected(item, true); + m_sessionpanel->slotActivateSession(); + } +} + +//------------------------------------------- +KateSessionListActionMenu::KateSessionListActionMenu(KateMainWindow *mw, const TQString &text, TQObject *parent, const char *name) + : TDEActionMenu(text, parent, name), m_mainWindow(mw) { -// FIXME do we still need this code here? -// KateDocManager::self()->saveDocumentList (sessionConfig); + connect(popupMenu(), TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(slotAboutToShow())); +} + +//------------------------------------------- +void KateSessionListActionMenu::slotAboutToShow() +{ + popupMenu()->clear(); + + TQPtrList<KateSession> &sessions = KateApp::self()->sessionManager()->getSessionsList(); + for (int idx = 0; idx < (int)sessions.count(); ++idx) + { + popupMenu()->insertItem(sessions[idx]->getSessionName(), m_mainWindow, TQT_SLOT(activateSession(int)), 0, idx); + } } // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katemainwindow.h b/kate/app/katemainwindow.h index 15b7f35c6..aa2a6cee7 100644 --- a/kate/app/katemainwindow.h +++ b/kate/app/katemainwindow.h @@ -68,7 +68,6 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa /** * Accessor methodes for interface and child objects */ - public: Kate::MainWindow *mainWindow () { return m_mainWindow; } Kate::ToolViewManager *toolViewManager () { return m_toolViewManager; } @@ -79,7 +78,6 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa /** * various methodes to get some little info out of this */ - public: /** Returns the URL of the current document. * anders: I add this for use from the file selector. */ KURL activeDocumentUrl(); @@ -101,14 +99,27 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa */ KateTabWidget *tabWidget (); - public: void readProperties(TDEConfig *config); void saveProperties(TDEConfig *config); - void saveGlobalProperties( TDEConfig* sessionConfig ); - public: bool queryClose_internal(); + void openURL (const TQString &name=0L); + + public slots: + /** + * update "Sessions" menu status when selection in session panel has changed + */ + void slotSelectionChanged(); + + /** + * activate the specified session. When there is the need to activate a session + * from the outside (for example from DCOP), using this method assures that + * the session activation is consistent with the behavior of the session panel + * @param sessionId the id of the session to activate + */ + void activateSession(int sessionId); + private: void setupMainWindow(); void setupActions(); @@ -127,11 +138,11 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa void dragEnterEvent( TQDragEnterEvent * ); void dropEvent( TQDropEvent * ); + private slots: /** * slots used for actions in the menus/toolbars * or internal signal connections */ - private slots: void newWindow (); void slotConfigure(); @@ -163,18 +174,12 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa void pluginHelp(); void slotFullScreen(bool); - public: - void openURL (const TQString &name=0L); - - private slots: void updateGrepDir (bool visible); - + void slotDocumentCloseAll(); + protected: bool event( TQEvent * ); - private slots: - void slotDocumentCloseAll(); - private: static uint uniqueID; uint myID; @@ -198,7 +203,7 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa KateFileList *filelist; KateFileSelector *fileselector; - KateSessionPanel *sessionpanel; + KateSessionPanel *m_sessionpanel; TDEActionMenu* documentOpenWith; @@ -214,6 +219,21 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa KateTabWidget *m_tabWidget; }; +class KateSessionListActionMenu : public TDEActionMenu +{ + Q_OBJECT + + public: + KateSessionListActionMenu(KateMainWindow *mw, const TQString &text, TQObject *parent = NULL, const char *name = NULL); + ~KateSessionListActionMenu() {} + + public slots: + void slotAboutToShow(); + + protected: + KateMainWindow *m_mainWindow; +}; + #endif // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 1f7817f01..4b973214b 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -852,7 +852,7 @@ KateSessionChooser::KateSessionChooser(TQWidget *parent) connect (m_listview, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged())); connect (m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotUser2())); - TQPtrList<KateSession>& sessions = KateSessionManager::self()->getSessionsList(); + TQPtrList<KateSession> &sessions = KateSessionManager::self()->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) { new KateSessionChooserItem(m_listview, sessions[idx]->getSessionName(), diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 50db624b6..665ac867b 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -245,6 +245,11 @@ class KateSessionManager : public TQObject const TQString& getBaseDir() const { return m_baseDir; } /** + * @return the number of existing sessions + */ + int getSessionCount() const { return m_sessions.count(); } + + /** * @return the active session id */ int getActiveSessionId() const { return m_activeSessionId; } diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 25980dc40..0cf7e235b 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -126,9 +126,8 @@ void KateSessionPanelToolBarParent::resizeEvent (TQResizeEvent*) //------------------------------------------- KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *viewManager, TQWidget *parent, const char *name) - : TQVBox(parent, name), m_mainWin(mainWindow), m_viewManager(viewManager), - m_sessionManager(KateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)), - m_columnName(-1), m_columnPixmap(-1) + : TQVBox(parent, name), m_sessionManager(KateSessionManager::self()), + m_actionCollection(new TDEActionCollection(this)), m_columnName(-1), m_columnPixmap(-1) { // Toolbar setup_toolbar(); @@ -171,7 +170,7 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * this, TQT_SLOT(slotLVSessionRenamed(TQListViewItem*))); TQPtrList<KateSession>& sessions = m_sessionManager->getSessionsList(); - for (int idx = sessions.count()-1; idx >= 0; --idx) + for (int idx = sessions.count() - 1; idx >= 0; --idx) { new KateSessionPanelItem(m_listview, sessions[idx]->getSessionName(), idx); if (idx == m_sessionManager->getActiveSessionId()) @@ -444,14 +443,17 @@ void KateSessionPanel::slotActivateSession() void KateSessionPanel::slotSessionToggleReadOnly() { KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem()); - if (!sessionItem) + const KateSession *ks(NULL); + if (sessionItem) + { + ks = m_sessionManager->getSessionFromId(sessionItem->getSessionId()); + } + if (!sessionItem || !ks) { return; } - - m_sessionManager->setSessionReadOnlyStatus(sessionItem->getSessionId(), - (dynamic_cast<TDEToggleAction*>( - m_actionCollection->action("session_toggle_read_only")))->isChecked()); + + m_sessionManager->setSessionReadOnlyStatus(sessionItem->getSessionId(), !ks->isReadOnly()); slotSelectionChanged(); // Update the toolbar button status } @@ -549,13 +551,16 @@ void KateSessionPanel::slotSelectionChanged() readOnlyAction->setEnabled(true); readOnlyAction->setChecked(ks->isReadOnly()); } + int sessId = sessionItem->getSessionId(); + int activeSessId = m_sessionManager->getActiveSessionId(); m_actionCollection->action("session_save_as")->setEnabled(true); - m_actionCollection->action("session_reload")->setEnabled( - sessionItem->getSessionId() == m_sessionManager->getActiveSessionId()); - m_actionCollection->action("session_activate")->setEnabled(true); - m_actionCollection->action("session_move_up")->setEnabled(true); - m_actionCollection->action("session_move_down")->setEnabled(true); + m_actionCollection->action("session_reload")->setEnabled(sessId == activeSessId); + m_actionCollection->action("session_activate")->setEnabled(sessId != activeSessId); + m_actionCollection->action("session_move_up")->setEnabled(sessId > 0); + m_actionCollection->action("session_move_down")->setEnabled(sessId < (m_sessionManager->getSessionCount() - 1)); } + + emit selectionChanged(); } //------------------------------------------- diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 4b4f47236..acaec56cd 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -111,13 +111,21 @@ class KateSessionPanel : public TQVBox { Q_OBJECT + friend class KateMainWindow; + public: KateSessionPanel(KateMainWindow *mainWindow=0, KateViewManager *viewManager=0, TQWidget *parent=0, const char *name=0); ~KateSessionPanel() {} - + signals: + /** + * Emitted when the session selection in the panel has changed + */ + void selectionChanged(); + + public slots: void slotNewSession(); void slotSaveSession(); @@ -131,7 +139,7 @@ class KateSessionPanel : public TQVBox void slotSessionMoveDown(); void slotItemExecuted(TQListViewItem *item); - void slotSelectionChanged(); + void slotSelectionChanged(); /** @emit selectionChanged */ void slotSessionActivated(int newSessionId, int oldSessionId); void slotSessionCreated(int sessionId); void slotSessionDeleted(int sessionId); @@ -153,8 +161,6 @@ class KateSessionPanel : public TQVBox */ int handleSessionSwitch(); - KateMainWindow *m_mainWin; - KateViewManager *m_viewManager; KateSessionManager *m_sessionManager; TDEActionCollection *m_actionCollection; TDEToolBar *m_toolbar; |