Merge lp:~superscript18/scratch/bugfix-1390607 into lp:~elementary-apps/scratch/scratch

Proposed by SuperScript
Status: Rejected
Rejected by: Cody Garver
Proposed branch: lp:~superscript18/scratch/bugfix-1390607
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 220 lines (+59/-81)
3 files modified
data/scratch-text-editor.desktop (+1/-1)
src/MainWindow.vala (+2/-46)
src/Scratch.vala (+56/-34)
To merge this branch: bzr merge lp:~superscript18/scratch/bugfix-1390607
Reviewer Review Type Date Requested Status
Jeremy Wootten Needs Fixing
Danielle Foré Needs Fixing
Review via email: mp+250651@code.launchpad.net

This proposal supersedes a proposal from 2015-02-10.

Description of the change

I have reworked the logic in launching Scratch. This new method is quite a bit cleaner and fixes several problems:

1. Scratch opens temporary (unsaved) documents when you open a second window. This is a pain because they are opened twice and cannot be closed in either instance without losing data.

2. When you opened a new window in Scratch, the previous window would try to get your attention (`window.present ()`) resulting in an unneeded red icon in Plank.

3. Middle-clicking on the Scratch icon in Plank did nothing. Now it should open a blank new window ready for you to work.

I've included elementary-design to decide if all this functionality is correct.

This fixes bugs:
Bug #1420549: middle-click on Plank does nothing
Bug #1390607: don't open unsaved files in new windows

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

* Segfault when closing a second new window with nothing open while having a file open in the first window

*Can confirm that unsaved files don't open in new windows.

review: Needs Fixing
Revision history for this message
SuperScript (superscript18) wrote :

@DanielFore: I can't reproduce that SEGFAULT. Can you post some more detail instructions?

Also, should we have Pantheon Files open a new window by default, too?

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

Conflicts with trunk r1618 and does not compile with vala-0.28.

After fixing conflicts compiles on valac 0.28. Note careful resolving of conflict in Scratch.vala required.

Using the merged branch:

Cannot reproduce bug 1390607 in latest trunk (or in this branch).

New window on middle click on Plank icon works.

Could not reproduce crash mentioned by Dan.

See inline comment regarding unhandled errors and spelling

Needs fixing but potentially mergeable.

review: Needs Fixing

Unmerged revisions

1451. By SuperScript

 isn't needed anymore.

1450. By SuperScript

fixed tab/space to match elementary guidelines

1449. By SuperScript

