Merge lp:~artem-anufrij/footnote/footnote-dev into lp:footnote

Proposed by Artem Anufrij
Status: Merged
Approved by: Artem Anufrij
Approved revision: 313
Merged at revision: 313
Proposed branch: lp:~artem-anufrij/footnote/footnote-dev
Merge into: lp:footnote
Diff against target: 421 lines (+174/-59)
5 files modified
src/Database.vala (+70/-18)
src/Widgets/EditView.vala (+63/-10)
src/Widgets/Note.vala (+5/-0)
src/Widgets/NoteView.vala (+35/-30)
src/Widgets/SideBar.vala (+1/-1)
To merge this branch: bzr merge lp:~artem-anufrij/footnote/footnote-dev
Reviewer Review Type Date Requested Status
Tom Beckmann Pending
Review via email: mp+245697@code.launchpad.net

Commit message

- hotkey: EDIT-Mode (F2) (like "Files" for editing a filename)
- hotkey: CANCEL (ESC)
- hotkey: SAVE note (Ctrl+s)

DESIGN:
- added a separator between the notes in the "three columns view"
- add css-class ("h3") to the title label "three columns view"

WORKFLOW:
- after creating a new note, the title will be selected for instant input a text
- set focus to the content after changed to the EditView
- after canceling changes: restore 'original' content in the NoteView

Description of the change

- hotkey: EDIT-Mode (F2) (like "Files" for editing a filename)
- hotkey: CANCEL (ESC)
- hotkey: SAVE note (Ctrl+s)

DESIGN:
- added a separator between the notes in the "three columns view"
- add css-class ("h3") to the title label "three columns view"

WORKFLOW:
- after creating a new note, the title will be selected for instant input a text
- set focus to the content after changed to the EditView
- after canceling changes: restore 'original' content in the NoteView

To post a comment you must log in.
313. By artem-anufrij

