Keyboard navigation in File Browser (issue 1919, on behalf of Adam Reichold)

Select a thumbnail using the arrow keys, select multiple with Shift
This commit is contained in:
michael 2013-07-02 13:33:46 -04:00
parent fbf5a98e1c
commit 01414d0550
4 changed files with 188 additions and 34 deletions

View File

@ -310,12 +310,12 @@ void FileBrowser::rightClicked (ThumbBrowserEntryBase* entry) {
trash->set_sensitive (false); trash->set_sensitive (false);
untrash->set_sensitive (false); untrash->set_sensitive (false);
for (size_t i=0; i<selected.size(); i++) for (size_t i=0; i<selected.size(); i++)
if ((static_cast<FileBrowserEntry*>(selected[i]))->thumbnail->getStage()==1) { if ((static_cast<FileBrowserEntry*>(selected[i]))->thumbnail->getStage()==1) {
untrash->set_sensitive (true); untrash->set_sensitive (true);
break; break;
} }
for (size_t i=0; i<selected.size(); i++) for (size_t i=0; i<selected.size(); i++)
if ((static_cast<FileBrowserEntry*>(selected[i]))->thumbnail->getStage()==0) { if ((static_cast<FileBrowserEntry*>(selected[i]))->thumbnail->getStage()==0) {
trash->set_sensitive (true); trash->set_sensitive (true);
break; break;
@ -331,7 +331,7 @@ void FileBrowser::rightClicked (ThumbBrowserEntryBase* entry) {
int p = 0; int p = 0;
Gtk::Menu* applmenu = Gtk::manage (new Gtk::Menu ()); Gtk::Menu* applmenu = Gtk::manage (new Gtk::Menu ());
std::vector<Glib::ustring> profnames = profileStore.getProfileNames (); std::vector<Glib::ustring> profnames = profileStore.getProfileNames ();
for (size_t i=0; i<profnames.size(); i++) { for (size_t i=0; i<profnames.size(); i++) {
Gtk::MenuItem* mi = Gtk::manage (new Gtk::MenuItem (profnames[i])); Gtk::MenuItem* mi = Gtk::manage (new Gtk::MenuItem (profnames[i]));
applmenu->attach (*mi, 0, 1, p, p+1); p++; applmenu->attach (*mi, 0, 1, p, p+1); p++;
mi->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::applyMenuItemActivated), profnames[i])); mi->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::applyMenuItemActivated), profnames[i]));
@ -343,7 +343,7 @@ void FileBrowser::rightClicked (ThumbBrowserEntryBase* entry) {
p = 0; p = 0;
Gtk::Menu* applpartmenu = Gtk::manage (new Gtk::Menu ()); Gtk::Menu* applpartmenu = Gtk::manage (new Gtk::Menu ());
//std::vector<Glib::ustring> profnames = profileStore.getProfileNames (); // this is already created for submenu applmenu above //std::vector<Glib::ustring> profnames = profileStore.getProfileNames (); // this is already created for submenu applmenu above
for (size_t i=0; i<profnames.size(); i++) { for (size_t i=0; i<profnames.size(); i++) {
Gtk::MenuItem* mi = Gtk::manage (new Gtk::MenuItem (profnames[i])); Gtk::MenuItem* mi = Gtk::manage (new Gtk::MenuItem (profnames[i]));
applpartmenu->attach (*mi, 0, 1, p, p+1); p++; applpartmenu->attach (*mi, 0, 1, p, p+1); p++;
mi->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::applyPartialMenuItemActivated), profnames[i])); mi->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::applyPartialMenuItemActivated), profnames[i]));
@ -404,7 +404,7 @@ struct addparams {
int AddEntryUIThread (void* data) { int AddEntryUIThread (void* data) {
addparams* ap = static_cast<addparams*>(data); addparams* ap = static_cast<addparams*>(data);
FileBrowserIdleHelper* fbih = ap->fbih; FileBrowserIdleHelper* fbih = ap->fbih;
if (fbih->destroyed) { if (fbih->destroyed) {
@ -563,7 +563,7 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) {
MYREADERLOCK(l, entryRW); MYREADERLOCK(l, entryRW);
#endif #endif
for (size_t i=0; i<selected.size(); i++) for (size_t i=0; i<selected.size(); i++)
mselected.push_back (static_cast<FileBrowserEntry*>(selected[i])); mselected.push_back (static_cast<FileBrowserEntry*>(selected[i]));
} }
@ -786,7 +786,7 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) {
else if (m==partpasteprof) else if (m==partpasteprof)
partPasteProfile (); partPasteProfile ();
else if (m==clearprof) { else if (m==clearprof) {
for (size_t i=0; i<mselected.size(); i++) for (size_t i=0; i<mselected.size(); i++)
mselected[i]->thumbnail->clearProcParams (FILEBROWSER); mselected[i]->thumbnail->clearProcParams (FILEBROWSER);
queue_draw (); queue_draw ();
} else if (m==execcustprof) { } else if (m==execcustprof) {
@ -802,12 +802,12 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) {
if (!mselected.empty() && bppcl) if (!mselected.empty() && bppcl)
bppcl->endBatchPParamsChange(); bppcl->endBatchPParamsChange();
} else if (m==clearFromCache) { } else if (m==clearFromCache) {
for (size_t i=0; i<mselected.size(); i++) for (size_t i=0; i<mselected.size(); i++)
tbl->clearFromCacheRequested (mselected, false); tbl->clearFromCacheRequested (mselected, false);
//queue_draw (); //queue_draw ();
} }
else if (m==clearFromCacheFull) { else if (m==clearFromCacheFull) {
for (size_t i=0; i<mselected.size(); i++) for (size_t i=0; i<mselected.size(); i++)
tbl->clearFromCacheRequested (mselected, true); tbl->clearFromCacheRequested (mselected, true);
//queue_draw (); //queue_draw ();
} else if (miOpenDefaultViewer!=NULL && m==miOpenDefaultViewer) { } else if (miOpenDefaultViewer!=NULL && m==miOpenDefaultViewer) {
@ -919,7 +919,7 @@ void FileBrowser::openDefaultViewer (int destination) {
} }
if (!success) { if (!success) {
Gtk::MessageDialog msgd (M("MAIN_MSG_IMAGEUNPROCESSED"), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog msgd (M("MAIN_MSG_IMAGEUNPROCESSED"), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run (); msgd.run ();
} }
} }
@ -970,6 +970,22 @@ bool FileBrowser::keyPressed (GdkEventKey* event) {
FileBrowser::openNextImage (); FileBrowser::openNextImage ();
return true; return true;
} }
else if (event->keyval==GDK_Left) {
selectPrev (1, shift);
return true;
}
else if (event->keyval==GDK_Right) {
selectNext (1, shift);
return true;
}
else if (event->keyval==GDK_Up) {
selectPrev (numOfCols, shift);
return true;
}
else if (event->keyval==GDK_Down) {
selectNext (numOfCols, shift);
return true;
}
else if (event->keyval==GDK_F5) { else if (event->keyval==GDK_F5) {
int dest = 1; int dest = 1;
@ -1065,7 +1081,7 @@ void FileBrowser::applyMenuItemActivated (Glib::ustring ppname) {
if (partProfile->pparams && !selected.empty()) { if (partProfile->pparams && !selected.empty()) {
if (bppcl) if (bppcl)
bppcl->beginBatchPParamsChange(selected.size()); bppcl->beginBatchPParamsChange(selected.size());
for (size_t i=0; i<selected.size(); i++) for (size_t i=0; i<selected.size(); i++)
(static_cast<FileBrowserEntry*>(selected[i]))->thumbnail->setProcParams (*partProfile->pparams, partProfile->pedited, FILEBROWSER); (static_cast<FileBrowserEntry*>(selected[i]))->thumbnail->setProcParams (*partProfile->pparams, partProfile->pedited, FILEBROWSER);
if (bppcl) if (bppcl)
bppcl->endBatchPParamsChange(); bppcl->endBatchPParamsChange();
@ -1090,7 +1106,7 @@ void FileBrowser::applyPartialMenuItemActivated (Glib::ustring ppname) {
if (bppcl) if (bppcl)
bppcl->beginBatchPParamsChange(selected.size()); bppcl->beginBatchPParamsChange(selected.size());
for (size_t i=0; i<selected.size(); i++) { for (size_t i=0; i<selected.size(); i++) {
selected[i]->thumbnail->createProcParamsForUpdate(false, false); // this can execute customprofilebuilder to generate param file selected[i]->thumbnail->createProcParamsForUpdate(false, false); // this can execute customprofilebuilder to generate param file
rtengine::procparams::PartialProfile dstProfile(true); rtengine::procparams::PartialProfile dstProfile(true);
@ -1213,7 +1229,7 @@ bool FileBrowser::checkFilter (ThumbBrowserEntryBase* entryb) { // true -> entry
void FileBrowser::toTrashRequested (std::vector<FileBrowserEntry*> tbe) { void FileBrowser::toTrashRequested (std::vector<FileBrowserEntry*> tbe) {
for (size_t i=0; i<tbe.size(); i++) { for (size_t i=0; i<tbe.size(); i++) {
// try to load the last saved parameters from the cache or from the paramfile file // try to load the last saved parameters from the cache or from the paramfile file
tbe[i]->thumbnail->createProcParamsForUpdate(false, false); // this can execute customprofilebuilder to generate param file tbe[i]->thumbnail->createProcParamsForUpdate(false, false); // this can execute customprofilebuilder to generate param file
@ -1235,7 +1251,7 @@ void FileBrowser::toTrashRequested (std::vector<FileBrowserEntry*> tbe) {
void FileBrowser::fromTrashRequested (std::vector<FileBrowserEntry*> tbe) { void FileBrowser::fromTrashRequested (std::vector<FileBrowserEntry*> tbe) {
for (size_t i=0; i<tbe.size(); i++) { for (size_t i=0; i<tbe.size(); i++) {
// if thumbnail was marked inTrash=true then param file must be there, no need to run customprofilebuilder // if thumbnail was marked inTrash=true then param file must be there, no need to run customprofilebuilder
if (tbe[i]->thumbnail->getStage()==0) if (tbe[i]->thumbnail->getStage()==0)

View File

@ -14,18 +14,18 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>. * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <glibmm.h> #include <glibmm.h>
#include "../rtengine/rt_math.h" #include "../rtengine/rt_math.h"
#include "thumbbrowserbase.h" #include "thumbbrowserbase.h"
#include "multilangmgr.h" #include "multilangmgr.h"
#include "options.h" #include "options.h"
#include "../rtengine/mytime.h" #include "../rtengine/mytime.h"
using namespace std; using namespace std;
ThumbBrowserBase::ThumbBrowserBase () ThumbBrowserBase::ThumbBrowserBase ()
: lastClicked(NULL), previewHeight(options.thumbSize) { : lastClicked(NULL), previewHeight(options.thumbSize), numOfCols(1) {
inTabMode=false; // corresponding to take thumbSize inTabMode=false; // corresponding to take thumbSize
inW = -1; inH = -1; inW = -1; inH = -1;
@ -91,6 +91,137 @@ void ThumbBrowserBase::scrollPage (int direction) {
hscroll.set_value (hscroll.get_value() + (direction==GDK_SCROLL_DOWN ? +1 : -1) * hscroll.get_adjustment()->get_page_increment()); hscroll.set_value (hscroll.get_value() + (direction==GDK_SCROLL_DOWN ? +1 : -1) * hscroll.get_adjustment()->get_page_increment());
} }
static void scrollToEntry (double& h, double& v, int iw, int ih, ThumbBrowserEntryBase* entry) {
const int hmin = entry->getX ();
const int hmax = hmin + entry->getEffectiveWidth () - iw;
const int vmin = entry->getY ();
const int vmax = vmin + entry->getEffectiveHeight () - ih;
if (hmin < 0)
h += hmin;
else if (hmax > 0)
h += hmax;
if(vmin < 0)
v += vmin;
else if (vmax > 0)
v += vmax;
}
void ThumbBrowserBase::selectPrev (int distance, bool enlarge) {
double h, v;
getScrollPosition (h, v);
{
#if PROTECT_VECTORS
MYWRITERLOCK(l, entryRW);
#endif
if (!selected.empty ()) {
std::vector<ThumbBrowserEntryBase*>::iterator front = std::find (fd.begin (), fd.end (), selected.front ());
std::vector<ThumbBrowserEntryBase*>::iterator back = std::find (fd.begin (), fd.end (), selected.back ());
if(front > back)
std::swap(front, back);
// find next thumbnail at filtered distance before 'front'
for (; front >= fd.begin (); --front) {
if(!(*front)->filtered) {
if (distance-- == 0) {
// clear current selection
for (size_t i=0; i<selected.size (); ++i) {
selected[i]->selected = false;
redrawNeeded (selected[i]);
}
selected.clear ();
// make sure the newly selected thumbnail is visible
scrollToEntry (h, v, internal.get_width (), internal.get_height (), *front);
// either enlarge current selection or set new selection
for(; front <= back; ++front) {
if(!(*front)->filtered) {
(*front)->selected = true;
redrawNeeded (*front);
selected.push_back (*front);
}
if(!enlarge)
break;
}
break;
}
}
}
}
#if PROTECT_VECTORS
MYWRITERLOCK_RELEASE(l);
#endif
selectionChanged ();
}
setScrollPosition (h, v);
}
void ThumbBrowserBase::selectNext (int distance, bool enlarge) {
double h, v;
getScrollPosition (h, v);
{
#if PROTECT_VECTORS
MYWRITERLOCK(l, entryRW);
#endif
if (!selected.empty ()) {
std::vector<ThumbBrowserEntryBase*>::iterator front = std::find (fd.begin (), fd.end (), selected.front ());
std::vector<ThumbBrowserEntryBase*>::iterator back = std::find (fd.begin (), fd.end (), selected.back ());
if(front > back)
std::swap(front, back);
// find next thumbnail at filtered distance after 'back'
for (; back < fd.end (); ++back) {
if(!(*back)->filtered) {
if (distance-- == 0) {
// clear current selection
for (size_t i=0; i<selected.size (); ++i) {
selected[i]->selected = false;
redrawNeeded (selected[i]);
}
selected.clear ();
// make sure the newly selected thumbnail is visible
scrollToEntry (h, v, internal.get_width (), internal.get_height (), *back);
// either enlarge current selection or set new selection
for(; back >= front; --back) {
if(!(*back)->filtered) {
(*back)->selected = true;
redrawNeeded (*back);
selected.push_back (*back);
}
if(!enlarge)
break;
}
break;
}
}
}
}
#if PROTECT_VECTORS
MYWRITERLOCK_RELEASE(l);
#endif
selectionChanged ();
}
setScrollPosition (h, v);
}
void ThumbBrowserBase::resizeThumbnailArea (int w, int h) { void ThumbBrowserBase::resizeThumbnailArea (int w, int h) {
inW = w; inW = w;
@ -167,7 +298,7 @@ void ThumbBrowserBase::arrangeFiles () {
rowHeight = fd[i]->getMinimalHeight (); rowHeight = fd[i]->getMinimalHeight ();
if (arrangement==TB_Horizontal) { if (arrangement==TB_Horizontal) {
numOfCols = 1;
int numOfRows = 1; int numOfRows = 1;
// if (rowHeight>0) { // if (rowHeight>0) {
// numOfRows = (internal.get_height()+rowHeight/2)/rowHeight; // numOfRows = (internal.get_height()+rowHeight/2)/rowHeight;
@ -206,7 +337,7 @@ void ThumbBrowserBase::arrangeFiles () {
else { else {
int availWidth = internal.get_width(); int availWidth = internal.get_width();
// initial number of columns // initial number of columns
int numOfCols = 0; numOfCols = 0;
int colsWidth = 0; int colsWidth = 0;
for (int i=0; i<N; i++) for (int i=0; i<N; i++)
if (!fd[i]->filtered && colsWidth + fd[i]->getMinimalWidth() <= availWidth) { if (!fd[i]->filtered && colsWidth + fd[i]->getMinimalWidth() <= availWidth) {
@ -285,7 +416,7 @@ bool ThumbBrowserBase::Internal::on_query_tooltip (int x, int y, bool keyboard_t
MYREADERLOCK(l, parent->entryRW); MYREADERLOCK(l, parent->entryRW);
#endif #endif
for (size_t i=0; i<parent->fd.size(); i++) for (size_t i=0; i<parent->fd.size(); i++)
if (parent->fd[i]->drawable && parent->fd[i]->inside (x, y)) { if (parent->fd[i]->drawable && parent->fd[i]->inside (x, y)) {
ttip = parent->fd[i]->getToolTip (x, y); ttip = parent->fd[i]->getToolTip (x, y);
break; break;
@ -383,18 +514,18 @@ void ThumbBrowserBase::buttonPressed (int x, int y, int button, GdkEventType typ
} }
else { else {
// find the start and the end of the selection interval // find the start and the end of the selection interval
size_t startx = fd.size()-1; size_t startx = fd.size()-1;
if (lastClicked) { if (lastClicked) {
for (; startx>0; startx--) for (; startx>0; startx--)
if (fd[startx]==lastClicked) if (fd[startx]==lastClicked)
break; break;
} }
else { else {
for (; startx>0; startx--) for (; startx>0; startx--)
if (fd[startx]==selected[0]) if (fd[startx]==selected[0])
break; break;
} }
size_t endx = 0; size_t endx = 0;
for (; endx<fd.size(); endx++) for (; endx<fd.size(); endx++)
if (fd[endx]==fileDescr) if (fd[endx]==fileDescr)
break; break;
@ -404,7 +535,7 @@ void ThumbBrowserBase::buttonPressed (int x, int y, int button, GdkEventType typ
startx = tmp; startx = tmp;
} }
// clear current selection // clear current selection
for (size_t i=0; i<selected.size(); i++) for (size_t i=0; i<selected.size(); i++)
selected[i]->selected = false; selected[i]->selected = false;
selected.clear (); selected.clear ();
// select thumbnails in the interval // select thumbnails in the interval
@ -515,7 +646,7 @@ bool ThumbBrowserBase::Internal::on_button_release_event (GdkEventButton* event)
MYREADERLOCK(l, parent->entryRW); MYREADERLOCK(l, parent->entryRW);
#endif #endif
for (size_t i=0; i<parent->fd.size(); i++) for (size_t i=0; i<parent->fd.size(); i++)
if (parent->fd[i]->drawable && parent->fd[i]->insideWindow (0, 0, w, h)) { if (parent->fd[i]->drawable && parent->fd[i]->insideWindow (0, 0, w, h)) {
ThumbBrowserEntryBase* tbe = parent->fd[i]; ThumbBrowserEntryBase* tbe = parent->fd[i];
#if PROTECT_VECTORS #if PROTECT_VECTORS
@ -539,7 +670,7 @@ bool ThumbBrowserBase::Internal::on_motion_notify_event (GdkEventMotion* event)
MYREADERLOCK(l, parent->entryRW); MYREADERLOCK(l, parent->entryRW);
#endif #endif
for (size_t i=0; i<parent->fd.size(); i++) for (size_t i=0; i<parent->fd.size(); i++)
if (parent->fd[i]->drawable && parent->fd[i]->insideWindow (0, 0, w, h)) { if (parent->fd[i]->drawable && parent->fd[i]->insideWindow (0, 0, w, h)) {
/*#if PROTECT_VECTORS /*#if PROTECT_VECTORS
MYREADERLOCK_RELEASE(l); // motionNotify calls the queue, which locks MYREADERLOCK_RELEASE(l); // motionNotify calls the queue, which locks
@ -629,7 +760,7 @@ void ThumbBrowserBase::refreshEditedState (const std::set<Glib::ustring>& efiles
MYREADERLOCK(l, entryRW); MYREADERLOCK(l, entryRW);
#endif #endif
for (size_t i=0; i<fd.size(); i++) for (size_t i=0; i<fd.size(); i++)
fd[i]->framed = editedFiles.find (fd[i]->filename)!=editedFiles.end(); fd[i]->framed = editedFiles.find (fd[i]->filename)!=editedFiles.end();
} }
@ -672,11 +803,11 @@ void ThumbBrowserBase::enableTabMode(bool enable) {
#endif #endif
hscroll.set_value (min(h, hscroll.get_adjustment()->get_upper())); hscroll.set_value (min(h, hscroll.get_adjustment()->get_upper()));
} else { } else {
double v=selected[0]->getStartY(); double v=selected[0]->getStartY();
#if PROTECT_VECTORS #if PROTECT_VECTORS
MYREADERLOCK_RELEASE(l); MYREADERLOCK_RELEASE(l);
#endif #endif
vscroll.set_value (min(v, vscroll.get_adjustment()->get_upper())); vscroll.set_value (min(v, vscroll.get_adjustment()->get_upper()));
} }
} }
} }
@ -705,7 +836,7 @@ int ThumbBrowserBase::getEffectiveHeight() {
#endif #endif
// Filtered items do not change in size, so take a non-filtered // Filtered items do not change in size, so take a non-filtered
for (size_t i=0;i<fd.size();i++) for (size_t i=0;i<fd.size();i++)
if (!fd[i]->filtered) { if (!fd[i]->filtered) {
h+=fd[i]->getEffectiveHeight(); h+=fd[i]->getEffectiveHeight();
break; break;

View File

@ -78,6 +78,9 @@ class ThumbBrowserBase : public Gtk::VBox {
void scroll (int direction); void scroll (int direction);
void scrollPage (int direction); void scrollPage (int direction);
void selectPrev(int distance, bool enlarge);
void selectNext(int distance, bool enlarge);
protected: protected:
int eventTime; int eventTime;
@ -88,6 +91,7 @@ class ThumbBrowserBase : public Gtk::VBox {
ThumbBrowserEntryBase* lastClicked; ThumbBrowserEntryBase* lastClicked;
int previewHeight; int previewHeight;
int numOfCols;
Arrangement arrangement; Arrangement arrangement;

View File

@ -110,10 +110,13 @@ protected:
int getMinimalHeight () { return height; } int getMinimalHeight () { return height; }
int getMinimalWidth () { return width; } int getMinimalWidth () { return width; }
int getEffectiveWidth () const { return exp_width; }
int getEffectiveHeight () const { return exp_height; } int getEffectiveHeight () const { return exp_height; }
int getPreviewHeight () const { return preh; } int getPreviewHeight () const { return preh; }
int getStartX () const { return startx; } int getStartX () const { return startx; }
int getStartY () const { return starty; } int getStartY () const { return starty; }
int getX () const { return ofsX+startx; }
int getY () const { return ofsY+starty; }
bool inside (int x, int y); bool inside (int x, int y);
bool insideWindow (int x, int y, int w, int h); bool insideWindow (int x, int y, int w, int h);