summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-13 21:58:30 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-13 21:58:30 +0200
commitf360858836525e4a8305a7596f6ec30f1ef7979b (patch)
tree9aed31915ebdbb4acff317a8e52218e304867506
parentf1c4b65089805463abea187313ea89d74da31e12 (diff)
downloadserenity-f360858836525e4a8305a7596f6ec30f1ef7979b.zip
LibGUI: Tweak selection modification behavior on context menu event
Before bringing up the context menu, clicking... - ...on an already selected item leaves selection alone - ...on an unselected item makes it the only selected item - ...outside any item clears the selection
-rw-r--r--Libraries/LibGUI/GItemView.cpp6
-rw-r--r--Libraries/LibGUI/GTableView.cpp12
2 files changed, 10 insertions, 8 deletions
diff --git a/Libraries/LibGUI/GItemView.cpp b/Libraries/LibGUI/GItemView.cpp
index 096511c0d0..14498d071d 100644
--- a/Libraries/LibGUI/GItemView.cpp
+++ b/Libraries/LibGUI/GItemView.cpp
@@ -105,8 +105,10 @@ void GItemView::context_menu_event(GContextMenuEvent& event)
GModelIndex index;
if (item_index != -1) {
index = model()->index(item_index, m_model_column);
- selection().add(index);
- update();
+ if (!selection().contains(index))
+ selection().set(index);
+ } else {
+ selection().clear();
}
if (on_context_menu_request)
on_context_menu_request(index, event);
diff --git a/Libraries/LibGUI/GTableView.cpp b/Libraries/LibGUI/GTableView.cpp
index 3c61464c42..46fcb17700 100644
--- a/Libraries/LibGUI/GTableView.cpp
+++ b/Libraries/LibGUI/GTableView.cpp
@@ -517,12 +517,12 @@ void GTableView::context_menu_event(GContextMenuEvent& event)
}
auto index = index_at_event_position(event.position());
- if (!index.is_valid())
- return;
- dbgprintf("context menu requested for index (%d,%d) '%s'\n", index.row(), index.column(), model()->data(index).to_string().characters());
-
- selection().set(index);
- update();
+ if (index.is_valid()) {
+ if (!selection().contains(index))
+ selection().set(index);
+ } else {
+ selection().clear();
+ }
if (on_context_menu_request)
on_context_menu_request(index, event);
}