Added textbox edit tool popup menu
This commit is contained in:
parent
266e218e2f
commit
550c31f088
3 changed files with 42 additions and 28 deletions
|
|
@ -271,30 +271,40 @@ void TextBoxEditTool::right_click_popup_gui(Vector2f popupPos) {
|
|||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
auto& a = static_cast<TextBoxCanvasComponent&>(comp->obj->get_comp());
|
||||
|
||||
gui.element<PositionAdjustingPopupMenu>("Text popup menu", popupPos, [&, popupPos] {
|
||||
text_label_light(gui, "Text menu");
|
||||
InputManager& input = drawP.world.main.input;
|
||||
//drawP.popup_menu_action_button("Paste", "Paste", [&] {
|
||||
// input.call_text_paste(true);
|
||||
//});
|
||||
//drawP.popup_menu_action_button("Paste without formatting", "Paste without formatting", [&] {
|
||||
// input.call_text_paste(false);
|
||||
//});
|
||||
//if(a.cursor->selectionBeginPos != a.cursor->selectionEndPos) {
|
||||
// drawP.popup_menu_action_button("Copy", "Copy", [&] {
|
||||
// input.set_clipboard_plain_and_richtext_pair(a.textBox->process_copy(*a.cursor));
|
||||
// });
|
||||
// drawP.popup_menu_action_button("Cut", "Cut", [&] {
|
||||
// input.text.do_textbox_operation_with_undo([&]() {
|
||||
// input.set_clipboard_plain_and_richtext_pair(a.textBox->process_cut(*a.cursor));
|
||||
// });
|
||||
// });
|
||||
//}
|
||||
gui.set_z_index(-1, [&] {
|
||||
gui.element<PositionAdjustingPopupMenu>("Text popup menu", popupPos, [&] {
|
||||
text_label_light(gui, "Text menu");
|
||||
InputManager& input = drawP.world.main.input;
|
||||
drawP.popup_menu_action_button("Paste", "Paste", [&] {
|
||||
drawP.world.main.input.call_paste(CustomEvents::PasteEventDataType::TEXT, { .allowRichText = true });
|
||||
});
|
||||
drawP.popup_menu_action_button("Paste without formatting", "Paste without formatting", [&] {
|
||||
drawP.world.main.input.call_paste(CustomEvents::PasteEventDataType::TEXT, { .allowRichText = false });
|
||||
});
|
||||
if(a.cursor->selectionBeginPos != a.cursor->selectionEndPos) {
|
||||
drawP.popup_menu_action_button("Copy", "Copy", [&] {
|
||||
input.set_clipboard_plain_and_richtext_pair(a.textBox->process_copy(*a.cursor));
|
||||
});
|
||||
drawP.popup_menu_action_button("Cut", "Cut", [&] {
|
||||
userInput->do_textbox_operation_with_undo([&]() {
|
||||
input.set_clipboard_plain_and_richtext_pair(a.textBox->process_cut(*a.cursor));
|
||||
});
|
||||
commit_update_and_layout_func();
|
||||
set_styles_at_selection(a);
|
||||
});
|
||||
}
|
||||
}, LayoutElement::Callbacks{
|
||||
.mouseButton = [&](LayoutElement*, const InputManager::MouseButtonCallbackArgs& button) {
|
||||
if(button.down && button.button != InputManager::MouseButton::RIGHT)
|
||||
drawP.clear_right_click_popup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TextBoxEditTool::hold_undo_data(const std::string& undoName, TextBoxCanvasComponent& a) {
|
||||
|
|
|
|||
|
|
@ -914,7 +914,7 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
|||
set_key_down(e, f->second);
|
||||
}
|
||||
|
||||
void InputManager::call_paste(CustomEvents::PasteEventDataType type, const std::optional<Vector2f>& pastePosition) {
|
||||
void InputManager::call_paste(CustomEvents::PasteEventDataType type, const InputManagerCallPasteInfo& info) {
|
||||
// Workaround for not being able to copy richtext to system clipboard, this should at least work within the application itself
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if(type == PasteDataType::TEXT) {
|
||||
|
|
@ -924,12 +924,10 @@ void InputManager::call_paste(CustomEvents::PasteEventDataType type, const std::
|
|||
inMan->process_text_paste(pData);
|
||||
}, this);
|
||||
}
|
||||
else {
|
||||
}
|
||||
#else
|
||||
switch(type) {
|
||||
case CustomEvents::PasteEventDataType::TEXT:
|
||||
process_text_paste(get_clipboard_str_SDL());
|
||||
process_text_paste(get_clipboard_str_SDL(), info.allowRichText);
|
||||
break;
|
||||
case CustomEvents::PasteEventDataType::IMAGE:
|
||||
break;
|
||||
|
|
@ -937,11 +935,11 @@ void InputManager::call_paste(CustomEvents::PasteEventDataType type, const std::
|
|||
#endif
|
||||
}
|
||||
|
||||
void InputManager::process_text_paste(const std::string& pasteStr) {
|
||||
void InputManager::process_text_paste(const std::string& pasteStr, bool allowRichText) {
|
||||
CustomEvents::emit_paste_event({
|
||||
.type = CustomEvents::PasteEventDataType::TEXT,
|
||||
.data = pasteStr,
|
||||
.richText = lastCopiedRichText.has_value() && lastCopiedRichText.value().get_plain_text() == remove_carriage_returns_from_str(pasteStr) ? lastCopiedRichText : std::nullopt
|
||||
.richText = allowRichText && lastCopiedRichText.has_value() && lastCopiedRichText.value().get_plain_text() == remove_carriage_returns_from_str(pasteStr) ? lastCopiedRichText : std::nullopt
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@
|
|||
using namespace Eigen;
|
||||
class MainProgram;
|
||||
|
||||
|
||||
struct InputManagerCallPasteInfo {
|
||||
std::optional<Vector2f> pastePosition;
|
||||
bool allowRichText = true;
|
||||
};
|
||||
|
||||
struct InputManager {
|
||||
InputManager(MainProgram& initMain);
|
||||
|
||||
|
|
@ -281,8 +287,8 @@ struct InputManager {
|
|||
std::string get_clipboard_str_SDL();
|
||||
void get_clipboard_image_data_SDL(const std::function<void(std::string_view data)>& callback);
|
||||
|
||||
void call_paste(CustomEvents::PasteEventDataType type, const std::optional<Vector2f>& pastePosition = std::nullopt);
|
||||
void process_text_paste(const std::string& pasteStr);
|
||||
void call_paste(CustomEvents::PasteEventDataType type, const InputManagerCallPasteInfo& info = {});
|
||||
void process_text_paste(const std::string& pasteStr, bool allowRichText);
|
||||
|
||||
std::optional<RichText::TextData> lastCopiedRichText;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue