Merge lp:~gue5t/midori/notes-cleanup into lp:midori

Proposed by gue5t gue5t
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 6616
Merged at revision: 6616
Proposed branch: lp:~gue5t/midori/notes-cleanup
Merge into: lp:midori
Diff against target: 111 lines (+22/-21)
1 file modified
extensions/notes.vala (+22/-21)
To merge this branch: bzr merge lp:~gue5t/midori/notes-cleanup
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Review via email: mp+212068@code.launchpad.net

Commit message

Maintain a current note instead of an id in the notes extension

Description of the change

Just a minor cleanup.

To post a comment you must log in.
Revision history for this message
Paweł Forysiuk (tuxator) wrote :

Nice cleanup. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extensions/notes.vala'
2--- extensions/notes.vala 2014-03-17 02:36:25 +0000
3+++ extensions/notes.vala 2014-03-20 22:22:44 +0000
4@@ -19,7 +19,7 @@
5 Midori.Database database;
6 unowned Sqlite.Database db;
7 Gtk.ListStore notes_list_store;
8- int64 last_used_id;
9+ Note? current_note;
10
11 class Note : GLib.Object {
12 public int64 id { get; set; }
13@@ -118,7 +118,11 @@
14 Note note;
15 notes_list_store.get (iter, 0, out note);
16 if (id == note.id) {
17+ if (current_note == note) {
18+ current_note = null;
19+ }
20 notes_list_store.remove (iter);
21+ break;
22 }
23 } while (notes_list_store.iter_next (ref iter));
24 }
25@@ -231,17 +235,10 @@
26 }
27
28 void save_current_note () {
29- Gtk.TreePath? path;
30- notes_tree_view.get_cursor (out path, null);
31- return_val_if_fail (path != null, false);
32- Gtk.TreeIter iter;
33- if (notes_list_store.get_iter (out iter, path)) {
34- Note note;
35- notes_list_store.get (iter, 0, out note);
36- if (last_used_id == note.id) {
37- string note_content = note_text_view.buffer.text;
38- note.update (note_content);
39- }
40+ if (current_note != null) {
41+ string note_content = note_text_view.buffer.text;
42+ if (note_content != current_note.content)
43+ current_note.update (note_content);
44 }
45 }
46
47@@ -277,6 +274,7 @@
48
49 private void selection_changed (Gtk.TreeSelection selection)
50 {
51+ save_current_note ();
52 show_note_content (selection);
53 }
54
55@@ -299,9 +297,9 @@
56 Note note;
57 notes_list_store.get (iter, 0, out note);
58
59- if (last_used_id != note.id) {
60+ if (note != current_note) {
61 note_text_view.buffer.text = note.content;
62- last_used_id = note.id;
63+ current_note = note;
64 }
65
66 return true;
67@@ -331,8 +329,15 @@
68 }
69
70 bool show_popup_menu (Gdk.EventButton? event) {
71- Gtk.TreeIter iter;
72- if (notes_tree_view.get_selection ().get_selected (null, out iter)) {
73+ return_val_if_fail (event.window == notes_tree_view.get_bin_window(), false);
74+ Gtk.TreePath path = null;
75+ notes_tree_view.get_path_at_pos ((int)event.x, (int)event.y, out path,
76+ null, null, null);
77+ if (path != null) {
78+ Gtk.TreeIter iter;
79+ notes_list_store.get_iter (out iter, path);
80+ Note note;
81+ notes_list_store.get (iter, 0, out note);
82
83 var menu = new Gtk.Menu ();
84
85@@ -341,7 +346,7 @@
86 menuitem.always_show_image = true;
87 menuitem.set_image (image);
88 menuitem.activate.connect (() => {
89- notes_tree_view.set_cursor (notes_list_store.get_path (iter),
90+ notes_tree_view.set_cursor (path,
91 notes_tree_view.get_column (1), true);
92 });
93 menu.append (menuitem);
94@@ -352,8 +357,6 @@
95 menuitem.always_show_image = true;
96 menuitem.set_image (image);
97 menuitem.activate.connect (() => {
98- Note note;
99- notes_list_store.get (iter, 0, out note);
100 get_clipboard (Gdk.SELECTION_CLIPBOARD).set_text (note.content, -1);
101 });
102 menu.append (menuitem);
103@@ -364,8 +367,6 @@
104 menuitem.always_show_image = true;
105 menuitem.set_image (image);
106 menuitem.activate.connect (() => {
107- Note note;
108- notes_list_store.get (iter, 0, out note);
109 note.remove ();
110 });
111 menu.append (menuitem);

Subscribers

People subscribed via source and target branches

to all changes: