1 |
################################################## |
2 |
# $Id:$ |
3 |
# small plugin for glimmer |
4 |
# |
5 |
# Authors: |
6 |
# Andreas Motl<andreas.motl@ilo.de> |
7 |
# Sebastian Utz<su@tunemedia.de> |
8 |
# |
9 |
# ToDo: |
10 |
# - Bug: FunctionList doesn't refresh on new opened files by its own |
11 |
# - tune regex for more languages |
12 |
# |
13 |
# Changelog: |
14 |
# $Log$ |
15 |
# |
16 |
################################################## |
17 |
|
18 |
import glimmer |
19 |
import string |
20 |
import re |
21 |
import sys |
22 |
import os |
23 |
sys.argv=[] |
24 |
sys.argv.append("null") |
25 |
from gtk import * |
26 |
import _gtk |
27 |
import _gnome |
28 |
import _gnomeui |
29 |
from gnome.ui import * |
30 |
import gnome.config |
31 |
|
32 |
global row_number |
33 |
|
34 |
row_number = [] |
35 |
|
36 |
# --------------------------------------------------------- |
37 |
# some regular expressions to scan for |
38 |
# class/function/sub/packages signatures |
39 |
# in source code |
40 |
prefix_pattern = '^[|\s]*' |
41 |
sigpart = '\s+([\w|:]+?)\s*' |
42 |
regex_universal=re.compile(prefix_pattern + '(?:\w+?)\*??' + sigpart + '\(.*?\)[\s|:|{]*$') |
43 |
regex_perl=re.compile(prefix_pattern + '(?:package|sub)' + sigpart + '[;|{]$') |
44 |
|
45 |
def get_functionNameFromLine(str): |
46 |
for regex in (regex_universal, regex_perl): |
47 |
match=regex.search(str) |
48 |
if match: |
49 |
str = match.group(1) |
50 |
return str |
51 |
|
52 |
def get_allFunctionNames(content): |
53 |
names=[] |
54 |
lines=string.split(content, "\n") |
55 |
count=1 |
56 |
for line in lines: |
57 |
funcname=get_functionNameFromLine(line) |
58 |
if funcname: |
59 |
names.append((funcname, count)) |
60 |
count=count+1 |
61 |
return names |
62 |
|
63 |
# --------------------------------------------------------- |
64 |
|
65 |
def get_current_text(): |
66 |
start = 0 |
67 |
end = glimmer.buffer_size() |
68 |
str = glimmer.get_text(start, end) |
69 |
return str |
70 |
|
71 |
def functionlist_init (): |
72 |
title = "Functions:" |
73 |
functionlist.set_column_title(0, title) |
74 |
functionlist.clear() |
75 |
|
76 |
def functionlist_append(label): |
77 |
listentry=[] |
78 |
listentry.append(label) |
79 |
listentry.append("") |
80 |
functionlist.append(listentry) |
81 |
|
82 |
def our_main(): |
83 |
global row_number |
84 |
gettext = get_current_text() |
85 |
if gettext: |
86 |
entries=get_allFunctionNames(gettext) |
87 |
functionlist_init() |
88 |
row_number=[] |
89 |
for entry in entries: |
90 |
label=entry[0] |
91 |
rownum=entry[1] |
92 |
functionlist_append(label) |
93 |
row_number.append(rownum) |
94 |
|
95 |
def select_row_callback(clist, row, col, event, data): |
96 |
import glimmer |
97 |
import string |
98 |
global row_number |
99 |
num = row_number[row] |
100 |
glimmer.move_to_line(num) |
101 |
glimmer.move_to(glimmer.line_start()) |
102 |
del glimmer |
103 |
del string |
104 |
|
105 |
|
106 |
def close_function_selector(button, citem, fbox): |
107 |
citem.destroy() |
108 |
glimmer.remove_paned_object("FunctionSelector") |
109 |
|
110 |
|
111 |
def refresh_function_selector(refresh): |
112 |
our_main() |
113 |
|
114 |
def callback_change(): |
115 |
our_main() |
116 |
|
117 |
functionbox = GtkVBox(FALSE, 0) |
118 |
functionbox.show() |
119 |
titleframe = GtkFrame() |
120 |
functionbox.pack_start(titleframe, FALSE, FALSE, 2) |
121 |
titleframe.show() |
122 |
buttonbox = GtkHBox(FALSE, 0) |
123 |
titleframe.add(buttonbox) |
124 |
buttonbox.show() |
125 |
optionsbutton = GtkButton() |
126 |
optionsbutton.set_relief(RELIEF_NONE) |
127 |
buttonbox.pack_start(optionsbutton, FALSE, FALSE, 2) |
128 |
optionsbutton.show() |
129 |
optionsbuttonbox = GtkHBox(FALSE, 0) |
130 |
optionsbutton.add(optionsbuttonbox) |
131 |
optionsbuttonbox.pack_start(GtkLabel("Refresh List"), FALSE, FALSE, 0) |
132 |
optionsbuttonbox.show_all() |
133 |
|
134 |
_gtk.gtk_signal_connect(optionsbutton._o, "clicked", refresh_function_selector) |
135 |
closebutton = GtkButton() |
136 |
closebutton.set_relief(RELIEF_NONE) |
137 |
closebutton.add(GnomeStock("Close")) |
138 |
closebutton.set_usize(22, 22) |
139 |
buttonbox.pack_end(closebutton, FALSE, FALSE, 2) |
140 |
closebutton.show_all() |
141 |
functionwindow = GtkScrolledWindow() |
142 |
functionbox.pack_start(functionwindow, TRUE, TRUE, 2) |
143 |
functionwindow.set_usize(130, 500) |
144 |
functionwindow.show() |
145 |
functionlist = GtkCList(1) |
146 |
functionwindow.add(functionlist) |
147 |
functionlist.show() |
148 |
#functionlist.column_titles_show(1) |
149 |
glimmer.add_paned_object(functionbox._o, "FunctionSelector", 0) |
150 |
our_main() |
151 |
checkitem = GtkCheckMenuItem("Function Selector") |
152 |
checkitem.set_active(TRUE) |
153 |
checkitem.show() |
154 |
glimmer.add_widget_to_menu("_View/Status Bar", checkitem._o) |
155 |
|
156 |
glimmer.register_signal_hook("open-file", callback_change) |
157 |
|
158 |
glimmer.register_signal_hook("change-file", callback_change) |
159 |
|
160 |
glimmer.register_signal_hook("save-file", callback_change) |
161 |
|
162 |
args = (checkitem, functionbox, ) |
163 |
_gtk.gtk_signal_connect(closebutton._o, "clicked", close_function_selector, args) |
164 |
args = (None, ) |
165 |
_gtk.gtk_signal_connect(functionlist._o, "select_row", select_row_callback, args) |