Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit b3309e495114ae94e07c5b12576d7f46ea503e15 0 parents
@nagaozen authored
Showing with 586 additions and 0 deletions.
  1. +9 −0 codebrowser.gedit-plugin
  2. +123 −0 codebrowser/__init__.py
  3. BIN  codebrowser/__init__.pyc
  4. +82 −0 codebrowser/iconlib.py
  5. BIN  codebrowser/iconlib.pyc
  6. +268 −0 codebrowser/parsers.py
  7. BIN  codebrowser/parsers.pyc
  8. BIN  codebrowser/pixmaps/class.png
  9. BIN  codebrowser/pixmaps/class_priv.png
  10. BIN  codebrowser/pixmaps/class_prot.png
  11. BIN  codebrowser/pixmaps/const.png
  12. BIN  codebrowser/pixmaps/const_priv.png
  13. BIN  codebrowser/pixmaps/const_prot.png
  14. BIN  codebrowser/pixmaps/default.png
  15. BIN  codebrowser/pixmaps/enum.png
  16. BIN  codebrowser/pixmaps/enum_priv.png
  17. BIN  codebrowser/pixmaps/enum_prot.png
  18. BIN  codebrowser/pixmaps/event.png
  19. BIN  codebrowser/pixmaps/event_priv.png
  20. BIN  codebrowser/pixmaps/event_prot.png
  21. BIN  codebrowser/pixmaps/exception.png
  22. BIN  codebrowser/pixmaps/exception_priv.png
  23. BIN  codebrowser/pixmaps/exception_prot.png
  24. BIN  codebrowser/pixmaps/field.png
  25. BIN  codebrowser/pixmaps/field_priv.png
  26. BIN  codebrowser/pixmaps/field_prot.png
  27. BIN  codebrowser/pixmaps/interface.png
  28. BIN  codebrowser/pixmaps/interface_priv.png
  29. BIN  codebrowser/pixmaps/interface_prot.png
  30. BIN  codebrowser/pixmaps/macro.png
  31. BIN  codebrowser/pixmaps/macro_priv.png
  32. BIN  codebrowser/pixmaps/macro_prot.png
  33. BIN  codebrowser/pixmaps/method.png
  34. BIN  codebrowser/pixmaps/method_priv.png
  35. BIN  codebrowser/pixmaps/method_prot.png
  36. BIN  codebrowser/pixmaps/namespace.png
  37. BIN  codebrowser/pixmaps/namespace_priv.png
  38. BIN  codebrowser/pixmaps/namespace_prot.png
  39. BIN  codebrowser/pixmaps/object.png
  40. BIN  codebrowser/pixmaps/object_priv.png
  41. BIN  codebrowser/pixmaps/object_prot.png
  42. BIN  codebrowser/pixmaps/patch.png
  43. BIN  codebrowser/pixmaps/proc.png
  44. BIN  codebrowser/pixmaps/proc_priv.png
  45. BIN  codebrowser/pixmaps/proc_prot.png
  46. BIN  codebrowser/pixmaps/prop.png
  47. BIN  codebrowser/pixmaps/prop_priv.png
  48. BIN  codebrowser/pixmaps/prop_prot.png
  49. BIN  codebrowser/pixmaps/struct.png
  50. BIN  codebrowser/pixmaps/struct_priv.png
  51. BIN  codebrowser/pixmaps/struct_prot.png
  52. BIN  codebrowser/pixmaps/typedef.png
  53. BIN  codebrowser/pixmaps/typedef_priv.png
  54. BIN  codebrowser/pixmaps/typedef_prot.png
  55. BIN  codebrowser/pixmaps/union.png
  56. BIN  codebrowser/pixmaps/union_priv.png
  57. BIN  codebrowser/pixmaps/union_prot.png
  58. +104 −0 codebrowser/plugin.py
  59. BIN  codebrowser/plugin.pyc
