Commit 9c8756cc authored by Krzysztof Stokop's avatar Krzysztof Stokop
Browse files

The working version of the closing project. Need to switch project in other...

The working version of the closing project. Need to switch project in other windows (synchronization), because if different projects are selected in different windows then bugs appear.
parent 37f8bacc
......@@ -12,6 +12,7 @@
#include <ktexteditor/application.h>
#include <ktexteditor/editor.h>
#include <ktexteditor/view.h>
#include <KConfigGroup>
#include <KLocalizedString>
......@@ -190,8 +191,11 @@ KateProject *KateProjectPlugin::projectForDir(QDir dir)
}
bool KateProjectPlugin::closeProject(KateProject *project)
{
Q_EMIT pluginViewProjectClosing(project);
m_projects.removeOne(project);
for (KateProject *projectIterator : m_projects)
{
......
......@@ -126,6 +126,13 @@ public:
ClickAction doubleClickAcion();
Q_SIGNALS:
/**
* Signal that for view to clean up
* @param project to close
*/
void pluginViewProjectClosing(KateProject *project);
/**
* Signal that a new project got created.
* @param project new created project
......
......@@ -10,6 +10,7 @@
#include "gitwidget.h"
#include "kateprojectinfoviewindex.h"
#include <ktexteditor/application.h>
#include <ktexteditor/codecompletioninterface.h>
#include <ktexteditor/document.h>
......@@ -113,8 +114,10 @@ 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::slotProjectClose);
connect(m_closeProjectButton, &QToolButton::clicked, this, &KateProjectPluginView::slotProjectAboutToClose);
connect(this, &KateProjectPluginView::pluginProjectClose, m_plugin, &KateProjectPlugin::closeProject);
connect(m_plugin, &KateProjectPlugin::pluginViewProjectClosing, this, &KateProjectPluginView::slotProjectClose);
connect(m_gitStatusRefreshButton, &QToolButton::clicked, this, [this] {
if (auto widget = m_stackedgitViews->currentWidget()) {
qobject_cast<GitWidget *>(widget)->getStatus();
......@@ -563,31 +566,36 @@ void KateProjectPluginView::slotProjectReload()
}
}
void KateProjectPluginView::slotProjectClose()
void KateProjectPluginView::slotProjectAboutToClose()
{
if (QWidget *current = m_stackedProjectViews->currentWidget())
{
const auto project = static_cast<KateProjectView *>(current)->project();
// m_project2View.erase(m_project2View.find(project));
// m_stackedProjectViews->removeWidget(m_stackedProjectViews->currentWidget());
// m_stackedProjectInfoViews->removeWidget(m_stackedProjectInfoViews->currentWidget());
// m_stackedgitViews->removeWidget(m_stackedgitViews->currentWidget());
// m_plugin->projects().removeAt(m_plugin->projects().indexOf(project));
// m_projectsCombo->removeItem(m_plugin->projects().indexOf(project));
// m_projectsComboGit->removeItem(m_plugin->projects().indexOf(project));
//
// m_plugin->closeProject(project);
for(int i = 0; i < project->files().size(); i++)
Q_EMIT pluginProjectClose(project);
for(int i = 0; i < m_mainWindow->views().size(); i++)
{
m_mainWindow->closeUrl(QUrl(project->files()[i]));
if(QUrl(project->baseDir()).isParentOf(m_mainWindow->views()[i]->document()->url().adjusted(QUrl::RemoveScheme)))
{
KTextEditor::Editor::instance()->application()->closeDocument(m_mainWindow->views()[i]->document());
}
}
}
}
void KateProjectPluginView::slotProjectClose(KateProject *project)
{
m_project2View.erase(m_project2View.find(project));
m_stackedProjectViews->removeWidget(m_stackedProjectViews->currentWidget());
m_stackedProjectInfoViews->removeWidget(m_stackedProjectInfoViews->currentWidget());
m_stackedgitViews->removeWidget(m_stackedgitViews->currentWidget());
m_plugin->projects().removeAt(m_plugin->projects().indexOf(project));
m_projectsCombo->removeItem(m_plugin->projects().indexOf(project));
m_projectsComboGit->removeItem(m_plugin->projects().indexOf(project));
}
QString KateProjectPluginView::currentWord() const
{
......
......@@ -150,9 +150,15 @@ private Q_SLOTS:
void slotProjectReload();
/**
* Close current project, if any.
* Getting project for others windows
* and closing project documents.
*/
void slotProjectClose();
void slotProjectAboutToClose();
/**
* Close current project.
*/
void slotProjectClose(KateProject *project);
/**
* Lookup current word
......@@ -165,6 +171,12 @@ private Q_SLOTS:
void slotGotoSymbol();
Q_SIGNALS:
/**
* Emitted if project is about to close.
*/
void pluginProjectClose(KateProject *project);
/**
* Emitted if projectFileName changed.
*/
......
......@@ -881,11 +881,6 @@ void KateMainWindow::openUrl(const QString &name)
m_viewManager->openUrl(QUrl(name));
}
// void KateMainWindow::closeUrl(const QString &name)
// {
// m_viewManager->closeUrl(QUrl(name));
// }
void KateMainWindow::slotConfigure()
{
showPluginConfigPage(nullptr, 0);
......
......@@ -233,7 +233,6 @@ Q_SIGNALS:
public:
void openUrl(const QString &name = QString());
// void closeUrl(const QString &name = QString());
QHash<KTextEditor::Plugin *, QObject *> &pluginViews()
{
......
......@@ -323,20 +323,6 @@ void KateViewManager::openUrl(const QUrl &url)
openUrl(url, QString());
}
bool KateViewManager::closeUrl(const QUrl &url)
{
for(int i = 0; i < activeViewSpace()->documentList().size(); i++)
{
if(activeViewSpace()->documentList()[i]->url() == url)
{
slotDocumentClose(activeViewSpace()->documentList()[i]);
return true;
}
}
return false;
}
KateMainWindow *KateViewManager::mainWindow()
{
return m_mainWindow;
......
......@@ -59,8 +59,6 @@ public:
KTextEditor::Document *
openUrl(const QUrl &url, const QString &encoding, bool activate = true, bool isTempFile = false, const KateDocumentInfo &docInfo = KateDocumentInfo());
bool closeUrl(const QUrl &url);
KTextEditor::Document *
openUrls(const QList<QUrl> &url, const QString &encoding, bool isTempFile = false, const KateDocumentInfo &docInfo = KateDocumentInfo());
......
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