diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 83d4db02f3..0844a9a5af 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -1,176 +1,174 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kdevplatform\") add_subdirectory(tests) set(KDevPlatformShell_LIB_SRCS workingsetcontroller.cpp workingsets/workingset.cpp workingsets/workingsetfilelabel.cpp workingsets/workingsettoolbutton.cpp workingsets/workingsettooltipwidget.cpp workingsets/workingsetwidget.cpp workingsets/closedworkingsetswidget.cpp workingsets/workingsethelpers.cpp assistantpopup.cpp mainwindow.cpp mainwindow_p.cpp plugincontroller.cpp ktexteditorpluginintegration.cpp shellextension.cpp core.cpp uicontroller.cpp projectcontroller.cpp project.cpp partcontroller.cpp #document.cpp partdocument.cpp textdocument.cpp documentcontroller.cpp languagecontroller.cpp statusbar.cpp runcontroller.cpp sessioncontroller.cpp session.cpp sessionlock.cpp sessionchooserdialog.cpp savedialog.cpp - sessiondialog.cpp sourceformattercontroller.cpp completionsettings.cpp openprojectpage.cpp openprojectdialog.cpp projectinfopage.cpp selectioncontroller.cpp documentationcontroller.cpp debugcontroller.cpp launchconfiguration.cpp launchconfigurationdialog.cpp loadedpluginsdialog.cpp testcontroller.cpp projectsourcepage.cpp debug.cpp configdialog.cpp editorconfigpage.cpp environmentconfigurebutton.cpp checkerstatus.cpp problem.cpp problemmodelset.cpp problemmodel.cpp problemstore.cpp watcheddocumentset.cpp filteredproblemstore.cpp progresswidget/progressmanager.cpp progresswidget/statusbarprogresswidget.cpp progresswidget/overlaywidget.cpp progresswidget/progressdialog.cpp areadisplay.cpp settings/uipreferences.cpp settings/pluginpreferences.cpp settings/sourceformattersettings.cpp settings/editstyledialog.cpp settings/projectpreferences.cpp settings/environmentwidget.cpp settings/environmentgroupmodel.cpp settings/environmentpreferences.cpp settings/languagepreferences.cpp settings/bgpreferences.cpp settings/templateconfig.cpp settings/templatepage.cpp ) kconfig_add_kcfg_files(KDevPlatformShell_LIB_SRCS settings/uiconfig.kcfgc settings/projectconfig.kcfgc settings/languageconfig.kcfgc settings/bgconfig.kcfgc ) ki18n_wrap_ui(KDevPlatformShell_LIB_SRCS - sessiondialog.ui projectinfopage.ui launchconfigurationdialog.ui projectsourcepage.ui settings/uiconfig.ui settings/editstyledialog.ui settings/sourceformattersettings.ui settings/projectpreferences.ui settings/environmentwidget.ui settings/languagepreferences.ui settings/bgpreferences.ui settings/templateconfig.ui settings/templatepage.ui ) qt5_add_resources(KDevPlatformShell_LIB_SRCS kdevplatformshell.qrc) kdevplatform_add_library(KDevPlatformShell SOURCES ${KDevPlatformShell_LIB_SRCS}) target_link_libraries(KDevPlatformShell LINK_PUBLIC KF5::XmlGui KDev::Sublime KDev::OutputView KDev::Interfaces LINK_PRIVATE Qt5::Quick Qt5::QuickWidgets KF5::GuiAddons KF5::IconThemes KF5::KIOFileWidgets KF5::KIOWidgets KF5::Parts KF5::Notifications KF5::NotifyConfig KF5::TextEditor KF5::ThreadWeaver KF5::JobWidgets KF5::ItemViews KF5::WindowSystem KF5::KCMUtils #for KPluginSelector, not sure why it is in kcmutils KF5::NewStuff # template config page KF5::Archive # template config page KDev::Debugger KDev::Project KDev::Vcs KDev::Language KDev::Util KDev::Documentation ) install(FILES mainwindow.h plugincontroller.h shellextension.h core.h uicontroller.h projectcontroller.h project.h partcontroller.h partdocument.h textdocument.h documentcontroller.h languagecontroller.h session.h sessioncontroller.h sessionlock.h sourceformattercontroller.h selectioncontroller.h runcontroller.h launchconfiguration.h environmentconfigurebutton.h checkerstatus.h problem.h problemmodel.h problemmodelset.h problemconstants.h filteredproblemstore.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kdevplatform/shell COMPONENT Devel ) install( FILES AssistantButton.qml assistantpopup.qml DESTINATION ${KDE_INSTALL_DATADIR}/kdevelop ) diff --git a/shell/mainwindow_actions.cpp b/shell/mainwindow_actions.cpp index 005104c9a0..c4315f77ff 100644 --- a/shell/mainwindow_actions.cpp +++ b/shell/mainwindow_actions.cpp @@ -1,247 +1,246 @@ /* This file is part of the KDevelop project Copyright 2002 Falk Brettschneider Copyright 2003 John Firebaugh Copyright 2006 Adam Treat Copyright 2006, 2007 Alexander Dymo This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include "core.h" #include "documentcontroller.h" #include "mainwindow_p.h" -#include "sessiondialog.h" #include "uicontroller.h" #include "mainwindow.h" #include "loadedpluginsdialog.h" #include #include namespace KDevelop { // merge the gotoNext and gotoPrev code, to prevent copy/paste errors static void gotoPrevNextWindow(bool next) { UiController* ui = Core::self()->uiControllerInternal(); if( !ui->activeSublimeWindow() ) return; Sublime::Area* activeArea = ui->activeArea(); if (!activeArea) return; Sublime::View* activeView = ui->activeSublimeWindow()->activeView(); Sublime::AreaIndex* index = activeArea->indexOf(activeView); if (!index) return; int viewIndex = index->views().indexOf(activeView); viewIndex = next ? viewIndex + 1 : viewIndex -1; if (viewIndex < 0) viewIndex = index->views().count() - 1; else if (viewIndex >= index->views().count()) viewIndex = 0; if (viewIndex >= 0 && viewIndex < index->views().count()) ui->activeSublimeWindow()->activateView(index->views().at(viewIndex)); } void MainWindowPrivate::gotoNextWindow() { gotoPrevNextWindow(true); } void MainWindowPrivate::gotoPreviousWindow() { gotoPrevNextWindow(false); } void MainWindowPrivate::selectPrevItem() { auto actionListener = qobject_cast( Core::self()->uiControllerInternal()->activeToolViewActionListener()); if (actionListener) { actionListener->selectPreviousItem(); } } void MainWindowPrivate::selectNextItem() { auto actionListener = qobject_cast( Core::self()->uiControllerInternal()->activeToolViewActionListener()); if (actionListener) { actionListener->selectNextItem(); } } void MainWindowPrivate::newToolbarConfig() { m_mainWindow->applyMainWindowSettings( KConfigGroup(KSharedConfig::openConfig(), "MainWindow") ); } void MainWindowPrivate::settingsDialog() { Core::self()->uiControllerInternal()->showSettingsDialog(); } void MainWindowPrivate::newWindow() { Core::self()->uiController()->switchToArea(m_mainWindow->area()->objectName(), UiController::NewWindow); } void MainWindowPrivate::splitHorizontal() { split(Qt::Vertical); } void MainWindowPrivate::splitVertical() { split(Qt::Horizontal); } void MainWindowPrivate::split(Qt::Orientation orientation) { if (!m_mainWindow->area()) return; Sublime::View *view = m_mainWindow->activeView(); if (!view) return; Sublime::View *newView = view->document()->createView(); m_mainWindow->area()->addView(newView, view, orientation); m_mainWindow->activateView(newView); } static void gotoPrevNextSplit(bool next) { UiController* ui = Core::self()->uiControllerInternal(); if( !ui->activeSublimeWindow() ) return; Sublime::Area* area = ui->activeSublimeWindow()->area(); if (!area) return; QList topViews = ui->activeSublimeWindow()->getTopViews(); Sublime::View *activeView = ui->activeSublimeWindow()->activeView(); if (!activeView) return; int viewIndex = topViews.indexOf(activeView); viewIndex = next ? viewIndex + 1 : viewIndex -1; if (viewIndex < 0) viewIndex = topViews.count() - 1; else if (viewIndex >= topViews.count()) viewIndex = 0; if (viewIndex >= 0 && viewIndex < topViews.count()) ui->activeSublimeWindow()->activateView(topViews.at(viewIndex)); } void MainWindowPrivate::gotoNextSplit() { gotoPrevNextSplit(true); } void MainWindowPrivate::gotoPreviousSplit() { gotoPrevNextSplit(false); } void MainWindowPrivate::toggleFullScreen(bool fullScreen) { KToggleFullScreenAction::setFullScreen( m_mainWindow, fullScreen ); } void MainWindowPrivate::fileNew() { Core::self()->documentControllerInternal()->openDocument(DocumentController::nextEmptyDocumentUrl()); } void MainWindowPrivate::viewAddNewToolView() { Core::self()->uiControllerInternal()->selectNewToolViewToAdd(m_mainWindow); } void MainWindowPrivate::quitAll() { QApplication::closeAllWindows(); } void MainWindowPrivate::configureNotifications() { KNotifyConfigWidget::configure(m_mainWindow); } void MainWindowPrivate::showAboutPlatform() { KAboutApplicationDialog dlg(Core::self()->aboutData(), m_mainWindow ); dlg.exec(); } void MainWindowPrivate::showLoadedPlugins() { LoadedPluginsDialog dlg(m_mainWindow); dlg.exec(); } void MainWindowPrivate::contextMenuFileNew() { m_mainWindow->activateView(m_tabView); fileNew(); } void MainWindowPrivate::contextMenuSplitHorizontal() { m_mainWindow->activateView(m_tabView); splitHorizontal(); } void MainWindowPrivate::contextMenuSplitVertical() { m_mainWindow->activateView(m_tabView); splitVertical(); } void MainWindowPrivate::reloadAll() { foreach ( IDocument* doc, Core::self()->documentController()->openDocuments() ) { doc->reload(); } } } diff --git a/shell/sessioncontroller.cpp b/shell/sessioncontroller.cpp index adf8314d5d..2c5d6eac5d 100644 --- a/shell/sessioncontroller.cpp +++ b/shell/sessioncontroller.cpp @@ -1,678 +1,664 @@ /* This file is part of KDevelop Copyright 2008 Andreas Pakulat Copyright 2010 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sessioncontroller.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "session.h" #include "core.h" #include "uicontroller.h" -#include "sessiondialog.h" #include "shellextension.h" #include "sessionlock.h" #include "sessionchooserdialog.h" #include "debug.h" #include #include #include #include #include namespace KDevelop { namespace { int argc = 0; char** argv = 0; }; void SessionController::setArguments(int _argc, char** _argv) { argc = _argc; argv = _argv; } static QStringList standardArguments() { QStringList ret; for(int a = 0; a < argc; ++a) { QString arg = QString::fromLocal8Bit(argv[a]); if(arg.startsWith(QLatin1String("-graphicssystem")) || arg.startsWith(QLatin1String("-style"))) { ret << '-' + arg; if(a+1 < argc) ret << QString::fromLocal8Bit(argv[a+1]); } } return ret; } class SessionControllerPrivate : public QObject { Q_OBJECT public: SessionControllerPrivate( SessionController* s ) : q(s) , activeSession(0) , grp(0) { } ~SessionControllerPrivate() override { } Session* findSessionForName( const QString& name ) const { foreach( Session* s, sessionActions.keys() ) { if( s->name() == name ) return s; } return 0; } Session* findSessionForId(QString idString) { QUuid id(idString); foreach( Session* s, sessionActions.keys() ) { if( s->id() == id) return s; } return 0; } void newSession() { qsrand(QDateTime::currentDateTimeUtc().toTime_t()); Session* session = new Session( QUuid::createUuid().toString() ); KProcess::startDetached(ShellExtension::getInstance()->binaryPath(), QStringList() << QStringLiteral("-s") << session->id().toString() << standardArguments()); delete session; #if 0 //Terminate this instance of kdevelop if the user agrees foreach(Sublime::MainWindow* window, Core::self()->uiController()->controller()->mainWindows()) window->close(); #endif } - void configureSessions() - { - SessionDialog dlg(ICore::self()->uiController()-> activeMainWindow()); - dlg.exec(); - } - void deleteCurrentSession() { int choice = KMessageBox::warningContinueCancel(Core::self()->uiController()->activeMainWindow(), i18n("The current session and all contained settings will be deleted. The projects will stay unaffected. Do you really want to continue?")); if(choice == KMessageBox::Continue) { q->deleteSessionFromDisk(sessionLock); q->emitQuitSession(); } } void renameSession() { bool ok; auto newSessionName = QInputDialog::getText(Core::self()->uiController()->activeMainWindow(), i18n("Rename Session"), i18n("New Session Name:"), QLineEdit::Normal, q->activeSession()->name(), &ok); if (ok) { static_cast(q->activeSession())->setName(newSessionName); } q->updateXmlGuiActionList(); // resort } bool loadSessionExternally( Session* s ) { Q_ASSERT( s ); KProcess::startDetached(ShellExtension::getInstance()->binaryPath(), QStringList() << QStringLiteral("-s") << s->id().toString() << standardArguments()); return true; } TryLockSessionResult activateSession( Session* s ) { Q_ASSERT( s ); activeSession = s; TryLockSessionResult result = SessionController::tryLockSession( s->id().toString()); if( !result.lock ) { activeSession = 0; return result; } Q_ASSERT(s->id().toString() == result.lock->id()); sessionLock = result.lock; KConfigGroup grp = KSharedConfig::openConfig()->group( SessionController::cfgSessionGroup() ); grp.writeEntry( SessionController::cfgActiveSessionEntry(), s->id().toString() ); grp.sync(); if (Core::self()->setupFlags() & Core::NoUi) return result; QHash::iterator it = sessionActions.find(s); Q_ASSERT( it != sessionActions.end() ); (*it)->setCheckable(true); (*it)->setChecked(true); for(it = sessionActions.begin(); it != sessionActions.end(); ++it) { if(it.key() != s) (*it)->setCheckable(false); } return result; } void loadSessionFromAction(QAction* action) { auto session = action->data().value(); loadSessionExternally(session); } void addSession( Session* s ) { if (Core::self()->setupFlags() & Core::NoUi) { sessionActions[s] = 0; return; } QAction* a = new QAction( grp ); a->setText( s->description() ); a->setCheckable( false ); a->setData(QVariant::fromValue(s)); sessionActions[s] = a; q->actionCollection()->addAction( "session_"+s->id().toString(), a ); connect( s, &Session::sessionUpdated, this, &SessionControllerPrivate::sessionUpdated ); sessionUpdated( s ); } SessionController* q; QHash sessionActions; ISession* activeSession; QActionGroup* grp; ISessionLock::Ptr sessionLock; static QString sessionBaseDirectory() { return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +'/'+ qApp->applicationName() + "/sessions/"; } QString ownSessionDirectory() const { Q_ASSERT(activeSession); return q->sessionDirectory( activeSession->id().toString() ); } private slots: void sessionUpdated( KDevelop::ISession* s ) { sessionActions[static_cast( s )]->setText( KStringHandler::rsqueeze(s->description()) ); } }; SessionController::SessionController( QObject *parent ) : QObject( parent ), d(new SessionControllerPrivate(this)) { setObjectName(QStringLiteral("SessionController")); setComponentName(QStringLiteral("kdevsession"), QStringLiteral("KDevSession")); setXMLFile(QStringLiteral("kdevsessionui.rc")); QDBusConnection::sessionBus().registerObject( QStringLiteral("/org/kdevelop/SessionController"), this, QDBusConnection::ExportScriptableSlots ); if (Core::self()->setupFlags() & Core::NoUi) return; QAction* action = actionCollection()->addAction( QStringLiteral("new_session"), this, SLOT(newSession()) ); action->setText( i18nc("@action:inmenu", "Start New Session") ); action->setToolTip( i18nc("@info:tooltip", "Start a new KDevelop instance with an empty session") ); action->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); action = actionCollection()->addAction( QStringLiteral("rename_session"), this, SLOT(renameSession()) ); action->setText( i18n("Rename Current Session...") ); action->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); action = actionCollection()->addAction( QStringLiteral("delete_session"), this, SLOT(deleteCurrentSession()) ); action->setText( i18n("Delete Current Session...") ); action->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"))); action = actionCollection()->addAction( QStringLiteral("quit"), this, SIGNAL(quitSession()) ); action->setText( i18n("Quit") ); action->setMenuRole( QAction::NoRole ); // OSX: prevent QT from hiding this due to conflict with 'Quit KDevelop...' actionCollection()->setDefaultShortcut( action, Qt::CTRL | Qt::Key_Q ); action->setIcon(QIcon::fromTheme(QStringLiteral("application-exit"))); - #if 0 - action = actionCollection()->addAction( "configure_sessions", this, SLOT(configureSessions()) ); - action->setText( i18n("Configure Sessions...") ); - action->setToolTip( i18n("Create/Delete/Activate Sessions") ); - action->setWhatsThis( i18n( "Shows a dialog to Create/Delete Sessions and set a new active session." ) ); - #endif - d->grp = new QActionGroup( this ); connect( d->grp, &QActionGroup::triggered, this, [&] (QAction* a) { d->loadSessionFromAction(a); } ); } SessionController::~SessionController() { delete d; } void SessionController::startNewSession() { d->newSession(); } void SessionController::cleanup() { if (d->activeSession) { Q_ASSERT(d->activeSession->id().toString() == d->sessionLock->id()); if (d->activeSession->isTemporary()) { deleteSessionFromDisk(d->sessionLock); } d->activeSession = 0; } d->sessionLock.clear(); qDeleteAll(d->sessionActions); d->sessionActions.clear(); } void SessionController::initialize( const QString& session ) { QDir sessiondir( SessionControllerPrivate::sessionBaseDirectory() ); foreach( const QString& s, sessiondir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot ) ) { QUuid id( s ); if( id.isNull() ) continue; // Only create sessions for directories that represent proper uuid's Session* ses = new Session( id.toString(), this ); //Delete sessions that have no name and are empty if( ses->containedProjects().isEmpty() && ses->name().isEmpty() && (session.isEmpty() || (ses->id().toString() != session && ses->name() != session)) ) { TryLockSessionResult result = tryLockSession(s); if (result.lock) { deleteSessionFromDisk(result.lock); } delete ses; } else { d->addSession( ses ); } } loadDefaultSession( session ); updateXmlGuiActionList(); } ISession* SessionController::activeSession() const { return d->activeSession; } ISessionLock::Ptr SessionController::activeSessionLock() const { return d->sessionLock; } void SessionController::loadSession( const QString& nameOrId ) { d->loadSessionExternally( session( nameOrId ) ); } QList SessionController::sessionNames() const { QStringList l; foreach( const Session* s, d->sessionActions.keys() ) { l << s->name(); } return l; } QList< const KDevelop::Session* > SessionController::sessions() const { QList< const KDevelop::Session* > ret; foreach( const Session* s, d->sessionActions.keys() ) { ret << s; } return ret; } Session* SessionController::createSession( const QString& name ) { Session* s; if(name.startsWith('{')) { s = new Session( QUuid(name).toString() ); }else{ qsrand(QDateTime::currentDateTimeUtc().toTime_t()); s = new Session( QUuid::createUuid().toString() ); s->setName( name ); } d->addSession( s ); updateXmlGuiActionList(); return s; } void SessionController::deleteSession( const ISessionLock::Ptr& lock ) { Session* s = session(lock->id()); QHash::iterator it = d->sessionActions.find(s); Q_ASSERT( it != d->sessionActions.end() ); unplugActionList( QStringLiteral("available_sessions") ); actionCollection()->removeAction(*it); if (d->grp) { // happens in unit tests d->grp->removeAction(*it); plugActionList( QStringLiteral("available_sessions"), d->grp->actions() ); } if (s == d->activeSession) { d->activeSession = nullptr; } deleteSessionFromDisk(lock); emit sessionDeleted( s->id().toString() ); d->sessionActions.remove(s); delete s; } void SessionController::deleteSessionFromDisk( const ISessionLock::Ptr& lock ) { qCDebug(SHELL) << "Deleting session:" << lock->id(); static_cast(lock.data())->removeFromDisk(); ItemRepositoryRegistry::deleteRepositoryFromDisk( lock ); } void SessionController::loadDefaultSession( const QString& session ) { QString load = session; if (load.isEmpty()) { KConfigGroup grp = KSharedConfig::openConfig()->group( cfgSessionGroup() ); load = grp.readEntry( cfgActiveSessionEntry(), "default" ); } // Iteratively try to load the session, asking user what to do in case of failure // If showForceOpenDialog() returns empty string, stop trying Session* s = 0; do { s = this->session( load ); if( !s ) { s = createSession( load ); } TryLockSessionResult result = d->activateSession( s ); if( result.lock ) { Q_ASSERT(d->activeSession == s); Q_ASSERT(d->sessionLock = result.lock); break; } load = handleLockedSession( s->name(), s->id().toString(), result.runInfo ); } while( !load.isEmpty() ); } Session* SessionController::session( const QString& nameOrId ) const { Session* ret = d->findSessionForName( nameOrId ); if(ret) return ret; return d->findSessionForId( nameOrId ); } QString SessionController::cloneSession( const QString& nameOrid ) { Session* origSession = session( nameOrid ); qsrand(QDateTime::currentDateTimeUtc().toTime_t()); QUuid id = QUuid::createUuid(); auto copyJob = KIO::copy(QUrl::fromLocalFile(sessionDirectory(origSession->id().toString())), QUrl::fromLocalFile(sessionDirectory( id.toString()))); KJobWidgets::setWindow(copyJob, Core::self()->uiController()->activeMainWindow()); copyJob->exec(); Session* newSession = new Session( id.toString() ); newSession->setName( i18n( "Copy of %1", origSession->name() ) ); d->addSession(newSession); updateXmlGuiActionList(); return newSession->name(); } void SessionController::updateXmlGuiActionList() { unplugActionList( QStringLiteral("available_sessions") ); if (d->grp) { auto actions = d->grp->actions(); std::sort(actions.begin(), actions.end(), [](const QAction* lhs, const QAction* rhs) { auto s1 = lhs->data().value(); auto s2 = rhs->data().value(); return QString::localeAwareCompare(s1->description(), s2->description()) < 0; }); plugActionList(QStringLiteral("available_sessions"), actions); } } QString SessionController::cfgSessionGroup() { return QStringLiteral("Sessions"); } QString SessionController::cfgActiveSessionEntry() { return QStringLiteral("Active Session ID"); } QList SessionController::availableSessionInfo() { return availableSessionInfos().toList(); } SessionInfos SessionController::availableSessionInfos() { SessionInfos sessionInfos; foreach( const QString& sessionId, QDir( SessionControllerPrivate::sessionBaseDirectory() ).entryList( QDir::AllDirs ) ) { if( !QUuid( sessionId ).isNull() ) { sessionInfos << Session::parse( sessionId ); } } return sessionInfos; } QString SessionController::sessionDirectory(const QString& sessionId) { return SessionControllerPrivate::sessionBaseDirectory() + sessionId; } TryLockSessionResult SessionController::tryLockSession(const QString& id) { return SessionLock::tryLockSession(id, true); } bool SessionController::isSessionRunning(const QString& id) { return sessionRunInfo(id).isRunning; } SessionRunInfo SessionController::sessionRunInfo(const QString& id) { return SessionLock::tryLockSession(id, false).runInfo; } QString SessionController::showSessionChooserDialog(QString headerText, bool onlyRunning) { ///FIXME: move this code into sessiondialog.cpp QListView* view = new QListView; QLineEdit* filter = new QLineEdit; filter->setClearButtonEnabled( true ); filter->setPlaceholderText(i18n("Search")); QStandardItemModel* model = new QStandardItemModel(view); QSortFilterProxyModel *proxy = new QSortFilterProxyModel(model); proxy->setSourceModel(model); proxy->setFilterKeyColumn( 1 ); proxy->setFilterCaseSensitivity( Qt::CaseInsensitive ); connect(filter, &QLineEdit::textChanged, proxy, &QSortFilterProxyModel::setFilterFixedString); SessionChooserDialog dialog(view, proxy, filter); view->setEditTriggers(QAbstractItemView::NoEditTriggers); QVBoxLayout layout(dialog.mainWidget()); if(!headerText.isEmpty()) { QLabel* heading = new QLabel(headerText); QFont font = heading->font(); font.setBold(true); heading->setFont(font); layout.addWidget(heading); } model->setColumnCount(3); model->setHeaderData(0, Qt::Horizontal,i18n("Identity")); model->setHeaderData(1, Qt::Horizontal, i18n("Contents")); model->setHeaderData(2, Qt::Horizontal,i18n("State")); view->setModel(proxy); view->setModelColumn(1); QHBoxLayout* filterLayout = new QHBoxLayout(); filterLayout->addWidget(new QLabel(i18n("Filter:"))); filterLayout->addWidget(filter); layout.addLayout(filterLayout); layout.addWidget(view); filter->setFocus(); int row = 0; QString defaultSession = KSharedConfig::openConfig()->group( cfgSessionGroup() ).readEntry( cfgActiveSessionEntry(), "default" ); foreach(const KDevelop::SessionInfo& si, KDevelop::SessionController::availableSessionInfos()) { if ( si.name.isEmpty() && si.projects.isEmpty() ) { continue; } bool running = KDevelop::SessionController::isSessionRunning(si.uuid.toString()); if(onlyRunning && !running) continue; model->setItem(row, 0, new QStandardItem(si.uuid.toString())); model->setItem(row, 1, new QStandardItem(si.description)); model->setItem(row, 2, new QStandardItem); ++row; } model->sort(1); if(!onlyRunning) { model->setItem(row, 0, new QStandardItem); model->setItem(row, 1, new QStandardItem(QIcon::fromTheme(QStringLiteral("window-new")), i18n("Create New Session"))); } dialog.updateState(); dialog.mainWidget()->layout()->setContentsMargins(0,0,0,0); const QModelIndex defaultSessionIndex = model->match(model->index(0, 0), Qt::DisplayRole, defaultSession, 1, Qt::MatchExactly).value(0); view->selectionModel()->setCurrentIndex(proxy->mapFromSource(defaultSessionIndex), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); view->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); ///@todo We need a way to get a proper size-hint from the view, but unfortunately, that only seems possible after the view was shown. dialog.resize(QSize(900, 600)); if(dialog.exec() != QDialog::Accepted) { return QString(); } QModelIndex selected = view->selectionModel()->currentIndex(); if (!selected.isValid()) return QString(); const QString selectedSessionId = selected.sibling(selected.row(), 0).data().toString(); if (selectedSessionId.isEmpty()) { // "Create New Session" item selected, return a fresh UUID qsrand(QDateTime::currentDateTimeUtc().toTime_t()); return QUuid::createUuid().toString(); } return selectedSessionId; } QString SessionController::handleLockedSession( const QString& sessionName, const QString& sessionId, const SessionRunInfo& runInfo ) { return SessionLock::handleLockedSession(sessionName, sessionId, runInfo); } QString SessionController::sessionDir() { if( !activeSession() ) return QString(); return d->ownSessionDirectory(); } QString SessionController::sessionName() { if(!activeSession()) return QString(); return activeSession()->description(); } } #include "sessioncontroller.moc" #include "moc_sessioncontroller.cpp" diff --git a/shell/sessioncontroller.h b/shell/sessioncontroller.h index 28521b21f5..f358540fa5 100644 --- a/shell/sessioncontroller.h +++ b/shell/sessioncontroller.h @@ -1,181 +1,180 @@ /* This file is part of KDevelop Copyright 2008 Andreas Pakulat Copyright 2013 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_SESSIONCONTROLLER_H #define KDEVPLATFORM_SESSIONCONTROLLER_H #include "shellexport.h" #include "session.h" #include #include #include namespace KDevelop { struct SessionRunInfo { SessionRunInfo() : isRunning(false) , holderPid(-1) {} bool operator==(const SessionRunInfo& o) const { return isRunning == o.isRunning && holderPid == o.holderPid && holderApp == o.holderApp && holderHostname == o.holderHostname; } bool operator!=(const SessionRunInfo& o) const { return !(operator==(o)); } // if this is true, this session is currently running in an external process bool isRunning; // if the session is running, this contains the PID of its process qint64 holderPid; // if the session is running, this contains the name of its process QString holderApp; // if the session is running, this contains the host name where the process runs QString holderHostname; }; struct TryLockSessionResult { TryLockSessionResult(const ISessionLock::Ptr& _lock) : lock(_lock) {} TryLockSessionResult(const SessionRunInfo& _runInfo) : runInfo(_runInfo) {} // if this is non-null then the session was locked ISessionLock::Ptr lock; // otherwise this contains information about who is locking the session SessionRunInfo runInfo; }; class KDEVPLATFORMSHELL_EXPORT SessionController : public QObject, public KXMLGUIClient { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kdevelop.SessionController") public: explicit SessionController( QObject *parent = nullptr ); ~SessionController() override; void initialize( const QString& session ); void cleanup(); /// Returns whether the given session can be locked (i. e., is not locked currently). /// @param doLocking whether to really lock the session or just "dry-run" the locking process static TryLockSessionResult tryLockSession(const QString& id); /** * @return true when the given session is currently running, false otherwise */ static bool isSessionRunning(const QString& id); /** * @return information about whether the session @p id is running */ static SessionRunInfo sessionRunInfo(const QString& id); /// The application should call this on startup to tell the /// session-controller about the received arguments. /// Some of them may need to be passed to newly opened sessions. static void setArguments(int argc, char** argv); ///Finds a session by its name or by its UUID Session* session( const QString& nameOrId ) const; virtual ISession* activeSession() const; ISessionLock::Ptr activeSessionLock() const; QList sessionNames() const; Session* createSession( const QString& name ); QList sessions() const; void loadDefaultSession( const QString& session ); void startNewSession(); void loadSession( const QString& nameOrId ); void deleteSession( const ISessionLock::Ptr& lock ); static void deleteSessionFromDisk( const ISessionLock::Ptr& lock ); QString cloneSession( const QString& nameOrid ); /** * Path to session directory for the session with the given @p sessionId. */ static QString sessionDirectory( const QString& sessionId ); static QString cfgSessionGroup(); static QString cfgActiveSessionEntry(); static QT_DEPRECATED QList availableSessionInfo(); // use availableSessionInfos() static SessionInfos availableSessionInfos(); /** * Shows a dialog where the user can choose the session * @param headerText an additional text that will be shown at the top in a label * @param onlyRunning whether only currently running sessions should be shown * @return UUID on success, empty string in any other case */ static QString showSessionChooserDialog(QString headerText = QString(), bool onlyRunning = false); /// Should be called if session to be opened is locked. /// It attempts to bring existing instance's window up via a DBus call; if that succeeds, empty string is returned. /// Otherwise (if the app did not respond) it shows a dialog where the user may choose /// 1) to force-remove the lockfile and continue, /// 2) to select another session via \ref showSessionChooserDialog, /// 3) to quit the current (starting-up) instance. /// @param sessionName session name (for the message) /// @param sessionId current session GUID (to return if user chooses force-removal) /// @param runInfo the run information about the session /// @return new session GUID to try or an empty string if application startup shall be aborted static QString handleLockedSession( const QString& sessionName, const QString& currentSessionId, const SessionRunInfo& runInfo ); void updateXmlGuiActionList(); void emitQuitSession() { emit quitSession(); } public Q_SLOTS: // Returns the pretty name of the currently active session (used in the shell integration) virtual Q_SCRIPTABLE QString sessionName(); // Returns the directory associated to the active session (used in the shell integration) virtual Q_SCRIPTABLE QString sessionDir(); Q_SIGNALS: void sessionLoaded( ISession* ); void sessionDeleted( const QString& id); void quitSession(); private: Q_PRIVATE_SLOT( d, void newSession() ) - Q_PRIVATE_SLOT( d, void configureSessions() ) Q_PRIVATE_SLOT( d, void deleteCurrentSession() ) Q_PRIVATE_SLOT( d, void renameSession() ) Q_PRIVATE_SLOT( d, void loadSessionFromAction( QAction* ) ) class SessionControllerPrivate* const d; }; } #endif diff --git a/shell/sessiondialog.cpp b/shell/sessiondialog.cpp deleted file mode 100644 index 95b867b202..0000000000 --- a/shell/sessiondialog.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* This file is part of KDevelop -Copyright 2008 Andreas Pakulat - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public License -along with this library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. -*/ - -#include "sessiondialog.h" -#include "ui_sessiondialog.h" - -#include -#include - -#include -#include - -#include "core.h" -#include "sessioncontroller.h" -#include "session.h" - -namespace KDevelop -{ - -QString newSessionName() { return QStringLiteral("New Session"); } - -SessionModel::SessionModel( QObject* parent ) - : QAbstractListModel( parent ) -{ -} - -int SessionModel::rowCount( const QModelIndex& parent ) const -{ - if( parent.isValid() ) - return 0; - return Core::self()->sessionController()->sessionNames().count(); -} - -QVariant SessionModel::headerData( int, Qt::Orientation, int ) const -{ - return QVariant(); -} - -QVariant SessionModel::data( const QModelIndex& idx, int role ) const -{ - if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() - || ( role != Qt::DisplayRole && role != Qt::BackgroundRole && role != Qt::EditRole && role != Qt::FontRole ) ) - { - return QVariant(); - } - const Session* s = Core::self()->sessionController()->sessions().at( idx.row() ); - if( role == Qt::DisplayRole ) - { - return s->description(); - } else if( role == Qt::EditRole ) - { - return s->name(); - } else if( role == Qt::FontRole ) - { - QFont f = QFontDatabase::systemFont(QFontDatabase::GeneralFont); - if( Core::self()->activeSession()->name() == s->name() ) - { - f.setBold( true ); - } - return QVariant::fromValue( f ); - } else - { - if( Core::self()->activeSession()->name() == s->name() ) - { - return KColorScheme( QPalette::Active ).background( KColorScheme::ActiveBackground ); - } else - { - return KColorScheme( QPalette::Active ).background( KColorScheme::NormalBackground ); - } - } -} - -Qt::ItemFlags SessionModel::flags( const QModelIndex& idx ) const -{ - if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() ) - { - return 0; - } - return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; -} - -bool SessionModel::setData( const QModelIndex& idx, const QVariant& value, int role ) -{ - if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() || role != Qt::EditRole || !value.isValid() || !value.canConvert( QVariant::String ) ) - { - return false; - } - QString sname = Core::self()->sessionController()->sessionNames().at( idx.row() ); - Session* s = Core::self()->sessionController()->session( sname ); - s->setName( value.toString() ); - emit dataChanged( idx, idx ); - return true; -} - -void SessionModel::addSession() -{ - beginInsertRows( QModelIndex(), rowCount(), rowCount() ); - Core::self()->sessionController()->createSession( (newSessionName()) ); - endInsertRows(); -} - -void SessionModel::deleteSessions( const QList& indexes ) -{ - if( indexes.isEmpty() ) - { - return; - } - QVector deleteSessions; - int startRow = rowCount(), endRow = -1; - foreach( const QModelIndex& idx, indexes ) - { - if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() ) - { - continue; - } - QString sname = Core::self()->sessionController()->sessionNames().at( idx.row() ); - TryLockSessionResult locked = SessionController::tryLockSession( sname ); - if (!locked.lock) { - continue; - } - if( idx.row() < startRow ) - startRow = idx.row(); - if( idx.row() > endRow ) - endRow = idx.row(); - deleteSessions << locked.lock; - } - beginRemoveRows( QModelIndex(), startRow, endRow ); - foreach( const ISessionLock::Ptr& session, deleteSessions ) - { - Core::self()->sessionController()->deleteSessionFromDisk( session ); - } - endRemoveRows(); -} - -void SessionModel::activateSession( const QModelIndex& idx ) -{ - if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() ) - { - return; - } - QStringList sessionList = Core::self()->sessionController()->sessionNames(); - QString sname = sessionList.at( idx.row() ); - QString aname = Core::self()->activeSession()->name(); - if( sname == aname ) - { - return; - } - int activerow = sessionList.indexOf( aname ); - Core::self()->sessionController()->loadSession( sname ); - emit dataChanged( index( activerow, 0, QModelIndex() ), index( activerow, 0, QModelIndex() ) ); - emit dataChanged( idx, idx ); -} - -void SessionModel::cloneSession( const QModelIndex& idx ) -{ - if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() ) - { - return; - } - - beginInsertRows( QModelIndex(), rowCount(), rowCount() ); - - Core::self()->sessionController()->cloneSession( - Core::self()->sessionController()->sessions().at( idx.row() )->id().toString() - ); - endInsertRows(); -} - -SessionDialog::SessionDialog( QWidget* parent ) - : QDialog( parent ), m_ui( new Ui::SessionDialog ), m_model( new SessionModel( this ) ) -{ - setWindowTitle( i18n( "Configure Sessions" ) ); - - m_ui->setupUi(this); - m_ui->sessionList->setModel( m_model ); - connect( m_ui->newButton, &QPushButton::clicked, this, &SessionDialog::createSession ); - connect( m_ui->deleteButton, &QPushButton::clicked, this, &SessionDialog::deleteSession ); - connect( m_ui->activateButton, &QPushButton::clicked, this, &SessionDialog::activateSession ); - connect( m_ui->cloneButton, &QPushButton::clicked, this, &SessionDialog::cloneSession ); - connect( m_ui->sessionList->selectionModel(), &QItemSelectionModel::selectionChanged, - this, static_cast(&SessionDialog::enableButtons) ); - connect( m_ui->sessionList->selectionModel(), &QItemSelectionModel::currentChanged, - this, static_cast(&SessionDialog::enableButtons) ); - connect( m_model, &SessionModel::rowsRemoved, - this, static_cast(&SessionDialog::enableButtons) ); - enableButtons( m_ui->sessionList->selectionModel()->selection(), QItemSelection() ); - enableButtons(); -} - -SessionDialog::~SessionDialog() -{ - delete m_ui; -} - -void SessionDialog::enableButtons() -{ - m_ui->activateButton->setEnabled( m_model->rowCount() > 1 ); - m_ui->deleteButton->setEnabled( m_model->rowCount() > 1 ); -} - -void SessionDialog::enableButtons( const QModelIndex& current, const QModelIndex& previous ) -{ - Q_UNUSED( previous ); - if( m_model->data( current ).toString() == Core::self()->activeSession()->name() ) - { - m_ui->activateButton->setEnabled( false ); - m_ui->deleteButton->setEnabled( false ); - } else - { - m_ui->activateButton->setEnabled( true ); - m_ui->deleteButton->setEnabled( true ); - } -} - -void SessionDialog::enableButtons( const QItemSelection& selected, const QItemSelection& ) -{ - m_ui->deleteButton->setEnabled( !selected.isEmpty() ); - m_ui->activateButton->setEnabled( !selected.isEmpty() ); - m_ui->cloneButton->setEnabled( !selected.isEmpty() ); - QString activeName = Core::self()->activeSession()->name(); - foreach( const QModelIndex& idx, m_ui->sessionList->selectionModel()->selectedRows() ) - { - if( m_model->data( idx ).toString() == activeName ) - { - m_ui->deleteButton->setEnabled( false ); - m_ui->activateButton->setEnabled( false ); - break; - } - } -} - -void SessionDialog::createSession() -{ - m_model->addSession(); - m_ui->sessionList->edit( m_model->index( m_model->rowCount() - 1, 0, QModelIndex() ) ); - m_ui->deleteButton->setEnabled( true ); - m_ui->activateButton->setEnabled( true ); -} - -void SessionDialog::deleteSession() -{ - m_model->deleteSessions( m_ui->sessionList->selectionModel()->selectedRows() ); -} - -void SessionDialog::activateSession() -{ - m_model->activateSession( m_ui->sessionList->selectionModel()->selectedRows().at( 0 ) ); -} - -void SessionDialog::cloneSession() -{ - m_model->cloneSession( m_ui->sessionList->selectionModel()->selectedRows().at( 0 ) ); - m_ui->sessionList->edit( m_model->index( m_model->rowCount() - 1, 0, QModelIndex() ) ); -} - -} - diff --git a/shell/sessiondialog.h b/shell/sessiondialog.h deleted file mode 100644 index 478b1ff3ac..0000000000 --- a/shell/sessiondialog.h +++ /dev/null @@ -1,76 +0,0 @@ -/* This file is part of KDevelop -Copyright 2008 Andreas Pakulat - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public License -along with this library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. -*/ - -#ifndef KDEVPLATFORM_SESSIONDIALOG_H -#define KDEVPLATFORM_SESSIONDIALOG_H - -#include -#include - -namespace Ui -{ -class SessionDialog; -} - -class QModelIndex; -class QItemSelection; -class QVariant; - -namespace KDevelop -{ -class Session; - -class SessionModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit SessionModel( QObject* parent = nullptr ); - int rowCount( const QModelIndex& = QModelIndex() ) const override; - QVariant data( const QModelIndex&, int = Qt::DisplayRole ) const override; - QVariant headerData( int, Qt::Orientation, int = Qt::DisplayRole ) const override; - bool setData( const QModelIndex&, const QVariant&, int = Qt::DisplayRole ) override; - Qt::ItemFlags flags( const QModelIndex& ) const override; - void deleteSessions( const QList& ); - void activateSession( const QModelIndex& ); - void addSession(); - void cloneSession( const QModelIndex& ); -}; - -class SessionDialog : public QDialog -{ - Q_OBJECT -public: - explicit SessionDialog( QWidget* = nullptr ); - ~SessionDialog() override; -private Q_SLOTS: - void createSession(); - void deleteSession(); - void activateSession(); - void cloneSession(); - void enableButtons( const QModelIndex&, const QModelIndex& ); - void enableButtons( const QItemSelection&, const QItemSelection& ); - void enableButtons(); -private: - Ui::SessionDialog* m_ui; - SessionModel* m_model; -}; - -} - -#endif diff --git a/shell/sessiondialog.ui b/shell/sessiondialog.ui deleted file mode 100644 index 967ba89a35..0000000000 --- a/shell/sessiondialog.ui +++ /dev/null @@ -1,105 +0,0 @@ - - - SessionDialog - - - - 0 - 0 - 395 - 189 - - - - - - - true - - - - - - - 20 - - - - - 3 - - - - - New - - - false - - - - - - - Clone - - - false - - - - - - - - - false - - - Make Active - - - false - - - - - - - false - - - Delete - - - false - - - - - - - - - Qt::Vertical - - - - 20 - 23 - - - - - - - - QDialogButtonBox::Close - - - - - - - -