Skip to content
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
7 changes: 4 additions & 3 deletions data/Application.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ textview.scrubber {
.fuzzy-popover entry {
margin-left: 1rem;
margin-right: 1rem;
margin-bottom: 1rem;
}

.fuzzy-popover scrolledwindow {
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 11 additions & 14 deletions plugins/FuzzySearch/FileItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

public class FileItem : Gtk.ListBoxRow {
public SearchResult result { get; private set; }
public SearchResult result { get; construct; }

public string filepath {
get {
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
54 changes: 19 additions & 35 deletions plugins/FuzzySearch/FuzzySearchPopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<GLib.Cancellable> 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
);
}

Expand All @@ -41,31 +32,32 @@ 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
};
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
};
Expand All @@ -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<GLib.Cancellable> ();

search_result_container.row_activated.connect ((row) => {
Expand All @@ -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));
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down