forked from Mirrors/apostrophe
Add shortcut for find and replace
Also renames "search" to "find" as most other Gtk apps.github/fork/yochananmarqos/patch-1
parent
859ad84524
commit
23cddba0d0
|
@ -21,11 +21,11 @@
|
|||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Save _As</attribute>
|
||||
<attribute name="label" translatable="yes">Save As</attribute>
|
||||
<attribute name="action">app.save_as</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Export</attribute>
|
||||
<attribute name="label" translatable="yes">Export</attribute>
|
||||
<attribute name="action">app.export</attribute>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -33,6 +33,12 @@
|
|||
<attribute name="action">app.copy_html</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Find and Replace</attribute>
|
||||
<attribute name="action">app.search_replace</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Preferences</attribute>
|
||||
|
|
|
@ -92,14 +92,21 @@
|
|||
<child>
|
||||
<object class="GtkShortcutsGroup" id="search">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Search</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Find</property>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut" id="s1-10">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Search</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Find</property>
|
||||
<property name="accelerator"><Primary>f</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut" id="s1-11">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Find and replace</property>
|
||||
<property name="accelerator"><Primary>h</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<object class="GtkImage" id="edit-find-replace">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xpad">12</property>
|
||||
<property name="icon_name">edit-find-replace-symbolic</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="go-up">
|
||||
|
@ -268,7 +269,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Open Replace</property>
|
||||
<property name="tooltip_text" translatable="yes">Replace</property>
|
||||
<property name="image">edit-find-replace</property>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -360,7 +361,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="replace_all">
|
||||
<property name="label" translatable="yes">Replace all</property>
|
||||
<property name="label" translatable="yes">Replace All</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
|
|
|
@ -98,6 +98,10 @@ class Application(Gtk.Application):
|
|||
action.connect("activate", self.on_copy_html)
|
||||
self.add_action(action)
|
||||
|
||||
action = Gio.SimpleAction.new("search_replace", None)
|
||||
action.connect("activate", self.on_search_replace)
|
||||
self.add_action(action)
|
||||
|
||||
action = Gio.SimpleAction.new("preferences", None)
|
||||
action.connect("activate", self.on_preferences)
|
||||
self.add_action(action)
|
||||
|
@ -143,6 +147,7 @@ class Application(Gtk.Application):
|
|||
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"])
|
||||
self.set_accels_for_action("app.search_replace", ["<Ctl>h"])
|
||||
self.set_accels_for_action("app.spellcheck", ["F7"])
|
||||
|
||||
self.set_accels_for_action("app.new", ["<Ctl>n"])
|
||||
|
@ -208,7 +213,10 @@ class Application(Gtk.Application):
|
|||
self.window.save_document()
|
||||
|
||||
def on_search(self, _action, _value):
|
||||
self.window.open_search_and_replace()
|
||||
self.window.open_search()
|
||||
|
||||
def on_search_replace(self, _action, _value):
|
||||
self.window.open_search(replace=True)
|
||||
|
||||
def on_focus_mode(self, action, value):
|
||||
action.set_state(value)
|
||||
|
|
|
@ -166,7 +166,7 @@ def main_buttons(app):
|
|||
btn.open_recent.pack_start(open_button, False, False, 0)
|
||||
btn.open_recent.pack_end(recents_button, False, False, 0)
|
||||
|
||||
btn.search.set_tooltip_text(_("Search and Replace"))
|
||||
btn.search.set_tooltip_text(_("Find"))
|
||||
btn.menu.set_tooltip_text(_("Menu"))
|
||||
btn.menu.set_image(Gtk.Image.new_from_icon_name("open-menu-symbolic",
|
||||
Gtk.IconSize.BUTTON))
|
||||
|
|
|
@ -467,11 +467,11 @@ class MainWindow(StyledWindow):
|
|||
|
||||
self.load_file(helpers.get_media_file('uberwriter_markdown.md'))
|
||||
|
||||
def open_search_and_replace(self):
|
||||
def open_search(self, replace=False):
|
||||
"""toggle the search box
|
||||
"""
|
||||
|
||||
self.searchreplace.toggle_search()
|
||||
self.searchreplace.toggle_search(replace=replace)
|
||||
|
||||
def open_advanced_export(self, _widget=None, _data=None):
|
||||
"""open the export and advanced export dialog
|
||||
|
|
|
@ -82,11 +82,10 @@ class SearchAndReplace:
|
|||
"""
|
||||
self.replacebox.set_reveal_child(widget.get_active())
|
||||
|
||||
# TODO: refactorize!
|
||||
def key_pressed(self, _widget, event, _data=None):
|
||||
"""hide the search and replace content box when ESC is pressed
|
||||
"""
|
||||
if event.keyval in [Gdk.KEY_Escape]:
|
||||
if event.keyval == Gdk.KEY_Escape:
|
||||
self.hide()
|
||||
|
||||
def focused_texteditor(self, _widget, _data=None):
|
||||
|
@ -94,15 +93,19 @@ class SearchAndReplace:
|
|||
"""
|
||||
self.hide()
|
||||
|
||||
def toggle_search(self, _widget=None, _data=None):
|
||||
def toggle_search(self, replace=False):
|
||||
"""
|
||||
show search box
|
||||
toggle search box
|
||||
"""
|
||||
if self.textview.get_mapped() and (
|
||||
self.box.get_reveal_child() is False or self.searchbar.get_search_mode() is False):
|
||||
search_hidden = self.textview.get_mapped() and (
|
||||
self.box.get_reveal_child() is False or self.searchbar.get_search_mode() is False)
|
||||
replace_hidden = not self.open_replace_button.get_active()
|
||||
if search_hidden or (replace and replace_hidden):
|
||||
self.searchbar.set_search_mode(True)
|
||||
self.box.set_reveal_child(True)
|
||||
self.searchentry.grab_focus()
|
||||
if replace:
|
||||
self.open_replace_button.set_active(True)
|
||||
else:
|
||||
self.hide()
|
||||
self.open_replace_button.set_active(False)
|
||||
|
|
Loading…
Reference in New Issue