Changeset c4ae90d9c1f1…
Parent 2b3f52e1dd1c…
by
Changes to 4 files · Browse files at c4ae90d9c1f1 Showing diff from parent 2b3f52e1dd1c Diff from another changeset...
|
@@ -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,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,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,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['.'])
|
Loading...