]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QCitationDialog.C
code cosmetics to the iterator fix
[lyx.git] / src / frontends / qt2 / QCitationDialog.C
index 020a50e85d7c70a898d90f5391fb4b1d3fe8e64e..70a245e6de9cc72deb3a96e3ccab6659062e828d 100644 (file)
 
 #include <config.h>
 
+#include "QCitationDialog.h"
+#include "ui/QCitationFindDialogBase.h"
+#include "QCitation.h"
 #include "qt_helpers.h"
+
 #include "controllers/ControlCitation.h"
-#include "ButtonController.h"
+#include "controllers/ButtonController.h"
 
 #include <qcheckbox.h>
 #include <qlineedit.h>
 #include <qmultilineedit.h>
 #include <qpushbutton.h>
 
-#include "ui/QCitationFindDialogBase.h"
-#include "QCitationDialog.h"
-#include "QCitation.h"
 
 using std::vector;
 using std::string;
+using std::swap;
 
+namespace lyx {
+namespace frontend {
 
 QCitationDialog::QCitationDialog(QCitation * form)
        : QCitationDialogBase(0, 0, false, 0),
@@ -79,7 +83,8 @@ void QCitationDialog::openFind()
        if (form_->readOnly())
                return;
 
-       if (selectedLB->count() == 0 && add_->availableLB->count() != 0){
+       if (isVisible() && selectedLB->count() == 0 
+           && add_->availableLB->count() != 0){
                // open the find dialog
                add();
                // and let the user press ok after a selection
@@ -184,16 +189,16 @@ void QCitationDialog::up()
 {
        int const sel = selectedLB->currentItem();
 
+       BOOST_ASSERT(sel > 0);
+
        // Move the selected key up one line
-       vector<string>::iterator it = form_->citekeys.begin() + sel;
-       string const tmp = *it;
+       string const tmp = form_->citekeys[sel];
 
        selectedLB->removeItem(sel);
-       form_->citekeys.erase(it);
+       swap(form_->citekeys[sel - 1], form_->citekeys[sel]);
 
        selectedLB->insertItem(toqstr(tmp), sel - 1);
        selectedLB->setSelected(sel - 1, true);
-       form_->citekeys.insert(it - 1, tmp);
 
        form_->changed();
        form_->fillStyles();
@@ -205,16 +210,16 @@ void QCitationDialog::down()
 {
        int const sel = selectedLB->currentItem();
 
+       BOOST_ASSERT(sel < (int)form_->citekeys.size());
+
        // Move the selected key down one line
-       vector<string>::iterator it = form_->citekeys.begin() + sel;
-       string const tmp = *it;
+       string const tmp = form_->citekeys[sel];
 
        selectedLB->removeItem(sel);
-       form_->citekeys.erase(it);
+       swap(form_->citekeys[sel + 1], form_->citekeys[sel]);
 
        selectedLB->insertItem(toqstr(tmp), sel + 1);
        selectedLB->setSelected(sel + 1, true);
-       form_->citekeys.insert(it + 1, tmp);
 
        form_->changed();
        form_->fillStyles();
@@ -249,8 +254,6 @@ void QCitationDialog::find(biblio::Direction dir)
        // Find the NEXT instance...
        if (dir == biblio::FORWARD)
                start += 1;
-       else
-               start -= 1;
 
        bool const casesens = add_->searchCaseCB->isChecked();
        string const str = fromqstr(add_->searchED->text());
@@ -279,6 +282,12 @@ void QCitationDialog::find(biblio::Direction dir)
        }
 
        // Update the display
+       // note that we have multi selection mode!
+       add_->availableLB->setSelected(sel, false);
        add_->availableLB->setSelected(found, true);
+       add_->availableLB->setCurrentItem(found);
        add_->availableLB->ensureCurrentVisible();
 }
+
+} // namespace frontend
+} // namespace lyx