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
This commit is contained in:
Richard Heck 2008-05-28 16:02:09 +00:00
parent 5254716219
commit 8921a18a89
6 changed files with 86 additions and 23 deletions

View 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:

View 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;
}

View 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;
}

View 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
};

View 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;
}

View 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