Merge lp:~philip.scott/pantheon-notes/open-with into lp:pantheon-notes
- open-with
- Merge into trunk
Proposed by
Felipe Escoto
Status: | Needs review |
---|---|
Proposed branch: | lp:~philip.scott/pantheon-notes/open-with |
Merge into: | lp:pantheon-notes |
Diff against target: |
525 lines (+209/-85) 8 files modified
CMakeLists.txt (+0/-1) data/pantheon-notes.desktop (+2/-1) src/Application.vala (+61/-6) src/Main.vala (+0/-17) src/Services/Page.vala (+19/-5) src/Widgets/Editor.vala (+14/-11) src/Widgets/PagesList.vala (+18/-4) src/Widgets/Window.vala (+95/-40) |
To merge this branch: | bzr merge lp:~philip.scott/pantheon-notes/open-with |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Zisu Andrei (community) | Needs Fixing | ||
Review via email:
|
Commit message
open-with support
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Zisu Andrei (matzipan) wrote : | # |
Built it and ran it, and I couldn't find any "Open with" menu entry.
review:
Needs Fixing
Unmerged revisions
- 10. By Felipe Escoto
-
Open-with support
- 9. By Felipe Escoto
-
working with CMD args
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2016-03-06 22:25:43 +0000 |
3 | +++ CMakeLists.txt 2016-03-22 22:02:29 +0000 |
4 | @@ -69,7 +69,6 @@ |
5 | include(ValaPrecompile) |
6 | |
7 | vala_precompile(VALA_C |
8 | - src/Main.vala |
9 | src/Application.vala |
10 | src/Services/FileManager.vala |
11 | src/Services/Notebook.vala |
12 | |
13 | === modified file 'data/pantheon-notes.desktop' |
14 | --- data/pantheon-notes.desktop 2016-03-06 22:25:43 +0000 |
15 | +++ data/pantheon-notes.desktop 2016-03-22 22:02:29 +0000 |
16 | @@ -2,8 +2,9 @@ |
17 | Encoding=UTF-8 |
18 | Name=Notes |
19 | Comment=Simple note taking |
20 | -Exec=/usr/bin/pantheon-notes |
21 | +Exec=/usr/bin/pantheon-notes %U |
22 | Icon=pantheon-notes |
23 | +MimeType=text/plain; |
24 | Terminal=false |
25 | Type=Application |
26 | StartupNotify=true |
27 | |
28 | === modified file 'src/Application.vala' |
29 | --- src/Application.vala 2016-03-07 12:11:58 +0000 |
30 | +++ src/Application.vala 2016-03-22 22:02:29 +0000 |
31 | @@ -1,26 +1,69 @@ |
32 | |
33 | namespace Notes { |
34 | - public Notes.PagesList pages_list; |
35 | - public Notes.Editor editor; |
36 | - public Notes.Services.Settings settings; |
37 | - public Notes.Window window; |
38 | public string NOTES_DIR; |
39 | + public static const string APP_NAME = "Notes"; |
40 | + public static const string CODE_NAME = "pantheon-notes"; |
41 | } |
42 | |
43 | public class Notes.Application : Granite.Application { |
44 | + private Notes.Window window; |
45 | + |
46 | public const string PROGRAM_NAME = N_("Notes"); |
47 | public const string COMMENT = N_("Simple notes editing"); |
48 | public const string ABOUT_STOCK = N_("About Notes"); |
49 | |
50 | public bool running = false; |
51 | |
52 | + public static int main (string[] args) { |
53 | + Application app = Application.instance; |
54 | + return app.run (args); |
55 | + } |
56 | + |
57 | + construct { |
58 | + flags |= ApplicationFlags.HANDLES_OPEN; |
59 | + |
60 | + program_name = APP_NAME; |
61 | + exec_name = "pantheon-notes"; |
62 | + app_years = "2011-2015"; |
63 | + app_icon = "accessories-notes"; |
64 | + app_launcher = "pantheon-notes.desktop"; |
65 | + application_id = "org.elementary." + CODE_NAME.down (); |
66 | + main_url = "https://launchpad.net/pantheon-notes"; |
67 | + bug_url = "https://bugs.launchpad.net/pantheon-notes"; |
68 | + help_url = "https://elementary.io/help/pantheon-notes"; |
69 | + translate_url = "https://translations.launchpad.net/pantheon-notes"; |
70 | + about_authors = { "Felipe Escoto <felescoto95@hotmail.com>", null}; |
71 | + about_documenters = { "",null }; |
72 | + about_artists = { "", null}; |
73 | + about_translators = _("translator-credits"); |
74 | + about_license_type = Gtk.License.GPL_3_0; |
75 | + } |
76 | + |
77 | public Application () { |
78 | - Object (application_id: "org.pantheon-notes"); |
79 | + Intl.setlocale (LocaleCategory.ALL, Intl.get_language_names ()[0]); |
80 | + Environment.set_application_name (APP_NAME); |
81 | + Environment.set_prgname (APP_NAME); |
82 | + } |
83 | + |
84 | + public static Application _instance = null; |
85 | + |
86 | + public static Application instance { |
87 | + get { |
88 | + if (_instance == null) |
89 | + _instance = new Application (); |
90 | + return _instance; |
91 | + } |
92 | } |
93 | |
94 | public override void activate () { |
95 | + this.hold (); |
96 | + app_window (); |
97 | + this.release (); |
98 | + } |
99 | + |
100 | + private void app_window () { |
101 | if (!running) { |
102 | - settings = new Notes.Services.Settings (); |
103 | + var settings = new Notes.Services.Settings (); |
104 | |
105 | if (settings.notes_location == "") { |
106 | settings.notes_location = Path.build_filename (Environment.get_user_data_dir (), CODE_NAME); |
107 | @@ -36,4 +79,16 @@ |
108 | |
109 | window.show_app (); |
110 | } |
111 | + |
112 | + private void file_window (File file) { |
113 | + var window = new Notes.Window.with_file (this, file); |
114 | + window.show_app (); |
115 | + } |
116 | + |
117 | + //the application was requested to open some files |
118 | + public override void open (File[] files, string hint) { |
119 | + foreach (File file in files) { |
120 | + file_window (file); |
121 | + } |
122 | + } |
123 | } |
124 | |
125 | === modified file 'src/Main.vala' |
126 | --- src/Main.vala 2016-03-07 12:10:23 +0000 |
127 | +++ src/Main.vala 2016-03-22 22:02:29 +0000 |
128 | @@ -14,20 +14,3 @@ |
129 | with this program. If not, see <http://www.gnu.org/licenses/>. |
130 | ***/ |
131 | |
132 | -public static const string APP_NAME = "Notes"; |
133 | -public static const string CODE_NAME = "pantheon-notes"; |
134 | - |
135 | -public static int main (string[] args) { |
136 | - /* Initiliaze gettext support */ |
137 | - Intl.setlocale (LocaleCategory.ALL, Intl.get_language_names ()[0]); |
138 | - //Intl.textdomain (Config.GETTEXT_PACKAGE); |
139 | - |
140 | - Environment.set_application_name (APP_NAME); |
141 | - Environment.set_prgname (CODE_NAME); |
142 | - |
143 | - var application = new Notes.Application (); |
144 | - |
145 | - return application.run (args); |
146 | -} |
147 | - |
148 | - |
149 | |
150 | === modified file 'src/Services/Page.vala' |
151 | --- src/Services/Page.vala 2016-03-06 21:56:56 +0000 |
152 | +++ src/Services/Page.vala 2016-03-22 22:02:29 +0000 |
153 | @@ -28,6 +28,16 @@ |
154 | load_subtitle (load_text ()); |
155 | } |
156 | |
157 | + public Page.from_file (File file) { |
158 | + this.file = file; |
159 | + if (!file.query_exists ()) { |
160 | + new_page = true; |
161 | + } |
162 | + |
163 | + this.path = file.get_path (); |
164 | + this.name = file.get_basename (); |
165 | + } |
166 | + |
167 | private void load_subtitle (string data) { |
168 | setup (); |
169 | string line[2]; |
170 | @@ -71,7 +81,7 @@ |
171 | return; |
172 | } |
173 | |
174 | - string file_name = make_filename (); |
175 | + string file_name = make_filename (data); |
176 | |
177 | try { |
178 | if (file.query_exists ()) { |
179 | @@ -111,11 +121,15 @@ |
180 | return output; |
181 | } |
182 | |
183 | - private string make_filename () { |
184 | - string file_name = editor.get_text ().split ("\n", 2)[0]; |
185 | - file_name = file_name.replace ("#", "").replace ("\n", ""); |
186 | + private string make_filename (string page_contents) { |
187 | + string file_name = ""; |
188 | + if (ID != -1) { |
189 | + file_name = page_contents.split ("\n", 2)[0]; |
190 | + file_name = file_name.replace ("#", "").replace ("\n", ""); |
191 | + file_name = ID.to_string () + "§" + file_name; |
192 | + } |
193 | |
194 | - return ID.to_string () + "§" + file_name; |
195 | + return file_name; |
196 | } |
197 | |
198 | private void setup () { |
199 | |
200 | === modified file 'src/Widgets/Editor.vala' |
201 | --- src/Widgets/Editor.vala 2016-03-07 12:10:23 +0000 |
202 | +++ src/Widgets/Editor.vala 2016-03-22 22:02:29 +0000 |
203 | @@ -1,4 +1,5 @@ |
204 | public class Notes.Editor : Gtk.Box { |
205 | + private Notes.Window window; |
206 | private Gtk.SourceView code_view; |
207 | private Gtk.SourceBuffer code_buffer; |
208 | |
209 | @@ -6,18 +7,22 @@ |
210 | |
211 | public Notes.Page current_page = null; |
212 | |
213 | - public Editor () { |
214 | + public Editor (Notes.Window window) { |
215 | + this.window = window; |
216 | + |
217 | build_ui (); |
218 | reset (true); |
219 | load_settings (); |
220 | } |
221 | |
222 | public void load_file (Notes.Page page) { |
223 | + window.set_title (page.name); |
224 | + |
225 | code_buffer.begin_not_undoable_action (); |
226 | |
227 | save_file (); |
228 | |
229 | - current_page = page; |
230 | + current_page = page; |
231 | code_buffer.text = page.load_text (); |
232 | |
233 | code_buffer.end_not_undoable_action (); |
234 | @@ -58,7 +63,7 @@ |
235 | if (disable_save) { |
236 | edited = false; |
237 | } |
238 | - |
239 | + |
240 | code_buffer.text = ""; |
241 | } |
242 | |
243 | @@ -71,8 +76,8 @@ |
244 | } |
245 | |
246 | public void load_settings () { |
247 | - set_scheme (settings.editor_scheme); |
248 | - set_font (settings.editor_font); |
249 | + set_scheme (window.settings.editor_scheme); |
250 | + set_font (window.settings.editor_font); |
251 | } |
252 | |
253 | public void set_font (string name) { |
254 | @@ -91,8 +96,6 @@ |
255 | } |
256 | |
257 | private void build_ui () { |
258 | - var manager = Gtk.SourceLanguageManager.get_default (); |
259 | - var language = manager.guess_language (null, "text/x-markdown"); |
260 | code_buffer = new Gtk.SourceBuffer (null); |
261 | code_buffer.set_max_undo_levels (100); |
262 | |
263 | @@ -108,13 +111,13 @@ |
264 | code_view.wrap_mode = Gtk.WrapMode.WORD; |
265 | code_view.show_line_numbers = false; |
266 | |
267 | - var scroll_box = new Gtk.ScrolledWindow (null, null); |
268 | - scroll_box.add (code_view); |
269 | + var scroll_box = new Gtk.ScrolledWindow (null, null); |
270 | + scroll_box.add (code_view); |
271 | |
272 | - this.set_orientation (Gtk.Orientation.VERTICAL); |
273 | + this.set_orientation (Gtk.Orientation.VERTICAL); |
274 | this.add (scroll_box); |
275 | this.set_sensitive (false); |
276 | - scroll_box.expand = true; |
277 | + scroll_box.expand = true; |
278 | this.show_all (); |
279 | } |
280 | } |
281 | |
282 | === modified file 'src/Widgets/PagesList.vala' |
283 | --- src/Widgets/PagesList.vala 2016-03-07 12:10:23 +0000 |
284 | +++ src/Widgets/PagesList.vala 2016-03-22 22:02:29 +0000 |
285 | @@ -2,6 +2,9 @@ |
286 | private Gtk.ListBox listbox; |
287 | private Gtk.Frame toolbar; |
288 | |
289 | + private Notes.Editor editor; |
290 | + private Notes.Window window; |
291 | + |
292 | private Gtk.Separator separator; |
293 | private Gtk.Button minus_button; |
294 | private Gtk.Button plus_button; |
295 | @@ -10,7 +13,10 @@ |
296 | |
297 | public Notes.Notebook current_notebook; |
298 | |
299 | - public PagesList () { |
300 | + public PagesList (Notes.Window window, Notes.Editor editor) { |
301 | + this.window = window; |
302 | + this.editor = editor; |
303 | + |
304 | build_ui (); |
305 | connect_signals (); |
306 | |
307 | @@ -23,10 +29,12 @@ |
308 | orientation = Gtk.Orientation.VERTICAL; |
309 | |
310 | var scroll_box = new Gtk.ScrolledWindow (null, null); |
311 | + |
312 | listbox = new Gtk.ListBox (); |
313 | - listbox.set_size_request (200,250); |
314 | + listbox.activate_on_single_click = true; |
315 | + listbox.vexpand = true; |
316 | + |
317 | scroll_box.set_size_request (200,250); |
318 | - listbox.vexpand = true; |
319 | toolbar = build_toolbar (); |
320 | |
321 | scroll_box.add (listbox); |
322 | @@ -144,6 +152,8 @@ |
323 | editor.load_file (page); |
324 | listbox.prepend (page_item); |
325 | listbox.show_all (); |
326 | + |
327 | + listbox.select_row (page_item); |
328 | } |
329 | |
330 | private void connect_signals () { |
331 | @@ -165,7 +175,11 @@ |
332 | |
333 | listbox.row_selected.connect ((row) => { |
334 | minus_button.sensitive = (row != null); |
335 | - if (row == null) return; |
336 | + if (row == null) { |
337 | + window.set_title (null); |
338 | + return; |
339 | + } |
340 | + |
341 | editor.load_file (((Notes.PageItem) row).page); |
342 | editor.give_focus (); |
343 | }); |
344 | |
345 | === modified file 'src/Widgets/Window.vala' |
346 | --- src/Widgets/Window.vala 2016-03-07 12:10:23 +0000 |
347 | +++ src/Widgets/Window.vala 2016-03-22 22:02:29 +0000 |
348 | @@ -1,38 +1,66 @@ |
349 | public class Notes.Window : Gtk.ApplicationWindow { |
350 | + public Notes.Services.Settings settings; |
351 | + |
352 | private Notes.Headerbar headerbar; |
353 | + private Notes.Editor editor; |
354 | + private Notes.PagesList pages_list; |
355 | + |
356 | private Gtk.Paned pane; |
357 | |
358 | + private bool full_app = true; |
359 | + |
360 | public Window (Gtk.Application app) { |
361 | - Object (application: app); |
362 | - |
363 | - build_ui (); |
364 | + Object (application: app); |
365 | + |
366 | + settings = new Notes.Services.Settings (); |
367 | + |
368 | + build_ui (); |
369 | connect_signals (app); |
370 | load_settings (); |
371 | } |
372 | |
373 | + public Window.with_file (Gtk.Application app, File file) { |
374 | + Object (application: app); |
375 | + |
376 | + settings = new Notes.Services.Settings (); |
377 | + |
378 | + simple_ui (); |
379 | + simple_settings (); |
380 | + |
381 | + full_app = false; |
382 | + |
383 | + var page = new Notes.Page.from_file (file); |
384 | + editor.load_file (page); |
385 | + } |
386 | + |
387 | protected override bool delete_event (Gdk.EventAny event) { |
388 | - int width; |
389 | - int height; |
390 | - int x; |
391 | - int y; |
392 | - |
393 | - editor.save_file (); |
394 | - get_size (out width, out height); |
395 | - get_position (out x, out y); |
396 | - |
397 | - settings.pos_x = x; |
398 | - settings.pos_y = y; |
399 | - settings.panel_size = pane.position; |
400 | - settings.window_width = width; |
401 | - settings.window_height = height; |
402 | - settings.last_folder = pages_list.current_notebook.path; |
403 | - settings.page_path = editor.current_page.full_path; |
404 | - |
405 | - return false; |
406 | - } |
407 | + int width; |
408 | + int height; |
409 | + int x; |
410 | + int y; |
411 | + |
412 | + this.get_size (out width, out height); |
413 | + this.get_position (out x, out y); |
414 | + |
415 | + settings.pos_x = x; |
416 | + settings.pos_y = y; |
417 | + settings.window_width = width; |
418 | + settings.window_height = height; |
419 | + |
420 | + if (full_app) { |
421 | + editor.save_file (); |
422 | + settings.panel_size = pane.position; |
423 | + settings.last_folder = pages_list.current_notebook.path; |
424 | + settings.page_path = editor.current_page.full_path; |
425 | + } else { |
426 | + editor.save_file (); |
427 | + } |
428 | + |
429 | + return false; |
430 | + } |
431 | |
432 | protected override bool key_press_event (Gdk.EventKey event) { |
433 | - if (pages_list.current_notebook.pages.length () <= 0) { |
434 | + if (full_app && pages_list.current_notebook.pages.length () <= 0) { |
435 | new_page (); |
436 | pages_list.select_first (); |
437 | } |
438 | @@ -40,22 +68,31 @@ |
439 | return base.key_press_event (event); |
440 | } |
441 | |
442 | - private void load_settings () { |
443 | + private void load_settings () { |
444 | + simple_settings (); |
445 | + pane.position = settings.panel_size; |
446 | + |
447 | + if (settings.last_folder != "") { |
448 | + var notebook = new Notes.Notebook (settings.last_folder); |
449 | + notebook.refresh (); |
450 | + |
451 | + pages_list.load_pages (notebook); |
452 | + } |
453 | + |
454 | + string path = settings.page_path; |
455 | + |
456 | + if (path != "") { |
457 | + var page = new Notes.Page (path); |
458 | + |
459 | + if (!page.new_page) |
460 | + editor.load_file (page); |
461 | + } |
462 | + } |
463 | + |
464 | + private void simple_settings () { |
465 | resize (settings.window_width, settings.window_height); |
466 | - pane.position = settings.panel_size; |
467 | - |
468 | - if (settings.last_folder != "") { |
469 | - var notebook = new Notes.Notebook (settings.last_folder); |
470 | - notebook.refresh (); |
471 | - |
472 | - pages_list.load_pages (notebook); |
473 | - } |
474 | - |
475 | - var row = pages_list.get_row_from_path (settings.page_path); |
476 | - if (row != null) { |
477 | - row.activate (); |
478 | - } |
479 | - } |
480 | + Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true; |
481 | + } |
482 | |
483 | private void build_ui () { |
484 | headerbar = new Notes.Headerbar (); |
485 | @@ -63,8 +100,8 @@ |
486 | set_titlebar (headerbar); |
487 | |
488 | pane = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); |
489 | - editor = new Notes.Editor (); |
490 | - pages_list = new Notes.PagesList (); |
491 | + editor = new Notes.Editor (this); |
492 | + pages_list = new Notes.PagesList (this, editor); |
493 | |
494 | pane.pack1 (pages_list, false, false); |
495 | pane.pack2 (editor, true, false); |
496 | @@ -75,6 +112,16 @@ |
497 | this.show_all (); |
498 | } |
499 | |
500 | + private void simple_ui () { |
501 | + this.headerbar = new Notes.Headerbar (); |
502 | + set_titlebar (headerbar); |
503 | + |
504 | + editor = new Notes.Editor (this); |
505 | + |
506 | + this.add (editor); |
507 | + this.show_all (); |
508 | + } |
509 | + |
510 | private void connect_signals (Gtk.Application app) { |
511 | var save_action = new SimpleAction ("save", null); |
512 | save_action.activate.connect (save); |
513 | @@ -110,4 +157,12 @@ |
514 | |
515 | editor.give_focus (); |
516 | } |
517 | + |
518 | + public new void set_title (string? title) { |
519 | + if (title != null) { |
520 | + headerbar.set_title (title); |
521 | + } else { |
522 | + headerbar.set_title (APP_NAME); |
523 | + } |
524 | + } |
525 | } |
Some feedback. I can't see anything obviously wrong. Haven't build it.