Commit 568ac672 authored by Krzysztof Stokop's avatar Krzysztof Stokop
Browse files

Added alert before project closing

parent 8b8f9cf7
......@@ -21,6 +21,8 @@
#include <QCoreApplication>
#include <QFileInfo>
#include <QTime>
#include <QMessageBox>
#include <QString>
#include <vector>
......@@ -193,19 +195,38 @@ KateProject *KateProjectPlugin::projectForDir(QDir dir)
bool KateProjectPlugin::closeProject(KateProject *project)
{
QList< KTextEditor::Document* > documents = KTextEditor::Editor::instance()->application()->documents();
QVector< KTextEditor::Document* > projectDocuments;
QString text = i18n("Documents will be closed:\n");
QString title = i18n("Confirm project closing: ") + project->name();
for(int i = 0; i<documents.size(); i++)
{
if(QUrl(project->baseDir()).isParentOf(documents[i]->url().adjusted(QUrl::RemoveScheme)))
KTextEditor::Editor::instance()->application()->closeDocument(documents[i]);
{
projectDocuments.push_back(documents[i]);
text+=documents[i]->url().adjusted(QUrl::RemoveScheme).toDisplayString();
text+=i18n("\n");
}
}
QMessageBox confirmationBox(QMessageBox::Information, title, text, QMessageBox::Cancel | QMessageBox::Yes);
confirmationBox.setDefaultButton(QMessageBox::Cancel);
Q_EMIT pluginViewProjectClosing(project);
if(m_projects.removeOne(project))
if(16384==confirmationBox.exec())//4194304 for QMessageBox::Cancel
{
m_fileWatcher.removePath(QFileInfo(project->fileName()).canonicalPath());
delete project;
return true;
for(int i = 0; i<projectDocuments.size(); i++)
KTextEditor::Editor::instance()->application()->closeDocument(projectDocuments[i]);
Q_EMIT pluginViewProjectClosing(project);
if(m_projects.removeOne(project))
{
m_fileWatcher.removePath(QFileInfo(project->fileName()).canonicalPath());
delete project;
return true;
}
}
else return false;
return false;
}
KateProject *KateProjectPlugin::projectForUrl(const QUrl &url)
......
......@@ -114,7 +114,7 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
connect(m_projectsCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KateProjectPluginView::slotCurrentChanged);
connect(m_reloadButton, &QToolButton::clicked, this, &KateProjectPluginView::slotProjectReload);
// connect(m_closeProjectButton, &QToolButton::clicked, this, &KateProjectPluginView::slotProjectAboutToClose);
connect(m_closeProjectButton, &QToolButton::clicked, this, &KateProjectPluginView::slotProjectAboutToClose);
connect(m_plugin, &KateProjectPlugin::pluginViewProjectClosing, this, &KateProjectPluginView::slotProjectClose);
connect(m_gitStatusRefreshButton, &QToolButton::clicked, this, [this] {
......@@ -570,7 +570,7 @@ void KateProjectPluginView::slotProjectReload()
void KateProjectPluginView::slotProjectAboutToClose()
{
if (QWidget *current = m_stackedProjectViews->currentWidget())
if (QWidget* current = m_stackedProjectViews->currentWidget())
{
m_plugin->closeProject(static_cast<KateProjectView *>(current)->project());
}
......
Markdown is supported
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