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
=== modified file 'src/Database.vala'
--- src/Database.vala 2015-01-03 22:37:21 +0000
+++ src/Database.vala 2015-01-06 21:52:43 +0000
@@ -16,6 +16,7 @@
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *17 *
18 * Authored by: Corentin Noël <corentin@elementaryos.org>18 * Authored by: Corentin Noël <corentin@elementaryos.org>
19 * Artem Anufrij <artem.anufrij@live.de>
19 */20 */
2021
21public class Footnote.DataBase : GLib.Object {22public class Footnote.DataBase : GLib.Object {
@@ -42,8 +43,6 @@
42 } catch (SQLHeavy.Error e) {43 } catch (SQLHeavy.Error e) {
43 critical ("Could not create db: %s", e.message);44 critical ("Could not create db: %s", e.message);
44 }45 }
45
46
47 }46 }
4847
49 /*48 /*
@@ -93,28 +92,56 @@
93 }92 }
94 }93 }
9594
95 public void restore_note (Widgets.Note note) {
96
97 try {
98 var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE rowid=:id");
99 q.set_int (":id", note.id);
100
101 var res = q.execute ();
102
103 DateTime datetime = datetime_converter (res);
104
105 // TITLE
106 note.title.label = res.fetch_string (0);
107
108 // CONTENT
109 if (res.fetch_blob (1) != null) {
110 Gtk.TextIter start;
111 Gtk.TextIter end;
112
113 // Clear currently content
114 note.content.buffer.get_start_iter (out start);
115 note.content.buffer.get_end_iter (out end);
116 note.content.buffer.delete_range (start, end);
117
118 note.content.buffer.get_start_iter (out start);
119 try {
120 note.content.buffer.deserialize (note.content.buffer, note.deformat, start, res.fetch_blob (1));
121 } catch (Error e) {
122 critical (e.message);
123 }
124 }
125
126 // DATETIME
127 note.datetime = datetime;
128 note.month = datetime.get_month ();
129 note.year = datetime.get_year ();
130
131 // BOOKMARKED
132 note.bookmarked = (bool)res.fetch_int (4);
133 } catch (SQLHeavy.Error e) {
134 critical (e.message);
135 }
136 }
137
96 public Gee.ArrayList<Widgets.Note> get_notes_from_notebook (Widgets.Notebook nb) {138 public Gee.ArrayList<Widgets.Note> get_notes_from_notebook (Widgets.Notebook nb) {
97 var list = new Gee.ArrayList<Widgets.Note> ();139 var list = new Gee.ArrayList<Widgets.Note> ();
98 try {140 try {
99 var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE notebook = :id ORDER BY rowid ASC;");141 var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE notebook = :id ORDER BY rowid ASC;");
100 q.set_int (":id", nb.id);142 q.set_int (":id", nb.id);
101 for (var res = q.execute (); !res.finished; res.next ()) {143 for (var res = q.execute (); !res.finished; res.next ()) {
102 DateTime datetime;144 DateTime datetime = datetime_converter (res);
103 // Keep backward compatibility, but now it's stored as an int64.
104 if (res.field_type (3) == typeof(string)) {
105 var date_string = res.fetch_string (3);
106 var parts = date_string.split (" ", 3);
107 var hour_parts = parts[0].split (":", 2);
108 var day_parts = parts[2].split (".", 3);
109 var year = int.parse (day_parts[2]);
110 var month = int.parse (day_parts[1]);
111 var day = int.parse (day_parts[0]);
112 var hours = int.parse (hour_parts[0]);
113 var minutes = int.parse (hour_parts[1]);
114 datetime = new DateTime.local (year, month, day, hours, minutes, 0);
115 } else {
116 datetime = new DateTime.from_unix_local (res.fetch_int64 (3));
117 }
118145
119 var note = new Widgets.Note.from_existing (nb, res.fetch_string (0), res.fetch_blob (1), 146 var note = new Widgets.Note.from_existing (nb, res.fetch_string (0), res.fetch_blob (1),
120 res.fetch_int (2), datetime, (bool)res.fetch_int (4));147 res.fetch_int (2), datetime, (bool)res.fetch_int (4));
@@ -234,4 +261,29 @@
234 dialog.run ();261 dialog.run ();
235 dialog.destroy ();262 dialog.destroy ();
236 }263 }
264
265 public DateTime datetime_converter (SQLHeavy.QueryResult res) {
266 DateTime return_value = new DateTime.now_local ();
267
268 try {
269 if (res.field_type (3) == typeof(string)) {
270 var date_string = res.fetch_string (3);
271 var parts = date_string.split (" ", 3);
272 var hour_parts = parts[0].split (":", 2);
273 var day_parts = parts[2].split (".", 3);
274 var year = int.parse (day_parts[2]);
275 var month = int.parse (day_parts[1]);
276 var day = int.parse (day_parts[0]);
277 var hours = int.parse (hour_parts[0]);
278 var minutes = int.parse (hour_parts[1]);
279
280 return_value = new DateTime.local (year, month, day, hours, minutes, 0);
281 } else
282 return_value = new DateTime.from_unix_local (res.fetch_int64 (3));
283 } catch (SQLHeavy.Error e) {
284 critical (e.message);
285 }
286
287 return return_value;
288 }
237}289}
238290
=== modified file 'src/Widgets/EditView.vala'
--- src/Widgets/EditView.vala 2015-01-03 22:37:21 +0000
+++ src/Widgets/EditView.vala 2015-01-06 21:52:43 +0000
@@ -1,3 +1,23 @@
1/*
2 * Copyright (C) 2014-2015 Elementary Developers
3 *
4 * This program or library is free software; you can redistribute it
5 * and/or modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
18 *
19 * Authored by: Artem Anufrij <artem.anufrij@live.de>
20 */
121
2namespace Footnote.Widgets {22namespace Footnote.Widgets {
3 23
@@ -10,6 +30,7 @@
10 private Gtk.ToggleToolButton italic;30 private Gtk.ToggleToolButton italic;
11 private Gtk.ToggleToolButton strike;31 private Gtk.ToggleToolButton strike;
12 private Gtk.ToggleToolButton mark;32 private Gtk.ToggleToolButton mark;
33
13 private bool applying_style = false;34 private bool applying_style = false;
14 35
15 public signal void close (bool reverse=false);36 public signal void close (bool reverse=false);
@@ -33,14 +54,17 @@
33 54
34 title = new Gtk.TextView ();55 title = new Gtk.TextView ();
35 title.override_background_color (Gtk.StateFlags.NORMAL, {0, 0, 0, 0});56 title.override_background_color (Gtk.StateFlags.NORMAL, {0, 0, 0, 0});
57
36 content = new Gtk.TextView ();58 content = new Gtk.TextView ();
37 content.override_background_color (Gtk.StateFlags.NORMAL, {0, 0, 0, 0});59 content.override_background_color (Gtk.StateFlags.NORMAL, {0, 0, 0, 0});
60
38 var content_scroll = new Gtk.ScrolledWindow (null, null);61 var content_scroll = new Gtk.ScrolledWindow (null, null);
39 62
40 var undo = new Gtk.ToolButton (null, null);63 var undo = new Gtk.ToolButton (null, null);
41 undo.tooltip_text = _("Undo");64 undo.tooltip_text = _("Undo");
42 undo.icon_name = "edit-undo";65 undo.icon_name = "edit-undo";
43 var redo = new Gtk.ToolButton (null, null);66
67 var redo = new Gtk.ToolButton (null, null);
44 redo.tooltip_text = _("Redo");68 redo.tooltip_text = _("Redo");
45 redo.icon_name = "edit-redo";69 redo.icon_name = "edit-redo";
4670
@@ -122,20 +146,43 @@
122 }146 }
123 return false;147 return false;
124 });148 });
149
125 done.clicked.connect ( () => {150 done.clicked.connect ( () => {
126 current_note.title.label = title.buffer.text;151 this.done ();
127 current_note.save ();
128 this.close ();
129 });152 });
153
130 cancel.clicked.connect ( () => {154 cancel.clicked.connect ( () => {
131 this.close ();155 this.cancel ();
132 });156 });
157
133 title.buffer.changed.connect ( () => {158 title.buffer.changed.connect ( () => {
134 if (title.buffer.text == "")159 if (title.buffer.text == "")
135 done.sensitive = false;160 done.sensitive = false;
136 else161 else
137 done.sensitive = true;162 done.sensitive = true;
138 });163 });
164
165 this.key_press_event.connect ( (e) => {
166 if (e.keyval == Gdk.Key.Escape) {
167 this.cancel ();
168 return true;
169 } else if (e.keyval == Gdk.Key.s && Gdk.ModifierType.CONTROL_MASK in e.state) {
170 this.done ();
171 return true;
172 }
173 return false;
174 });
175 }
176
177 private void done () {
178 current_note.title.label = this.title.buffer.text;
179 current_note.save ();
180 this.close ();
181 }
182
183 private void cancel () {
184 current_note.restore ();
185 this.close ();
139 }186 }
140 187
141 public void open_note (Note n) {188 public void open_note (Note n) {
@@ -143,13 +190,14 @@
143 open (); //show the edit view190 open (); //show the edit view
144191
145 title.buffer.text = n.title.label;192 title.buffer.text = n.title.label;
193
146 content.buffer = n.content.buffer;194 content.buffer = n.content.buffer;
147195 content.show_all ();
148 content.buffer.notify["cursor-position"].connect ( () => {196 content.buffer.notify["cursor-position"].connect ( () => {
149 Gtk.TextIter s;197 Gtk.TextIter s;
150 content.buffer.get_selection_bounds (out s, null);198 content.buffer.get_selection_bounds (out s, null);
151 string [] tags = new string[s.get_tags ().length ()];199 string [] tags = new string[s.get_tags ().length ()];
152 for (var i=0;i<s.get_tags ().length ();i++) {200 for (var i = 0;i < s.get_tags ().length (); i++) {
153 tags[i] = s.get_tags ().nth_data (i).name;201 tags[i] = s.get_tags ().nth_data (i).name;
154 }202 }
155203
@@ -161,9 +209,14 @@
161 applying_style = false;209 applying_style = false;
162 });210 });
163 211
212 if (n.title.label == _("Untitled") || n.title.label == _("New Note")) {
213 title.grab_focus ();
214 title.select_all (true);
215 }
216 else
217 content.grab_focus ();
218
164 current_note = n;219 current_note = n;
165 }220 }
166
167
168 }221 }
169}222}
170223
=== modified file 'src/Widgets/Note.vala'
--- src/Widgets/Note.vala 2015-01-04 01:24:24 +0000
+++ src/Widgets/Note.vala 2015-01-06 21:52:43 +0000
@@ -14,6 +14,7 @@
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//16//
17// Authored by: Artem Anufrij <artem.anufrij@live.de>
1718
1819
19namespace Footnote.Widgets {20namespace Footnote.Widgets {
@@ -271,6 +272,10 @@
271 if (this.is_brand_new == true)272 if (this.is_brand_new == true)
272 this.is_brand_new = false;273 this.is_brand_new = false;
273 }274 }
275
276 public void restore () {
277 DataBase.get_default ().restore_note (this);
278 }
274 }279 }
275}280}
276281
277282
=== modified file 'src/Widgets/NoteView.vala'
--- src/Widgets/NoteView.vala 2015-01-04 01:24:24 +0000
+++ src/Widgets/NoteView.vala 2015-01-06 21:52:43 +0000
@@ -14,6 +14,7 @@
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//16//
17// Authored by: Artem Anufrij <artem.anufrij@live.de>
1718
18namespace Footnote.Widgets {19namespace Footnote.Widgets {
19 20
@@ -179,31 +180,33 @@
179 private Gtk.ListBox miller_listbox;180 private Gtk.ListBox miller_listbox;
180 private Gtk.ScrolledWindow miller_scroll;181 private Gtk.ScrolledWindow miller_scroll;
181 public NoteViewer miller_noteviewer;182 public NoteViewer miller_noteviewer;
182 private EditView edit_view;183 private EditView edit_view;
183 private Gtk.ListBox note_list;184 private Gtk.ListBox note_list;
184 private Notebook notebook;185 private Notebook notebook;
185 private Gtk.Stack main_stack;186 private Gtk.Stack main_stack;
186187
187 private Gtk.InfoBar deletion_infobar;188 private Gtk.InfoBar deletion_infobar;
188 private Gtk.Label deletion_label;189 private Gtk.Label deletion_label;
189 private Note trashed_note;190 private Note trashed_note;
190191
191 private int year = -1;192 private int year = -1;
192 private int month = -1;193 private int month = -1;
193194
194 //public GtkClutter.Actor undo_bar;
195
196 private int current; //currently used view
197
198 /**195 /**
199 * Constructor196 * Constructor
200 */197 */
201 public NoteView (FootnoteApp app, Notebook notebook) {198 public NoteView (FootnoteApp app, Notebook notebook) {
202 orientation = Gtk.Orientation.VERTICAL;199 orientation = Gtk.Orientation.VERTICAL;
203 this.app = app;200 this.app = app;
204 this.notebook = notebook;201 this.notebook = notebook;
205 this.filter = "";202 this.filter = "";
206 this.current = 0;203 this.key_press_event.connect ( (e) => {
204 if (e.keyval == Gdk.Key.F2) {
205 miller_noteviewer.current_note.edit ();
206 return true;
207 }
208 return false;
209 });
207 edit_view = new EditView (app);210 edit_view = new EditView (app);
208211
209 deletion_infobar = new Gtk.InfoBar ();212 deletion_infobar = new Gtk.InfoBar ();
@@ -262,6 +265,10 @@
262265
263 edit_view.close.connect ( (reverse) => {266 edit_view.close.connect ( (reverse) => {
264 toggle_edit (false);267 toggle_edit (false);
268
269 Gtk.ListBoxRow selected_row = miller_listbox.get_selected_row ();
270 if (selected_row != null)
271 selected_row.activate ();
265 });272 });
266273
267 var empty_label = new Gtk.Label (_("Notebook \"%s\" is empty").printf (notebook.title));274 var empty_label = new Gtk.Label (_("Notebook \"%s\" is empty").printf (notebook.title));
@@ -365,11 +372,8 @@
365 miller_listbox.select_row (row);372 miller_listbox.select_row (row);
366 miller_listbox.row_activated (row);373 miller_listbox.row_activated (row);
367 }374 }
368 } else {375 } else
369 main_stack.set_visible_child_name ("list");376 main_stack.set_visible_child_name ("list");
370 }
371 current = app.view_mode.selected;
372
373 }377 }
374378
375 public void change_month (int month) {379 public void change_month (int month) {
@@ -429,26 +433,27 @@
429 public MillerRow (Note note) {433 public MillerRow (Note note) {
430 this.note = note;434 this.note = note;
431 title_label = new Gtk.Label ("");435 title_label = new Gtk.Label ("");
436 title_label.get_style_context ().add_class ("h3");
432 title_label.xalign = 0;437 title_label.xalign = 0;
433 title_label.ellipsize = Pango.EllipsizeMode.END;438 title_label.ellipsize = Pango.EllipsizeMode.END;
434 date_label = new Gtk.Label ("");439 date_label = new Gtk.Label ("");
435 date_label.xalign = 0;440 date_label.xalign = 0;
436 date_label.opacity = 0.8;441 date_label.opacity = 0.7;
437 date_label.ellipsize = Pango.EllipsizeMode.END;442 date_label.ellipsize = Pango.EllipsizeMode.END;
438 summary_label = new Gtk.Label ("");443 summary_label = new Gtk.Label ("");
439 summary_label.xalign = 0;444 summary_label.xalign = 0;
445 summary_label.opacity = 0.9;
440 summary_label.ellipsize = Pango.EllipsizeMode.END;446 summary_label.ellipsize = Pango.EllipsizeMode.END;
441447
442 var grid = new Gtk.Grid ();448 var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
443 grid.margin = 6;449 box.margin = 6;
444 grid.row_spacing = 6;450 box.margin_bottom = 0;
445 grid.orientation = Gtk.Orientation.VERTICAL;451 box.pack_start (title_label);
446 grid.add (title_label);452 box.pack_start (date_label);
447 grid.add (date_label);453 box.pack_start (summary_label);
448 grid.add (summary_label);454 box.pack_start (new Gtk.Separator(Gtk.Orientation.HORIZONTAL));
449455
450 add (grid);456 add (box);
451
452 update_labels ();457 update_labels ();
453458
454 note.edited.connect (() => {459 note.edited.connect (() => {
455460
=== modified file 'src/Widgets/SideBar.vala'
--- src/Widgets/SideBar.vala 2015-01-03 23:38:01 +0000
+++ src/Widgets/SideBar.vala 2015-01-06 21:52:43 +0000
@@ -119,7 +119,7 @@
119 step = 4;119 step = 4;
120 }120 }
121121
122 var pix_number = pixbuf.width*pixbuf.height*step;122 var pix_number = pixbuf.width * pixbuf.height * step;
123 uint8[] new_pixels = new uint8[pix_number];123 uint8[] new_pixels = new uint8[pix_number];
124 for (int i = 0; i < pix_number; i+=step) {124 for (int i = 0; i < pix_number; i+=step) {
125 var r = pixels[i];125 var r = pixels[i];

Subscribers

People subscribed via source and target branches