Ejemplo n.º 1
0
Archivo: manager.py Proyecto: onia/pygi
    def do_parser_finished(self, builder):
        self.builder = builder

        handlers_dic = {
            'on_action_new_snippet_activated':
            self.on_action_new_snippet_activated,
            'on_action_remove_snippet_activated':
            self.on_action_remove_snippet_activated,
            'on_action_import_snippets_activated':
            self.on_action_import_snippets_activated,
            'on_action_export_snippets_activated':
            self.on_action_export_snippets_activated,
            'on_entry_tab_trigger_focus_out':
            self.on_entry_tab_trigger_focus_out,
            'on_entry_tab_trigger_changed': self.on_entry_tab_trigger_changed,
            'on_entry_accelerator_focus_out':
            self.on_entry_accelerator_focus_out,
            'on_entry_accelerator_focus_in':
            self.on_entry_accelerator_focus_in,
            'on_entry_accelerator_key_press':
            self.on_entry_accelerator_key_press,
            'on_source_view_snippet_focus_out':
            self.on_source_view_snippet_focus_out,
            'on_tree_view_snippets_row_expanded':
            self.on_tree_view_snippets_row_expanded,
            'on_tree_view_snippets_key_press':
            self.on_tree_view_snippets_key_press
        }

        self.builder.connect_signals(handlers_dic)

        self.build_tree_view()
        self.build_model()

        # join treeview and toolbar
        context = self['scrolled_window_snippets'].get_style_context()
        context.set_junction_sides(Gtk.JunctionSides.BOTTOM)
        context = self['toolbar'].get_style_context()
        context.set_junction_sides(Gtk.JunctionSides.TOP)

        source_view = self['source_view_snippet']
        manager = get_language_manager()
        lang = manager.get_language('snippets')

        if lang:
            source_view.get_buffer().set_highlight_syntax(True)
            source_view.get_buffer().set_language(lang)

        combo = self['combo_drop_targets']

        entry = combo.get_child()
        entry.connect('focus-out-event', self.on_entry_drop_targets_focus_out)
        entry.connect('drag-data-received',
                      self.on_entry_drop_targets_drag_data_received)

        lst = entry.drag_dest_get_target_list()
        lst.add_uri_targets(self.TARGET_URI)
Ejemplo n.º 2
0
        def do_get_info_widget(self, proposal):
                if not self.info_widget:
                        view = Gedit.View.new_with_buffer(Gedit.Document())
                        manager = get_language_manager()

                        lang = manager.get_language('snippets')
                        view.get_buffer().set_language(lang)

                        sw = Gtk.ScrolledWindow()
                        sw.add(view)

                        self.info_view = view
                        self.info_widget = sw

                return self.info_widget
Ejemplo n.º 3
0
        def do_parser_finished(self, builder):
                self.builder = builder

                handlers_dic = {
                        'on_action_new_snippet_activated': self.on_action_new_snippet_activated,
                        'on_action_remove_snippet_activated': self.on_action_remove_snippet_activated,
                        'on_action_import_snippets_activated': self.on_action_import_snippets_activated,
                        'on_action_export_snippets_activated': self.on_action_export_snippets_activated,
                        'on_entry_tab_trigger_focus_out': self.on_entry_tab_trigger_focus_out,
                        'on_entry_tab_trigger_changed': self.on_entry_tab_trigger_changed,
                        'on_entry_accelerator_focus_out': self.on_entry_accelerator_focus_out,
                        'on_entry_accelerator_focus_in': self.on_entry_accelerator_focus_in,
                        'on_entry_accelerator_key_press': self.on_entry_accelerator_key_press,
                        'on_source_view_snippet_focus_out': self.on_source_view_snippet_focus_out,
                        'on_tree_view_snippets_row_expanded': self.on_tree_view_snippets_row_expanded,
                        'on_tree_view_snippets_key_press': self.on_tree_view_snippets_key_press}

                self.builder.connect_signals(handlers_dic)

                self.build_tree_view()
                self.build_model()

                # join treeview and toolbar
                context = self['scrolled_window_snippets'].get_style_context()
                context.set_junction_sides(Gtk.JunctionSides.BOTTOM)
                context = self['toolbar'].get_style_context()
                context.set_junction_sides(Gtk.JunctionSides.TOP)

                source_view = self['source_view_snippet']
                manager = get_language_manager()
                lang = manager.get_language('snippets')

                if lang:
                        source_view.get_buffer().set_highlight_syntax(True)
                        source_view.get_buffer().set_language(lang)

                combo = self['combo_drop_targets']

                entry = combo.get_child()
                entry.connect('focus-out-event', self.on_entry_drop_targets_focus_out)
                entry.connect('drag-data-received', self.on_entry_drop_targets_drag_data_received)

                lst = entry.drag_dest_get_target_list()
                lst.add_uri_targets(self.TARGET_URI)
