def update_cursor(self, *args): doc = self.geditwindow.get_active_document() if doc and self.parser: it = doc.get_iter_at_mark(doc.get_insert()) line = it.get_line() if line != self.previousline: self.previousline = line if options.singleton().verbose: print "current line:", line # pipe the current line to the parser self.parser.current_line_changed(self.browser.get_model(), doc, line) # set cursor on the tag the cursor is pointing to try: path = self.parser.get_tag_at_line( self.browser.get_model(), doc, line) if path: self.browser.realize() if options.singleton().autocollapse: self.browser.collapse_all() self.browser.expand_to_path(path) self.browser.set_cursor(path) if options.singleton().verbose: print "jump to", path except Exception, e: if options.singleton().verbose: print "no tag at line", line
def cellrenderer(self, column, ctr, model, it): """ Render the browser cell according to the token it represents. """ tok = model.get_value(it, 0) name = tok.name colour = options.singleton().colours["function"] if tok.type == "class": name = "class " + tok.name colour = options.singleton().colours["class"] ctr.set_property("text", name) ctr.set_property("foreground-gdk", colour)
def cellrenderer(self, column, ctr, model, it): """ Render the browser cell according to the token it represents. """ tok = model.get_value(it,0) name = tok.name colour = options.singleton().colours[ "function" ] if tok.type == "class": name = "class "+tok.name colour = options.singleton().colours[ "class" ] ctr.set_property("text", name) ctr.set_property("foreground-gdk", colour)
def __onClick(self, treeview, event): if event.button == 2: if options.singleton().jumpToTagOnMiddleClick: x, y = int(event.x), int(event.y) pthinfo = treeview.get_path_at_pos(x, y) if pthinfo is None: return path, col, cellx, celly = pthinfo self.__jump_to_tag(path) return True if event.button == 3: x, y = int(event.x), int(event.y) pthinfo = treeview.get_path_at_pos(x, y) if pthinfo is None: return path, col, cellx, celly = pthinfo #treeview.grab_focus() #treeview.set_cursor(path) menu = gtk.Menu() tagpos = self.parser.get_tag_position(self.browser.get_model(), path) if tagpos is not None: filename, line = tagpos m = gtk.ImageMenuItem(gtk.STOCK_JUMP_TO) menu.append(m) m.show() m.connect("activate", lambda w, p, l: self.__openDocumentAtLine(p, l), filename, line) # add the menu items from the parser menuitems = self.parser.get_menu(self.browser.get_model(), path) for item in menuitems: menu.append(item) item.show() m = gtk.SeparatorMenuItem() m.show() menu.append(m) m = gtk.CheckMenuItem("autocollapse") menu.append(m) m.show() m.set_active(options.singleton().autocollapse) def setcollapse(w): options.singleton().autocollapse = w.get_active() m.connect("toggled", setcollapse) menu.popup(None, None, None, event.button, event.time)
def cellrenderer(self, treeviewcolumn, cellrenderertext, treemodel, it): token = treemodel.get_value(it, 0) colour = options.singleton().colours["member"] if token.type == "path": colour = options.singleton().colours["namespace"] elif token.type == "file": colour = options.singleton().colours["class"] cellrenderertext.set_property("text", token.name) cellrenderertext.set_property("style", pango.STYLE_NORMAL) cellrenderertext.set_property("foreground-gdk", colour)
def cellrenderer(self, treeviewcolumn, cellrenderertext, treemodel, it): token = treemodel.get_value(it,0) colour = options.singleton().colours["member"] if token.type == 'path': colour = options.singleton().colours["namespace"] elif token.type == 'file': colour = options.singleton().colours["class"] cellrenderertext.set_property("text", token.name) cellrenderertext.set_property("style", pango.STYLE_NORMAL) cellrenderertext.set_property("foreground-gdk", colour)
def jump_to_tag(self, direction=1): #use self dince python doesn't have true closures, yuck! self.iter_target = None self.iter_next = None self.iter_found = False def get_previous(model, path, iter, path_searched): if path_searched is None: self.iter_found = True self.iter_target = model.get_iter_root() if path == path_searched: self.iter_found = True #if we are at the beginning of the tree if self.iter_target is None: self.iter_target = model.get_iter_root() return True self.iter_target = iter return False def get_next(model, path, iter, path_searched): if path_searched is None: self.iter_found = True self.iter_target = model.get_iter_root() if self.iter_found: self.iter_target = iter return True if path == path_searched: self.iter_found = True return False search_funcs = get_previous, get_next if (0 > direction) or (len(search_funcs) <= direction): print "Direction ", direction, " must be between 0 and ", len( search_funcs) raise ValueError, "Invalid direction" model = self.browser.get_model() iter, path = self.get_current_iter() model.foreach(search_funcs[direction], path) if not self.iter_found or not self.iter_target: if options.singleton().verbose: print "No target path" return target_path = model.get_path(self.iter_target) tagpos = self.parser.get_tag_position(model, target_path) if tagpos is not None: path, line = tagpos if options.singleton().verbose: print "jump to", path self.__openDocumentAtLine(path, line)
def __onClick(self, treeview, event): if event.button == 2: if options.singleton().jumpToTagOnMiddleClick: x, y = int(event.x), int(event.y) pthinfo = treeview.get_path_at_pos(x, y) if pthinfo is None: return path, col, cellx, celly = pthinfo self.__jump_to_tag(path) return True if event.button == 3: x, y = int(event.x), int(event.y) pthinfo = treeview.get_path_at_pos(x, y) if pthinfo is None: return path, col, cellx, celly = pthinfo #treeview.grab_focus() #treeview.set_cursor(path) menu = gtk.Menu() tagpos = self.parser.get_tag_position(self.browser.get_model(),path) if tagpos is not None: filename, line = tagpos m = gtk.ImageMenuItem(gtk.STOCK_JUMP_TO) menu.append(m) m.show() m.connect("activate", lambda w,p,l: self.__openDocumentAtLine(p,l), filename, line ) # add the menu items from the parser menuitems = self.parser.get_menu(self.browser.get_model(),path) for item in menuitems: menu.append(item) item.show() m = gtk.SeparatorMenuItem() m.show() menu.append( m ) m = gtk.CheckMenuItem("autocollapse") menu.append(m) m.show() m.set_active( options.singleton().autocollapse ) def setcollapse(w): options.singleton().autocollapse = w.get_active() m.connect("toggled", setcollapse ) menu.popup( None, None, None, event.button, event.time)
def jump_to_tag(self, direction = 1): #use self dince python doesn't have true closures, yuck! self.iter_target = None self.iter_next = None self.iter_found = False def get_previous(model, path, iter, path_searched): if path_searched is None: self.iter_found = True self.iter_target = model.get_iter_root() if path == path_searched: self.iter_found = True #if we are at the beginning of the tree if self.iter_target is None: self.iter_target = model.get_iter_root() return True self.iter_target = iter return False def get_next(model,path, iter, path_searched): if path_searched is None: self.iter_found = True self.iter_target = model.get_iter_root() if self.iter_found: self.iter_target = iter return True if path == path_searched: self.iter_found = True return False search_funcs = get_previous, get_next if ( 0 > direction) or (len(search_funcs) <= direction): print "Direction ", direction, " must be between 0 and ", len(search_funcs) raise ValueError, "Invalid direction" model = self.browser.get_model() iter, path = self.get_current_iter() model.foreach(search_funcs[direction], path) if not self.iter_found or not self.iter_target: if options.singleton().verbose: print "No target path" return target_path = model.get_path(self.iter_target) tagpos = self.parser.get_tag_position(model, target_path) if tagpos is not None: path, line = tagpos if options.singleton().verbose: print "jump to", path self.__openDocumentAtLine(path,line)
def parse(self, doc): # on first parse set autoexpandable setting if not self.initializedExpandAll: if options.singleton(): options.singleton().autocollapse = False # the next calls should behave inline with user's settings self.initializedExpandAll = True text = doc.get_text(*doc.get_bounds()) # create top level node that is required by tree root = Token("root") parent = self.__get_toplevel_package(root, text, doc.get_uri()) self.__get_tokens(parent, text, doc.get_uri()) self.__browsermodel = gtk.TreeStore(gobject.TYPE_PYOBJECT) for child in root.children: self.__appendTokenToBrowser(child,None) return self.__browsermodel
def parse(self, d): parser = customParser() try: parser.feed(d.get_text(*d.get_bounds())) except HTMLParseError, e: if options.singleton().verbose: print e, e.lineno, e.offset
def parse(self, doc): # on first parse set autoexpandable setting if not self.initializedExpandAll: if options.singleton(): options.singleton().autocollapse = False # the next calls should behave inline with user's settings self.initializedExpandAll = True text = doc.get_text(*doc.get_bounds()) # create top level node that is required by tree root = Token("root") parent = self.__get_toplevel_package(root, text, doc.get_uri()) self.__get_tokens(parent, text, doc.get_uri()) self.__browsermodel = gtk.TreeStore(gobject.TYPE_PYOBJECT) for child in root.children: self.__appendTokenToBrowser(child, None) return self.__browsermodel
def current_line_changed(self, model, doc, line): # parse again if line count changed if abs(self.rubyfile.linestotal - doc.get_line_count()) > 0: if abs(self.rubyfile.linestotal - doc.get_line_count()) > 5: if options.singleton().verbose: print "RubyParser: refresh because line dif > 5" self.rubyfile.parse() else: it = doc.get_iter_at_line(line) a = it.copy(); b = it.copy() a.backward_line(); a.backward_line() b.forward_line(); b.forward_line() t = doc.get_text(a,b) if t.find("class") >= 0 or t.find("def") >= 0: if options.singleton().verbose: print "RubyParser: refresh because line cound changed near keyword" self.rubyfile.parse()
def current_line_changed(self, model, doc, line): # parse again if line count changed if abs(self.pythonfile.linestotal - doc.get_line_count()) > 0: if abs(self.pythonfile.linestotal - doc.get_line_count()) > 5: if options.singleton().verbose: print "PythonParser: refresh because line dif > 5" self.pythonfile.parse() else: it = doc.get_iter_at_line(line) a = it.copy(); b = it.copy() a.backward_line(); a.backward_line() b.forward_line(); b.forward_line() t = doc.get_text(a,b) if t.find("class") >= 0 or t.find("def") >= 0: if options.singleton().verbose: print "PythonParser: refresh because line cound changed near keyword" self.pythonfile.parse()
def __register(self, doc, tab): if doc is None: return uri = doc.get_uri() if uri in self.openfiles: return self.openfiles.append(uri) tab.get_view().connect_after("notify",self.browser.on_cursor_changed) tab.get_view().connect_after("move-cursor",self.browser.update_cursor) #doc.set_modified(True) doc.connect("modified-changed",self.__update) if options.singleton().verbose: print "added:",uri
def __register(self, doc, tab): if doc is None: return uri = doc.get_uri() if uri in self.openfiles: return self.openfiles.append(uri) tab.get_view().connect_after("notify", self.browser.on_cursor_changed) tab.get_view().connect_after("move-cursor", self.browser.update_cursor) #doc.set_modified(True) doc.connect("modified-changed", self.__update) if options.singleton().verbose: print "added:", uri
def set_model(self, treemodel, parser=None): """ set the gtk.TreeModel that contains the current class tree. parser must be an instance of a subclass of ClassParserInterface. """ self.browser.set_model(treemodel) if parser: self.column.set_cell_data_func(self.crt, parser.cellrenderer) self.column.set_cell_data_func(self.cellrendererpixbuf, parser.pixbufrenderer) self.parser = parser # after setting new model either expand or collapse the treee if options.singleton().autocollapse == False: self.browser.expand_all() self.browser.queue_draw()
def update_cursor(self, *args): doc = self.geditwindow.get_active_document() if doc and self.parser: it = doc.get_iter_at_mark(doc.get_insert()) line = it.get_line() if line != self.previousline: self.previousline = line if options.singleton().verbose: print "current line:",line # pipe the current line to the parser self.parser.current_line_changed(doc, line) # set cursor on the tag the cursor is pointing to try: path = self.parser.get_tag_at_line(self.browser.get_model(),doc,line) if path: self.browser.realize() self.browser.expand_to_path(path) self.browser.set_cursor(path) if options.singleton().verbose: print "jump to", path except Exception, e: if options.singleton().verbose: print "no tag at line",line
def parse(self, doc): """ Create a gtk.TreeModel with the class elements of the document The parser uses the ctags command from the shell to create a ctags file, then parses the file, and finally populates a treemodel. """ self.rubyfile = RubyFile(doc) self.rubyfile.parse(options.singleton().verbose) self.__browsermodel = gtk.TreeStore(gobject.TYPE_PYOBJECT) for child in self.rubyfile.children: self.appendTokenToBrowser(child, None) return self.__browsermodel
def cellrenderer(self, column, ctr, model, it): i = model.get_value(it,0) ctr.set_property("text", i) elements = { "c":"class", "f":"function", "m":"member", "e":"enumerator", "d":"define", } i = model.get_value(it,3) try: colour = options.singleton().colours[ elements[i] ] except: colour = gtk.gdk.Color(0,0,0) ctr.set_property("foreground-gdk", colour)
def parse(self, doc): """ Create a gtk.TreeModel with the class elements of the document The parser uses the ctags command from the shell to create a ctags file, then parses the file, and finally populates a treemodel. """ self.rubyfile = RubyFile(doc) self.rubyfile.parse(options.singleton().verbose) self.__browsermodel = gtk.TreeStore(gobject.TYPE_PYOBJECT) for child in self.rubyfile.children: self.appendTokenToBrowser(child,None) return self.__browsermodel
def cellrenderer(self, column, ctr, model, it): """ Render the browser cell according to the token it represents. """ tok = model.get_value(it, 0) weight = 400 style = pango.STYLE_NORMAL name = tok.name #+tok.params colour = options.singleton().colours["function"] # set label and colour if tok.type == "class": name = "class " + name + tok.params colour = options.singleton().colours["class"] weight = 600 if tok.comment: name = "#" + name if tok.parent: if tok.parent.type == "class": colour = options.singleton().colours["member"] # assing properties ctr.set_property("text", name) ctr.set_property("style", style) ctr.set_property("foreground-gdk", colour)
def handle_starttag(self, tag, attrs): # construct tagstring tagstring = "<"+tag for name, value in attrs: if name in ["id","name"]: # append only certain attributes tagstring += " %s=%s"%(name,value) tagstring += ">" #print tagstring lineno, offset = self.getpos() it = self.ls.append( self.currenttag,(tag,tagstring,lineno,0) ) if options.singleton().verbose: print (tag,tagstring,lineno,0) self.currenttag = it
def cellrenderer(self, column, ctr, model, it): """ Render the browser cell according to the token it represents. """ tok = model.get_value(it,0) weight = 400 style = pango.STYLE_NORMAL name = tok.name#+tok.params colour = options.singleton().colours[ "function" ] # set label and colour if tok.type == "class": name = "class "+name+tok.params colour = options.singleton().colours[ "class" ] weight = 600 if tok.comment: name = "#"+name if tok.parent: if tok.parent.type == "class": colour = options.singleton().colours[ "member" ] # assing properties ctr.set_property("text", name) ctr.set_property("style", style) ctr.set_property("foreground-gdk", colour)
def handle_starttag(self, tag, attrs): # construct tagstring tagstring = "<" + tag for name, value in attrs: if name in ["id", "name"]: # append only certain attributes tagstring += " %s=%s" % (name, value) tagstring += ">" #print tagstring lineno, offset = self.getpos() it = self.ls.append(self.currenttag, (tag, tagstring, lineno, 0)) if options.singleton().verbose: print(tag, tagstring, lineno, 0) self.currenttag = it
def cellrenderer(self, column, ctr, model, it): i = model.get_value(it, 0) ctr.set_property("text", i) elements = { "c": "class", "f": "function", "m": "member", "e": "enumerator", "d": "define", } i = model.get_value(it, 3) try: colour = options.singleton().colours[elements[i]] except: colour = gtk.gdk.Color(0, 0, 0) ctr.set_property("foreground-gdk", colour)
def __update(self, *args): doc = self.plumawindow.get_active_document() if doc: lang = doc.get_language() parser = self.defaultparser if lang: m = lang.get_name() if m in self.languageParsers: parser = self.languageParsers[m] if options.singleton().verbose: print "parse %s (%s)"%(doc.get_uri(),parser.__class__.__name__) model = parser.parse(doc) self.browser.set_model(model, parser) self.currentDoc = doc else: self.browser.set_model(None)
def __update(self, *args): doc = self.geditwindow.get_active_document() if doc: lang = doc.get_language() parser = self.defaultparser if lang: m = lang.get_name() if m in self.languageParsers: parser = self.languageParsers[m] if options.singleton().verbose: print "parse %s (%s)"%(doc.get_uri(),parser.__class__.__name__) model = parser.parse(doc) self.browser.set_model(model, parser) self.currentDoc = doc else: self.browser.set_model(None)
def setcollapse(w): options.singleton().autocollapse = w.get_active()
def create_configure_dialog(self): return options.singleton().create_configure_dialog()