-// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 2000 The LyX Team.
+/**
+ * \file ControlCommand.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ======================================================
+ * \author Angus Leeming
*
- * \file ControlCommand.C
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * Full author contact details are available in file CREDITS.
*/
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include <config.h>
#include "ControlCommand.h"
-#include "BufferView.h"
-#include "ButtonController.h"
-#include "Dialogs.h"
-#include "lyxfunc.h"
-#include "LyXView.h"
-#include "support/LAssert.h"
-#include "ViewBase.h"
-
-ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac)
- : ControlConnectInset<InsetCommand>(lv, d),
- params_(0), action_(ac)
-{}
-
-
-void ControlCommand::showInset(InsetCommand * inset)
-{
- if (inset == 0) return; // maybe we should Assert this?
- connectInset(inset);
- show(inset->params());
-}
+#include "funcrequest.h"
+#include "insets/insetcommand.h"
-void ControlCommand::createInset(string const & arg)
-{
- connectInset();
+using std::string;
- if ( !arg.empty() )
- bc().valid(); // so that the user can press Ok
+namespace lyx {
+namespace frontend {
- InsetCommandParams params;
- params.setFromString(arg);
- show(params);
-}
+ControlCommand::ControlCommand(Dialog & dialog, string const & lfun_name)
+ : Dialog::Controller(dialog),
+ lfun_name_(lfun_name)
+{}
-void ControlCommand::update()
+bool ControlCommand::initialiseParams(string const & data)
{
- if (params_) delete params_;
-
- if (inset_)
- params_ = new InsetCommandParams(inset_->params());
- else
- params_ = new InsetCommandParams;
-
- bc().readOnly(isReadonly());
- view().update();
+ // 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 ControlCommand::show(InsetCommandParams const & params)
+void ControlCommand::clearParams()
{
- if (params_) delete params_;
- params_ = new InsetCommandParams(params);
-
- bc().readOnly(isReadonly());
- view().show();
+ params_ = InsetCommandParams();
}
-void ControlCommand::hide()
+void ControlCommand::dispatchParams()
{
- if (params_) {
- delete params_;
- params_ = 0;
- }
-
- disconnect();
- view().hide();
-}
+ if (lfun_name_.empty())
+ return;
-InsetCommandParams & ControlCommand::params() const
-{
- Assert(params_);
- return *params_;
+ string const lfun = InsetCommandMailer::params2string(lfun_name_,
+ params_);
+ kernel().dispatch(FuncRequest(getLfun(), lfun));
}
-
-void ControlCommand::apply()
-{
- view().apply();
-
- if (inset_) {
- // Only update if contents have changed
- if (params() != inset_->params()) {
- inset_->setParams(params());
- lv_.view()->updateInset(inset_, true);
- }
- } else if (action_ != LFUN_NOACTION){
- lv_.getLyXFunc()->Dispatch(action_, params().getAsString());
- }
-}
+} // namespace frontend
+} // namespace lyx