Skip to content

Commit

Permalink
1.5.3 - Undo/Redo note content [Ctrl(-Shift)-Z]
Browse files Browse the repository at this point in the history
  • Loading branch information
Lains committed Dec 15, 2018
1 parent 8cbb90a commit 87f163b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
8 changes: 8 additions & 0 deletions data/com.github.lainsce.notejot.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
<content_attribute id="money-gambling">none</content_attribute>
</content_rating>
<releases>
<release version="1.5.3" date="2018-12-15">
<description>
<p>Release: Undo/Redo Your Notes</p>
<ul>
<li>Now you can undo/redo stuff inside your notes!</li>
</ul>
</description>
</release>
<release version="1.5.2" date="2018-11-23">
<description>
<p>Release: Desktop Notes</p>
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
com.github.lainsce.notejot (1.5.3) xenial; urgency=low

* New stuff. Please read the enclosed appdata book.

-- Lains <[email protected]> Fri, 15 Dec 2018 13:04:00 -0300

com.github.lainsce.notejot (1.4.4) xenial; urgency=low

* New stuff. Please read the enclosed appdata book.
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Name our project
project('com.github.lainsce.notejot', ['vala', 'c'],
version: '1.4.4'
version: '1.5.3'
)

# Import main lib files
Expand Down
60 changes: 54 additions & 6 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
namespace Notejot {
public class MainWindow : Gtk.Window {
private Gtk.Button delete_item;
private Gtk.TextView view = new Gtk.TextView ();
private new Gtk.SourceBuffer buffer;
private Gtk.SourceView view;
private Gtk.HeaderBar header;
private Gtk.ActionBar actionbar;
private int uid;
Expand All @@ -34,15 +35,19 @@ namespace Notejot {

public SimpleActionGroup actions { get; construct; }

public const string ACTION_PREFIX = "win.";
public const string ACTION_NEW = "action_new";
public const string ACTION_DELETE = "action_delete";
public const string ACTION_PREFIX = "win.";
public const string ACTION_NEW = "action_new";
public const string ACTION_DELETE = "action_delete";
public const string ACTION_UNDO = "action_undo";
public const string ACTION_REDO = "action_redo";

public static Gee.MultiMap<string, string> action_accelerators = new Gee.HashMultiMap<string, string> ();

private const GLib.ActionEntry[] action_entries = {
{ ACTION_NEW, action_new },
{ ACTION_DELETE, action_delete }
{ ACTION_NEW, action_new },
{ ACTION_DELETE, action_delete },
{ ACTION_UNDO, action_new },
{ ACTION_REDO, action_delete }
};

public MainWindow (Gtk.Application app, Storage? storage) {
Expand Down Expand Up @@ -115,6 +120,9 @@ namespace Notejot {
var scrolled = new Gtk.ScrolledWindow (null, null);
scrolled.set_size_request (330,270);

buffer = new Gtk.SourceBuffer (null);
buffer.set_highlight_matching_brackets (false);
view = new Gtk.SourceView.with_buffer (buffer);
view.bottom_margin = 10;
view.buffer.text = this.content;
view.get_style_context().add_class("notejot-view");
Expand Down Expand Up @@ -147,6 +155,21 @@ namespace Notejot {
view.buffer.changed.connect (() => {
update_storage ();
});

key_press_event.connect ((e) => {
uint keycode = e.hardware_keycode;
if ((e.state & Gdk.ModifierType.CONTROL_MASK) != 0) {
if (match_keycode (Gdk.Key.z, keycode)) {
action_undo ();
}
}
if ((e.state & Gdk.ModifierType.CONTROL_MASK + Gdk.ModifierType.SHIFT_MASK) != 0) {
if (match_keycode (Gdk.Key.z, keycode)) {
action_redo ();
}
}
return false;
});
}

public new void set_title (string title) {
Expand Down Expand Up @@ -511,6 +534,14 @@ namespace Notejot {
this.close ();
}

private void action_undo () {
buffer.undo ();
}

private void action_redo () {
buffer.redo ();
}

public Storage get_storage_note() {
int x, y;
string color = this.color;
Expand All @@ -527,6 +558,23 @@ namespace Notejot {
return new Storage.from_storage(x, y, color, selected_color_text, pinned, content, title_name);
}

#if VALA_0_42
protected bool match_keycode (uint keyval, uint code) {
#else
protected bool match_keycode (int keyval, uint code) {
#endif
Gdk.KeymapKey [] keys;
Gdk.Keymap keymap = Gdk.Keymap.get_for_display (Gdk.Display.get_default ());
if (keymap.get_entries_for_keyval (keyval, out keys)) {
foreach (var key in keys) {
if (code == key.keycode)
return true;
}
}

return false;
}

public override bool delete_event (Gdk.EventAny event) {
var settings = AppSettings.get_default ();

Expand Down

0 comments on commit 87f163b

Please sign in to comment.