Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

hgqt: move file edit functionality to qtlib

Many modules import wctxacions just to open files in an editor. This
functionality belongs in qtlib.

Changeset c4ae90d9c1f1

Parent 2b3f52e1dd1c

by Steve Borho

Changes to 4 files · Browse files at c4ae90d9c1f1 Showing diff from parent 2b3f52e1dd1c Diff from another changeset...

 
10
11
12
 
13
14
15
16
 
17
18
19
 
28
29
30
 
 
 
 
 
 
31
32
33
 
79
80
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
83
84
 
10
11
12
13
14
15
16
 
17
18
19
20
 
29
30
31
32
33
34
35
36
37
38
39
40
 
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
@@ -10,10 +10,11 @@
 import atexit  import shutil  import stat +import subprocess  import tempfile  import re   -from mercurial import extensions +from mercurial import extensions, util    from tortoisehg.util import hglib, paths, wconfig  from hgext.color import _styles @@ -28,6 +29,12 @@
  (QT_VERSION_STR, PYQT_VERSION_STR))   sys.exit()   +try: + import win32con + openflags = win32con.CREATE_NO_WINDOW +except ImportError: + openflags = 0 +  tmproot = None  def gettempdir():   global tmproot @@ -79,6 +86,64 @@
    return fn, wconfig.readfile(fn)   +def editfiles(repo, files, lineno=None, search=None, parent=None): + files = [util.shellquote(util.localpath(f)) for f in files] + editor = repo.ui.config('tortoisehg', 'editor') + assert len(files) == 1 or lineno == None + if editor: + try: + regexp = re.compile('\[([^\]]*)\]') + expanded = [] + pos = 0 + for m in regexp.finditer(editor): + expanded.append(editor[pos:m.start()-1]) + phrase = editor[m.start()+1:m.end()-1] + pos=m.end()+1 + if '$LINENUM' in phrase: + if lineno is None: + # throw away phrase + continue + phrase = phrase.replace('$LINENUM', str(lineno)) + elif '$SEARCH' in phrase: + if search is None: + # throw away phrase + continue + phrase = phrase.replace('$SEARCH', search) + if '$FILE' in phrase: + phrase = phrase.replace('$FILE', files[0]) + files = [] + expanded.append(phrase) + expanded.append(editor[pos:]) + cmdline = ' '.join(expanded + files) + except ValueError, e: + # '[' or ']' not found + cmdline = ' '.join([editor] + files) + except TypeError, e: + # variable expansion failed + cmdline = ' '.join([editor] + files) + else: + editor = os.environ.get('HGEDITOR') or repo.ui.config('ui', 'editor') \ + or os.environ.get('EDITOR', 'vi') + cmdline = ' '.join([editor] + files) + if os.path.basename(editor) in ('vi', 'vim', 'hgeditor'): + res = QMessageBox.critical(parent, + _('No visual editor configured'), + _('Please configure a visual editor.')) + from tortoisehg.hgqt.settings import SettingsDialog + dlg = SettingsDialog(False, focus='tortoisehg.editor') + dlg.exec_() + return + + cmdline = util.quotecommand(cmdline) + try: + subprocess.Popen(cmdline, shell=True, creationflags=openflags, + stderr=None, stdout=None, stdin=None) + except (OSError, EnvironmentError), e: + QMessageBox.warning(parent, + _('Editor launch failure'), + _('%s : %s') % (cmd, str(e))) + return False +  # _styles maps from ui labels to effects  # _effects maps an effect to font style properties. We define a limited  # set of _effects, since we convert color effect names to font style
 
35
36
37
38
39
40
41
42
43
44
45
46
 
87
88
89
90
 
91
92
93
 
35
36
37
 
 
 
 
 
 
38
39
40
 
81
82
83
 
