Commit ef30d668 authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

[Feature] Add "Recent Files" submenu

BUG: 409138
FIXED-IN: 19.08
parent a2c01cbb
......@@ -27,6 +27,7 @@
#include <KStandardAction>
#include <KNS3/DownloadDialog>
#include <KParts/ReadWritePart>
#include <KRecentFilesAction>
#include <QApplication>
#include <QCloseEvent>
......@@ -75,6 +76,12 @@ CantorShell::CantorShell() : KParts::MainWindow(), m_part(nullptr)
updateNewSubmenu();
}
CantorShell::~CantorShell()
{
if (m_recentProjectsAction)
m_recentProjectsAction->saveEntries(KSharedConfig::openConfig()->group(QLatin1String("Recent Files")));
}
void CantorShell::load(const QUrl &url)
{
if (!m_part||!m_part->url().isEmpty() || m_part->isModified() )
......@@ -84,6 +91,8 @@ void CantorShell::load(const QUrl &url)
}
if (!m_part->openUrl( url ))
closeTab(m_tabWidget->currentIndex());
if (m_recentProjectsAction)
m_recentProjectsAction->addUrl(url);
}
bool CantorShell::hasAvailableBackend()
......@@ -104,6 +113,9 @@ void CantorShell::setupActions()
openNew->setPriority(QAction::LowPriority);
QAction* open = KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
open->setPriority(QAction::LowPriority);
m_recentProjectsAction = KStandardAction::openRecent(this, &CantorShell::load, actionCollection());
m_recentProjectsAction->setPriority(QAction::LowPriority);
m_recentProjectsAction->loadEntries(KSharedConfig::openConfig()->group(QLatin1String("Recent Files")));
KStandardAction::close (this, SLOT(closeTab()), actionCollection());
......@@ -299,6 +311,7 @@ void CantorShell::addWorksheet(const QString& backendName)
if (part)
{
connect(part, SIGNAL(setCaption(QString,QIcon)), this, SLOT(setTabCaption(QString,QIcon)));
connect(part, SIGNAL(worksheetSave(QUrl)), this, SLOT(onWorksheetSave(QUrl)));
m_parts.append(part);
int tab = m_tabWidget->addTab(part->widget(), QIcon::fromTheme(backend->icon()), i18n("Session %1", sessionCount++));
......@@ -667,3 +680,9 @@ void CantorShell::pluginVisibilityRequested()
}
}
}
void CantorShell::onWorksheetSave(const QUrl& url)
{
if (m_recentProjectsAction)
m_recentProjectsAction->addUrl(url);
}
......@@ -28,6 +28,7 @@
class QTabWidget;
class KTextEdit;
class KRecentFilesAction;
namespace Cantor{
class WorksheetAccessInterface;
......@@ -53,12 +54,7 @@ public:
/**
* Default Destructor
*/
~CantorShell() override = default;
/**
* Use this method to load whatever file/URL you have
*/
void load(const QUrl& url);
~CantorShell() override;
/**
* checks if at least one usable Backend is installed
......@@ -82,10 +78,13 @@ protected:
public Q_SLOTS:
void addWorksheet();
void addWorksheet(const QString& backendName);
/// Use this method/slot to load whatever file/URL you have
void load(const QUrl& url);
private Q_SLOTS:
void fileNew();
void fileOpen();
void onWorksheetSave(const QUrl& url);
void optionsConfigureKeys();
void activateWorksheet(int index);
......@@ -115,6 +114,7 @@ private:
QTabWidget* m_tabWidget;
QList<QDockWidget*> m_panels;
QDockWidget* m_helpDocker;
KRecentFilesAction* m_recentProjectsAction;
};
#endif // CANTOR_H
......@@ -450,6 +450,7 @@ bool CantorPart::saveFile()
m_worksheet->save( localFilePath() );
setModified(false);
emit worksheetSave(QUrl::fromLocalFile(localFilePath()));
return true;
}
......@@ -480,7 +481,9 @@ void CantorPart::fileSaveAs()
{
if (!file_name.endsWith(QLatin1String(".cws")))
file_name += QLatin1String(".cws");
saveAs(QUrl::fromLocalFile(file_name));
const QUrl& url = QUrl::fromLocalFile(file_name);
saveAs(url);
emit worksheetSave(url);
}
else
m_worksheet->savePlain(file_name);
......
......@@ -82,6 +82,7 @@ public:
Q_SIGNALS:
void setCaption(const QString& caption, const QIcon& icon);
void showHelp(const QString& help);
void worksheetSave(const QUrl& url);
protected:
/**
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="cantor_shell" version="1">
<kpartgui name="cantor_shell" version="2">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Action name="file_new"/>
......@@ -7,6 +7,7 @@
<ActionList name="new_worksheet_with_backend_list" />
</Menu>
<Action name="file_open"/>
<Action name="file_open_recent"/>
<Action name="file_example_download"/>
<Action name="file_example_open"/>
<Separator/>
......
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