]> 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 b8aef69f5c2d02f173d81edcc27420cc7f930b3b..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"
-#include "QRefDialog.h"
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "ControlRef.h"
 #include "QRef.h"
-#include "Qt2BC.h" 
-#include "gettext.h"
-#include "insets/insetref.h"
+#include "QRefDialog.h"
+#include "Qt2BC.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)
 {
 }
@@ -39,40 +52,53 @@ void QRef::build_dialog()
 {
        dialog_.reset(new QRefDialog(this));
 
-       bc().setOK(dialog_->okPB); 
-       bc().setCancel(dialog_->closePB); 
+       bc().setOK(dialog_->okPB);
+       bc().setCancel(dialog_->closePB);
        bc().addReadOnly(dialog_->refsLB);
        bc().addReadOnly(dialog_->sortCB);
        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());
 }
 
 
@@ -82,14 +108,14 @@ bool QRef::nameAllowed()
                controller().docType() != ControlRef::LITERATE;
 }
 
+
 bool QRef::typeAllowed()
 {
        return controller().docType() == ControlRef::LINUXDOC ||
            controller().docType() == ControlRef::DOCBOOK;
 }
 
+
 void QRef::setGoBack()
 {
        dialog_->gotoPB->setText(_("&Go back"));
@@ -97,7 +123,7 @@ void QRef::setGoBack()
        QToolTip::add(dialog_->gotoPB, _("Go back"));
 }
 
+
 void QRef::setGotoRef()
 {
        dialog_->gotoPB->setText(_("&Goto"));
@@ -105,10 +131,10 @@ void QRef::setGotoRef()
        QToolTip::add(dialog_->gotoPB, _("Go to reference"));
 }
 
+
 void QRef::gotoRef()
 {
-       string ref(dialog_->referenceED->text());
+       string ref(dialog_->referenceED->text().latin1());
 
        if (at_ref_) {
                // go back
@@ -122,14 +148,14 @@ void QRef::gotoRef()
        at_ref_ = !at_ref_;
 }
 
+
 void QRef::redoRefs()
 {
        dialog_->refsLB->setAutoUpdate(false);
 
        // 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,8 +183,9 @@ 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()); 
+       dialog_->refsLB->setEnabled(!refs_.empty());
        redoRefs();
 }