Skip to content

Commit 211eb6e

Browse files
committed
Move find and replace to GActions
1 parent 14d3847 commit 211eb6e

8 files changed

Lines changed: 23 additions & 41 deletions

File tree

data/ui/meldapp-ui.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<ui>
22
<menubar name="Menubar">
3-
<menu action="EditMenu">
4-
<menuitem action="Find"/>
5-
<menuitem action="Replace"/>
6-
</menu>
73
<menu action="ChangesMenu">
84
<placeholder name="ChangesActions" />
95
</menu>

meld/accelerators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
def register_accels(app: Gtk.Application):
66
view_accels = (
7+
('view.find', '<Primary>F'),
78
('view.find-next', '<Primary>G'),
89
('view.find-previous', '<Primary><Shift>G'),
10+
('view.find-replace', '<Primary>H'),
911
('view.folder-compare', 'Return'),
1012
('view.folder-copy-left', '<Alt>Left'),
1113
('view.folder-copy-right', '<Alt>Right'),

meld/dirdiff.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ def __init__(self, num_panes):
408408

409409
# Manually handle GAction additions
410410
actions = (
411+
('find', self.action_find),
411412
('folder-collapse', self.action_folder_collapse),
412413
('folder-compare', self.action_diff),
413414
('folder-copy-left', self.action_copy_left),
@@ -1662,7 +1663,7 @@ def action_previous_change(self, *args):
16621663
def action_next_change(self, *args):
16631664
self.next_diff(Gdk.ScrollDirection.DOWN)
16641665

1665-
def action_refresh(self, *extra):
1666+
def action_refresh(self, *args):
16661667
self.on_fileentry_file_set(None)
16671668

16681669
def on_delete_event(self):
@@ -1671,7 +1672,7 @@ def on_delete_event(self):
16711672
self.close_signal.emit(0)
16721673
return Gtk.ResponseType.OK
16731674

1674-
def on_find_activate(self, *extra):
1675+
def action_find(self, *args):
16751676
self.focus_pane.emit("start-interactive-search")
16761677

16771678
def auto_compare(self):

meld/filediff.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,10 @@ def __init__(self, num_panes):
291291
actions = (
292292
('add-sync-point', self.add_sync_point),
293293
('clear-sync-point', self.clear_sync_points),
294+
('find', self.action_find),
294295
('find-next', self.action_find_next),
295296
('find-previous', self.action_find_previous),
297+
('find-replace', self.action_find_replace),
296298
('format-as-patch', self.action_format_as_patch),
297299
('go-to-line', self.action_go_to_line),
298300
('merge-all-left', self.action_pull_all_changes_left),
@@ -1157,12 +1159,12 @@ def get_selected_text(self, pane):
11571159
if sel:
11581160
return buf.get_text(sel[0], sel[1], False)
11591161

1160-
def on_find_activate(self, *args):
1162+
def action_find(self, *args):
11611163
selected_text = self.get_selected_text()
11621164
self.findbar.start_find(
11631165
textview=self.focus_pane, replace=False, text=selected_text)
11641166

1165-
def on_replace_activate(self, *args):
1167+
def action_find_replace(self, *args):
11661168
selected_text = self.get_selected_text()
11671169
self.findbar.start_find(
11681170
textview=self.focus_pane, replace=True, text=selected_text)

meld/melddoc.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ def open_cb(source, result, *data):
168168
f.query_info_async(query_attrs, 0, GLib.PRIORITY_LOW, None,
169169
open_cb, None)
170170

171-
def on_find_activate(self, *extra):
172-
pass
173-
174-
def on_replace_activate(self, *extra):
175-
pass
176-
177171
def on_file_changed(self, filename):
178172
pass
179173

meld/meldwindow.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ def __init__(self):
6060
self.init_template()
6161

6262
actions = (
63-
("EditMenu", None, _("_Edit")),
64-
("Find", Gtk.STOCK_FIND, _("Find…"), None, _("Search for text"),
65-
self.on_menu_find_activate),
66-
("Replace", Gtk.STOCK_FIND_AND_REPLACE,
67-
_("_Replace…"), "<Primary>H",
68-
_("Find and replace text"),
69-
self.on_menu_replace_activate),
70-
7163
("ChangesMenu", None, _("_Changes")),
7264
)
7365
self.actiongroup = Gtk.ActionGroup(name='MainActions')
@@ -224,17 +216,6 @@ def _update_page_action_sensitivity(self):
224216
page = None
225217

226218
self.lookup_action('close').set_enabled(bool(page))
227-
if not isinstance(page, MeldDoc):
228-
for action in (
229-
"Find", "Replace",
230-
):
231-
self.actiongroup.get_action(action).set_sensitive(False)
232-
else:
233-
for action in ("Find",):
234-
self.actiongroup.get_action(action).set_sensitive(True)
235-
is_filediff = isinstance(page, FileDiff)
236-
for action in ("Replace",):
237-
self.actiongroup.get_action(action).set_sensitive(is_filediff)
238219

239220
def handle_current_doc_switch(self, page):
240221
page.on_container_switch_out_event(self.ui, self)
@@ -280,12 +261,6 @@ def action_close(self, *extra):
280261
page = self.notebook.get_nth_page(i)
281262
page.on_delete_event()
282263

283-
def on_menu_find_activate(self, *extra):
284-
self.current_doc().on_find_activate()
285-
286-
def on_menu_replace_activate(self, *extra):
287-
self.current_doc().on_replace_activate()
288-
289264
def on_action_fullscreen_change_state(self, action, state):
290265
window_state = self.get_window().get_state()
291266
is_full = window_state & Gdk.WindowState.FULLSCREEN

meld/resources/gtk/menus.ui

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
<attribute name="action">view.revert</attribute>
4040
</item>
4141
</section>
42+
<section>
43+
<attribute name="id">find-section</attribute>
44+
<item>
45+
<attribute name="label" translatable="yes">_Find…</attribute>
46+
<attribute name="action">view.find</attribute>
47+
</item>
48+
<item>
49+
<attribute name="label" translatable="yes">_Replace…</attribute>
50+
<attribute name="action">view.find-replace</attribute>
51+
</item>
52+
</section>
4253
<section>
4354
<submenu>
4455
<attribute name="label" translatable="yes">View</attribute>

meld/vcview.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def __init__(self):
201201
# Manually handle GAction additions
202202
actions = (
203203
('compare', self.action_diff),
204+
('find', self.action_find),
204205
('next-change', self.action_next_change),
205206
('open-external', self.action_open_external),
206207
('previous-change', self.action_previous_change),
@@ -896,10 +897,10 @@ def action_previous_change(self, *args):
896897
def action_next_change(self, *args):
897898
self.next_diff(Gdk.ScrollDirection.DOWN)
898899

899-
def action_refresh(self, *extra):
900+
def action_refresh(self, *args):
900901
self.on_fileentry_file_set(self.fileentry)
901902

902-
def on_find_activate(self, *extra):
903+
def action_find(self, *args):
903904
self.treeview.emit("start-interactive-search")
904905

905906
def auto_compare(self):

0 commit comments

Comments
 (0)