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

webconf: implement "open file" and "save file"

Changeset cd777dc3f76c

Parent 6d5b1fcb118e

by Yuya Nishihara

Changes to 2 files · Browse files at cd777dc3f76c Showing diff from parent 6d5b1fcb118e Diff from another changeset...

 
5
6
7
 
8
9
10
 
12
13
14
15
 
 
16
17
18
 
38
39
40
41
 
42
43
44
 
62
63
64
65
66
67
68
69
70
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
73
74
 
5
6
7
8
9
10
11
 
13
14
15
 
16
17
18
19
20
 
40
41
42
 
43
44
45
46
 
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
@@ -5,6 +5,7 @@
 # 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  from PyQt4.QtCore import *  from PyQt4.QtGui import *  from tortoisehg.util import hglib, wconfig @@ -12,7 +13,8 @@
 from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt.webconf_ui import Ui_WebconfForm   -# TODO: open/save webconf file +_FILE_FILTER = _('Config files (*.conf *.config *.ini);;Any files (*)') +  # TODO: edit repository map  class WebconfForm(QWidget):   """Widget to show/edit webconf""" @@ -38,7 +40,7 @@
    def setwebconf(self, webconf):   """set current webconf object""" - path = getattr(webconf, 'path', None) or '' + path = hglib.tounicode(getattr(webconf, 'path', None) or '')   i = self._qui.path_edit.findText(path)   if i < 0:   i = 0 @@ -62,13 +64,39 @@
    def _updateform(self):   """Update availability of each widget""" - self._qui.path_edit.setEnabled(False) # TODO - self._qui.open_button.setEnabled(False) # TODO - self._qui.save_button.setEnabled(False) # TODO   self._qui.add_button.setEnabled(False) # TODO   self._qui.edit_button.setEnabled(False) # TODO   self._qui.remove_button.setEnabled(False) # TODO   + @pyqtSlot() + def on_open_button_clicked(self): + path = QFileDialog.getOpenFileName( + self, _('Open hgweb config'), + getattr(self.webconf, 'path', None) or '', _FILE_FILTER) + if path: + self.openwebconf(path) + + def openwebconf(self, path): + """load the specified webconf file""" + path = hglib.fromunicode(path) + c = wconfig.readfile(path) + c.path = os.path.abspath(path) + self.setwebconf(c) + + @pyqtSlot() + def on_save_button_clicked(self): + path = QFileDialog.getSaveFileName( + self, _('Save hgweb config'), + getattr(self.webconf, 'path', None) or '', _FILE_FILTER) + if path: + self.savewebconf(path) + + def savewebconf(self, path): + """save current webconf to the specified file""" + path = hglib.fromunicode(path) + wconfig.writefile(self.webconf, path) + self.openwebconf(path) # reopen in case file path changed +  class WebconfModel(QAbstractTableModel):   """Wrapper for webconf object to be a Qt's model object"""   _COLUMNS = [(_('Path'),),
 
34
35
36
 
 
 
37
38
39
 
34
35
36
37
38
39
40
41
42
@@ -34,6 +34,9 @@
  <verstretch>0</verstretch>   </sizepolicy>   </property> + <property name="insertPolicy"> + <enum>QComboBox::InsertAtTop</enum> + </property>   </widget>   </item>   <item>