Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

nautilus: use a single function to dispatch all dialogs

This is a part of the large cleanup in mind for 0.8. The arguments
passed to hgproc.py (soon to be hgtk) will be normalized. You get
the menu option selected and the list of files and/or folders selected
in the shell.

Changeset 4ac62b74dc45

Parent 7492a978e7f1

by Steve Borho

Changes to 2 files · Browse files at 4ac62b74dc45 Showing diff from parent 7492a978e7f1 Diff from another changeset...

 
33
34
35
 
 
36
37
38
 
61
62
63
 
64
65
66
 
 
 
 
67
68
69
 
75
76
77
78
79
80
81
 
85
86
87
88
89
90
91
92
93
94
 
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
 
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
 
258
259
260
261
 
262
263
264
 
279
280
281
282
 
283
284
285
 
33
34
35
36
37
38
39
40
 
63
64
65
66
67
 
 
68
69
70
71
72
73
74
 
80
81
82
 
83
84
85
 
89
90
91
 
 
 
 
92
93
94
 
114
115
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
118
119
 
120
121
122
 
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
 
177
178
179
 
180
181
182
183
 
198
199
200
 
201
202
203
204
@@ -33,6 +33,8 @@
 from mercurial.node import short    TORTOISEHG_PATH = '~/tools/tortoisehg-dev' +nofilecmds = 'about serve synch repoconfig userconfig merge unmerge'.split() +nocachecmds = 'about serve repoconfig userconfig'.split()    class HgExtension(nautilus.MenuProvider,   nautilus.ColumnProvider, @@ -61,9 +63,12 @@
  sys.path.insert(0, thgpath)   # else assume tortoise is already in PYTHONPATH   try: + import tortoise.thgutil   import tortoise.menuthg - except ImportError: - print 'unable to import tortoise.menuthg' + except ImportError, e: + # if thgutil is not found, then repository cannot be found + # if menuthg is not found, you have an older version in sys.path + print e   self.menu = None   return   @@ -75,7 +80,6 @@
  self.hgproc = os.path.join(thgpath, 'hgproc.py')   self.ipath = os.path.join(thgpath, 'icons', 'tortoise')   self.menu = tortoise.menuthg.menuThg() - self.menu.handlers = self     def icon(self, iname):   return os.path.join(self.ipath, iname) @@ -85,10 +89,6 @@
  return None   return urllib.unquote(vfs_file.get_uri()[7:])   - def clear_cached_repo(self): - self.cacheroot = None - self.cacherepo = None -   def get_repo_for_path(self, path):   '''   Find mercurial repository for vfs_file @@ -114,102 +114,9 @@
  return None    #start dialogs - def _about(self, window, info): - self._run_dialog('about', filelist=False) - - def _add(self, window, vfs_files): - self._run_dialog('add') - self.clear_cached_repo() - - def _clone(self, window, info): - self._run_dialog('clone') - - def _commit(self, window, vfs_files): - self._run_dialog('commit') - self.clear_cached_repo() - - def _datamine(self, window, vfs_files): - self._run_dialog('datamine') - - def _diff(self, window, vfs_files): - path = self.files[0] - if path is None: - return - repo = self.get_repo_for_path(path) - if repo is None: - return - diffcmd = repo.ui.config('tortoisehg', 'vdiff', None) - if diffcmd is None: - self._run_dialog('diff') - else: - cmdline = ['hg', diffcmd] - cwd = os.path.isdir(path) and path or os.path.dirname(path) - paths = [self.get_path_for_vfs_file(f) for f in vfs_files] - subprocess.Popen(cmdline+paths, shell=False, env=self.env, cwd=cwd) - - def _history(self, window, info): - self._run_dialog('history') - self.clear_cached_repo() - - def _init(self, window, info): - self._run_dialog('init') - - def _recovery(self, window, info): - self._run_dialog('recovery') - self.clear_cached_repo() - - def _revert(self, window, vfs_files): - self._run_dialog('revert') - self.clear_cached_repo() - - def _serve(self, window, info): - self._run_dialog('serve', filelist=False) - - def _status(self, window, info): - self._run_dialog('status') - - def _synch(self, window, info): - self._run_dialog('synch', filelist=False) - self.clear_cached_repo() - - def _config_repo(self, window, info): - self._run_dialog('config') - - def _config_user(self, window, info): - self._run_dialog('config', filelist=False) - - def _unmerge(self, window, info): - self._run_dialog('checkout', filelist=False, - extras=['--', '--clean', str(self.rev0)]) - self.clear_cached_repo() - - def _shelve(self, window, info): - self._run_dialog('shelve') - - _vdiff=_diff - - def _rename(self, window, info): - self._run_dialog('rename') - - def _remove(self, window, info): - self._run_dialog('status') - - def _annotate(self, window, info): - self._run_dialog('datamine') - - def _update(self, window, info): - print "not supported" # will be replaced - - def _merge(self, window, info): - print "not supported" # will be replaced - - def _grep(self, window, info): - self._run_dialog('datamine') - - def _run_dialog(self, hgcmd, filelist=True, extras=[]): + def run_dialog(self, menuitem, hgcmd):   '''   hgcmd - hgproc subcommand - filelist - bool for whether to generate file list for hgproc   '''   paths = self.files   if paths[0] is None: @@ -224,25 +131,37 @@
  else:   root = cwd   + if hgcmd == 'vdiff': + diffcmd = repo.ui.config('tortoisehg', 'vdiff', None) + if diffcmd is None: + hgcmd = 'diff' + else: + cmdline = ['hg', diffcmd] + cwd = os.path.isdir(path) and path or os.path.dirname(path) + paths = [self.get_path_for_vfs_file(f) for f in vfs_files] + subprocess.Popen(cmdline+paths, shell=False, env=self.env, + cwd=cwd) + return +   cmdopts = [sys.executable, self.hgproc]   cmdopts += ['--root', root]   cmdopts += ['--cwd', cwd]   cmdopts += ['--command', hgcmd]   - if filelist: + if hgcmd not in nofilecmds:   # Use temporary file to store file list (avoid shell command   # line limitations)   fd, tmpfile = tempfile.mkstemp(prefix="tortoisehg_filelist_")   os.write(fd, "\n".join(paths))   os.close(fd)   cmdopts += ['--listfile', tmpfile, '--deletelistfile'] - cmdopts.extend(extras)     subprocess.Popen(cmdopts, cwd=cwd, env=self.env, shell=False)   - # Remove cached repo object, dirstate may change - self.cacherepo = None - self.cacheroot = None + if hgcmd not in nocachecmds: + # Remove cached repo object, dirstate may change + self.cacherepo = None + self.cacheroot = None     def buildMenu(self, menuf, vfsfile):   '''Build menu''' @@ -258,7 +177,7 @@
  pos += 1   idstr = 'HgNautilus::%02d' % pos   if menu_info.isSep(): - #can not insert a separator till now + # can not insert a separator till now   pass   elif menu_info.isSubmenu():   if nautilus.__dict__.get('Menu'): @@ -279,7 +198,7 @@
  menu_info.menutext,   menu_info.helptext,   self.icon(menu_info.icon)) - item.connect('activate', menu_info.handler, '') + item.connect('activate', self.run_dialog, menu_info.hgcmd)   items.append(item)   return items  
 
18
19
20
21
 
22
23
24
 
25
26
27
 
38
39
40
41
 
42
43
 
44
45
46
 
80
81
82
83
84
85
86
 
110
111
112
113
 
114
115
116
117
118
 
119
120
121
 
137
138
139
140
 
141
142
143
144
145
146
147
 
 
148
149
150
151
 
152
153
154
 
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
 
261
262
263
264
 
265
266
267
268
269
 
270
271
272
273
274
275
 
276
277
278
 
18
19
20
 
21
22
23
 
24
25
26
27
 
38
39
40
 
41
42
 
43
44
45
46
 
80
81
82
 
83
84
85
 
109
110
111
 
112
113
114
115
116
 
117
118
119
120
 
136
137
138
 
139
140
141
142
143
144
145
 
146
147
148
149
 
 
150
151
152
153
 
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
 
260
261
262
 
263
264
265
266
 
 
267
268
269
270
271
272
 
273
274
275
276
@@ -18,10 +18,10 @@
   class TortoiseMenu(object):   - def __init__(self, menutext, helptext, handler, icon=None, state=True): + def __init__(self, menutext, helptext, hgcmd, icon=None, state=True):   self.menutext = menutext   self.helptext = helptext - self.handler = handler + self.hgcmd = hgcmd   self.state = state   self.icon = icon   @@ -38,9 +38,9 @@
  TortoiseMenu.__init__(self, menutext, helptext, None, icon)   self.menus = menus[:]   - def add_menu(self, menutext, helptext, handler, icon=None, state=True): + def add_menu(self, menutext, helptext, hgcmd, icon=None, state=True):   self.menus.append(TortoiseMenu(menutext, helptext, - handler, icon, state)) + hgcmd, icon, state))     def add_sep(self):   self.menus.append(TortoiseMenuSep()) @@ -80,7 +80,6 @@
  """shell extension that adds context menu items"""     def __init__(self): - self.handlers = self   self.name = "TortoiseHG"     def get_commands_dragdrop(self, srcfiles, destfolder): @@ -110,12 +109,12 @@
  thgmenu = []   thgmenu.append(TortoiseMenu(_("Create Clone"),   _("Create clone here from source"), - self.handlers._clone_here, icon="menuclone.ico")) + 'clone', icon="menuclone.ico"))     if drop_repo:   thgmenu.append(TortoiseMenu(_("Synchronize"),   _("Synchronize with dragged repository"), - self.handlers._synch_here, icon="menusynch.py")) + 'synch', icon="menusynch.py"))   return thgmenu     def get_commands(self, files): @@ -137,18 +136,18 @@
  if repo:   thgmenu.append(TortoiseMenu(_("HG Commit..."),   _("Commit changes in repository"), - self.handlers._commit, icon="menucommit.ico")) + 'commit', icon="menucommit.ico"))     menu = TortoiseSubmenu(self.name, "Mercurial", [], icon="hg.ico")     if repo is None:   menu.append(TortoiseMenu(_("Clone a Repository"),   _("clone a repository"), - self.handlers._clone, icon="menuclone.ico")) + 'clone', icon="menuclone.ico")) + if os.path.isdir(rpath):   menu.append(TortoiseMenu(_("Create Repository Here"),   _("create a new repository in this directory"), - self.handlers._init, icon="menucreaterepos.ico", - state=os.path.isdir(rpath))) + 'init', icon="menucreaterepos.ico"))   else:   canannotate = len(files) > 0   hashgignore = False @@ -161,99 +160,99 @@
  if hashgignore: # needs ico   menu.append(TortoiseMenu(_("Edit Ignore Filter"),   _("Edit repository ignore filter"), - self.handlers._hgignore, icon="general.ico")) + 'hgignore', icon="general.ico"))     menu.append(TortoiseMenu(_("View File Status"),   _("Repository status"), - self.handlers._status, icon="menushowchanged.ico")) + 'status', icon="menushowchanged.ico"))     menu.append(TortoiseMenu(_("Shelve Changes"),   _("Shelve or unshelve repository changes"), - self.handlers._shelve, icon="general.ico")) # needs ico + 'shelve', icon="general.ico")) # needs ico     # Visual Diff (any extdiff command)   has_vdiff = repo.ui.config('tortoisehg', 'vdiff', '') != '' - menu.append(TortoiseMenu(_("Visual Diff"), + if has_vdiff: + menu.append(TortoiseMenu(_("Visual Diff"),   _("View changes using GUI diff tool"), - self.handlers._vdiff, icon="TortoiseMerge.ico", - state=has_vdiff)) + 'vdiff', icon="TortoiseMerge.ico"))     if len(files) == 0: # needs ico   menu.append(TortoiseMenu(_("Guess Renames"),   _("Detect renames and copies"), - self.handlers._guess_rename, icon="general.ico")) + 'guess', icon="general.ico"))   elif len(files) == 1: # needs ico   menu.append(TortoiseMenu(_("Rename File"),   _("Rename file or directory"), - self.handlers._rename, icon="general.ico")) + 'rename', icon="general.ico"))     if len(files):   menu.append(TortoiseMenu(_("Add Files"),   _("Add files to Hg repository"), - self.handlers._add, icon="menuadd.ico")) + 'add', icon="menuadd.ico"))   menu.append(TortoiseMenu(_("Remove Files"),   _("Remove selected files on the next commit"), - self.handlers._remove, icon="menudelete.ico")) + 'remove', icon="menudelete.ico"))   menu.append(TortoiseMenu(_("Undo Changes"),   _("Revert selected files"), - self.handlers._revert, icon="menurevert.ico")) + 'revert', icon="menurevert.ico"))     # we can only annotate file but not directories - menu.append(TortoiseMenu(_("Annotate Files"), + if canannotate: + menu.append(TortoiseMenu(_("Annotate Files"),   _("show changeset information per file line"), - self.handlers._annotate, icon="menublame.ico", - state=canannotate)) + 'annotate', icon="menublame.ico"))     menu.append(TortoiseMenuSep())   menu.append(TortoiseMenu(_("Update To Revision"),   _("update working directory"), - self.handlers._update, icon="menucheckout.ico")) + 'update', icon="menucheckout.ico"))     canmerge = len(repo.heads()) > 1 and \   len(repo.changectx(None).parents()) < 2 - menu.append(TortoiseMenu(_("Merge Revisions"), + if canmerge: + menu.append(TortoiseMenu(_("Merge Revisions"),   _("merge working directory with another revision"), - self.handlers._merge, icon="menumerge.ico", - state=canmerge)) + 'merge', icon="menumerge.ico"))     inmerge = len(repo.changectx(None).parents()) > 1 - menu.append(TortoiseMenu(_("Undo Merge"), + if inmerge: + menu.append(TortoiseMenu(_("Undo Merge"),   _("Undo merge by updating to revision"), - self.handlers._merge, icon="menuunmerge.ico", - state=inmerge)) + 'unmerge', icon="menuunmerge.ico"))     menu.append(TortoiseMenuSep())     menu.append(TortoiseMenu(_("View Changelog"),   _("View revision history"), - self.handlers._history, icon="menulog.ico")) + 'history', icon="menulog.ico"))     if len(files) == 0:   menu.append(TortoiseMenu(_("Search Repository"),   _("Search revisions of files for a text pattern"), - self.handlers._grep, icon="menurepobrowse.ico")) + 'grep', icon="menurepobrowse.ico"))   - menu.append(TortoiseMenuSep()) + menu.append(TortoiseMenuSep())   - menu.append(TortoiseMenu(_("Synchronize..."), - _("Synchronize with remote repository"), - self.handlers._synch, icon="menusynch.ico")) - menu.append(TortoiseMenu(_("Recovery..."), - _("General repair and recovery of repository"), - self.handlers._recovery, icon="general.ico")) - menu.append(TortoiseMenu(_("Web Server"), - _("start web server for this repository"), - self.handlers._serve, icon="proxy.ico")) + menu.append(TortoiseMenu(_("Synchronize..."), + _("Synchronize with remote repository"), + '_synch', icon="menusynch.ico")) + menu.append(TortoiseMenu(_("Recovery..."), + _("General repair and recovery of repository"), + 'recovery', icon="general.ico")) + menu.append(TortoiseMenu(_("Web Server"), + _("start web server for this repository"), + 'serve', icon="proxy.ico"))     menu.append(TortoiseMenuSep())   menu.append(TortoiseMenu(_("Create Clone"),   _("Clone a repository here"), - self.handlers._clone, icon="menuclone.ico")) - can_init = repo.root != rpath and os.path.isdir(rpath) - menu.append(TortoiseMenu(_("Create Repository Here"), + 'clone', icon="menuclone.ico")) + caninit = repo.root != rpath and os.path.isdir(rpath) + if caninit: + menu.append(TortoiseMenu(_("Create Repository Here"),   _("create a new repository in this directory"), - self.handlers._init, icon="menucreaterepos.ico", - state=can_init)) + 'init', icon="menucreaterepos.ico"))     # config settings menu   menu.append(TortoiseMenuSep()) @@ -261,18 +260,17 @@
  icon="menusettings.ico")   optmenu.add_menu(_("Global"),   _("Configure user wide settings"), - self.handlers._config_user, icon="settings_user.ico") + 'userconfig', icon="settings_user.ico")   if repo:   optmenu.add_menu(_("Repository"),   _("Configure settings local to this repository"), - self.handlers._config_repo, - icon="settings_repo.ico") + 'repoconfig', icon="settings_repo.ico")   menu.append(optmenu)     # add common menu items   menu.append(TortoiseMenuSep())   menu.append(TortoiseMenu(_("About"), _("About TortoiseHg"), - self.handlers._about, icon="menuabout.ico")) + 'about', icon="menuabout.ico"))     thgmenu.append(menu)   thgmenu.append(TortoiseMenuSep())