diff --git a/doc/index.docbook b/doc/index.docbook --- a/doc/index.docbook +++ b/doc/index.docbook @@ -207,7 +207,7 @@ Tools - Clicking on this button shows a drop-down menu, offering access to the print dialog. + Clicking on this button shows a drop-down menu, offering access to various functions. You can open the Print dialog, and Open Screenshots Folder is a shortcut to highlight the last saved screenshot in the default file manager. diff --git a/src/ExportManager.h b/src/ExportManager.h --- a/src/ExportManager.h +++ b/src/ExportManager.h @@ -55,6 +55,8 @@ 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 @@ 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 mUsedTempFileNames; diff --git a/src/ExportManager.cpp b/src/ExportManager.cpp --- a/src/ExportManager.cpp +++ b/src/ExportManager.cpp @@ -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 @@ return savePath; } +QUrl ExportManager::lastSavePath() const +{ + return isFileExists(mLastSavePath) ? mLastSavePath : QUrl(); +} + void ExportManager::setSaveLocation(const QString &savePath) { KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); diff --git a/src/Gui/KSMainWindow.h b/src/Gui/KSMainWindow.h --- a/src/Gui/KSMainWindow.h +++ b/src/Gui/KSMainWindow.h @@ -50,6 +50,7 @@ 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(); diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp --- a/src/Gui/KSMainWindow.cpp +++ b/src/Gui/KSMainWindow.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "SettingsDialog/SettingsDialog.h" #include "ExportMenu.h" @@ -149,7 +150,6 @@ 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 @@ 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 @@ 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) {