]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormBranch.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / FormBranch.C
index 3ef6f982a6cf2bd7ef88c7d712b2beb04b7e4db1..c2badd04ea346446011031fb9576f4ed5414d33e 100644 (file)
@@ -5,20 +5,26 @@
  *
  * \author Martin Vermeer
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 
 #include <config.h>
 
-#include "xformsBC.h"
-#include "ControlBranch.h"
 #include "FormBranch.h"
 #include "forms/form_branch.h"
-#include "xforms_helpers.h" // formatted
-#include "lyx_forms.h"
+#include "xformsBC.h"
+
+#include "BranchList.h"
+
+#include "controllers/ControlBranch.h"
+
 #include "insets/insetbranch.h"
-#include "debug.h"
+
+#include "lyx_forms.h"
+
+using std::string;
+
 
 typedef FormController<ControlBranch, FormView<FD_branch> > base_class;
 
@@ -29,12 +35,8 @@ FormBranch::FormBranch(Dialog & parent)
 
 void FormBranch::build()
 {
-       string all_branches(controller().params().branchlist.allBranches());
-
        dialog_.reset(build_branch(this));
 
-       fl_addto_choice(dialog_->choice_branch, all_branches.c_str());
-       
        bcview().setOK(dialog_->button_ok);
        bcview().setApply(dialog_->button_apply);
        bcview().setCancel(dialog_->button_cancel);
@@ -43,21 +45,30 @@ void FormBranch::build()
 
 void FormBranch::update()
 {
-       // Make changes in all_branches propagate within session:
-       string all_branches(controller().params().branchlist.allBranches());
+       typedef BranchList::const_iterator const_iterator;
+
+       BranchList const & branchlist = controller().branchlist();
+       string const cur_branch = controller().params().branch;
+
        fl_clear_choice(dialog_->choice_branch);
-       fl_addto_choice(dialog_->choice_branch, all_branches.c_str());
 
-       string branch(controller().params().branch);
-       if (all_branches.find(branch) != string::npos && branch != "none")
-               fl_set_choice_text(dialog_->choice_branch, branch.c_str());
+       const_iterator const begin = branchlist.begin();
+       const_iterator const end = branchlist.end();
+       int id = 1;
+       int count = 1;
+       for (const_iterator it = begin; it != end; ++it, ++count) {
+               string const & branch = it->getBranch();
+               fl_addto_choice(dialog_->choice_branch, branch.c_str());
+
+               if (cur_branch == branch)
+                       id = count;
+       }
+       fl_set_choice(dialog_->choice_branch, id);
 }
 
 
 void FormBranch::apply()
 {
        string const type = fl_get_choice_text(dialog_->choice_branch);
-
        controller().params().branch = type;
 }
-