From a53f20314f1c3545ef3e21be60de4d30dad03699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 27 May 2021 22:08:40 +0200 Subject: [PATCH] Improved/fixed data dir changes handling --- src/GUI/filebrowser.cpp | 4 +++- src/GUI/filebrowser.h | 3 +++ src/GUI/gui.cpp | 21 ++++++--------------- src/GUI/gui.h | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/GUI/filebrowser.cpp b/src/GUI/filebrowser.cpp index c1d66238..a864bfbb 100644 --- a/src/GUI/filebrowser.cpp +++ b/src/GUI/filebrowser.cpp @@ -83,8 +83,10 @@ QString FileBrowser::first() void FileBrowser::reloadDirectory(const QString &path) { QDir dir(path); - QFileInfo current = _files.at(_index); + QFileInfo current = (_index >= 0) ? _files.at(_index) : QFileInfo(); _files = dir.entryInfoList(_filter, QDir::Files); _index = _files.empty() ? -1 : _files.indexOf(current); + + emit listChanged(); } diff --git a/src/GUI/filebrowser.h b/src/GUI/filebrowser.h index cddca22d..00a06ce7 100644 --- a/src/GUI/filebrowser.h +++ b/src/GUI/filebrowser.h @@ -25,6 +25,9 @@ public: bool isLast() const; bool isFirst() const; +signals: + void listChanged(); + private slots: void reloadDirectory(const QString &path); diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index 2f3b5d02..9860e297 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -109,6 +109,8 @@ void GUI::createBrowser() { _browser = new FileBrowser(this); _browser->setFilter(Data::filter()); + connect(_browser, &FileBrowser::listChanged, this, + &GUI::updateNavigationActions); } TreeNode GUI::createMapActions() @@ -1791,21 +1793,10 @@ void GUI::graphChanged(int index) void GUI::updateNavigationActions() { - if (_browser->isLast()) { - _nextAction->setEnabled(false); - _lastAction->setEnabled(false); - } else { - _nextAction->setEnabled(true); - _lastAction->setEnabled(true); - } - - if (_browser->isFirst()) { - _prevAction->setEnabled(false); - _firstAction->setEnabled(false); - } else { - _prevAction->setEnabled(true); - _firstAction->setEnabled(true); - } + _lastAction->setEnabled(!_browser->isLast()); + _nextAction->setEnabled(!_browser->isLast()); + _firstAction->setEnabled(!_browser->isFirst()); + _prevAction->setEnabled(!_browser->isFirst()); } bool GUI::updateGraphTabs() diff --git a/src/GUI/gui.h b/src/GUI/gui.h index a01bb7aa..17c27048 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -82,6 +82,7 @@ private slots: void prev(); void last(); void first(); + void updateNavigationActions(); void setTotalTime() {setTimeType(Total);} void setMovingTime() {setTimeType(Moving);} @@ -136,7 +137,6 @@ private: QMenu *menu, const QList &existingActions); void updateStatusBarInfo(); void updateWindowTitle(); - void updateNavigationActions(); bool updateGraphTabs(); TimeType timeType() const;