Merge lp:~gero-bare/scratch/fix-bug-1633916 into lp:~elementary-apps/scratch/scratch

Proposed by Gero.Bare
Status: Rejected
Rejected by: Adam Bieńkowski
Proposed branch: lp:~gero-bare/scratch/fix-bug-1633916
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 116 lines (+67/-2)
2 files modified
plugins/filemanager/FileManagerPlugin.vala (+33/-2)
plugins/filemanager/FileView.vala (+34/-0)
To merge this branch: bzr merge lp:~gero-bare/scratch/fix-bug-1633916
Reviewer Review Type Date Requested Status
Zisu Andrei (community) Needs Fixing
Review via email: mp+309190@code.launchpad.net

Description of the change

This might be an overkill but I'm not aware of a better solution.

On doc closes check if the document is currently selected and de select it from the file view.

I keep track of the documents in order to disconnect the signals when opportune.

To post a comment you must log in.
1772. By Gero.Bare

Fix formatting error.

Revision history for this message
Zisu Andrei (matzipan) wrote :

I confirm your branch fixes the issue and does not introduce any regressions.

However, there's a tiny comment inline.

review: Needs Fixing
Revision history for this message
Zisu Andrei (matzipan) wrote :

Actually, I think I spotted a bug: what happens if the user has 2 tabs open for the same file (right click on the tab and click "duplicate"). When one of them is closed, the item is deselected and no deselection occurs for the second one.

review: Needs Fixing
1773. By Gero.Bare

Now theflemanger selects atomatically the document currently opened in the editor.
Fixed some style issues.

1774. By Gero.Bare

Fix a little screw up. It should compile now.

Revision history for this message
Zisu Andrei (matzipan) wrote :

Hey Gero,

Great progress, but I found a little bug.

How to test:
Open a file (say file a)
Then click the settings icon in the top right and click "Add View".
Now press ctrl+o and open a different file (say file b)
Then press ctrl+o and open the same file as the one you opened in your first step (say file a).

You will have two views, one with two tabs, a and b, and one with a single tab, a.

In the view with two tabs. Close "a". This will leave you with a view with "a", and one with "b".

Press the "a" tab. Your selection won't happen.

Also, there's some comments inline.

Let's get this merged!

review: Needs Fixing
1775. By Gero.Bare

Don't reopen documents unnecessarily.

Revision history for this message
Gero.Bare (gero-bare) wrote :

document.focus () => doesn't focus a shit. Sorry my language but there's only so much I can do it here.

Besides that, I think this works.

Revision history for this message
Zisu Andrei (matzipan) wrote :

Can anybody reject this branch? I'm working on an improvement here: https://code.launchpad.net/~matzipan/scratch/select-file-in-sidebar/+merge/313838

Unmerged revisions

1775. By Gero.Bare

Don't reopen documents unnecessarily.

1774. By Gero.Bare

Fix a little screw up. It should compile now.

1773. By Gero.Bare

Now theflemanger selects atomatically the document currently opened in the editor.
Fixed some style issues.

1772. By Gero.Bare

Fix formatting error.

1771. By Gero.Bare

On document close, check if the file is currently selected and deselect it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/filemanager/FileManagerPlugin.vala'
2--- plugins/filemanager/FileManagerPlugin.vala 2016-09-03 11:50:58 +0000
3+++ plugins/filemanager/FileManagerPlugin.vala 2016-11-18 21:54:58 +0000
4@@ -27,6 +27,7 @@
5
6 Gtk.Box box;
7 FileManager.FileView view;
8+ private Gee.TreeSet <Scratch.Services.Document> docs;
9
10 public Object object { owned get; construct; }
11
12@@ -37,11 +38,21 @@
13 public void activate () {
14 plugins = (Scratch.Services.Interface) object;
15 plugins.hook_notebook_sidebar.connect (on_hook_sidebar);
16+
17+ docs = new Gee.TreeSet <Scratch.Services.Document> ();
18+ plugins.hook_document.connect (on_hook_document);
19 }
20
21 public void deactivate () {
22 if (box != null)
23 box.destroy();
24+
25+ foreach (var doc in docs) {
26+ docs.remove (doc);
27+ doc.doc_closed.disconnect (on_doc_closed);
28+ }
29+
30+ plugins.hook_document.disconnect (on_hook_document);
31 }
32
33 public void update_state () {
34@@ -57,8 +68,14 @@
35 // File View
36 view = new FileManager.FileView ();
37
38- view.select.connect ((a) => {
39- var file = GLib.File.new_for_path (a);
40+ view.select.connect ((path) => {
41+ foreach (var document in docs) {
42+ if (document.file.get_path () == path) {
43+ document.focus ();
44+ return;
45+ }
46+ }
47+ var file = GLib.File.new_for_path (path);
48 plugins.open_file (file);
49 });
50
51@@ -103,6 +120,20 @@
52
53 notebook.append_page (box, new Gtk.Label (_("File Manager")));
54 }
55+
56+ void on_hook_document (Scratch.Services.Document doc) {
57+ if (!docs.contains (doc)) {
58+ docs.add (doc);
59+ doc.doc_closed.connect (on_doc_closed);
60+ }
61+
62+ view.select_item_from_path (doc.file.get_path ());
63+ }
64+
65+ void on_doc_closed (Scratch.Services.Document doc) {
66+ docs.remove (doc);
67+ view.deselect_file_path (doc.file.get_path ());
68+ }
69 }
70 }
71
72
73=== modified file 'plugins/filemanager/FileView.vala'
74--- plugins/filemanager/FileView.vala 2016-09-03 11:50:58 +0000
75+++ plugins/filemanager/FileView.vala 2016-11-18 21:54:58 +0000
76@@ -102,6 +102,40 @@
77 this.selected = null;
78 }
79
80+ public void deselect_file_path (string path) {
81+ if (selected != null) {
82+ if ((selected as FileItem).file.file.get_path () == path) {
83+ selected = null;
84+ }
85+ }
86+ }
87+
88+ public void select_item_from_path (string path) {
89+ debug ("Select filepath %s", path);
90+ if (selected == null || (selected as FileItem).path != path) {
91+ var file = new File (path);
92+ if (file.is_valid_directory) {
93+ return;
94+ }
95+
96+ var parent_folder = new File(file.file.get_parent ().get_path ());
97+ open_folder (parent_folder);
98+
99+ if (this.folder == null) {
100+ debug ("Failed to open %s", parent_folder.file.get_path ());
101+ return;
102+ }
103+
104+ foreach (var item in this.folder.children) {
105+ if ((item as Item).path == path) {
106+ selected = (item as Item);
107+ break;
108+ }
109+ }
110+ debug ("Failed to open filepath %s", path);
111+ }
112+ }
113+
114 private bool is_open (File folder) {
115 foreach (var child in root.children) {
116 if (folder.path == (child as Item).path) {

Subscribers

People subscribed via source and target branches