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
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-04-14 20:39:34 +0000
+++ src/CMakeLists.txt 2014-12-16 00:30:51 +0000
@@ -2,6 +2,7 @@
2 Switchboard.vala2 Switchboard.vala
3 CategoryView.vala3 CategoryView.vala
4 EmbeddedAlert.vala4 EmbeddedAlert.vala
5 SearchView.vala
5 NavigationButton.vala6 NavigationButton.vala
6)7)
78
89
=== added file 'src/SearchView.vala'
--- src/SearchView.vala 1970-01-01 00:00:00 +0000
+++ src/SearchView.vala 2014-12-16 00:30:51 +0000
@@ -0,0 +1,90 @@
1/***
2BEGIN LICENSE
3Copyright (C) 2011-2012 Avi Romanoff <aviromanoff@gmail.com>
4This program is free software: you can redistribute it and/or modify it
5under the terms of the GNU Lesser General Public License version 2.1, as published
6by the Free Software Foundation.
7
8This program is distributed in the hope that it will be useful, but
9WITHOUT ANY WARRANTY; without even the implied warranties of
10MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along
14with this program. If not, see <http://www.gnu.org/licenses/>.
15END LICENSE
16***/
17
18public class Switchboard.SearchView : Gtk.ScrolledWindow {
19 public signal void switch_to_plug (Plug plug);
20 public signal void no_result ();
21 private GLib.List<SearchItem> results;
22 private Gtk.Grid grid;
23 public SearchView () {
24 expand = true;
25 results = new GLib.List<SearchItem> ();
26 grid = new Gtk.Grid ();
27 grid.expand = true;
28 grid.orientation = Gtk.Orientation.VERTICAL;
29 add_with_viewport (grid);
30 }
31
32 public async void search (string query) {
33 foreach (var result in results) {
34 result.destroy ();
35 }
36
37 while (results.length () != 0)
38 results.remove_link (results);
39
40 var plugs = PlugsManager.get_default ().get_plugs ();
41 foreach (Switchboard.Plug plug in plugs) {
42 var newresults = yield plug.search (query);
43 foreach (var entry in newresults.entries) {
44 var result = new SearchItem (plug, entry.key, entry.value);
45 result.switch_to_plug.connect ((plug) => switch_to_plug (plug));
46 results.append (result);
47 if (results.length () == 1)
48 result.margin_top = 12;
49 grid.add (result);
50 }
51 }
52
53 if (results.length () == 0)
54 no_result ();
55
56 grid.show_all ();
57 }
58}
59
60public class Switchboard.SearchItem : Gtk.Button {
61 public signal void switch_to_plug (Plug plug);
62
63 private Gtk.Image icon;
64 private Gtk.Label name_label;
65 public SearchItem (Plug plug, string label, string callback) {
66 relief = Gtk.ReliefStyle.NONE;
67 margin_start = margin_end = 12;
68 hexpand = true;
69 get_style_context ().add_class ("app");
70
71 name_label = new Gtk.Label (label);
72 name_label.xalign = 0.0f;
73 icon = new Gtk.Image.from_icon_name (plug.icon, Gtk.IconSize.DND);
74
75 var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
76 box.pack_start (icon, false);
77 box.pack_start (name_label, true);
78 box.margin_start = 12;
79 box.margin_top = box.margin_bottom = 3;
80 add (box);
81
82 clicked.connect (() => {
83 switch_to_plug (plug);
84 Idle.add (() => {
85 plug.search_callback (callback);
86 return false;
87 });
88 });
89 }
90}
091
=== modified file 'src/Switchboard.vala'
--- src/Switchboard.vala 2014-12-10 09:08:33 +0000
+++ src/Switchboard.vala 2014-12-16 00:30:51 +0000
@@ -45,6 +45,7 @@
45 private Gtk.ScrolledWindow category_scrolled;45 private Gtk.ScrolledWindow category_scrolled;
46 private Switchboard.NavigationButton navigation_button;46 private Switchboard.NavigationButton navigation_button;
47 private Switchboard.CategoryView category_view;47 private Switchboard.CategoryView category_view;
48 private Switchboard.SearchView search_view;
4849
49 private Gee.LinkedList <string> loaded_plugs;50 private Gee.LinkedList <string> loaded_plugs;
50 private string all_settings_label = _("All Settings");51 private string all_settings_label = _("All Settings");
@@ -55,6 +56,7 @@
55 private GLib.Settings settings;56 private GLib.Settings settings;
56 private int default_width = 0;57 private int default_width = 0;
57 private int default_height = 0;58 private int default_height = 0;
59 private Switchboard.Plug plug_before_search = null;
5860
59 private static string? plug_to_open = null;61 private static string? plug_to_open = null;
60 private static bool opened_directly = false;62 private static bool opened_directly = false;
@@ -233,6 +235,7 @@
233 update_saved_state ();235 update_saved_state ();
234 return false;236 return false;
235 });237 });
238
236 main_window.window_state_event.connect ((event) => {239 main_window.window_state_event.connect ((event) => {
237 if (event.new_window_state == Gdk.WindowState.MAXIMIZED)240 if (event.new_window_state == Gdk.WindowState.MAXIMIZED)
238 settings.set_enum ("window-state", WindowState.MAXIMIZED);241 settings.set_enum ("window-state", WindowState.MAXIMIZED);
@@ -241,6 +244,7 @@
241244
242 return false;245 return false;
243 });246 });
247
244 setup_toolbar ();248 setup_toolbar ();
245249
246 // Set up accelerators (hotkeys)250 // Set up accelerators (hotkeys)
@@ -263,6 +267,16 @@
263 category_scrolled.add_with_viewport (category_view);267 category_scrolled.add_with_viewport (category_view);
264 category_scrolled.set_vexpand (true);268 category_scrolled.set_vexpand (true);
265269
270 search_view = new Switchboard.SearchView ();
271 search_view.no_result.connect (() => {
272 show_alert (_("No settings found"), _("Try changing your search terms"), Gtk.MessageType.INFO);
273 });
274
275 search_view.switch_to_plug.connect ((plug) => {
276 search_box.text = "";
277 load_plug (plug);
278 });
279
266 // Set up UI280 // Set up UI
267 alert_view = new Granite.Widgets.EmbeddedAlert ();281 alert_view = new Granite.Widgets.EmbeddedAlert ();
268 alert_view.set_vexpand (true);282 alert_view.set_vexpand (true);
@@ -270,6 +284,7 @@
270284
271 stack = new Gtk.Stack ();285 stack = new Gtk.Stack ();
272 stack.expand = true;286 stack.expand = true;
287 stack.add_named (search_view, "search");
273 stack.add_named (alert_view, "alert");288 stack.add_named (alert_view, "alert");
274 stack.add_named (category_scrolled, "main");289 stack.add_named (category_scrolled, "main");
275 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;290 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
@@ -280,8 +295,6 @@
280 navigation_button.hide ();295 navigation_button.hide ();
281296
282 main_window.size_allocate.connect (() => {297 main_window.size_allocate.connect (() => {
283 if (opened_directly)
284 search_box.sensitive = false;
285 category_view.recalculate_columns ();298 category_view.recalculate_columns ();
286 });299 });
287300
@@ -342,7 +355,6 @@
342 private void handle_navigation_button_clicked () {355 private void handle_navigation_button_clicked () {
343 if (navigation_button.get_text () == all_settings_label) {356 if (navigation_button.get_text () == all_settings_label) {
344 opened_directly = false;357 opened_directly = false;
345 search_box.sensitive = true;
346 switch_to_icons ();358 switch_to_icons ();
347 navigation_button.hide ();359 navigation_button.hide ();
348 } else {360 } else {
@@ -360,10 +372,10 @@
360 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT);372 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT);
361 }373 }
362374
363 search_box.sensitive = false;
364 plug.shown ();375 plug.shown ();
365 stack.set_visible_child_name (plug.code_name);376 stack.set_visible_child_name (plug.code_name);
366 category_scrolled.hide ();377 category_scrolled.hide ();
378 plug_before_search = plug;
367 }379 }
368380
369 // Switches back to the icons381 // Switches back to the icons
@@ -373,15 +385,13 @@
373 }385 }
374 category_scrolled.show ();386 category_scrolled.show ();
375 stack.set_visible_child (category_scrolled);387 stack.set_visible_child (category_scrolled);
376 current_plug.hidden ();388 if (current_plug != null)
389 current_plug.hidden ();
377390
378 // Reset state391 // Reset state
379 reset_title ();392 reset_title ();
380 search_box.set_text ("");
381 search_box.sensitive = Switchboard.PlugsManager.get_default ().has_plugs ();393 search_box.sensitive = Switchboard.PlugsManager.get_default ().has_plugs ();
382394 plug_before_search = null;
383 if (search_box.sensitive)
384 search_box.has_focus = true;
385395
386 return true;396 return true;
387 }397 }
@@ -400,18 +410,35 @@
400 search_box.margin_right = 5;410 search_box.margin_right = 5;
401 search_box.sensitive = false;411 search_box.sensitive = false;
402 search_box.changed.connect(() => {412 search_box.changed.connect(() => {
403 category_view.filter_plugs(search_box.get_text ());413 if (search_box.text.strip () == "") {
414 if (plug_before_search != null)
415 switch_to_plug (plug_before_search);
416 else
417 switch_to_icons ();
418 return;
419 }
420
421 search_view.search.begin (search_box.text);
422 if (stack.visible_child_name != "alert")
423 stack.set_visible_child_name ("search");
424 else
425 stack.set_visible_child_full ("search", Gtk.StackTransitionType.NONE);
426 category_scrolled.hide ();
404 });427 });
405428
406 // Focus typing to the search bar429 // Focus typing to the search bar
407 main_window.key_press_event.connect ((event) => {430 main_window.key_press_event.connect ((event) => {
408 // alt+left should go back to all settings431 // alt+left should go back to all settings
409 if ((event.state | Gdk.ModifierType.MOD1_MASK) != 0 && event.keyval == Gdk.Key.Left) {432 if (Gdk.ModifierType.MOD1_MASK in event.state && event.keyval == Gdk.Key.Left) {
410 navigation_button.clicked ();433 navigation_button.clicked ();
411 }434 }
412435
413 // Don't focus if it is a modifier or if search_box is already focused436 // Don't focus if it is a modifier or if search_box is already focused
414 if ((event.is_modifier == 0) && !search_box.has_focus)437 if ((event.is_modifier == 0) &&
438 !search_box.has_focus &&
439 (stack.visible_child_name == "alert"
440 || stack.visible_child_name == "search"
441 || stack.visible_child_name == "main"))
415 search_box.grab_focus ();442 search_box.grab_focus ();
416443
417 return false;444 return false;

Subscribers

People subscribed via source and target branches

to all changes: