Skip to content
Closed
14 changes: 12 additions & 2 deletions src/FolderManager/FileItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,19 @@ namespace Scratch.FolderManager {
/**
* Normal item in the source list, represents a textfile.
*/


internal class FileItem : Item {
public FileItem (File file, FileView view) {
Object (file: file, view: view);
private ProjectFolderItem _root;
public ProjectFolderItem project_root { get; construct; }
get {
return _root;
}
}

public FileItem (File file, FileView view, ProjectFolderItem root) {
Object (file: file, view: view, project_root: root);
this._root = root;
}

public override Gtk.Menu? get_context_menu () {
Expand Down
7 changes: 5 additions & 2 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace Scratch.FolderManager {
internal class FileView : Granite.Widgets.SourceList, Code.PaneSwitcher {
private FolderManagerSettings settings;

public signal void select (string file);
public signal void select (string file, string project_root);
public signal void project_closed (string project_root);

// This is a workaround for SourceList silliness: you cannot remove an item
// without it automatically selecting another one.
Expand All @@ -52,7 +53,8 @@ namespace Scratch.FolderManager {
}

if (item is FileItem) {
select ((item as FileItem).file.path);
unowned FileItem it = (FileItem) item;
select (it.file.path, it.project_root.file.path );
}
}

Expand Down Expand Up @@ -142,6 +144,7 @@ namespace Scratch.FolderManager {
folder_root.closed.connect (() => {
root.remove (folder_root);
write_settings ();
project_closed (folder_root.file.path);
});

folder_root.close_all_except.connect (() => {
Expand Down
4 changes: 2 additions & 2 deletions src/FolderManager/FolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace Scratch.FolderManager {
if (child.is_valid_directory) {
item = new FolderItem (child, view);
} else if (child.is_valid_textfile) {
item = new FileItem (child, view);
item = new FileItem (child, view, get_root_folder ());
}

if (item != null) {
Expand Down Expand Up @@ -288,7 +288,7 @@ namespace Scratch.FolderManager {
if (file.is_valid_directory) {
item = new FolderItem (file, view);
} else if (!file.is_temporary) {
item = new FileItem (file, view);
item = new FileItem (file, view, get_root_folder ());
}
}

Expand Down
21 changes: 19 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ namespace Scratch {

folder_manager_view = new FolderManager.FileView ();

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

if (file.is_valid_textfile) {
open_document (doc);
Expand All @@ -342,6 +342,23 @@ namespace Scratch {
}
});


folder_manager_view.project_closed.connect ((a) => {
foreach (Scratch.Widgets.DocumentView? v in split_view.views) {
var to_close = new GLib.List<Services.Document> ();
foreach (Services.Document doc in v.docs) {
if (doc.project_folder == a) {
to_close.append (doc);
}
}

foreach (unowned Services.Document doc in to_close) {
v.close_document (doc);
}

}
});

folder_manager_view.root.child_added.connect (() => {
if (folder_manager_view.get_n_visible_children (folder_manager_view.root) == 0) {
project_pane.add_tab (folder_manager_view);
Expand Down
4 changes: 3 additions & 1 deletion src/Services/Document.vala
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace Scratch.Services {
public string original_content;
private string last_save_content;
public bool saved = true;
public string? project_folder;

private Gtk.ScrolledWindow scroll;
private Gtk.InfoBar info_bar;
Expand All @@ -109,9 +110,10 @@ namespace Scratch.Services {
// Zeitgeist integration
private ZeitgeistLogger zg_log = new ZeitgeistLogger ();
#endif
public Document (SimpleActionGroup actions, File? file = null) {
public Document (SimpleActionGroup actions, File? file = null, string? project_folder = null) {
this.actions = actions;
this.file = file;
this.project_folder = project_folder;
page = main_stack;
}

Expand Down