code style

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Database.vala'
2--- src/Database.vala 2015-01-03 22:37:21 +0000
3+++ src/Database.vala 2015-01-06 21:52:43 +0000
4@@ -16,6 +16,7 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 *
7 * Authored by: Corentin Noël <corentin@elementaryos.org>
8+ * Artem Anufrij <artem.anufrij@live.de>
9 */
10
11 public class Footnote.DataBase : GLib.Object {
12@@ -42,8 +43,6 @@
13 } catch (SQLHeavy.Error e) {
14 critical ("Could not create db: %s", e.message);
15 }
16-
17-
18 }
19
20 /*
21@@ -93,28 +92,56 @@
22 }
23 }
24
25+ public void restore_note (Widgets.Note note) {
26+
27+ try {
28+ var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE rowid=:id");
29+ q.set_int (":id", note.id);
30+
31+ var res = q.execute ();
32+
33+ DateTime datetime = datetime_converter (res);
34+
35+ // TITLE
36+ note.title.label = res.fetch_string (0);
37+
38+ // CONTENT
39+ if (res.fetch_blob (1) != null) {
40+ Gtk.TextIter start;
41+ Gtk.TextIter end;
42+
43+ // Clear currently content
44+ note.content.buffer.get_start_iter (out start);
45+ note.content.buffer.get_end_iter (out end);
46+ note.content.buffer.delete_range (start, end);
47+
48+ note.content.buffer.get_start_iter (out start);
49+ try {
50+ note.content.buffer.deserialize (note.content.buffer, note.deformat, start, res.fetch_blob (1));
51+ } catch (Error e) {
52+ critical (e.message);
53+ }
54+ }
55+
56+ // DATETIME
57+ note.datetime = datetime;
58+ note.month = datetime.get_month ();
59+ note.year = datetime.get_year ();
60+
61+ // BOOKMARKED
62+ note.bookmarked = (bool)res.fetch_int (4);
63+ } catch (SQLHeavy.Error e) {
64+ critical (e.message);
65+ }
66+ }
67+
68 public Gee.ArrayList<Widgets.Note> get_notes_from_notebook (Widgets.Notebook nb) {
69 var list = new Gee.ArrayList<Widgets.Note> ();
70 try {
71 var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE notebook = :id ORDER BY rowid ASC;");
72 q.set_int (":id", nb.id);
73 for (var res = q.execute (); !res.finished; res.next ()) {
74- DateTime datetime;
75- // Keep backward compatibility, but now it's stored as an int64.
76- if (res.field_type (3) == typeof(string)) {
77- var date_string = res.fetch_string (3);
78- var parts = date_string.split (" ", 3);
79- var hour_parts = parts[0].split (":", 2);
80- var day_parts = parts[2].split (".", 3);
81- var year = int.parse (day_parts[2]);
82- var month = int.parse (day_parts[1]);
83- var day = int.parse (day_parts[0]);
84- var hours = int.parse (hour_parts[0]);
85- var minutes = int.parse (hour_parts[1]);
86- datetime = new DateTime.local (year, month, day, hours, minutes, 0);
87- } else {
88- datetime = new DateTime.from_unix_local (res.fetch_int64 (3));
89- }
90+ DateTime datetime = datetime_converter (res);
91
92 var note = new Widgets.Note.from_existing (nb, res.fetch_string (0), res.fetch_blob (1),
93 res.fetch_int (2), datetime, (bool)res.fetch_int (4));
94@@ -234,4 +261,29 @@
95 dialog.run ();
96 dialog.destroy ();
97 }
98+
99+ public DateTime datetime_converter (SQLHeavy.QueryResult res) {
100+ DateTime return_value = new DateTime.now_local ();
101+
102+ try {
103+ if (res.field_type (3) == typeof(string)) {
104+ var date_string = res.fetch_string (3);
105+ var parts = date_string.split (" ", 3);
106+ var hour_parts = parts[0].split (":", 2);
107+ var day_parts = parts[2].split (".", 3);
108+ var year = int.parse (day_parts[2]);
109+ var month = int.parse (day_parts[1]);
110+ var day = int.parse (day_parts[0]);
111+ var hours = int.parse (hour_parts[0]);
112+ var minutes = int.parse (hour_parts[1]);
113+
114+ return_value = new DateTime.local (year, month, day, hours, minutes, 0);
115+ } else
116+ return_value = new DateTime.from_unix_local (res.fetch_int64 (3));
117+ } catch (SQLHeavy.Error e) {
118+ critical (e.message);
119+ }
120+
121+ return return_value;
122+ }
123 }
124
125=== modified file 'src/Widgets/EditView.vala'
126--- src/Widgets/EditView.vala 2015-01-03 22:37:21 +0000
127+++ src/Widgets/EditView.vala 2015-01-06 21:52:43 +0000
128@@ -1,3 +1,23 @@
129+/*
130+ * Copyright (C) 2014-2015 Elementary Developers
131+ *
132+ * This program or library is free software; you can redistribute it
133+ * and/or modify it under the terms of the GNU Lesser General Public
134+ * License as published by the Free Software Foundation; either
135+ * version 3 of the License, or (at your option) any later version.
136+ *
137+ * This library is distributed in the hope that it will be useful,
138+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
139+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
140+ * Lesser General Public License for more details.
141+ *
142+ * You should have received a copy of the GNU Lesser General
143+ * Public License along with this library; if not, write to the
144+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
145+ * Boston, MA 02110-1301 USA.
146+ *
147+ * Authored by: Artem Anufrij <artem.anufrij@live.de>
148+ */
149
150 namespace Footnote.Widgets {
151
152@@ -10,6 +30,7 @@
153 private Gtk.ToggleToolButton italic;
154 private Gtk.ToggleToolButton strike;
155 private Gtk.ToggleToolButton mark;
156+
157 private bool applying_style = false;
158
159 public signal void close (bool reverse=false);
160@@ -33,14 +54,17 @@
161
162 title = new Gtk.TextView ();
163 title.override_background_color (Gtk.StateFlags.NORMAL, {0, 0, 0, 0});
164+
165 content = new Gtk.TextView ();
166 content.override_background_color (Gtk.StateFlags.NORMAL, {0, 0, 0, 0});
167+
168 var content_scroll = new Gtk.ScrolledWindow (null, null);
169
170- var undo = new Gtk.ToolButton (null, null);
171+ var undo = new Gtk.ToolButton (null, null);
172 undo.tooltip_text = _("Undo");
173 undo.icon_name = "edit-undo";
174- var redo = new Gtk.ToolButton (null, null);
175+
176+ var redo = new Gtk.ToolButton (null, null);
177 redo.tooltip_text = _("Redo");
178 redo.icon_name = "edit-redo";
179
180@@ -122,20 +146,43 @@
181 }
182 return false;
183 });
184+
185 done.clicked.connect ( () => {
186- current_note.title.label = title.buffer.text;
187- current_note.save ();
188- this.close ();
189+ this.done ();
190 });
191+
192 cancel.clicked.connect ( () => {
193- this.close ();
194+ this.cancel ();
195 });
196+
197 title.buffer.changed.connect ( () => {
198 if (title.buffer.text == "")
199 done.sensitive = false;
200 else
201 done.sensitive = true;
202 });
203+
204+ this.key_press_event.connect ( (e) => {
205+ if (e.keyval == Gdk.Key.Escape) {
206+ this.cancel ();
207+ return true;
208+ } else if (e.keyval == Gdk.Key.s && Gdk.ModifierType.CONTROL_MASK in e.state) {
209+ this.done ();
210+ return true;
211+ }
212+ return false;
213+ });
214+ }
215+
216+ private void done () {
217+ current_note.title.label = this.title.buffer.text;
218+ current_note.save ();
219+ this.close ();
220+ }
221+
222+ private void cancel () {
223+ current_note.restore ();
224+ this.close ();
225 }
226
227 public void open_note (Note n) {
228@@ -143,13 +190,14 @@
229 open (); //show the edit view
230
231 title.buffer.text = n.title.label;
232+
233 content.buffer = n.content.buffer;
234-
235+ content.show_all ();
236 content.buffer.notify["cursor-position"].connect ( () => {
237 Gtk.TextIter s;
238 content.buffer.get_selection_bounds (out s, null);
239 string [] tags = new string[s.get_tags ().length ()];
240- for (var i=0;i<s.get_tags ().length ();i++) {
241+ for (var i = 0;i < s.get_tags ().length (); i++) {
242 tags[i] = s.get_tags ().nth_data (i).name;
243 }
244
245@@ -161,9 +209,14 @@
246 applying_style = false;
247 });
248
249+ if (n.title.label == _("Untitled") || n.title.label == _("New Note")) {
250+ title.grab_focus ();
251+ title.select_all (true);
252+ }
253+ else
254+ content.grab_focus ();
255+
256 current_note = n;
257 }
258-
259-
260 }
261 }
262
263=== modified file 'src/Widgets/Note.vala'
264--- src/Widgets/Note.vala 2015-01-04 01:24:24 +0000
265+++ src/Widgets/Note.vala 2015-01-06 21:52:43 +0000
266@@ -14,6 +14,7 @@
267 // You should have received a copy of the GNU General Public License
268 // along with this program. If not, see <http://www.gnu.org/licenses/>.
269 //
270+// Authored by: Artem Anufrij <artem.anufrij@live.de>
271
272
273 namespace Footnote.Widgets {
274@@ -271,6 +272,10 @@
275 if (this.is_brand_new == true)
276 this.is_brand_new = false;
277 }
278+
279+ public void restore () {
280+ DataBase.get_default ().restore_note (this);
281+ }
282 }
283 }
284
285
286=== modified file 'src/Widgets/NoteView.vala'
287--- src/Widgets/NoteView.vala 2015-01-04 01:24:24 +0000
288+++ src/Widgets/NoteView.vala 2015-01-06 21:52:43 +0000
289@@ -14,6 +14,7 @@
290 // You should have received a copy of the GNU General Public License
291 // along with this program. If not, see <http://www.gnu.org/licenses/>.
292 //
293+// Authored by: Artem Anufrij <artem.anufrij@live.de>
294
295 namespace Footnote.Widgets {
296
297@@ -179,31 +180,33 @@
298 private Gtk.ListBox miller_listbox;
299 private Gtk.ScrolledWindow miller_scroll;
300 public NoteViewer miller_noteviewer;
301- private EditView edit_view;
302- private Gtk.ListBox note_list;
303- private Notebook notebook;
304- private Gtk.Stack main_stack;
305+ private EditView edit_view;
306+ private Gtk.ListBox note_list;
307+ private Notebook notebook;
308+ private Gtk.Stack main_stack;
309
310- private Gtk.InfoBar deletion_infobar;
311- private Gtk.Label deletion_label;
312- private Note trashed_note;
313+ private Gtk.InfoBar deletion_infobar;
314+ private Gtk.Label deletion_label;
315+ private Note trashed_note;
316
317 private int year = -1;
318 private int month = -1;
319
320- //public GtkClutter.Actor undo_bar;
321-
322- private int current; //currently used view
323-
324 /**
325 * Constructor
326 */
327 public NoteView (FootnoteApp app, Notebook notebook) {
328 orientation = Gtk.Orientation.VERTICAL;
329- this.app = app;
330- this.notebook = notebook;
331- this.filter = "";
332- this.current = 0;
333+ this.app = app;
334+ this.notebook = notebook;
335+ this.filter = "";
336+ this.key_press_event.connect ( (e) => {
337+ if (e.keyval == Gdk.Key.F2) {
338+ miller_noteviewer.current_note.edit ();
339+ return true;
340+ }
341+ return false;
342+ });
343 edit_view = new EditView (app);
344
345 deletion_infobar = new Gtk.InfoBar ();
346@@ -262,6 +265,10 @@
347
348 edit_view.close.connect ( (reverse) => {
349 toggle_edit (false);
350+
351+ Gtk.ListBoxRow selected_row = miller_listbox.get_selected_row ();
352+ if (selected_row != null)
353+ selected_row.activate ();
354 });
355
356 var empty_label = new Gtk.Label (_("Notebook \"%s\" is empty").printf (notebook.title));
357@@ -365,11 +372,8 @@
358 miller_listbox.select_row (row);
359 miller_listbox.row_activated (row);
360 }
361- } else {
362+ } else
363 main_stack.set_visible_child_name ("list");
364- }
365- current = app.view_mode.selected;
366-
367 }
368
369 public void change_month (int month) {
370@@ -429,26 +433,27 @@
371 public MillerRow (Note note) {
372 this.note = note;
373 title_label = new Gtk.Label ("");
374+ title_label.get_style_context ().add_class ("h3");
375 title_label.xalign = 0;
376 title_label.ellipsize = Pango.EllipsizeMode.END;
377 date_label = new Gtk.Label ("");
378 date_label.xalign = 0;
379- date_label.opacity = 0.8;
380+ date_label.opacity = 0.7;
381 date_label.ellipsize = Pango.EllipsizeMode.END;
382 summary_label = new Gtk.Label ("");
383 summary_label.xalign = 0;
384+ summary_label.opacity = 0.9;
385 summary_label.ellipsize = Pango.EllipsizeMode.END;
386
387- var grid = new Gtk.Grid ();
388- grid.margin = 6;
389- grid.row_spacing = 6;
390- grid.orientation = Gtk.Orientation.VERTICAL;
391- grid.add (title_label);
392- grid.add (date_label);
393- grid.add (summary_label);
394-
395- add (grid);
396-
397+ var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
398+ box.margin = 6;
399+ box.margin_bottom = 0;
400+ box.pack_start (title_label);
401+ box.pack_start (date_label);
402+ box.pack_start (summary_label);
403+ box.pack_start (new Gtk.Separator(Gtk.Orientation.HORIZONTAL));
404+
405+ add (box);
406 update_labels ();
407
408 note.edited.connect (() => {
409
410=== modified file 'src/Widgets/SideBar.vala'
411--- src/Widgets/SideBar.vala 2015-01-03 23:38:01 +0000
412+++ src/Widgets/SideBar.vala 2015-01-06 21:52:43 +0000
413@@ -119,7 +119,7 @@
414 step = 4;
415 }
416
417- var pix_number = pixbuf.width*pixbuf.height*step;
418+ var pix_number = pixbuf.width * pixbuf.height * step;
419 uint8[] new_pixels = new uint8[pix_number];
420 for (int i = 0; i < pix_number; i+=step) {
421 var r = pixels[i];

Subscribers

People subscribed via source and target branches