diff --git a/src/FuncCode.h b/src/FuncCode.h index b9c88c8b78..ebab4cc8fc 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -413,6 +413,8 @@ enum FuncCode LFUN_WORD_FINDADV, // Tommaso, 20081003 LFUN_REGEXP_MODE, // Tommaso, 20081003 LFUN_COPY_LABEL_AS_REF, // sts, 20081116 + // 320 + LFUN_VC_COMMAND, LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 25bb4e4c8c..0b48393c79 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -1984,6 +1984,24 @@ void LyXAction::init() * \endvar */ { LFUN_VC_UNDO_LAST, "vc-undo-last", ReadOnly, System }, +/*! + * \var lyx::FuncCode lyx::LFUN_VC_COMMAND + * \li Action: Executes external command. This command is intended to support + additonal VCS commands. + * \li Syntax: vc-command + * \li Params: : Flags for the command can be combined together.\n + U - dUmmy - no flags \n + D - Doc - need document loaded to proceed \n + I - dIrty - mark document dirty \n + R - Reload - reload the document after command execution \n + M - Message - ask for input string (commit message)\n + : path where to start. $$p will be replaced by the current document path.\n + : command to execute. $$i/$$p/$$m will be replaced by the current document/path/message. + * \li Sample: vc-command DR $$p "svn up" + * \li Origin: sanda, 13 Jan 2009 + * \endvar + */ + { LFUN_VC_COMMAND, "vc-command", NoBuffer | ReadOnly, System }, /*! * \var lyx::FuncCode lyx::LFUN_CHANGES_TRACK diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index fea1d1138d..3bef300269 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -566,6 +566,15 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const break; } + case LFUN_VC_COMMAND: { + if (cmd.argument().empty()) + enable = false; + + if (!buf && contains(cmd.getArg(0), 'D')) + enable = false; + break; + } + case LFUN_WORD_FIND_FORWARD: case LFUN_WORD_FIND_BACKWARD: case LFUN_WORD_FINDADV: @@ -1599,6 +1608,48 @@ void LyXFunc::dispatch(FuncRequest const & cmd) theSession().bookmarks().clear(); break; + case LFUN_VC_COMMAND: { + string flag = cmd.getArg(0); + if (buffer && contains(flag, 'R') && !ensureBufferClean(view())) + break; + docstring message; + if (contains(flag, 'M')) + if (!Alert::askForText(message, _("LyX VC: Log Message"))) + break; + + string path = cmd.getArg(1); + if (contains(path, "$$p") && buffer) + path = subst(path, "$$p", buffer->filePath()); + LYXERR(Debug::LYXVC, "Directory: " << path); + FileName pp(path); + if (!pp.isReadableDirectory()) { + lyxerr<< _("Directory is not readable.\n"); + break; + } + support::PathChanger p(pp); + + string command = cmd.getArg(2); + if (command.empty()) + break; + if (buffer) { + command = subst(command, "$$i", buffer->absFileName()); + command = subst(command, "$$p", buffer->filePath()); + } + command = subst(command, "$$m", to_utf8(message)); + LYXERR(Debug::LYXVC, "Command: " << command); + Systemcall one; + one.startscript(Systemcall::Wait, command); + + if (!buffer) + break; + if (contains(flag, 'I')) + buffer->markDirty(); + if (contains(flag, 'R')) + reloadBuffer(); + + break; + } + default: LASSERT(theApp(), /**/); // Let the frontend dispatch its own actions.