]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbranch.C
The speed patch: redraw only rows that have changed
[lyx.git] / src / insets / insetbranch.C
index c2fc42df2ca42e1301f3ab9e3e60d1d134b5dee7..a18bf41d4f8693cc3b5aeefbd99dc70c628cc570 100644 (file)
@@ -94,13 +94,18 @@ void InsetBranch::setButtonLabel()
        font.decSize();
        font.decSize();
 
-       string s = "Branch: " + params_.branch;
-       setLabel(isOpen() ? s : getNewLabel(s) );
+       string s = _("Branch: ") + params_.branch;
        font.setColor(LColor::foreground);
-       if (!params_.branch.empty())
-               setBackgroundColor(lcolor.getFromLyXName(params_.branch));
-       else
+       if (!params_.branch.empty()) {
+               LColor_color c = lcolor.getFromLyXName(params_.branch);
+               if (c == LColor::none) {
+                       c = LColor::error;
+                       s = _("Undef: ") + s;
+               }
+               setBackgroundColor(c);
+       } else
                setBackgroundColor(LColor::background);
+       setLabel(isOpen() ? s : getNewLabel(s) );
        setLabelFont(font);
 }
 
@@ -143,39 +148,22 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd)
 
 
        case LFUN_INSET_TOGGLE:
-               // We assume that this lfun is indeed going to be dispatched.
-               cur.dispatched();
-
-               if (cmd.argument == "open")
-                       setStatus(Open);
-               else if (cmd.argument == "close") {
-                       setStatus(Collapsed);
-                       leaveInset(cur, *this);
-               } else if (cmd.argument == "toggle") {
-                       if (isOpen()) {
-                               setStatus(Collapsed);
-                               leaveInset(cur, *this);
-                       } else
-                       setStatus(Open);
-
-               // The branch inset uses "assign".
-               } else if (cmd.argument == "assign"
-                          || cmd.argument.empty()) {
-                       BranchList const & branchlist =
-                               cur.buffer().params().branchlist();
-                       if (isBranchSelected(branchlist)) {
+               if (cmd.argument == "assign" || cmd.argument.empty()) {
+                       // The branch inset uses "assign".
+                       if (isBranchSelected(cur.buffer())) {
                                if (status() != Open)
-                                       setStatus(Open);
+                                       setStatus(cur, Open);
                                else
                                        cur.undispatched();
                        } else {
-                               if (status() != Collapsed) {
-                                       setStatus(Collapsed);
-                                       leaveInset(cur, *this);
-                               } else
+                               if (status() != Collapsed)
+                                       setStatus(cur, Collapsed);
+                               else
                                        cur.undispatched();
                        }
                }
+               else
+                       InsetCollapsable::doDispatch(cur, cmd);
                break;
 
        default:
@@ -200,19 +188,10 @@ bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd,
                        flag.enabled(true);
                else if (cmd.argument == "assign"
                           || cmd.argument.empty()) {
-                       BranchList const & branchlist =
-                               cur.buffer().params().branchlist();
-                       if (isBranchSelected(branchlist)) {
-                               if (status() != Open)
-                                       flag.enabled(true);
-                               else
-                                       flag.enabled(false);
-                       } else {
-                               if (status() != Collapsed)
-                                       flag.enabled(true);
-                               else
-                                       flag.enabled(false);
-                       }
+                       if (isBranchSelected(cur.buffer()))
+                               flag.enabled(status() != Open);
+                       else
+                               flag.enabled(status() != Collapsed);
                } else
                        flag.enabled(true);
                break;
@@ -224,8 +203,10 @@ bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd,
 }
 
 
-bool InsetBranch::isBranchSelected(BranchList const & branchlist) const
+bool InsetBranch::isBranchSelected(Buffer const & buffer) const
 {
+       Buffer const & realbuffer = *buffer.getMasterBuffer();
+       BranchList const & branchlist = realbuffer.params().branchlist();
        BranchList::const_iterator const end = branchlist.end();
        BranchList::const_iterator it =
                std::find_if(branchlist.begin(), end,
@@ -239,7 +220,7 @@ bool InsetBranch::isBranchSelected(BranchList const & branchlist) const
 int InsetBranch::latex(Buffer const & buf, ostream & os,
                       OutputParams const & runparams) const
 {
-       return isBranchSelected(buf.params().branchlist()) ?
+       return isBranchSelected(buf) ?
                InsetText::latex(buf, os, runparams) : 0;
 }
 
@@ -247,7 +228,7 @@ int InsetBranch::latex(Buffer const & buf, ostream & os,
 int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os,
                          OutputParams const & runparams) const
 {
-       return isBranchSelected(buf.params().branchlist()) ?
+       return isBranchSelected(buf) ?
                InsetText::linuxdoc(buf, os, runparams) : 0;
 }
 
@@ -255,7 +236,7 @@ int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os,
 int InsetBranch::docbook(Buffer const & buf, std::ostream & os,
                         OutputParams const & runparams) const
 {
-       return isBranchSelected(buf.params().branchlist()) ?
+       return isBranchSelected(buf) ?
                InsetText::docbook(buf, os, runparams) : 0;
 }
 
@@ -263,7 +244,7 @@ int InsetBranch::docbook(Buffer const & buf, std::ostream & os,
 int InsetBranch::plaintext(Buffer const & buf, std::ostream & os,
                           OutputParams const & runparams) const
 {
-       return isBranchSelected(buf.params().branchlist()) ?
+       return isBranchSelected(buf) ?
                InsetText::plaintext(buf, os, runparams): 0;
 }