forked from Mirrors/apostrophe
parent
6d7bfe82cb
commit
3f87bd1d22
|
@ -6,6 +6,10 @@
|
|||
<attribute name="label" translatable="yes">Focus Mode</attribute>
|
||||
<attribute name="action">app.focus_mode</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Hemingway Mode</attribute>
|
||||
<attribute name="action">app.hemingway_mode</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Preview</attribute>
|
||||
<attribute name="action">app.preview</attribute>
|
||||
|
|
|
@ -55,20 +55,27 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut" id="s1-7">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Hemingway mode</property>
|
||||
<property name="accelerator"><Primary>t</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut" id="s1-8">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Fullscreen</property>
|
||||
<property name="accelerator">F11</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut" id="s1-8">
|
||||
<object class="GtkShortcutsShortcut" id="s1-9">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Preview</property>
|
||||
<property name="accelerator"><Primary>p</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut" id="s1-9">
|
||||
<object class="GtkShortcutsShortcut" id="s1-10">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Search</property>
|
||||
<property name="accelerator"><Primary>f</property>
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
"""
|
||||
|
|
|
@ -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", ["<Ctl>d"])
|
||||
self.set_accels_for_action("app.hemingway_mode", ["<Ctl>t"])
|
||||
self.set_accels_for_action("app.fullscreen", ["F11"])
|
||||
self.set_accels_for_action("app.preview", ["<Ctl>p"])
|
||||
self.set_accels_for_action("app.search", ["<Ctl>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)
|
||||
|
|
Loading…
Reference in New Issue