mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fix bug #8627: Command line switches to change branch do not appear to work
Move the handling of branch-(de)activate(master) to Buffer. This code was moved to Bufferview in [3a03e71c/lyxgit] because a cursor was necessary to call Undo::recordUndoFullDocument(). However, it turns out that the undo code is already prepared to handle an empty cursor (and do nothing in this case). Therefore we do that and move the branch code to Buffer where it belongs. Note that there was a bug in the previous code that broke undo support: recordUndo should always be called _before_ doing any change.
This commit is contained in:
parent
712e1871ca
commit
21c5bbec71
125
src/Buffer.cpp
125
src/Buffer.cpp
@ -2246,57 +2246,70 @@ bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
||||
|
||||
switch (cmd.action()) {
|
||||
|
||||
case LFUN_BUFFER_TOGGLE_READ_ONLY:
|
||||
flag.setOnOff(isReadonly());
|
||||
break;
|
||||
case LFUN_BUFFER_TOGGLE_READ_ONLY:
|
||||
flag.setOnOff(isReadonly());
|
||||
break;
|
||||
|
||||
// FIXME: There is need for a command-line import.
|
||||
//case LFUN_BUFFER_IMPORT:
|
||||
|
||||
case LFUN_BUFFER_AUTO_SAVE:
|
||||
break;
|
||||
case LFUN_BUFFER_AUTO_SAVE:
|
||||
break;
|
||||
|
||||
case LFUN_BUFFER_EXPORT_CUSTOM:
|
||||
// FIXME: Nothing to check here?
|
||||
break;
|
||||
case LFUN_BUFFER_EXPORT_CUSTOM:
|
||||
// FIXME: Nothing to check here?
|
||||
break;
|
||||
|
||||
case LFUN_BUFFER_EXPORT: {
|
||||
docstring const arg = cmd.argument();
|
||||
if (arg == "custom") {
|
||||
enable = true;
|
||||
break;
|
||||
}
|
||||
string format = to_utf8(arg);
|
||||
size_t pos = format.find(' ');
|
||||
if (pos != string::npos)
|
||||
format = format.substr(0, pos);
|
||||
enable = params().isExportable(format);
|
||||
if (!enable)
|
||||
flag.message(bformat(
|
||||
_("Don't know how to export to format: %1$s"), arg));
|
||||
case LFUN_BUFFER_EXPORT: {
|
||||
docstring const arg = cmd.argument();
|
||||
if (arg == "custom") {
|
||||
enable = true;
|
||||
break;
|
||||
}
|
||||
string format = to_utf8(arg);
|
||||
size_t pos = format.find(' ');
|
||||
if (pos != string::npos)
|
||||
format = format.substr(0, pos);
|
||||
enable = params().isExportable(format);
|
||||
if (!enable)
|
||||
flag.message(bformat(
|
||||
_("Don't know how to export to format: %1$s"), arg));
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_BUFFER_CHKTEX:
|
||||
enable = params().isLatex() && !lyxrc.chktex_command.empty();
|
||||
break;
|
||||
case LFUN_BUFFER_CHKTEX:
|
||||
enable = params().isLatex() && !lyxrc.chktex_command.empty();
|
||||
break;
|
||||
|
||||
case LFUN_BUILD_PROGRAM:
|
||||
enable = params().isExportable("program");
|
||||
break;
|
||||
case LFUN_BUILD_PROGRAM:
|
||||
enable = params().isExportable("program");
|
||||
break;
|
||||
|
||||
case LFUN_BRANCH_ADD:
|
||||
case LFUN_BRANCHES_RENAME:
|
||||
case LFUN_BUFFER_PRINT:
|
||||
// if no Buffer is present, then of course we won't be called!
|
||||
break;
|
||||
case LFUN_BRANCH_ACTIVATE:
|
||||
case LFUN_BRANCH_DEACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_ACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_DEACTIVATE: {
|
||||
bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
|
||||
BranchList const & branchList = master ? masterBuffer()->params().branchlist()
|
||||
: params().branchlist();
|
||||
docstring const branchName = cmd.argument();
|
||||
flag.setEnabled(!branchName.empty() && branchList.find(branchName));
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_BUFFER_LANGUAGE:
|
||||
enable = !isReadonly();
|
||||
break;
|
||||
case LFUN_BRANCH_ADD:
|
||||
case LFUN_BRANCHES_RENAME:
|
||||
case LFUN_BUFFER_PRINT:
|
||||
// if no Buffer is present, then of course we won't be called!
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
case LFUN_BUFFER_LANGUAGE:
|
||||
enable = !isReadonly();
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
flag.setEnabled(enable);
|
||||
return true;
|
||||
@ -2404,6 +2417,42 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
|
||||
resetAutosaveTimers();
|
||||
break;
|
||||
|
||||
case LFUN_BRANCH_ACTIVATE:
|
||||
case LFUN_BRANCH_DEACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_ACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_DEACTIVATE: {
|
||||
bool const master = (func.action() == LFUN_BRANCH_MASTER_ACTIVATE
|
||||
|| func.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
|
||||
Buffer * buf = master ? const_cast<Buffer *>(masterBuffer())
|
||||
: this;
|
||||
|
||||
docstring const branch_name = func.argument();
|
||||
// the case without a branch name is handled elsewhere
|
||||
if (branch_name.empty()) {
|
||||
dispatched = false;
|
||||
break;
|
||||
}
|
||||
Branch * branch = buf->params().branchlist().find(branch_name);
|
||||
if (!branch) {
|
||||
LYXERR0("Branch " << branch_name << " does not exist.");
|
||||
dr.setError(true);
|
||||
docstring const msg =
|
||||
bformat(_("Branch \"%1$s\" does not exist."), branch_name);
|
||||
dr.setMessage(msg);
|
||||
break;
|
||||
}
|
||||
bool const activate = (func.action() == LFUN_BRANCH_ACTIVATE
|
||||
|| func.action() == LFUN_BRANCH_MASTER_ACTIVATE);
|
||||
if (branch->isSelected() != activate) {
|
||||
buf->undo().recordUndoFullDocument(CursorData());
|
||||
branch->setSelected(activate);
|
||||
dr.setError(false);
|
||||
dr.screenUpdate(Update::Force);
|
||||
dr.forceBufferUpdate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_BRANCH_ADD: {
|
||||
docstring branch_name = func.argument();
|
||||
if (branch_name.empty()) {
|
||||
|
@ -1186,22 +1186,6 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXME We do not really want this here, but at present we need to
|
||||
// handle their dispatch here, for reasons explained there, so we'll
|
||||
// handle this here, too, for consistency.
|
||||
case LFUN_BRANCH_ACTIVATE:
|
||||
case LFUN_BRANCH_DEACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_ACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_DEACTIVATE: {
|
||||
bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
|
||||
BranchList const & branchList = master ? buffer().masterBuffer()->params().branchlist()
|
||||
: buffer().params().branchlist();
|
||||
docstring const branchName = cmd.argument();
|
||||
flag.setEnabled(!branchName.empty() && branchList.find(branchName));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -1988,48 +1972,6 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXME We do not really want this here, but it has to be at present
|
||||
// because we need a cursor for the recordUndoFullDocument call. What
|
||||
// we would really like is a recordUndoBufferParams call that did not
|
||||
// need a cursor, but we do not have that yet.
|
||||
// So, if this does get fixed, this code can be moved back to Buffer.cpp,
|
||||
// and the corresponding code in getStatus() should be moved back, too.
|
||||
case LFUN_BRANCH_ACTIVATE:
|
||||
case LFUN_BRANCH_DEACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_ACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_DEACTIVATE: {
|
||||
bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
|
||||
Buffer * buf = master ? const_cast<Buffer *>(buffer().masterBuffer())
|
||||
: &buffer();
|
||||
|
||||
docstring const branch_name = cmd.argument();
|
||||
// the case without a branch name is handled elsewhere
|
||||
if (branch_name.empty()) {
|
||||
dispatched = false;
|
||||
break;
|
||||
}
|
||||
Branch * branch = buf->params().branchlist().find(branch_name);
|
||||
if (!branch) {
|
||||
LYXERR0("Branch " << branch_name << " does not exist.");
|
||||
dr.setError(true);
|
||||
docstring const msg =
|
||||
bformat(_("Branch \"%1$s\" does not exist."), branch_name);
|
||||
dr.setMessage(msg);
|
||||
break;
|
||||
}
|
||||
bool activate = (cmd.action() == LFUN_BRANCH_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE);
|
||||
if (branch->isSelected() != activate) {
|
||||
branch->setSelected(activate);
|
||||
cur.recordUndoFullDocument();
|
||||
dr.setError(false);
|
||||
dr.screenUpdate(Update::Force);
|
||||
dr.forceBufferUpdate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// OK, so try the Buffer itself...
|
||||
buffer_.dispatch(cmd, dr);
|
||||
|
Loading…
Reference in New Issue
Block a user