Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

cslist: fix & improve selection feature

Changeset 5664027cc5e7

Parent 03ba81491456

by Yuki KODAMA

Changes to 2 files · Browse files at 5664027cc5e7 Showing diff from parent 03ba81491456 Diff from another changeset...

 
22
23
24
25
26
 
 
 
27
28
29
 
32
33
34
 
 
 
 
 
35
 
 
36
 
37
38
39
 
 
40
41
42
 
87
88
89
90
 
91
92
93
 
110
111
112
113
114
115
116
 
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
 
158
159
160
161
162
 
163
164
 
 
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
167
168
 
173
174
175
176
177
 
 
178
179
180
 
203
204
205
206
207
208
209
210
211
212
213
 
 
214
 
215
216
217
218
219
 
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
 
271
272
273
274
275
 
 
276
277
278
 
279
280
281
 
349
350
351
352
353
354
355
356
 
 
 
 
 
 
357
358
359
 
 
 
360
361
362
 
 
 
 
 
 
 
 
 
 
363
364
365
 
 
 
 
366
367
 
368
369
370
371
372
373
374
 
 
 
375
376
377
 
400
401
402
 
 
 
 
403
404
405
 
22
23
24
 
 
25
26
27
28
29
30
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
48
49
50
51
52
 
97
98
99
 
100
101
102
103
 
120
121
122
 
123
124
125
 
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
 
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
 
199
200
201
 
 
202
203
204
205
206
 
229
230
231
 
 
 
 
 
 
 
 
232
233
234
235
236
 
237
238
239
 
250
251
252
 
 
 
253
254
255
256
257
 
 
 
258
259
260
261
262
 
 
 
 
 
 
 
263
264
265
266
 
 
 
 
 
 
 
 
 
267
268
269
 
273
274
275
 
 
276
277
278
279
 
280
281
282
283
 
351
352
353
 
 
 
 
 
354
355
356
357
358
359
360
361
 
362
363
364
365
 
 
366
367
368
369
370
371
372
373
374
375
376
 
 
377
378
379
380
381
382
383
384
385
386
387
388
 
 
389
390
391
392
393
394
 