84
85
86
87
@@ -35,12 +35,6 @@
 except ImportError:   config_nofork = None   -try: - import win32con - openflags = win32con.CREATE_NO_WINDOW -except ImportError: - openflags = 0 -  nonrepo_commands = '''userconfig shellconfig clone debugcomplete init  about help version thgstatus serve rejects log'''   @@ -87,7 +81,7 @@
  cmdline = subprocess.list2cmdline(args)   os.chdir(origwdir)   subprocess.Popen(cmdline, - creationflags=openflags, + creationflags=qtlib.openflags,   shell=True)   sys.exit(0)  
 
23
24
25
26
27
28
29
30
31
32
33
34
 
128
129
130
131
 
132
133
134
 
23
24
25
 
 
 
 
 
 
26
27
28
 
122
123
124
 
125
126
127
128
@@ -23,12 +23,6 @@
 from PyQt4.QtCore import *  from PyQt4.QtGui import *   -try: - import win32con - openflags = win32con.CREATE_NO_WINDOW -except ImportError: - openflags = 0 -  # Match parent2 first, so 'parent1?' will match both parent1 and parent  _regex = '\$(parent2|parent1?|child|plabel1|plabel2|clabel|repo|phash1|phash2|chash)'   @@ -128,7 +122,7 @@
  cmdline = util.quotecommand(cmdline)   try:   proc = subprocess.Popen(cmdline, shell=True, - creationflags=openflags, + creationflags=qtlib.openflags,   stderr=subprocess.PIPE,   stdout=subprocess.PIPE,   stdin=subprocess.PIPE)
 
7
8
9
10
11
12
13
 
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
 
7
8
9
 
10
11
12
 
197
198
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
201
202
203
@@ -7,7 +7,6 @@
   import os  import re -import subprocess    from mercurial import util, error, merge, commands  from tortoisehg.hgqt import qtlib, htmlui, visdiff @@ -198,63 +197,7 @@
  dlg.exec_()    def edit(parent, ui, repo, files, lineno=None, search=None): - files = [util.shellquote(util.localpath(f)) for f in files] - editor = ui.config('tortoisehg', 'editor') - assert len(files) == 1 or lineno == None - if editor: - try: - regexp = re.compile('\[([^\]]*)\]') - expanded = [] - pos = 0 - for m in regexp.finditer(editor): - expanded.append(editor[pos:m.start()-1]) - phrase = editor[m.start()+1:m.end()-1] - pos=m.end()+1 - if '$LINENUM' in phrase: - if lineno is None: - # throw away phrase - continue - phrase = phrase.replace('$LINENUM', str(lineno)) - elif '$SEARCH' in phrase: - if search is None: - # throw away phrase - continue - phrase = phrase.replace('$SEARCH', search) - if '$FILE' in phrase: - phrase = phrase.replace('$FILE', files[0]) - files = [] - expanded.append(phrase) - expanded.append(editor[pos:]) - cmdline = ' '.join(expanded + files) - except ValueError, e: - # '[' or ']' not found - cmdline = ' '.join([editor] + files) - except TypeError, e: - # variable expansion failed - cmdline = ' '.join([editor] + files) - else: - editor = os.environ.get('HGEDITOR') or ui.config('ui', 'editor') or \ - os.environ.get('EDITOR', 'vi') - cmdline = ' '.join([editor] + files) - if os.path.basename(editor) in ('vi', 'vim', 'hgeditor'): - res = QMessageBox.critical(parent, - _('No visual editor configured'), - _('Please configure a visual editor.')) - from tortoisehg.hgqt.settings import SettingsDialog - dlg = SettingsDialog(False, focus='tortoisehg.editor') - dlg.exec_() - return - - cmdline = util.quotecommand(cmdline) - try: - subprocess.Popen(cmdline, shell=True, creationflags=visdiff.openflags, - stderr=None, stdout=None, stdin=None) - except (OSError, EnvironmentError), e: - QMessageBox.warning(parent, - _('Editor launch failure'), - _('%s : %s') % (cmd, str(e))) - return False - + qtlib.editfiles(repo, files, lineno, search, parent)    def viewmissing(parent, ui, repo, files):   base, _ = visdiff.snapshot(repo, files, repo['.'])