]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbranch.C
Remove a whole heap of redundant functions from classes derived from
[lyx.git] / src / insets / insetbranch.C
index a7da67000a179af366c0c995e8b58bce98ca48c8..9cc918f402d28f79cdd029f3aa0b486a28a9d5dd 100644 (file)
 
 #include <config.h>
 
-#include "Lsstream.h"
-
 #include "insetbranch.h"
-#include "gettext.h"
-#include "lyxfont.h"
-#include "language.h"
+
 #include "buffer.h"
+#include "bufferparams.h"
 #include "BufferView.h"
-#include "LaTeXFeatures.h"
-#include "latexrunparams.h"
+#include "dispatchresult.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "LColor.h"
 #include "lyxlex.h"
-#include "lyxtext.h"
-#include "insets/insettext.h"
-#include "support/LOstream.h"
-#include "support/lstrings.h"
-#include "debug.h"
+#include "paragraph.h"
 
-using std::ostream;
+#include "support/std_sstream.h"
+
+
+using std::string;
 using std::auto_ptr;
+using std::istringstream;
+using std::ostream;
+using std::ostringstream;
+
 
 void InsetBranch::init()
 {
        setInsetName("Branch");
+       setButtonLabel();
 }
 
 
@@ -42,7 +45,7 @@ InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
        params_.branch = label;
        // Hack: stash the list of all allowable branch labels from this
        // buffer into inset's parm list as a "stowaway":
-       params_.branchlist = bp.branchlist;
+       params_.branchlist = bp.branchlist();
        init();
 }
 
@@ -56,8 +59,7 @@ InsetBranch::InsetBranch(InsetBranch const & in)
 
 InsetBranch::~InsetBranch()
 {
-       InsetBranchMailer mailer("branch", *this);
-       mailer.hideDialog();
+       InsetBranchMailer(*this).hideDialog();
 }
 
 
@@ -97,12 +99,11 @@ void InsetBranch::setButtonLabel()
        font.decSize();
        font.decSize();
 
-       setLabel(params_.branch);
+       setLabel("Branch: " + params_.branch);
        font.setColor(LColor::foreground);
-       string const color = params_.branchlist.getColor(params_.branch);
-       if (!color.empty()) {
+       if (!params_.branch.empty())
                setBackgroundColor(lcolor.getFromLyXName(params_.branch));
-       else
+       else
                setBackgroundColor(LColor::background);
        setLabelFont(font);
 }
@@ -110,76 +111,83 @@ void InsetBranch::setButtonLabel()
 
 bool InsetBranch::showInsetDialog(BufferView * bv) const
 {
-       InsetBranchMailer("branch", const_cast<InsetBranch &>(*this)).showDialog(bv);
+       InsetBranchMailer(const_cast<InsetBranch &>(*this)).showDialog(bv);
        return true;
 }
 
 
-dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd)
+DispatchResult
+InsetBranch::priv_dispatch(FuncRequest const & cmd,
+                          idx_type & idx, pos_type & pos)
 {
        BufferView * bv = cmd.view();
        switch (cmd.action) {
-       case LFUN_INSET_MODIFY:
-               {
+       case LFUN_INSET_MODIFY: {
                InsetBranchParams params;
                InsetBranchMailer::string2params(cmd.argument, params);
                params_.branch = params.branch;
                setButtonLabel();
-               bv->updateInset(this);
-               return DISPATCHED;
-               }
-       case LFUN_INSET_EDIT:
+               return DispatchResult(true, true);
+       }
+
+       case LFUN_MOUSE_PRESS:
                if (cmd.button() != mouse_button::button3)
-                       return InsetCollapsable::localDispatch(cmd);
-               
-               return UNDISPATCHED;
+                       return InsetCollapsable::priv_dispatch(cmd, idx, pos);
+               return DispatchResult(false);
+
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetBranchMailer("branch", *this).updateDialog(bv);
-               return DISPATCHED;
+               InsetBranchMailer(*this).updateDialog(bv);
+               return DispatchResult(true);
+
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
-                   InsetBranchMailer("branch", *this).showDialog(bv);
-                       return DISPATCHED;
+                       InsetBranchMailer(*this).showDialog(bv);
+                       return DispatchResult(true);
                }
-               // fallthrough:
+               return InsetCollapsable::priv_dispatch(cmd, idx, pos);
+               
        default:
-               return InsetCollapsable::localDispatch(cmd);
+               return InsetCollapsable::priv_dispatch(cmd, idx, pos);
        }
 }
 
 
