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

Proposed by gue5t gue5t
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 6605
Merged at revision: 6609
Proposed branch: lp:~gue5t/midori/notes-editing
Merge into: lp:midori
Diff against target: 123 lines (+27/-33)
1 file modified
extensions/notes.vala (+27/-33)
To merge this branch: bzr merge lp:~gue5t/midori/notes-editing
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Review via email: mp+211236@code.launchpad.net

Commit message

Rename notes inline

Description of the change

Changes the notes extension to use inline treeview editing instead of a dialog to rename notes

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'extensions/notes.vala'
--- extensions/notes.vala 2014-02-20 18:27:01 +0000
+++ extensions/notes.vala 2014-03-17 02:39:01 +0000
@@ -157,6 +157,16 @@
157 return toolbar;157 return toolbar;
158 }158 }
159159
160 internal void title_edited (Gtk.CellRendererText renderer, string? path_str, string? new_title) {
161 var path = new Gtk.TreePath.from_string (path_str);
162 Gtk.TreeIter iter;
163 notes_list_store.get_iter (out iter, path);
164 Note note;
165 notes_list_store.get (iter, 0, out note);
166 note.rename (new_title);
167 notes_list_store.set (iter, 0, note);
168 }
169
160 public Sidebar () {170 public Sidebar () {
161 Gtk.TreeViewColumn column;171 Gtk.TreeViewColumn column;
162172
@@ -164,6 +174,7 @@
164 notes_tree_view = new Gtk.TreeView.with_model (notes_list_store);174 notes_tree_view = new Gtk.TreeView.with_model (notes_list_store);
165 notes_tree_view.headers_visible = true;175 notes_tree_view.headers_visible = true;
166 notes_tree_view.button_press_event.connect (button_pressed);176 notes_tree_view.button_press_event.connect (button_pressed);
177 notes_tree_view.get_selection().changed.connect (selection_changed);
167178
168 notes_list_store.set_sort_column_id (0, Gtk.SortType.ASCENDING);179 notes_list_store.set_sort_column_id (0, Gtk.SortType.ASCENDING);
169 notes_list_store.set_sort_func (0, tree_sort_func);180 notes_list_store.set_sort_func (0, tree_sort_func);
@@ -176,6 +187,8 @@
176187
177 column = new Gtk.TreeViewColumn ();188 column = new Gtk.TreeViewColumn ();
178 Gtk.CellRendererText renderer_title = new Gtk.CellRendererText ();189 Gtk.CellRendererText renderer_title = new Gtk.CellRendererText ();
190 renderer_title.editable = true;
191 renderer_title.edited.connect (title_edited);
179 column.set_title (_("Notes"));192 column.set_title (_("Notes"));
180 column.pack_start (renderer_title, true);193 column.pack_start (renderer_title, true);
181 column.set_cell_data_func (renderer_title, on_render_note_title);194 column.set_cell_data_func (renderer_title, on_render_note_title);
@@ -217,7 +230,7 @@
217 return strcmp (note1.title, note2.title);230 return strcmp (note1.title, note2.title);
218 }231 }
219232
220 bool focus_lost (Gdk.EventFocus event) {233 void save_current_note () {
221 Gtk.TreePath? path;234 Gtk.TreePath? path;
222 notes_tree_view.get_cursor (out path, null);235 notes_tree_view.get_cursor (out path, null);
223 return_val_if_fail (path != null, false);236 return_val_if_fail (path != null, false);
@@ -230,6 +243,10 @@
230 note.update (note_content);243 note.update (note_content);
231 }244 }
232 }245 }
246 }
247
248 bool focus_lost (Gdk.EventFocus event) {
249 save_current_note ();
233 return false;250 return false;
234 }251 }
235252
@@ -258,12 +275,15 @@
258 renderer.set ("pixbuf", pixbuf);275 renderer.set ("pixbuf", pixbuf);
259 }276 }
260277
278 private void selection_changed (Gtk.TreeSelection selection)
279 {
280 show_note_content (selection);
281 }
282
261 bool button_pressed (Gdk.EventButton event) {283 bool button_pressed (Gdk.EventButton event) {
262 if (event.button == 1) {284 if (event.button == 1) {
263 if (event.type == Gdk.EventType.2BUTTON_PRESS) {285 if (event.type == Gdk.EventType.2BUTTON_PRESS) {
264 return show_note_webpage_in_new_tab (event, false);286 return show_note_webpage_in_new_tab (event, false);
265 } else {
266 return show_note_content (event);
267 }287 }
268 }288 }
269 if (event.button == 2)289 if (event.button == 2)
@@ -273,9 +293,9 @@
273 return false;293 return false;
274 }294 }
275295
276 bool show_note_content (Gdk.EventButton? event) {296 bool show_note_content (Gtk.TreeSelection selection) {
277 Gtk.TreeIter iter;297 Gtk.TreeIter iter;
278 if (notes_tree_view.get_selection ().get_selected (null, out iter)) {298 if (selection.get_selected (null, out iter)) {
279 Note note;299 Note note;
280 notes_list_store.get (iter, 0, out note);300 notes_list_store.get (iter, 0, out note);
281301
@@ -321,34 +341,8 @@
321 menuitem.always_show_image = true;341 menuitem.always_show_image = true;
322 menuitem.set_image (image);342 menuitem.set_image (image);
323 menuitem.activate.connect (() => {343 menuitem.activate.connect (() => {
324 Note note;344 notes_tree_view.set_cursor (notes_list_store.get_path (iter),
325 notes_list_store.get (iter, 0, out note);345 notes_tree_view.get_column (1), true);
326
327 var dialog = new Gtk.Dialog. with_buttons (_("Rename note"), null,
328 Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
329 Gtk.Stock.OK, Gtk.ResponseType.OK);
330 Gtk.Box content = (Gtk.Box) dialog.get_content_area ();
331 dialog.set_default_response (Gtk.ResponseType.OK);
332 dialog.resizable = false;
333 dialog.icon_name = Gtk.STOCK_EDIT;
334
335 var entry = new Gtk.Entry ();
336 entry.text = note.title;
337 entry.activates_default = true;
338 content.add (entry);
339 content.show_all ();
340
341 int response = dialog.run ();
342 dialog.hide ();
343 if (response == Gtk.ResponseType.OK) {
344 string new_title = entry.text;
345 if (entry.text != null && new_title != note.title) {
346 note.rename (new_title);
347 notes_list_store.set (iter, 0, note);
348 }
349 }
350 dialog.destroy ();
351
352 });346 });
353 menu.append (menuitem);347 menu.append (menuitem);
354348

Subscribers

People subscribed via source and target branches

to all changes: