From 8921a18a89c9a60ab6bb84fa37e1baafcc1a1cb5 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 28 May 2008 16:02:09 +0000 Subject: [PATCH] Add LFUN_BRANCH_ACTIVATE and LFUN_BRANCH_DEACTIVATE, fixing bug 4341. 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 | 7 +++++++ src/Buffer.cpp | 13 ++++++++++++ src/BufferView.cpp | 17 +++++++++++++++ src/FuncCode.h | 2 ++ src/LyX.cpp | 52 ++++++++++++++++++++++++++-------------------- src/LyXAction.cpp | 18 ++++++++++++++++ 6 files changed, 86 insertions(+), 23 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index d8b626ea54..ed49840fdb 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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: diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 3e2877ade4..110923a416 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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; } diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 85ac21a8e3..a3f3672e5c 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -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; } diff --git a/src/FuncCode.h b/src/FuncCode.h index b26430a35e..21fb52f6d0 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -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 }; diff --git a/src/LyX.cpp b/src/LyX.cpp index 0d4d2053eb..c41d16579a 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -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 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::const_iterator bcit = pimpl_->batch_commands.begin(); + vector::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::const_iterator bcit = pimpl_->batch_commands.begin(); + vector::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 cmd_helper; +typedef boost::function 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; } diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 0590c977df..a4e7610f7b 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -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 + * \li Params: : 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 + * \li Params: : 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 -- 2.39.2