]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QRef.C
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / QRef.C
index a088407ffb8b56ffbda0ffd01bd8b30f57860008..f7218513054e72bf9ce505036c626c51c7d7bea7 100644 (file)
@@ -1,21 +1,23 @@
 /**
  * \file QRef.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
  * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 
-#include "support/lstrings.h"
+#ifdef __GNUG__
+#pragma implementation
+#endif
 
-#include "QRefDialog.h"
 #include "ControlRef.h"
 #include "QRef.h"
+#include "QRefDialog.h"
 #include "Qt2BC.h"
-#include "gettext.h"
-#include "insets/insetref.h"
 
 #include <qlineedit.h>
 #include <qcheckbox.h>
 #include <qpushbutton.h>
 #include <qtooltip.h>
 
+#include "helper_funcs.h" // getStringFromVector
+#include "support/lstrings.h" // frontStrip, strip
+#include "gettext.h"
+#include "insets/insetref.h"
+
+using std::find;
+using std::max;
+using std::sort;
+using std::vector;
 using std::endl;
 
+
 typedef Qt2CB<ControlRef, Qt2DB<QRefDialog> > base_class;
 
-QRef::QRef(ControlRef & c)
-       : base_class(c, _("Cross Reference")),
+
+QRef::QRef()
+       : base_class(_("Cross Reference")),
        sort_(false), at_ref_(false)
 {
 }
@@ -46,33 +59,46 @@ void QRef::build_dialog()
        bc().addReadOnly(dialog_->nameED);
        bc().addReadOnly(dialog_->referenceED);
        bc().addReadOnly(dialog_->typeCO);
+       bc().addReadOnly(dialog_->bufferCO);
 }
 
 
 void QRef::update_contents()
 {
-       dialog_->referenceED->setText(controller().params().getContents().c_str());
-       dialog_->nameED->setText(controller().params().getOptions().c_str());
+       InsetCommandParams const & params = controller().params();
 
-       dialog_->typeCO->setCurrentItem(InsetRef::getType(controller().params().getCmdName()));
+       dialog_->referenceED->setText(params.getContents().c_str());
 
+       dialog_->nameED->setText(params.getOptions().c_str());
        dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
 
+       dialog_->typeCO->setCurrentItem(InsetRef::getType(params.getCmdName()));
        dialog_->typeCO->setEnabled(!typeAllowed() && !readOnly());
        if (!typeAllowed())
                dialog_->typeCO->setCurrentItem(0);
 
        dialog_->sortCB->setChecked(sort_);
 
+       // insert buffer list
+       dialog_->bufferCO->clear();
+       vector<string> const buffers = controller().getBufferList();
+       for (vector<string>::const_iterator it = buffers.begin();
+               it != buffers.end(); ++it) {
+               dialog_->bufferCO->insertItem(it->c_str());
+       }
+       dialog_->bufferCO->setCurrentItem(controller().getBufferNum());
+
        updateRefs();
 }
 
 
 void QRef::apply()
 {
-       controller().params().setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
-       controller().params().setContents(dialog_->referenceED->text().latin1());
-       controller().params().setOptions(dialog_->nameED->text().latin1());
+       InsetCommandParams & params = controller().params();
+
+       params.setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
+       params.setContents(dialog_->referenceED->text().latin1());
+       params.setOptions(dialog_->nameED->text().latin1());
 }
 
 
@@ -108,7 +134,7 @@ void QRef::setGotoRef()
 
 void QRef::gotoRef()
 {
-       string ref(dialog_->referenceED->text());
+       string ref(dialog_->referenceED->text().latin1());
 
        if (at_ref_) {
                // go back
@@ -129,7 +155,7 @@ void QRef::redoRefs()
 
        // need this because Qt will send a highlight() here for
        // the first item inserted
-       string tmp(dialog_->referenceED->text());
+       string const tmp(dialog_->referenceED->text().latin1());
 
        for (std::vector<string>::const_iterator iter = refs_.begin();
                iter != refs_.end(); ++iter) {
@@ -157,7 +183,8 @@ void QRef::updateRefs()
        if (at_ref_)
                gotoRef();
        dialog_->refsLB->clear();
-       refs_ = controller().getLabelList(string());
+       string const name = controller().getBufferName(dialog_->bufferCO->currentItem());
+       refs_ = controller().getLabelList(name);
        dialog_->sortCB->setEnabled(!refs_.empty());
        dialog_->refsLB->setEnabled(!refs_.empty());
        redoRefs();