Commit fa72c7f1 authored by Krzysztof Stokop's avatar Krzysztof Stokop
Browse files

First version with bugs and a button (to be changed to menu) of closing project.

parent 675eaa6e
......@@ -73,6 +73,20 @@ bool KateProject::reload(bool force)
return load(m_globalProject, force);
}
void KateProject::close(bool force)
{
QVariantMap map = readProjectFile();
if (!map.isEmpty())
{
m_plugin->deleteProject(this);
m_globalProject.clear();
delete this;
}
load(m_globalProject, force);
}
/**
* Read a JSON document from file.
*
......
......@@ -67,6 +67,13 @@ public:
* @return success
*/
bool reload(bool force = false);
/**
* Try to close a project.
* @param force will enforce the worker to update files list and co even if the content of the file was not changed!
* @return success
*/
void close(bool force = false);
/**
* Accessor to file name.
......
......@@ -189,6 +189,22 @@ KateProject *KateProjectPlugin::projectForDir(QDir dir)
return nullptr;
}
void KateProjectPlugin::deleteProject(KateProject *project)
{
m_projects.removeOne(project);
for (KateProject *projectIterator : m_projects)
{
if(project == projectIterator)
{
m_fileWatcher.removePath(QFileInfo(projectIterator->fileName()).canonicalPath());
delete projectIterator;
}
}
}
KateProject *KateProjectPlugin::projectForUrl(const QUrl &url)
{
if (url.isEmpty() || !url.isLocalFile()) {
......
......@@ -58,6 +58,8 @@ public:
* @return project or null if not openable
*/
KateProject *projectForDir(QDir dir);
void deleteProject(KateProject *project);
/**
* Search and open project that contains given url, if possible.
......
......@@ -75,10 +75,14 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
m_reloadButton = new QToolButton(m_toolView);
m_reloadButton->setAutoRaise(true);
m_reloadButton->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
m_closeProjectButton = new QToolButton(m_toolView);
m_closeProjectButton->setAutoRaise(true);
m_closeProjectButton->setIcon(QIcon::fromTheme(QStringLiteral("window-close")));
QHBoxLayout *layout = new QHBoxLayout();
layout->setSpacing(0);
layout->addWidget(m_projectsCombo);
layout->addWidget(m_reloadButton);
layout->addWidget(m_closeProjectButton);
m_toolView->layout()->addItem(layout);
m_toolView->layout()->setSpacing(0);
......@@ -107,6 +111,9 @@ 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_gitStatusRefreshButton, &QToolButton::clicked, this, [this] {
if (auto widget = m_stackedgitViews->currentWidget()) {
qobject_cast<GitWidget *>(widget)->getStatus();
......@@ -555,6 +562,28 @@ void KateProjectPluginView::slotProjectReload()
}
}
void KateProjectPluginView::slotProjectClose()
{
if (QWidget *current = m_stackedProjectViews->currentWidget())
{
m_project2View.erase(m_project2View.find(static_cast<KateProjectView *>(current)->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(static_cast<KateProjectView *>(current)->project()));
m_projectsCombo->removeItem(m_plugin->projects().indexOf(static_cast<KateProjectView *>(current)->project()));
m_projectsComboGit->removeItem(m_plugin->projects().indexOf(static_cast<KateProjectView *>(current)->project()));
static_cast<KateProjectView *>(current)->project()->close(true);
//delete static_cast<KateProjectView *>(current)->project();
}
}
QString KateProjectPluginView::currentWord() const
{
KTextEditor::View *kv = m_activeTextEditorView;
......
......@@ -148,6 +148,11 @@ private Q_SLOTS:
* This will trigger a reload with force.
*/
void slotProjectReload();
/**
* Close current project, if any.
*/
void slotProjectClose();
/**
* Lookup current word
......@@ -272,6 +277,11 @@ private:
* Reload button
*/
QToolButton *m_reloadButton;
/**
* Closeing button
*/
QToolButton *m_closeProjectButton;
/**
* Git status refresh button
......
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