Merge lp:~artem-anufrij/footnote/optimize-workflow into lp:footnote

Proposed by Artem Anufrij
Status: Merged
Approved by: Artem Anufrij
Approved revision: 319
Merged at revision: 315
Proposed branch: lp:~artem-anufrij/footnote/optimize-workflow
Merge into: lp:footnote
Diff against target: 687 lines (+111/-175)
5 files modified
src/Database.vala (+14/-12)
src/Footnote.vala (+6/-39)
src/Widgets/EditView.vala (+31/-44)
src/Widgets/Note.vala (+12/-15)
src/Widgets/NoteView.vala (+48/-65)
To merge this branch: bzr merge lp:~artem-anufrij/footnote/optimize-workflow
Reviewer Review Type Date Requested Status
Artem Anufrij (community) Approve
Review via email: mp+245903@code.launchpad.net

Commit message

- Show last save date, instead create date.
- autosave on selection_changed (like Scratch)
- autosave on window destroy (like Scratch)
- no "read_only" mode. The note can be instant modified after selected it.
- delete/export/bookmark - buttons are moved into listbox items (mouse over, like Geary).
- some improvement of code design

Description of the change

- Show last save date, instead create date.
- autosave on selection_changed (like Scratch)
- autosave on window destroy (like Scratch)
- no "read_only" mode. The note can be instant modified after selected it.
- delete/export/bookmark - buttons are moved into listbox items (mouse over, like Geary).
- some improvement of code design

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

remove // line

318. By artem-anufrij

remove comment lines

319. By artem-anufrij

remove comment lines

