📄 meldapp.py
字号:
idx = self.editor_command.index(radio) for k,v in self.editor_radio_values.items(): if v == idx: self.prefs.edit_command_type = k break # # display # def on_draw_style_toggled(self, radio): if radio.get_active(): self.prefs.draw_style = self.draw_style.index(radio) def on_toolbar_style_toggled(self, radio): if radio.get_active(): self.prefs.toolbar_style = self.toolbar_style.index(radio) # # filters # def on_checkbutton_ignore_symlinks_toggled(self, check): self.prefs.ignore_symlinks = check.get_active() def on_checkbutton_ignore_blank_lines_toggled(self, check): self.prefs.ignore_blank_lines = check.get_active() # # encoding # def on_save_encoding_toggled(self, radio): if radio.get_active(): self.prefs.save_encoding = self.save_encoding.index(radio) def on_response(self, dialog, arg): if arg==gtk.RESPONSE_CLOSE: self.prefs.text_codecs = self.entry_text_codecs.get_property("text") self.prefs.edit_command_custom = self.custom_edit_command_entry.get_property("text") self.widget.destroy()################################################################################## MeldStatusBar#################################################################################class MeldStatusBar(object): def __init__(self, task_progress, task_status, doc_status): self.task_progress = task_progress self.task_status = task_status self.doc_status = doc_status def set_task_status(self, status): self.task_status.pop(1) self.task_status.push(1, status) def set_doc_status(self, status): self.doc_status.pop(1) self.doc_status.push(1, status)################################################################################## NotebookLabel#################################################################################class NotebookLabel(gtk.HBox): tab_width_in_chars = 30 def __init__(self, iconname, text, onclose): gtk.HBox.__init__(self, False, 4) label = gtk.Label(text) # FIXME: ideally, we would use custom ellipsization that ellipsized the # two paths separately, but that requires significant changes to label # generation in many different parts of the code label.set_ellipsize(pango.ELLIPSIZE_MIDDLE); label.set_single_line_mode(True) label.set_alignment(0.0, 0.5) label.set_padding(0, 0) context = self.get_pango_context() metrics = context.get_metrics(self.style.font_desc, context.get_language()) char_width = metrics.get_approximate_digit_width() (w, h) = gtk.icon_size_lookup_for_settings (self.get_settings(), gtk.ICON_SIZE_MENU) self.set_size_request(self.tab_width_in_chars * pango.PIXELS(char_width) + 2 * w, -1) button = gtk.Button() button.set_relief(gtk.RELIEF_NONE) button.set_focus_on_click(False) image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image.set_tooltip_text(_("Close tab")) button.add(image) button.set_name("meld-tab-close-button") button.set_size_request(w + 2, h + 2) button.connect("clicked", onclose) icon = gtk.Image() icon.set_from_file( paths.share_dir("glade2/pixmaps/%s" % iconname) ) icon.set_from_pixbuf(icon.get_pixbuf().scale_simple(16, 16, 2)) #TODO stock image self.pack_start(icon, expand=False) self.pack_start(label) self.pack_start(button, expand=False) self.set_tooltip_text(text) self.show_all() self.__label = label def get_label_text(self): return self.__label.get_text() def set_label_text(self, text): self.__label.set_text(text) self.set_tooltip_text(text)################################################################################## MeldPreferences#################################################################################class MeldPreferences(prefs.Preferences): defaults = { "window_size_x": prefs.Value(prefs.INT, 600), "window_size_y": prefs.Value(prefs.INT, 600), "use_custom_font": prefs.Value(prefs.BOOL,0), "custom_font": prefs.Value(prefs.STRING,"monospace, 14"), "tab_size": prefs.Value(prefs.INT, 4), "show_line_numbers": prefs.Value(prefs.BOOL, 0), "use_syntax_highlighting": prefs.Value(prefs.BOOL, 0), "edit_wrap_lines" : prefs.Value(prefs.INT, 0), "edit_command_type" : prefs.Value(prefs.STRING, "internal"), #internal, gnome, custom "edit_command_custom" : prefs.Value(prefs.STRING, "gedit"), "supply_newline": prefs.Value(prefs.BOOL,1), "text_codecs": prefs.Value(prefs.STRING, "utf8 latin1"), "save_encoding": prefs.Value(prefs.INT, 0), "draw_style": prefs.Value(prefs.INT,2), "toolbar_style": prefs.Value(prefs.INT,0), "ignore_symlinks": prefs.Value(prefs.BOOL,0), "vc_console_visible": prefs.Value(prefs.BOOL, 0), "color_delete_bg" : prefs.Value(prefs.STRING, "DarkSeaGreen1"), "color_delete_fg" : prefs.Value(prefs.STRING, "Red"), "color_replace_bg" : prefs.Value(prefs.STRING, "#ddeeff"), "color_replace_fg" : prefs.Value(prefs.STRING, "Black"), "color_conflict_bg" : prefs.Value(prefs.STRING, "Pink"), "color_conflict_fg" : prefs.Value(prefs.STRING, "Black"), "color_inline_bg" : prefs.Value(prefs.STRING, "LightSteelBlue2"), "color_inline_fg" : prefs.Value(prefs.STRING, "Red"), "color_edited_bg" : prefs.Value(prefs.STRING, "gray90"), "color_edited_fg" : prefs.Value(prefs.STRING, "Black"), "filters" : prefs.Value(prefs.STRING, #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("Backups\t1\t#*# .#* ~* *~ *.{orig,bak,swp}\n") + \ #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("Version Control\t1\tCVS .svn MT [{]arch[}] .arch-ids .arch-inventory RCS\n") + \ #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("Binaries\t1\t*.{pyc,a,obj,o,so,la,lib,dll}\n") + \ #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("Media\t0\t*.{jpg,gif,png,wav,mp3,ogg,xcf,xpm}")), #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact "regexes" : prefs.Value(prefs.STRING, _("CVS keywords\t0\t\$\\w+(:[^\\n$]+)?\$\n") + \ #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("C++ comment\t0\t//.*\n") + \ #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("C comment\t0\t/\*.*?\*/\n") + \ #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("All whitespace\t0\t[ \\t\\r\\f\\v]*\n") + \ #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("Leading whitespace\t0\t^[ \\t\\r\\f\\v]*\n") + \ #TRANSLATORS: translate this string ONLY to the first "\t", leave it and the following parts intact _("Script comment\t0\t#.*")), "ignore_blank_lines" : prefs.Value(prefs.BOOL, 1) } def __init__(self): prefs.Preferences.__init__(self, "/apps/meld", self.defaults) def get_current_font(self): if self.use_custom_font: return self.custom_font else: return self._gconf.get_string('/desktop/gnome/interface/monospace_font_name') or "Monospace 10" def get_toolbar_style(self): if self.toolbar_style == 0: style = self._gconf.get_string('/desktop/gnome/interface/toolbar_style') or "both" style = style.replace("-","_") style = {"both":gtk.TOOLBAR_BOTH, "text":gtk.TOOLBAR_TEXT, "icon":gtk.TOOLBAR_ICONS, "icons":gtk.TOOLBAR_ICONS, "both_horiz":gtk.TOOLBAR_BOTH_HORIZ, "both-horiz":gtk.TOOLBAR_BOTH_HORIZ }[style] else: style = self.toolbar_style - 1 return style def get_gnome_editor_command(self, files): argv = [] editor = self._gconf.get_string('/desktop/gnome/applications/editor/exec') or "gedit" if self._gconf.get_bool("/desktop/gnome/applications/editor/needs_term"): texec = self._gconf.get_string("/desktop/gnome/applications/terminal/exec") if texec: argv.append(texec) targ = self._gconf.get_string("/desktop/gnome/applications/terminal/exec_arg") if targ: argv.append(targ) argv.append( "%s %s" % (editor, " ".join( [f.replace(" ","\\ ") for f in files]) ) ) else: argv = [editor] + files return argv def get_custom_editor_command(self, files): return self.edit_command_custom.split() + files################################################################################## MeldApp#################################################################################class MeldApp(gnomeglade.GnomeApp): # # init # def __init__(self): gtk.rc_parse_string ("style \"meld-tab-close-button-style\"\n" "{\n" "GtkWidget::focus-padding = 0\n" "GtkWidget::focus-line-width = 0\n" "xthickness = 0\n" "ythickness = 0\n" "}\n" "widget \"*.meld-tab-close-button\" style \"meld-tab-close-button-style\"") gladefile = paths.share_dir("glade2/meldapp.glade") gnomeglade.GnomeApp.__init__(self, "meld", version, gladefile, "meldapp") self._map_widgets_into_lists( "settings_drawstyle".split() ) self.statusbar = MeldStatusBar(self.task_progress, self.task_status, self.doc_status) self.prefs = MeldPreferences() if not developer:#hide magic testing button self.toolbar_magic.hide() elif 1: def showPrefs(): PreferencesDialog(self) gobject.idle_add(showPrefs) self.toolbar.set_style( self.prefs.get_toolbar_style() ) self.prefs.notify_add(self.on_preference_changed) self.idle_hooked = 0 self.scheduler = task.LifoScheduler() self.scheduler.connect("runnable", self.on_scheduler_runnable ) self.widget.set_default_size(self.prefs.window_size_x, self.prefs.window_size_y) self.widget.show() def on_idle(self): ret = self.scheduler.iteration() if ret: if type(ret) in (type(""), type(u"")): self.statusbar.set_task_status(ret) elif type(ret) == type(0.0): self.statusbar.task_progress.set_fraction(ret) else: self.statusbar.task_progress.pulse() else: self.statusbar.task_progress.set_fraction(0) if self.scheduler.tasks_pending(): self.toolbar_stop.set_sensitive(1) self.menu_view_stop.set_sensitive(1) return 1 else: self.statusbar.set_task_status("") self.idle_hooked = 0 self.toolbar_stop.set_sensitive(0) self.menu_view_stop.set_sensitive(0) return 0 def on_scheduler_runnable(self, sched): if not self.idle_hooked: self.idle_hooked = 1 gobject.idle_add( self.on_idle ) def on_preference_changed(self, key, value): if key == "toolbar_style": self.toolbar.set_style( self.prefs.get_toolbar_style() ) # # General events and callbacks # def on_delete_event(self, *extra): return self.on_menu_quit_activate() def on_switch_page(self, notebook, page, which): newdoc = notebook.get_nth_page(which).get_data("pyobject") newseq = newdoc.undosequence self.button_undo.set_sensitive(newseq.can_undo()) self.button_redo.set_sensitive(newseq.can_redo()) nbl = self.notebook.get_tab_label( newdoc.widget ) self.widget.set_title(nbl.get_label_text() + " - Meld") self.statusbar.set_doc_status("") newdoc.on_switch_event() self.scheduler.add_task( newdoc.scheduler ) def on_notebook_label_changed(self, component, text):
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -