]> git.lyx.org Git - features.git/commitdiff
Remove now duplicated code.
authorRichard Heck <rgheck@comcast.net>
Mon, 20 Oct 2008 19:53:15 +0000 (19:53 +0000)
committerRichard Heck <rgheck@comcast.net>
Mon, 20 Oct 2008 19:53:15 +0000 (19:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26996 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h

index 715d7da70a8e5502495dd27c3f9585d2055b6637..8214dfd8d32f6cb549956c77d8dde1af9834bfb1 100644 (file)
@@ -244,9 +244,10 @@ public:
                QPushButton * upPB, 
                QPushButton * downPB,
                GuiIdListModel * availableModel,
-               GuiIdListModel * selectedModel)
+               GuiIdListModel * selectedModel,
+               GuiDocument const * container)
        : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
-                        upPB, downPB, availableModel, selectedModel)
+                               upPB, downPB, availableModel, selectedModel), container_(container)
                {}
 private:
        ///
@@ -267,6 +268,8 @@ private:
        {
                return dynamic_cast<GuiIdListModel *>(selectedModel);
        }
+       /// 
+       GuiDocument const * container_;
 };
 
 void ModuleSelectionManager::updateAddPB() 
@@ -285,48 +288,9 @@ void ModuleSelectionManager::updateAddPB()
        QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
        string const modName = getAvailableModel()->getIDString(idx.row());
 
-       int const srows = selectedModel->rowCount();
-       // if no modules are yet selected, there is no more to check.
-       if (srows == 0) {
-               addPB->setEnabled(true);
-               return;
-       }
-
-       vector<string> selModList;
-       for (int i = 0; i < srows; ++i)
-               selModList.push_back(getSelectedModel()->getIDString(i));
-
-       vector<string>::const_iterator const selModStart = selModList.begin();
-       vector<string>::const_iterator const selModEnd   = selModList.end();
-
-       // Check whether some required module is available
-       vector<string> const reqs = getRequiredList(modName);
-       if (!reqs.empty()) {
-               bool foundOne = false;
-               vector<string>::const_iterator it = reqs.begin();
-               vector<string>::const_iterator en = reqs.end();
-               for (; it != en; ++it) {
-                       if (find(selModStart, selModEnd, *it) != selModEnd) {
-                               foundOne = true;
-                               break;
-                       }
-               }
-               if (!foundOne) {
-                       addPB->setEnabled(false);
-                       return;
-               }
-       }
-
-       // Check for conflicts with used modules
-       vector<string>::const_iterator selModIt = selModStart;
-       for (; selModIt != selModEnd; ++selModIt) {
-               if (!LyXModule::areCompatible(modName, *selModIt)) {
-                       addPB->setEnabled(false);
-                       return;
-               }
-       }
-
-       addPB->setEnabled(true);
+       bool const enable = 
+               container_->params().moduleCanBeAdded(modName);
+       addPB->setEnabled(enable);
 }
 
 
@@ -403,7 +367,7 @@ void ModuleSelectionManager::updateDelPB()
                deletePB->setEnabled(false);
                return;
        }
-       
+
        QModelIndex const & curIdx = 
                selectedLV->selectionModel()->currentIndex();
        int const curRow = curIdx.row();
@@ -905,7 +869,7 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(latexModule->childDocPB, SIGNAL(clicked()),
                this, SLOT(browseMaster()));
-       
+
        // postscript drivers
        for (int n = 0; tex_graphics[n][0]; ++n) {
                QString enc = qt_(tex_graphics_gui[n]);
@@ -950,7 +914,7 @@ GuiDocument::GuiDocument(GuiView & lv)
                        modulesModule->selectedLV,
                        modulesModule->addPB, modulesModule->deletePB,
                        modulesModule->upPB, modulesModule->downPB,
-                       availableModel(), selectedModel());
+                       availableModel(), selectedModel(), this);
        connect(selectionManager, SIGNAL(updateHook()),
                this, SLOT(updateModuleInfo()));
        connect(selectionManager, SIGNAL(updateHook()),
index 6ba761fd74d853345ecc492d665f543e9f5e452b..1e9a1f38edd351a0fa66fa0de7857b5d3306b710 100644 (file)
@@ -73,6 +73,8 @@ public:
        void updatePagestyle(std::string const &, std::string const &);
 
        void showPreamble();
+       ///
+       BufferParams const & params() const { return bp_; }
 
 private Q_SLOTS:
        void updateNumbering();
@@ -171,8 +173,6 @@ private:
        ///
        BufferParams & params() { return bp_; }
        ///
-       BufferParams const & params() const { return bp_; }
-       ///
        BufferId id() const;
        ///
        struct modInfoStruct {