# Path: meld/ui/bufferselectors.py
# class EncodingSelector(FilteredListSelector, Gtk.Grid):
#     # The subclassing here is weird; the Selector must directly
#     # subclass Gtk.Grid, or the template building explodes.
# 
#     __gtype_name__ = 'EncodingSelector'
# 
#     __gsignals__ = {
#         'encoding-selected': (
#             GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION,
#             None, (GtkSource.Encoding,)),
#     }
# 
#     # These exist solely to make subclassing easier.
#     value_accessor = 'get_charset'
#     change_signal_name = 'encoding-selected'
# 
#     entry = Gtk.Template.Child('entry')
#     treeview = Gtk.Template.Child('treeview')
# 
#     def populate_model(self):
#         for enc in GtkSource.Encoding.get_all():
#             self.liststore.append((self.get_value_label(enc), enc))
# 
#     def get_value_label(self, enc):
#         return _('{name} ({charset})').format(
#             name=enc.get_name(), charset=enc.get_charset())
# 
# class SourceLangSelector(FilteredListSelector, Gtk.Grid):
# 
#     __gtype_name__ = "SourceLangSelector"
# 
#     __gsignals__ = {
#         'language-selected': (
#             GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION,
#             None, (GtkSource.Language,)),
#     }
# 
#     # These exist solely to make subclassing easier.
#     value_accessor = 'get_id'
#     change_signal_name = 'language-selected'
# 
#     entry = Gtk.Template.Child('entry')
#     treeview = Gtk.Template.Child('treeview')
# 
#     def populate_model(self):
#         self.liststore.append((_("Plain Text"), None))
#         manager = GtkSource.LanguageManager.get_default()
#         for lang_id in manager.get_language_ids():
#             lang = manager.get_language(lang_id)
#             self.liststore.append((lang.get_name(), lang))
# 
#     def get_value_label(self, lang):
#         if not lang:
#             return _("Plain Text")
#         return lang.get_name()


from gi.repository import GObject, Gtk, GtkSource, Pango
from meld.conf import _
from meld.ui.bufferselectors import EncodingSelector, SourceLangSelector
        pop = Gtk.Popover()
        pop.set_position(Gtk.PositionType.TOP)
        pop.add(selector)

        def format_cursor_position(binding, cursor):
            line, offset = cursor
            return self._line_column_text.format(
                line=line + 1, column=offset + 1)

        button = MeldStatusMenuButton()
        self.bind_property(
            'cursor_position', button, 'label', GObject.BindingFlags.DEFAULT,
            format_cursor_position)
        self.connect('start-go-to-line', lambda *args: button.clicked())
        button.set_popover(pop)
        # Set a label width to avoid other widgets moving on cursor change
        reasonable_width = len(format_cursor_position(None, (1000, 100))) - 2
        button.set_label_width(reasonable_width)
        button.show()

        return button

    def construct_encoding_selector(self):
        def change_encoding(selector, encoding):
            self.emit('encoding-changed', encoding)
            pop.hide()

        def set_initial_encoding(selector):
            selector.select_value(self.props.source_encoding)


# Path: meld/ui/bufferselectors.py
# class EncodingSelector(FilteredListSelector, Gtk.Grid):
#     # The subclassing here is weird; the Selector must directly
#     # subclass Gtk.Grid, or the template building explodes.
# 
#     __gtype_name__ = 'EncodingSelector'
# 
#     __gsignals__ = {
#         'encoding-selected': (
#             GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION,
#             None, (GtkSource.Encoding,)),
#     }
# 
#     # These exist solely to make subclassing easier.
#     value_accessor = 'get_charset'
#     change_signal_name = 'encoding-selected'
# 
#     entry = Gtk.Template.Child('entry')
#     treeview = Gtk.Template.Child('treeview')
# 
#     def populate_model(self):
#         for enc in GtkSource.Encoding.get_all():
#             self.liststore.append((self.get_value_label(enc), enc))
# 
#     def get_value_label(self, enc):
#         return _('{name} ({charset})').format(
#             name=enc.get_name(), charset=enc.get_charset())
# 
# class SourceLangSelector(FilteredListSelector, Gtk.Grid):
# 
#     __gtype_name__ = "SourceLangSelector"
# 
#     __gsignals__ = {
#         'language-selected': (
#             GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION,
#             None, (GtkSource.Language,)),
#     }
# 
#     # These exist solely to make subclassing easier.
#     value_accessor = 'get_id'
#     change_signal_name = 'language-selected'
# 
#     entry = Gtk.Template.Child('entry')
#     treeview = Gtk.Template.Child('treeview')
# 
#     def populate_model(self):
#         self.liststore.append((_("Plain Text"), None))
#         manager = GtkSource.LanguageManager.get_default()
#         for lang_id in manager.get_language_ids():
#             lang = manager.get_language(lang_id)
#             self.liststore.append((lang.get_name(), lang))
# 
#     def get_value_label(self, lang):
#         if not lang:
#             return _("Plain Text")
#         return lang.get_name()


# Path: meld/ui/statusbar.py
from gi.repository import GObject, Gtk, GtkSource, Pango
from meld.conf import _
from meld.ui.bufferselectors import EncodingSelector, SourceLangSelector

        pop = Gtk.Popover()
        pop.set_position(Gtk.PositionType.TOP)
        pop.add(selector)

        def format_cursor_position(binding, cursor):
            line, offset = cursor
            return self._line_column_text.format(
                line=line + 1, column=offset + 1)

        button = MeldStatusMenuButton()
        self.bind_property(
            'cursor_position', button, 'label', GObject.BindingFlags.DEFAULT,
            format_cursor_position)
        self.connect('start-go-to-line', lambda *args: button.clicked())
        button.set_popover(pop)
        # Set a label width to avoid other widgets moving on cursor change
        reasonable_width = len(format_cursor_position(None, (1000, 100))) - 2
        button.set_label_width(reasonable_width)
        button.show()

        return button

    def construct_encoding_selector(self):
        def change_encoding(selector, encoding):
            self.emit('encoding-changed', encoding)
            pop.hide()

        def set_initial_encoding(selector):
            selector.select_value(self.props.source_encoding)


        selector = EncodingSelector()