]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiRef.cpp
Compil fix.
[lyx.git] / src / frontends / qt4 / GuiRef.cpp
index a01e1d339a83a5433081a4d234efd909123eb719..c7770453d67d6f0899e008d7707ed9255e01e459 100644 (file)
@@ -21,9 +21,8 @@
 
 #include "insets/InsetRef.h"
 
-#include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
-
-#include <boost/filesystem/operations.hpp>
+#include "support/FileName.h"
+#include "support/filetools.h" // makeAbsPath, makeDisplayPath
 
 #include <QLineEdit>
 #include <QCheckBox>
 #include <QToolTip>
 #include <QCloseEvent>
 
-#include <algorithm>
-
-using std::find;
-using std::vector;
-using std::string;
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
 
-using support::makeAbsPath;
-using support::makeDisplayPath;
-
-//FIXME It should be possible to eliminate lfun_name_
-//now and recover that information from params().insetType().
-//But let's not do that quite yet.
-/// Flags what action is taken by Kernel::dispatch()
-static std::string const lfun_name_ = "ref";
-
-GuiRef::GuiRef(LyXView & lv)
-       : GuiDialog(lv, "ref"), Controller(this),
-               params_("ref")
+GuiRef::GuiRef(GuiView & lv)
+       : GuiDialog(lv, "ref", qt_("Cross-reference")),
+         params_(insetCode("ref"))
 {
        setupUi(this);
-       setController(this, false);
-       setViewTitle(_("Cross-reference"));
 
        sort_ = false;
        at_ref_ = false;
@@ -70,9 +55,9 @@ GuiRef::GuiRef(LyXView & lv)
 
        connect(typeCO, SIGNAL(activated(int)),
                this, SLOT(changed_adaptor()));
-       connect(referenceED, SIGNAL(textChanged(const QString &)),
+       connect(referenceED, SIGNAL(textChanged(QString)),
                this, SLOT(changed_adaptor()));
-       connect(nameED, SIGNAL(textChanged(const QString &)),
+       connect(nameED, SIGNAL(textChanged(QString)),
                this, SLOT(changed_adaptor()));
        connect(refsLW, SIGNAL(itemClicked(QListWidgetItem *)),
                this, SLOT(refHighlighted(QListWidgetItem *)));
@@ -117,6 +102,7 @@ void GuiRef::gotoClicked()
        gotoRef();
 }
 
+
 void GuiRef::selectionChanged()
 {
        if (isBufferReadonly())
@@ -133,7 +119,7 @@ void GuiRef::selectionChanged()
 
 void GuiRef::refHighlighted(QListWidgetItem * sel)
 {
-       if (controller().isBufferReadonly())
+       if (isBufferReadonly())
                return;
 
 /*     int const cur_item = refsLW->currentRow();
@@ -195,7 +181,7 @@ void GuiRef::closeEvent(QCloseEvent * e)
 {
        slotClose();
        reset_dialog();
-       GuiDialog::closeEvent(e);
+       e->accept();
 }
 
 
@@ -224,15 +210,17 @@ void GuiRef::updateContents()
        vector<string> buffers = theBufferList().getFileNames();
        for (vector<string>::iterator it = buffers.begin();
             it != buffers.end(); ++it) {
-               bufferCO->addItem(toqstr(lyx::to_utf8(makeDisplayPath(*it))));
+               bufferCO->addItem(toqstr(makeDisplayPath(*it)));
        }
 
        // restore the buffer combo setting for new insets
        if (params_["reference"].empty() && restored_buffer_ != -1
-       && restored_buffer_ < bufferCO->count())
+           && restored_buffer_ < bufferCO->count()) 
                bufferCO->setCurrentIndex(restored_buffer_);
-       else
-               bufferCO->setCurrentIndex(bufferNum());
+       else {
+               int num = theBufferList().bufferNum(buffer().absFileName());
+               bufferCO->setCurrentIndex(num);
+       }
 
        updateRefs();
        bc().setValid(false);
@@ -311,7 +299,7 @@ void GuiRef::redoRefs()
        // the first item inserted
        QString const oldSelection(referenceED->text());
 
-       for (std::vector<docstring>::const_iterator iter = refs_.begin();
+       for (vector<docstring>::const_iterator iter = refs_.begin();
                iter != refs_.end(); ++iter) {
                refsLW->addItem(toqstr(*iter));
        }
@@ -326,20 +314,18 @@ void GuiRef::redoRefs()
        if (!oldSelection.isEmpty() || !last_reference_.isEmpty()) {
                bool const newInset = oldSelection.isEmpty();
                QString textToFind = newInset ? last_reference_ : oldSelection;
-               bool foundItem = false;
-               for (int i = 0; !foundItem && i < refsLW->count(); ++i) {
+               last_reference_.clear();
+               for (int i = 0; i != refsLW->count(); ++i) {
                        QListWidgetItem * item = refsLW->item(i);
                        if (textToFind == item->text()) {
                                refsLW->setCurrentItem(item);
                                refsLW->setItemSelected(item, !newInset);
                                //Make sure selected item is visible
                                refsLW->scrollToItem(item);
-                               foundItem = true;
+                               last_reference_ = textToFind;
+                               break;
                        }
                }
-               if (foundItem)
-                       last_reference_ = textToFind;
-               else last_reference_ = "";
        }
        refsLW->setUpdatesEnabled(true);
        refsLW->update();
@@ -354,7 +340,8 @@ void GuiRef::updateRefs()
 {
        refs_.clear();
        string const name = theBufferList().getFileNames()[bufferCO->currentIndex()];
-       Buffer const * buf = theBufferList().getBuffer(makeAbsPath(name).absFilename());
+       Buffer const * buf = theBufferList().getBuffer(
+               support::makeAbsPath(name).absFilename());
        buf->getLabelList(refs_);
        sortCB->setEnabled(!refs_.empty());
        refsLW->setEnabled(!refs_.empty());
@@ -382,41 +369,22 @@ void GuiRef::gotoBookmark()
 }
 
 
-int GuiRef::bufferNum() const
-{
-       vector<string> buffers = theBufferList().getFileNames();
-       string const name = buffer().fileName();
-       vector<string>::const_iterator cit =
-               std::find(buffers.begin(), buffers.end(), name);
-       if (cit == buffers.end())
-               return 0;
-       return int(cit - buffers.begin());
-}
-
-
-bool GuiRef::initialiseParams(string const & data)
+bool GuiRef::initialiseParams(std::string const & data)
 {
-       // The name passed with LFUN_INSET_APPLY is also the name
-       // used to identify the mailer.
-       InsetCommandMailer::string2params(lfun_name_, data, params_);
+       InsetCommand::string2params("ref", data, params_);
        return true;
 }
 
 
-void GuiRef::clearParams()
-{
-       params_.clear();
-}
-
-
 void GuiRef::dispatchParams()
 {
-       string const lfun = InsetCommandMailer::params2string(lfun_name_, params_);
+       std::string const lfun = InsetCommand::params2string("ref", params_);
        dispatch(FuncRequest(getLfun(), lfun));
 }
 
 
-Dialog * createGuiRef(LyXView & lv) { return new GuiRef(lv); }
+
+Dialog * createGuiRef(GuiView & lv) { return new GuiRef(lv); }
 
 
 } // namespace frontend