diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -118,6 +118,9 @@ void SocExplorerMainWindow::makeConnecti connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this,SLOT(showSessionManager(bool))); connect(this->p_SessionManagerDialog, SIGNAL(switchSession(QString)),this,SLOT(setActiveSession(QString))); + connect(this->p_SessionManagerDialog, SIGNAL(sessionRenamed(QString,QString)),this,SLOT(renameSession(QString,QString))); + connect(this->p_SessionManagerDialog, SIGNAL(sessionAdded(QString)),this,SLOT(addSession(QString))); + connect(this->p_SessionManagerDialog, SIGNAL(sessionRemoved(QString)),this,SLOT(removeSession(QString))); connect(this->sessionsActions,SIGNAL(triggered(QAction*)),this,SLOT(setActiveSession(QAction*))); this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString))); @@ -193,13 +196,7 @@ void SocExplorerMainWindow::loadSessions } foreach (stext, p_Sessions) { - sact = new QAction(stext,this); - sact->setCheckable(true); - sact->setData(stext); - if(p_currentSession==stext) - sact->setChecked(true); - sessionsActions->addAction(sact); - SessionsMenu->addAction(sact); + addSession(stext); } } @@ -316,14 +313,45 @@ void SocExplorerMainWindow::showSessionM this->p_SessionManagerDialog->show(); } -//TODO handle rename -void SocExplorerMainWindow::sessionListChanged() +void SocExplorerMainWindow::renameSession(const QString &oldName, const QString &newName) +{ + for(int i=0;iactions().count();i++) + { + if(Q_UNLIKELY(sessionsActions->actions().at(i)->text()==oldName)) + { + sessionsActions->actions().at(i)->setText(newName); + } + } +} + +void SocExplorerMainWindow::addSession(const QString &newSession) { + QAction* sact = new QAction(newSession,this); + sact->setCheckable(true); + sact->setData(newSession); + if(Q_UNLIKELY(p_currentSession==newSession)) + sact->setChecked(true); + sessionsActions->addAction(sact); + SessionsMenu->addAction(sact); +} +void SocExplorerMainWindow::removeSession(const QString &session) +{ + QAction* sact; + foreach (sact, sessionsActions->actions()) + { + if(Q_UNLIKELY(sact->text()==session)) + { + sessionsActions->removeAction(sact); + SessionsMenu->removeAction(sact); + delete sact; + } + } } + void SocExplorerMainWindow::closeEvent(QCloseEvent *event) { saveCurrentSession(); diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -71,7 +71,9 @@ public slots: void setActiveSession(const QString & session); void setActiveSession(QAction* session); void showSessionManager(bool); - void sessionListChanged(); + void renameSession(const QString& oldName,const QString& newName); + void addSession(const QString& newSession); + void removeSession(const QString& session); signals: void translateSig(); void registerObject(QObject* object,const QString& instanceName); diff --git a/src/sessionmanagerdialog.cpp b/src/sessionmanagerdialog.cpp --- a/src/sessionmanagerdialog.cpp +++ b/src/sessionmanagerdialog.cpp @@ -100,6 +100,7 @@ void SessionManagerDialog::newSession(QS { this->ui->listWidget->addItem(session); updateSessionList(); + emit sessionAdded(session); } } @@ -127,7 +128,8 @@ void SessionManagerDialog::renameSession if (ok && !text.isEmpty()) { item->setText(text); - SocExplorerSettings::renameSession(text,OldText); + SocExplorerSettings::renameSession(OldText,text); + emit sessionRenamed(OldText,text); updateSessionList(); emit sessionListChanged(); } @@ -142,6 +144,7 @@ void SessionManagerDialog::deleteSession { this->ui->listWidget->removeItemWidget(item); SocExplorerSettings::deleteSession(item->text()); + emit sessionRemoved(item->text()); delete item; updateSessionList(); } diff --git a/src/sessionmanagerdialog.h b/src/sessionmanagerdialog.h --- a/src/sessionmanagerdialog.h +++ b/src/sessionmanagerdialog.h @@ -49,7 +49,9 @@ private slots: signals: void switchSession(QString session); void sessionListChanged(); - + void sessionRenamed(const QString& oldName,const QString& newName); + void sessionRemoved(const QString& session); + void sessionAdded(const QString& newSession); private: void updateSessionList(); Ui::SessionManagerDialog *ui;