Commit 78149a31 authored by Eric Armbruster's avatar Eric Armbruster 🍁 Committed by Christoph Cullmann
Browse files

add recent projects

This adds recent projects to the recent open recent menu and
lets us open recent projects from there and from the welcome view.

Further changes to welcomeview will be done in a followup MR.
parent a56d2446
......@@ -26,8 +26,10 @@
#include <KActionMenu>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KStandardAction>
#include <KStringHandler>
#include <KXMLGUIFactory>
#include <KXmlGuiWindow>
#include <QAction>
#include <QFileDialog>
......@@ -819,6 +821,11 @@ void KateProjectPluginView::openDirectoryOrProject()
return;
}
openDirectoryOrProject(dir);
}
void KateProjectPluginView::openDirectoryOrProject(const QDir &dir)
{
// switch to this project if there
if (auto project = m_plugin->projectForDir(dir, true)) {
// just activate the right plugin in the toolview
......@@ -826,6 +833,15 @@ void KateProjectPluginView::openDirectoryOrProject()
// this is a user action, ensure the toolview is visible
mainWindow()->showToolView(m_toolView);
// add the project to the recently opened items list
if (auto *parentClient = qobject_cast<KXmlGuiWindow *>(m_mainWindow->window())) {
if (auto *openRecentAction = parentClient->action(KStandardAction::name(KStandardAction::StandardAction::OpenRecent))) {
if (auto *recentFilesAction = qobject_cast<KRecentFilesAction *>(openRecentAction)) {
recentFilesAction->addUrl(QUrl(dir.path()));
}
}
}
}
}
......
......@@ -294,6 +294,11 @@ private Q_SLOTS:
*/
void openDirectoryOrProject();
/**
* Open a folder / project
*/
void openDirectoryOrProject(const QDir &dir);
/**
* Show projects To-Dos and Fix-mes
*/
......
......@@ -289,7 +289,20 @@ void KateMainWindow::setupActions()
->addAction(KStandardAction::Open, QStringLiteral("file_open"), m_viewManager, SLOT(slotDocumentOpen()))
->setWhatsThis(i18n("Open an existing document for editing"));
m_fileOpenRecent = KStandardAction::openRecent(m_viewManager, SLOT(openUrl(QUrl)), this);
m_fileOpenRecent = KStandardAction::openRecent(
m_viewManager,
[this](const QUrl &url) {
if (url.isLocalFile()) {
QDir dir(url.path());
if (dir.exists()) {
Utils::openDirectoryOrProject(this, dir);
return;
}
}
openUrl(url);
},
this);
m_fileOpenRecent->setMaxItems(KateConfigDialog::recentFilesMaxCount());
actionCollection()->addAction(m_fileOpenRecent->objectName(), m_fileOpenRecent);
m_fileOpenRecent->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
......
......@@ -7,6 +7,7 @@
#include "ktexteditor_utils.h"
#include "katemainwindow.h"
#include <QDir>
#include <QFontDatabase>
#include <QIcon>
#include <QMimeDatabase>
......@@ -15,6 +16,8 @@
#include <QVariant>
#include <KActionCollection>
#include <KLocalizedString>
#include <KMessageBox>
#include <KTextEditor/Application>
#include <KTextEditor/ConfigInterface>
#include <KTextEditor/Editor>
......@@ -189,4 +192,13 @@ QVariantMap projectMapForDocument(KTextEditor::Document *doc)
}
return projectMap;
}
void openDirectoryOrProject(KateMainWindow *mainWindow, const QDir &dir)
{
if (QObject *pview = mainWindow->pluginView(QStringLiteral("kateprojectplugin"))) {
QMetaObject::invokeMethod(pview, "openDirectoryOrProject", Q_ARG(const QDir &, dir));
} else {
KMessageBox::error(mainWindow, i18n("Please enable the project plugin to load directories"));
}
}
}
......@@ -10,6 +10,7 @@
QT_BEGIN_NAMESPACE
class QScrollBar;
class QAction;
class QDir;
class QFont;
class QIcon;
class QVariant;
......@@ -24,6 +25,7 @@ class Document;
class MainWindow;
}
struct DiffParams;
class KateMainWindow;
namespace Utils
{
......@@ -88,4 +90,11 @@ KATE_PRIVATE_EXPORT QString projectBaseDirForDocument(KTextEditor::Document *doc
* Returns project map for provided document
*/
KATE_PRIVATE_EXPORT QVariantMap projectMapForDocument(KTextEditor::Document *doc);
/**
* Opens a directory or project for the provided url
*
* Returns whether the url is a directory
*/
KATE_PRIVATE_EXPORT void openDirectoryOrProject(KateMainWindow *mainWindow, const QDir &dir);
}
......@@ -9,6 +9,7 @@
#include "kateapp.h"
#include "kateviewmanager.h"
#include "ktexteditor_utils.h"
#include "recentfilesmodel.h"
#include "savedsessionsmodel.h"
......@@ -20,6 +21,7 @@
#include <KIO/OpenFileManagerWindowJob>
#include <QClipboard>
#include <QDir>
#include <QGraphicsOpacityEffect>
#include <QLabel>
#include <QMenu>
......@@ -82,6 +84,14 @@ WelcomeView::WelcomeView(KateViewManager *viewManager, QWidget *parent)
if (index.isValid()) {
const QUrl url = m_recentFilesModel->url(index);
Q_ASSERT(url.isValid());
if (url.isLocalFile()) {
QDir dir = {url.path()};
if (dir.exists()) {
Utils::openDirectoryOrProject(m_viewManager->mainWindow(), dir);
return;
}
}
m_viewManager->openUrl(url);
}
});
......
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