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

Reliably open documents from sidebar #1465

Merged
merged 3 commits into from
Nov 3, 2024
Merged
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
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
25 changes: 5 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,10 +305,12 @@ 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));

// RecentManager requires valid URI
var new_uri = "file://" + new_path; // Code only edits local files
Gtk.RecentManager.get_default ().add_item (new_uri);
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