]> git.lyx.org Git - features.git/commitdiff
Add LFUN_VC_COMMAND.
authorPavel Sanda <sanda@lyx.org>
Tue, 13 Jan 2009 21:33:56 +0000 (21:33 +0000)
committerPavel Sanda <sanda@lyx.org>
Tue, 13 Jan 2009 21:33:56 +0000 (21:33 +0000)
http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg147331.html

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28138 a592a061-630c-0410-9148-cb99ea01b6c8

src/FuncCode.h
src/LyXAction.cpp
src/LyXFunc.cpp

index b9c88c8b78189da6328fd054c4b1b807c7636770..ebab4cc8fc2b2d5b6dbf3c4c7cf047d6aace3c3e 100644 (file)
@@ -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
 };
index 25bb4e4c8c1c106d8dcde5ccfdd2a34830694e95..0b48393c794f2e169f089c5d47c268639714aca3 100644 (file)
@@ -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 <FLAG> <PATH> <COMMAND>
+ * \li Params:  <FLAG>: 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>: path where to start. $$p will be replaced by the current document path.\n
+               <COMMAND>: 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
index fea1d1138d4679f622854dd56e73787ad0aac317..3bef300269db48e982fa577b715942b773055446 100644 (file)
@@ -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.