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

nautilus: more simplification work for menu generators

menuThg.get_commands() should not have to devine a cwd or repo
from the passed in file list, each platform could have different
schemes. So this command is now passed in repo and cwd, which
will be common. Also, make a separate function for non-repo
menus.

On the nautilus side, fix it up so this logic happens in one
place. Also, send canonized paths to hgproc to make things
more readable to the user (makes paths relative to cwd)

Changeset 283fe96bcb86

Parent 08b697ca6875

by Steve Borho

Changes to 2 files · Browse files at 283fe96bcb86 Showing diff from parent 08b697ca6875 Diff from another changeset...

 
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 
 
133
134
135
 
137
138
139
140
141
142
143
 
 
144
145
146
147
 
148
149
150
151
 
152
153
154
155
 
156
157
158
 
163
164
165
166
 
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
169
170
171
172
173
 
174
175
176
 
204
205
206
207
 
208
209
210
211
212
 
213
214
215
 
118
119
120
 
 
 
 
 
 
 
 
 
 
 
 
121
122
123
124
125
 
127
128
129
 
 
 
 
130
131
132
133
134
 
135
136
137
138
 
139
140
141
142
 
143
144
145
146
 
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
 
206
207
208
 
209
210
211
212
213
 
214
215
216
217
@@ -118,18 +118,8 @@
  '''   hgcmd - hgproc subcommand   ''' - paths = self.files - if paths[0] is None: - return - - path = paths[0] - repo = self.get_repo_for_path(path) - cwd = os.path.isdir(path) and path or os.path.dirname(path) - - if repo is not None: - root = repo.root - else: - root = cwd + cwd = self.cwd + repo = self.get_repo_for_path(cwd)     if hgcmd == 'vdiff':   diffcmd = repo.ui.config('tortoisehg', 'vdiff', None) @@ -137,22 +127,20 @@
  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) + cmdline.extend(self.files) + subprocess.Popen(cmdline, shell=False, env=self.env, cwd=cwd)   return     cmdopts = [sys.executable, self.hgproc] - cmdopts += ['--root', root] + if repo: cmdopts += ['--root', repo.root]   cmdopts += ['--cwd', cwd]   cmdopts += ['--command', hgcmd]   - if hgcmd not in nofilecmds: + if hgcmd not in nofilecmds and self.files:   # 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.write(fd, "\n".join(self.files))   os.close(fd)   cmdopts += ['--listfile', tmpfile, '--deletelistfile']   @@ -163,14 +151,28 @@
  self.cacherepo = None   self.cacheroot = None   - def buildMenu(self, menuf, vfsfile): + def buildMenu(self, vfs_files, bg):   '''Build menu''' + self.pos = 0 + self.files = [] + files = [self.get_path_for_vfs_file(f) for f in vfs_files] + if bg: + cwd = files[0] + files = [] + repo = self.get_repo_for_path(cwd) + else: + cwd = os.path.dirname(files[0]) + repo = self.get_repo_for_path(cwd) + if repo: + menus = self.menu.get_commands(repo, cwd, files) + for f in files: + self.files.append(util.canonpath(repo.root, cwd, f)) + else: + menus = self.menu.get_norepo_commands(cwd, files) + self.cwd = cwd + return self._buildMenu(menus)   - self.files = [self.get_path_for_vfs_file(f) for f in vfsfile] - self.pos = 0 - return self._buildMenu(menuf(self.files)) - - def _buildMenu(self, menus, pos=0): + def _buildMenu(self, menus):   '''Build menu'''   items = []   for menu_info in menus: @@ -204,12 +206,12 @@
  def get_background_items(self, window, vfs_file):   '''Build context menu for current directory'''   if vfs_file and self.menu: - return self.buildMenu(self.menu.get_commands, [vfs_file]) + return self.buildMenu([vfs_file], True)     def get_file_items(self, window, vfs_files):   '''Build context menu for selected files/directories'''   if vfs_files and self.menu: - return self.buildMenu(self.menu.get_commands, vfs_files) + return self.buildMenu(vfs_files, False)     def get_columns(self):   return nautilus.Column("HgNautilus::80hg_status",
 
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
 
261
262
263
264
265
266
267
 
 
 
268
269
270
 
275
276
277
278
 
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
 
257
258
259
 
 
 
 
260
261
262
263
264
265
 
270
271
272
 
@@ -117,142 +117,138 @@
  'synch', icon="menusynch.py"))   return thgmenu   - def get_commands(self, files): + def get_norepo_commands(self, cwd, files): + thgmenu = [] + menu = TortoiseSubmenu(self.name, "Mercurial", [], icon="hg.ico") + menu.append(TortoiseMenu(_("Clone a Repository"), + _("clone a repository"), + 'clone', icon="menuclone.ico")) + menu.append(TortoiseMenu(_("Create Repository Here"), + _("create a new repository in this directory"), + 'init', icon="menucreaterepos.ico")) + menu.append(TortoiseMenu(_("Global Settings"), + _("Configure user wide settings"), + 'userconfig', icon="settings_user.ico")) + menu.append(TortoiseMenuSep()) + menu.append(TortoiseMenu(_("About"), _("About TortoiseHg"), + 'about', icon="menuabout.ico")) + thgmenu.append(menu) + thgmenu.append(TortoiseMenuSep()) + return thgmenu + + def get_commands(self, repo, cwd, files):   """   Get a list of commands valid for the current selection.     Commands are instances of TortoiseMenu, TortoiseMenuSep or TortoiseMenu   """ - # open repo - if type(files) != list: - files = [files] - if not files: - return [] - rpath = files[0] - repo = open_repo(rpath) -   thgmenu = [] - - if repo: - thgmenu.append(TortoiseMenu(_("HG Commit..."), - _("Commit changes in repository"), - 'commit', icon="menucommit.ico")) + thgmenu.append(TortoiseMenu(_("HG Commit..."), + _("Commit changes in repository"), + 'commit', icon="menucommit.ico"))     menu = TortoiseSubmenu(self.name, "Mercurial", [], icon="hg.ico") + canannotate = len(files) > 0 + hashgignore = False + for f in files: + if not os.path.isfile(f): + canannotate = False + if f.endswith('.hgignore'): + hashgignore = True   - if repo is None: - menu.append(TortoiseMenu(_("Clone a Repository"), - _("clone a repository"), - 'clone', icon="menuclone.ico")) - if os.path.isdir(rpath): - menu.append(TortoiseMenu(_("Create Repository Here"), - _("create a new repository in this directory"), - 'init', icon="menucreaterepos.ico")) - else: - canannotate = len(files) > 0 - hashgignore = False - for f in files: - if not os.path.isfile(f): - canannotate = False - if f.endswith('.hgignore'): - hashgignore = True + if hashgignore: # needs ico + menu.append(TortoiseMenu(_("Edit Ignore Filter"), + _("Edit repository ignore filter"), + 'hgignore', icon="general.ico"))   - if hashgignore: # needs ico - menu.append(TortoiseMenu(_("Edit Ignore Filter"), - _("Edit repository ignore filter"), - 'hgignore', icon="general.ico")) - - menu.append(TortoiseMenu(_("View File Status"), - _("Repository status"), - 'status', icon="menushowchanged.ico")) + menu.append(TortoiseMenu(_("View File Status"), + _("Repository status"), + 'status', icon="menushowchanged.ico"))   - menu.append(TortoiseMenu(_("Shelve Changes"), - _("Shelve or unshelve repository changes"), - 'shelve', icon="general.ico")) # needs ico + menu.append(TortoiseMenu(_("Shelve Changes"), + _("Shelve or unshelve repository changes"), + 'shelve', icon="general.ico")) # needs ico   - # Visual Diff (any extdiff command) - has_vdiff = repo.ui.config('tortoisehg', 'vdiff', '') != '' - if has_vdiff: - menu.append(TortoiseMenu(_("Visual Diff"), + # Visual Diff (any extdiff command) + has_vdiff = repo.ui.config('tortoisehg', 'vdiff', '') != '' + if has_vdiff: + menu.append(TortoiseMenu(_("Visual Diff"),   _("View changes using GUI diff tool"),   'vdiff', icon="TortoiseMerge.ico"))   - if len(files) == 0: # needs ico - menu.append(TortoiseMenu(_("Guess Renames"), - _("Detect renames and copies"), - 'guess', icon="general.ico")) - elif len(files) == 1: # needs ico - menu.append(TortoiseMenu(_("Rename File"), - _("Rename file or directory"), - 'rename', icon="general.ico")) + if len(files) == 0: # needs ico + menu.append(TortoiseMenu(_("Guess Renames"), + _("Detect renames and copies"), + 'guess', icon="general.ico")) + elif len(files) == 1: # needs ico + menu.append(TortoiseMenu(_("Rename File"), + _("Rename file or directory"), + 'rename', icon="general.ico"))   - if len(files): - menu.append(TortoiseMenu(_("Add Files"), - _("Add files to Hg repository"), - 'add', icon="menuadd.ico")) - menu.append(TortoiseMenu(_("Remove Files"), - _("Remove selected files on the next commit"), - 'remove', icon="menudelete.ico")) - menu.append(TortoiseMenu(_("Undo Changes"), - _("Revert selected files"), - 'revert', icon="menurevert.ico")) + if len(files): + menu.append(TortoiseMenu(_("Add Files"), + _("Add files to Hg repository"), + 'add', icon="menuadd.ico")) + menu.append(TortoiseMenu(_("Remove Files"), + _("Remove selected files on the next commit"), + 'remove', icon="menudelete.ico")) + menu.append(TortoiseMenu(_("Undo Changes"), + _("Revert selected files"), + 'revert', icon="menurevert.ico"))   - # we can only annotate file but not directories - if canannotate: - menu.append(TortoiseMenu(_("Annotate Files"), + # we can only annotate file but not directories + if canannotate: + menu.append(TortoiseMenu(_("Annotate Files"),   _("show changeset information per file line"), - 'annotate', icon="menublame.ico")) + 'datamine', icon="menublame.ico"))   - menu.append(TortoiseMenuSep()) - menu.append(TortoiseMenu(_("Update To Revision"), - _("update working directory"), - 'update', icon="menucheckout.ico")) + menu.append(TortoiseMenuSep()) + menu.append(TortoiseMenu(_("Update To Revision"), + _("update working directory"), + 'update', icon="menucheckout.ico"))   - canmerge = len(repo.heads()) > 1 and \ - len(repo.changectx(None).parents()) < 2 - if canmerge: - menu.append(TortoiseMenu(_("Merge Revisions"), - _("merge working directory with another revision"), - 'merge', icon="menumerge.ico")) + if len(repo.changectx(None).parents()) < 2: + menu.append(TortoiseMenu(_("Merge Revisions"), + _("merge working directory with another revision"), + 'merge', icon="menumerge.ico"))   - inmerge = len(repo.changectx(None).parents()) > 1 - if inmerge: - menu.append(TortoiseMenu(_("Undo Merge"), - _("Undo merge by updating to revision"), - 'unmerge', icon="menuunmerge.ico")) + inmerge = len(repo.changectx(None).parents()) > 1 + if inmerge: + menu.append(TortoiseMenu(_("Undo Merge"), + _("Undo merge by updating to revision"), + 'merge', icon="menuunmerge.ico")) + + menu.append(TortoiseMenuSep()) + + menu.append(TortoiseMenu(_("View Changelog"), + _("View revision history"), + 'history', icon="menulog.ico")) + + if len(files) == 0: + menu.append(TortoiseMenu(_("Search Repository"), + _("Search revisions of files for a text pattern"), + 'grep', icon="menurepobrowse.ico"))     menu.append(TortoiseMenuSep())   - menu.append(TortoiseMenu(_("View Changelog"), - _("View revision history"), - 'history', icon="menulog.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"))   - if len(files) == 0: - menu.append(TortoiseMenu(_("Search Repository"), - _("Search revisions of files for a text pattern"), - 'grep', icon="menurepobrowse.ico")) - - menu.append(TortoiseMenuSep()) - - 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"), - '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"), - 'init', icon="menucreaterepos.ico")) + menu.append(TortoiseMenuSep()) + menu.append(TortoiseMenu(_("Create Clone"), + _("Clone a repository here"), + 'clone', icon="menuclone.ico")) + if repo.root != cwd: + menu.append(TortoiseMenu(_("Create Repository Here"), + _("create a new repository in this directory"), + 'init', icon="menucreaterepos.ico"))     # config settings menu   menu.append(TortoiseMenuSep()) @@ -261,10 +257,9 @@
  optmenu.add_menu(_("Global"),   _("Configure user wide settings"),   'userconfig', icon="settings_user.ico") - if repo: - optmenu.add_menu(_("Repository"), - _("Configure settings local to this repository"), - 'repoconfig', icon="settings_repo.ico") + optmenu.add_menu(_("Repository"), + _("Configure settings local to this repository"), + 'repoconfig', icon="settings_repo.ico")   menu.append(optmenu)     # add common menu items @@ -275,4 +270,3 @@
  thgmenu.append(menu)   thgmenu.append(TortoiseMenuSep())   return thgmenu -