[meld] ui.statusbar: Initial implementation of Filediff-specific status bar
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] ui.statusbar: Initial implementation of Filediff-specific status bar
- Date: Sat, 25 Nov 2017 22:05:47 +0000 (UTC)
commit f5d5b074d95a15de2ded7e4fbe3900602007f382
Author: Kai Willadsen <kai willadsen gmail com>
Date: Wed Jan 14 07:39:28 2015 +1000
ui.statusbar: Initial implementation of Filediff-specific status bar
data/ui/gedit-highlight-mode-selector.ui | 83 ++++++++++++++++++++++
meld/ui/statusbar.py | 111 ++++++++++++++++++++++++++++++
2 files changed, 194 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/gedit-highlight-mode-selector.ui b/data/ui/gedit-highlight-mode-selector.ui
new file mode 100644
index 0000000..0da2ed2
--- /dev/null
+++ b/data/ui/gedit-highlight-mode-selector.ui
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <object class="GtkListStore" id="liststore">
+ <columns>
+ <!-- column-name name -->
+ <column type="gchararray"/>
+ <!-- column-name lang -->
+ <column type="GtkSourceLanguage"/>
+ </columns>
+ </object>
+ <object class="GtkTreeModelFilter" id="treemodelfilter">
+ <property name="child_model">liststore</property>
+ </object>
+ <template class="HighlightModeSelector" parent="GtkGrid">
+ <property name="width_request">300</property>
+ <property name="height_request">400</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="row_spacing">3</property>
+ <property name="border_width">6</property>
+ <child>
+ <object class="GtkSearchEntry" id="entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_focus">True</property>
+ <property name="is_focus">False</property>
+ <property name="activates_default">True</property>
+ <property name="placeholder_text" translatable="yes">Search highlight mode...</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="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkTreeView" id="treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="model">treemodelfilter</property>
+ <property name="headers_visible">False</property>
+ <property name="headers_clickable">False</property>
+ <property name="enable_search">False</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection" id="treeview_selection"/>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn">
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </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>
+ </template>
+</interface>
diff --git a/meld/ui/statusbar.py b/meld/ui/statusbar.py
index feed0a5..f1f84ad 100644
--- a/meld/ui/statusbar.py
+++ b/meld/ui/statusbar.py
@@ -13,10 +13,14 @@
# 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 GLib
from gi.repository import GObject
from gi.repository import Gtk
+from gi.repository import GtkSource
from gi.repository import Pango
+from meld.conf import _, ui_file
+
Gtk.rc_parse_string(
"""
@@ -49,8 +53,115 @@ class MeldStatusBar(Gtk.Statusbar):
self.pack_start(alignment, True, True, 0)
alignment.show()
+ self.box_box = Gtk.HBox(homogeneous=False, spacing=6)
+ self.pack_start(self.box_box, True, True, 0)
+ self.box_box.pack_end(self.construct_highlighting_selector(), False, True, 0)
+ self.box_box.show_all()
+
+ def construct_highlighting_selector(self):
+ pop = Gtk.Popover()
+ pop.set_position(Gtk.PositionType.TOP)
+ pop.add(HighlightModeSelector())
+
+ button = Gtk.MenuButton()
+ button.set_label("Foo")
+ button.set_popover(pop)
+ button.show()
+
+ return button
+
def set_info_box(self, widgets):
for child in self.info_box.get_children():
self.info_box.remove(child)
for widget in widgets:
self.info_box.pack_end(widget, False, True, 0)
+
+
+class TemplateHackMixin(object):
+
+ def get_template_child(self, widget_type, name):
+ # Taken from an in-progress patch on bgo#701843
+
+ def get_template_child(widget, widget_type, name):
+ # Explicitly use gtk_buildable_get_name() because it is masked by
+ # gtk_widget_get_name() in GI.
+ if isinstance(widget, widget_type) and \
+ isinstance(widget, Gtk.Buildable) and \
+ Gtk.Buildable.get_name(widget) == name:
+ return widget
+
+ if isinstance(widget, Gtk.Container):
+ for child in widget.get_children():
+ result = get_template_child(child, widget_type, name)
+ if result is not None:
+ return result
+
+ return get_template_child(self, widget_type, name)
+
+
+# HighlightModeSelector was copied and translated to Python from gedit
+# Copyright (C) 2013 - Ignacio Casal Quinteiro
+# Python translation and adaptations
+# Copyright (C) 2015 Kai Willadsen <kai willadsen gmail com>
+
+
+class HighlightModeSelector(TemplateHackMixin, Gtk.Grid):
+
+ __gtype_name__ = "HighlightModeSelector"
+
+ __gsignals__ = {
+ 'language-selected': (
+ GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION,
+ None, (GtkSource.Language,)),
+ }
+
+ NAME_COLUMN, LANG_COLUMN = 0, 1
+
+ def __init__(self):
+ Gtk.Grid.__init__(self)
+ self.init_template()
+
+ self.entry = self.get_template_child(Gtk.SearchEntry, 'entry')
+ self.treeview = self.get_template_child(Gtk.TreeView, 'treeview')
+ self.treeview_selection = self.treeview.get_selection()
+ # FIXME: Should be able to access as a template child, but can't.
+ self.listfilter = self.treeview.get_model()
+ self.liststore = self.listfilter.get_model()
+
+ self.liststore.append((_("Plain Text"), None))
+ manager = GtkSource.LanguageManager()
+ for lang_id in manager.get_language_ids():
+ lang = manager.get_language(lang_id)
+ self.liststore.append((lang.get_name(), lang))
+
+ self.filter_string = ''
+ self.entry.connect('changed', self.on_entry_changed)
+ self.listfilter.set_visible_func(self.lang_name_filter)
+
+ self.entry.connect('activate', self.on_activate)
+ self.treeview.connect('row-activated', self.on_activate)
+
+ def lang_name_filter(self, model, it, *args):
+ if not self.filter_string:
+ return True
+ lang_name = model.get_value(it, self.NAME_COLUMN).lower()
+ return self.filter_string.lower() in lang_name
+
+ def on_entry_changed(self, entry):
+ self.filter_string = entry.get_text()
+ self.listfilter.refilter()
+ first = self.listfilter.get_iter_first()
+ if first:
+ self.treeview_selection.select_iter(first)
+
+ def on_activate(self, *args):
+ model, it = self.treeview_selection.get_selected()
+ if not it:
+ return
+ lang = model.get_value(it, self.LANG_COLUMN)
+ self.emit('language-selected', lang)
+
+
+template = open(ui_file('gedit-highlight-mode-selector.ui')).read()
+template_bytes = GLib.Bytes.new(template)
+HighlightModeSelector.set_template(template_bytes)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]