diff --git a/data/ui/Menu.ui b/data/ui/Menu.ui
index 55319df..e07092c 100644
--- a/data/ui/Menu.ui
+++ b/data/ui/Menu.ui
@@ -6,6 +6,10 @@
Focus Mode
app.focus_mode
+ -
+ Hemingway Mode
+ app.hemingway_mode
+
-
Preview
app.preview
diff --git a/data/ui/Shortcuts.ui b/data/ui/Shortcuts.ui
index d3c6dee..3234844 100644
--- a/data/ui/Shortcuts.ui
+++ b/data/ui/Shortcuts.ui
@@ -55,20 +55,27 @@
+
+
+
-
-
+
True
Search
<Primary>f
diff --git a/uberwriter/UberwriterTextEditor.py b/uberwriter/UberwriterTextEditor.py
index 6965b54..63673d4 100644
--- a/uberwriter/UberwriterTextEditor.py
+++ b/uberwriter/UberwriterTextEditor.py
@@ -122,6 +122,9 @@ class TextEditor(Gtk.TextView):
self.not_undoable_action = False
self.undo_in_progress = False
+ self.can_delete = True
+ self.connect('key-press-event', self.on_key_press_event)
+
self.format_shortcuts = FormatShortcuts(self.get_buffer(), self)
self.connect('insert-italic', self.set_italic)
@@ -393,6 +396,12 @@ class TextEditor(Gtk.TextView):
toggles self.not_undoable_action"""
self.not_undoable_action = False
+ def on_key_press_event(self, widget, event):
+ if widget == self and not self.can_delete:
+ return event.keyval == Gdk.KEY_BackSpace or event.keyval == Gdk.KEY_Delete
+ else:
+ return False
+
def set_italic(self, _widget, _data=None):
"""Ctrl + I"""
self.format_shortcuts.italic()
diff --git a/uberwriter/UberwriterWindow.py b/uberwriter/UberwriterWindow.py
index dd993d4..188e857 100644
--- a/uberwriter/UberwriterWindow.py
+++ b/uberwriter/UberwriterWindow.py
@@ -358,7 +358,7 @@ class UberwriterWindow(Gtk.ApplicationWindow):
self.update_line_and_char_count()
self.check_scroll(self.text_buffer.get_insert())
- def toggle_fullscreen(self, state):
+ def set_fullscreen(self, state):
"""Puts the application in fullscreen mode and show/hides
the poller for motion in the top border
@@ -376,7 +376,7 @@ class UberwriterWindow(Gtk.ApplicationWindow):
self.text_editor.grab_focus()
- def set_focusmode(self, state):
+ def set_focus_mode(self, state):
"""toggle focusmode
"""
@@ -408,6 +408,12 @@ class UberwriterWindow(Gtk.ApplicationWindow):
self.spell_checker._misspelled.set_property('underline', 4)
_click_event = self.text_editor.disconnect(self.click_event)
+ def set_hemingway_mode(self, state):
+ """toggle hemingwaymode
+ """
+ self.text_editor.can_delete = not state.get_boolean()
+ self.text_editor.grab_focus()
+
def on_focusmode_click(self, *_args):
"""call MarkupBuffer to mark as bold the line where the cursor is
"""
diff --git a/uberwriter_lib/AppWindow.py b/uberwriter_lib/AppWindow.py
index 3e446ae..f286761 100644
--- a/uberwriter_lib/AppWindow.py
+++ b/uberwriter_lib/AppWindow.py
@@ -72,6 +72,12 @@ class Application(Gtk.Application):
action.connect("change-state", self.on_focus_mode)
self.add_action(action)
+ action = Gio.SimpleAction.new_stateful("hemingway_mode",
+ None,
+ GLib.Variant.new_boolean(False))
+ action.connect("change-state", self.on_hemingway_mode)
+ self.add_action(action)
+
action = Gio.SimpleAction.new_stateful("fullscreen",
None,
GLib.Variant.new_boolean(False))
@@ -143,6 +149,7 @@ class Application(Gtk.Application):
# Shortcuts
self.set_accels_for_action("app.focus_mode", ["d"])
+ self.set_accels_for_action("app.hemingway_mode", ["t"])
self.set_accels_for_action("app.fullscreen", ["F11"])
self.set_accels_for_action("app.preview", ["p"])
self.set_accels_for_action("app.search", ["f"])
@@ -238,11 +245,15 @@ class Application(Gtk.Application):
def on_focus_mode(self, action, value):
action.set_state(value)
- self.window.set_focusmode(value)
+ self.window.set_focus_mode(value)
+
+ def on_hemingway_mode(self, action, value):
+ action.set_state(value)
+ self.window.set_hemingway_mode(value)
def on_fullscreen(self, action, value):
action.set_state(value)
- self.window.toggle_fullscreen(value)
+ self.window.set_fullscreen(value)
def on_preview(self, action, value):
action.set_state(value)