=== 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 @@
* along with this program. If not, see .
*
* Authored by: Corentin Noël
+ * Artem Anufrij
*/
public class Footnote.DataBase : GLib.Object {
@@ -42,8 +43,6 @@
} catch (SQLHeavy.Error e) {
critical ("Could not create db: %s", e.message);
}
-
-
}
/*
@@ -93,28 +92,56 @@
}
}
+ public void restore_note (Widgets.Note note) {
+
+ try {
+ var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE rowid=:id");
+ q.set_int (":id", note.id);
+
+ var res = q.execute ();
+
+ DateTime datetime = datetime_converter (res);
+
+ // TITLE
+ note.title.label = res.fetch_string (0);
+
+ // CONTENT
+ if (res.fetch_blob (1) != null) {
+ Gtk.TextIter start;
+ Gtk.TextIter end;
+
+ // Clear currently content
+ note.content.buffer.get_start_iter (out start);
+ note.content.buffer.get_end_iter (out end);
+ note.content.buffer.delete_range (start, end);
+
+ note.content.buffer.get_start_iter (out start);
+ try {
+ note.content.buffer.deserialize (note.content.buffer, note.deformat, start, res.fetch_blob (1));
+ } catch (Error e) {
+ critical (e.message);
+ }
+ }
+
+ // DATETIME
+ note.datetime = datetime;
+ note.month = datetime.get_month ();
+ note.year = datetime.get_year ();
+
+ // BOOKMARKED
+ note.bookmarked = (bool)res.fetch_int (4);
+ } catch (SQLHeavy.Error e) {
+ critical (e.message);
+ }
+ }
+
public Gee.ArrayList get_notes_from_notebook (Widgets.Notebook nb) {
var list = new Gee.ArrayList ();
try {
var q = db.prepare ("SELECT title,content,rowid,date,bookmarked FROM 'notes' WHERE notebook = :id ORDER BY rowid ASC;");
q.set_int (":id", nb.id);
for (var res = q.execute (); !res.finished; res.next ()) {
- DateTime datetime;
- // Keep backward compatibility, but now it's stored as an int64.
- if (res.field_type (3) == typeof(string)) {
- var date_string = res.fetch_string (3);
- var parts = date_string.split (" ", 3);
- var hour_parts = parts[0].split (":", 2);
- var day_parts = parts[2].split (".", 3);
- var year = int.parse (day_parts[2]);
- var month = int.parse (day_parts[1]);
- var day = int.parse (day_parts[0]);
- var hours = int.parse (hour_parts[0]);
- var minutes = int.parse (hour_parts[1]);
- datetime = new DateTime.local (year, month, day, hours, minutes, 0);
- } else {
- datetime = new DateTime.from_unix_local (res.fetch_int64 (3));
- }
+ DateTime datetime = datetime_converter (res);
var note = new Widgets.Note.from_existing (nb, res.fetch_string (0), res.fetch_blob (1),
res.fetch_int (2), datetime, (bool)res.fetch_int (4));
@@ -234,4 +261,29 @@
dialog.run ();
dialog.destroy ();
}
+
+ public DateTime datetime_converter (SQLHeavy.QueryResult res) {
+ DateTime return_value = new DateTime.now_local ();
+
+ try {
+ if (res.field_type (3) == typeof(string)) {
+ var date_string = res.fetch_string (3);
+ var parts = date_string.split (" ", 3);
+ var hour_parts = parts[0].split (":", 2);
+ var day_parts = parts[2].split (".", 3);
+ var year = int.parse (day_parts[2]);
+ var month = int.parse (day_parts[1]);
+ var day = int.parse (day_parts[0]);
+ var hours = int.parse (hour_parts[0]);
+ var minutes = int.parse (hour_parts[1]);
+
+ return_value = new DateTime.local (year, month, day, hours, minutes, 0);
+ } else
+ return_value = new DateTime.from_unix_local (res.fetch_int64 (3));
+ } catch (SQLHeavy.Error e) {
+ critical (e.message);
+ }
+
+ return return_value;
+ }
}
=== 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 @@
+/*
+ * Copyright (C) 2014-2015 Elementary Developers
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Authored by: Artem Anufrij
+ */
namespace Footnote.Widgets {
@@ -10,6 +30,7 @@
private Gtk.ToggleToolButton italic;
private Gtk.ToggleToolButton strike;
private Gtk.ToggleToolButton mark;
+
private bool applying_style = false;
public signal void close (bool reverse=false);
@@ -33,14 +54,17 @@
title = new Gtk.TextView ();
title.override_background_color (Gtk.StateFlags.NORMAL, {0, 0, 0, 0});
+
content = new Gtk.TextView ();
content.override_background_color (Gtk.StateFlags.NORMAL, {0, 0, 0, 0});
+
var content_scroll = new Gtk.ScrolledWindow (null, null);
- var undo = new Gtk.ToolButton (null, null);
+ var undo = new Gtk.ToolButton (null, null);
undo.tooltip_text = _("Undo");
undo.icon_name = "edit-undo";
- var redo = new Gtk.ToolButton (null, null);
+
+ var redo = new Gtk.ToolButton (null, null);
redo.tooltip_text = _("Redo");
redo.icon_name = "edit-redo";
@@ -122,20 +146,43 @@
}
return false;
});
+
done.clicked.connect ( () => {
- current_note.title.label = title.buffer.text;
- current_note.save ();
- this.close ();
+ this.done ();
});
+
cancel.clicked.connect ( () => {
- this.close ();
+ this.cancel ();
});
+
title.buffer.changed.connect ( () => {
if (title.buffer.text == "")
done.sensitive = false;
else
done.sensitive = true;
});
+
+ this.key_press_event.connect ( (e) => {
+ if (e.keyval == Gdk.Key.Escape) {
+ this.cancel ();
+ return true;
+ } else if (e.keyval == Gdk.Key.s && Gdk.ModifierType.CONTROL_MASK in e.state) {
+ this.done ();
+ return true;
+ }
+ return false;
+ });
+ }
+
+ private void done () {
+ current_note.title.label = this.title.buffer.text;
+ current_note.save ();
+ this.close ();
+ }
+
+ private void cancel () {
+ current_note.restore ();
+ this.close ();
}
public void open_note (Note n) {
@@ -143,13 +190,14 @@
open (); //show the edit view
title.buffer.text = n.title.label;
+
content.buffer = n.content.buffer;
-
+ content.show_all ();
content.buffer.notify["cursor-position"].connect ( () => {
Gtk.TextIter s;
content.buffer.get_selection_bounds (out s, null);
string [] tags = new string[s.get_tags ().length ()];
- for (var i=0;i.
//
+// Authored by: Artem Anufrij
namespace Footnote.Widgets {
@@ -271,6 +272,10 @@
if (this.is_brand_new == true)
this.is_brand_new = false;
}
+
+ public void restore () {
+ DataBase.get_default ().restore_note (this);
+ }
}
}
=== 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 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
+// Authored by: Artem Anufrij
namespace Footnote.Widgets {
@@ -179,31 +180,33 @@
private Gtk.ListBox miller_listbox;
private Gtk.ScrolledWindow miller_scroll;
public NoteViewer miller_noteviewer;
- private EditView edit_view;
- private Gtk.ListBox note_list;
- private Notebook notebook;
- private Gtk.Stack main_stack;
+ private EditView edit_view;
+ private Gtk.ListBox note_list;
+ private Notebook notebook;
+ private Gtk.Stack main_stack;
- private Gtk.InfoBar deletion_infobar;
- private Gtk.Label deletion_label;
- private Note trashed_note;
+ private Gtk.InfoBar deletion_infobar;
+ private Gtk.Label deletion_label;
+ private Note trashed_note;
private int year = -1;
private int month = -1;
- //public GtkClutter.Actor undo_bar;
-
- private int current; //currently used view
-
/**
* Constructor
*/
public NoteView (FootnoteApp app, Notebook notebook) {
orientation = Gtk.Orientation.VERTICAL;
- this.app = app;
- this.notebook = notebook;
- this.filter = "";
- this.current = 0;
+ this.app = app;
+ this.notebook = notebook;
+ this.filter = "";
+ this.key_press_event.connect ( (e) => {
+ if (e.keyval == Gdk.Key.F2) {
+ miller_noteviewer.current_note.edit ();
+ return true;
+ }
+ return false;
+ });
edit_view = new EditView (app);
deletion_infobar = new Gtk.InfoBar ();
@@ -262,6 +265,10 @@
edit_view.close.connect ( (reverse) => {
toggle_edit (false);
+
+ Gtk.ListBoxRow selected_row = miller_listbox.get_selected_row ();
+ if (selected_row != null)
+ selected_row.activate ();
});
var empty_label = new Gtk.Label (_("Notebook \"%s\" is empty").printf (notebook.title));
@@ -365,11 +372,8 @@
miller_listbox.select_row (row);
miller_listbox.row_activated (row);
}
- } else {
+ } else
main_stack.set_visible_child_name ("list");
- }
- current = app.view_mode.selected;
-
}
public void change_month (int month) {
@@ -429,26 +433,27 @@
public MillerRow (Note note) {
this.note = note;
title_label = new Gtk.Label ("");
+ title_label.get_style_context ().add_class ("h3");
title_label.xalign = 0;
title_label.ellipsize = Pango.EllipsizeMode.END;
date_label = new Gtk.Label ("");
date_label.xalign = 0;
- date_label.opacity = 0.8;
+ date_label.opacity = 0.7;
date_label.ellipsize = Pango.EllipsizeMode.END;
summary_label = new Gtk.Label ("");
summary_label.xalign = 0;
+ summary_label.opacity = 0.9;
summary_label.ellipsize = Pango.EllipsizeMode.END;
- var grid = new Gtk.Grid ();
- grid.margin = 6;
- grid.row_spacing = 6;
- grid.orientation = Gtk.Orientation.VERTICAL;
- grid.add (title_label);
- grid.add (date_label);
- grid.add (summary_label);
-
- add (grid);
-
+ var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
+ box.margin = 6;
+ box.margin_bottom = 0;
+ box.pack_start (title_label);
+ box.pack_start (date_label);
+ box.pack_start (summary_label);
+ box.pack_start (new Gtk.Separator(Gtk.Orientation.HORIZONTAL));
+
+ add (box);
update_labels ();
note.edited.connect (() => {
=== 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 @@
step = 4;
}
- var pix_number = pixbuf.width*pixbuf.height*step;
+ var pix_number = pixbuf.width * pixbuf.height * step;
uint8[] new_pixels = new uint8[pix_number];
for (int i = 0; i < pix_number; i+=step) {
var r = pixels[i];