aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/TextHostControlService.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-12-04 18:06:43 +0800
committercrupest <crupest@outlook.com>2021-12-04 18:06:43 +0800
commit942f1d34c48e61a853db745cd68e46db13266a5c (patch)
treefdb859933dbb302404391ed686bae8c7126c96ee /src/ui/controls/TextHostControlService.cpp
parent2317061516b0bd0002467acbead3120cbe49a6c5 (diff)
downloadcru-942f1d34c48e61a853db745cd68e46db13266a5c.tar.gz
cru-942f1d34c48e61a853db745cd68e46db13266a5c.tar.bz2
cru-942f1d34c48e61a853db745cd68e46db13266a5c.zip
...
Diffstat (limited to 'src/ui/controls/TextHostControlService.cpp')
-rw-r--r--src/ui/controls/TextHostControlService.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp
index b250ccae..90896632 100644
--- a/src/ui/controls/TextHostControlService.cpp
+++ b/src/ui/controls/TextHostControlService.cpp
@@ -14,12 +14,15 @@
#include "cru/platform/gui/Window.hpp"
#include "cru/ui/Base.hpp"
#include "cru/ui/DebugFlags.hpp"
+#include "cru/ui/components/Menu.hpp"
#include "cru/ui/events/UiEvent.hpp"
#include "cru/ui/helper/ShortcutHub.hpp"
#include "cru/ui/host/WindowHost.hpp"
#include "cru/ui/render/ScrollRenderObject.hpp"
#include "cru/ui/render/TextRenderObject.hpp"
+#include <memory>
+
namespace cru::ui::controls {
TextControlMovePattern TextControlMovePattern::kLeft(
helper::ShortcutKeyBind(platform::gui::KeyCode::Left),
@@ -119,6 +122,8 @@ std::vector<TextControlMovePattern> TextControlMovePattern::kDefaultPatterns = {
TextHostControlService::TextHostControlService(gsl::not_null<Control*> control)
: control_(control),
text_host_control_(dynamic_cast<ITextHostControl*>(control.get())) {
+ context_menu_ = std::make_unique<components::PopupMenu>();
+
SetUpShortcuts();
SetupOneHandler(&Control::MouseMoveEvent,
@@ -152,6 +157,16 @@ void TextHostControlService::SetEnabled(bool enable) {
}
}
+void TextHostControlService::SetContextMenuEnabled(bool enabled) {
+ if (context_menu_enabled_ == enabled) return;
+
+ context_menu_enabled_ = enabled;
+
+ if (!context_menu_enabled_ && context_menu_) {
+ context_menu_->Close();
+ }
+}
+
void TextHostControlService::SetEditable(bool editable) {
this->editable_ = editable;
if (!editable) CancelComposition();
@@ -594,4 +609,25 @@ void TextHostControlService::SetUpShortcuts() {
});
}
}
+
+void TextHostControlService::OpenContextMenu(const Point& position,
+ ContextMenuItem items) {
+ context_menu_ = std::make_unique<components::PopupMenu>();
+ auto menu = context_menu_->GetMenu();
+ if (items & ContextMenuItem::kSelectAll) {
+ menu->AddTextItem(u"Select All", [this] { this->SelectAll(); });
+ }
+ if (items & ContextMenuItem::kCopy) {
+ menu->AddTextItem(u"Copy", [this] { this->Copy(); });
+ }
+ if (items & ContextMenuItem::kCut) {
+ menu->AddTextItem(u"Cut", [this] { this->Cut(); });
+ }
+ if (items & ContextMenuItem::kPaste) {
+ menu->AddTextItem(u"Paste", [this] { this->Paste(); });
+ }
+ context_menu_->SetPosition(position);
+ context_menu_->Show();
+}
+
} // namespace cru::ui::controls