From 0f0dc03849b7d4c8b50f2d121d23e205f1db5845 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Mon, 29 Jul 2019 15:21:23 +0200 Subject: [PATCH 1/4] Fix broken thumbnail butto tooltips --- rtgui/batchqueueentry.cc | 8 +++++--- rtgui/batchqueueentry.h | 2 +- rtgui/thumbbrowserbase.cc | 12 ++++++++---- rtgui/thumbbrowserentrybase.cc | 5 +++-- rtgui/thumbbrowserentrybase.h | 4 ++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/rtgui/batchqueueentry.cc b/rtgui/batchqueueentry.cc index a5dfb6dde..23982095c 100644 --- a/rtgui/batchqueueentry.cc +++ b/rtgui/batchqueueentry.cc @@ -168,10 +168,12 @@ void BatchQueueEntry::getIconSize (int& w, int& h) const } -Glib::ustring BatchQueueEntry::getToolTip (int x, int y) const +std::tuple BatchQueueEntry::getToolTip (int x, int y) const { // get the parent class' tooltip first - Glib::ustring tooltip = ThumbBrowserEntryBase::getToolTip(x, y); + Glib::ustring tooltip; + bool useMarkup; + std::tie(tooltip, useMarkup) = ThumbBrowserEntryBase::getToolTip(x, y); // add the saving param options if (!outFileName.empty()) { @@ -198,7 +200,7 @@ Glib::ustring BatchQueueEntry::getToolTip (int x, int y) const } } - return tooltip; + return std::make_tuple(std::move(tooltip), useMarkup); } diff --git a/rtgui/batchqueueentry.h b/rtgui/batchqueueentry.h index d13dfe827..0ea56e403 100644 --- a/rtgui/batchqueueentry.h +++ b/rtgui/batchqueueentry.h @@ -70,7 +70,7 @@ public: std::vector> getIconsOnImageArea () override; void getIconSize (int& w, int& h) const override; - Glib::ustring getToolTip (int x, int y) const override; + std::tuple getToolTip (int x, int y) const override; // bqentryupdatelistener interface void updateImage (guint8* img, int w, int h, int origw, int origh, guint8* newOPreview) override; diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index dba5390c1..f637015bc 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -745,20 +745,24 @@ void ThumbBrowserBase::Internal::on_realize() bool ThumbBrowserBase::Internal::on_query_tooltip (int x, int y, bool keyboard_tooltip, const Glib::RefPtr& tooltip) { // Gtk signals automatically acquire the GUI (i.e. this method is enclosed by gdk_thread_enter and gdk_thread_leave) - Glib::ustring ttip = ""; - + Glib::ustring ttip; + boolean useMarkup = false; { MYREADERLOCK(l, parent->entryRW); for (size_t i = 0; i < parent->fd.size(); i++) if (parent->fd[i]->drawable && parent->fd[i]->inside (x, y)) { - ttip = parent->fd[i]->getToolTip (x, y); + std::tie(ttip, useMarkup) = parent->fd[i]->getToolTip (x, y); break; } } if (!ttip.empty()) { - tooltip->set_text(ttip); + if (useMarkup) { + tooltip->set_markup(ttip); + } else { + tooltip->set_text(ttip); + } return true; } else { return false; diff --git a/rtgui/thumbbrowserentrybase.cc b/rtgui/thumbbrowserentrybase.cc index f9e2b41b5..e660e794b 100644 --- a/rtgui/thumbbrowserentrybase.cc +++ b/rtgui/thumbbrowserentrybase.cc @@ -724,7 +724,7 @@ bool ThumbBrowserEntryBase::releaseNotify (int button, int type, int bstate, int return buttonSet ? buttonSet->releaseNotify (x, y) : false; } -Glib::ustring ThumbBrowserEntryBase::getToolTip (int x, int y) const +std::tuple ThumbBrowserEntryBase::getToolTip (int x, int y) const { Glib::ustring tooltip; @@ -734,6 +734,7 @@ Glib::ustring ThumbBrowserEntryBase::getToolTip (int x, int y) const // Always show the filename in the tooltip since the filename in the thumbnail could be truncated. // If "Show Exif info" is disabled, also show Exif info in the tooltip. + bool useMarkup = !tooltip.empty(); if (inside(x, y) && tooltip.empty()) { tooltip = dispname; @@ -748,7 +749,7 @@ Glib::ustring ThumbBrowserEntryBase::getToolTip (int x, int y) const } } - return tooltip; + return std::make_tuple(std::move(tooltip), useMarkup); } diff --git a/rtgui/thumbbrowserentrybase.h b/rtgui/thumbbrowserentrybase.h index 12e64c60d..6cbcb37d0 100644 --- a/rtgui/thumbbrowserentrybase.h +++ b/rtgui/thumbbrowserentrybase.h @@ -19,7 +19,7 @@ #pragma once #include - +#include #include #include "cursormanager.h" @@ -190,7 +190,7 @@ public: virtual bool motionNotify (int x, int y); virtual bool pressNotify (int button, int type, int bstate, int x, int y); virtual bool releaseNotify (int button, int type, int bstate, int x, int y); - virtual Glib::ustring getToolTip (int x, int y) const; + virtual std::tuple getToolTip (int x, int y) const; inline ThumbBrowserEntryBase* getOriginal() const { From 287bd5bbe31d5e7595c06c16434aa0dc995cdf35 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Mon, 29 Jul 2019 23:05:01 +0200 Subject: [PATCH 2/4] boolean > bool --- rtgui/thumbbrowserbase.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index f637015bc..53b5828aa 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -746,7 +746,7 @@ bool ThumbBrowserBase::Internal::on_query_tooltip (int x, int y, bool keyboard_t { // Gtk signals automatically acquire the GUI (i.e. this method is enclosed by gdk_thread_enter and gdk_thread_leave) Glib::ustring ttip; - boolean useMarkup = false; + bool useMarkup = false; { MYREADERLOCK(l, parent->entryRW); From 6b868a8d4d7b9f0ac1efbb19284dfd2cb91aba84 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Tue, 30 Jul 2019 13:22:15 +0200 Subject: [PATCH 3/4] Make thumbnail range-selection more similar to OS behaviour, fixes #5393 --- rtgui/filebrowser.cc | 1 + rtgui/thumbbrowserbase.cc | 26 +++++++++++++------------- rtgui/thumbbrowserbase.h | 1 + 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index cc215e70a..b968a285e 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -667,6 +667,7 @@ void FileBrowser::close () MYWRITERLOCK(l, entryRW); selected.clear (); + anchor = nullptr; MYWRITERLOCK_RELEASE(l); // notifySelectionListener will need read access! diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index 53b5828aa..71f9e4a04 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -28,7 +28,7 @@ using namespace std; ThumbBrowserBase::ThumbBrowserBase () - : location(THLOC_FILEBROWSER), inspector(nullptr), isInspectorActive(false), eventTime(0), lastClicked(nullptr), previewHeight(options.thumbSize), numOfCols(1), arrangement(TB_Horizontal) + : location(THLOC_FILEBROWSER), inspector(nullptr), isInspectorActive(false), eventTime(0), lastClicked(nullptr), anchor(nullptr), previewHeight(options.thumbSize), numOfCols(1), arrangement(TB_Horizontal) { inW = -1; inH = -1; @@ -162,30 +162,29 @@ inline void removeFromSelection (const ThumbIterator& iterator, ThumbVector& sel void ThumbBrowserBase::selectSingle (ThumbBrowserEntryBase* clicked) { - clearSelection (selected); + clearSelection(selected); + anchor = clicked; - if (clicked) - addToSelection (clicked, selected); + if (clicked) { + addToSelection(clicked, selected); + } } void ThumbBrowserBase::selectRange (ThumbBrowserEntryBase* clicked, bool additional) { - if (selected.empty()) { + if (selected.empty() && !anchor) { addToSelection(clicked, selected); + anchor = clicked; return; } if (!additional || !lastClicked) { // Extend the current range w.r.t to first selected entry. - ThumbIterator front = std::find(fd.begin(), fd.end(), selected.front()); - ThumbIterator back; - ThumbIterator current = std::find(fd.begin(), fd.end(), clicked); + ThumbIterator back = std::find(fd.begin(), fd.end(), clicked); + ThumbIterator front = std::find(fd.begin(), fd.end(), anchor); - if (front > current) { - front = current; - back = std::find(fd.begin(), fd.end(), selected.back()); - } else { - back = current; + if (front > back) { + std::swap(front, back); } clearSelection(selected); @@ -217,6 +216,7 @@ void ThumbBrowserBase::selectSet (ThumbBrowserEntryBase* clicked) } else { addToSelection (clicked, selected); } + anchor = clicked; } static void scrollToEntry (double& h, double& v, int iw, int ih, ThumbBrowserEntryBase* entry) diff --git a/rtgui/thumbbrowserbase.h b/rtgui/thumbbrowserbase.h index ae561db43..953ec44ec 100644 --- a/rtgui/thumbbrowserbase.h +++ b/rtgui/thumbbrowserbase.h @@ -171,6 +171,7 @@ protected: std::vector fd; std::vector selected; ThumbBrowserEntryBase* lastClicked; + ThumbBrowserEntryBase* anchor; int previewHeight; int numOfCols; From f85de946e63b4668716bceddade50b772037d6c3 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Tue, 30 Jul 2019 14:44:18 +0200 Subject: [PATCH 4/4] Fix some corner cases in thumb selection, #5393 --- rtgui/filebrowser.cc | 25 ++++++++++++++++--------- rtgui/thumbbrowserbase.cc | 20 +++++++++++--------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index b968a285e..eb85613ee 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -783,16 +783,20 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) { MYWRITERLOCK(l, entryRW); - selected.clear (); + selected.clear(); - for (size_t i = 0; i < fd.size(); i++) - if (checkFilter (fd[i])) { + for (size_t i = 0; i < fd.size(); ++i) { + if (checkFilter(fd[i])) { fd[i]->selected = true; - selected.push_back (fd[i]); + selected.push_back(fd[i]); } + } + if (!anchor && !selected.empty()) { + anchor = selected[0]; + } } queue_draw (); - notifySelectionListener (); + notifySelectionListener(); } else if( m == copyTo) { tbl->copyMoveRequested (mselected, false); } @@ -1438,12 +1442,12 @@ void FileBrowser::applyFilter (const BrowserFilter& filter) } for (size_t i = 0; i < fd.size(); i++) { - if (checkFilter (fd[i])) { + if (checkFilter(fd[i])) { numFiltered++; - } else if (fd[i]->selected ) { + } else if (fd[i]->selected) { fd[i]->selected = false; - std::vector::iterator j = std::find (selected.begin(), selected.end(), fd[i]); - selected.erase (j); + std::vector::iterator j = std::find(selected.begin(), selected.end(), fd[i]); + selected.erase(j); if (lastClicked == fd[i]) { lastClicked = nullptr; @@ -1452,6 +1456,9 @@ void FileBrowser::applyFilter (const BrowserFilter& filter) selchanged = true; } } + if (selected.empty() || (anchor && std::find(selected.begin(), selected.end(), anchor) == selected.end())) { + anchor = nullptr; + } } if (selchanged) { diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index 71f9e4a04..20a7d3e44 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -172,16 +172,18 @@ void ThumbBrowserBase::selectSingle (ThumbBrowserEntryBase* clicked) void ThumbBrowserBase::selectRange (ThumbBrowserEntryBase* clicked, bool additional) { - if (selected.empty() && !anchor) { - addToSelection(clicked, selected); + if (!anchor) { anchor = clicked; - return; + if (selected.empty()) { + addToSelection(clicked, selected); + return; + } } if (!additional || !lastClicked) { // Extend the current range w.r.t to first selected entry. ThumbIterator back = std::find(fd.begin(), fd.end(), clicked); - ThumbIterator front = std::find(fd.begin(), fd.end(), anchor); + ThumbIterator front = anchor == clicked ? back : std::find(fd.begin(), fd.end(), anchor); if (front > back) { std::swap(front, back); @@ -195,7 +197,7 @@ void ThumbBrowserBase::selectRange (ThumbBrowserEntryBase* clicked, bool additio } else { // Add an additional range w.r.t. the last clicked entry. ThumbIterator last = std::find(fd.begin(), fd.end(), lastClicked); - ThumbIterator current = std::find (fd.begin(), fd.end(), clicked); + ThumbIterator current = std::find(fd.begin(), fd.end(), clicked); if (last > current) { std::swap(last, current); @@ -209,12 +211,12 @@ void ThumbBrowserBase::selectRange (ThumbBrowserEntryBase* clicked, bool additio void ThumbBrowserBase::selectSet (ThumbBrowserEntryBase* clicked) { - const ThumbIterator iterator = std::find (selected.begin (), selected.end (), clicked); + const ThumbIterator iterator = std::find(selected.begin(), selected.end(), clicked); - if (iterator != selected.end ()) { - removeFromSelection (iterator, selected); + if (iterator != selected.end()) { + removeFromSelection(iterator, selected); } else { - addToSelection (clicked, selected); + addToSelection(clicked, selected); } anchor = clicked; }