Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchView: Add placeholder #518

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/SlingshotView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public class Slingshot.SlingshotView : Gtk.Grid {
view_selector_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT;
view_selector_revealer.add (view_selector);

search_entry = new Gtk.SearchEntry ();
search_entry.placeholder_text = _("Search Apps");
search_entry.hexpand = true;
search_entry = new Gtk.SearchEntry () {
placeholder_text = _("Search Apps and Actions"),
hexpand = true
};
search_entry.secondary_icon_tooltip_markup = Granite.markup_accel_tooltip (
{"<Ctrl>BackSpace"}, _("Clear all")
);
Expand Down Expand Up @@ -126,7 +127,7 @@ public class Slingshot.SlingshotView : Gtk.Grid {
});

focus_in_event.connect (() => {
search_entry.grab_focus ();
grab_focus ();
return Gdk.EVENT_PROPAGATE;
});

Expand All @@ -141,7 +142,12 @@ public class Slingshot.SlingshotView : Gtk.Grid {
search.begin (search_entry.text);
});

search_entry.grab_focus ();
search_entry.focus_in_event.connect (() => {
if (modality != Modality.SEARCH_VIEW) {
set_modality (Modality.SEARCH_VIEW);
}
});

search_entry.activate.connect (search_entry_activated);

category_view.search_focus_request.connect (() => {
Expand Down Expand Up @@ -329,12 +335,6 @@ public class Slingshot.SlingshotView : Gtk.Grid {

public void show_slingshot () {
search_entry.text = "";

/* TODO
set_focus (null);
*/

search_entry.grab_focus ();
// This is needed in order to not animate if the previous view was the search view.
view_selector_revealer.transition_type = Gtk.RevealerTransitionType.NONE;
stack.transition_type = Gtk.StackTransitionType.NONE;
Expand All @@ -354,8 +354,6 @@ public class Slingshot.SlingshotView : Gtk.Grid {

view_selector_revealer.set_reveal_child (true);
stack.set_visible_child_name ("normal");

search_entry.grab_focus ();
break;

case Modality.CATEGORY_VIEW:
Expand All @@ -365,8 +363,6 @@ public class Slingshot.SlingshotView : Gtk.Grid {

view_selector_revealer.set_reveal_child (true);
stack.set_visible_child_name ("category");

search_entry.grab_focus ();
break;

case Modality.SEARCH_VIEW:
Expand Down
67 changes: 61 additions & 6 deletions src/Views/SearchView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,59 @@ public class Slingshot.Widgets.SearchView : Gtk.ScrolledWindow {
public signal void start_search (Synapse.SearchMatch search_match, Synapse.Match? target);
public signal void app_launched ();

private Granite.Widgets.AlertView alert_view;
private AppListBox list_box;
Gee.HashMap<SearchItem.ResultType, uint> limitator;

construct {
hscrollbar_policy = Gtk.PolicyType.NEVER;

alert_view = new Granite.Widgets.AlertView ("", _("Try changing search terms."), "edit-find-symbolic");
alert_view.show_all ();
var placeholder_title = new Gtk.Label (_("Search apps, actions, and more"));
placeholder_title.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);

var suggest_apps = new SuggestionGrid (
"application-default-icon",
_("Installed Apps"),
_("“Videos”")
);

var suggest_actions = new SuggestionGrid (
"system-run",
_("Actions"),
_("“Check for updates”")
);

var suggest_settings = new SuggestionGrid (
"preferences-desktop",
_("System Settings"),
_("“Text size”")
);

var suggest_bookmarks = new SuggestionGrid (
"user-bookmarks",
_("Bookmarked Folders"),
_("“Pictures”")
);

var placeholder = new Gtk.Grid () {
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER,
row_spacing = 12,
orientation = Gtk.Orientation.VERTICAL
};
placeholder.add (placeholder_title);
placeholder.add (suggest_apps);
placeholder.add (suggest_actions);
placeholder.add (suggest_settings);
placeholder.add (suggest_bookmarks);
placeholder.show_all ();

// list box
limitator = new Gee.HashMap<SearchItem.ResultType, uint> ();
list_box = new AppListBox ();
list_box.activate_on_single_click = true;
list_box.set_sort_func ((row1, row2) => update_sort (row1, row2));
list_box.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) update_header);
list_box.set_placeholder (alert_view);
list_box.set_placeholder (placeholder);

list_box.close_request.connect (() => {
app_launched ();
Expand Down Expand Up @@ -127,8 +163,6 @@ public class Slingshot.Widgets.SearchView : Gtk.ScrolledWindow {
create_item (app, search_term, result_type);
}

} else {
alert_view.title = _("No Results for “%s”").printf (search_term);
}


Expand Down Expand Up @@ -192,4 +226,25 @@ public class Slingshot.Widgets.SearchView : Gtk.ScrolledWindow {

row.set_header (header);
}

private class SuggestionGrid : Gtk.Grid {
public SuggestionGrid (string icon_name, string title, string description) {
var icon = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DND);

var title_label = new Gtk.Label (title) {
xalign = 0
};
title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);

var description_label = new Gtk.Label (description) {
xalign = 0
};
description_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);

column_spacing = 12;
attach (icon, 0, 0, 1, 2);
attach (title_label, 1, 0);
attach (description_label, 1, 1);
}
}
}