This patch (for trunk only) does two things:
* it adds an lfun branch-add,
* if you paste unknown branches to a document, it issues a dialog that asks
you if those should be added to the document's branch list (bug #4462).
What is missing is the possibility to add the branch to the master if you are
in a child document. We cannot change the master buffer's params from within
the child, since masterBuffer() is const.
Jürgen
Index: src/LyXAction.cpp
===================================================================
--- src/LyXAction.cpp (Revision 30391)
+++ src/LyXAction.cpp (Arbeitskopie)
@@ -3278,6 +3278,17 @@
/*!
+ * \var lyx::FuncCode lyx::LFUN_BRANCH_ADD
+ * \li Action: Add a branch to the buffer's BranchList
+ * \li Syntax: branch-add <BRANCH>
+ * \li Params: <BRANCH>: Name of the branch to add
+ * \li Origin: spitz, 7 Jul 2009
+ * \endvar
+ */
+ { LFUN_BRANCH_ADD, "branch-add", Noop, Buffer },
+
+
+/*!
* \var lyx::FuncCode lyx::LFUN_BRANCH_ACTIVATE
* \li Action: Activate the branch
* \li Syntax: branch-activate <BRANCH>
Index: src/insets/InsetBranch.h
===================================================================
--- src/insets/InsetBranch.h (Revision 30391)
+++ src/insets/InsetBranch.h (Arbeitskopie)
@@ -51,6 +51,8 @@
static std::string params2string(InsetBranchParams const &);
///
static void string2params(std::string const &, InsetBranchParams &);
+ ///
+ docstring branch() const { return params_.branch; }
private:
///
Index: src/CutAndPaste.cpp
===================================================================
--- src/CutAndPaste.cpp (Revision 30391)
+++ src/CutAndPaste.cpp (Arbeitskopie)
@@ -15,6 +15,7 @@
#include "CutAndPaste.h"
+#include "BranchList.h"
#include "Buffer.h"
#include "buffer_funcs.h"
#include "BufferList.h"
@@ -37,8 +38,9 @@
#include "ParIterator.h"
#include "Undo.h"
+#include "insets/InsetBranch.h"
+#include "insets/InsetCommand.h"
#include "insets/InsetFlex.h"
-#include "insets/InsetCommand.h"
#include "insets/InsetGraphics.h"
#include "insets/InsetGraphicsParams.h"
#include "insets/InsetInclude.h"
@@ -54,6 +56,7 @@
#include "support/limited_stack.h"
#include "support/lstrings.h"
+#include "frontends/alert.h"
#include "frontends/Clipboard.h"
#include "frontends/Selection.h"
@@ -271,6 +274,31 @@
break;
}
+ case BRANCH_CODE: {
+ // check if branch is known to target buffer
+ // or its master
+ InsetBranch & br = static_cast<InsetBranch &>(*it);
+ docstring const name = br.branch();
+ if (name.empty())
+ break;
+ bool const is_child = (&buffer != buffer.masterBuffer());
+ BranchList branchlist = buffer.params().branchlist();
+ if ((!is_child && branchlist.find(name))
+ || (is_child && (branchlist.find(name)
+ || buffer.masterBuffer()->params().branchlist().find(name))))
+ break;
+ // FIXME: add an option to add the branch to the master's BranchList.
+ docstring text = bformat(
+ _("The pasted branch \"%1$s\" is undefined.\n"
+ "Do you want to add it to the document's branch list?"),
+ name);
+ if (frontend::Alert::prompt(_("Unknown branch"),
+ text, 0, 1, _("&Add"), _("&Don't Add")) != 0)
+ break;
+ lyx::dispatch(FuncRequest(LFUN_BRANCH_ADD, name));
+ break;
+ }
+
default:
break; // nothing
}
Index: src/FuncCode.h
===================================================================
--- src/FuncCode.h (Revision 30391)
+++ src/FuncCode.h (Arbeitskopie)
@@ -435,6 +435,7 @@
LFUN_FONT_UWAVE,
LFUN_BUFFER_EXPORT, // Lgb 97-07-29
LFUN_BUFFER_TOGGLE_COMPRESSION, // bpeng 20060427
+ LFUN_BRANCH_ADD, // spitz 20090707
LFUN_LASTACTION // end of the table
};
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (Revision 30391)
+++ src/Buffer.cpp (Arbeitskopie)
@@ -1621,6 +1621,7 @@
break;
}
+ case LFUN_BRANCH_ADD:
case LFUN_BUFFER_PRINT:
// if no Buffer is present, then of course we won't be called!
flag.setEnabled(true);
@@ -1657,6 +1658,28 @@
break;
}
+ case LFUN_BRANCH_ADD: {
+ BranchList & branchList = params().branchlist();
+ docstring const branchName = func.argument();
+ if (branchName.empty()) {
+ dispatched = false;
+ break;
+ }
+ Branch * branch = branchList.find(branchName);
+ if (branch) {
+ LYXERR0("Branch " << branchName << " does already exist.");
+ dr.setError(true);
+ docstring const msg =
+ bformat(_("Branch \"%1$s\" does already exist."), branchName);
+ dr.setMessage(msg);
+ } else {
+ branchList.add(branchName);
+ dr.setError(false);
+ dr.update(Update::Force);
+ }
+ break;
+ }
+
case LFUN_BRANCH_ACTIVATE:
case LFUN_BRANCH_DEACTIVATE: {
BranchList & branchList = params().branchlist();
@@ -3106,7 +3129,7 @@
// Do this here in case the master has no gui associated with it. Then,
// the TocModel is not updated and TocModel::toc_ is invalid (bug 5699).
if (!master->gui_)
- structureChanged();
+ structureChanged();
// was buf referenced from the master (i.e. not in bufToUpdate anymore)?
if (bufToUpdate.find(this) == bufToUpdate.end())