Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

browse: directory browsing now functional

Changeset ba2dea51f18b

Parent 2e296e173e29

by Steve Borho

Changes to one file · Browse files at ba2dea51f18b Showing diff from parent 2e296e173e29 Diff from another changeset...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 
84
85
 
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
 
 
 
 
 
 
 
183
184
185
186
187
188
189
 
190
191
192
193
194
195
196
 
 
 
 
 
 
 
 
197
198
199
 
 
200
201
 
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
 
 
231
232
233
234
235
236
237
 
 
 
 
 
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
 
256
257
 
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
 
 
 
 
 
 
 
 
 
 
 
 
 
277
278
279
280
281
282
283
284
285
286
287
 
 
 
 
 
 
 
288
289
290
291
292
293
294
295
296
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 
83
84
 
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
 
 
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
 
 
 
187
188
189
190
 
 
191
192
193
194
195
196
197
198
 
199
200
201
202
203
204
205
 
 
 
 
 
 
206
207
208
209
210
211
212
213
214
 
 
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
 
248
249
250
251
252
253
254
255
 
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
 
 
 
276
277
 
278
279
280
281
282
283
284
285
286
287
288
289
 
 
290
291
 
292
 
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
 
 
313
 
 
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
 # browse.py - TortoiseHg's repository browser  #  # Copyright 2009 Steve Borho <steve@borho.org>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    import os  import gtk  import gobject  import pango    from mercurial import hg, ui, cmdutil    from tortoisehg.util.i18n import _  from tortoisehg.util import hglib, paths, shlib, menuthg    from tortoisehg.hgtk import hgcmd, gtklib, gdialog    folderxpm = [   "17 16 7 1",   " c #000000",   ". c #808000",   "X c yellow",   "o c #808080",   "O c #c0c0c0",   "+ c white",   "@ c None",   "@@@@@@@@@@@@@@@@@",   "@@@@@@@@@@@@@@@@@",   "@@+XXXX.@@@@@@@@@",   "@+OOOOOO.@@@@@@@@",   "@+OXOXOXOXOXOXO. ",   "@+XOXOXOXOXOXOX. ",   "@+OXOXOXOXOXOXO. ",   "@+XOXOXOXOXOXOX. ",   "@+OXOXOXOXOXOXO. ",   "@+XOXOXOXOXOXOX. ",   "@+OXOXOXOXOXOXO. ",   "@+XOXOXOXOXOXOX. ",   "@+OOOOOOOOOOOOO. ",   "@ ",   "@@@@@@@@@@@@@@@@@",   "@@@@@@@@@@@@@@@@@"   ]  folderpb = gtk.gdk.pixbuf_new_from_xpm_data(folderxpm)    filexpm = [   "12 12 3 1",   " c #000000",   ". c #ffff04",   "X c #b2c0dc",   "X XXX",   "X ...... XXX",   "X ...... X",   "X . ... X",   "X ........ X",   "X . .... X",   "X ........ X",   "X . .. X",   "X ........ X",   "X . .. X",   "X ........ X",   "X X"   ]  filepb = gtk.gdk.pixbuf_new_from_xpm_data(filexpm)    class dirnode(object):   def __init__(self):   self.subdirs = {}   self.files = []   self.statuses = set()   def addfile(self, filename, st):   self.files.append((filename, st))   self.addstatus(st)   def addsubdir(self, dirname):   self.subdirs[dirname] = dirnode()   def addstatus(self, st):   self.statuses.add(st)    class BrowsePane(gtk.TreeView):   'Dialog for browsing repo.status() output' - def __init__(self, entry): + def __init__(self, callback):   gtk.TreeView.__init__(self) - self.entry = entry + self.callback = callback + self.cachedroot = None   self.menu = menuthg.menuThg()   fm = gtk.ListStore(str, # canonical path   bool, # Checked   str, # basename-UTF8   bool, # M   bool, # A   bool, # R   bool, # !   bool, # ?   bool, # I   bool, # C   bool) # isfile   self.set_model(fm)     self.set_headers_visible(False)   self.set_reorderable(True)   self.connect('popup-menu', self.popupmenu)   self.connect('button-release-event', self.buttonrelease)   self.connect('row-activated', self.rowactivated)   self.get_selection().set_mode(gtk.SELECTION_MULTIPLE)   self.set_reorderable(False)   self.set_enable_search(True)   if hasattr(self, 'set_rubber_banding'):   self.set_rubber_banding(True)     col = gtk.TreeViewColumn(_('status'))   self.append_column(col)     iconw, iconh = gtk.icon_size_lookup(gtk.ICON_SIZE_SMALL_TOOLBAR)   def packpixmap(ico, id):   iconpath = paths.get_tortoise_icon(ico)   if iconpath == None:   raise (_("could not open icon file '%s' (check install)") % ico)   pm = gtk.gdk.pixbuf_new_from_file_at_size(iconpath, iconw, iconh)   cell = gtk.CellRendererPixbuf()   cell.set_property('pixbuf', pm)   col.pack_start(cell, expand=False)   col.add_attribute(cell, 'visible', id)     #packpixmap('filemodify.ico', 3) # this icon does not load for me   packpixmap('menucommit.ico', 3) # M   packpixmap('fileadd.ico', 4) # A   packpixmap('filedelete.ico', 5) # R   packpixmap('detect_rename.ico', 6) # missing   packpixmap('menublame.ico', 7) # unknown   #packpixmap('ignore.ico', 8) # ignored   #packpixmap('hg.ico', 9) # clean     def cell_seticon(column, cell, model, iter):   isfile = model.get_value(iter, 10)   pixbuf = isfile and filepb or folderpb   cell.set_property('pixbuf', pixbuf)     col = gtk.TreeViewColumn(_('type'))   cell = gtk.CellRendererPixbuf()   col.pack_start(cell, expand=False)   col.set_cell_data_func(cell, cell_seticon)   self.append_column(col)     col = gtk.TreeViewColumn(_('path'), gtk.CellRendererText(), text=2)   self.append_column(col)     def split(self, filename):   'Split a filename into a list of directories and the basename'   dirs = []   path, basename = os.path.split(filename)   while path:   path, piece = os.path.split(path)   dirs.append(piece)   dirs.reverse()   return dirs, basename   - def chdir(self, cwd, repo): - 'change directories inside a repo, or out of a repo' + def chdir(self, cwd): + 'change to a new directory' + # disable updates while we refill the model + model = self.get_model() + self.set_model(None) + model.clear() + try: + self._chdir(model, cwd) + except Exception, e: + # report to status bar + pass + self.set_model(model) + + def _chdir(self, model, cwd):   def buildrow(name, stset, isfile):   dirs, basename = self.split(name)   row = [ name, False, hglib.toutf(basename),   'M' in stset, 'A' in stset, 'R' in stset,   '!' in stset, '?' in stset, 'I' in stset,   'C' in stset, isfile ]   return row     def adddir(node):   for dname, dirnode in node.subdirs.iteritems():   model.append(buildrow(dname, dirnode.statuses, False))   for fname, st in node.files:   model.append(buildrow(fname, st, True))   - model = self.get_model() - self.set_model(None) # disable updates while we fill the model - model.clear()   drive, tail = os.path.splitdrive(cwd)   if cwd != '/' or (drive and tail):   model.append(buildrow('..', '', False))   - if repo and cwd.startswith(repo.root): - relpath = cwd[len(repo.root)+len(os.sep):] + root = paths.find_root(cwd) + if root and self.cachedroot != root: + self.cacherepo(root) + + if root: + node = self.cachedmodel + relpath = cwd[len(root)+len(os.sep):]   dirs, basename = self.split(relpath) - node = self.cachedmodel   for dname in dirs:   node = node.subdirs[dname]   if basename:   node = node.subdirs[basename]   adddir(node) + self.currepo = None   else: - for name in os.listdir(cwd): - model.append(buildrow(name, '', os.path.isfile(name))) - self.entry.set_text(cwd) - self.set_model(model) - self.cwd = cwd - self.repo = repo + try: + for name in os.listdir(cwd): + isfile = os.path.isfile(os.path.join(cwd, name)) + model.append(buildrow(name, '', isfile)) + except OSError: + # report to status bar + pass + self.currepo = self.cachedrepo   - def refresh(self, cwd, repo, pats=[], filetypes='CI?'): - hglib.invalidaterepo(repo) + + def cacherepo(self, root, pats=[], filetypes='CI?'):   status = ([],)*7   try: + repo = hg.repository(ui.ui(), path=root)   matcher = cmdutil.match(repo, pats)   st = repo.status(match=matcher,   clean='C' in filetypes,   ignored='I' in filetypes,   unknown='?' in filetypes)   except IOError:   pass   filelist = []   # concatenate status output into a single list, then sort on filename   for l, s in ( (st[0], 'M'), (st[1], 'A'), (st[2], 'R'), (st[3], '!'),   (st[4], '?'), (st[5], 'I'), (st[6], 'C') ):   for m in l:   filelist.append([ m, s ])   filelist.sort()     # Build tree data structure   modelroot = dirnode()   for name, filestatus in filelist:   dirs, basename = self.split(name)   curdir = modelroot   for dir in dirs:   if dir not in curdir.subdirs:   curdir.addsubdir(dir)   curdir.addstatus(filestatus)   curdir = curdir.subdirs[dir]   curdir.addfile(name, filestatus)     self.cachedmodel = modelroot - self.chdir(cwd, repo) + self.cachedroot = root + self.cachedrepo = repo     def popupmenu(self, browse):   model, tpaths = browse.get_selection().get_selected_rows()   if not tpaths:   return   files = [model[p][0] for p in tpaths if model[p][10]] - menus = self.menu.get_commands(self.repo, self.repo.root, files) + if self.currepo: + repo = self.currepo + menus = self.menu.get_commands(repo, repo.root, files) + else: + menus = self.menu.get_norepo_commands(None, files)   # see nautilus extension for usage info   for menu_info in menus:   print menu_info     def buttonrelease(self, browse, event):   if event.button != 3:   return False   self.popupmenu(browse)   return True     def rowactivated(self, browse, path, column):   model, tpaths = browse.get_selection().get_selected_rows()   if not tpaths:   return   if len(tpaths) == 1 and not model[tpaths[0]][10]: - newpath = os.path.join(self.cwd, model[tpaths[0]][0]) - newpath = os.path.abspath(newpath) - self.chdir(newpath, self.repo) + self.callback(model[tpaths[0]][0])   else: - files = [model[p][0] for p in tpaths and model[p][10]] + files = [model[p][0] for p in tpaths if model[p][10]]   print files, 'activated'    class BrowseDialog(gtk.Dialog):   'Wrapper application for BrowsePane'   def __init__(self, command, pats):   gtk.Dialog.__init__(self)   gtklib.set_tortoise_icon(self, 'hg.ico')   gtklib.set_tortoise_keys(self)   self.set_has_separator(False)   self.set_default_size(400, 500)   self.connect('response', self.dialog_response) - repo = hg.repository(ui.ui(), path=paths.find_root()) - self.set_title(_('%s - browser') % hglib.get_reponame(repo))     entry = gtk.Entry() - entry.set_text(repo.root)   self.vbox.pack_start(entry, False, True) - browse = BrowsePane(entry)   + def newfolder_notify(newfolder): + curpath = entry.get_text() + newpath = os.path.join(curpath, newfolder) + newpath = hglib.toutf(os.path.abspath(newpath)) + root = paths.find_root(newpath) + if root: + self.set_title(root + ' - ' + _('browser')) + else: + self.set_title(_('browser')) + entry.set_text(newpath) + browse.chdir(newpath) + + browse = BrowsePane(newfolder_notify)   scroller = gtk.ScrolledWindow()   scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)   scroller.set_shadow_type(gtk.SHADOW_ETCHED_IN)   scroller.add(browse)   self.vbox.pack_start(scroller, True, True)   self.show_all() - self.browse = browse - gobject.idle_add(self.refresh, repo.root, repo)   - def refresh(self, cwd, repo): - self.browse.refresh(cwd, repo) + cwd = hglib.toutf(os.getcwd()) + entry.connect('activate', self.entry_activated, browse) + entry.set_text(cwd) + browse.chdir(cwd) + + def entry_activated(self, entry, browse): + browse.chdir(entry.get_text())     def dialog_response(self, dialog, response):   return True    def run(ui, *pats, **opts):   pats = hglib.canonpaths(pats)   if opts.get('canonpats'):   pats = list(pats) + opts['canonpats']   return BrowseDialog(opts.get('alias'), pats)