Fcitx
statusarea.cpp
1 /*
2  * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #include "statusarea.h"
9 #include "action.h"
10 #include "inputcontext.h"
11 
12 namespace fcitx {
13 
15 public:
16  StatusAreaPrivate(InputContext *ic) : ic_(ic) {}
17  SimpleAction separatorBeforeIM, separatorAfterIM;
18  std::unordered_map<Action *, std::vector<ScopedConnection>> actions_;
19  InputContext *ic_;
20  void update() const {
22  }
23 };
24 
26  : d_ptr(std::make_unique<StatusAreaPrivate>(ic)) {
27  clear();
28 }
29 
30 StatusArea::~StatusArea() {}
31 
33  FCITX_D();
34  if (isChild(action)) {
35  removeChild(action);
36  d->actions_.erase(action);
37  }
38  switch (group) {
40  insertChild(&d->separatorBeforeIM, action);
41  break;
42  case StatusGroup::InputMethod:
43  insertChild(&d->separatorAfterIM, action);
44  break;
46  addChild(action);
47  break;
48  }
49  d->actions_[action].emplace_back(
50  action->connect<ObjectDestroyed>([this, d](void *p) {
51  auto *action = static_cast<Action *>(p);
52  removeAction(action);
53  d->update();
54  }));
55  d->actions_[action].emplace_back(
56  action->connect<Action::Update>([d](InputContext *ic) {
57  if (ic == d->ic_) {
58  d->update();
59  }
60  }));
61  d->update();
62 }
63 
65  FCITX_D();
66  if (isChild(action)) {
67  removeChild(action);
68  d->actions_.erase(action);
69  d->update();
70  }
71 }
72 
74  FCITX_D();
75  removeAllChild();
76  addChild(&d->separatorBeforeIM);
77  addChild(&d->separatorAfterIM);
78 }
79 
81  for (auto *action : actions(group)) {
82  removeAction(action);
83  }
84 }
85 std::vector<Action *> StatusArea::allActions() const {
86  FCITX_D();
87  std::vector<Action *> result;
88  for (auto *ele : childs()) {
89  if (ele == &d->separatorBeforeIM || ele == &d->separatorAfterIM) {
90  continue;
91  }
92  result.push_back(static_cast<Action *>(ele));
93  }
94  return result;
95 }
96 
97 std::vector<Action *> StatusArea::actions(StatusGroup group) const {
98  FCITX_D();
99  std::vector<Action *> result;
100  switch (group) {
102  for (auto *ele : childs()) {
103  if (ele == &d->separatorBeforeIM) {
104  break;
105  }
106  result.push_back(static_cast<Action *>(ele));
107  }
108  break;
109  case StatusGroup::InputMethod: {
110  bool push = false;
111  for (auto *ele : childs()) {
112  if (ele == &d->separatorBeforeIM) {
113  push = true;
114  continue;
115  }
116  if (ele == &d->separatorAfterIM) {
117  break;
118  }
119  if (push) {
120  result.push_back(static_cast<Action *>(ele));
121  }
122  }
123  break;
124  }
126  bool push = false;
127  for (auto *ele : childs()) {
128  if (ele == &d->separatorAfterIM) {
129  push = true;
130  continue;
131  }
132  if (push) {
133  result.push_back(static_cast<Action *>(ele));
134  }
135  }
136  break;
137  }
138  }
139  return result;
140 }
141 } // namespace fcitx
StatusArea(InputContext *ic)
Construct status area for associated input context.
Definition: statusarea.cpp:25
void addAction(StatusGroup group, Action *action)
Add an action to given group.
Definition: statusarea.cpp:32
Definition: action.cpp:17
Definition: matchrule.h:78
The Action class provides an abstraction for user commands that can be added to user interfaces...
Definition: action.h:34
std::vector< Action * > actions(StatusGroup group) const
Get the associated actions for group.
Definition: statusarea.cpp:97
void clearGroup(StatusGroup group)
Clear only given status group.
Definition: statusarea.cpp:80
Action shown before input method group.
Class for status area in UI.
Action class.
void clear()
Clear all the actions, will be called when input context lost focus.
Definition: statusarea.cpp:73
StatusGroup
Definition: statusarea.h:27
void removeAction(Action *action)
Remove an action from given group.
Definition: statusarea.cpp:64
std::vector< Action * > allActions() const
Get all the associated actions.
Definition: statusarea.cpp:85
Input Context for Fcitx.
const std::list< Element * > & childs() const
List all childs.
Definition: element.cpp:30
bool isChild(const Element *element) const
Enable query between different elements.
Definition: element.cpp:42
Action shown after input method group.
An input context represents a client of Fcitx.
Definition: inputcontext.h:47
void updateUserInterface(UserInterfaceComponent component, bool immediate=false)
Notifies UI about changes in user interface.