← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1668052-fix-multiselect into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1668052-fix-multiselect into lp:widelands.

Commit message:
Fixed multiselect with shift in tables:
- Send selected signal when selecting with shift.
- More elegant way of detecting ctrl and shift presses.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1668052 in widelands: "Shift doesn't trigger selected signal in tables"
  https://bugs.launchpad.net/widelands/+bug/1668052

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1668052-fix-multiselect/+merge/320760

The savegame details etc are now updated when selecting with shift.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1668052-fix-multiselect into lp:widelands.
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc	2017-02-27 13:45:46 +0000
+++ src/ui_basic/table.cc	2017-03-23 06:22:10 +0000
@@ -71,9 +71,7 @@
      sort_descending_(rowtype == TableRows::kSingleDescending ||
                       rowtype == TableRows::kMultiDescending),
      flexible_column_(std::numeric_limits<size_t>::max()),
-     is_multiselect_(rowtype == TableRows::kMulti || rowtype == TableRows::kMultiDescending),
-     ctrl_down_(false),
-     shift_down_(false) {
+	  is_multiselect_(rowtype == TableRows::kMulti || rowtype == TableRows::kMultiDescending) {
 	set_thinks(false);
 	set_can_focus(true);
 	scrollbar_filler_button_->set_visible(false);
@@ -350,24 +348,10 @@
  * handle key presses
  */
 bool Table<void*>::handle_key(bool down, SDL_Keysym code) {
-	if (is_multiselect_) {
-		switch (code.sym) {
-		case SDLK_LSHIFT:
-		case SDLK_RSHIFT:
-			shift_down_ = down;
-			break;
-		case SDLK_LCTRL:
-		case SDLK_RCTRL:
-			ctrl_down_ = down;
-			break;
-		default:
-			break;
-		}
-	}
 	if (down) {
 		switch (code.sym) {
 		case SDLK_a:
-			if (is_multiselect_ && ctrl_down_ && !empty()) {
+			if (is_multiselect_ && (code.mod & KMOD_CTRL) && !empty()) {
 				multiselect_.clear();
 				for (uint32_t i = 0; i < size(); ++i) {
 					toggle_entry(i);
@@ -424,7 +408,7 @@
 		}
 
 		// Check if doubleclicked
-		if (!ctrl_down_ && !shift_down_ && time - real_last_click_time < DOUBLE_CLICK_INTERVAL &&
+		if (!(SDL_GetModState() & (KMOD_CTRL | KMOD_SHIFT)) && time - real_last_click_time < DOUBLE_CLICK_INTERVAL &&
 		    last_selection_ == selection_ && selection_ != no_selection_index()) {
 			double_clicked(selection_);
 		}
@@ -492,7 +476,7 @@
 void Table<void*>::multiselect(uint32_t row) {
 	if (is_multiselect_) {
 		// Ranged selection with Shift
-		if (shift_down_) {
+		if (SDL_GetModState() & KMOD_SHIFT) {
 			multiselect_.clear();
 			if (has_selection()) {
 				const uint32_t last_selected = selection_index();
@@ -502,12 +486,13 @@
 					toggle_entry(i);
 				}
 				select(last_selected);
+				selected(last_selected);
 			} else {
 				select(toggle_entry(row));
 			}
 		} else {
 			// Single selection without Ctrl
-			if (!ctrl_down_) {
+			if (!(SDL_GetModState() & KMOD_CTRL)) {
 				multiselect_.clear();
 			}
 			select(toggle_entry(row));

=== modified file 'src/ui_basic/table.h'
--- src/ui_basic/table.h	2017-02-27 13:45:46 +0000
+++ src/ui_basic/table.h	2017-03-23 06:22:10 +0000
@@ -313,8 +313,6 @@
 	// This column will grow/shrink depending on the scrollbar being present
 	size_t flexible_column_;
 	bool is_multiselect_;
-	bool ctrl_down_;   // Whether the ctrl key is being pressed
-	bool shift_down_;  // Whether the shift key is being pressed
 
 	void header_button_clicked(Columns::size_type);
 	using EntryRecordVector = std::vector<EntryRecord*>;


Follow ups