9 codebrowser.gedit-plugin
@@ -0,0 +1,9 @@
+[Gedit Plugin]
+Loader=python
+Module=codebrowser
+IAge=2
+Name=Evolved Code Browser
+Description=A code browser powered by etags.
+Authors=Fabio Zendhi Nagao <nagaozen@hotmail.com>\nhttp://zend.lojcomm.com.br/
+Copyright=Copyright © 2011 Fabio Zendhi Nagao
+Website=http://github.com/nagaozen/gedit-plugin-codebrowser/
123 codebrowser/__init__.py
@@ -0,0 +1,123 @@
+# -*- coding: utf-8 -*-
+
+# gEdit CodeBrowser plugin
+# Copyright (C) 2011 Fabio Zendhi Nagao
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+
+import gtk
+import gedit
+from plugin import CodeBrowser
+from parsers import *
+
+class CodeBrowserWindowHelper:
+
+ ICO = [
+ # width height ncolors chars_per_pixel
+ "16 16 16 1",
+ # colors
+ " c None",
+ "1 c #EEEEEC",# Tango Aluminium
+ "2 c #D3D7CF",
+ "3 c #BABDB6",
+ "4 c #888A85",
+ "5 c #555753",
+ "6 c #2E3436",
+ "a c #E9B96E",# Tango Chocolate
+ "b c #C17D11",
+ "c c #8F5902",
+ "d c #729FCF",# Tango Sky Blue
+ "e c #3465A4",
+ "f c #204A87",
+ "g c #AD7FA8",# Tango Plum
+ "h c #75507B",
+ "i c #5C3566",
+ # pixels
+ "aaa ",
+ "abc 123456666 ",
+ "ccc ",
+ " ",
+ " 3 ddd ",
+ " 3def 123456666",
+ " 3 fff ",
+ " ",
+ " 3 ggg ",
+ " 3ghi 1234566 ",
+ " 3 iii ",
+ " 3 ",
+ " 3 3 ddd ",
+ " 33def 123456",
+ " 3 fff ",
+ " ",
+ ]
+
+ def __init__(self, plugin, window):
+ self._window = window
+ self._plugin = plugin
+ self._panel = self._window.get_side_panel()
+
+ # Generate the side panel tab icon
+ drawable = gtk.gdk.get_default_root_window()
+ colormap = drawable.get_colormap()
+ pixmap, mask = gtk.gdk.pixmap_colormap_create_from_xpm_d(drawable, colormap, None, self.ICO)
+
+ image = gtk.Image()
+ image.set_from_pixmap(pixmap, mask)
+
+ # Create and assign widget to the panel
+ self._codebrowser = CodeBrowser(self._plugin, self._window)
+ self._panel.add_item(self._codebrowser, "Code Browser", image)
+
+ self.parser = CTagsParser()
+
+ def deactivate(self):
+ self._panel.remove_item(self._codebrowser)
+ self._codebrowser.deactivate()
+ self._codebrowser = None
+
+ self._panel = None
+ self._window = None
+ self._plugin = None
+
+ def update_ui(self):
+ doc = self._window.get_active_document()
+ if doc:
+ parser = self.parser
+ ts = parser.parse(doc)
+ self._codebrowser.set_model(ts, parser)
+ else:
+ self._codebrowser.set_model(None)
+
+
+class CodeBrowserPlugin(gedit.Plugin):
+
+ WINDOW_DATA_KEY = "CodeBrowserPluginWindowData"
+
+ def __init__(self):
+ gedit.Plugin.__init__(self)
+
+ def activate(self, window):
+ helper = CodeBrowserWindowHelper(self, window)
+ window.set_data(self.WINDOW_DATA_KEY, helper)
+
+ def deactivate(self, window):
+ window.get_data(self.WINDOW_DATA_KEY).deactivate()
+ window.set_data(self.WINDOW_DATA_KEY, None)
+
+ def update_ui(self, window):
+ window.get_data(self.WINDOW_DATA_KEY).update_ui()
+
+
+# ex:ts=4:et:
+
BIN  codebrowser/__init__.pyc
Binary file not shown
82 codebrowser/iconlib.py
@@ -0,0 +1,82 @@
+# -*- coding: utf-8 -*-
+
+# gEdit CodeBrowser plugin
+# Copyright (C) 2011 Fabio Zendhi Nagao
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+
+import gtk
+import os
+
+pixbufs = {
+ "class": None,
+ "class_priv": None,
+ "class_prot": None,
+ "const": None,
+ "const_priv": None,
+ "const_prot": None,
+ "enum": None,
+ "enum_priv": None,
+ "enum_prot": None,
+ "event": None,
+ "event_priv": None,
+ "event_prot": None,
+ "exception": None,
+ "exception_priv": None,
+ "exception_prot": None,
+ "field": None,
+ "field_priv": None,
+ "field_prot": None,
+ "interface": None,
+ "interface_priv": None,
+ "interface_prot": None,
+ "macro": None,
+ "macro_priv": None,
+ "macro_prot": None,
+ "method": None,
+ "method_priv": None,
+ "method_prot": None,
+ "namespace": None,
+ "namespace_priv": None,
+ "namespace_prot": None,
+ "object": None,
+ "object_priv": None,
+ "object_prot": None,
+ "proc": None,
+ "proc_priv": None,
+ "proc_prot": None,
+ "prop": None,
+ "prop_priv": None,
+ "prop_prot": None,
+ "struct": None,
+ "struct_priv": None,
+ "struct_prot": None,
+ "typedef": None,
+ "typedef_priv": None,
+ "typedef_prot": None,
+ "union": None,
+ "union_priv": None,
+ "union_prot": None,
+
+ "default": None,
+ "patch": None
+}
+
+def populate(plugin):
+ for key in pixbufs:
+ filename = os.path.join( plugin.get_install_dir(), "codebrowser", "pixmaps", "%s.png" %key )
+ pixbufs[key] = gtk.gdk.pixbuf_new_from_file(filename)
+
+# ex:ts=4:et:
+
BIN  codebrowser/iconlib.pyc
Binary file not shown
268 codebrowser/parsers.py
@@ -0,0 +1,268 @@
+# -*- coding: utf-8 -*-
+
+# gEdit CodeBrowser plugin
+# Copyright (C) 2011 Fabio Zendhi Nagao
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+
+import gtk
+import iconlib
+import os
+import re
+import subprocess
+import tempfile
+
+def iif(condition, trueVal, falseVal):
+ if condition:
+ return trueVal
+ else:
+ return falseVal
+
+class ParserInterface:
+
+ def parse(self, doc):
+ pass
+
+ def cellrenderer(self, tvc, crt, ts, piter):
+ pass
+
+ def pixbufrenderer(self, tvc, crp, ts, piter):
+ crp.set_property("pixbuf", "default")
+
+
+class CTagsParser(ParserInterface):
+
+ def parse(self, doc):
+ code = doc.get_text(*doc.get_bounds())
+ lang = doc.get_language()
+
+ if not lang:
+ return None
+
+ lang = self.__get_lang(lang.get_id())
+
+ if not lang:
+ return None
+
+ tags = self.__generate_tags(code, lang)
+ ts = self.__tags_to_ts(tags)
+
+ return ts
+
+ def cellrenderer(self, tvc, crt, ts, piter):
+ text = ts.get_value(piter, 0)
+ crt.set_property("foreground-gdk", gtk.gdk.Color(0, 0, 0))
+ crt.set_property("text", text)
+
+ def pixbufrenderer(self, tvc, crp, ts, piter):
+ try:
+ icon = ts.get_value(piter, 3)
+ except:
+ icon = "default"
+ crp.set_property("pixbuf", iconlib.pixbufs[icon])
+
+ def __generate_tags(self, code, lang):
+ hdl_code, tmp_code = tempfile.mkstemp()
+ hdl_tags, tmp_tags = tempfile.mkstemp()
+
+ os.close(hdl_code)
+ os.close(hdl_tags)
+
+ f = open(tmp_code, 'w')
+ f.write(code)
+ f.close()
+
+ cmd = "ctags --fields=-fst+Kn --sort=no --language-force=%s -f %s %s" %(lang, tmp_tags, tmp_code)
+ subprocess.Popen(cmd, shell=True).wait()
+
+ os.remove(tmp_code)
+
+ return tmp_tags
+
+ #
+ # NOTE: CTags file format info at <http://ctags.sourceforge.net/ctags.html#TAG FILE FORMAT>
+ #
+
+ def __tags_to_ts(self, tags):
+ ts = gtk.TreeStore(str, str, int, str)
+ ts.set_sort_column_id(2, gtk.SORT_ASCENDING)
+
+ scopes = []
+ indent = "INDENT_UNIT_IS_UNKNOWN"
+
+ f = open(tags, 'r')
+ for line in f.readlines():
+ data = self.__get_line_data(line)
+
+ if data:
+ tagname = data[0]
+ tagfile = data[1]
+ tagaddress = data[2]
+ tagkind = data[3]
+ tagline = data[4]
+
+ if ( indent == "INDENT_UNIT_IS_UNKNOWN" ) and ( tagaddress.startswith(' ') or tagaddress.startswith('\t') ):
+ indent = self.__detect_indent_unit(tagaddress)
+
+ lvl = tagaddress.count(indent)
+ scopes = scopes[:lvl]
+
+ parent = None
+ if lvl > 0 and len(scopes) > 0:
+ parent = scopes[len(scopes) - 1]
+
+ scopes.append( ts.append(parent , [ tagname, tagfile, tagline, tagkind ]) )
+ f.close()
+
+ os.remove(tags)
+
+ return ts
+
+ def __get_line_data(self, line):
+ if line.startswith("!_"):
+ return None
+
+ tagaddress = re.findall(r'\/\^.*\$/;"', line)
+ if len(tagaddress) > 0:
+ tagaddress = tagaddress.pop()
+ else:
+ tagaddress = ""
+
+ line = re.sub(r'\/\^.*\$/;"', 'TAG_ADDRESS_REMOVED', line)
+ tokens = line.strip().split('\t')
+
+ tokens[2] = tagaddress[2:len(tokens[2])-4]# ignores regexp and vim compat hacks and get only the ... in /^...$/;"
+ tokens[3] = self.__get_type(tokens[0], tokens[2], tokens[3])
+ tokens[4] = int(tokens[4].strip().split(":").pop())
+
+ return tokens
+
+ def __detect_indent_unit(self, line):
+ indent = []
+ for c in line:
+ if c.isspace():
+ indent.append(c)
+ else:
+ break
+ return ''.join(indent)
+
+ def __get_type(self, tagname, tagaddress, tagkind):
+ maps = {
+ "array" : "enum",
+ "class" : "class",
+ "constant" : "const",
+ "component" : "struct",
+ "define" : "typedef",
+ "enum constant" : "enum",
+ "enum" : "enum",
+ "enumerator" : "enum",
+ "event" : "event",
+ "externvar" : "field",
+ "feature" : "method",
+ "field" : "field",
+ "format" : "method",
+ "function" : "method",
+ "interface" : "interface",
+ "jsfunction" : "method",
+ "label" : "proc",
+ "local" : "field",
+ "macro" : "macro",
+ "member" : "method",
+ "method" : "method",
+ "module" : "namespace",
+ "mxtag" : "default",
+ "namelist" : "enum",
+ "namespace" : "namespace",
+ "object" : "object",
+ "package" : "namespace",
+ "property" : "prop",
+ "prototype" : "method",
+ "record" : "struct",
+ "set" : "field",
+ "singleton method" : "method",
+ "struct" : "struct",
+ "subroutine" : "proc",
+ "type" : "struct",
+ "typedef" : "typedef",
+ "union" : "union",
+ "variable" : "field"
+ }
+
+ try:
+ tagkind = maps[tagkind]
+ if tagname.startswith("_") or ( tagaddress.lower().find("private") > -1 ):
+ tagkind = "%s_priv"%tagkind
+ elif tagaddress.lower().find("protected") > -1:
+ tagkind = "%s_prot"%tagkind
+ except:
+ print "<<CodeBrowser>> Warning: Failed to find %s map. Cascading to default." % tagkind
+ tagkind = "default"
+
+ return tagkind
+
+ def __get_lang(self, lang):
+ maps = {
+ "ant" : "ant",
+ "asm" : "asm",
+ "asp" : "asp",
+ "awk" : "awk",
+ "basic" : "basic",
+ "beta" : "beta",
+ "c" : "c",
+ "c-sharp" : "c#",
+ "cpp" : "c++",
+ "cobol" : "cobol",
+ "dosbatch" : "dosbatch",
+ "eiffel" : "eiffel",
+ "erlang" : "erlang",
+ "flex" : "flex",
+ "fortran" : "fortran",
+ "html" : "html",
+ "java" : "java",
+ "js" : "js",
+ "lisp" : "lisp",
+ "lua" : "lua",
+ "makefile" : "make",
+ "matlab" : "matlab",
+ "objective-caml" : "ocaml",
+ "pascal" : "pascal",
+ "perl" : "perl",
+ "php" : "php",
+ "python" : "python",
+ "rexx" : "rexx",
+ "ruby" : "ruby",
+ "scheme" : "scheme",
+ "sh" : "sh",
+ "slang" : "slang",
+ "sml" : "sml",
+ "sql" : "sql",
+ "tcl" : "tcl",
+ "texinfo" : "tex",
+ "vera" : "vera",
+ "verilog" : "verilog",
+ "vhdl" : "vhdl",
+ "vim" : "vim",
+ "yacc" : "yacc"
+ }
+
+ try:
+ ctags_lang = maps[lang]
+ except:
+ ctags_lang = None
+
+ return ctags_lang
+
+
+# ex:ts=4:et:
+
BIN  codebrowser/parsers.pyc
Binary file not shown
BIN  codebrowser/pixmaps/class.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/class_priv.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/class_prot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/const.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/const_priv.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/const_prot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/default.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/enum.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/enum_priv.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/enum_prot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/event.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/event_priv.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/event_prot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/exception.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/exception_priv.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/exception_prot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/field.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/field_priv.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/field_prot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/interface.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/interface_priv.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/interface_prot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/macro.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/macro_priv.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/macro_prot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  codebrowser/pixmaps/method.png
Diff not rendered
BIN  codebrowser/pixmaps/method_priv.png
Diff not rendered
BIN  codebrowser/pixmaps/method_prot.png
Diff not rendered
BIN  codebrowser/pixmaps/namespace.png
Diff not rendered
BIN  codebrowser/pixmaps/namespace_priv.png
Diff not rendered
BIN  codebrowser/pixmaps/namespace_prot.png
Diff not rendered
BIN  codebrowser/pixmaps/object.png
Diff not rendered
BIN  codebrowser/pixmaps/object_priv.png
Diff not rendered
BIN  codebrowser/pixmaps/object_prot.png
Diff not rendered
BIN  codebrowser/pixmaps/patch.png
Diff not rendered
BIN  codebrowser/pixmaps/proc.png
Diff not rendered
BIN  codebrowser/pixmaps/proc_priv.png
Diff not rendered
BIN  codebrowser/pixmaps/proc_prot.png
Diff not rendered
BIN  codebrowser/pixmaps/prop.png
Diff not rendered
BIN  codebrowser/pixmaps/prop_priv.png
Diff not rendered
BIN  codebrowser/pixmaps/prop_prot.png
Diff not rendered
BIN  codebrowser/pixmaps/struct.png
Diff not rendered
BIN  codebrowser/pixmaps/struct_priv.png
Diff not rendered
BIN  codebrowser/pixmaps/struct_prot.png
Diff not rendered
BIN  codebrowser/pixmaps/typedef.png
Diff not rendered
BIN  codebrowser/pixmaps/typedef_priv.png
Diff not rendered
BIN  codebrowser/pixmaps/typedef_prot.png
Diff not rendered
BIN  codebrowser/pixmaps/union.png
Diff not rendered
BIN  codebrowser/pixmaps/union_priv.png
Diff not rendered
BIN  codebrowser/pixmaps/union_prot.png
Diff not rendered
104 codebrowser/plugin.py
@@ -0,0 +1,104 @@
+# -*- coding: utf-8 -*-
+
+# gEdit CodeBrowser plugin
+# Copyright (C) 2011 Fabio Zendhi Nagao
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+
+import gtk
+import iconlib
+
+class CodeBrowser(gtk.VBox):
+
+ def __init__(self, plugin, window):
+ self._window = window
+ self._plugin = plugin
+
+ gtk.VBox.__init__(self)
+ iconlib.populate(self._plugin)
+
+ sw = gtk.ScrolledWindow()
+ self._browser = gtk.TreeView()
+ self._tvc = gtk.TreeViewColumn()
+ self._crp = gtk.CellRendererPixbuf()
+ self._crt = gtk.CellRendererText()
+
+ sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ sw.set_shadow_type(gtk.SHADOW_IN)
+ sw.add(self._browser)
+
+ self._on_row_activated_id = self._browser.connect("row-activated", self.on_row_activated)
+ self._browser.props.has_tooltip = True
+ self._browser.connect("query-tooltip", self.on_query_tooltip)
+ self._browser.get_selection().connect("changed", self.on_selection_changed, self._browser)
+
+ self._browser.set_headers_visible(False)
+ self._browser.append_column(self._tvc)
+
+ self._tvc.pack_start(self._crp, False)
+ self._tvc.pack_start(self._crt, False)
+
+ self.pack_start(sw)
+ self.show_all()
+
+ def deactivate(self):
+ self._browser.disconnect(self._on_row_activated_id)
+
+ if self._browser.get_model():
+ self._browser.get_model().clear()
+
+ self._crt = None
+ self._crp = None
+ self._tvc = None
+ self._browser = None
+
+ self._plugin = None
+ self._window = None
+
+ def set_model(self, ts, parser = None):
+ self._browser.set_model(ts)
+
+ if parser:
+ self._tvc.set_cell_data_func(self._crp, parser.pixbufrenderer)
+ self._tvc.set_cell_data_func(self._crt, parser.cellrenderer)
+ self._browser.queue_draw()
+ self._browser.expand_all()
+
+ def on_row_activated(self, tv, path, tvc):
+ model = tv.get_model()
+ piter = model.get_iter(path)
+ line = model.get_value(piter, 2)
+
+ self._window.get_active_document().goto_line(line - 1)
+ self._window.get_active_view().scroll_to_cursor()
+
+ def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip):
+ if not widget.get_tooltip_context(x, y, keyboard_tip):
+ return False
+ else:
+ model, path, piter = widget.get_tooltip_context(x, y, keyboard_tip)
+ info = model.get(piter, 0, 2, 3)
+ name = info[0]
+ line = info[1]
+ kind = info[2]
+ tooltip.set_markup("<b>(%s) <span foreground='#B8CFE7'>%s</span></b> @ line: %s "%(kind, name, line))
+ widget.set_tooltip_row(tooltip, path)
+ return True
+
+ def on_selection_changed(self, selection, tv):
+ tv.trigger_tooltip_query()
+
+
+# ex:ts=4:et:
+
BIN  codebrowser/plugin.pyc
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.