Revision history for this message
Artem Anufrij (artem-anufrij) :
review: Approve

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-06 21:31:31 +0000
+++ src/Database.vala 2015-01-08 20:03:55 +0000
@@ -31,10 +31,10 @@
31 private SQLHeavy.Database db;31 private SQLHeavy.Database db;
3232
33 private DataBase () {33 private DataBase () {
34 var db_file = File.new_for_path (Environment.get_user_data_dir ()+"/footnote/notes.db");34 var db_file = File.new_for_path (Environment.get_user_data_dir () + "/footnote/notes.db");
35 var need_create = !db_file.query_exists ();35 var need_create = !db_file.query_exists ();
36 try {36 try {
37 db = new SQLHeavy.Database (Environment.get_user_data_dir ()+"/footnote/notes.db", 37 db = new SQLHeavy.Database (Environment.get_user_data_dir () + "/footnote/notes.db",
38 SQLHeavy.FileMode.READ | SQLHeavy.FileMode.WRITE | SQLHeavy.FileMode.CREATE);38 SQLHeavy.FileMode.READ | SQLHeavy.FileMode.WRITE | SQLHeavy.FileMode.CREATE);
39 if (need_create) {39 if (need_create) {
40 db.execute ("CREATE TABLE notebooks (name TEXT, color TEXT, id INTEGER PRIMARY KEY AUTOINCREMENT);");40 db.execute ("CREATE TABLE notebooks (name TEXT, color TEXT, id INTEGER PRIMARY KEY AUTOINCREMENT);");
@@ -66,6 +66,7 @@
6666
67 public void update_note (Widgets.Note note) {67 public void update_note (Widgets.Note note) {
68 try {68 try {
69 DateTime datetime = new DateTime.now_local ();
69 Gtk.TextIter s, e;70 Gtk.TextIter s, e;
70 note.content.buffer.get_bounds (out s, out e);71 note.content.buffer.get_bounds (out s, out e);
71 uint8 [] data = note.content.buffer.serialize (note.content.buffer, note.format, s, e);72 uint8 [] data = note.content.buffer.serialize (note.content.buffer, note.format, s, e);
@@ -73,9 +74,10 @@
73 q.set_string (":title", note.title.label);74 q.set_string (":title", note.title.label);
74 q.set_blob (":content", data);75 q.set_blob (":content", data);
75 q.set_int (":bookmarked", (int)note.bookmarked);76 q.set_int (":bookmarked", (int)note.bookmarked);
76 q.set_int64 (":date", note.datetime.to_unix ());77 q.set_int64 (":date", datetime.to_unix ());
77 q.set_int (":id", note.id);78 q.set_int (":id", note.id);
78 q.execute ();79 q.execute ();
80 note.datetime = datetime;
79 note.edited ();81 note.edited ();
80 } catch (SQLHeavy.Error e) {82 } catch (SQLHeavy.Error e) {
81 critical (e.message);83 critical (e.message);
@@ -95,12 +97,12 @@
95 public void restore_note (Widgets.Note note) {97 public void restore_note (Widgets.Note note) {
96 98
97 try {99 try {
98 var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE rowid=:id");100 var q = db.prepare ("SELECT title, content, rowid, date, bookmarked FROM 'notes' WHERE rowid=:id");
99 q.set_int (":id", note.id);101 q.set_int (":id", note.id);
100 102
101 var res = q.execute ();103 var res = q.execute ();
102104
103 DateTime datetime = datetime_converter (res);105 DateTime datetime = datetime_converter (res, 3);
104106
105 // TITLE107 // TITLE
106 note.title.label = res.fetch_string (0);108 note.title.label = res.fetch_string (0);
@@ -138,10 +140,10 @@
138 public Gee.ArrayList<Widgets.Note> get_notes_from_notebook (Widgets.Notebook nb) {140 public Gee.ArrayList<Widgets.Note> get_notes_from_notebook (Widgets.Notebook nb) {
139 var list = new Gee.ArrayList<Widgets.Note> ();141 var list = new Gee.ArrayList<Widgets.Note> ();
140 try {142 try {
141 var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE notebook = :id ORDER BY rowid ASC;");143 var q = db.prepare ("SELECT title, content, rowid, date, bookmarked FROM 'notes' WHERE notebook = :id ORDER BY rowid ASC;");
142 q.set_int (":id", nb.id);144 q.set_int (":id", nb.id);
143 for (var res = q.execute (); !res.finished; res.next ()) {145 for (var res = q.execute (); !res.finished; res.next ()) {
144 DateTime datetime = datetime_converter (res);146 DateTime datetime = datetime_converter (res, 3);
145147
146 var note = new Widgets.Note.from_existing (nb, res.fetch_string (0), res.fetch_blob (1), 148 var note = new Widgets.Note.from_existing (nb, res.fetch_string (0), res.fetch_blob (1),
147 res.fetch_int (2), datetime, (bool)res.fetch_int (4));149 res.fetch_int (2), datetime, (bool)res.fetch_int (4));
@@ -262,12 +264,12 @@
262 dialog.destroy ();264 dialog.destroy ();
263 }265 }
264 266
265 public DateTime datetime_converter (SQLHeavy.QueryResult res) {267 public DateTime datetime_converter (SQLHeavy.QueryResult res, int column_index) {
266 DateTime return_value = new DateTime.now_local ();268 DateTime return_value = new DateTime.now_local ();
267269
268 try {270 try {
269 if (res.field_type (3) == typeof(string)) {271 if (res.field_type (column_index) == typeof(string)) {
270 var date_string = res.fetch_string (3);272 var date_string = res.fetch_string (column_index);
271 var parts = date_string.split (" ", 3);273 var parts = date_string.split (" ", 3);
272 var hour_parts = parts[0].split (":", 2);274 var hour_parts = parts[0].split (":", 2);
273 var day_parts = parts[2].split (".", 3);275 var day_parts = parts[2].split (".", 3);
@@ -279,7 +281,7 @@
279 281
280 return_value = new DateTime.local (year, month, day, hours, minutes, 0);282 return_value = new DateTime.local (year, month, day, hours, minutes, 0);
281 } else283 } else
282 return_value = new DateTime.from_unix_local (res.fetch_int64 (3));284 return_value = new DateTime.from_unix_local (res.fetch_int64 (column_index));
283 } catch (SQLHeavy.Error e) {285 } catch (SQLHeavy.Error e) {
284 critical (e.message);286 critical (e.message);
285 }287 }
286288
=== modified file 'src/Footnote.vala'
--- src/Footnote.vala 2015-01-03 23:38:01 +0000
+++ src/Footnote.vala 2015-01-08 20:03:55 +0000
@@ -55,7 +55,6 @@
55 public Gtk.Window mainwindow;55 public Gtk.Window mainwindow;
56 public Widgets.SideBar sidebar;56 public Widgets.SideBar sidebar;
57 public Granite.Widgets.Welcome welcome;57 public Granite.Widgets.Welcome welcome;
58 public Granite.Widgets.ModeButton view_mode;
59 public Granite.Widgets.ThinPaned hmain;58 public Granite.Widgets.ThinPaned hmain;
60 private Gtk.Stack stack;59 private Gtk.Stack stack;
61 60
@@ -86,7 +85,7 @@
86 public bool showing_search;85 public bool showing_search;
87 public bool fullscreened;86 public bool fullscreened;
88 public Gtk.InfoBar undo_bar;87 public Gtk.InfoBar undo_bar;
89 private Gtk.ToolButton add_new_button;88 private Gtk.ToolButton add_new_button;
9089
91 public int year;90 public int year;
92 public int month;91 public int month;
@@ -170,9 +169,10 @@
170 settings.window_state = window_state;169 settings.window_state = window_state;
171170
172 settings.sidebar_width = hmain.position;171 settings.sidebar_width = hmain.position;
173 settings.view_mode = view_mode.selected;172 if (selected_notebook != null) {
174 if (selected_notebook != null)
175 settings.last_notebook = selected_notebook.id;173 settings.last_notebook = selected_notebook.id;
174 selected_notebook.view.miller_noteviewer.save ();
175 }
176176
177 Gtk.main_quit ();177 Gtk.main_quit ();
178 });178 });
@@ -201,20 +201,13 @@
201 export_button.icon_name = "document-export";201 export_button.icon_name = "document-export";
202 export_button.name = _("Export notebook");202 export_button.name = _("Export notebook");
203 export_button.tooltip_text = _("Export current notebook…");203 export_button.tooltip_text = _("Export current notebook…");
204204
205 view_mode = new Granite.Widgets.ModeButton ();
206 view_mode.append (new Gtk.Image.from_icon_name ("view-filter-symbolic", Gtk.IconSize.BUTTON));
207 view_mode.append (new Gtk.Image.from_icon_name ("view-column-symbolic", Gtk.IconSize.BUTTON));
208 view_mode.valign = Gtk.Align.CENTER;
209 view_mode.selected = settings.view_mode;
210
211 search = new Gtk.SearchEntry ();205 search = new Gtk.SearchEntry ();
212 search.placeholder_text = _("Search Notes");206 search.placeholder_text = _("Search Notes");
213207
214 var tb = new Gtk.HeaderBar ();208 var tb = new Gtk.HeaderBar ();
215 tb.show_close_button = true;209 tb.show_close_button = true;
216 tb.pack_start (add_new_button);210 tb.pack_start (add_new_button);
217 tb.pack_start (view_mode);
218 tb.pack_end (export_button);211 tb.pack_end (export_button);
219 tb.pack_end (search);212 tb.pack_end (search);
220213
@@ -283,10 +276,6 @@
283 /**276 /**
284 * events277 * events
285 **/278 **/
286 /*switch views*/
287 view_mode.mode_changed.connect (() => {
288 selected_notebook.view.update_view ();
289 });
290 /*search on every keypress*/279 /*search on every keypress*/
291 search.search_changed.connect (() => {280 search.search_changed.connect (() => {
292 on_search_changed ();281 on_search_changed ();
@@ -312,7 +301,7 @@
312 add_button.sensitive = false;301 add_button.sensitive = false;
313 var note = ((Widgets.BookmarkItem)item).note;302 var note = ((Widgets.BookmarkItem)item).note;
314 stack.set_visible_child (note.notebook.view);303 stack.set_visible_child (note.notebook.view);
315 note.notebook.view.open_note (note);304 note.notebook.view.open_note (note, true);
316 }305 }
317 });306 });
318 /*add a new notebook*/307 /*add a new notebook*/
@@ -376,11 +365,6 @@
376 sidebar.selected = notebook.sidebar_item;365 sidebar.selected = notebook.sidebar_item;
377 selected_notebook.view.update_view ();366 selected_notebook.view.update_view ();
378 generate_year_combobox ();367 generate_year_combobox ();
379 if (notebook.is_empty ()) {
380 view_mode.sensitive = false;
381 } else {
382 view_mode.sensitive = true;
383 }
384 }368 }
385369
386 private void on_search_changed () {370 private void on_search_changed () {
@@ -396,23 +380,6 @@
396 sidebar.add_notebook (notebook);380 sidebar.add_notebook (notebook);
397 notebook.note_added.connect ((note) => {381 notebook.note_added.connect ((note) => {
398 generate_year_combobox ();382 generate_year_combobox ();
399 if (notebook == selected_notebook) {
400 if (notebook.is_empty ()) {
401 view_mode.sensitive = false;
402 } else {
403 view_mode.sensitive = true;
404 }
405 }
406 });
407
408 notebook.note_trashed.connect (() => {
409 if (notebook == selected_notebook) {
410 if (notebook.is_empty ()) {
411 view_mode.sensitive = false;
412 } else {
413 view_mode.sensitive = true;
414 }
415 }
416 });383 });
417384
418 notebook.view.start_editing.connect (() => {385 notebook.view.start_editing.connect (() => {
419386
=== modified file 'src/Widgets/EditView.vala'
--- src/Widgets/EditView.vala 2015-01-06 21:31:31 +0000
+++ src/Widgets/EditView.vala 2015-01-08 20:03:55 +0000
@@ -23,9 +23,9 @@
23 23
24 public class EditView : Gtk.EventBox {24 public class EditView : Gtk.EventBox {
25 25
26 public Gtk.TextView title;26 public Gtk.TextView title;
27 public Gtk.TextView content;27 public Gtk.TextView content;
28 public Gtk.Toolbar editbar;28 public Gtk.Toolbar editbar;
29 private Gtk.ToggleToolButton bold;29 private Gtk.ToggleToolButton bold;
30 private Gtk.ToggleToolButton italic;30 private Gtk.ToggleToolButton italic;
31 private Gtk.ToggleToolButton strike;31 private Gtk.ToggleToolButton strike;
@@ -100,19 +100,12 @@
100 current_note.tag ("marked", mark.active);100 current_note.tag ("marked", mark.active);
101 });101 });
102102
103 var done = new Gtk.ToolButton (null, null);103 var revert = new Gtk.ToolButton (null, null);
104 done.label = _("Save");104 revert.label = _("revert");
105 done.icon_name = "document-save";105 revert.icon_name = "document-revert";
106 done.tooltip_text = _("Save the current note");106 revert.tooltip_text = _("Restore this file");
107 done.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);107
108108 editbar.insert (revert, -1);
109 var cancel = new Gtk.ToolButton (null, null);
110 cancel.label = _("Cancel");
111 cancel.icon_name = "go-previous";
112 cancel.tooltip_text = _("Cancel all changes");
113
114 editbar.insert (cancel, -1);
115 editbar.insert (done, -1);
116 editbar.insert (new Gtk.SeparatorToolItem (), -1);109 editbar.insert (new Gtk.SeparatorToolItem (), -1);
117 editbar.insert (undo, -1);110 editbar.insert (undo, -1);
118 editbar.insert (redo, -1);111 editbar.insert (redo, -1);
@@ -126,13 +119,13 @@
126 content_scroll.add (this.content);119 content_scroll.add (this.content);
127 content_scroll.hscrollbar_policy = Gtk.PolicyType.NEVER;120 content_scroll.hscrollbar_policy = Gtk.PolicyType.NEVER;
128 this.content.wrap_mode = Gtk.WrapMode.WORD_CHAR;121 this.content.wrap_mode = Gtk.WrapMode.WORD_CHAR;
129 title.get_style_context ().add_class ("h2");122 this.title.get_style_context ().add_class ("h2");
130 this.title.margin_top = 12;123 this.title.margin_top = 12;
131124
132 content_scroll.margin_left = content_scroll.margin_right = this.title.margin_left = 12;125 content_scroll.margin_left = content_scroll.margin_right = this.title.margin_left = 12;
133 126
134 container.pack_start (editbar, false);127 container.pack_start (editbar, false);
135 container.pack_start (title, false);128 container.pack_start (title, false);
136 container.pack_start (content_scroll);129 container.pack_start (content_scroll);
137 130
138 this.title.margin_bottom = 12;131 this.title.margin_bottom = 12;
@@ -146,46 +139,37 @@
146 }139 }
147 return false;140 return false;
148 });141 });
149 142
150 done.clicked.connect ( () => {143 revert.clicked.connect ( () => {
151 this.done ();
152 });
153
154 cancel.clicked.connect ( () => {
155 this.cancel ();144 this.cancel ();
156 });145 });
157 146
158 title.buffer.changed.connect ( () => {
159 if (title.buffer.text == "")
160 done.sensitive = false;
161 else
162 done.sensitive = true;
163 });
164
165 this.key_press_event.connect ( (e) => {147 this.key_press_event.connect ( (e) => {
166 if (e.keyval == Gdk.Key.Escape) {148 if (e.keyval == Gdk.Key.s && Gdk.ModifierType.CONTROL_MASK in e.state) {
167 this.cancel ();149 this.save ();
168 return true;
169 } else if (e.keyval == Gdk.Key.s && Gdk.ModifierType.CONTROL_MASK in e.state) {
170 this.done ();
171 return true;150 return true;
172 }151 }
173 return false;152 return false;
174 });153 });
175 }154 }
176 155
177 private void done () {156 public void save () {
178 current_note.title.label = this.title.buffer.text;157 if (current_note != null && (this.title.buffer.get_modified () || this.content.buffer.get_modified ())) {
179 current_note.save ();158 current_note.title.label = this.title.buffer.text;
180 this.close ();159 current_note.save ();
160
161 this.title.buffer.set_modified (false);
162 this.content.buffer.set_modified (false);
163 }
181 }164 }
182 165
183 private void cancel () {166 private void cancel () {
184 current_note.restore ();167 current_note.restore ();
185 this.close ();
186 }168 }
187 169
188 public void open_note (Note n) {170 public void open_note (Note n) {
171 this.save ();
172
189 if (parent == null)173 if (parent == null)
190 open (); //show the edit view174 open (); //show the edit view
191175
@@ -215,7 +199,10 @@
215 }199 }
216 else200 else
217 content.grab_focus ();201 content.grab_focus ();
218 202
203 this.title.buffer.set_modified (false);
204 this.content.buffer.set_modified (false);
205
219 current_note = n;206 current_note = n;
220 }207 }
221 }208 }
222209
=== modified file 'src/Widgets/Note.vala'
--- src/Widgets/Note.vala 2015-01-06 21:31:31 +0000
+++ src/Widgets/Note.vala 2015-01-08 20:03:55 +0000
@@ -32,8 +32,8 @@
32 public Gtk.TextView content;32 public Gtk.TextView content;
33 public Gtk.Label date;33 public Gtk.Label date;
34 public Notebook notebook;34 public Notebook notebook;
35 public Gtk.Button bookmarked_button;35 public Gtk.Button bookmarked_button;
36 public bool bookmarked;36 public bool bookmarked;
3737
38 public int id;38 public int id;
39 public int month;39 public int month;
@@ -47,7 +47,7 @@
47 public Gdk.Atom deformat;47 public Gdk.Atom deformat;
4848
49 public Note.from_existing (Notebook notebook, 49 public Note.from_existing (Notebook notebook,
50 string title, uint8[] content_, int id, DateTime datetime, bool bookmarked){50 string title, uint8[] content_, int id, DateTime datetime, bool bookmarked) {
51 this.bookmarked = bookmarked;51 this.bookmarked = bookmarked;
52 this.notebook = notebook;52 this.notebook = notebook;
53 this.id = id;53 this.id = id;
@@ -94,7 +94,6 @@
94 date.get_style_context ().add_class ("h3");94 date.get_style_context ().add_class ("h3");
95 date.margin_top = date.margin_bottom = 6;95 date.margin_top = date.margin_bottom = 6;
96 date.selectable = true;96 date.selectable = true;
97 set_time_label ();
9897
99 content.editable = false;98 content.editable = false;
100 content.cursor_visible = false;99 content.cursor_visible = false;
@@ -241,7 +240,10 @@
241 DataBase.get_default ().add_note (this);240 DataBase.get_default ().add_note (this);
242 }241 }
243242
244 private void set_time_label () {243 public string get_time_label (DateTime? dt) {
244 if (dt == null)
245 return "";
246
245 // If AM/PM doesn't exist, use 24h.247 // If AM/PM doesn't exist, use 24h.
246 string time_format;248 string time_format;
247 if (Posix.nl_langinfo (Posix.NLItem.AM_STR) == null || Posix.nl_langinfo (Posix.NLItem.AM_STR) == "") {249 if (Posix.nl_langinfo (Posix.NLItem.AM_STR) == null || Posix.nl_langinfo (Posix.NLItem.AM_STR) == "") {
@@ -251,20 +253,15 @@
251 // If AM/PM exists, assume it is the default time format and check for format override.253 // If AM/PM exists, assume it is the default time format and check for format override.
252 var setting = new GLib.Settings ("org.gnome.desktop.interface");254 var setting = new GLib.Settings ("org.gnome.desktop.interface");
253 var clockformat = setting.get_user_value ("clock-format");255 var clockformat = setting.get_user_value ("clock-format");
254 if (clockformat == null) {256
257 if (clockformat == null || clockformat.get_string ().contains ("12h"))
255 time_format = Granite.DateTime.get_default_time_format (true);258 time_format = Granite.DateTime.get_default_time_format (true);
256 } else {259 else
257260 time_format = Granite.DateTime.get_default_time_format (false);
258 if (clockformat.get_string ().contains ("12h")) {
259 time_format = Granite.DateTime.get_default_time_format (true);
260 } else {
261 time_format = Granite.DateTime.get_default_time_format (false);
262 }
263 }
264 }261 }
265262
266 var date_format = Granite.DateTime.get_default_date_format (false, true, true);263 var date_format = Granite.DateTime.get_default_date_format (false, true, true);
267 date.label = datetime.format (date_format + " - " + time_format);264 return dt.format (date_format + " " + time_format);
268 }265 }
269266
270 public void save () {267 public void save () {
271268
=== modified file 'src/Widgets/NoteView.vala'
--- src/Widgets/NoteView.vala 2015-01-07 21:46:07 +0000
+++ src/Widgets/NoteView.vala 2015-01-08 20:03:55 +0000
@@ -21,7 +21,6 @@
21 public class ActionMenu : Gtk.Revealer {21 public class ActionMenu : Gtk.Revealer {
22 22
23 public Gtk.Button export_button;23 public Gtk.Button export_button;
24 public Gtk.Button edit_button;
25 public Gtk.Button delete_button;24 public Gtk.Button delete_button;
26 public Gtk.Button bookmarked_button;25 public Gtk.Button bookmarked_button;
27 26
@@ -32,10 +31,6 @@
32 export_button.tooltip_text = _("Export");31 export_button.tooltip_text = _("Export");
33 export_button.relief = Gtk.ReliefStyle.NONE;32 export_button.relief = Gtk.ReliefStyle.NONE;
34 33
35 edit_button = new Gtk.Button.from_icon_name ("edit-symbolic", Gtk.IconSize.BUTTON);
36 edit_button.tooltip_text = _("Edit");
37 edit_button.relief = Gtk.ReliefStyle.NONE;
38
39 delete_button = new Gtk.Button.from_icon_name ("edit-delete-symbolic", Gtk.IconSize.BUTTON);34 delete_button = new Gtk.Button.from_icon_name ("edit-delete-symbolic", Gtk.IconSize.BUTTON);
40 delete_button.tooltip_text = _("Delete");35 delete_button.tooltip_text = _("Delete");
41 delete_button.relief = Gtk.ReliefStyle.NONE;36 delete_button.relief = Gtk.ReliefStyle.NONE;
@@ -56,21 +51,18 @@
56 51
57 var buttons = new Gtk.Grid ();52 var buttons = new Gtk.Grid ();
58 buttons.orientation = orientation;53 buttons.orientation = orientation;
54 buttons.add (bookmarked_button);
55 buttons.add (export_button);
59 buttons.add (delete_button);56 buttons.add (delete_button);
60 buttons.add (export_button);57
61 buttons.add (edit_button);58 buttons.opacity = 0.5;
62 buttons.add (bookmarked_button);
63
64 this.transition_type = Gtk.RevealerTransitionType.CROSSFADE;59 this.transition_type = Gtk.RevealerTransitionType.CROSSFADE;
65 this.add (buttons);60 this.add (buttons);
66 61
67 /**62 /**
68 * Events63 * Events
69 **/64 **/
70 /*ask the app to edit the note*/65
71 edit_button.clicked.connect ( () => {
72 this.note.edit ();
73 });
74 /*export clicked, show contractor dialog*/66 /*export clicked, show contractor dialog*/
75 export_button.clicked.connect ( () => {67 export_button.clicked.connect ( () => {
76 var app = (Gtk.Application)GLib.Application.get_default ();68 var app = (Gtk.Application)GLib.Application.get_default ();
@@ -86,12 +78,14 @@
86 contr.run_selected ();78 contr.run_selected ();
87 dialog.destroy ();79 dialog.destroy ();
88 });80 });
81
89 /*delete note*/82 /*delete note*/
90 delete_button.clicked.connect ( () => {83 delete_button.clicked.connect ( () => {
91 this.note.is_trashed = true;84 this.note.is_trashed = true;
92 this.note.trashed ();85 this.note.trashed ();
93 });86 });
9487
88 /*bookmark note*/
95 bookmarked_button.clicked.connect (() => {89 bookmarked_button.clicked.connect (() => {
96 this.note.bookmarked = !this.note.bookmarked;90 this.note.bookmarked = !this.note.bookmarked;
97 this.note.bookmark (this.note.bookmarked);91 this.note.bookmark (this.note.bookmarked);
@@ -199,8 +193,8 @@
199 private Gtk.Paned miller_paned;193 private Gtk.Paned miller_paned;
200 private Gtk.ListBox miller_listbox;194 private Gtk.ListBox miller_listbox;
201 private Gtk.ScrolledWindow miller_scroll;195 private Gtk.ScrolledWindow miller_scroll;
202 public NoteViewer miller_noteviewer;196 public EditView miller_noteviewer;
203 private EditView edit_view;197 private Gtk.ScrolledWindow miller_view_scroll;
204 private Gtk.ListBox note_list;198 private Gtk.ListBox note_list;
205 private Notebook notebook;199 private Notebook notebook;
206 private Gtk.Stack main_stack;200 private Gtk.Stack main_stack;
@@ -216,13 +210,11 @@
216 * Constructor210 * Constructor
217 */211 */
218 public NoteView (FootnoteApp app, Notebook notebook) {212 public NoteView (FootnoteApp app, Notebook notebook) {
219213 this.orientation = Gtk.Orientation.VERTICAL;
220 this.app = app;214 this.app = app;
221 this.notebook = notebook;215 this.notebook = notebook;
222 this.filter = "";216 this.filter = "";
223217
224 edit_view = new EditView (app);
225
226 deletion_infobar = new Gtk.InfoBar ();218 deletion_infobar = new Gtk.InfoBar ();
227 deletion_infobar.message_type = Gtk.MessageType.INFO;219 deletion_infobar.message_type = Gtk.MessageType.INFO;
228 deletion_infobar.no_show_all = true;220 deletion_infobar.no_show_all = true;
@@ -264,13 +256,13 @@
264 });256 });
265 257
266 miller_listbox = new Gtk.ListBox ();258 miller_listbox = new Gtk.ListBox ();
267 miller_noteviewer = new NoteViewer ();259 miller_noteviewer = new EditView (app);
268260
269 miller_scroll = new Gtk.ScrolledWindow (null, null);261 miller_scroll = new Gtk.ScrolledWindow (null, null);
270 miller_scroll.add (miller_noteviewer);262 miller_scroll.add (miller_noteviewer);
271263
272 miller_listbox.row_activated.connect ((row) => {264 miller_listbox.row_activated.connect ((row) => {
273 miller_noteviewer.open_note (((MillerRow)row).note);265 open_note (((MillerRow)row).note);
274 });266 });
275267
276 miller_listbox.set_filter_func ((row) => {268 miller_listbox.set_filter_func ((row) => {
@@ -281,18 +273,6 @@
281 return should_appear ((Note)row.get_child ());273 return should_appear ((Note)row.get_child ());
282 });274 });
283275
284 notebook.note_edit.connect ((note) => {
285 open_note (note);
286 });
287
288 edit_view.close.connect ( (reverse) => {
289 toggle_edit (false);
290
291 Gtk.ListBoxRow selected_row = miller_listbox.get_selected_row ();
292 if (selected_row != null)
293 selected_row.activate ();
294 });
295
296 var empty_label = new Gtk.Label (_("Notebook \"%s\" is empty").printf (notebook.title));276 var empty_label = new Gtk.Label (_("Notebook \"%s\" is empty").printf (notebook.title));
297 empty_label.expand = true;277 empty_label.expand = true;
298 empty_label.halign = Gtk.Align.CENTER;278 empty_label.halign = Gtk.Align.CENTER;
@@ -302,7 +282,7 @@
302 empty_grid.expand = true;282 empty_grid.expand = true;
303 empty_grid.add (empty_label);283 empty_grid.add (empty_label);
304284
305 var miller_view_scroll = new Gtk.ScrolledWindow (null, null);285 miller_view_scroll = new Gtk.ScrolledWindow (null, null);
306 miller_view_scroll.add (miller_listbox);286 miller_view_scroll.add (miller_listbox);
307 miller_view_scroll.hscrollbar_policy = Gtk.PolicyType.NEVER;287 miller_view_scroll.hscrollbar_policy = Gtk.PolicyType.NEVER;
308288
@@ -314,7 +294,6 @@
314 main_stack.add_named (empty_grid, "empty");294 main_stack.add_named (empty_grid, "empty");
315 main_stack.add_named (list_scroll, "list");295 main_stack.add_named (list_scroll, "list");
316 main_stack.add_named (miller_paned, "miller");296 main_stack.add_named (miller_paned, "miller");
317 main_stack.add_named (edit_view, "editor");
318297
319 add (deletion_infobar);298 add (deletion_infobar);
320 add (main_stack);299 add (main_stack);
@@ -327,15 +306,9 @@
327 **/306 **/
328 public void toggle_edit (bool show) {307 public void toggle_edit (bool show) {
329 if (show) {308 if (show) {
330 main_stack.set_visible_child_name ("editor");
331 start_editing ();309 start_editing ();
332 } else {310 } else {
333 stop_editing ();311 stop_editing ();
334 if (app.view_mode.selected == 1) {
335 main_stack.set_visible_child_name ("miller");
336 } else {
337 main_stack.set_visible_child_name ("list");
338 }
339 }312 }
340 }313 }
341314
@@ -377,25 +350,19 @@
377 * filter string (e.g. in title, text or as a tag).350 * filter string (e.g. in title, text or as a tag).
378 */351 */
379 public void update_view () {352 public void update_view () {
380 /*switch view if necessary*/
381 if (main_stack.get_visible_child () == edit_view)
382 edit_view.close (true);
383
384 if (notebook.is_empty ()) {353 if (notebook.is_empty ()) {
385 start_editing ();354 start_editing ();
386 main_stack.set_visible_child_name ("empty");355 main_stack.set_visible_child_name ("empty");
387 return;356 return;
388 }357 }
389358
390 if (app.view_mode.selected == 1) {359 main_stack.set_visible_child_name ("miller");
391 main_stack.set_visible_child_name ("miller");360 var row = miller_listbox.get_row_at_index (0);
392 var row = miller_listbox.get_row_at_index (0);361 if (row != null) {
393 if (row != null) {362 miller_listbox.select_row (row);
394 miller_listbox.select_row (row);363 miller_listbox.row_activated (row);
395 miller_listbox.row_activated (row);364 }
396 }365
397 } else
398 main_stack.set_visible_child_name ("list");
399 }366 }
400367
401 public void change_month (int month) {368 public void change_month (int month) {
@@ -441,9 +408,15 @@
441 /**408 /**
442 * Scroll to a certain note in the list.409 * Scroll to a certain note in the list.
443 */410 */
444 public void open_note (Footnote.Widgets.Note n) {411 public void open_note (Footnote.Widgets.Note n, bool bookmarked = false) {
445 toggle_edit (true);412 toggle_edit (true);
446 edit_view.open_note (n);413
414 miller_noteviewer.open_note (n);
415
416 if (bookmarked)
417 miller_view_scroll.hide ();
418 else
419 miller_view_scroll.show ();
447 }420 }
448 }421 }
449 422
@@ -467,28 +440,31 @@
467 date_label.xalign = 0;440 date_label.xalign = 0;
468 date_label.opacity = 0.8;441 date_label.opacity = 0.8;
469 date_label.ellipsize = Pango.EllipsizeMode.END;442 date_label.ellipsize = Pango.EllipsizeMode.END;
443 date_label.use_markup = true;
470 date_label.halign = Gtk.Align.END;444 date_label.halign = Gtk.Align.END;
445 date_label.margin_right = 6;
471 446
472 summary_label = new Gtk.Label ("");447 summary_label = new Gtk.Label ("");
473 summary_label.xalign = 0;448 summary_label.xalign = 0;
474 summary_label.valign = Gtk.Align.START;449 summary_label.valign = Gtk.Align.START;
475 summary_label.ellipsize = Pango.EllipsizeMode.END;450 summary_label.ellipsize = Pango.EllipsizeMode.END;
476 summary_label.expand = true;
477 summary_label.set_lines (5);
478 summary_label.use_markup = true;451 summary_label.use_markup = true;
479 summary_label.opacity = 0.8;452 summary_label.opacity = 0.8;
453 summary_label.margin_right = 6;
454 summary_label.expand = true;
455
480 var buttons_revealer = new ActionMenu (note, Gtk.Orientation.VERTICAL);456 var buttons_revealer = new ActionMenu (note, Gtk.Orientation.VERTICAL);
481 457
482 var grid = new Gtk.Grid ();458 var grid = new Gtk.Grid ();
483 grid.margin_top = 6;459 grid.margin_top = 6;
484 grid.row_spacing = 2;460 grid.row_spacing = 4;
485 grid.column_spacing = 2;461 grid.column_spacing = 2;
486 grid.attach (buttons_revealer, 0, 0, 1, 2);462 grid.attach (buttons_revealer, 0, 0, 1, 2);
487 grid.attach (title_label, 1, 0, 1, 1);463 grid.attach (title_label, 1, 0, 1, 1);
488 grid.attach (date_label, 2, 0, 1, 1);464 grid.attach (date_label, 2, 0, 1, 1);
489 grid.attach (summary_label, 1, 1, 2, 1);465 grid.attach (summary_label, 1, 1, 2, 1);
490 grid.attach (new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 3, 3, 1);466 grid.attach (new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 3, 3, 1);
491 467
492 var event_box = new Gtk.EventBox ();468 var event_box = new Gtk.EventBox ();
493 event_box.add (grid);469 event_box.add (grid);
494 event_box.events |= Gdk.EventMask.ENTER_NOTIFY_MASK|Gdk.EventMask.LEAVE_NOTIFY_MASK;470 event_box.events |= Gdk.EventMask.ENTER_NOTIFY_MASK|Gdk.EventMask.LEAVE_NOTIFY_MASK;
@@ -504,7 +480,7 @@
504 buttons_revealer.set_reveal_child (false);480 buttons_revealer.set_reveal_child (false);
505 return false;481 return false;
506 });482 });
507 483
508 add (event_box);484 add (event_box);
509 this.show_all();485 this.show_all();
510 update_labels ();486 update_labels ();
@@ -523,13 +499,20 @@
523 string [] lines = note.content.buffer.text.split ("\n");499 string [] lines = note.content.buffer.text.split ("\n");
524 500
525 var result = "";501 var result = "";
526 502 var result_lines = 0;
527 for (int i = 0; i < 5 && i < lines.length ; i++) {503 foreach (string line in lines) {
528 result += lines [i] + "\n";504 if (line.strip ().length == 0)
505 continue;
506
507 result += line + "\n";
508 result_lines ++;
509
510 if (result_lines == 3)
511 break;
529 }512 }
530 513
531 summary_label.label = "<span font_size=\"small\">" + result + "</span>";;514 summary_label.label = "<span font_size=\"small\">" + result.strip () + "</span>";;
532 date_label.label = note.date.label;515 date_label.label = "<span font_size=\"small\">" + note.get_time_label (note.datetime) + "</span>";
533 title_label.label = note.title.label;516 title_label.label = note.title.label;
534 }517 }
535 }518 }

Subscribers

People subscribed via source and target branches