def getCurrentUsername(widget, repo, opts=None): if opts: # 1. Override has highest priority user = opts.get('user') if user: return user # 2. Read from repository try: return repo.ui.username() except error.Abort: pass # 3. Get a username from the user QMessageBox.information(widget, _('Please enter a username'), _('You must identify yourself to Mercurial'), QMessageBox.Ok) from tortoisehg.hgqt.settings import SettingsDialog dlg = SettingsDialog(False, focus='ui.username') dlg.exec_() repo.invalidateui() try: return repo.ui.username() except error.Abort: return None
def editSettings(self): tw = self.repoTabsWidget w = tw.currentWidget() twrepo = (w and w.repo.root or '') sd = SettingsDialog(configrepo=False, focus='tortoisehg.authorcolor', parent=self, root=twrepo) sd.exec_()
def editfiles(repo, files, lineno=None, search=None, parent=None): if len(files) == 1: # if editing a single file, open in cwd context of that file filename = files[0].strip() if not filename: return files = [filename] path = repo.wjoin(filename) cwd = os.path.dirname(path) files = [os.path.basename(path)] else: # else edit in cwd context of repo root cwd = repo.root toolpath, args, argsln, argssearch = editor.detecteditor(repo, files) if os.path.basename(toolpath) 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 files = [util.shellquote(util.localpath(f)) for f in files] assert len(files) == 1 or lineno == None cmdline = None if search: assert lineno is not None if argssearch: cmdline = ' '.join([toolpath, argssearch]) cmdline = cmdline.replace('$LINENUM', str(lineno)) cmdline = cmdline.replace('$SEARCH', search) elif argsln: cmdline = ' '.join([toolpath, argsln]) cmdline = cmdline.replace('$LINENUM', str(lineno)) elif args: cmdline = ' '.join([toolpath, args]) elif lineno: if argsln: cmdline = ' '.join([toolpath, argsln]) cmdline = cmdline.replace('$LINENUM', str(lineno)) elif args: cmdline = ' '.join([toolpath, args]) else: if args: cmdline = ' '.join([toolpath, args]) if cmdline is None: # editor was not specified by editor-tools configuration, fall # back to older tortoisehg.editor OpenAtLine parsing cmdline = ' '.join([toolpath] + files) # default try: regexp = re.compile('\[([^\]]*)\]') expanded = [] pos = 0 for m in regexp.finditer(toolpath): expanded.append(toolpath[pos:m.start()-1]) phrase = toolpath[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(toolpath[pos:]) cmdline = ' '.join(expanded + files) except ValueError, e: # '[' or ']' not found pass except TypeError, e: # variable expansion failed pass
def settings(): from tortoisehg.hgqt.settings import SettingsDialog dlg = SettingsDialog(True, focus='tortoisehg.summarylen') dlg.exec_()
# '[' or ']' not found cmdline = ' '.join([editor] + files) except TypeError, e: # variable expansion failed cmdline = ' '.join([editor] + files) else: editor = os.environ.get('HPLUMAOR') or repo.ui.config('ui', 'editor') \ or os.environ.get('EDITOR', 'vi') cmdline = ' '.join([editor] + files) if os.path.basename(editor) in ('vi', 'vim', 'hplumaor'): 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) shell = not (len(cwd) >= 2 and cwd[0:2] == r'\\') try: subprocess.Popen(cmdline, shell=shell, creationflags=openflags, stderr=None, stdout=None, stdin=None, cwd=cwd) except (OSError, EnvironmentError), e: QMessageBox.warning(parent, _('Editor launch failure'), u'%s : %s' % (hglib.tounicode(cmdline), hglib.tounicode(str(e)))) return False def savefiles(repo, files, rev, parent=None):
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('HPLUMAOR') or repo.ui.config('ui', 'editor') \ or os.environ.get('EDITOR', 'vi') cmdline = ' '.join([editor] + files) if os.path.basename(editor) in ('vi', 'vim', 'hplumaor'): 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) shell = not (len(cwd) >= 2 and cwd[0:2] == r'\\') try: subprocess.Popen(cmdline, shell=shell, creationflags=openflags, stderr=None, stdout=None, stdin=None, cwd=cwd) except (OSError, EnvironmentError), e: QMessageBox.warning( parent, _('Editor launch failure'),
def editfiles(repo, files, lineno=None, search=None, parent=None): if len(files) == 1: # if editing a single file, open in cwd context of that file filename = files[0].strip() if not filename: return files = [filename] path = repo.wjoin(filename) cwd = os.path.dirname(path) files = [os.path.basename(path)] else: # else edit in cwd context of repo root cwd = repo.root toolpath, args, argsln, argssearch = editor.detecteditor(repo, files) if os.path.basename(toolpath) 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 files = [util.shellquote(util.localpath(f)) for f in files] assert len(files) == 1 or lineno == None cmdline = None if search: assert lineno is not None if argssearch: cmdline = ' '.join([toolpath, argssearch]) cmdline = cmdline.replace('$LINENUM', str(lineno)) cmdline = cmdline.replace('$SEARCH', search) elif argsln: cmdline = ' '.join([toolpath, argsln]) cmdline = cmdline.replace('$LINENUM', str(lineno)) elif args: cmdline = ' '.join([toolpath, args]) elif lineno: if argsln: cmdline = ' '.join([toolpath, argsln]) cmdline = cmdline.replace('$LINENUM', str(lineno)) elif args: cmdline = ' '.join([toolpath, args]) else: if args: cmdline = ' '.join([toolpath, args]) if cmdline is None: # editor was not specified by editor-tools configuration, fall # back to older tortoisehg.editor OpenAtLine parsing cmdline = ' '.join([toolpath] + files) # default try: regexp = re.compile('\[([^\]]*)\]') expanded = [] pos = 0 for m in regexp.finditer(toolpath): expanded.append(toolpath[pos:m.start() - 1]) phrase = toolpath[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(toolpath[pos:]) cmdline = ' '.join(expanded + files) except ValueError, e: # '[' or ']' not found pass except TypeError, e: # variable expansion failed pass
def editSettings(self, focus=None): sd = SettingsDialog(configrepo=False, focus=focus, parent=self, root=hglib.fromunicode(self.currentRepoRootPath())) sd.exec_()