See attached. "only" 48 lines of our code saved (529 remaining)
40365 + 64275 - 78251 = 26389 lines of compiled code saved. Two intermediate layers (ControlRef and ControlCommand) gone. We have 50+ of such things, so a by a very crude approximation one should expect to be able to throw out 2400 lines of code and save compilation of ~1.3 mio lines. Andre'
Index: GuiRef.cpp =================================================================== --- GuiRef.cpp (revision 20732) +++ GuiRef.cpp (working copy) @@ -13,11 +13,18 @@ #include "GuiRef.h" -#include "ControlRef.h" +#include "Buffer.h" +#include "BufferList.h" +#include "FuncRequest.h" + #include "qt_helpers.h" #include "insets/InsetRef.h" +#include "support/filetools.h" // MakeAbsPath, MakeDisplayPath + +#include <boost/filesystem/operations.hpp> + #include <QLineEdit> #include <QCheckBox> #include <QListWidget> @@ -26,19 +33,30 @@ #include <QToolTip> #include <QCloseEvent> +#include <algorithm> +using std::find; using std::vector; using std::string; - 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"; + GuiRefDialog::GuiRefDialog(LyXView & lv) - : GuiDialog(lv, "ref") + : GuiDialog(lv, "ref"), Controller(*static_cast<Dialog*>(this)), + params_("ref") { setupUi(this); - setController(new ControlRef(*this)); + setController(this, false); setViewTitle(_("Cross-reference")); sort_ = false; @@ -88,12 +106,6 @@ } -ControlRef & GuiRefDialog::controller() -{ - return static_cast<ControlRef &>(GuiDialog::controller()); -} - - void GuiRefDialog::changed_adaptor() { changed(); @@ -107,7 +119,7 @@ void GuiRefDialog::selectionChanged() { - if (controller().isBufferReadonly()) + if (isBufferReadonly()) return; QList<QListWidgetItem *> selections = refsLW->selectedItems(); @@ -144,7 +156,7 @@ void GuiRefDialog::refSelected(QListWidgetItem * sel) { - if (controller().isBufferReadonly()) + if (isBufferReadonly()) return; /* int const cur_item = refsLW->currentRow(); @@ -189,21 +201,19 @@ void GuiRefDialog::updateContents() { - InsetCommandParams const & params = controller().params(); - int orig_type = typeCO->currentIndex(); - referenceED->setText(toqstr(params["reference"])); + referenceED->setText(toqstr(params_["reference"])); - nameED->setText(toqstr(params["name"])); - nameED->setReadOnly(!nameAllowed() && !controller().isBufferReadonly()); + nameED->setText(toqstr(params_["name"])); + nameED->setReadOnly(!nameAllowed() && !isBufferReadonly()); // restore type settings for new insets - if (params["reference"].empty()) + if (params_["reference"].empty()) typeCO->setCurrentIndex(orig_type); else - typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName())); - typeCO->setEnabled(typeAllowed() && !controller().isBufferReadonly()); + typeCO->setCurrentIndex(InsetRef::getType(params_.getCmdName())); + typeCO->setEnabled(typeAllowed() && !isBufferReadonly()); if (!typeAllowed()) typeCO->setCurrentIndex(0); @@ -211,17 +221,18 @@ // insert buffer list bufferCO->clear(); - vector<string> const buffers = controller().getBufferList(); - for (vector<string>::const_iterator it = buffers.begin(); - it != buffers.end(); ++it) { - bufferCO->addItem(toqstr(*it)); + vector<string> buffers = theBufferList().getFileNames(); + for (vector<string>::iterator it = buffers.begin(); + it != buffers.end(); ++it) { + bufferCO->addItem(toqstr(lyx::to_utf8(makeDisplayPath(*it)))); } + // restore the buffer combo setting for new insets - if (params["reference"].empty() && restored_buffer_ != -1 + if (params_["reference"].empty() && restored_buffer_ != -1 && restored_buffer_ < bufferCO->count()) bufferCO->setCurrentIndex(restored_buffer_); else - bufferCO->setCurrentIndex(controller().getBufferNum()); + bufferCO->setCurrentIndex(bufferNum()); updateRefs(); bc().setValid(false); @@ -230,13 +241,11 @@ void GuiRefDialog::applyView() { - InsetCommandParams & params = controller().params(); - last_reference_ = referenceED->text(); - params.setCmdName(InsetRef::getName(typeCO->currentIndex())); - params["reference"] = qstring_to_ucs4(last_reference_); - params["name"] = qstring_to_ucs4(nameED->text()); + params_.setCmdName(InsetRef::getName(typeCO->currentIndex())); + params_["reference"] = qstring_to_ucs4(last_reference_); + params_["name"] = qstring_to_ucs4(nameED->text()); restored_buffer_ = bufferCO->currentIndex(); } @@ -244,14 +253,14 @@ bool GuiRefDialog::nameAllowed() { - KernelDocType const doc_type = controller().docType(); + KernelDocType const doc_type = docType(); return doc_type != LATEX && doc_type != LITERATE; } bool GuiRefDialog::typeAllowed() { - return controller().docType() != DOCBOOK; + return docType() != DOCBOOK; } @@ -278,11 +287,11 @@ if (at_ref_) { // go back setGotoRef(); - controller().gotoBookmark(); + gotoBookmark(); } else { // go to the ref setGoBack(); - controller().gotoRef(ref); + gotoRef(ref); } at_ref_ = !at_ref_; } @@ -344,8 +353,9 @@ void GuiRefDialog::updateRefs() { refs_.clear(); - string const name = controller().getBufferName(bufferCO->currentIndex()); - refs_ = controller().getLabelList(name); + string const name = theBufferList().getFileNames()[bufferCO->currentIndex()]; + Buffer const * buf = theBufferList().getBuffer(makeAbsPath(name).absFilename()); + buf->getLabelList(refs_); sortCB->setEnabled(!refs_.empty()); refsLW->setEnabled(!refs_.empty()); gotoPB->setEnabled(!refs_.empty()); @@ -358,6 +368,53 @@ return !referenceED->text().isEmpty(); } + +void GuiRefDialog::gotoRef(string const & ref) +{ + dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0")); + dispatch(FuncRequest(LFUN_LABEL_GOTO, ref)); +} + + +void GuiRefDialog::gotoBookmark() +{ + dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0")); +} + + +int GuiRefDialog::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 GuiRefDialog::initialiseParams(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_); + return true; +} + + +void GuiRefDialog::clearParams() +{ + params_.clear(); +} + + +void GuiRefDialog::dispatchParams() +{ + string const lfun = InsetCommandMailer::params2string(lfun_name_, params_); + dispatch(FuncRequest(getLfun(), lfun)); +} + } // namespace frontend } // namespace lyx Index: GuiDialog.h =================================================================== --- GuiDialog.h (revision 20732) +++ GuiDialog.h (working copy) @@ -123,7 +123,7 @@ */ //@{ /// \param ptr is stored and destroyed by \c Dialog. - void setController(Controller * ptr); + void setController(Controller * ptr, bool destroy = true); //@} /** \name Dialog Components @@ -160,6 +160,7 @@ */ std::string name_; Controller * controller_; + bool destroy_controller_; LyXView * lyxview_; // FIXME: replace by moving to constructor }; Index: GuiRef.h =================================================================== --- GuiRef.h (revision 20732) +++ GuiRef.h (working copy) @@ -13,8 +13,9 @@ #define GUIREF_H #include "GuiDialog.h" -#include "ControlRef.h" +#include "Dialog.h" #include "ui_RefUi.h" +#include "insets/InsetCommandParams.h" #include <vector> @@ -23,7 +24,7 @@ namespace lyx { namespace frontend { -class GuiRefDialog : public GuiDialog, public Ui::RefUi +class GuiRefDialog : public GuiDialog, public Ui::RefUi, public Controller { Q_OBJECT @@ -42,9 +43,28 @@ private: /// + bool initialiseParams(std::string const & data); + /// clean-up on hide. + void clearParams(); + /// clean-up on hide. + void dispatchParams(); + /// + bool isBufferDependent() const { return true; } + + /** disconnect from the inset when the Apply button is pressed. + Allows easy insertion of multiple references. */ + bool disconnectOnApply() const { return true; } + /// + void gotoRef(std::string const &); + /// + void gotoBookmark(); + /// + int bufferNum() const; + + /// void closeEvent(QCloseEvent * e); /// parent controller - ControlRef & controller(); + Controller & controller() { return *static_cast<Controller*>(this); } /// bool isValid(); /// apply changes @@ -77,6 +97,9 @@ int restored_buffer_; /// the references std::vector<docstring> refs_; + + /// + InsetCommandParams params_; }; } // namespace frontend Index: GuiDialog.cpp =================================================================== --- GuiDialog.cpp (revision 20732) +++ GuiDialog.cpp (working copy) @@ -25,7 +25,7 @@ namespace frontend { GuiDialog::GuiDialog(LyXView & lv, std::string const & name) - : is_closing_(false), name_(name), controller_(0) + : is_closing_(false), name_(name), controller_(0), destroy_controller_(false) { lyxview_ = &lv; } @@ -33,7 +33,8 @@ GuiDialog::~GuiDialog() { - delete controller_; + if (destroy_controller_) + delete controller_; } @@ -232,10 +233,11 @@ } -void GuiDialog::setController(Controller * controller) +void GuiDialog::setController(Controller * controller, bool destroy) { BOOST_ASSERT(controller); BOOST_ASSERT(!controller_); + destroy_controller_ = destroy; controller_ = controller; controller_->setLyXView(*lyxview_); }