Merge lp:~tintou/switchboard/search into lp:~elementary-pantheon/switchboard/switchboard

Proposed by Corentin Noël
Status: Rejected
Rejected by: xapantu
Proposed branch: lp:~tintou/switchboard/search
Merge into: lp:~elementary-pantheon/switchboard/switchboard
Diff against target: 254 lines (+130/-12)
3 files modified
src/CMakeLists.txt (+1/-0)
src/SearchView.vala (+90/-0)
src/Switchboard.vala (+39/-12)
To merge this branch: bzr merge lp:~tintou/switchboard/search
Reviewer Review Type Date Requested Status
Avi Romanoff Pending
Review via email: mp+244806@code.launchpad.net

Description of the change

Changes are not made to the API.

Implementing the search feature at the server side (switchboard itself).

To post a comment you must log in.
lp:~tintou/switchboard/search updated
532. By Corentin Noël

Fix focus issues with the search box.

Revision history for this message
xapantu (xapantu) wrote :

Looks like this was superseded a while ago, see the bug report.

Unmerged revisions

532. By Corentin Noël

Fix focus issues with the search box.

531. By Corentin Noël

Implement search feature.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2014-04-14 20:39:34 +0000
3+++ src/CMakeLists.txt 2014-12-16 00:30:51 +0000
4@@ -2,6 +2,7 @@
5 Switchboard.vala
6 CategoryView.vala
7 EmbeddedAlert.vala
8+ SearchView.vala
9 NavigationButton.vala
10 )
11
12
13=== added file 'src/SearchView.vala'
14--- src/SearchView.vala 1970-01-01 00:00:00 +0000
15+++ src/SearchView.vala 2014-12-16 00:30:51 +0000
16@@ -0,0 +1,90 @@
17+/***
18+BEGIN LICENSE
19+Copyright (C) 2011-2012 Avi Romanoff <aviromanoff@gmail.com>
20+This program is free software: you can redistribute it and/or modify it
21+under the terms of the GNU Lesser General Public License version 2.1, as published
22+by the Free Software Foundation.
23+
24+This program is distributed in the hope that it will be useful, but
25+WITHOUT ANY WARRANTY; without even the implied warranties of
26+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
27+PURPOSE. See the GNU General Public License for more details.
28+
29+You should have received a copy of the GNU General Public License along
30+with this program. If not, see <http://www.gnu.org/licenses/>.
31+END LICENSE
32+***/
33+
34+public class Switchboard.SearchView : Gtk.ScrolledWindow {
35+ public signal void switch_to_plug (Plug plug);
36+ public signal void no_result ();
37+ private GLib.List<SearchItem> results;
38+ private Gtk.Grid grid;
39+ public SearchView () {
40+ expand = true;
41+ results = new GLib.List<SearchItem> ();
42+ grid = new Gtk.Grid ();
43+ grid.expand = true;
44+ grid.orientation = Gtk.Orientation.VERTICAL;
45+ add_with_viewport (grid);
46+ }
47+
48+ public async void search (string query) {
49+ foreach (var result in results) {
50+ result.destroy ();
51+ }
52+
53+ while (results.length () != 0)
54+ results.remove_link (results);
55+
56+ var plugs = PlugsManager.get_default ().get_plugs ();
57+ foreach (Switchboard.Plug plug in plugs) {
58+ var newresults = yield plug.search (query);
59+ foreach (var entry in newresults.entries) {
60+ var result = new SearchItem (plug, entry.key, entry.value);
61+ result.switch_to_plug.connect ((plug) => switch_to_plug (plug));
62+ results.append (result);
63+ if (results.length () == 1)
64+ result.margin_top = 12;
65+ grid.add (result);
66+ }
67+ }
68+
69+ if (results.length () == 0)
70+ no_result ();
71+
72+ grid.show_all ();
73+ }
74+}
75+
76+public class Switchboard.SearchItem : Gtk.Button {
77+ public signal void switch_to_plug (Plug plug);
78+
79+ private Gtk.Image icon;
80+ private Gtk.Label name_label;
81+ public SearchItem (Plug plug, string label, string callback) {
82+ relief = Gtk.ReliefStyle.NONE;
83+ margin_start = margin_end = 12;
84+ hexpand = true;
85+ get_style_context ().add_class ("app");
86+
87+ name_label = new Gtk.Label (label);
88+ name_label.xalign = 0.0f;
89+ icon = new Gtk.Image.from_icon_name (plug.icon, Gtk.IconSize.DND);
90+
91+ var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
92+ box.pack_start (icon, false);
93+ box.pack_start (name_label, true);
94+ box.margin_start = 12;
95+ box.margin_top = box.margin_bottom = 3;
96+ add (box);
97+
98+ clicked.connect (() => {
99+ switch_to_plug (plug);
100+ Idle.add (() => {
101+ plug.search_callback (callback);
102+ return false;
103+ });
104+ });
105+ }
106+}
107
108=== modified file 'src/Switchboard.vala'
109--- src/Switchboard.vala 2014-12-10 09:08:33 +0000
110+++ src/Switchboard.vala 2014-12-16 00:30:51 +0000
111@@ -45,6 +45,7 @@
112 private Gtk.ScrolledWindow category_scrolled;
113 private Switchboard.NavigationButton navigation_button;
114 private Switchboard.CategoryView category_view;
115+ private Switchboard.SearchView search_view;
116
117 private Gee.LinkedList <string> loaded_plugs;
118 private string all_settings_label = _("All Settings");
119@@ -55,6 +56,7 @@
120 private GLib.Settings settings;
121 private int default_width = 0;
122 private int default_height = 0;
123+ private Switchboard.Plug plug_before_search = null;
124
125 private static string? plug_to_open = null;
126 private static bool opened_directly = false;
127@@ -233,6 +235,7 @@
128 update_saved_state ();
129 return false;
130 });
131+
132 main_window.window_state_event.connect ((event) => {
133 if (event.new_window_state == Gdk.WindowState.MAXIMIZED)
134 settings.set_enum ("window-state", WindowState.MAXIMIZED);
135@@ -241,6 +244,7 @@
136
137 return false;
138 });
139+
140 setup_toolbar ();
141
142 // Set up accelerators (hotkeys)
143@@ -263,6 +267,16 @@
144 category_scrolled.add_with_viewport (category_view);
145 category_scrolled.set_vexpand (true);
146
147+ search_view = new Switchboard.SearchView ();
148+ search_view.no_result.connect (() => {
149+ show_alert (_("No settings found"), _("Try changing your search terms"), Gtk.MessageType.INFO);
150+ });
151+
152+ search_view.switch_to_plug.connect ((plug) => {
153+ search_box.text = "";
154+ load_plug (plug);
155+ });
156+
157 // Set up UI
158 alert_view = new Granite.Widgets.EmbeddedAlert ();
159 alert_view.set_vexpand (true);
160@@ -270,6 +284,7 @@
161
162 stack = new Gtk.Stack ();
163 stack.expand = true;
164+ stack.add_named (search_view, "search");
165 stack.add_named (alert_view, "alert");
166 stack.add_named (category_scrolled, "main");
167 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
168@@ -280,8 +295,6 @@
169 navigation_button.hide ();
170
171 main_window.size_allocate.connect (() => {
172- if (opened_directly)
173- search_box.sensitive = false;
174 category_view.recalculate_columns ();
175 });
176
177@@ -342,7 +355,6 @@
178 private void handle_navigation_button_clicked () {
179 if (navigation_button.get_text () == all_settings_label) {
180 opened_directly = false;
181- search_box.sensitive = true;
182 switch_to_icons ();
183 navigation_button.hide ();
184 } else {
185@@ -360,10 +372,10 @@
186 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT);
187 }
188
189- search_box.sensitive = false;
190 plug.shown ();
191 stack.set_visible_child_name (plug.code_name);
192 category_scrolled.hide ();
193+ plug_before_search = plug;
194 }
195
196 // Switches back to the icons
197@@ -373,15 +385,13 @@
198 }
199 category_scrolled.show ();
200 stack.set_visible_child (category_scrolled);
201- current_plug.hidden ();
202+ if (current_plug != null)
203+ current_plug.hidden ();
204
205 // Reset state
206 reset_title ();
207- search_box.set_text ("");
208 search_box.sensitive = Switchboard.PlugsManager.get_default ().has_plugs ();
209-
210- if (search_box.sensitive)
211- search_box.has_focus = true;
212+ plug_before_search = null;
213
214 return true;
215 }
216@@ -400,18 +410,35 @@
217 search_box.margin_right = 5;
218 search_box.sensitive = false;
219 search_box.changed.connect(() => {
220- category_view.filter_plugs(search_box.get_text ());
221+ if (search_box.text.strip () == "") {
222+ if (plug_before_search != null)
223+ switch_to_plug (plug_before_search);
224+ else
225+ switch_to_icons ();
226+ return;
227+ }
228+
229+ search_view.search.begin (search_box.text);
230+ if (stack.visible_child_name != "alert")
231+ stack.set_visible_child_name ("search");
232+ else
233+ stack.set_visible_child_full ("search", Gtk.StackTransitionType.NONE);
234+ category_scrolled.hide ();
235 });
236
237 // Focus typing to the search bar
238 main_window.key_press_event.connect ((event) => {
239 // alt+left should go back to all settings
240- if ((event.state | Gdk.ModifierType.MOD1_MASK) != 0 && event.keyval == Gdk.Key.Left) {
241+ if (Gdk.ModifierType.MOD1_MASK in event.state && event.keyval == Gdk.Key.Left) {
242 navigation_button.clicked ();
243 }
244
245 // Don't focus if it is a modifier or if search_box is already focused
246- if ((event.is_modifier == 0) && !search_box.has_focus)
247+ if ((event.is_modifier == 0) &&
248+ !search_box.has_focus &&
249+ (stack.visible_child_name == "alert"
250+ || stack.visible_child_name == "search"
251+ || stack.visible_child_name == "main"))
252 search_box.grab_focus ();
253
254 return false;

Subscribers

People subscribed via source and target branches

to all changes: