diff --git a/data/Application.css b/data/Application.css index 6b743ee58..97e5f663a 100644 --- a/data/Application.css +++ b/data/Application.css @@ -28,6 +28,7 @@ textview.scrubber { .fuzzy-popover entry { margin-left: 1rem; margin-right: 1rem; + margin-bottom: 1rem; } .fuzzy-popover scrolledwindow { @@ -59,9 +60,9 @@ textview.scrubber { color: @selected_fg_color; } -.fuzzy-item .fuzzy-file-icon { - margin-right: 0.5rem; -} +/*.fuzzy-item .fuzzy-file-icon {*/ +/* margin-right: 0.5rem;*/ +/*}*/ .symbol-outline > box.horizontal { margin: 1em; diff --git a/plugins/FuzzySearch/FileItem.vala b/plugins/FuzzySearch/FileItem.vala index ef8cb5ca6..6c19ef7c4 100644 --- a/plugins/FuzzySearch/FileItem.vala +++ b/plugins/FuzzySearch/FileItem.vala @@ -7,7 +7,7 @@ */ public class FileItem : Gtk.ListBoxRow { - public SearchResult result { get; private set; } + public SearchResult result { get; construct; } public string filepath { get { @@ -16,13 +16,7 @@ public class FileItem : Gtk.ListBoxRow { } public FileItem (SearchResult res, bool should_distinguish_project = false) { - this.get_style_context ().add_class ("fuzzy-item"); - this.get_style_context ().add_class ("flat"); - - result = res; - Icon icon; - var path_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 1); - path_box.valign = Gtk.Align.CENTER; + Object (result: res); var path_label = new Gtk.Label (get_path_label (should_distinguish_project)) { halign = START, @@ -34,6 +28,7 @@ public class FileItem : Gtk.ListBoxRow { var filename_label = new Gtk.Label (Path.get_basename (result.relative_path)); filename_label.halign = Gtk.Align.START; + Icon icon; try { var fi = File.new_for_path (result.full_path); var info = fi.query_info ("standard::*", 0); @@ -43,19 +38,21 @@ public class FileItem : Gtk.ListBoxRow { } var image = new Gtk.Image.from_gicon (icon, Gtk.IconSize.DND); - image.get_style_context ().add_class ("fuzzy-file-icon"); + var path_box = new Gtk.Box (VERTICAL, 0) { + valign = CENTER + }; path_box.add (filename_label); path_box.add (path_label); - var container_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 1) { - valign = Gtk.Align.CENTER - }; - + var container_box = new Gtk.Box (HORIZONTAL, 12); container_box.add (image); container_box.add (path_box); - this.child = container_box; + get_style_context ().add_class ("fuzzy-item"); + child = container_box; + + show_all (); } private string get_path_label (bool show_project) { diff --git a/plugins/FuzzySearch/FuzzySearchPopover.vala b/plugins/FuzzySearch/FuzzySearchPopover.vala index c314b5a1e..be9dae0a2 100644 --- a/plugins/FuzzySearch/FuzzySearchPopover.vala +++ b/plugins/FuzzySearch/FuzzySearchPopover.vala @@ -11,26 +11,17 @@ public class Scratch.FuzzySearchPopover : Gtk.Popover { public signal void close_search (); public Scratch.MainWindow current_window { get; construct; } - public Scratch.Services.FuzzySearchIndexer search_indexer { get; construct; } - public bool sidebar_is_visible { get; set; } + public Scratch.Services.FuzzySearchIndexer indexer { get; construct; } - private Gtk.SearchEntry search_term_entry; - private Services.FuzzyFinder fuzzy_finder; - private Gtk.ListBox search_result_container; private ListStore search_list_store; - private int preselected_index; - private Gtk.ScrolledWindow scrolled; - private Scratch.Services.FuzzySearchIndexer indexer; - private int max_items; private Gee.LinkedList cancellables; private Gtk.EventControllerKey search_term_entry_key_controller; - private Gtk.Label title_label; private string current_doc_project; public FuzzySearchPopover (Scratch.Services.FuzzySearchIndexer search_indexer, Scratch.MainWindow window) { Object ( current_window: window, - search_indexer: search_indexer + indexer: search_indexer ); } @@ -41,20 +32,15 @@ public class Scratch.FuzzySearchPopover : Gtk.Popover { pointing_to = { 0, 32, 1, 1 }; get_style_context ().add_class ("fuzzy-popover"); - title_label = new Granite.HeaderLabel (_("Find project files")); - - search_term_entry = new Gtk.SearchEntry () { + var search_term_entry = new Gtk.SearchEntry () { + placeholder_text = _("Find project files"), hexpand = true, valign = START }; - search_list_store = new ListStore (typeof (FileItem)); - search_result_container = new Gtk.ListBox () { - selection_mode = BROWSE, - activate_on_single_click = true + var title_label = new Granite.HeaderLabel (_("Find project files")) { + mnemonic_widget = search_term_entry }; - search_result_container.get_style_context ().add_class ("fuzzy-list"); - search_result_container.bind_model (search_list_store, (obj) => (FileItem)obj); var entry_layout = new Gtk.Box (VERTICAL, 0) { valign = START @@ -62,10 +48,16 @@ public class Scratch.FuzzySearchPopover : Gtk.Popover { entry_layout.add (title_label); entry_layout.add (search_term_entry); - scrolled = new Gtk.ScrolledWindow (null, null) { + search_list_store = new ListStore (typeof (FileItem)); + + var search_result_container = new Gtk.ListBox () { + selection_mode = BROWSE, + activate_on_single_click = true + }; + search_result_container.bind_model (search_list_store, (obj) => (FileItem)obj); + + var scrolled = new Gtk.ScrolledWindow (null, null) { propagate_natural_height = true, - hexpand = true, - vexpand = true, child = search_result_container, hscrollbar_policy = NEVER }; @@ -74,13 +66,9 @@ public class Scratch.FuzzySearchPopover : Gtk.Popover { box.add (entry_layout); box.add (scrolled); box.show_all (); + child = box; - scrolled.hide (); - - add (box); - - fuzzy_finder = new Services.FuzzyFinder (search_indexer.project_paths); - indexer = search_indexer; + var fuzzy_finder = new Services.FuzzyFinder (indexer.project_paths); cancellables = new Gee.LinkedList (); search_result_container.row_activated.connect ((row) => { @@ -106,6 +94,7 @@ public class Scratch.FuzzySearchPopover : Gtk.Popover { return Gdk.EVENT_PROPAGATE; }); + int preselected_index; search_term_entry.activate.connect (() => { if (search_list_store.n_items > 0) { handle_item_selection ((FileItem) search_list_store.get_item (preselected_index)); @@ -168,9 +157,6 @@ public class Scratch.FuzzySearchPopover : Gtk.Popover { search_list_store.insert_sorted (file_item, sort_func); } - scrolled.hide (); - scrolled.show_all (); - // Reset scrolling scrolled.vadjustment.value = 0; } @@ -180,13 +166,11 @@ public class Scratch.FuzzySearchPopover : Gtk.Popover { }); } else { search_list_store.remove_all (); - - scrolled.hide (); } }); search_term_entry.realize.connect_after (() => { - int height; + int height, max_items; current_window.get_size (null, out height); // Limit the shown results if the window height is too small