Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.7, 0.7.1, and 0.7.2

rename: start a rename dialog

Initially, just add a quick dialog to allow renaming from
the shell context menu. It simply calls 'hg mv old new'.
99% of the time, this is all you need.

Changeset 78030fddc3f6

Parent 62ec1295c074

by Steve Borho

Changes to one file · Browse files at 78030fddc3f6 Showing diff from parent 62ec1295c074 Diff from another changeset...

Change 1 of 1 Show Entire File hggtk/​rename.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,74 @@
+# +# rename.py - TortoiseHg's dialogs for handling renames +# +# Copyright (C) 2009 Steve Borho <steve@borho.org> +# + +import os +import sys +import gtk +from shlib import shell_notify +from mercurial import hg, ui, commands, match +from mercurial.repo import RepoError + +class DetectRenameDialog(gtk.Window): + """ Detect renames after they occur """ + def __init__(self, root=''): + """ Initialize the Dialog """ + gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) + + self.root = root + self.set_title('Detect Renames in %s' + os.path.basename(root)) + + adjustment = gtk.Adjustment(50, 0, 100, 1) + adjustment.connect('value-changed', self._adj_changed) + hscale = gtk.HScale(adjustment) + self.add(mainvbox) + + def _adj_changed(self, adj): + print adj.get_value() + +def run(fname='', **opts): + from dialog import entry_dialog + title = 'Rename ' + fname + dialog = entry_dialog(None, title, True, fname, rename_resp) + dialog.orig = fname + dialog.show_all() + dialog.connect('destroy', gtk.main_quit) + gtk.gdk.threads_init() + gtk.gdk.threads_enter() + gtk.main() + gtk.gdk.threads_leave() + +def rename_resp(dialog, response): + if response != gtk.RESPONSE_OK: + print 'no response' + gtk.main_quit() + return + try: + import hglib + root = hglib.rootpath() + repo = hg.repository(ui.ui(), root) + except ImportError, RepoError: + gtk.main_quit() + return + + new_name = dialog.entry.get_text() + opts = {} + opts['force'] = False # Checkbox? Nah. + opts['after'] = False + opts['dry_run'] = False + + # Sigh, some errors go to stdout, which is regrettable + repo.ui.pushbuffer() + commands.rename(repo.ui, repo, dialog.orig, new_name, **opts) + out = repo.ui.popbuffer() + if out: + from dialog import error_dialog + dialog = error_dialog(None, 'rename error', out) + dialog.run() + gtk.main_quit() + +if __name__ == "__main__": + opts = {'fname' : sys.argv[1]} + run(**opts)