librime: switcher.h Source File

| librime 1.2 Rime Input Method Engine, the core library

switcher.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2011-12-07 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_SWITCHER_H_
8#define RIME_SWITCHER_H_
9
10#include <rime/common.h>
11#include <rime/engine.h>
12#include <rime/processor.h>
13
14namespace rime {
15
16class Config;
17class Context;
18class Translator;
19
20 class Switcher : public Processor, public Engine {
21 public:
22 Switcher(const Ticket& ticket);
23 virtual ~Switcher();
24
25 virtual bool ProcessKey(const KeyEvent& key_event) {
26 return ProcessKeyEvent(key_event) == kAccepted;
27 }
28 virtual ProcessResult ProcessKeyEvent(const KeyEvent& key_event);
29
30 static int ForEachSchemaListEntry(
31 Config* config,
32 function<bool(const string& schema_id)> process_entry);
33
34 void SetActiveSchema(const string& schema_id);
35 Schema* CreateSchema();
36 void SelectNextSchema();
37 bool IsAutoSave(const string& option) const;
38 void RestoreSavedOptions();
39
40 void RefreshMenu();
41 void Activate();
42 void Deactivate();
43 void DeactivateAndApply(function<void()> apply);
44
45 Engine* attached_engine() const { return engine_; }
46 Config* user_config() const { return user_config_.get(); }
47 bool active() const { return active_; }
48
49 protected:
50 void InitializeComponents();
51 void LoadSettings();
52
53 void HighlightNextSchema();
54 void OnSelect(Context* ctx);
55
56 the<Config> user_config_;
57 string caption_;
58 vector<KeyEvent> hotkeys_;
59 set<string> save_options_;
60 bool fold_options_ = false;
61 bool fix_schema_list_order_ = false;
62
63 vector<of<Processor>> processors_;
64 vector<of<Translator>> translators_;
65 bool active_ = false;
66};
67
68 class SwitcherCommand {
69 public:
70 SwitcherCommand(const string& keyword) : keyword_(keyword) {}
71 virtual void Apply(Switcher* switcher) = 0;
72 const string& keyword() const { return keyword_; }
73
74 protected:
75 string keyword_;
76};
77
78} // namespace rime
79
80#endif // RIME_SWITCHER_H_
processor.h
common.h
engine.h
rime
Definition algebra.cc:12
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::ProcessResult
ProcessResult
Definition processor.h:18
rime::kAccepted
@ kAccepted
Definition processor.h:20
rime::Config
Definition config_component.h:21
rime::Context
Definition context.h:19
rime::Engine::Engine
Engine()
Definition engine.cc:64
rime::KeyEvent
Definition key_event.h:17
rime::Processor::Processor
Processor(const Ticket &ticket)
Definition processor.h:26
rime::Processor::engine_
Engine * engine_
Definition processor.h:37
rime::Schema
Definition schema.h:15
rime::Switcher
Definition switcher.h:20
rime::Switcher::ForEachSchemaListEntry
static int ForEachSchemaListEntry(Config *config, function< bool(const string &schema_id)> process_entry)
Definition switcher.cc:146
rime::Switcher::active_
bool active_
Definition switcher.h:65
rime::Switcher::DeactivateAndApply
void DeactivateAndApply(function< void()> apply)
Definition switcher.cc:257
rime::Switcher::OnSelect
void OnSelect(Context *ctx)
Definition switcher.cc:218
rime::Switcher::InitializeComponents
void InitializeComponents()
Definition switcher.cc:293
rime::Switcher::active
bool active() const
Definition switcher.h:47
rime::Switcher::fix_schema_list_order_
bool fix_schema_list_order_
Definition switcher.h:61
rime::Switcher::caption_
string caption_
Definition switcher.h:57
rime::Switcher::LoadSettings
void LoadSettings()
Definition switcher.cc:264
rime::Switcher::ProcessKeyEvent
virtual ProcessResult ProcessKeyEvent(const KeyEvent &key_event)
Definition switcher.cc:51
rime::Switcher::RestoreSavedOptions
void RestoreSavedOptions()
Definition switcher.cc:40
rime::Switcher::Deactivate
void Deactivate()
Definition switcher.cc:251
rime::Switcher::HighlightNextSchema
void HighlightNextSchema()
Definition switcher.cc:83
rime::Switcher::user_config
Config * user_config() const
Definition switcher.h:46
rime::Switcher::save_options_
set< string > save_options_
Definition switcher.h:59
rime::Switcher::ProcessKey
virtual bool ProcessKey(const KeyEvent &key_event)
Definition switcher.h:25
rime::Switcher::translators_
vector< of< Translator > > translators_
Definition switcher.h:64
rime::Switcher::fold_options_
bool fold_options_
Definition switcher.h:60
rime::Switcher::user_config_
the< Config > user_config_
Definition switcher.h:56
rime::Switcher::RefreshMenu
void RefreshMenu()
Definition switcher.cc:225
rime::Switcher::SetActiveSchema
void SetActiveSchema(const string &schema_id)
Definition switcher.cc:165
rime::Switcher::Activate
void Activate()
Definition switcher.cc:243
rime::Switcher::SelectNextSchema
void SelectNextSchema()
Definition switcher.cc:198
rime::Switcher::CreateSchema
Schema * CreateSchema()
Definition switcher.cc:174
rime::Switcher::IsAutoSave
bool IsAutoSave(const string &option) const
Definition switcher.cc:214
rime::Switcher::attached_engine
Engine * attached_engine() const
Definition switcher.h:45
rime::Switcher::processors_
vector< of< Processor > > processors_
Definition switcher.h:63
rime::Switcher::hotkeys_
vector< KeyEvent > hotkeys_
Definition switcher.h:58
rime::Switcher::Switcher
Switcher(const Ticket &ticket)
Definition switcher.cc:23
rime::SwitcherCommand::keyword
const string & keyword() const
Definition switcher.h:72
rime::SwitcherCommand::SwitcherCommand
SwitcherCommand(const string &keyword)
Definition switcher.h:70
rime::SwitcherCommand::Apply
virtual void Apply(Switcher *switcher)=0
rime::SwitcherCommand::keyword_
string keyword_
Definition switcher.h:75
rime::Ticket
Definition ticket.h:17
rime::Translator
Definition translator.h:22