Ejemplo n.º 4
0
        def build_model(self, force_reload = False):
                window = Gedit.App.get_default().get_active_window()

                if window:
                        view = window.get_active_view()

                        if not view:
                                current_lang = None
                        else:
                                current_lang = view.get_buffer().get_language()
                                source_view = self['source_view_snippet']

                else:
                        current_lang = None

                tree_view = self['tree_view_snippets']
                expand = None

                if not self.model or force_reload:
                        self.model = Gtk.TreeStore(str, str, GObject.Object, object)
                        self.model.set_sort_column_id(self.SORT_COLUMN, Gtk.SortType.ASCENDING)

                        manager = get_language_manager()

                        langs = [manager.get_language(x) for x in manager.get_language_ids()]
                        langs.sort(key=lambda x: x.get_name())

                        piter = self.model.append(None, (_('Global'), '', None, None))

                        # Add dummy node
                        self.model.append(piter, ('', '', None, None))

                        nm = None

                        if current_lang:
                                nm = current_lang.get_name()

                        for lang in langs:
                                name = lang.get_name()
                                parent = self.model.append(None, (name, name, lang, None))

                                # Add dummy node
                                self.model.append(parent, ('', '', None, None))

                                if (nm == name):
                                        expand = parent
                else:
                        if current_lang:
                                piter = self.model.get_iter_first()
                                nm = current_lang.get_name()

                                while piter:
                                        lang = self.model.get_value(piter, \
                                                        self.SORT_COLUMN)

                                        if lang == nm:
                                                expand = piter
                                                break;

                                        piter = self.model.iter_next(piter)

                tree_view.set_model(self.model)

                if not expand:
                        expand = self.model.get_iter_first()

                tree_view.expand_row(self.model.get_path(expand), False)
                self.select_iter(expand)
Ejemplo n.º 5
0
Archivo: manager.py Proyecto: onia/pygi
    def build_model(self, force_reload=False):
        window = Gedit.App.get_default().get_active_window()

        if window:
            view = window.get_active_view()

            if not view:
                current_lang = None
            else:
                current_lang = view.get_buffer().get_language()
                source_view = self['source_view_snippet']

        else:
            current_lang = None

        tree_view = self['tree_view_snippets']
        expand = None

        if not self.model or force_reload:
            self.model = Gtk.TreeStore(str, str, GObject.Object, object)
            self.model.set_sort_column_id(self.SORT_COLUMN,
                                          Gtk.SortType.ASCENDING)

            manager = get_language_manager()

            langs = [
                manager.get_language(x) for x in manager.get_language_ids()
            ]
            langs.sort(key=lambda x: x.get_name())

            piter = self.model.append(None, (_('Global'), '', None, None))

            # Add dummy node
            self.model.append(piter, ('', '', None, None))

            nm = None

            if current_lang:
                nm = current_lang.get_name()

            for lang in langs:
                name = lang.get_name()
                parent = self.model.append(None, (name, name, lang, None))

                # Add dummy node
                self.model.append(parent, ('', '', None, None))

                if (nm == name):
                    expand = parent
        else:
            if current_lang:
                piter = self.model.get_iter_first()
                nm = current_lang.get_name()

                while piter:
                    lang = self.model.get_value(piter, \
                                    self.SORT_COLUMN)

                    if lang == nm:
                        expand = piter
                        break

                    piter = self.model.iter_next(piter)

        tree_view.set_model(self.model)

        if not expand:
            expand = self.model.get_iter_first()

        tree_view.expand_row(self.model.get_path(expand), False)
        self.select_iter(expand)