hi, i started to use branches lately and i found out that our UI for them is bit annoying since every other change needs tobe done through preferences dislog.
the attached patches: - introduce new menu item for defining new branch, so you can directly put new branch into the document. - introduce actvation/deactivation through the context menu (2 JMarc - i tried your proposal through branch-activate lfun, but when i come to thepoint when i needed to copy the whole code from next-inset-toggle lfun i returned to the idea of enhancing our own inset-toggle.) - fix already presesnt bug for update status of branch inset. objections? pavel
commit 21e518027cae7a242b0b1bbc54766120d9f9a49e Author: Pavel Sanda <p...@twin.jikos.cz> Date: Sat Mar 14 11:51:57 2009 +0100 Add LFUN_BRANCH_ADD, add new branch command to ui. diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 12638f8..28fb43f 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -443,6 +443,8 @@ Menuset End Menu "insert_branches" + Item "Add New Branch|A" "branch-add branch_inset_insert" + Separator Branches End diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 3b31fd5..18fbeec 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -909,6 +909,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) case LFUN_NOTES_MUTATE: case LFUN_ALL_INSETS_TOGGLE: case LFUN_STATISTICS: + case LFUN_BRANCH_ADD: flag.setEnabled(true); break; @@ -1536,6 +1537,35 @@ bool BufferView::dispatch(FuncRequest const & cmd) break; } + case LFUN_BRANCH_ADD: { + BranchList & branch_list = buffer_.params().branchlist(); + docstring branch_name = from_utf8(cmd.getArg(0)); + bool branch_insert = false; + if (branch_name == "branch_inset_insert") { + branch_insert = true; + branch_name = from_utf8(cmd.getArg(1)); + } + if (branch_name.empty()) + if (!Alert::askForText(branch_name, _("Branch name")) || + branch_name.empty()) + return false; + + if (!branch_list.add(branch_name)) { + cur.message(from_utf8(N_("Branch already exists."))); + return false; + } + Branch const * branch = branch_list.find(branch_name); + string const x11hexname = X11hexname(branch->color()); + docstring const str = branch_name + ' ' + from_ascii(x11hexname); + lyx::dispatch(FuncRequest(LFUN_SET_COLOR, str)); + + if (branch_insert) + lyx::dispatch(FuncRequest(LFUN_BRANCH_INSERT, branch_name)); + + cur.message(branch_name + " " + from_utf8(N_("branch added."))); + break; + } + default: return false; } diff --git a/src/FuncCode.h b/src/FuncCode.h index 503f30f..c0d39a4 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -418,6 +418,7 @@ enum FuncCode LFUN_VC_COMMAND, LFUN_MATH_FONT_STYLE, LFUN_PHANTOM_INSERT, // uwestoehr, 20090130 + LFUN_BRANCH_ADD, LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 137f760..c8755bb 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3158,6 +3158,17 @@ void LyXAction::init() * \endvar */ { LFUN_BRANCH_DEACTIVATE, "branch-deactivate", Argument, Buffer }, +/*! + * \var lyx::FuncCode lyx::LFUN_BRANCH_ADD + * \li Action: Add new branch into the document + * \li Syntax: branch-add [<OPT>] <BRANCH> + * \li Params: <OPT>: branch_inset_insert - inserts branch inset at the current cursor position \n + <BRANCH>: The new branch name + * \li Origin: sanda, 6 March, 2009 + * \endvar + */ + { LFUN_BRANCH_ADD, "branch-add", Argument, Buffer }, + /*! * \var lyx::FuncCode lyx::LFUN_COPY_LABEL_AS_REF commit f50a1e07e3a25445a8f3e5d73582dde8c0d055f6 Author: Pavel Sanda <p...@twin.jikos.cz> Date: Fri Mar 13 00:15:00 2009 +0100 Context-branch menu uselessly shows both open/close items. diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 468933b..2501a40 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -178,8 +178,11 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd, break; case LFUN_INSET_TOGGLE: - if (cmd.argument() == "open" || cmd.argument() == "close" || - cmd.argument() == "toggle") + if (cmd.argument() == "open") + flag.setEnabled(status_ != Open); + else if (cmd.argument() == "close") + flag.setEnabled(status_ == Open); + else if (cmd.argument() == "toggle") flag.setEnabled(true); else if (cmd.argument() == "assign" || cmd.argument().empty()) { if (isBranchSelected()) commit 04efb3a02367c6445109fb84e4ada4d514d11c42 Author: Pavel Sanda <p...@twin.jikos.cz> Date: Fri Mar 13 00:07:04 2009 +0100 Enable (De)activation of branch from context menu diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 9523bcb..db32c54 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -134,6 +134,22 @@ Menuset OptItem "Settings...|S" "inset-settings" End + +# +# InsetCollapsable context menu +# + Menu "context-branch" + OptItem "Open Inset|O" "next-inset-toggle open" + OptItem "Close Inset|C" "next-inset-toggle close" + Separator + OptItem "Activate Branch|A" "next-inset-toggle activate" + OptItem "Deactivate Branch|E" "next-inset-toggle deactivate" + Separator + Item "Dissolve Inset|D" "inset-dissolve" + OptItem "Settings...|S" "inset-settings" + End + + # # InsetBox context menu # diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index e22ed9a..137f760 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2204,11 +2204,12 @@ void LyXAction::init() * \var lyx::FuncCode lyx::LFUN_INSET_TOGGLE * \li Action: Toggles the collapsable inset we are currently in. * \li Syntax: inset-toggle [<ARG>] - * \li Params: <ARG>: <open|close|toggle|assign>. \n + * \li Params: <ARG>: <open|close|toggle|assign|activate|deactivate>. \n open/close/toggle are for collapsable insets. close can be currently used by #LFUN_NEXT_INSET_TOGGLE. toggle is used when no argument is given.\n assign synchronize the branch-inset with activation status of the branch. - Used for global toggling when changed activation. + Used for global toggling when changed activation.\n + (de)activate toggles branch activation at the cursor position. * \li Origin: lasgouttes, 19 Jul 2001 * \endvar */ diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 68dfe19..468933b 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -153,8 +153,11 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) else cur.undispatched(); } - } - else + } else if (cmd.argument() == "deactivate") { + buffer().dispatch(FuncRequest(LFUN_BRANCH_DEACTIVATE, params().branch)); + } else if (cmd.argument() == "activate") { + buffer().dispatch(FuncRequest(LFUN_BRANCH_ACTIVATE, params().branch)); + } else InsetCollapsable::doDispatch(cur, cmd); break; @@ -183,6 +186,10 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd, flag.setEnabled(status(cur.bv()) != Open); else flag.setEnabled(status(cur.bv()) != Collapsed); + } else if (cmd.argument() == "activate") { + flag.setEnabled(!isBranchSelected()); + } else if (cmd.argument() == "deactivate") { + flag.setEnabled(isBranchSelected()); } else flag.setEnabled(true); break; @@ -290,6 +297,12 @@ void InsetBranch::addToToc(DocIterator const & cpit) } +docstring InsetBranch::contextMenu(BufferView const &, int, int) const +{ + return from_ascii("context-branch"); +} + + void InsetBranchParams::write(ostream & os) const { os << "Branch " << to_utf8(branch) << '\n'; diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index 607d8cf..418b654 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -111,6 +111,8 @@ private: docstring name() const { return from_ascii("Branch"); } /// Inset * clone() const { return new InsetBranch(*this); } + /// + docstring contextMenu(BufferView const & bv, int x, int y) const; /// friend class InsetBranchParams;