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

settings: give edit widgets knowledge of curvalue and history

Next up will be to connect current and history values to each widget,
then implemen applyChanges() and isDirty() in main dialog

Changeset b2aa0793b2db

Parent db31fba9eedb

by Steve Borho

Changes to one file · Browse files at b2aa0793b2db Showing diff from parent db31fba9eedb Diff from another changeset...

 
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
 
409
410
411
412
 
413
414
415
 
419
420
421
422
423
424
425
426
427
428
429
 
435
436
437
438
 
 
 
 
 
 
439
440
441
 
443
444
445
446
447
448
449
450
451
452
453
454
455
 
483
484
485
486
487
488
489
490
491
 
555
556
557
558
559
560
561
562
563
 
577
578
579
580
581
582
583
584
585
586
587
 
683
684
685
686
687
688
689
690
 
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
 
462
463
464
 
465
466
467
468
 
472
473
474
 
 
 
 
 
475
476
477
 
483
484
485
 
486
487
488
489
490
491
492
493
494
 
496
497
498
 
 
 
 
 
 
 
499
500
501
 
529
530
531
 
 
 
532
533
534
 
598
599
600
 
 
 
601
602
603
 
617
618
619
 
 
 
 
 
620
621
622
 
718
719
720
 
 
721
722
723
@@ -37,45 +37,98 @@
  QComboBox.__init__(self, parent)   self.opts = opts   self.setEditable(opts.get('canedit', False)) - val = opts.get('validator') - if val: - self.setValidator(val) - self.reset(opts.get('defaults', [])) + self.setValidator(opts.get('validator', None)) + self.previous = [] + self.defaults = opts.get('defaults', []) + self.curvalue = False + self.loaded = False + self.resetList()   - def reset(self, msgs): + def resetList(self):   self.clear() - if self.opts.get('defer'): - self.loaded = False - self.addItem('...') + if self.opts.get('defer') and not self.loaded: + if self.curvalue == False: # unspecified + self.addItem(_unspecstr) + else: + self.addItem(self.curvalue or '...')   return   self.addItem(_unspecstr) - for m in msgs: + cur = None + for s in self.defaults: + self.addItem(s) + if self.curvalue == s: + cur = self.count() + for m in self.previous:   self.addItem(m) - self.loaded = True + if self.curvalue == s: + cur = self.count() + if self.defaults and self.previous: + self.insertSeparator(len(self.defaults)) + if cur: + self.setCurrentIndex(i) + elif self.curvalue == False: + self.setCurrentIndex(0) + else: + self.addItem(self.curvalue) + self.setCurrentIndex(self.count()-1)     def showPopup(self): - if not self.loaded: - self.clear() - self.addItem(_unspecstr) - for s in self.opts['defer'](): - self.addItem(s) + if self.opts.get('defer') and not self.loaded: + self.defaults = self.opts['defer']()   self.loaded = True + self.resetList()   QComboBox.showPopup(self)     def focusInEvent(self, e):   self.opts['descwidget'].setPlainText(self.opts['tooltip'])   QComboBox.focusInEvent(self, e)   + ## common APIs for all edit widgets + + def setHistory(self, oldvalues): + self.previous = oldvalues + self.resetList() + + def setCurValue(self, curvalue): + self.curvalue = curvalue + self.resetList() + + def getValue(self): + utext = self.currentText() + if utext == _unspecstr: + return False + return hglib.fromunicode(utext) + + def isDirty(self): + return self.getValue() != self.curvalue +  class PasswordEntry(QLineEdit):   def __init__(self, parent=None, **opts):   QLineEdit.__init__(self, parent)   self.opts = opts + self.curvalue = None   self.setEchoMode(QLineEdit.Password)     def focusInEvent(self, e):   self.opts['descwidget'].setPlainText(self.opts['tooltip'])   QLineEdit.focusInEvent(self, e)   + ## common APIs for all edit widgets + + def setHistory(self, oldvalues): + pass # orly? + + def setCurValue(self, curvalue): + self.curvalue = curvalue + self.setPlainText(curvalue) + + def getValue(self): + utext = self.text() + return utext and hglib.fromunicode(utext) or False + + def isDirty(self): + return self.getValue() != self.curvalue +  def genEditCombo(opts, defaults=[]):   # supplied opts keys: cpath, tooltip, descwidget, defaults   opts['canedit'] = True @@ -409,7 +462,7 @@
  stack = QStackedWidget()   bothbox.addWidget(pageList, 0)   bothbox.addWidget(stack, 1) - pageList.currentRowChanged.connect(self.setCurPage) + pageList.currentRowChanged.connect(stack.setCurrentIndex)   self.stack = stack     self.dirty = False @@ -419,11 +472,6 @@
  s = QSettings()   self.restoreGeometry(s.value('settings/geom').toByteArray())   - # add page items to treeview - for meta, info in INFO: - # TODO: set meta['icon'] - pageList.addItem(meta['label']) -   desctext = QTextBrowser()   layout.addWidget(desctext)   self.desctext = desctext @@ -435,7 +483,12 @@
  layout.addWidget(bb)   self.bb = bb   - self.dirty = False + # add page items to treeview + for meta, info in INFO: + # TODO: set meta['icon'] + pageList.addItem(meta['label']) + self.addPage(meta['name']) +   combo.setCurrentIndex(configrepo and CONF_REPO or CONF_GLOBAL)   combo.currentIndexChanged.connect(self.refresh)   self.refresh() @@ -443,13 +496,6 @@
  # TODO: focus 'general' page or specified field   pageList.setCurrentRow(0)   - def setCurPage(self, index): - 'create pages on demand' - meta, info = INFO[index] - if meta['name'] not in self.pages: - self.addPage(meta['name']) - self.stack.setCurrentIndex(index) -   def fileselect(self, combo):   'select another hgrc file'   if self.dirty: @@ -483,9 +529,6 @@
  self.ini = self.load_config(self.rcpath)   self.refreshHistory()   - # clear modification status - self.dirty = False -   def editClicked(self, button):   'Open internal editor in stacked widget'   pass @@ -555,9 +598,6 @@
  pagenum = self.stack.addWidget(frame)   self.pages[name] = (pagenum, info, frame, widgets)   - # prepare to show - self.refreshHistory(name) -   def refreshHistory(self, pagename=None):   # sotre modification status   prev_dirty = self.dirty @@ -577,11 +617,6 @@
  canedit = hasattr(w, 'isEditable') and w.isEditable()   # TODO: provide methods to add history, set cur value   - # clear modification status forcibly if need - if self.dirty != prev_dirty: - self._btn_apply.set_sensitive(False) - self.dirty = False -   def get_ini_config(self, cpath):   '''Retrieve a value from the parsed config file'''   try: @@ -683,8 +718,6 @@
  f = open(self.fn, 'w')   f.write(str(self.ini))   f.close() - self._btn_apply.set_sensitive(False) - self.dirty = False   except IOError, e:   qtlib.WarningMsgBox(_('Unable to write configuration file'),   str(e), parent=self)