Redid Scratch's startup procedure

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/scratch-text-editor.desktop'
2--- data/scratch-text-editor.desktop 2014-04-12 23:26:29 +0000
3+++ data/scratch-text-editor.desktop 2015-02-23 16:40:09 +0000
4@@ -3,7 +3,7 @@
5 Name=Scratch
6 Comment=Edit text files
7 GenericName=Text Editor
8-Exec=scratch-text-editor %U
9+Exec=scratch-text-editor --new-window %U
10 Icon=accessories-text-editor
11 Terminal=false
12 Categories=GNOME;GTK;Utility;TextEditor;
13
14=== modified file 'src/MainWindow.vala'
15--- src/MainWindow.vala 2015-01-22 21:59:26 +0000
16+++ src/MainWindow.vala 2015-02-23 16:40:09 +0000
17@@ -94,9 +94,6 @@
18 // Restore session
19 restore_saved_state_extra ();
20
21- // Crate folder for unsaved documents
22- create_unsaved_documents_directory ();
23-
24 #if HAVE_ZEITGEIST
25 // Set up the Data Source Registry for Zeitgeist
26 registry = new DataSourceRegistry ();
27@@ -263,17 +260,13 @@
28
29 this.search_revealer.set_reveal_child (false);
30
31- main_actions.get_action ("OpenTemporaryFiles").visible = this.has_temporary_files ();
32 main_actions.get_action ("SaveFile").visible = !settings.autosave;
33 main_actions.get_action ("Templates").visible = plugins.plugin_iface.template_manager.template_available;
34 plugins.plugin_iface.template_manager.notify["template_available"].connect ( () => {
35 main_actions.get_action ("Templates").visible = plugins.plugin_iface.template_manager.template_available;
36 });
37-
38- if (has_temporary_files ())
39- action_open_temporary_files ();
40- else
41- this.split_view.show_welcome ();
42+
43+ this.split_view.show_welcome ();
44
45 // Plugins hook
46 HookFunc hook_func = () => {
47@@ -422,18 +415,6 @@
48 return split_view.is_empty ();
49 }
50
51- public bool has_temporary_files () {
52- FileEnumerator enumerator = File.new_for_path (app.data_home_folder_unsaved).enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
53- var fileinfo = enumerator.next_file (null);
54- while (fileinfo != null) {
55- if (!fileinfo.get_name ().has_suffix ("~")) {
56- return true;
57- }
58- fileinfo = enumerator.next_file (null);
59- }
60- return false;
61- }
62-
63 // Check if there no unsaved changes
64 private bool check_unsaved_changes () {
65 if (!is_empty ()) {
66@@ -471,16 +452,6 @@
67 vp.set_position (Scratch.saved_state.vp_size);
68 }
69
70- private void create_unsaved_documents_directory () {
71- File directory = File.new_for_path (app.data_home_folder_unsaved);
72- if (!directory.query_exists ()) {
73- debug ("create 'unsaved' directory: %s", directory.get_path ());
74- directory.make_directory_with_parents ();
75- return;
76- }
77- debug ("'unsaved' directory already exists.");
78- }
79-
80 private void update_saved_state () {
81
82 // Save window state
83@@ -648,21 +619,6 @@
84 filech.close ();
85 }
86
87- void action_open_temporary_files () {
88- FileEnumerator enumerator = File.new_for_path (app.data_home_folder_unsaved).enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
89- var fileinfo = enumerator.next_file (null);
90- while (fileinfo != null) {
91- if (!fileinfo.get_name ().has_suffix ("~")) {
92- debug ("open temporary file: %s", fileinfo.get_name ());
93- var file = File.new_for_path (app.data_home_folder_unsaved + fileinfo.get_name ());
94- var doc = new Scratch.Services.Document (this.main_actions, file);
95- this.open_document (doc);
96- }
97- // Next file info
98- fileinfo = enumerator.next_file (null);
99- }
100- }
101-
102 void action_save () {
103 this.get_current_document ().save ();
104 }
105
106=== modified file 'src/Scratch.vala'
107--- src/Scratch.vala 2014-11-29 11:46:53 +0000
108+++ src/Scratch.vala 2015-02-23 16:40:09 +0000
109@@ -125,22 +125,56 @@
110
111 return Posix.EXIT_FAILURE;
112 }
113-
114- bool is_app_launch = (get_last_window () == null);
115-
116- // Create (or show) the first window
117- activate ();
118-
119- // Create a next window if requested and it's not the app launch
120- if (create_new_window && !is_app_launch) {
121+
122+ var window = get_last_window ();
123+
124+ bool is_app_launch = (window == null);
125+
126+ if (create_new_window || is_app_launch) {
127 create_new_window = false;
128- this.new_window ();
129+ window = this.new_window ();
130+ }
131+
132+ // Crate folder for unsaved documents
133+ create_unsaved_documents_directory ();
134+
135+ if (is_app_launch) {
136+ // restore opened documents
137+ if (settings.show_at_start == "last-tabs") {
138+ window.start_loading ();
139+
140+ string[] uris = settings.schema.get_strv ("opened-files");
141+
142+ foreach (string uri in uris) {
143+ if (uri != "") {
144+ var file = File.new_for_uri (uri);
145+ if (file.query_exists ()) {
146+ var doc = new Scratch.Services.Document (window.main_actions, file);
147+ window.open_document (doc);
148+ }
149+ }
150+ }
151+ window.stop_loading ();
152+ }
153+
154+ // restore temporary files
155+ FileEnumerator enumerator = File.new_for_path (data_home_folder_unsaved).enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
156+ var fileinfo = enumerator.next_file (null);
157+ while (fileinfo != null) {
158+ if (!fileinfo.get_name ().has_suffix ("~")) {
159+ debug ("open temporary file: %s", fileinfo.get_name ());
160+ var file = File.new_for_path (data_home_folder_unsaved + fileinfo.get_name ());
161+ var doc = new Scratch.Services.Document (window.main_actions, file);
162+ window.open_document (doc);
163+ }
164+ // Next file info
165+ fileinfo = enumerator.next_file (null);
166+ }
167 }
168
169 // Create a new document if requested
170 if (create_new_tab) {
171 create_new_tab = false;
172- var window = get_last_window ();
173 window.main_actions.get_action ("NewTab").activate ();
174 }
175
176@@ -162,32 +196,20 @@
177 return Posix.EXIT_SUCCESS;
178 }
179
180+ private void create_unsaved_documents_directory () {
181+ File directory = File.new_for_path (data_home_folder_unsaved);
182+ if (!directory.query_exists ()) {
183+ debug ("create 'unsaved' directory: %s", directory.get_path ());
184+ directory.make_directory_with_parents ();
185+ return;
186+ }
187+ debug ("'unsaved' directory already exists.");
188+ }
189+
190 protected override void activate () {
191- var window = get_last_window ();
192- if (window == null) {
193- window = this.new_window ();
194- window.show ();
195- // Restore opened documents
196- if (settings.show_at_start == "last-tabs") {
197- window.start_loading ();
198-
199- string[] uris = settings.schema.get_strv ("opened-files");
200-
201- foreach (string uri in uris) {
202- if (uri != "") {
203- var file = File.new_for_uri (uri);
204- if (file.query_exists ()) {
205- var doc = new Scratch.Services.Document (window.main_actions, file);
206- window.open_document (doc);
207- }
208- }
209- }
210- window.stop_loading ();
211- }
212- } else {
213+ var window = get_last_window();
214+ if (window != null)
215 window.present ();
216- }
217-
218 }
219
220 protected override void open (File[] files, string hint) {

Subscribers

People subscribed via source and target branches