]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCommand.C
Merging BRANCH_MVC back into HEAD.
[lyx.git] / src / frontends / controllers / ControlCommand.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \file ControlCommand.C
12  * \author Angus Leeming <a.leeming@ic.ac.uk>
13  */
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include <config.h>
20
21 #include "ControlCommand.h"
22 #include "BufferView.h"
23 #include "ButtonController.h"
24 #include "Dialogs.h"
25 #include "lyxfunc.h"
26 #include "LyXView.h"
27 #include "support/LAssert.h"
28 #include "ViewBase.h"
29
30 ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac)
31         : ControlConnectInset<InsetCommand>(lv, d),
32           params_(0), action_(ac)
33 {}
34
35
36 void ControlCommand::showInset(InsetCommand * inset)
37 {
38         if (inset == 0) return;  // maybe we should Assert this?
39
40         connectInset(inset);
41         show(inset->params());
42 }
43
44
45 void ControlCommand::createInset(string const & arg)
46 {
47         connectInset();
48
49         if ( !arg.empty() )
50                 bc().valid(); // so that the user can press Ok
51
52         InsetCommandParams params;
53         params.setFromString(arg);
54         show(params);
55 }
56
57
58 void ControlCommand::update()
59 {
60         if (params_) delete params_;
61
62         if (inset_)
63                 params_ = new InsetCommandParams(inset_->params());
64         else
65                 params_ = new InsetCommandParams;
66
67         bc().readOnly(isReadonly());
68         view().update();
69 }
70
71
72 void ControlCommand::show(InsetCommandParams const & params)
73 {
74         if (params_) delete params_;
75         params_ = new InsetCommandParams(params);
76
77         bc().readOnly(isReadonly());
78         view().show();
79 }
80
81
82 void ControlCommand::hide()
83 {
84         if (params_) {
85                 delete params_;
86                 params_ = 0;
87         }
88
89         disconnect();
90         view().hide();
91 }
92
93 InsetCommandParams & ControlCommand::params() const
94 {
95         Assert(params_);
96         return *params_;
97 }
98
99
100 void ControlCommand::apply()
101 {
102         view().apply();
103
104         if (inset_) {
105                 // Only update if contents have changed
106                 if (params() != inset_->params()) {
107                         inset_->setParams(params());
108                         lv_.view()->updateInset(inset_, true);
109                 }
110         } else if (action_ != LFUN_NOACTION){
111                 lv_.getLyXFunc()->Dispatch(action_, params().getAsString());
112         }
113 }