2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2001 The LyX Team.
9 * ======================================================
11 * \file ControlCommand.C
12 * \author Angus Leeming <a.leeming@ic.ac.uk>
16 #pragma implementation
21 #include "ControlCommand.h"
22 #include "BufferView.h"
23 #include "ButtonController.h"
27 #include "support/LAssert.h"
30 ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac)
31 : ControlConnectInset<InsetCommand>(lv, d),
32 params_(0), action_(ac)
36 void ControlCommand::showInset(InsetCommand * inset)
38 if (inset == 0) return; // maybe we should Assert this?
41 show(inset->params());
45 void ControlCommand::createInset(string const & arg)
50 bc().valid(); // so that the user can press Ok
52 InsetCommandParams params;
53 params.setFromString(arg);
58 void ControlCommand::update()
60 if (params_) delete params_;
63 params_ = new InsetCommandParams(inset_->params());
65 params_ = new InsetCommandParams;
67 bc().readOnly(isReadonly());
72 void ControlCommand::show(InsetCommandParams const & params)
74 if (params_) delete params_;
75 params_ = new InsetCommandParams(params);
77 bc().readOnly(isReadonly());
82 void ControlCommand::hide()
93 InsetCommandParams & ControlCommand::params() const
100 void ControlCommand::apply()
105 // Only update if contents have changed
106 if (params() != inset_->params()) {
107 inset_->setParams(params());
108 lv_.view()->updateInset(inset_, true);
110 } else if (action_ != LFUN_NOACTION){
111 lv_.getLyXFunc()->Dispatch(action_, params().getAsString());