-
 int InsetBranch::latex(Buffer const & buf, ostream & os,
-       LatexRunParams const & runparams) const
+       OutputParams const & runparams) const
 {
-       string const branch_sel = buf.params.branchlist.allSelected();
+       string const branch_sel = buf.params().branchlist().allSelected();
        if (branch_sel.find(params_.branch, 0) != string::npos)
                return inset.latex(buf, os, runparams);
        return 0;
 }
 
 
-int InsetBranch::linuxdoc(Buffer const &, std::ostream &) const
+int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os,
+                         OutputParams const & runparams) const
 {
+       string const branch_sel = buf.params().branchlist().allSelected();
+       if (branch_sel.find(params_.branch, 0) != string::npos)
+               return inset.linuxdoc(buf, os, runparams);
        return 0;
 }
 
 
-int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
+int InsetBranch::docbook(Buffer const & buf, std::ostream & os,
+                        OutputParams const & runparams) const
 {
-       // untested - MV
-       string const branch_sel = buf.params.branchlist.allSelected();
+       string const branch_sel = buf.params().branchlist().allSelected();
        if (branch_sel.find(params_.branch, 0) != string::npos)
-               return inset.docbook(buf, os, mixcont);
+               return inset.docbook(buf, os, runparams);
        return 0;
 }
 
 
-int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
+int InsetBranch::plaintext(Buffer const & buf, std::ostream & os,
+                      OutputParams const & runparams) const
 {
-       string const branch_sel = buf.params.branchlist.allSelected();
+       string const branch_sel = buf.params().branchlist().allSelected();
        if (branch_sel.find(params_.branch, 0) != string::npos) {
-               return inset.ascii(buf, os, ll);
+               return inset.plaintext(buf, os, runparams);
        }
        return 0;
 }
@@ -192,45 +200,49 @@ void InsetBranch::validate(LaTeXFeatures & features) const
 
 
 
-InsetBranchMailer::InsetBranchMailer(string const & name,
-                                               InsetBranch & inset)
-       : name_(name), inset_(inset)
-{
-}
+string const InsetBranchMailer:: name_("branch");
+
+InsetBranchMailer::InsetBranchMailer(InsetBranch & inset)
+       : inset_(inset)
+{}
 
 
 string const InsetBranchMailer::inset2string(Buffer const & buf) const
 {
        InsetBranchParams params = inset_.params();
-       params.branchlist = buf.params.branchlist;
+       params.branchlist = buf.params().branchlist();
        inset_.setParams(params);
-       return params2string(name_, params);
+       return params2string(params);
 }
 
 
-string const InsetBranchMailer::params2string(string const & name,
-                               InsetBranchParams const & params)
+string const InsetBranchMailer::params2string(InsetBranchParams const & params)
 {
        ostringstream data;
-       data << name << ' ';
+       data << name_ << ' ';
        params.write(data);
        // Add all_branches parameter to data:
        data << params.branchlist.allBranches() << "\n";
-       return STRCONV(data.str());
+       return data.str();
 }
 
 
 void InsetBranchMailer::string2params(string const & in,
-                                    InsetBranchParams & params)
+                                     InsetBranchParams & params)
 {
        params = InsetBranchParams();
-
        if (in.empty())
                return;
 
-       istringstream data(STRCONV(in));
+       istringstream data(in);
        LyXLex lex(0,0);
        lex.setStream(data);
+
+       string name;
+       lex >> name;
+       if (name != name_)
+               return print_mailer_error("InsetBranchMailer", in, 1, name_);
+
        params.read(lex);
        // Process all_branches here:
        if (lex.isOK()) {