fixes for multi rank selection, applies ontop of first fix

This commit is contained in:
Sam Tygier 2010-05-27 21:33:39 +01:00
parent 398694e492
commit 3de639d055
2 changed files with 57 additions and 32 deletions

View File

@ -97,7 +97,7 @@ FileCatalog::FileCatalog (CoarsePanel* cp, ToolBar* tb) : listener(NULL), fslist
bRank[i]->set_relief (Gtk::RELIEF_NONE); bRank[i]->set_relief (Gtk::RELIEF_NONE);
buttonBar->pack_start (*bRank[i], Gtk::PACK_SHRINK); buttonBar->pack_start (*bRank[i], Gtk::PACK_SHRINK);
bCateg[i+2] = bRank[i]->signal_toggled().connect (sigc::bind(sigc::mem_fun(*this, &FileCatalog::categoryButtonToggled), bRank[i])); bCateg[i+2] = bRank[i]->signal_toggled().connect (sigc::bind(sigc::mem_fun(*this, &FileCatalog::categoryButtonToggled), bRank[i]));
bRank[i]->signal_button_press_event().connect (sigc::mem_fun(*this, &FileCatalog::on_my_button_press_event),false); bRank[i]->signal_button_press_event().connect (sigc::mem_fun(*this, &FileCatalog::capture_event),false);
} }
bRank[0]->set_tooltip_text (M("FILEBROWSER_SHOWRANK1HINT")); bRank[0]->set_tooltip_text (M("FILEBROWSER_SHOWRANK1HINT"));
bRank[1]->set_tooltip_text (M("FILEBROWSER_SHOWRANK2HINT")); bRank[1]->set_tooltip_text (M("FILEBROWSER_SHOWRANK2HINT"));
@ -183,7 +183,7 @@ FileCatalog::FileCatalog (CoarsePanel* cp, ToolBar* tb) : listener(NULL), fslist
#endif #endif
} }
bool FileCatalog::on_my_button_press_event(GdkEventButton* event){ bool FileCatalog::capture_event(GdkEventButton* event){
// need to record modifiers on the button press, because signal_toggled does not pass the event. // need to record modifiers on the button press, because signal_toggled does not pass the event.
modifierKey = event->state; modifierKey = event->state;
return false; return false;
@ -592,45 +592,70 @@ void FileCatalog::renameRequested (std::vector<FileBrowserEntry*> tbe) {
void FileCatalog::categoryButtonToggled (Gtk::ToggleButton* b) { void FileCatalog::categoryButtonToggled (Gtk::ToggleButton* b) {
for (int i=0; i<8; i++) for (int i=0; i<8; i++)
bCateg[i].block (true); bCateg[i].block (true);
fileBrowser->getScrollPosition (hScrollPos[lastScrollPos], vScrollPos[lastScrollPos]); fileBrowser->getScrollPosition (hScrollPos[lastScrollPos], vScrollPos[lastScrollPos]);
// seek the one pressed //find the number of the button
int toggled_button = 0;
for (int i=0; i<8; i++){
if(categoryButtons[i]==b){
toggled_button = i;
}
}
//was control key pressed
bool control_down = modifierKey & GDK_CONTROL_MASK;
// for a normal switch, untoggle the other buttons
if (!control_down || toggled_button==0 || toggled_button==7){
for (int i=0; i<8; i++) { for (int i=0; i<8; i++) {
if (! (modifierKey & GDK_CONTROL_MASK)){ // if the contol key was not held, then untoggle other ranks categoryButtons[i]->set_active (i==toggled_button);
categoryButtons[i]->set_active (categoryButtons[i]==b);
} }
if (categoryButtons[i]==b) }else{
lastScrollPos = i; // but if we have control clicked a star we need to untoggle non-stars
categoryButtons[0]->set_active(false);
categoryButtons[1]->set_active(false);
categoryButtons[7]->set_active(false);
} }
// if you control so that no stars are toggle on, then toggle on the one you clicked // how we color the buttons depends on how many are selected
// makes behaviour more natural int toggled_count = 0;
if (modifierKey & GDK_CONTROL_MASK){ for (int i=0; i<8; i++) {
int activeCount = 0; if (categoryButtons[i]->get_active())
toggled_count ++;
}
// if we have untoggled all the buttons, set to show all
if (toggled_count == 0){
toggled_button = 0;
categoryButtons[0]->set_active(true);
}
// so set the right images
if (toggled_count == 1){
int n_stars = 0;
// only one button is active, find out which
// if its not a star button, then n_stars stays on zero
for (int i=0; i<5; i++){ for (int i=0; i<5; i++){
if (bRank[i]->get_active()) activeCount ++; if (bRank[i]->get_active())
n_stars = i+1;
} }
if (activeCount == 0){ // color up to the correct rank
b->set_active(); for (int i=0; i<5; i++){
} if (i<n_stars)
} bRank[i]->set_image (*iranked[i]);
else
// change the images of the buttons to reflect current ranking
for (int i=0; i<5; i++)
bRank[i]->set_image (*igranked[i]); bRank[i]->set_image (*igranked[i]);
if (! (modifierKey & GDK_CONTROL_MASK)){ }
for (int i=0; i<5; i++) }else{
if (b==bRank[i]) // if several stars are selected, color them
for (int j=0; j<=i; j++)
bRank[j]->set_image (*iranked[j]);
}else{ // if we are in control clicking mode, then light up the toggle bttons
for (int i=0; i<5; i++){ for (int i=0; i<5; i++){
if(bRank[i]->get_active()) bRank[i]->set_image (*iranked[i]); if (bRank[i]->get_active())
bRank[i]->set_image (*iranked[i]);
else
bRank[i]->set_image (*igranked[i]);
} }
} }

View File

@ -178,7 +178,7 @@ class FileCatalog : public Gtk::VBox,
void setFilterPanel (FilterPanel* fpanel); void setFilterPanel (FilterPanel* fpanel);
void exifInfoButtonToggled(); void exifInfoButtonToggled();
void categoryButtonToggled (Gtk::ToggleButton* b); void categoryButtonToggled (Gtk::ToggleButton* b);
bool on_my_button_press_event(GdkEventButton* event); bool capture_event(GdkEventButton* event);
void filterChanged (); void filterChanged ();
void runFilterDialog (); void runFilterDialog ();