Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.1, 1.1.1, and 1.1.2

status: extract action functions into new file statusact.py

Changeset cfc4cedefd70

Parent 802e4954cf8a

by Adrian Buehlmann

Changes to 2 files · Browse files at cfc4cedefd70 Showing diff from parent 802e4954cf8a Diff from another changeset...

 
15
16
17
18
 
19
20
21
22
 
23
24
 
25
26
27
 
92
93
94
 
95
96
97
 
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
 
1366
1367
1368
1369
 
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
 
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
 
1459
1460
 
1461
1462
1463
 
1483
1484
1485
1486
 
1487
1488
1489
 
1492
1493
1494
1495
 
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
 
1608
1609
1610
1611
 
1612
1613
 
1614
1615
1616
1617
1618
1619
 
1620
1621
1622
 
1623
1624
1625
 
1626
1627
1628
 
1651
1652
1653
1654
 
1655
1656
 
1657
1658
1659
 
15
16
17
 
18
19
20
21
 
22
23
 
24
25
26
27
 
92
93
94
95
96
97
98
 
934
935
936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
937
938
939
 
1292
1293
1294
 
1295
1296
1297
1298
1299
1300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1301
1302
1303
 
1304
1305
1306
1307
1308
1309
 
 
 
 
 
 
 
 
 
 
 
 
1310
1311
1312
1313
 
1314
1315
 
1316
1317
1318
1319
 
1339
1340
1341
 
1342
1343
1344
1345
 
1348
1349
1350
 
1351
1352
1353
1354
1355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1356
1357
1358
 
1444
1445
1446
 
1447
1448
 
1449
1450
1451
1452
1453
1454
 
1455
1456
1457
 
1458
1459
1460
 
1461
1462
1463
1464
 
1487
1488
1489
 
1490
1491
 
1492
1493
1494
1495
@@ -15,13 +15,13 @@
 import pango  import threading   -from mercurial import cmdutil, util, commands, patch, mdiff, error, hg +from mercurial import cmdutil, util, patch, mdiff, error, hg  from mercurial import merge as merge_    from tortoisehg.util.i18n import _ -from tortoisehg.util import hglib, shlib, paths, hgshelve +from tortoisehg.util import hglib, paths, hgshelve   -from tortoisehg.hgtk import dialog, gdialog, gtklib, guess, hgignore, statusbar +from tortoisehg.hgtk import dialog, gdialog, gtklib, guess, hgignore, statusbar, statusact    # file model row enumerations  FM_CHECKED = 0 @@ -92,6 +92,7 @@
  self.preview_tab_name_label = None   self.subrepos = []   self.colorstyle = self.repo.ui.config('tortoisehg', 'diffcolorstyle') + self.act = statusact.statusact(self)     def auto_check(self):   # Only auto-check files once, and only if a pattern was given. @@ -933,81 +934,6 @@
  text_renderer.set_property('foreground', gtklib.NORMAL)     - def rename_file(self, wfile): - fdir, fname = os.path.split(wfile) - utf_fname = hglib.toutf(fname) - newfile = dialog.entry_dialog(self, _('Rename file to:'), - True, utf_fname) - if newfile and newfile != utf_fname: - self.hg_move([wfile, os.path.join(fdir, hglib.fromutf(newfile))]) - return True - - - def copy_file(self, wfile): - wfile = self.repo.wjoin(wfile) - fdir, fname = os.path.split(wfile) - result = gtklib.NativeSaveFileDialogWrapper(title=_('Copy file to'), - initial=fdir, - filename=fname).run() - if not result: - return - if result != wfile: - self.hg_copy([wfile, result]) - return True - - - def hg_remove(self, files): - wfiles = [self.repo.wjoin(x) for x in files] - if self.count_revs() > 1: - gdialog.Prompt(_('Nothing Removed'), - _('Remove is not enabled when multiple revisions are specified.'), - self).run() - return - - # Create new opts, so nothing unintented gets through - removeopts = self.merge_opts(commands.table['^remove|rm'][1], - ('include', 'exclude')) - def dohgremove(): - commands.remove(self.ui, self.repo, *wfiles, **removeopts) - success, outtext = self._hg_call_wrapper('Remove', dohgremove) - if success: - self.reload_status() - - - def hg_move(self, files): - wfiles = [self.repo.wjoin(x) for x in files] - if self.count_revs() > 1: - gdialog.Prompt(_('Nothing Moved'), _('Move is not enabled when ' - 'multiple revisions are specified.'), self).run() - return - - # Create new opts, so nothing unintented gets through - moveopts = self.merge_opts(commands.table['rename|mv'][1], - ('include', 'exclude')) - def dohgmove(): - #moveopts['force'] = True - commands.rename(self.ui, self.repo, *wfiles, **moveopts) - success, outtext = self._hg_call_wrapper('Move', dohgmove) - if success: - self.reload_status() - - - def hg_copy(self, files): - wfiles = [self.repo.wjoin(x) for x in files] - if self.count_revs() > 1: - gdialog.Prompt(_('Nothing Copied'), _('Copy is not enabled when ' - 'multiple revisions are specified.'), self).run() - return - - # Create new opts, so nothing unintented gets through - cmdopts = self.merge_opts(commands.table['copy|cp'][1], - ('include', 'exclude')) - def dohgcopy(): - commands.copy(self.ui, self.repo, *wfiles, **cmdopts) - success, outtext = self._hg_call_wrapper('Copy', dohgcopy) - if success: - self.reload_status() -   def tree_sel_changed(self, selection, tree, page_num=None):   'Selection changed in file tree'   # page_num may be supplied, if called from switch-page event @@ -1366,98 +1292,28 @@
  def revert_clicked(self, toolbutton, data=None):   revert_list = self.relevant_checked_files('MAR!')   if len(revert_list) > 0: - self.hg_revert(revert_list) + self.act.hg_revert(revert_list)   else:   gdialog.Prompt(_('Nothing Reverted'),   _('No revertable files selected'), self).run()   return True   - - def hg_revert(self, files): - wfiles = [self.repo.wjoin(x) for x in files] - if self.count_revs() > 1: - gdialog.Prompt(_('Nothing Reverted'), - _('Revert not allowed when viewing revision range.'), - self).run() - return - - # Create new opts, so nothing unintented gets through. - revertopts = self.merge_opts(commands.table['revert'][1], - ('include', 'exclude', 'rev')) - def dohgrevert(): - commands.revert(self.ui, self.repo, *wfiles, **revertopts) - - def filelist(files): - text = '\n'.join(files[:5]) - if len(files) > 5: - text += ' ...\n' - return hglib.toutf(text) - - if self.is_merge(): - res = gdialog.CustomPrompt( - _('Uncommited merge - please select a parent revision'), - _('Revert files to local or other parent?'), - self, (_('&Local'), _('&Other'), _('&Cancel')), 2).run() - if res == 0: - revertopts['rev'] = self.repo[None].p1().rev() - elif res == 1: - revertopts['rev'] = self.repo[None].p2().rev() - else: - return - response = None - else: - # response: 0=Yes, 1=Yes,no backup, 2=Cancel - revs = revertopts['rev'] - if revs and type(revs) == list: - revertopts['rev'] = revs[0] - else: - revertopts['rev'] = str(self.repo['.'].rev()) - response = gdialog.CustomPrompt(_('Confirm Revert'), - _('Revert files to revision %s?\n\n%s') % (revertopts['rev'], - filelist(files)), self, (_('&Yes (backup changes)'), - _('Yes (&discard changes)'), - _('&Cancel')), 2, 2).run() - if response in (None, 0, 1): - if response == 1: - revertopts['no_backup'] = True - success, outtext = self._hg_call_wrapper('Revert', dohgrevert) - if success: - shlib.shell_notify(wfiles) - self.reload_status() - - def hg_forget(self, files): - wfiles = [self.repo.wjoin(x) for x in files] - commands.forget(self.ui, self.repo, *wfiles) - self.reload_status() -   def add_clicked(self, toolbutton, data=None):   add_list = self.relevant_checked_files('?I')   if len(add_list) > 0: - self.hg_add(add_list) + self.act.hg_add(add_list)   else:   gdialog.Prompt(_('Nothing Added'),   _('No addable files selected'), self).run()   return True   - def hg_add(self, files): - wfiles = [self.repo.wjoin(x) for x in files] - # Create new opts, so nothing unintented gets through - addopts = self.merge_opts(commands.table['^add'][1], - ('include', 'exclude')) - def dohgadd(): - commands.add(self.ui, self.repo, *wfiles, **addopts) - success, outtext = self._hg_call_wrapper('Add', dohgadd) - if success: - shlib.shell_notify(wfiles) - self.reload_status() -   def remove_clicked(self, toolbutton, data=None):   remove_list = self.relevant_checked_files('C!')   delete_list = self.relevant_checked_files('?I')   if len(remove_list) > 0: - self.hg_remove(remove_list) + self.act.hg_remove(remove_list)   if len(delete_list) > 0: - self.delete_files(delete_list) + self.act.delete_files(delete_list)   if not remove_list and not delete_list:   gdialog.Prompt(_('Nothing Removed'),   _('No removable files selected'), self).run() @@ -1483,7 +1339,7 @@
    # move the files to dest directory   move_list.append(hglib.fromutf(destdir)) - self.hg_move(move_list) + self.act.hg_move(move_list)   else:   gdialog.Prompt(_('Nothing Moved'), _('No movable files selected\n\n'   'Note: only clean files can be moved.'), self).run() @@ -1492,31 +1348,11 @@
  def forget_clicked(self, toolbutton, data=None):   forget_list = self.relevant_checked_files('CM')   if len(forget_list) > 0: - self.hg_forget(forget_list) + self.act.hg_forget(forget_list)   else:   gdialog.Prompt(_('Nothing Forgotten'),   _('No clean files selected'), self).run()   - def delete_files(self, files): - dlg = gdialog.Confirm(_('Confirm Delete Unrevisioned'), files, self, - _('Delete the following unrevisioned files?')) - if dlg.run() == gtk.RESPONSE_YES: - errors = '' - for wfile in files: - try: - os.unlink(self.repo.wjoin(wfile)) - except Exception, inst: - errors += str(inst) + '\n\n' - - if errors: - errors = errors.replace('\\\\', '\\') - if len(errors) > 500: - errors = errors[:errors.find('\n',500)] + '\n...' - gdialog.Prompt(_('Delete Errors'), errors, self).run() - - self.reload_status() - return True -   def ignoremask_updated(self):   '''User has changed the ignore mask in hgignore dialog'''   self.opts['check'] = True @@ -1608,21 +1444,21 @@
  def other(menuitem, files):   self._view_files(files, True)   def revert(menuitem, files): - self.hg_revert(files) + self.act.hg_revert(files)   def remove(menuitem, files): - self.hg_remove(files) + self.act.hg_remove(files)   def log(menuitem, files):   from tortoisehg.hgtk import history   dlg = history.run(self.ui, canonpats=files)   dlg.display()   def forget(menuitem, files, paths): - self.hg_forget(files) + self.act.hg_forget(files)   self.set_file_states(paths, state=False)   def add(menuitem, files, paths): - self.hg_add(files) + self.act.hg_add(files)   self.set_file_states(paths, state=True)   def delete(menuitem, files): - self.delete_files(files) + self.act.delete_files(files)   def unmark(menuitem, files):   ms = merge_.mergestate(self.repo)   for wfile in files: @@ -1651,9 +1487,9 @@
  else:   del os.environ['HGMERGE']   def rename(menuitem, files): - self.rename_file(files[0]) + self.act.rename_file(files[0])   def copy(menuitem, files): - self.copy_file(files[0]) + self.act.copy_file(files[0])   def guess_rename(menuitem, files):   dlg = guess.DetectRenameDialog()   dlg.show_all()
Change 1 of 1 Show Entire File tortoisehg/​hgtk/​statusact.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
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
@@ -0,0 +1,193 @@
+# statusact.py - actions for status dialog for TortoiseHg +# +# Copyright 2007 Brad Schick, brad at gmail . com +# Copyright 2007 TK Soh <teekaysoh@gmail.com> +# Copyright 2008 Steve Borho <steve@borho.org> +# Copyright 2008 Emmanuel Rosa <goaway1000@gmail.com> +# +# 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 + +from mercurial import commands + +from tortoisehg.util import hglib, shlib +from tortoisehg.util.i18n import _ + +from tortoisehg.hgtk import dialog, gdialog, gtklib + + +class statusact(object): + + def __init__(self, stat): + self.stat = stat + + def rename_file(self, wfile): + fdir, fname = os.path.split(wfile) + utf_fname = hglib.toutf(fname) + newfile = dialog.entry_dialog(self.stat, _('Rename file to:'), + True, utf_fname) + if newfile and newfile != utf_fname: + self.hg_move([wfile, os.path.join(fdir, hglib.fromutf(newfile))]) + return True + + + def copy_file(self, wfile): + wfile = self.stat.repo.wjoin(wfile) + fdir, fname = os.path.split(wfile) + result = gtklib.NativeSaveFileDialogWrapper(title=_('Copy file to'), + initial=fdir, + filename=fname).run() + if not result: + return + if result != wfile: + self.hg_copy([wfile, result]) + return True + + + def hg_remove(self, files): + wfiles = [self.stat.repo.wjoin(x) for x in files] + if self.stat.count_revs() > 1: + gdialog.Prompt(_('Nothing Removed'), + _('Remove is not enabled when multiple revisions are specified.'), + self.stat).run() + return + + # Create new opts, so nothing unintented gets through + removeopts = self.stat.merge_opts(commands.table['^remove|rm'][1], + ('include', 'exclude')) + def dohgremove(): + commands.remove(self.stat.ui, self.stat.repo, *wfiles, **removeopts) + success, outtext = self.stat._hg_call_wrapper('Remove', dohgremove) + if success: + self.stat.reload_status() + + + def hg_move(self, files): + wfiles = [self.stat.repo.wjoin(x) for x in files] + if self.stat.count_revs() > 1: + gdialog.Prompt(_('Nothing Moved'), _('Move is not enabled when ' + 'multiple revisions are specified.'), self.stat).run() + return + + # Create new opts, so nothing unintented gets through + moveopts = self.stat.merge_opts(commands.table['rename|mv'][1], + ('include', 'exclude')) + def dohgmove(): + #moveopts['force'] = True + commands.rename(self.stat.ui, self.stat.repo, *wfiles, **moveopts) + success, outtext = self.stat._hg_call_wrapper('Move', dohgmove) + if success: + self.stat.reload_status() + + + def hg_copy(self, files): + wfiles = [self.stat.repo.wjoin(x) for x in files] + if self.stat.count_revs() > 1: + gdialog.Prompt(_('Nothing Copied'), _('Copy is not enabled when ' + 'multiple revisions are specified.'), self).run() + return + + # Create new opts, so nothing unintented gets through + cmdopts = self.stat.merge_opts(commands.table['copy|cp'][1], + ('include', 'exclude')) + def dohgcopy(): + commands.copy(self.stat.ui, self.stat.repo, *wfiles, **cmdopts) + success, outtext = self.stat._hg_call_wrapper('Copy', dohgcopy) + if success: + self.stat.reload_status() + + + def hg_revert(self, files): + wfiles = [self.stat.repo.wjoin(x) for x in files] + if self.stat.count_revs() > 1: + gdialog.Prompt(_('Nothing Reverted'), + _('Revert not allowed when viewing revision range.'), + self.stat).run() + return + + # Create new opts, so nothing unintented gets through. + revertopts = self.stat.merge_opts(commands.table['revert'][1], + ('include', 'exclude', 'rev')) + def dohgrevert(): + commands.revert(self.stat.ui, self.stat.repo, *wfiles, **revertopts) + + def filelist(files): + text = '\n'.join(files[:5]) + if len(files) > 5: + text += ' ...\n' + return hglib.toutf(text) + + if self.stat.is_merge(): + res = gdialog.CustomPrompt( + _('Uncommited merge - please select a parent revision'), + _('Revert files to local or other parent?'), + self.stat, (_('&Local'), _('&Other'), _('&Cancel')), 2).run() + if res == 0: + revertopts['rev'] = self.stat.repo[None].p1().rev() + elif res == 1: + revertopts['rev'] = self.stat.repo[None].p2().rev() + else: + return + response = None + else: + # response: 0=Yes, 1=Yes,no backup, 2=Cancel + revs = revertopts['rev'] + if revs and type(revs) == list: + revertopts['rev'] = revs[0] + else: + revertopts['rev'] = str(self.stat.repo['.'].rev()) + response = gdialog.CustomPrompt(_('Confirm Revert'), + _('Revert files to revision %s?\n\n%s') % (revertopts['rev'], + filelist(files)), self.stat, (_('&Yes (backup changes)'), + _('Yes (&discard changes)'), + _('&Cancel')), 2, 2).run() + if response in (None, 0, 1): + if response == 1: + revertopts['no_backup'] = True + success, outtext = self.stat._hg_call_wrapper('Revert', dohgrevert) + if success: + shlib.shell_notify(wfiles) + self.stat.reload_status() + + + def hg_forget(self, files): + wfiles = [self.stat.repo.wjoin(x) for x in files] + commands.forget(self.stat.ui, self.stat.repo, *wfiles) + self.stat.reload_status() + + + def hg_add(self, files): + wfiles = [self.stat.repo.wjoin(x) for x in files] + # Create new opts, so nothing unintented gets through + addopts = self.stat.merge_opts(commands.table['^add'][1], + ('include', 'exclude')) + def dohgadd(): + commands.add(self.stat.ui, self.stat.repo, *wfiles, **addopts) + success, outtext = self.stat._hg_call_wrapper('Add', dohgadd) + if success: + shlib.shell_notify(wfiles) + self.stat.reload_status() + + + def delete_files(self, files): + dlg = gdialog.Confirm(_('Confirm Delete Unrevisioned'), files, self.stat, + _('Delete the following unrevisioned files?')) + if dlg.run() == gtk.RESPONSE_YES: + errors = '' + for wfile in files: + try: + os.unlink(self.stat.repo.wjoin(wfile)) + except Exception, inst: + errors += str(inst) + '\n\n' + + if errors: + errors = errors.replace('\\\\', '\\') + if len(errors) > 500: + errors = errors[:errors.find('\n',500)] + '\n...' + gdialog.Prompt(_('Delete Errors'), errors, self.stat).run() + + self.stat.reload_status() + return True