[dconf-editor] Open row's popover on Menu key press.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Open row's popover on Menu key press.
- Date: Wed, 11 May 2016 01:42:00 +0000 (UTC)
commit 9e74368351e9bdc4c0c67f3c354b0b0dcbc876e6
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed May 11 03:41:14 2016 +0200
Open row's popover on Menu key press.
editor/dconf-window.vala | 45 ++++++++++++++++++++++++++++++++++++++-
editor/help-overlay.ui | 7 ++++++
editor/key-list-box-row.vala | 47 +++++++++++++++++++++++++++++++++--------
3 files changed, 88 insertions(+), 11 deletions(-)
---
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 6edb928..69bcf64 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -305,6 +305,14 @@ class DConfWindow : ApplicationWindow
* * Search box
\*/
+ private void discard_row_popover ()
+ {
+ ListBoxRow? selected_row = (ListBoxRow) key_list_box.get_selected_row ();
+ if (selected_row == null)
+ return;
+ ((ClickableListBoxRow) ((!) selected_row).get_child ()).hide_right_click_popover ();
+ }
+
[GtkCallback]
private bool on_key_press_event (Widget widget, Gdk.EventKey event) // TODO better?
{
@@ -317,16 +325,19 @@ class DConfWindow : ApplicationWindow
case "b":
if (info_button.active)
info_button.active = false;
+ discard_row_popover ();
bookmarks_button.clicked ();
return true;
case "d":
if (info_button.active)
info_button.active = false;
+ discard_row_popover ();
bookmarks_button.set_bookmarked (true);
return true;
case "D":
if (info_button.active)
info_button.active = false;
+ discard_row_popover ();
bookmarks_button.set_bookmarked (false);
return true;
case "f":
@@ -334,17 +345,21 @@ class DConfWindow : ApplicationWindow
bookmarks_button.active = false;
if (info_button.active)
info_button.active = false;
+ discard_row_popover ();
search_bar.set_search_mode (!search_bar.get_search_mode ());
return true;
case "c":
+ discard_row_popover (); // TODO avoid duplicate get_selected_row () call
ListBoxRow? selected_row = (ListBoxRow) key_list_box.get_selected_row ();
ConfigurationEditor application = (ConfigurationEditor) get_application ();
application.copy (selected_row == null ? current_path : ((ClickableListBoxRow) ((!)
selected_row).get_child ()).get_text ());
return true;
case "C":
+ discard_row_popover ();
((ConfigurationEditor) get_application ()).copy (current_path);
return true;
case "F1":
+ discard_row_popover ();
if ((event.state & Gdk.ModifierType.SHIFT_MASK) == 0)
return false; // help overlay
((ConfigurationEditor) get_application ()).about_cb ();
@@ -353,11 +368,36 @@ class DConfWindow : ApplicationWindow
break; // TODO make <ctrl>v work; https://bugzilla.gnome.org/show_bug.cgi?id=762257 is
WONTFIX
}
}
- else if (name == "F10")
+
+ /* don't use "else if", or some widgets will not be hidden on <ctrl>F10 or such things */
+ if (name == "F10")
{
- bookmarks_button.active = false;
+ discard_row_popover ();
+ if (bookmarks_button.active)
+ bookmarks_button.active = false;
return false;
}
+ else if (name == "Menu")
+ {
+ ListBoxRow? selected_row = (ListBoxRow) key_list_box.get_selected_row ();
+ if (selected_row != null)
+ {
+ if (bookmarks_button.active)
+ bookmarks_button.active = false;
+ if (info_button.active)
+ info_button.active = false;
+ ((ClickableListBoxRow) ((!) selected_row).get_child ()).show_right_click_popover ();
+ }
+ else if (info_button.active == false)
+ {
+ if (bookmarks_button.active)
+ bookmarks_button.active = false;
+ info_button.active = true;
+ }
+ else
+ info_button.active = false;
+ return true;
+ }
if (bookmarks_button.active || info_button.active) // TODO open bug about modal popovers and
search_bar
return false;
@@ -368,6 +408,7 @@ class DConfWindow : ApplicationWindow
[GtkCallback]
private void on_menu_button_clicked ()
{
+ discard_row_popover ();
search_bar.set_search_mode (false);
}
diff --git a/editor/help-overlay.ui b/editor/help-overlay.ui
index c9d3548..027c649 100644
--- a/editor/help-overlay.ui
+++ b/editor/help-overlay.ui
@@ -44,6 +44,13 @@
<property name="accelerator">F10</property>
</object>
</child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes" context="shortcut window">Current row
menu</property>
+ <property name="accelerator">Menu</property>
+ </object>
+ </child>
</object>
</child>
<child>
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 910cad4..7c5ace8 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -39,22 +39,41 @@ private abstract class ClickableListBoxRow : EventBox
public override bool button_press_event (Gdk.EventButton event) // list_box_row selection is done
elsewhere
{
if (event.button == Gdk.BUTTON_SECONDARY)
+ show_right_click_popover ((int) (event.x - this.get_allocated_width () / 2.0));
+
+ return false;
+ }
+
+ public void hide_right_click_popover ()
+ {
+ if (nullable_popover != null)
+ ((!) nullable_popover).hide ();
+ }
+
+ public void show_right_click_popover (int event_x = 0)
+ {
+ if (nullable_popover == null)
{
nullable_popover = new ContextPopover ();
if (!generate_popover ((!) nullable_popover))
- return false;
+ {
+ ((!) nullable_popover).destroy (); // TODO better, again
+ return;
+ }
+
+ ((!) nullable_popover).destroy.connect (() => { nullable_popover = null; });
((!) nullable_popover).set_relative_to (this);
((!) nullable_popover).position = PositionType.BOTTOM; // TODO better
-
- Gdk.Rectangle rect;
- ((!) nullable_popover).get_pointing_to (out rect);
- rect.x = (int) (event.x - this.get_allocated_width () / 2.0);
- ((!) nullable_popover).set_pointing_to (rect);
- ((!) nullable_popover).show ();
}
-
- return false;
+ else if ((!) nullable_popover.visible)
+ warning ("show_right_click_popover() called but popover is visible"); // TODO is called on
multi-right-click or long Menu key press
+
+ Gdk.Rectangle rect;
+ ((!) nullable_popover).get_pointing_to (out rect);
+ rect.x = event_x;
+ ((!) nullable_popover).set_pointing_to (rect);
+ ((!) nullable_popover).show ();
}
}
@@ -238,6 +257,16 @@ private class ContextPopover : Popover
new_section_real ();
bind_model (menu, null);
+
+ key_press_event.connect (on_key_press_event);
+ }
+
+ private bool on_key_press_event (Widget widget, Gdk.EventKey event)
+ {
+ if (Gdk.keyval_name (event.keyval) != "Menu")
+ return false;
+ hide ();
+ return true;
}
/*\
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]