Commit 7034b50c authored by Henrik Fehlauer's avatar Henrik Fehlauer

Add action to open screenshots folder to tools menu

Summary:
With {nav Quit after Save or Copy} checked, there is a desktop
notification when saving which allows to open the folder containing the
saved screenshot. However, when the user opts to let the window stay
open, only the title will reflect the filename of the saved screenshot.
It's quite hard to know in which folder it was saved and not that easy
to open that folder.

By introducing {nav Tools > Open Screenshots Folder}, usability in that
regard is much-improved. When no screenshot has been saved yet, it will
open the last {nav Save As} folder or the default {nav Save} location
depending on the button state. As soon as a screenshot is saved, the
new action will highlight the new screenshot in the filemanager.

BUG: 389695

Depends on D10467
Ref T7841

Test Plan:
For {nav Save} and {nav Save As} each, click on new menu entry after
starting Spectacle as well as after saving. Also test everything with
`fish:/` (but beware of Bug 390297).

{F5705490}

Reviewers: #spectacle, ngraham

Reviewed By: #spectacle, ngraham

Subscribers: ngraham

Maniphest Tasks: T7841

Differential Revision: https://phabricator.kde.org/D10470
parent 3f9e76af
......@@ -207,7 +207,7 @@
<varlistentry>
<term><guibutton>Tools</guibutton></term>
<listitem>
<para>Clicking on this button shows a drop-down menu, offering access to the print dialog.</para>
<para>Clicking on this button shows a drop-down menu, offering access to various functions. You can open the <guimenuitem>Print</guimenuitem> dialog, and <guimenuitem>Open Screenshots Folder</guimenuitem> is a shortcut to highlight the last saved screenshot in the default file manager.</para>
</listitem>
</varlistentry>
<varlistentry>
......
......@@ -41,9 +41,14 @@
ExportManager::ExportManager(QObject *parent) :
QObject(parent),
mSavePixmap(QPixmap()),
mLastSavePath(QUrl()),
mTempFile(QUrl()),
mTempDir(nullptr)
{}
{
connect(this, &ExportManager::imageSaved, [this](const QUrl savedAt) {
mLastSavePath = savedAt;
});
}
ExportManager::~ExportManager()
{
......@@ -118,6 +123,11 @@ QString ExportManager::saveLocation() const
return savePath;
}
QUrl ExportManager::lastSavePath() const
{
return isFileExists(mLastSavePath) ? mLastSavePath : QUrl();
}
void ExportManager::setSaveLocation(const QString &savePath)
{
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("spectaclerc"));
......
......@@ -55,6 +55,8 @@ class ExportManager : public QObject
void setSaveLocation(const QString &location);
QString saveLocation() const;
QUrl lastSavePath() const;
bool isFileExists(const QUrl &url) const;
void setPixmap(const QPixmap &pixmap);
QPixmap pixmap() const;
QString pixmapDataUri() const;
......@@ -88,10 +90,10 @@ class ExportManager : public QObject
bool save(const QUrl &url);
bool localSave(const QUrl &url, const QString &mimetype);
bool remoteSave(const QUrl &url, const QString &mimetype);
bool isFileExists(const QUrl &url) const;
bool isTempFileAlreadyUsed(const QUrl &url) const;
QPixmap mSavePixmap;
QUrl mLastSavePath;
QUrl mTempFile;
QTemporaryDir *mTempDir;
QList<QUrl> mUsedTempFileNames;
......
......@@ -40,6 +40,7 @@
#include <KHelpMenu>
#include <KAboutData>
#include <KWindowSystem>
#include <KIO/OpenFileManagerWindowJob>
#include "SettingsDialog/SettingsDialog.h"
#include "ExportMenu.h"
......@@ -149,7 +150,6 @@ void KSMainWindow::init()
KGuiItem::assign(mToolsButton, KGuiItem(i18n("Tools")));
mToolsButton->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
mDialogButtonBox->addButton(mToolsButton, QDialogButtonBox::ActionRole);
mToolsMenu->addAction(KStandardAction::print(this, SLOT(showPrintDialog()), this));
mToolsButton->setMenu(mToolsMenu);
KGuiItem::assign(mSendToButton, KGuiItem(i18n("Export")));
......@@ -171,6 +171,13 @@ void KSMainWindow::init()
KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true);
mDialogButtonBox->button(QDialogButtonBox::Help)->setMenu(helpMenu->menu());
// the tools menu
mToolsMenu->addAction(KStandardAction::print(this, &KSMainWindow::showPrintDialog, this));
mToolsMenu->addAction(
QIcon::fromTheme(QStringLiteral("document-open-folder")),
i18n("Open Screenshots Folder"),
this, &KSMainWindow::openScreenshotsFolder);
// the save menu
mSaveAsAction = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this);
mSaveAction = KStandardAction::save(this, &KSMainWindow::save, this);
......@@ -286,6 +293,27 @@ void KSMainWindow::showPrintDialog()
delete printer;
}
void KSMainWindow::openScreenshotsFolder()
{
// Highlight last screenshot in file manager if user saved at least once,
// or open default directory as determined by save button
QUrl location = ExportManager::instance()->lastSavePath();
if (!ExportManager::instance()->isFileExists(location)) {
switch(saveButtonMode()) {
case SaveMode::Save:
location = QUrl::fromLocalFile(ExportManager::instance()->saveLocation() + QStringLiteral("/"));
break;
case SaveMode::SaveAs:
location = SpectacleConfig::instance()->lastSaveAsLocation();
break;
}
if (!ExportManager::instance()->isFileExists(location)) {
location = QUrl(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + QStringLiteral("/"));
}
}
KIO::highlightInFileManager({location});
}
void KSMainWindow::showImageSharedFeedback(bool error, const QString &message)
{
if (error) {
......
......@@ -50,6 +50,7 @@ class KSMainWindow : public QDialog
void captureScreenshot(ImageGrabber::GrabMode mode, int timeout, bool includePointer, bool includeDecorations);
void showPrintDialog();
void openScreenshotsFolder();
void showPreferencesDialog();
void showImageSharedFeedback(bool error, const QString &message);
void sendToClipboard();
......
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