Skip to content

Commit

Permalink
FileView: Use activate instead of select to open docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypw committed Sep 19, 2024
1 parent b52c591 commit 8af87a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/FolderManager/FileItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ namespace Scratch.FolderManager {
Object (file: file, view: view);
}

public override void activated () {
view.activate (file.path);
}

public override Gtk.Menu? get_context_menu () {
GLib.FileInfo info = null;

Expand Down
23 changes: 3 additions & 20 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
private Scratch.Services.GitManager git_manager;
private Scratch.Services.PluginsManager plugins;

public signal void select (string file);
public new signal void activate (string file);
public signal bool rename_request (File file);

public SimpleActionGroup actions { get; private set; }
public ActionGroup toplevel_action_group { get; private set; }
public bool ignore_next_select { get; set; default = false; }
public string icon_name { get; set; }
public string title { get; set; }
public string active_project_path {
Expand All @@ -72,11 +71,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
}

construct {
activate_on_single_click = true;
icon_name = "folder-symbolic";
title = _("Folders");

item_selected.connect (on_item_selected);

settings = new GLib.Settings ("io.elementary.code.folder-manager");

git_manager = Scratch.Services.GitManager.get_instance ();
Expand Down Expand Up @@ -128,19 +126,6 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
write_settings ();
}

private void on_item_selected (Code.Widgets.SourceList.Item? item) {
// This is a workaround for SourceList silliness: you cannot remove an item
// without it automatically selecting another one.
if (ignore_next_select) {
ignore_next_select = false;
return;
}

if (item is FileItem) {
select (((FileItem) item).file.path);
}
}

public void restore_saved_state () {
foreach (unowned string path in settings.get_strv ("opened-folders")) {
add_folder (new File (path), false);
Expand Down Expand Up @@ -184,9 +169,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
}

public void select_path (string path) {
item_selected.disconnect (on_item_selected);
selected = find_path (root, path);
item_selected.connect (on_item_selected);
}

public void unselect_all () {
Expand Down Expand Up @@ -322,7 +305,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
selected.disconnect (once);
var new_path = Path.get_dirname (path) + Path.DIR_SEPARATOR_S + new_name;
this.toplevel_action_group.activate_action (MainWindow.ACTION_CLOSE_TAB, new Variant.string (path));
this.select (new_path);
activate (new_path);
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/FolderManager/FolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ namespace Scratch.FolderManager {
}
}

view.ignore_next_select = true;
((Code.Widgets.SourceList.ExpandableItem)this).remove (item);
// Add back dummy if empty
if (!(has_dummy || n_children > 0)) {
Expand Down Expand Up @@ -384,7 +383,7 @@ namespace Scratch.FolderManager {
gfile.make_directory ();
} else {
gfile.create (FileCreateFlags.NONE);
view.select (gfile.get_path ());
view.activate (gfile.get_path ());
}
} catch (Error e) {
warning (e.message);
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ namespace Scratch {
sidebar.add_tab (folder_manager_view);
folder_manager_view.show_all ();

folder_manager_view.select.connect ((a) => {
folder_manager_view.activate.connect ((a) => {
var file = new Scratch.FolderManager.File (a);
var doc = new Scratch.Services.Document (actions, file.file);

Expand Down
6 changes: 6 additions & 0 deletions src/Widgets/SourceList/SourceList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2646,6 +2646,12 @@ public class SourceList : Gtk.ScrolledWindow {
get { return tree.editing; }
}

public bool activate_on_single_click {
set {
tree.activate_on_single_click = value;
}
}

private Tree tree;
private DataModel data_model = new DataModel ();

Expand Down

0 comments on commit 8af87a7

Please sign in to comment.