Reopen search view on query changes
This commit is contained in:
parent
a844e9f5dc
commit
96b50cefe4
|
@ -90,15 +90,39 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
img.pixel_size = 20; // For some reason Notifications icon is too small without this
|
||||
}
|
||||
|
||||
public void open_view (Widget widget) {
|
||||
widget.show ();
|
||||
var i = int.parse (primary_stack.get_visible_child_name ());
|
||||
public int get_visible_id () {
|
||||
return int.parse (primary_stack.get_visible_child_name ());
|
||||
}
|
||||
|
||||
public void open_view (AbstractView widget) {
|
||||
var i = get_visible_id ();
|
||||
i++;
|
||||
widget.stack_pos = i;
|
||||
widget.show ();
|
||||
primary_stack.add_named (widget, i.to_string ());
|
||||
primary_stack.set_visible_child_name (i.to_string ());
|
||||
header.update (false);
|
||||
}
|
||||
|
||||
public void back () {
|
||||
var i = get_visible_id ();
|
||||
primary_stack.set_visible_child_name ((i-1).to_string ());
|
||||
|
||||
var child = primary_stack.get_child_by_name (i.to_string ());
|
||||
child.destroy ();
|
||||
|
||||
var is_root = primary_stack.get_visible_child_name () == "0";
|
||||
header.update (is_root);
|
||||
}
|
||||
|
||||
public void reopen_view (int view_id) {
|
||||
var i = get_visible_id ();
|
||||
while (i != view_id && view_id != 0) {
|
||||
back ();
|
||||
i = get_visible_id ();
|
||||
}
|
||||
}
|
||||
|
||||
private void on_toast (string msg){
|
||||
toast.title = msg;
|
||||
toast.send_notification ();
|
||||
|
|
|
@ -2,6 +2,7 @@ using Gtk;
|
|||
|
||||
public abstract class Tootle.AbstractView : Gtk.ScrolledWindow {
|
||||
|
||||
public int stack_pos = -1;
|
||||
public Gtk.Image? image;
|
||||
public Gtk.Box view;
|
||||
protected Gtk.Box? empty;
|
||||
|
|
|
@ -2,7 +2,8 @@ using Gtk;
|
|||
|
||||
public class Tootle.SearchView : AbstractView {
|
||||
|
||||
Gtk.Entry entry;
|
||||
private string query = "";
|
||||
private Gtk.Entry entry;
|
||||
|
||||
construct {
|
||||
view.margin_bottom = 6;
|
||||
|
@ -11,6 +12,7 @@ public class Tootle.SearchView : AbstractView {
|
|||
entry.placeholder_text = _("Search");
|
||||
entry.secondary_icon_name = "system-search-symbolic";
|
||||
entry.width_chars = 25;
|
||||
entry.text = query;
|
||||
entry.show ();
|
||||
Tootle.window.header.pack_start (entry);
|
||||
|
||||
|
@ -56,14 +58,15 @@ public class Tootle.SearchView : AbstractView {
|
|||
}
|
||||
|
||||
private void request () {
|
||||
if (entry.text == "") {
|
||||
query = entry.text;
|
||||
if (query == "") {
|
||||
clear ();
|
||||
return;
|
||||
}
|
||||
Tootle.window.reopen_view (this.stack_pos);
|
||||
|
||||
var query = Soup.URI.encode (entry.text, null);
|
||||
var url = "%s/api/v1/search?q=%s".printf (Tootle.accounts.formal.instance, query);
|
||||
|
||||
var query_encoded = Soup.URI.encode (query, null);
|
||||
var url = "%s/api/v1/search?q=%s".printf (Tootle.accounts.formal.instance, query_encoded);
|
||||
var msg = new Soup.Message("GET", url);
|
||||
Tootle.network.queue(msg, (sess, mess) => {
|
||||
try{
|
||||
|
@ -100,7 +103,6 @@ public class Tootle.SearchView : AbstractView {
|
|||
}
|
||||
|
||||
empty_state ();
|
||||
|
||||
}
|
||||
catch (GLib.Error e) {
|
||||
warning ("Can't update feed");
|
||||
|
|
|
@ -19,17 +19,7 @@ public class Tootle.HeaderBar : Gtk.HeaderBar{
|
|||
button_back = new Button ();
|
||||
button_back.label = _("Back");
|
||||
button_back.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON);
|
||||
button_back.clicked.connect (() => {
|
||||
var primary_stack = Tootle.window.primary_stack;
|
||||
var i = int.parse (primary_stack.get_visible_child_name ());
|
||||
primary_stack.set_visible_child_name ((i-1).to_string ());
|
||||
|
||||
var child = primary_stack.get_child_by_name (i.to_string ());
|
||||
child.destroy ();
|
||||
|
||||
var is_root = primary_stack.get_visible_child_name () == "0";
|
||||
update (is_root);
|
||||
});
|
||||
button_back.clicked.connect (() => Tootle.window.back ());
|
||||
|
||||
button_toot = new Button ();
|
||||
button_toot.tooltip_text = "Toot";
|
||||
|
|
Loading…
Reference in New Issue