417
418
419
420
421
422
423
424
425
426
@@ -22,8 +22,9 @@
  __gsignals__ = {   'list-updated': (gobject.SIGNAL_RUN_FIRST,   gobject.TYPE_NONE, - (object, # number of count or None - object, # number of total or None + (object, # number of all items or None + object, # number of selections or None + object, # number of showings or None   bool, # whether all items are shown   bool)) # whether cslist is updating   } @@ -32,11 +33,20 @@
  gtk.Frame.__init__(self)   self.set_shadow_type(gtk.SHADOW_IN)   + # member variables + self.curitems = None + self.currepo = None + self.showitems = None + self.chkmap = {}   self.limit = 20 + + self.timeout_queue = []   self.sel_enable = False + self.dnd_enable = False     # dnd variables - self.dnd_enable = False + self.itemmap = {} + self.sepmap = {}   self.hlsep = None   self.dnd_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 1, 1)   self.scroll_timer = None @@ -87,7 +97,7 @@
    # signal handlers   self.allbtn.connect('clicked', lambda b: self.update(self.curitems, \ - self.currepo, limit=False, queue=False)) + self.currepo, limit=False, queue=False, keep=True))   self.compactopt.connect('toggled', lambda b: self.update( \   self.curitems, self.currepo, queue=False, keep=True))   @@ -110,7 +120,6 @@
  self.pstyle = csinfo.panelstyle()     # prepare to show - self.clear(noemit=True)   gtklib.idle_add_single_call(self.after_init)     ### public functions ### @@ -120,25 +129,26 @@
  Update the item list.     Public arguments: - items: List of revision numbers and/or patch file path. - You can pass mixed list. The order will be respected. - If omitted, previous items will be used to show them. - Default: None. - repo: Repository used to get changeset information. - If omitted, previous repo will be used to show them. - Default: None. - limit: If True, some of items will be shown. Default: True. - queue: If True, the update request will be queued to prevent - frequent updatings. In some cases, this option will help - to improve UI response. Default: False. + items: List of revision numbers and/or patch file path. + You can pass mixed list. The order will be respected. + If omitted, previous items will be used to show them. + Default: None. + repo: Repository used to get changeset information. + If omitted, previous repo will be used to show them. + Default: None. + limit: If True, some of items will be shown. Default: True. + queue: If True, the update request will be queued to prevent + frequent updatings. In some cases, this option will help + to improve UI response. Default: False.     Internal argument: - keep: If True, it keeps previous 'limit' state after refreshing. - Note that if you use this, 'limit' value will be ignored - and overwritten by previous 'limit' value. Default: False. + keep: If True, it keeps previous selection states and 'limit' value + after refreshing. Note that if you use 'limit' and this options + at the same time, 'limit' value is used against previous value. + Default: False.   - return: True if the item list was updated successfully, - False if it wasn't updated. + return: True if the item list was updated successfully, + False if it wasn't updated.   """   # check parameters   if not items or not repo: @@ -158,11 +168,27 @@
  if kargs.get('keep', False) and self.has_limit() is False:   limit = False   - self.clear(noemit=True) - + # initialize variables   self.curitems = items   self.currepo = repo + self.itemmap = {} + self.sepmap = {}   + if self.sel_enable and not kargs.get('keep', False): + self.chkmap = {} + for item in items: + self.chkmap[item] = True + + # determine items to show + numtotal = len(items) + if limit and self.limit < numtotal: + toshow, lastitem = items[:self.limit-1], items[self.limit-1:][-1] + else: + toshow, lastitem = items, None + numshow = len(toshow) + (lastitem and 1 or 0) + self.showitems = toshow + (lastitem and [lastitem] or []) + + # prepare to update item list   compactview = self.compactopt.get_active()   style = compactview and self.lstyle or self.pstyle   factory = csinfo.factory(repo, withupdate=True) @@ -173,8 +199,8 @@
  info.parent.remove(info)   if self.sel_enable:   check = gtk.CheckButton() - check.set_active(True) - self.chkmap[item] = check + check.set_active(self.chkmap[item]) + check.connect('toggled', self.check_toggled, item)   align = gtk.Alignment(0.5, 0)   align.add(check)   hbox = gtk.HBox() @@ -203,17 +229,11 @@
  snipbox.pack_start(gtk.Label())   self.item_snip = snipbox   - # determine items to show - numtotal = len(items) - if limit and self.limit < numtotal: - toshow, lastitem = items[:self.limit-1], items[self.limit-1:][-1] - else: - toshow, lastitem = items, None - numshow = len(toshow) + (lastitem and 1 or 0) - self.showitems = toshow + (lastitem and [lastitem] or []) + # clear item list + self.csbox.foreach(lambda c: c.parent.remove(c))   + # update item list   def proc(): - # update item list   add_sep(False, 'first', (-1, 0))   for index, r in enumerate(toshow):   add_csinfo(r) @@ -230,38 +250,20 @@
  self.csbox.show_all()     # update status - self.update_status(numshow, numtotal) - self.emit('list-updated', numshow, numtotal, - not self.has_limit(), False) + self.update_status()     if numshow < 80:   proc()   else: - self.update_status(message=_('Updating...')) - self.emit('list-updated', numshow, numtotal, - not self.has_limit(), True) + self.update_status(updating=True)   gtklib.idle_add_single_call(proc)     return True   - def clear(self, noemit=False): - """ - Clear the item list. - - noemit: If True, cslist won't emit 'list-updated' signal. - Default: False. - """ + def clear(self): + """ Clear the item list """   self.csbox.foreach(lambda c: c.parent.remove(c))   self.update_status() - if not noemit: - self.emit('list-updated', None, None, None, None) - self.curitems = None - self.showitems = None - self.currepo = None - self.timeout_queue = [] - self.itemmap = {} - self.chkmap = {} - self.sepmap = {}     def get_items(self, sel=False):   """ @@ -271,11 +273,11 @@
    sel: If True, it returns a list of tuples. Default: False.   """ - if self.curitems: - items = self.curitems + items = self.curitems + if items:   if not sel:   return items - return [(item, self.chkmap[item].get_active()) for item in items] + return [(item, self.chkmap[item]) for item in items]   return []     def get_list_limit(self): @@ -349,29 +351,44 @@
  add('center', (SIZE, SIZE, alloc.width - 2 * SIZE,   alloc.height - 2 * SIZE))   - def update_status(self, count=None, total=None, message=None): - all = button = False - if message: - text = message - elif count is None or total is None: + def update_status(self, updating=False): + numshow = numsel = numtotal = all = None + button = False + if updating: + text = _('Updating...') + elif self.curitems is None:   text = _('No items to display')   else: - all = count == total + numshow, numtotal = len(self.showitems), len(self.curitems) + data = dict(count=numshow, total=numtotal) + all = data['count'] == data['total']   button = not all - if all: - text = _('Displaying all items') + if self.sel_enable: + items = self.get_items(sel=True) + numsel = len([item for item, sel in items if sel]) + data['sel'] = numsel + if all: + text = _('Selecting %(sel)d of %(total)d, displaying ' + 'all items') % data + else: + text = _('Selecting %(sel)d, displaying %(count)d of ' + '%(total)d items') % data   else: - text = _('Displaying %(count)d of %(total)d items') \ - % dict(count=count, total=total) + if all: + text = _('Displaying all items') + else: + text = _('Displaying %(count)d of %(total)d items') % data   self.statuslabel.set_text(text)   self.allbtn.set_property('visible', button) + self.emit('list-updated', numtotal, numsel, numshow, all, updating)     def setup_dnd(self, restart=False):   if not restart and self.scroll_timer is None:   self.scroll_timer = gobject.timeout_add(25, self.scroll_timeout)   def teardown_dnd(self, pause=False): - self.sepmap['first'].set_visible(False) - self.sepmap['last'].set_visible(False) + if self.sepmap: + self.sepmap['first'].set_visible(False) + self.sepmap['last'].set_visible(False)   if self.hlsep:   self.hlsep.drag_unhighlight()   self.hlsep = None @@ -400,6 +417,10 @@
    ### signal handlers ###   + def check_toggled(self, button, item): + self.chkmap[item] = button.get_active() + self.update_status() +   def dnd_begin(self, widget, context):   self.setup_dnd()   context.set_icon_pixbuf(self.dnd_pb, 0, 0)
 
195
196
197
198
 
199
200
201
 
195
196
197
 
198
199
200
201
@@ -195,7 +195,7 @@
  else:   self.butable.hide()   - def preview_updated(self, cslist, count, total, *args): + def preview_updated(self, cslist, total, *args):   if total is None:   info = '<span weight="bold" foreground="#880000">%s</span>' \   % _('Unknown revision!')