Commit 38d34254 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

add action to close all projects without documents

parent 064ed40b
......@@ -260,15 +260,21 @@ void KateProjectPlugin::closeProject(KateProject *project)
}
// check: did all documents of the project go away? if not we shall not close it
if (!projectHasOpenDocuments(project)) {
Q_EMIT pluginViewProjectClosing(project);
m_projects.removeOne(project);
delete project;
}
}
bool KateProjectPlugin::projectHasOpenDocuments(KateProject *project) const
{
for (const auto &it : m_document2Project) {
if (it.second == project) {
return;
return true;
}
}
Q_EMIT pluginViewProjectClosing(project);
m_projects.removeOne(project);
delete project;
return false;
}
KateProject *KateProjectPlugin::projectForUrl(const QUrl &url)
......
......@@ -89,6 +89,13 @@ public:
return m_projects;
}
/**
* Has the given project open documents?
* @param project project to check open document for
* @return has the given project open documents
*/
bool projectHasOpenDocuments(KateProject *project) const;
/**
* Get global code completion.
* @return global completion object for KTextEditor::View
......
......@@ -203,6 +203,11 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
a->setText(i18n("Close All Projects"));
a->setIcon(QIcon::fromTheme(QStringLiteral(PROJECTCLOSEICON)));
m_projectCloseWithoutDocumentsAction = a =
actionCollection()->addAction(QStringLiteral("projects_close_without_open_documents"), this, SLOT(slotProjectsWithoutDocumentsAboutToClose()));
a->setText(i18n("Close Orphaned Projects"));
a->setIcon(QIcon::fromTheme(QStringLiteral(PROJECTCLOSEICON)));
m_gotoSymbolActionAppMenu = a = actionCollection()->addAction(KStandardAction::Goto, QStringLiteral("projects_goto_symbol"), this, SLOT(slotGotoSymbol()));
// popup menu
......@@ -658,6 +663,18 @@ void KateProjectPluginView::slotAllProjectsAboutToClose()
}
}
void KateProjectPluginView::slotProjectsWithoutDocumentsAboutToClose()
{
// we must close project after project
// project closing might activate a different one and then would load the files of that project again
const auto copiedProjects = m_plugin->projects();
for (auto project : copiedProjects) {
if (!m_plugin->projectHasOpenDocuments(project)) {
m_plugin->closeProject(project);
}
}
}
void KateProjectPluginView::slotProjectClose(KateProject *project)
{
const int index = m_plugin->projects().indexOf(project);
......@@ -850,6 +867,7 @@ void KateProjectPluginView::updateActions()
m_projectGotoIndexAction->setEnabled(projectActive);
m_projectCloseAction->setEnabled(projectActive);
m_projectCloseAllAction->setEnabled(m_projectsCombo->count() > 0);
m_projectCloseWithoutDocumentsAction->setEnabled(m_projectsCombo->count() > 0);
}
void KateProjectPluginView::slotActivateProject(KateProject *project)
......
......@@ -193,17 +193,20 @@ private Q_SLOTS:
void slotProjectReload();
/**
* Getting project for others windows
* and closing project documents.
* Close currently active project.
*/
void slotProjectAboutToClose();
/**
* Getting project for others windows
* and closing project documents.
* Close all projects.
*/
void slotAllProjectsAboutToClose();
/**
* Close all projects without open documents.
*/
void slotProjectsWithoutDocumentsAboutToClose();
/**
* Close current project.
*/
......@@ -441,6 +444,7 @@ private:
QAction *m_projectGotoIndexAction;
QAction *m_projectCloseAction;
QAction *m_projectCloseAllAction;
QAction *m_projectCloseWithoutDocumentsAction;
class FixedView
{
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="kateprojectplugin" library="kateprojectplugin" version="13" translationDomain="kateproject">
<gui name="kateprojectplugin" library="kateprojectplugin" version="14" translationDomain="kateproject">
<MenuBar>
<Menu name="file">
<Action name="projects_open_project" group="open_merge"/>
......@@ -15,6 +15,7 @@
<Separator/>
<Action name="projects_close" />
<Action name="projects_close_all" />
<Action name="projects_close_without_open_documents" />
<Separator/>
<Action name="projects_todos"/>
</Menu>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment