Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

quickop: begin to implement a Qt quickop application

Changeset e293f9b3a8b5

Parent cc633e6fc2b6

by Steve Borho

Changes to 2 files · Browse files at e293f9b3a8b5 Showing diff from parent cc633e6fc2b6 Diff from another changeset...

Change 1 of 2 Show Entire File tortoisehg/​hgqt/​quickop.py Stacked
copied from tortoisehg/hgtk/quickop.py
 
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
 
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
 
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
 
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
@@ -6,28 +6,32 @@
 # GNU General Public License version 2, incorporated herein by reference.    import os -import gtk -import pango   -from mercurial import cmdutil, util +from mercurial import hg, ui, cmdutil, util + +from PyQt4 import QtCore, QtGui    from tortoisehg.util.i18n import _ -from tortoisehg.util import hglib, shlib +from tortoisehg.util import hglib, shlib, paths   -from tortoisehg.hgtk import gtklib, gdialog +from tortoisehg.hgqt import qtlib, status    LABELS = { 'add': (_('Select files to add'), _('Add')),   'forget': (_('Select files to forget'), _('Forget')),   'revert': (_('Select files to revert'), _('Revert')),   'remove': (_('Select files to remove'), _('Remove')),}   -DEFAULT_SIZE = (450, 300) -DEFAULT_POS = (0, 0) +# Technical Debt +# +# show LABELS[cmd][0] somewhere +# persistent geometry +# command running functionality +# perhaps a check for no applicable files   -class QuickOpDialog(gdialog.GDialog): +class QuickOpDialog(QtGui.QDialog):   """ Dialog for performing quick dirstate operations """ - def __init__(self, command, pats): - gdialog.GDialog.__init__(self, resizable=True) + def __init__(self, command, pats, parent=None): + QtGui.QDialog.__init__(self, parent)   self.pats = pats     # Handle rm alias @@ -35,252 +39,48 @@
  command = 'remove'   self.command = command   - # show minimize/maximize buttons - self.realize() - if self.window: - self.window.set_decorations(gtk.gdk.DECOR_ALL) + repo = hg.repository(ui.ui(), path=paths.find_root()) + os.chdir(repo.root) + assert repo + self.setWindowTitle('%s - hg %s' % (hglib.get_reponame(repo), command))   - ### Start of Overriding Section ### + layout = QtGui.QVBoxLayout() + self.setLayout(layout)   - def get_title(self, reponame): - return reponame + ' - hg ' + self.command - - def get_icon(self): - return 'hg.ico' - - def get_defsize(self): - return self.defsize - - def get_setting_name(self): - return 'quickop' - - def get_body(self, vbox): - os.chdir(self.repo.root) - - # wrap box - wrapbox = gtk.VBox() - wrapbox.set_border_width(5) - vbox.pack_start(wrapbox, True, True) - self.wrapbox = wrapbox - - lbl = gtk.Label(LABELS[self.command][0]) - lbl.set_alignment(0, 0) - wrapbox.pack_start(lbl, False, False) - - def keypressed(tree, event): - 'Make spacebar toggle selected rows' - if event.keyval != 32: - return False - def toggler(model, path, bufiter): - model[path][0] = not model[path][0] - selection = tree.get_selection() - selection.selected_foreach(toggler) - return True - - # add file list treeview - fm = gtk.ListStore(bool, # Checked - str, # Path - str, # Path-UTF8 - str) # Status - self.filetree = gtk.TreeView(fm) - self.filetree.connect('key-press-event', keypressed) - self.filetree.set_headers_clickable(True) - self.filetree.set_reorderable(False) - if hasattr(self.filetree, 'set_rubber_banding'): - self.filetree.set_rubber_banding(True) - fontlist = hglib.getfontconfig()['fontlist'] - self.filetree.modify_font(pango.FontDescription(fontlist)) - - def select_toggle(cell, path): - fm[path][0] = not fm[path][0] - - # file selection checkboxes - toggle_cell = gtk.CellRendererToggle() - toggle_cell.connect('toggled', select_toggle) - toggle_cell.set_property('activatable', True) - - col = gtk.TreeViewColumn('', toggle_cell, active=0) - col.set_resizable(False) - self.filetree.append_column(col) - - col = gtk.TreeViewColumn(_('status'), gtk.CellRendererText(), text=3) - self.filetree.append_column(col) - - col = gtk.TreeViewColumn(_('path'), gtk.CellRendererText(), text=2) - self.filetree.append_column(col) - - scroller = gtk.ScrolledWindow() - scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - scroller.set_shadow_type(gtk.SHADOW_ETCHED_IN) - scroller.add(self.filetree) - wrapbox.pack_start(scroller, True, True, 6) - - def toggleall(button): - for row in self.filetree.get_model(): - row[0] = not row[0] - - # extra box - self.extrabox = hbox = gtk.HBox() - wrapbox.pack_start(hbox, False, False) - - ## toggle button - tb = gtk.Button(_('Toggle all selections')) - tb.connect('pressed', toggleall) - hbox.pack_start(tb, False, False) - - if self.command == 'revert': - ## no backup checkbox - chk = gtk.CheckButton(_('Do not save backup files (*.orig)')) - hbox.pack_start(chk, False, False, 6) - self.nobackup = chk - - ## padding - hbox.pack_start(gtk.Label()) - - types = { 'add' : 'I?', + types = { 'add' : 'I?',   'forget' : 'MAR!C',   'revert' : 'MAR!',   'remove' : 'MAR!CI?',   }   filetypes = types[self.command]   - try: - matcher = cmdutil.match(self.repo, self.pats) - status = self.repo.status(match=matcher, - clean='C' in filetypes, - ignored='I' in filetypes, - unknown='?' in filetypes) - except (IOError, util.Abort), e: - gdialog.Prompt(_('Unable to determine repository status'), - str(e), self).run() - self.earlyout=True - self.hide() - return + opts = {} + for s, val in status.statusTypes.iteritems(): + opts[val.name] = s in filetypes   - (modified, added, removed, deleted, unknown, ignored, clean) = status - if 'M' in filetypes: - for f in modified: - fm.append([True, f, hglib.toutf(f), _('modified')]) - if 'A' in filetypes: - for f in added: - fm.append([True, f, hglib.toutf(f), _('added')]) - if 'R' in filetypes: - for f in removed: - fm.append([True, f, hglib.toutf(f), _('removed')]) - if '!' in filetypes: - for f in deleted: - fm.append([True, f, hglib.toutf(f), _('missing')]) - if '?' in filetypes: - for f in unknown: - fm.append([True, f, hglib.toutf(f), _('unknown')]) - if 'I' in filetypes: - for f in ignored: - if self.command == 'remove' or f in self.pats: - fm.append([True, f, hglib.toutf(f), _('ignored')]) - if 'C' in filetypes: - for f in clean: - if self.command == 'remove' or f in self.pats: - fm.append([True, f, hglib.toutf(f), _('clean')]) + stwidget = status.StatusWidget(pats, opts, self) + layout.addWidget(stwidget)   - if not len(fm): - gdialog.Prompt(_('No appropriate files'), - _('No files found for this operation'), self).run() - self.earlyout=True - self.hide() + if self.command == 'revert': + ## no backup checkbox + chk = QtGui.QCheckBox(_('Do not save backup files (*.orig)')) + layout.addWidget(chk)   - def get_buttons(self): - return [('go', LABELS[self.command][1], gtk.RESPONSE_OK), - ('cancel', gtk.STOCK_CANCEL, gtk.RESPONSE_CLOSE)] + BB = QtGui.QDialogButtonBox + bb = QtGui.QDialogButtonBox(BB.Ok|BB.Cancel) + self.connect(bb, QtCore.SIGNAL("accepted()"), + self, QtCore.SLOT("accept()")) + self.connect(bb, QtCore.SIGNAL("rejected()"), + self, QtCore.SLOT("reject()")) + bb.button(BB.Ok).setDefault(True) + bb.button(BB.Ok).setText(LABELS[command][1]) + layout.addWidget(bb)   - def get_default_button(self): - return 'go' + def accept(self): + QtGui.QDialog.accept(self)   - def get_action_map(self): - return {gtk.RESPONSE_OK: self.operation} - - def switch_to(self, normal, working, cmd): - self.wrapbox.set_sensitive(normal) - self.buttons['go'].set_property('visible', normal) - self.buttons['cancel'].set_property('visible', normal) - if normal: - self.buttons['cancel'].grab_focus() - - def command_done(self, returncode, useraborted, list): - if returncode == 0: - shlib.shell_notify(list) - self.cmd.set_result(_('Successfully'), style='ok') - elif useraborted: - self.cmd.set_result(_('Canceled'), style='error') - else: - self.cmd.set_result(_('Failed'), style='error') - - def before_show(self): - # restore dialog state - if self.defmax: - self.maximize() - - # restore dialog position - screen = self.get_screen() - w, h = screen.get_width(), screen.get_height() - x, y = self.defpos - if x >= 0 and x < w and y >= 0 and y < h: - self.move(x, y) - - def load_settings(self): - self.defsize = self.settings.get_value('size', DEFAULT_SIZE) - self.defpos = self.settings.get_value('pos', DEFAULT_POS) - self.defmax = self.settings.get_value('maximize', False) - - def store_settings(self): - state = self.window.get_state() - ismaximized = bool(state & gtk.gdk.WINDOW_STATE_MAXIMIZED) - if ismaximized or state & gtk.gdk.WINDOW_STATE_ICONIFIED: - self.settings.set_value('size', DEFAULT_SIZE) - self.settings.set_value('pos', DEFAULT_POS) - else: - rect = self.get_allocation() - self.settings.set_value('size', (rect.width, rect.height)) - self.settings.set_value('pos', self.get_position()) - self.settings.set_value('maximize', ismaximized) - self.settings.write() - - ### End of Overriding Section ### - - def operation(self): - fm = self.filetree.get_model() - deleting = self.command == 'remove' - list, dellist = [], [] - for row in fm: - if not row[0]: continue - if deleting and row[3] in (_('unknown'), _('ignored')): - dellist.append(row[1]) - else: - list.append(row[1]) - - if not (list or dellist): - gdialog.Prompt(_('No files selected'), - _('No operation to perform'), self).run() - return - - for file in dellist: - try: - os.unlink(file) - except IOError: - pass - - if not list: - gtklib.idle_add_single_call(self.response, gtk.RESPONSE_CLOSE) - return - - # prepare command line - cmdline = ['hg', self.command, '--verbose'] - if hasattr(self, 'nobackup') and self.nobackup.get_active(): - cmdline.append('--no-backup') - cmdline.append('--') - cmdline += list - - # execute command - self.execute_command(cmdline, list) + def reject(self): + QtGui.QDialog.reject(self)    def run(ui, *pats, **opts):   pats = hglib.canonpaths(pats)
 
