def build(self): self.builder = gtk.Builder() self.builder.add_from_file(os.path.join(self.datadir, 'ui', 'snippets.ui')) handlers_dic = { 'on_dialog_snippets_response': self.on_dialog_snippets_response, 'on_dialog_snippets_destroy': self.on_dialog_snippets_destroy, 'on_button_new_snippet_clicked': self.on_button_new_snippet_clicked, 'on_button_import_snippets_clicked': self.on_button_import_snippets_clicked, 'on_button_export_snippets_clicked': self.on_button_export_snippets_clicked, 'on_button_remove_snippet_clicked': self.on_button_remove_snippet_clicked, '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() image = self['image_remove'] image.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_SMALL_TOOLBAR) 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) self.snippets_doc = Document(None, source_view) combo = self['combo_drop_targets'] combo.set_text_column(0) entry = combo.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 = gtk.target_list_add_uri_targets(entry.drag_dest_get_target_list(), self.TARGET_URI) entry.drag_dest_set_target_list(lst) self.dlg = self['dialog_snippets'] if self.default_size: self.dlg.set_default_size(*self.default_size)
def do_get_info_widget(self, proposal): if not self.info_widget: view = pluma.View(pluma.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
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, object) self.model.set_sort_column_id(self.SORT_COLUMN, gtk.SORT_ASCENDING) manager = get_language_manager() langs = gedit.language_manager_list_languages_sorted(manager, True) piter = self.model.append(None, (_('Global'), '', None)) # Add dummy node self.model.append(piter, ('', '', 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)) # Add dummy node self.model.append(parent, ('', '', 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_root() tree_view.expand_row(self.model.get_path(expand), False) self.select_iter(expand)
def build_model(self, force_reload = False): window = Pluma.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)
def build_model(self, force_reload=False): window = Pluma.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)