linux ubuntu下的merge小工具

  • A2_151692
    了解作者
  • 648.2KB
    文件大小
  • 文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-07 11:53
    上传日期
linux ubuntu下的merge对比小工具
80445562meld-1.1.4.tar.gz
内容介绍
### Copyright (C) 2002-2006 Stephen Kennedy <stevek@gnome.org> ### This program is free software; you can redistribute it and/or modify ### it under the terms of the GNU General Public License as published by ### the Free Software Foundation; either version 2 of the License, or ### (at your option) any later version. ### This program is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU General Public License for more details. ### You should have received a copy of the GNU General Public License ### along with this program; if not, write to the Free Software ### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from __future__ import generators import codecs import math import os import re import difflib import struct import pango import gobject import gtk import gtk.keysyms import diffutil import gnomeglade import misc import melddoc import paths sourceview_available = 0 for sourceview in "gtksourceview sourceview".split(): try: gsv = __import__(sourceview) sourceview_available = 1 break except ImportError: pass if sourceview_available: def set_highlighting_enabled(buf, fname, enabled): # gnome.vfs.get_mime_type seems to be broken. fake it. extmap = { "xml":"text/xml", "glade":"text/xml", "cpp":"text/x-cpp", "cxx":"text/x-cpp", "cc":"text/x-cpp", "C":"text/x-cpp", "c":"text/x-c", "hpp":"text/x-cpp", "hxx":"text/x-cpp", "hh":"text/x-cpp", "H":"text/x-cpp", "h":"text/x-cpp", "inl":"text/x-cpp", "desktop": "application/x-desktop", "diff": "text/x-diff", "patch": "text/x-diff", "html": "text/html", "po": "text/x-po", "py": "text/x-python" } ext = fname.split(".")[-1] man = gsv.SourceLanguagesManager() gsl = man.get_language_from_mime_type( extmap.get(ext, "text/plain") ) if gsl: buf.set_language(gsl) buf.set_highlight(enabled) gdk = gtk.gdk ################################################################################ # # FileDiff # ################################################################################ MASK_SHIFT, MASK_CTRL, MASK_ALT = 1, 2, 3 class FileDiff(melddoc.MeldDoc, gnomeglade.Component): """Two or three way diff of text files. """ keylookup = {gtk.keysyms.Shift_L : MASK_SHIFT, gtk.keysyms.Control_L : MASK_CTRL, gtk.keysyms.Alt_L : MASK_ALT, gtk.keysyms.Shift_R : MASK_SHIFT, gtk.keysyms.Control_R : MASK_CTRL, gtk.keysyms.Alt_R : MASK_ALT } def __init__(self, prefs, num_panes): """Start up an filediff with num_panes empty contents. """ melddoc.MeldDoc.__init__(self, prefs) override = {} if sourceview_available: override["GtkTextView"] = gsv.SourceView override["GtkTextBuffer"] = gsv.SourceBuffer gnomeglade.Component.__init__(self, paths.share_dir("glade2/filediff.glade"), "filediff", override) self._map_widgets_into_lists( ["textview", "fileentry", "diffmap", "scrolledwindow", "linkmap", "statusimage"] ) self._update_regexes() self.warned_bad_comparison = False if sourceview_available: for v in self.textview: v.set_buffer( gsv.SourceBuffer() ) v.set_show_line_numbers(self.prefs.show_line_numbers) self.keymask = 0 self.load_font() self.deleted_lines_pending = -1 self.textview_overwrite = 0 self.textview_focussed = None self.textview_overwrite_handlers = [ t.connect("toggle-overwrite", self.on_textview_toggle_overwrite) for t in self.textview ] for i in range(3): w = self.scrolledwindow[i] w.get_vadjustment().connect("value-changed", self._sync_vscroll ) w.get_hadjustment().connect("value-changed", self._sync_hscroll ) self._connect_buffer_handlers() self.linediffer = diffutil.Differ() for l in self.linkmap: # glade bug workaround l.set_events(gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK ) l.set_double_buffered(0) # we call paint_begin ourselves self.bufferdata = [] for text in self.textview: text.set_wrap_mode( self.prefs.edit_wrap_lines ) buf = text.get_buffer() self.bufferdata.append( MeldBufferData() ) def add_tag(name, props): tag = buf.create_tag(name) for p,v in props.items(): tag.set_property(p,v) add_tag("edited line", {"background": self.prefs.color_edited_bg, "foreground": self.prefs.color_edited_fg} ) add_tag("delete line", {"background": self.prefs.color_delete_bg, "foreground": self.prefs.color_delete_fg} ) add_tag("replace line", {"background": self.prefs.color_replace_bg, "foreground": self.prefs.color_replace_fg} ) add_tag("conflict line", {"background": self.prefs.color_conflict_bg, "foreground": self.prefs.color_conflict_fg} ) add_tag("inline line", {"background": self.prefs.color_inline_bg, "foreground": self.prefs.color_inline_fg} ) class ContextMenu(gnomeglade.Component): def __init__(self, app): gladefile = paths.share_dir("glade2/filediff.glade") gnomeglade.Component.__init__(self, gladefile, "popup") self.parent = app self.pane = -1 def popup_in_pane( self, pane ): self.pane = pane self.copy_left.set_sensitive( pane > 0 ) self.copy_right.set_sensitive( pane+1 < self.parent.num_panes ) self.widget.popup( None, None, None, 3, gtk.get_current_event_time() ) def on_save_activate(self, menuitem): self.parent.save() def on_save_as_activate(self, menuitem): self.parent.save_file( self.pane, 1) def on_make_patch_activate(self, menuitem): self.parent.make_patch( self.pane ) def on_cut_activate(self, menuitem): self.parent.on_cut_activate() def on_copy_activate(self, menuitem): self.parent.on_copy_activate() def on_paste_activate(self, menuitem): self.parent.on_paste_activate() def on_copy_left_activate(self, menuitem): self.parent.copy_selected(-1) def on_copy_right_activate(self, menuitem): self.parent.copy_selected(1) def on_edit_activate(self, menuitem): if self.parent.bufferdata[self.pane].filename: self.parent._edit_files( [self.parent.bufferdata[self.pane].filename] ) self.popup_menu = ContextMenu(self) self.find_dialog = None self.last_search = None self.set_num_panes(num_panes) gtk.idle_add( lambda *args: self.load_font()) # hack around Bug 316730 def _update_regexes(self): self.regexes = [] for r in [ misc.ListItem(i) for i in self.prefs.regexes.split("\n") ]: if r.active: try: self.regexes.append( (re.compile(r.value+"(?m)"), r.value) ) except re.error: pass def _disc
评论
    相关推荐