Merge lp:~gero-bare/scratch/fix-1392031-again into lp:~elementary-apps/scratch/scratch

Proposed by Gero.Bare
Status: Work in progress
Proposed branch: lp:~gero-bare/scratch/fix-1392031-again
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 143 lines (+22/-26)
2 files modified
src/MainWindow.vala (+8/-15)
src/Widgets/SplitView.vala (+14/-11)
To merge this branch: bzr merge lp:~gero-bare/scratch/fix-1392031-again
Reviewer Review Type Date Requested Status
Danielle Foré Needs Fixing
Review via email: mp+318710@code.launchpad.net

Description of the change

Ok things to be tested.

> Open files using the file manager plugin.
> Open new SplitView, make sure that:
  * new tabs (Ctrl-n) are opened in the right split view.
  * files opened with the filemanager are opened in the right view.
  * switch focus between views and test the same conditions.

etc.

Additional notes. Sometimes a view is closed and when reopened it opens all the previously opened files but sometimes not. I don't know if intended or not, I wont fix.
I found that opening files with folder icon, can sometimes open the same file twice in the same splitview, I couldn't reproduce reliably plus I found it in the middle of the iteration so be warned, but I don't think that it's entirely my fault. But I won't fix.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Please make sure this doesn't break the folder sidebar

review: Needs Fixing
Revision history for this message
Danielle Foré (danrabbit) wrote :

With this change, opening files from the folder sidebar often does not work. It seems like it's maybe trying to open the file in the closed pane instead of the opened one.

Unmerged revisions

1831. By Gero.Bare

      * Fixed bug 1392031 again

      * Removed calls to split_view.get_focus_child (), use get_current_view () instead.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/MainWindow.vala'
2--- src/MainWindow.vala 2017-01-06 17:11:40 +0000
3+++ src/MainWindow.vala 2017-03-04 05:29:54 +0000
4@@ -479,11 +479,7 @@
5 view.open_document (doc);
6 } else {
7 if (view == null) {
8- view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
9- }
10-
11- if (view == null) {
12- view = this.split_view.current_view;
13+ view = this.split_view.get_current_view ();
14 }
15
16 view.open_document (doc);
17@@ -497,10 +493,7 @@
18 view = split_view.add_view ();
19 view.close_document (doc);
20 } else {
21- view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
22- if (view == null) {
23- view = this.split_view.current_view;
24- }
25+ view = split_view.get_current_view ();
26
27 view.close_document (doc);
28 }
29@@ -762,7 +755,7 @@
30 if (this.split_view.is_empty ()) {
31 view = split_view.add_view ();
32 } else {
33- view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
34+ view = split_view.get_current_view ();
35 }
36
37 view.new_document ();
38@@ -773,7 +766,7 @@
39 if (this.split_view.is_empty ()) {
40 view = split_view.add_view ();
41 } else {
42- view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
43+ view = split_view.get_current_view ();
44 }
45
46 string text_from_clipboard = clipboard.wait_for_text ();
47@@ -859,19 +852,19 @@
48
49 private void action_next_tab () {
50 Scratch.Widgets.DocumentView? view = null;
51- view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
52+ view = split_view.get_current_view ();
53 view.next_document ();
54 }
55
56 private void action_previous_tab () {
57 Scratch.Widgets.DocumentView? view = null;
58- view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
59+ view = split_view.get_current_view ();
60 view.previous_document ();
61 }
62
63 private void action_to_lower_case () {
64 Scratch.Widgets.DocumentView? view = null;
65- view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
66+ view = split_view.get_current_view ();
67 var doc = view.get_current_document ();
68 if (doc == null) {
69 return;
70@@ -888,7 +881,7 @@
71
72 private void action_to_upper_case () {
73 Scratch.Widgets.DocumentView? view = null;
74- view = split_view.get_focus_child () as Scratch.Widgets.DocumentView;
75+ view = split_view.get_current_view ();
76 var doc = view.get_current_document ();
77 if (doc == null) {
78 return;
79
80=== modified file 'src/Widgets/SplitView.vala'
81--- src/Widgets/SplitView.vala 2017-02-17 17:07:43 +0000
82+++ src/Widgets/SplitView.vala 2017-03-04 05:29:54 +0000
83@@ -24,7 +24,7 @@
84
85 // Widgets
86 public Granite.Widgets.Welcome welcome_screen;
87- public Scratch.Widgets.DocumentView? current_view = null;
88+ private Scratch.Widgets.DocumentView? current_view = null;
89
90 public GLib.List<Scratch.Widgets.DocumentView> views;
91 private GLib.List<Scratch.Widgets.DocumentView> hidden_views;
92@@ -133,12 +133,14 @@
93 public void remove_view (Scratch.Widgets.DocumentView? view = null) {
94 // If no specific view is required to be removed, just remove the current one
95 if (view == null)
96- view = get_focus_child () as Scratch.Widgets.DocumentView;
97+ view = current_view;
98 if (view == null) {
99 warning ("There is no focused view to remove!");
100 return;
101 }
102
103+ view.save_opened_files ();
104+
105 foreach (var doc in view.docs) {
106 if (!doc.close (true)) {
107 view.set_current_document (doc);
108@@ -155,9 +157,6 @@
109
110 view.view_id = 2;
111 right_view.view_id = 1;
112-
113- view.save_opened_files ();
114- right_view.save_opened_files ();
115 } else {
116 remove (view);
117 }
118@@ -177,16 +176,20 @@
119 }
120
121 // Show/Hide welcome screen
122- if (this.views.length () == 0)
123+ if (this.views.length () == 0) {
124+ current_view = null;
125 show_welcome ();
126+ } else {
127+ current_view = get_child1 () as Scratch.Widgets.DocumentView;
128+ }
129+
130 }
131
132 public Scratch.Widgets.DocumentView? get_current_view () {
133- views.foreach ((v) => {
134- if (v.has_focus) {
135- current_view = v;
136- }
137- });
138+ Scratch.Widgets.DocumentView _current_view = get_focus_child () as Scratch.Widgets.DocumentView;
139+ if (_current_view != null) {
140+ current_view = _current_view;
141+ }
142 return current_view;
143 }
144

Subscribers

People subscribed via source and target branches