[meld/deprecation-cleanup] findbar: Move to template and resource loading
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/deprecation-cleanup] findbar: Move to template and resource loading
- Date: Sun, 9 Dec 2018 21:32:41 +0000 (UTC)
commit 3a6b647c4829f49ea6a8184197608ae94749fad7
Author: Kai Willadsen <kai willadsen gmail com>
Date: Mon Dec 10 06:25:19 2018 +1000
findbar: Move to template and resource loading
data/ui/findbar.ui | 289 -------------------------------------------
meld/filediff.py | 2 +-
meld/resources/ui/findbar.ui | 284 ++++++++++++++++++++++++++++++++++++++++++
meld/ui/findbar.py | 53 +++++---
4 files changed, 324 insertions(+), 304 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 607bbd27..85269be1 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -252,7 +252,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
)
self.findbar = FindBar(self.grid)
- self.grid.attach(self.findbar.widget, 1, 2, 5, 1)
+ self.grid.attach(self.findbar, 1, 2, 5, 1)
self.set_num_panes(num_panes)
self.cursor = CursorDetails()
diff --git a/meld/resources/ui/findbar.ui b/meld/resources/ui/findbar.ui
new file mode 100644
index 00000000..900decb1
--- /dev/null
+++ b/meld/resources/ui/findbar.ui
@@ -0,0 +1,284 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.6 -->
+ <object class="GtkArrow" id="arrow_left">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="arrow_type">left</property>
+ </object>
+ <object class="GtkArrow" id="arrow_right">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <template class="FindBar" parent="GtkGrid">
+ <property name="can_focus">False</property>
+ <property name="column_spacing">6</property>
+ <child>
+ <object class="GtkHButtonBox" id="hbuttonbox2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">start</property>
+ <child>
+ <object class="GtkButton" id="replace_button">
+ <property name="label" translatable="yes">_Replace</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="relief">none</property>
+ <property name="use_underline">True</property>
+ <property name="focus_on_click">False</property>
+ <signal name="clicked" handler="on_replace_button_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="replace_all_button">
+ <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>
+ <property name="relief">none</property>
+ <property name="use_underline">True</property>
+ <property name="focus_on_click">False</property>
+ <signal name="clicked" handler="on_replace_all_button_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHButtonBox" id="hbuttonbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">start</property>
+ <child>
+ <object class="GtkButton" id="find_previous_button">
+ <property name="label" translatable="yes">_Previous</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="image">arrow_left</property>
+ <property name="relief">none</property>
+ <property name="use_underline">True</property>
+ <property name="focus_on_click">False</property>
+ <signal name="clicked" handler="on_find_previous_button_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="find_next_button">
+ <property name="label" translatable="yes">_Next</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="image">arrow_right</property>
+ <property name="relief">none</property>
+ <property name="use_underline">True</property>
+ <property name="focus_on_click">False</property>
+ <signal name="clicked" handler="on_find_next_button_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="find_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Find:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">find_entry</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSearchEntry" id="find_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="width_chars">32</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <signal name="changed" handler="on_find_entry_changed" swapped="no"/>
+ <signal name="activate" handler="on_find_next_button_clicked" swapped="no"/>
+ <signal name="stop-search" handler="on_stop_search" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="replace_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Replace _with:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">replace_entry</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="replace_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="width_chars">32</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <signal name="activate" handler="on_replace_button_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="find_options">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkCheckButton" id="match_case">
+ <property name="label" translatable="yes">_Match case</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="focus_on_click">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="whole_word">
+ <property name="label" translatable="yes">Who_le word</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="focus_on_click">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="regex">
+ <property name="label" translatable="yes">Regular e_xpression</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="focus_on_click">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">3</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="wrap_box">
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkImage" id="wrap_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-info</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="wrap_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Wrapped</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">4</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </template>
+</interface>
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index cf9a606a..ed9ad63c 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -14,15 +14,34 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from gi.repository import Gtk
from gi.repository import GtkSource
-from meld.ui import gnomeglade
+from meld.ui._gtktemplate import Template
-class FindBar(gnomeglade.Component):
+@Template(resource_path='/org/gnome/meld/ui/findbar.ui')
+class FindBar(Gtk.Grid):
+
+ __gtype_name__ = 'FindBar'
+
+ arrow_left = Template.Child()
+ arrow_right = Template.Child()
+ find_entry = Template.Child()
+ find_next_button = Template.Child()
+ find_previous_button = Template.Child()
+ hbuttonbox2 = Template.Child()
+ match_case = Template.Child()
+ regex = Template.Child()
+ replace_entry = Template.Child()
+ replace_label = Template.Child()
+ whole_word = Template.Child()
+ wrap_box = Template.Child()
+
def __init__(self, parent):
- super().__init__("findbar.ui", "findbar",
- ["arrow_left", "arrow_right"])
+ super().__init__()
+ self.init_template()
+
self.set_text_view(None)
self.arrow_left.show()
self.arrow_right.show()
@@ -38,18 +57,15 @@ class FindBar(gnomeglade.Component):
def on_focus_child(self, container, widget):
if widget is not None:
- visible = self.widget.props.visible
- if widget is not self.widget and visible:
+ visible = self.props.visible
+ if widget is not self and visible:
self.hide()
return False
def hide(self):
self.set_text_view(None)
self.wrap_box.set_visible(False)
- self.widget.hide()
-
- def on_stop_search(self, search_entry):
- self.hide()
+ Gtk.Widget.hide(self)
def set_text_view(self, textview):
self.textview = textview
@@ -68,8 +84,8 @@ class FindBar(gnomeglade.Component):
self.find_entry.get_style_context().remove_class("not-found")
if text:
self.find_entry.set_text(text)
- self.widget.set_row_spacing(0)
- self.widget.show()
+ self.set_row_spacing(0)
+ self.show()
self.find_entry.grab_focus()
def start_find_next(self, textview):
@@ -91,17 +107,20 @@ class FindBar(gnomeglade.Component):
self.find_entry.get_style_context().remove_class("not-found")
if text:
self.find_entry.set_text(text)
- self.widget.set_row_spacing(6)
- self.widget.show_all()
+ self.set_row_spacing(6)
+ self.show_all()
self.find_entry.grab_focus()
self.wrap_box.set_visible(False)
+ @Template.Callback()
def on_find_next_button_clicked(self, button):
self._find_text()
+ @Template.Callback()
def on_find_previous_button_clicked(self, button):
self._find_text(backwards=True)
+ @Template.Callback()
def on_replace_button_clicked(self, entry):
buf = self.textview.get_buffer()
oldsel = buf.get_selection_bounds()
@@ -114,6 +133,7 @@ class FindBar(gnomeglade.Component):
newsel[0], newsel[1], self.replace_entry.get_text(), -1)
self._find_text(0)
+ @Template.Callback()
def on_replace_all_button_clicked(self, entry):
buf = self.textview.get_buffer()
saved_insert = buf.create_mark(
@@ -124,10 +144,15 @@ class FindBar(gnomeglade.Component):
self.textview.scroll_to_mark(
buf.get_insert(), 0.25, True, 0.5, 0.5)
+ @Template.Callback()
def on_find_entry_changed(self, entry):
self.find_entry.get_style_context().remove_class("not-found")
self._find_text(0)
+ @Template.Callback()
+ def on_stop_search(self, search_entry):
+ self.hide()
+
def _find_text(self, start_offset=1, backwards=False):
assert self.textview
assert self.search_context
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]