]> git.lyx.org Git - lyx.git/commitdiff
Migrate Branch dialog to InsetParamsWidget
authorAbdelrazak Younes <younes@lyx.org>
Fri, 19 Feb 2010 20:57:25 +0000 (20:57 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Fri, 19 Feb 2010 20:57:25 +0000 (20:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33521 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiBranch.cpp
src/frontends/qt4/GuiBranch.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/InsetParamsDialog.cpp
src/frontends/qt4/ui/BranchUi.ui
src/insets/Inset.cpp
src/insets/InsetBranch.cpp
src/insets/InsetBranch.h

index 57484c86f174426fd29c12c7d158339017d265d7..3124314401dda7abec6f6fe49b38774a64330b9e 100644 (file)
@@ -19,7 +19,6 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BranchList.h"
-#include "FuncRequest.h"
 
 #include "insets/InsetBranch.h"
 
@@ -30,36 +29,21 @@ using namespace std;
 namespace lyx {
 namespace frontend {
 
-GuiBranch::GuiBranch(GuiView & lv)
-       : GuiDialog(lv, "branch", qt_("Branch Settings"))
+GuiBranch::GuiBranch(QWidget * parent) : InsetParamsWidget(parent)
 {
        setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
-       connect(branchCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-
-       bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setCancel(closePB);
-}
-
-
-void GuiBranch::change_adaptor()
-{
-       changed();
+       connect(branchCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
 }
 
 
-void GuiBranch::updateContents()
+void GuiBranch::paramsToDialog(Inset const * inset)
 {
+       InsetBranch const * ib = static_cast<InsetBranch const *>(inset);
        typedef BranchList::const_iterator const_iterator;
-
-       BranchList const & branchlist = buffer().params().branchlist();
-       docstring const cur_branch = params_.branch;
+       BranchList const & branchlist = ib->buffer().params().branchlist();
+       docstring const cur_branch = ib->branch();
 
        branchCO->clear();
-
        const_iterator const begin = branchlist.begin();
        const_iterator const end = branchlist.end();
        int id = 0;
@@ -67,7 +51,6 @@ void GuiBranch::updateContents()
        for (const_iterator it = begin; it != end; ++it, ++count) {
                docstring const & branch = it->branch();
                branchCO->addItem(toqstr(branch));
-
                if (cur_branch == branch)
                        id = count;
        }
@@ -75,34 +58,12 @@ void GuiBranch::updateContents()
 }
 
 
-void GuiBranch::applyView()
-{
-       params_.branch = qstring_to_ucs4(branchCO->currentText());
-}
-
-
-bool GuiBranch::initialiseParams(string const & data)
-{
-       InsetBranch::string2params(data, params_);
-       return true;
-}
-
-
-void GuiBranch::clearParams()
-{
-       params_ = InsetBranchParams();
-}
-
-
-void GuiBranch::dispatchParams()
+docstring GuiBranch::dialogToParams() const
 {
-       dispatch(FuncRequest(getLfun(), InsetBranch::params2string(params_)));
+       InsetBranchParams params(qstring_to_ucs4(branchCO->currentText()));
+       return from_utf8(InsetBranch::params2string(params));
 }
 
-
-Dialog * createGuiBranch(GuiView & lv) { return new GuiBranch(lv); }
-
-
 } // namespace frontend
 } // namespace lyx
 
index b491d738bec9f7b2579509722001abb81b5cb499..62f2ecaa2a9b121d3fdee7bebc1b2c9ea29cfe9e 100644 (file)
 #ifndef GUIBRANCH_H
 #define GUIBRANCH_H
 
-#include "GuiDialog.h"
+#include "InsetParamsWidget.h"
 #include "ui_BranchUi.h"
-#include "insets/InsetBranch.h"
-
 
 namespace lyx {
 namespace frontend {
 
-class GuiBranch : public GuiDialog, public Ui::BranchUi
+class GuiBranch : public InsetParamsWidget, public Ui::BranchUi
 {
        Q_OBJECT
 
 public:
-       GuiBranch(GuiView & lv);
-
-private Q_SLOTS:
-       void change_adaptor();
+       GuiBranch(QWidget * parent = 0);
 
 private:
-       ///  Apply changes
-       void applyView();
-       /// Update dialog before showing it
-       void updateContents();
-       ///
-       bool initialiseParams(std::string const & data);
-       ///
-       void clearParams();
-       ///
-       void dispatchParams();
-       ///
-       bool isBufferDependent() const { return true; }
-
-       ///
-       InsetBranchParams params_;
+       /// \name DialogView inherited methods
+       //@{
+       InsetCode insetCode() const { return BRANCH_CODE; }
+       FuncCode creationCode() const { return LFUN_BRANCH_INSERT; }
+       void paramsToDialog(Inset const *);
+       docstring dialogToParams() const;
+       //@}
 };
 
 } // namespace frontend
index d440b6c114d52b88cb8669ba888c6e5209edddd5..0c1100d9e4893ef6b2efeadf5240a758fc58a037 100644 (file)
@@ -3443,7 +3443,6 @@ Dialog * createDialog(GuiView & lv, string const & name);
 Dialog * createGuiAbout(GuiView & lv);
 Dialog * createGuiBibitem(GuiView & lv);
 Dialog * createGuiBibtex(GuiView & lv);
-Dialog * createGuiBranch(GuiView & lv);
 Dialog * createGuiChanges(GuiView & lv);
 Dialog * createGuiCharacter(GuiView & lv);
 Dialog * createGuiCitation(GuiView & lv);
@@ -3501,8 +3500,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiBibitem(*this);
        if (name == "bibtex")
                return createGuiBibtex(*this);
-       if (name == "branch")
-               return createGuiBranch(*this);
        if (name == "changes")
                return createGuiChanges(*this);
        if (name == "character")
index e366bcbce192dd41d794d4923135af568e845bb0..16f29ca8e054861987e09ee085267423688fa201 100644 (file)
@@ -13,6 +13,7 @@
 #include "InsetParamsDialog.h"\r
 \r
 #include "GuiBox.h"\r
+#include "GuiBranch.h"\r
 #include "GuiERT.h"\r
 #include "GuiInfo.h"\r
 #include "GuiTabular.h"\r
@@ -204,6 +205,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
        case FLOAT_CODE:\r
                widget = new FloatPlacement(true);\r
                break;\r
+       case BRANCH_CODE:\r
+               widget = new GuiBranch;\r
+               break;\r
        case BOX_CODE:\r
                widget = new GuiBox;\r
                break;\r
index 4266f2084e9dc849c34b78c385070862be79b374..44700a70c738ca995f175b63a0606ca7b4a2c056 100644 (file)
@@ -1,84 +1,32 @@
-<ui version="4.0" >
+<ui version="4.0">
  <class>BranchUi</class>
- <widget class="QDialog" name="BranchUi" >
-  <property name="geometry" >
+ <widget class="QWidget" name="BranchUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>219</width>
-    <height>99</height>
+    <width>259</width>
+    <height>38</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <property name="sizeGripEnabled" >
-   <bool>true</bool>
-  </property>
-  <layout class="QGridLayout" >
-   <property name="margin" >
-    <number>9</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
-   <item row="0" column="0" colspan="3" >
-    <layout class="QVBoxLayout" >
-     <property name="margin" >
-      <number>0</number>
-     </property>
-     <property name="spacing" >
-      <number>6</number>
-     </property>
-     <item>
-      <widget class="QLabel" name="branchLA" >
-       <property name="text" >
-        <string>&amp;Available branches:</string>
-       </property>
-       <property name="buddy" >
-        <cstring>branchCO</cstring>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QComboBox" name="branchCO" >
-       <property name="toolTip" >
-        <string>Select your branch</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item row="1" column="0" >
-    <spacer>
-     <property name="orientation" >
-      <enum>Qt::Horizontal</enum>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QLabel" name="branchLA">
+     <property name="text">
+      <string>&amp;Available branches:</string>
      </property>
-     <property name="sizeHint" >
-      <size>
-       <width>31</width>
-       <height>20</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
-   <item row="1" column="2" >
-    <widget class="QPushButton" name="closePB" >
-     <property name="text" >
-      <string>&amp;Close</string>
-     </property>
-     <property name="default" >
-      <bool>true</bool>
+     <property name="buddy">
+      <cstring>branchCO</cstring>
      </property>
     </widget>
    </item>
-   <item row="1" column="1" >
-    <widget class="QPushButton" name="okPB" >
-     <property name="text" >
-      <string>&amp;OK</string>
-     </property>
-     <property name="default" >
-      <bool>false</bool>
+   <item row="0" column="1">
+    <widget class="QComboBox" name="branchCO">
+     <property name="toolTip">
+      <string>Select your branch</string>
      </property>
     </widget>
    </item>
  </widget>
  <tabstops>
   <tabstop>branchCO</tabstop>
-  <tabstop>okPB</tabstop>
-  <tabstop>closePB</tabstop>
  </tabstops>
  <includes>
-  <include location="local" >qt_i18n.h</include>
+  <include location="local">qt_i18n.h</include>
  </includes>
  <resources/>
  <connections/>
index b3fdf6fd944e48d9d2addd3445f1c7c28f82a8ef..119c1c4cd7048c469449680225fe88a431993a8d 100644 (file)
@@ -100,7 +100,7 @@ static void build_translator()
        insetnames[OPTARG_CODE] = InsetName("optarg");
        insetnames[NEWLINE_CODE] = InsetName("newline");
        insetnames[LINE_CODE] = InsetName("line");
-       insetnames[BRANCH_CODE] = InsetName("branch");
+       insetnames[BRANCH_CODE] = InsetName("branch", _("Branch"));
        insetnames[BOX_CODE] = InsetName("box", _("Box"));
        insetnames[FLEX_CODE] = InsetName("flex");
        insetnames[SPACE_CODE] = InsetName("space");
@@ -296,8 +296,8 @@ bool Inset::showInsetDialog(BufferView * bv) const
        case ERT_CODE:
        case FLOAT_CODE:
        case BOX_CODE:
+       case BRANCH_CODE:
        case INFO_CODE:
-       //FIXME: not ready yet.
        case TABULAR_CODE:
        case VSPACE_CODE:
                bv->showDialog(insetName(code));
index 900cd8b54ff54a506e60fcebda6aff5d98281424..fa238674b39736d4c0690d2b29bcb897cb4e80f4 100644 (file)
@@ -46,12 +46,6 @@ InsetBranch::InsetBranch(Buffer * buf, InsetBranchParams const & params)
 {}
 
 
-InsetBranch::~InsetBranch()
-{
-       hideDialogs("branch", this);
-}
-
-
 void InsetBranch::write(ostream & os) const
 {
        params_.write(os);
@@ -116,14 +110,6 @@ ColorCode InsetBranch::backgroundColor(PainterInfo const & pi) const
 }
 
 
-bool InsetBranch::showInsetDialog(BufferView * bv) const
-{
-       bv->showDialog("branch", params2string(params()),
-                       const_cast<InsetBranch *>(this));
-       return true;
-}
-
-
 void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
@@ -133,11 +119,6 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
                params_.branch = params.branch;
                break;
        }
-
-       case LFUN_INSET_DIALOG_UPDATE:
-               cur.bv().updateDialog("branch", params2string(params()));
-               break;
-
        case LFUN_BRANCH_ACTIVATE:
        case LFUN_BRANCH_DEACTIVATE: {
                // FIXME: I do not like this cast, but have no other idea...
@@ -153,7 +134,6 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
                our_branch->setSelected(cmd.action == LFUN_BRANCH_ACTIVATE);
                break;
        }
-
        case LFUN_INSET_TOGGLE:
                if (cmd.argument() == "assign")
                        setStatus(cur, isBranchSelected() ? Open : Collapsed);
@@ -173,7 +153,6 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY:
-       case LFUN_INSET_DIALOG_UPDATE:
                flag.setEnabled(true);
                break;
 
index bcebd00e1a06bf636bd90e6be930e239fe0edcc2..4100a631ccd6261180113112280f8687f0829f1d 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "InsetCollapsable.h"
 
-
 namespace lyx {
 
 class InsetBranchParams {
@@ -44,8 +43,6 @@ class InsetBranch : public InsetCollapsable
 public:
        ///
        InsetBranch(Buffer *, InsetBranchParams const &);
-       ///
-       ~InsetBranch();
 
        ///
        static std::string params2string(InsetBranchParams const &);
@@ -68,8 +65,6 @@ private:
        ///
        ColorCode backgroundColor(PainterInfo const &) const;
        ///
-       bool showInsetDialog(BufferView *) const;
-       ///
        int latex(odocstream &, OutputParams const &) const;
        ///
        int plaintext(odocstream &, OutputParams const &) const;