merge GuiCommand into its users.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24376 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-04-20 09:24:14 +00:00
parent c621ec9843
commit 5158ef3ee9
17 changed files with 232 additions and 130 deletions

View File

@ -17,10 +17,12 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "ui_BibtexAddUi.h"
#include "FuncRequest.h"
#include "LyXRC.h"
#include "qt_helpers.h"
#include "Validator.h"
#include "LyXRC.h"
#include "ui_BibtexAddUi.h"
#include "ButtonPolicy.h"
@ -49,7 +51,8 @@ namespace frontend {
GuiBibtex::GuiBibtex(GuiView & lv)
: GuiCommand(lv, "bibtex", qt_("BibTeX Bibliography"))
: GuiDialog(lv, "bibtex", qt_("BibTeX Bibliography")),
params_(insetCode("bibtex"))
{
setupUi(this);
@ -532,6 +535,21 @@ QString GuiBibtex::styleFile() const
}
bool GuiBibtex::initialiseParams(std::string const & data)
{
InsetCommand::string2params("bibtex", data, params_);
return true;
}
void GuiBibtex::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("bibtex", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiBibtex(GuiView & lv) { return new GuiBibtex(lv); }

View File

@ -13,11 +13,13 @@
#ifndef GUIBIBTEX_H
#define GUIBIBTEX_H
#include "GuiCommand.h"
#include "GuiDialog.h"
#include "ButtonController.h"
#include "ui_BibtexUi.h"
#include "ui_BibtexAddUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
@ -33,7 +35,7 @@ public:
};
class GuiBibtex : public GuiCommand, public Ui::BibtexUi
class GuiBibtex : public GuiDialog, public Ui::BibtexUi
{
Q_OBJECT
@ -79,6 +81,18 @@ private:
/// which stylefile do we use?
QString styleFile() const;
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
///
GuiBibtexAddDialog * add_;
///

View File

@ -18,6 +18,7 @@
#include "qt_helpers.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "FuncRequest.h"
#include "insets/InsetCommand.h"
@ -76,7 +77,8 @@ static vector<lyx::docstring> to_docstring_vector(QStringList const & qlist)
GuiCitation::GuiCitation(GuiView & lv)
: GuiCommand(lv, "citation", qt_("Citation"))
: GuiDialog(lv, "citation", qt_("Citation")),
params_(insetCode("citation"))
{
setupUi(this);
@ -589,7 +591,7 @@ void GuiCitation::setCitedKeys()
bool GuiCitation::initialiseParams(string const & data)
{
InsetCommand::string2params(lfun_name_, data, params_);
InsetCommand::string2params("citation", data, params_);
biblio::CiteEngine const engine = buffer().params().citeEngine();
bibkeysInfo_.fillWithBibKeys(&buffer());
citeStyles_ = biblio::getCiteStyles(engine);
@ -741,6 +743,13 @@ vector<docstring> GuiCitation::searchKeys(
}
void GuiCitation::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("citation", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiCitation(GuiView & lv) { return new GuiCitation(lv); }

View File

@ -15,18 +15,20 @@
#ifndef GUICITATION_H
#define GUICITATION_H
#include "GuiCommand.h"
#include "GuiDialog.h"
#include "GuiSelectionManager.h"
#include "ui_CitationUi.h"
#include "BiblioInfo.h"
#include "insets/InsetCommandParams.h"
#include <QStringList>
#include <QStringListModel>
namespace lyx {
namespace frontend {
class GuiCitation : public GuiCommand, public Ui::CitationUi
class GuiCitation : public GuiDialog, public Ui::CitationUi
{
Q_OBJECT
@ -126,6 +128,14 @@ private:
/// Set the Params variable for the Controller.
void apply(int const choice, bool const full, bool const force,
QString before, QString after);
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams();
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
/// available keys.
@ -136,12 +146,8 @@ private:
QStringList all_keys_;
/// Cited keys.
QStringList cited_keys_;
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams();
InsetCommandParams params_;
/** Disconnect from the inset when the Apply button is pressed.
* Allows easy insertion of multiple citations.

View File

@ -1,51 +0,0 @@
// -*- C++ -*-
/**
* \file GuiCommand.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#ifndef GUICOMMAND_H
#define GUICOMMAND_H
#include "GuiDialog.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class GuiCommand : public GuiDialog
{
public:
/// We need to know with what sort of inset we're associated.
// FIXME This should probably be an InsetCode
GuiCommand(GuiView &, QString const & name, QString const & title);
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
protected:
///
InsetCommandParams params_;
//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()
std::string const lfun_name_;
};
} // namespace frontend
} // namespace lyx
#endif // GUIDIALOG_H

View File

@ -11,14 +11,11 @@
#include <config.h>
#include "GuiDialog.h"
#include "GuiCommand.h"
#include "GuiView.h"
#include "qt_helpers.h"
#include "FuncRequest.h"
#include "insets/InsetCommand.h"
#include "support/debug.h"
#include <QCloseEvent>
@ -29,7 +26,7 @@ namespace lyx {
namespace frontend {
GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title)
: QDialog(&lv), Dialog(lv, name, "LyX: " + title), is_closing_(false)
: QDialog(&lv), Dialog(lv, name, "LyX: " + title), is_closing_(false)
{}
@ -111,40 +108,6 @@ void GuiDialog::updateView()
setUpdatesEnabled(true);
}
/////////////////////////////////////////////////////////////////////
//
// Command based dialogs
//
/////////////////////////////////////////////////////////////////////
GuiCommand::GuiCommand(GuiView & lv, QString const & name,
QString const & title)
: GuiDialog(lv, name, title), params_(insetCode(fromqstr(name))),
lfun_name_(fromqstr(name))
{
}
bool GuiCommand::initialiseParams(string const & data)
{
// The name passed with LFUN_INSET_APPLY is also the name
// used to identify the mailer.
InsetCommand::string2params(lfun_name_, data, params_);
return true;
}
void GuiCommand::dispatchParams()
{
if (lfun_name_.empty())
return;
string const lfun = InsetCommand::params2string(lfun_name_, params_);
dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend
} // namespace lyx

View File

@ -26,7 +26,8 @@ namespace lyx {
namespace frontend {
GuiHyperlink::GuiHyperlink(GuiView & lv)
: GuiCommand(lv, "href",qt_("Hyperlink"))
: GuiDialog(lv, "href", qt_("Hyperlink")),
params_(insetCode(fromqstr("href")))
{
setupUi(this);
@ -91,10 +92,23 @@ void GuiHyperlink::applyView()
bool GuiHyperlink::isValid()
{
QString const u = targetED->text();
QString const n = nameED->text();
return !targetED->text().isEmpty() || !nameED->text().isEmpty();
}
return !u.isEmpty() || !n.isEmpty();
bool GuiHyperlink::initialiseParams(std::string const & data)
{
// The name passed with LFUN_INSET_APPLY is also the name
// used to identify the mailer.
InsetCommand::string2params("href", data, params_);
return true;
}
void GuiHyperlink::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("href", params_);
dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -13,13 +13,15 @@
#ifndef GUIHYPERLINK_H
#define GUIHYPERLINK_H
#include "GuiCommand.h"
#include "GuiDialog.h"
#include "ui_HyperlinkUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class GuiHyperlink : public GuiCommand, public Ui::HyperlinkUi
class GuiHyperlink : public GuiDialog, public Ui::HyperlinkUi
{
Q_OBJECT
@ -37,6 +39,18 @@ private:
void applyView();
/// update dialog
void updateContents();
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
};
} // namespace frontend

View File

@ -47,7 +47,8 @@ namespace frontend {
GuiInclude::GuiInclude(GuiView & lv)
: GuiCommand(lv, "include", qt_("Child Document"))
: GuiDialog(lv, "include", qt_("Child Document")),
params_(insetCode("include"))
{
setupUi(this);
@ -339,6 +340,20 @@ void GuiInclude::edit(string const & file)
}
bool GuiInclude::initialiseParams(std::string const & data)
{
InsetCommand::string2params("include", data, params_);
return true;
}
void GuiInclude::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("include", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiInclude(GuiView & lv) { return new GuiInclude(lv); }

View File

@ -15,14 +15,15 @@
#define GUIINCLUDE_H
#include "GuiDialog.h"
#include "GuiCommand.h"
#include "ui_IncludeUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class GuiInclude : public GuiCommand, public Ui::IncludeUi
class GuiInclude : public GuiDialog, public Ui::IncludeUi
{
Q_OBJECT
@ -45,6 +46,15 @@ private Q_SLOTS:
void set_listings_msg();
private:
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
///
enum Type {
///
@ -68,10 +78,12 @@ private:
void applyView();
/// update
void updateContents();
///
bool isBufferDependent() const { return true; }
/// Browse for a file
QString browse(QString const &, Type) const;
private:
///
InsetCommandParams params_;
};
} // namespace frontend

View File

@ -12,9 +12,11 @@
#include "GuiLabel.h"
#include "FuncRequest.h"
#include "qt_helpers.h"
#include "support/debug.h"
#include "insets/InsetCommand.h"
#include <QLabel>
#include <QPushButton>
@ -27,12 +29,13 @@ namespace frontend {
/////////////////////////////////////////////////////////////////
//
// Base implementation
// GuiLabel
//
/////////////////////////////////////////////////////////////////
GuiLabel::GuiLabel(GuiView & lv)
: GuiCommand(lv, "label", qt_("Label"))
: GuiDialog(lv, "label", qt_("Label")),
params_(insetCode("label"))
{
setupUi(this);
@ -82,6 +85,20 @@ bool GuiLabel::isValid()
}
bool GuiLabel::initialiseParams(std::string const & data)
{
InsetCommand::string2params("label", data, params_);
return true;
}
void GuiLabel::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("label", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiLabel(GuiView & lv) { return new GuiLabel(lv); }

View File

@ -13,13 +13,15 @@
#ifndef GUILABEL_H
#define GUILABEL_H
#include "GuiCommand.h"
#include "GuiDialog.h"
#include "ui_LabelUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class GuiLabel : public GuiCommand, public Ui::LabelUi
class GuiLabel : public GuiDialog, public Ui::LabelUi
{
Q_OBJECT
@ -37,6 +39,18 @@ private:
void applyView();
/// update
void updateContents();
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
};
} // namespace frontend

View File

@ -14,14 +14,14 @@
#include "GuiNomencl.h"
#include "qt_helpers.h"
#include "FuncRequest.h"
#include "insets/InsetCommand.h"
#include "support/debug.h"
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QTextEdit>
#include <QWhatsThis>
using namespace std;
@ -29,7 +29,8 @@ namespace lyx {
namespace frontend {
GuiNomenclature::GuiNomenclature(GuiView & lv)
: GuiCommand(lv, "nomenclature", qt_("Nomenclature"))
: GuiDialog(lv, "nomenclature", qt_("Nomenclature")),
params_(insetCode("nomenclature"))
{
setupUi(this);
@ -92,6 +93,21 @@ bool GuiNomenclature::isValid()
}
bool GuiNomenclature::initialiseParams(std::string const & data)
{
InsetCommand::string2params("nomenclature", data, params_);
return true;
}
void GuiNomenclature::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("nomenclature", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiNomenclature(GuiView & lv)
{
return new GuiNomenclature(lv);

View File

@ -14,13 +14,15 @@
#ifndef GUINOMENCLATURE_H
#define GUINOMENCLATURE_H
#include "GuiCommand.h"
#include "GuiDialog.h"
#include "ui_NomenclUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class GuiNomenclature : public GuiCommand, public Ui::NomenclUi
class GuiNomenclature : public GuiDialog, public Ui::NomenclUi
{
Q_OBJECT
@ -38,6 +40,18 @@ private:
void applyView();
/// update
void updateContents();
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
};
} // namespace frontend

View File

@ -22,7 +22,7 @@
#include "insets/InsetRef.h"
#include "support/FileName.h"
#include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
#include "support/filetools.h" // makeAbsPath, makeDisplayPath
#include <QLineEdit>
#include <QCheckBox>
@ -39,7 +39,8 @@ namespace lyx {
namespace frontend {
GuiRef::GuiRef(GuiView & lv)
: GuiCommand(lv, "ref", qt_("Cross-reference"))
: GuiDialog(lv, "ref", qt_("Cross-reference")),
params_(insetCode("ref"))
{
setupUi(this);
@ -209,7 +210,7 @@ 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
@ -367,6 +368,21 @@ void GuiRef::gotoBookmark()
}
bool GuiRef::initialiseParams(std::string const & data)
{
InsetCommand::string2params("ref", data, params_);
return true;
}
void GuiRef::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("ref", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiRef(GuiView & lv) { return new GuiRef(lv); }

View File

@ -12,9 +12,11 @@
#ifndef GUIREF_H
#define GUIREF_H
#include "GuiCommand.h"
#include "GuiDialog.h"
#include "ui_RefUi.h"
#include "insets/InsetCommandParams.h"
#include <vector>
class QListWidgetItem;
@ -22,7 +24,7 @@ class QListWidgetItem;
namespace lyx {
namespace frontend {
class GuiRef : public GuiCommand, public Ui::RefUi
class GuiRef : public GuiDialog, public Ui::RefUi
{
Q_OBJECT
@ -72,6 +74,16 @@ private:
void redoRefs();
/// update references
void updateRefs();
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
private:
///
InsetCommandParams params_;
/// sort or not persistent state
bool sort_;

View File

@ -140,7 +140,6 @@ NOMOCHEADER = \
DialogView.h \
DockView.h \
FileDialog.h \
GuiCommand.h \
GuiFontExample.h \
GuiFontLoader.h \
GuiFontMetrics.h \