]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCommand.C
Reorganised, cleaned-up and improved documentation of controllers.
[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 2001 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 "Dialogs.h"
24 #include "lyxfunc.h"
25 #include "LyXView.h"
26 #include "support/LAssert.h"
27
28 ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac)
29         : ControlInset<InsetCommand>(lv, d),
30           params_(0), action_(ac)
31 {}
32
33
34 void ControlCommand::showInset(InsetCommand * inset)
35 {
36         if (inset == 0) return;  // maybe we should Assert this?
37
38         connectInset(inset);
39         show(inset->params());
40 }
41
42
43 void ControlCommand::createInset(string const & arg)
44 {
45         connectInset();
46
47         if ( !arg.empty() )
48                 bc().valid(); // so that the user can press Ok
49
50         InsetCommandParams params;
51         params.setFromString(arg);
52         show(params);
53 }
54
55
56 void ControlCommand::update()
57 {
58         if (params_) delete params_;
59
60         if (inset_)
61                 params_ = new InsetCommandParams(inset_->params());
62         else
63                 params_ = new InsetCommandParams;
64
65         bc().readOnly(isReadonly());
66         view().update();
67 }
68
69
70 void ControlCommand::show(InsetCommandParams const & params)
71 {
72         if (params_) delete params_;
73         params_ = new InsetCommandParams(params);
74
75         bc().readOnly(isReadonly());
76         view().show();
77 }
78
79
80 void ControlCommand::hide()
81 {
82         if (params_) {
83                 delete params_;
84                 params_ = 0;
85         }
86
87         clearParams();
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 }