-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c00aee
commit 22682ac
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Module from './module' | ||
|
||
export function getMenuActions() { | ||
return JSON.parse(Module.ccall('get_menu_actions', 'string', [], [])) | ||
} | ||
|
||
export function activateMenuAction(id: number) { | ||
return Module.ccall('activate_menu_action', 'void', ['number'], [id]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <emscripten.h> | ||
#include <fcitx/action.h> | ||
#include <fcitx/instance.h> | ||
#include <fcitx/menu.h> | ||
#include <fcitx/statusarea.h> | ||
#include <fcitx/userinterfacemanager.h> | ||
#include <nlohmann/json.hpp> | ||
|
||
namespace fcitx { | ||
extern std::unique_ptr<Instance> instance; | ||
|
||
static nlohmann::json actionToJson(Action *action, InputContext *ic) { | ||
nlohmann::json j; | ||
j["id"] = action->id(); | ||
j["desc"] = action->shortText(ic); | ||
if (action->isSeparator()) { | ||
j["separator"] = true; | ||
} | ||
if (action->isCheckable()) { | ||
bool checked = action->isChecked(ic); | ||
j["checked"] = checked; | ||
} | ||
if (auto *menu = action->menu()) { | ||
for (auto *subaction : menu->actions()) { | ||
j["children"].emplace_back(actionToJson(subaction, ic)); | ||
} | ||
} | ||
return j; | ||
} | ||
|
||
extern "C" { | ||
EMSCRIPTEN_KEEPALIVE const char *get_menu_actions() { | ||
static std::string ret; | ||
if (auto *ic = instance->mostRecentInputContext()) { | ||
nlohmann::json j = nlohmann::json::array(); | ||
auto &statusArea = ic->statusArea(); | ||
for (auto *action : statusArea.allActions()) { | ||
if (!action->id()) { | ||
// Not registered with UI manager. | ||
continue; | ||
} | ||
j.emplace_back(actionToJson(action, ic)); | ||
} | ||
ret = j.dump(); | ||
return ret.c_str(); | ||
} | ||
return "[]"; | ||
} | ||
|
||
EMSCRIPTEN_KEEPALIVE void activate_menu_action(int id) { | ||
if (auto *ic = instance->mostRecentInputContext()) { | ||
auto *action = instance->userInterfaceManager().lookupActionById(id); | ||
action->activate(ic); | ||
} | ||
} | ||
} | ||
} // namespace fcitx |