Skip to content

Commit

Permalink
Add "Reload File" feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Aug 27, 2023
1 parent 9f6c225 commit 4dfdabe
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/actionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ QMenuBar *ActionManager::buildMenuBar(QWidget *parent)
addCloneOfAction(fileMenu, "open");
addCloneOfAction(fileMenu, "openurl");
fileMenu->addMenu(buildRecentsMenu(true, fileMenu));
addCloneOfAction(fileMenu, "reloadfile");
fileMenu->addSeparator();
#ifdef Q_OS_MACOS
fileMenu->addSeparator();
Expand Down Expand Up @@ -585,6 +586,8 @@ void ActionManager::actionTriggered(QAction *triggeredAction, MainWindow *releva
relevantWindow->openWith(openWithItem);
} else if (key == "openurl") {
relevantWindow->pickUrl();
} else if (key == "reloadfile") {
relevantWindow->reloadFile();
} else if (key == "opencontainingfolder") {
relevantWindow->openContainingFolder();
} else if (key == "showfileinfo") {
Expand Down Expand Up @@ -660,6 +663,10 @@ void ActionManager::initializeActionLibrary()
auto *openUrlAction = new QAction(QIcon::fromTheme("document-open-remote", QIcon::fromTheme("folder-remote")), tr("Open &URL..."));
actionLibrary.insert("openurl", openUrlAction);

auto *reloadFileAction = new QAction(QIcon::fromTheme("view-refresh"), tr("Re&load File"));
reloadFileAction->setData({"disable"});
actionLibrary.insert("reloadfile", reloadFileAction);

auto *closeWindowAction = new QAction(QIcon::fromTheme("window-close"), tr("Close Window"));
actionLibrary.insert("closewindow", closeWindowAction);

Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ void MainWindow::pickUrl()
inputDialog->open();
}

void MainWindow::reloadFile()
{
graphicsView->reloadFile();
}

void MainWindow::openWith(const OpenWith::OpenWithItem &openWithItem)
{
OpenWith::openWith(getCurrentFileDetails().fileInfo.absoluteFilePath(), openWithItem);
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class MainWindow : public QMainWindow

void pickUrl();

void reloadFile();

void openContainingFolder();

void openWith(const OpenWith::OpenWithItem &exec);
Expand Down
8 changes: 8 additions & 0 deletions src/qvgraphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ void QVGraphicsView::loadFile(const QString &fileName)
imageCore.loadFile(fileName);
}

void QVGraphicsView::reloadFile()
{
if (!getCurrentFileDetails().isPixmapLoaded)
return;

imageCore.loadFile(getCurrentFileDetails().fileInfo.absoluteFilePath(), true);
}

void QVGraphicsView::postLoad()
{
updateLoadedPixmapItem();
Expand Down
2 changes: 2 additions & 0 deletions src/qvgraphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class QVGraphicsView : public QGraphicsView
void loadMimeData(const QMimeData *mimeData);
void loadFile(const QString &fileName);

void reloadFile();

void zoomIn(const QPoint &pos = QPoint(-1, -1));

void zoomOut(const QPoint &pos = QPoint(-1, -1));
Expand Down
4 changes: 2 additions & 2 deletions src/qvimagecore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ QVImageCore::QVImageCore(QObject *parent) : QObject(parent)
settingsUpdated();
}

void QVImageCore::loadFile(const QString &fileName)
void QVImageCore::loadFile(const QString &fileName, bool isReloading)
{
if (waitingOnLoad)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ void QVImageCore::loadFile(const QString &fileName)
QString cacheKey = getPixmapCacheKey(sanitaryFileName, fileInfo.size(), targetColorSpace);

//check if cached already before loading the long way
auto *cachedData = QVImageCore::pixmapCache.take(cacheKey);
auto *cachedData = isReloading ? nullptr : QVImageCore::pixmapCache.take(cacheKey);
if (cachedData != nullptr)
{
ReadData readData = *cachedData;
Expand Down
2 changes: 1 addition & 1 deletion src/qvimagecore.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class QVImageCore : public QObject

explicit QVImageCore(QObject *parent = nullptr);

void loadFile(const QString &fileName);
void loadFile(const QString &fileName, bool isReloaing = false);
ReadData readFile(const QString &fileName, const QColorSpace &targetColorSpace, bool forCache);
void loadPixmap(const ReadData &readData);
void closeImage();
Expand Down
1 change: 1 addition & 0 deletions src/shortcutmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void ShortcutManager::initializeShortcutsList()
{
shortcutsList.append({tr("Open"), "open", keyBindingsToStringList(QKeySequence::Open), {}});
shortcutsList.append({tr("Open URL"), "openurl", QStringList(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_O).toString()), {}});
shortcutsList.append({tr("Reload File"), "reloadfile", keyBindingsToStringList(QKeySequence::Refresh), {}});
shortcutsList.append({tr("Open Containing Folder"), "opencontainingfolder", {}, {}});
//Sets open containing folder action name to platform-appropriate alternative
#ifdef Q_OS_WIN
Expand Down

0 comments on commit 4dfdabe

Please sign in to comment.