332
333
334
 
 
 
 
 
335
336
337
 
361
362
363
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
365
366
 
600
601
602
 
603
604
605
 
620
621
622
 
 
 
623
624
625
 
332
333
334
335
336
337
338
339
340
341
342
 
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
 
620
621
622
623
624
625
626
 
641
642
643
644
645
646
647
648
649
@@ -332,6 +332,11 @@
  mainapp.exec_()   mainapp = None   +def add(ui, *pats, **opts): + """add files""" + from tortoisehg.hgqt.quickop import run + qtrun(run, ui, *pats, **opts) +  def thgstatus(ui, *pats, **opts):   """update TortoiseHg status cache"""   from tortoisehg.util.thgstatus import run @@ -361,6 +366,21 @@
  opts['nofork'] = True   qtrun(run, ui, *pats, **opts)   +def remove(ui, *pats, **opts): + """remove selected files""" + from tortoisehg.hgqt.quickop import run + qtrun(run, ui, *pats, **opts) + +def revert(ui, *pats, **opts): + """revert selected files""" + from tortoisehg.hgqt.quickop import run + qtrun(run, ui, *pats, **opts) + +def forget(ui, *pats, **opts): + """forget selected files""" + from tortoisehg.hgqt.quickop import run + qtrun(run, ui, *pats, **opts) +  def shellconfig(ui, *pats, **opts):   """Explorer extension configuration editor"""   from tortoisehg.hgqt.shellconf import run @@ -600,6 +620,7 @@
   table = {   "about": (about, [], _('thg about')), + "add": (add, [], _('hgtk add [FILE]...')),   "^clone":   (clone,   [('U', 'noupdate', None, @@ -620,6 +641,9 @@
  (log,   [('l', 'limit', '', _('limit number of changes displayed'))],   _('thg log [OPTIONS] [FILE]')), + "remove|rm": (revert, [], _('hgtk remove [FILE]...')), + "revert": (revert, [], _('hgtk revert [FILE]...')), + "forget": (forget, [], _('hgtk forget [FILE]...')),   "test": (test, [], _('thg test')),   "help": (help_, [], _('thg help [COMMAND]')),   "^update|checkout|co":