]> git.lyx.org Git - lyx.git/commitdiff
Add LFUN_BRANCH_ACTIVATE and LFUN_BRANCH_DEACTIVATE, fixing bug 4341.
authorRichard Heck <rgheck@comcast.net>
Wed, 28 May 2008 16:02:09 +0000 (16:02 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 28 May 2008 16:02:09 +0000 (16:02 +0000)
These have been added to BufferView::dispatch() and BufferView::getStatus() for now. Shortly, we'll be making wider use of Buffer::dispatch() and introducing Buffer::getStatus() and moving these and some other LFUNs there.

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

RELEASE-NOTES
src/Buffer.cpp
src/BufferView.cpp
src/FuncCode.h
src/LyX.cpp
src/LyXAction.cpp

index d8b626ea5478741e646ddc06a5c4570d4287d962..ed49840fdbdc8528c0887003445ca531b6eaa78c 100644 (file)
@@ -63,6 +63,13 @@ Some of the LyX functions have changed names:
 - The functions LFUN_HTML_INSERT, "html-insert", LFUN_URL_INSERT, "url-insert" was
   superseded by LFUN_HYPERLINK_INSERT, "href-insert".
 
+- New functions LFUN_BRANCH_ACTIVATE, "branch-activate", and LFUN_BRANCH_DEACTIVATE, 
+  "branch-deactivate" have been introduced. These can be used in export mode to turn
+  branches on and off. Thus, something like:
+    lyx -e pdf2 -x "branch-activate answers" finalexam.lyx
+  could be used to export a pdf with the answers branch included, without one's having
+  to open LyX and activate the branch manually.
+
 
 The following new LyX functions have been introduced:
 
index 3e2877ade43c9565216dbb4c492088468440cc27..110923a416b7c02e829bc849b1fbb8a535a18ca7 100644 (file)
@@ -1428,6 +1428,19 @@ bool Buffer::dispatch(FuncRequest const & func, bool * result)
                        break;
                }
 
+               case LFUN_BRANCH_ACTIVATE:
+               case LFUN_BRANCH_DEACTIVATE: {
+                       BranchList & branchList = params().branchlist();
+                       docstring const branchName = func.argument();
+                       Branch * branch = branchList.find(branchName);
+                       if (!branch)
+                               LYXERR0("Branch " << branchName << " does not exist.");
+                       else 
+                               branch->setSelected(func.action == LFUN_BRANCH_ACTIVATE);
+                       if (result)
+                               *result = true;
+               }
+
                default:
                        dispatched = false;
        }
index 85ac21a8e34dc280191ebd2e1d8190c0f1c905a6..a3f3672e5c0996d77813ec0f23e7223b3999c54b 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "BufferView.h"
 
+#include "BranchList.h"
 #include "Buffer.h"
 #include "buffer_funcs.h"
 #include "BufferList.h"
@@ -971,6 +972,16 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                }
                break;
 
+       case LFUN_BRANCH_ACTIVATE: 
+       case LFUN_BRANCH_DEACTIVATE: {
+               bool enable = false;
+               docstring const branchName = cmd.argument();
+               if (!branchName.empty())
+                       enable = buffer_.params().branchlist().find(branchName);
+               flag.enabled(enable);
+               break;
+       }
+
        default:
                flag.enabled(false);
        }
@@ -1383,6 +1394,12 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                break;
        }
 
+       case LFUN_BRANCH_ACTIVATE:
+       case LFUN_BRANCH_DEACTIVATE:
+               buffer_.dispatch(cmd);
+               processUpdateFlags(Update::Force);
+               break;
+
        default:
                return false;
        }
index b26430a35e27dcb480f92eec7d67e7d3c8b89f66..21fb52f6d08740e16f30dd9bb93c6a4a821b2e2b 100644 (file)
@@ -410,6 +410,8 @@ enum FuncCode
        // 315
        LFUN_GRAPHICS_GROUPS_UNIFY,
        LFUN_SET_GRAPHICS_GROUP,
+       LFUN_BRANCH_ACTIVATE,
+       LFUN_BRANCH_DEACTIVATE,
        LFUN_LASTACTION                  // end of the table
 };
 
index 0d4d2053eb8d42e25ae16b6558ae56dc5123f669..c41d16579a561f329df155573e14ad54ddd6b3b1 100644 (file)
@@ -163,7 +163,7 @@ struct LyX::Impl
        /// has this user started lyx for the first time?
        bool first_start;
        /// the parsed command line batch command if any
-       string batch_command;
+       vector<string> batch_commands;
 };
 
 ///
@@ -383,7 +383,7 @@ int LyX::exec(int & argc, char * argv[])
                // this is correct, since return values are inverted.
                exit_status = !loadFiles();
 
-               if (pimpl_->batch_command.empty() || pimpl_->buffer_list_.empty()) {
+               if (pimpl_->batch_commands.empty() || pimpl_->buffer_list_.empty()) {
                        prepareExit();
                        return exit_status;
                }
@@ -396,8 +396,12 @@ int LyX::exec(int & argc, char * argv[])
                        if (buf != buf->masterBuffer())
                                continue;
                        bool success = false;
-                       buf->dispatch(pimpl_->batch_command, &success);
-                       final_success |= success;
+                       vector<string>::const_iterator bcit  = pimpl_->batch_commands.begin();
+                       vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
+                       for (; bcit != bcend; bcit++) {
+                               buf->dispatch(*bcit, &success);
+                               final_success |= success;
+                       }
                }
                prepareExit();
                return !final_success;
@@ -613,12 +617,15 @@ void LyX::execBatchCommands()
                pimpl_->application_->restoreGuiSession();
 
        // Execute batch commands if available
-       if (pimpl_->batch_command.empty())
+       if (pimpl_->batch_commands.empty())
                return;
 
-       LYXERR(Debug::INIT, "About to handle -x '" << pimpl_->batch_command << '\'');
-
-       pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(pimpl_->batch_command));
+       vector<string>::const_iterator bcit  = pimpl_->batch_commands.begin();
+       vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
+       for (; bcit != bcend; bcit++) {
+               LYXERR(Debug::INIT, "About to handle -x '" << *bcit << '\'');
+               pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(*bcit));
+       }
 }
 
 
@@ -1012,12 +1019,10 @@ bool LyX::readEncodingsFile(string const & enc_name,
 
 namespace {
 
-string batch;
-
 /// return the the number of arguments consumed
-typedef boost::function<int(string const &, string const &)> cmd_helper;
+typedef boost::function<int(string const &, string const &, string &)> cmd_helper;
 
-int parse_dbg(string const & arg, string const &)
+int parse_dbg(string const & arg, string const &, string &)
 {
        if (arg.empty()) {
                lyxerr << to_utf8(_("List of supported debug flags:")) << endl;
@@ -1032,7 +1037,7 @@ int parse_dbg(string const & arg, string const &)
 }
 
 
-int parse_help(string const &, string const &)
+int parse_help(string const &, string const &, string &)
 {
        lyxerr <<
                to_utf8(_("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
@@ -1060,7 +1065,7 @@ int parse_help(string const &, string const &)
 }
 
 
-int parse_version(string const &, string const &)
+int parse_version(string const &, string const &, string &)
 {
        lyxerr << "LyX " << lyx_version
               << " (" << lyx_release_date << ")" << endl;
@@ -1072,7 +1077,7 @@ int parse_version(string const &, string const &)
 }
 
 
-int parse_sysdir(string const & arg, string const &)
+int parse_sysdir(string const & arg, string const &, string &)
 {
        if (arg.empty()) {
                Alert::error(_("No system directory"),
@@ -1084,7 +1089,7 @@ int parse_sysdir(string const & arg, string const &)
 }
 
 
-int parse_userdir(string const & arg, string const &)
+int parse_userdir(string const & arg, string const &, string &)
 {
        if (arg.empty()) {
                Alert::error(_("No user directory"),
@@ -1096,7 +1101,7 @@ int parse_userdir(string const & arg, string const &)
 }
 
 
-int parse_execute(string const & arg, string const &)
+int parse_execute(string const & arg, string const &, string & batch)
 {
        if (arg.empty()) {
                Alert::error(_("Incomplete command"),
@@ -1108,7 +1113,7 @@ int parse_execute(string const & arg, string const &)
 }
 
 
-int parse_export(string const & type, string const &)
+int parse_export(string const & type, string const &, string & batch)
 {
        if (type.empty()) {
                lyxerr << to_utf8(_("Missing file type [eg latex, ps...] after "
@@ -1121,7 +1126,7 @@ int parse_export(string const & type, string const &)
 }
 
 
-int parse_import(string const & type, string const & file)
+int parse_import(string const & type, string const & file, string & batch)
 {
        if (type.empty()) {
                lyxerr << to_utf8(_("Missing file type [eg latex, ps...] after "
@@ -1138,7 +1143,7 @@ int parse_import(string const & type, string const & file)
 }
 
 
-int parse_geometry(string const & arg1, string const &)
+int parse_geometry(string const & arg1, string const &, string &)
 {
        geometryArg = arg1;
 #if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING))
@@ -1186,7 +1191,10 @@ void LyX::easyParse(int & argc, char * argv[])
                string const arg2 =
                        (i + 2 < argc) ? to_utf8(from_local8bit(argv[i + 2])) : string();
 
-               int const remove = 1 + it->second(arg, arg2);
+               string batch;
+               int const remove = 1 + it->second(arg, arg2, batch);
+               if (!batch.empty())
+                       pimpl_->batch_commands.push_back(batch);
 
                // Now, remove used arguments by shifting
                // the following ones remove places down.
@@ -1197,8 +1205,6 @@ void LyX::easyParse(int & argc, char * argv[])
                        --i;
                }
        }
-
-       pimpl_->batch_command = batch;
 }
 
 
index 0590c977dfe6e39fe09591c05d5c1f55b93c06b2..a4e7610f7b3eef4d6e1de4e6d05d36c5139a00b1 100644 (file)
@@ -2176,6 +2176,24 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_COMPLETION_COMPLETE, "complete", SingleParUpdate, Edit },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_BRANCH_ACTIVATE
+ * \li Action: Activate the branch
+ * \li Syntax: branch-activate <BRANCH>
+ * \li Params: <BRANCH>: The branch to activate
+ * \li Origin: rgh, 27 May 2008
+ * \endvar
+ */
+               { LFUN_BRANCH_ACTIVATE, "branch-activate", Argument, Buffer },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_BRANCH_ACTIVATE
+ * \li Action: De-activate the branch
+ * \li Syntax: branch-deactivate <BRANCH>
+ * \li Params: <BRANCH>: The branch to deactivate
+ * \li Origin: rgh, 27 May 2008
+ * \endvar
+ */
+               { LFUN_BRANCH_DEACTIVATE, "branch-deactivate", Argument, Buffer },
 
                { LFUN_NOACTION, "", Noop, Hidden }
 #ifndef DOXYGEN_SHOULD_SKIP_THIS