diff --git a/src/bitmaps/button/direction_ltr_16.png b/src/bitmaps/button/direction_ltr_16.png new file mode 100644 index 0000000000..09305f7301 Binary files /dev/null and b/src/bitmaps/button/direction_ltr_16.png differ diff --git a/src/bitmaps/button/direction_ltr_24.png b/src/bitmaps/button/direction_ltr_24.png new file mode 100644 index 0000000000..65c0174c74 Binary files /dev/null and b/src/bitmaps/button/direction_ltr_24.png differ diff --git a/src/bitmaps/button/direction_ltr_32.png b/src/bitmaps/button/direction_ltr_32.png new file mode 100644 index 0000000000..d7b0986501 Binary files /dev/null and b/src/bitmaps/button/direction_ltr_32.png differ diff --git a/src/bitmaps/button/direction_ltr_48.png b/src/bitmaps/button/direction_ltr_48.png new file mode 100644 index 0000000000..503e71b528 Binary files /dev/null and b/src/bitmaps/button/direction_ltr_48.png differ diff --git a/src/bitmaps/button/direction_ltr_64.png b/src/bitmaps/button/direction_ltr_64.png new file mode 100644 index 0000000000..a1cca9e32f Binary files /dev/null and b/src/bitmaps/button/direction_ltr_64.png differ diff --git a/src/bitmaps/button/direction_rtl_16.png b/src/bitmaps/button/direction_rtl_16.png new file mode 100644 index 0000000000..6074aaa5cf Binary files /dev/null and b/src/bitmaps/button/direction_rtl_16.png differ diff --git a/src/bitmaps/button/direction_rtl_24.png b/src/bitmaps/button/direction_rtl_24.png new file mode 100644 index 0000000000..d2c16eea41 Binary files /dev/null and b/src/bitmaps/button/direction_rtl_24.png differ diff --git a/src/bitmaps/button/direction_rtl_32.png b/src/bitmaps/button/direction_rtl_32.png new file mode 100644 index 0000000000..0ad15597e8 Binary files /dev/null and b/src/bitmaps/button/direction_rtl_32.png differ diff --git a/src/bitmaps/button/direction_rtl_48.png b/src/bitmaps/button/direction_rtl_48.png new file mode 100644 index 0000000000..edc819efa6 Binary files /dev/null and b/src/bitmaps/button/direction_rtl_48.png differ diff --git a/src/bitmaps/button/direction_rtl_64.png b/src/bitmaps/button/direction_rtl_64.png new file mode 100644 index 0000000000..da282f8116 Binary files /dev/null and b/src/bitmaps/button/direction_rtl_64.png differ diff --git a/src/bitmaps/manifest.respack b/src/bitmaps/manifest.respack index 25e6fa33d2..c6291c0c63 100644 --- a/src/bitmaps/manifest.respack +++ b/src/bitmaps/manifest.respack @@ -91,6 +91,16 @@ button/button_color_two_24.png button/button_color_two_32.png button/button_color_two_48.png button/button_color_two_64.png +button/direction_ltr_16.png +button/direction_ltr_24.png +button/direction_ltr_32.png +button/direction_ltr_48.png +button/direction_ltr_64.png +button/direction_rtl_16.png +button/direction_rtl_24.png +button/direction_rtl_32.png +button/direction_rtl_48.png +button/direction_rtl_64.png button/button_fontname_16.png button/button_fontname_24.png button/button_fontname_32.png diff --git a/src/command/edit.cpp b/src/command/edit.cpp index 333cdc6d5d..b09009edfe 100644 --- a/src/command/edit.cpp +++ b/src/command/edit.cpp @@ -46,6 +46,7 @@ #include "../project.h" #include "../selection_controller.h" #include "../subs_controller.h" +#include "../subs_edit_ctrl.h" #include "../text_selection_controller.h" #include "../utils.h" #include "../video_controller.h" @@ -1265,6 +1266,40 @@ struct edit_insert_original final : public Command { } }; +struct edit_text_ltr final : public Command { + CMD_NAME("edit/text_ltr") + CMD_ICON(direction_ltr) + STR_DISP("Set text to LTR") + STR_MENU("Set text to LTR") + STR_HELP("Change the direction of the text to LTR") + + void operator()(agi::Context *c) override { + if (c->textSelectionController->GetControl()->GetLayoutDirection() != wxLayout_LeftToRight) { + c->textSelectionController->GetControl()->SetLayoutDirection (wxLayout_LeftToRight); + } + } +}; + +struct edit_text_rtl final : public Command { + CMD_NAME("edit/text_rtl") + CMD_ICON(direction_rtl) + STR_DISP("Set text to RTL") + STR_MENU("Set text to RTL") + STR_HELP("Change the direction of the text to RTL") + + void operator()(agi::Context *c) override { + if (c->textSelectionController->GetControl()->GetLayoutDirection() == wxLayout_RightToLeft) + return; + + c->textSelectionController->GetControl()->SetLayoutDirection (wxLayout_RightToLeft); + wxString data = c->textSelectionController->GetControl()->GetText(); + if (data.StartsWith(RTL_MARK) != false) { + data.insert(0, RTL_MARK); + c->textSelectionController->GetControl()->SetTextRaw(data.c_str()); + } + } +}; + } namespace cmd { @@ -1273,6 +1308,8 @@ namespace cmd { reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); + reg(agi::make_unique()); + reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); diff --git a/src/subs_edit_box.cpp b/src/subs_edit_box.cpp index 308023d6c0..a9d9e57dc1 100644 --- a/src/subs_edit_box.cpp +++ b/src/subs_edit_box.cpp @@ -188,6 +188,9 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context) MakeButton("edit/color/shadow"); middle_right_sizer->AddSpacer(5); MakeButton("grid/line/next/create"); + middle_right_sizer->AddSpacer(5); + MakeButton("edit/text_ltr"); + MakeButton("edit/text_rtl"); middle_right_sizer->AddSpacer(10); by_time = MakeRadio(_("T&ime"), true, _("Time by h:mm:ss.cs")); diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index ee5389a489..4028be8d2a 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -109,6 +109,7 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a using std::bind; Bind(wxEVT_CHAR_HOOK, &SubsTextEditCtrl::OnKeyDown, this); + Bind(wxEVT_CHAR, &SubsTextEditCtrl::OnChar, this); Bind(wxEVT_MENU, bind(&SubsTextEditCtrl::Cut, this), EDIT_MENU_CUT); Bind(wxEVT_MENU, bind(&SubsTextEditCtrl::Copy, this), EDIT_MENU_COPY); @@ -191,9 +192,29 @@ void SubsTextEditCtrl::OnLoseFocus(wxFocusEvent &event) { event.Skip(); } -void SubsTextEditCtrl::OnKeyDown(wxKeyEvent &event) { +void SubsTextEditCtrl::OnChar(wxKeyEvent &event) { event.Skip(); + // TODO upgrade system to support both RTL and LTR by fixing data + if (GetTextRaw().length() == 0) { + if (IsCharRTL(event.GetUnicodeKey())) + { + SetTextTo(RTL_MARK); + SetLayoutDirection(wxLayout_RightToLeft); + SetSelection(GetSelectionStart() + 5, GetSelectionStart() + 5); + } + else + { + SetLayoutDirection(wxLayout_LeftToRight); + } + } + + +} + +void SubsTextEditCtrl::OnKeyDown(wxKeyEvent &event) { + event.Skip(); + // Workaround for wxSTC eating tabs. if (event.GetKeyCode() == WXK_TAB) Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward); diff --git a/src/subs_edit_ctrl.h b/src/subs_edit_ctrl.h index ccb38f4f85..a8dfcb8530 100644 --- a/src/subs_edit_ctrl.h +++ b/src/subs_edit_ctrl.h @@ -87,6 +87,7 @@ class SubsTextEditCtrl final : public wxStyledTextCtrl { void OnSetThesLanguage(wxCommandEvent &event); void OnLoseFocus(wxFocusEvent &event); void OnKeyDown(wxKeyEvent &event); + void OnChar(wxKeyEvent &event); void SetSyntaxStyle(int id, wxFont &font, std::string const& name, wxColor const& default_background); void Subscribe(std::string const& name); diff --git a/src/text_selection_controller.h b/src/text_selection_controller.h index 634ec4a9a7..162ee7974b 100644 --- a/src/text_selection_controller.h +++ b/src/text_selection_controller.h @@ -57,6 +57,7 @@ class TextSelectionController { int GetStagedInsertionPoint() const { return has_staged_selection ? staged_selection_end : insertion_point; } void SetControl(wxStyledTextCtrl *ctrl); + wxStyledTextCtrl* GetControl() const {return ctrl;} ~TextSelectionController(); DEFINE_SIGNAL_ADDERS(AnnounceSelectionChanged, AddSelectionListener) diff --git a/src/utils.cpp b/src/utils.cpp index a66f8b68f6..b482f3a6ae 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -96,6 +96,11 @@ int SmallestPowerOf2(int x) { return x; } +bool IsCharRTL(wxChar c) { + // only hebrew for now + return (((wxChar)0x5d0) <= c) && (c <= ((wxChar)0x5ea)); +} + #ifndef __WXMAC__ void RestartAegisub() { config::opt->Flush(); diff --git a/src/utils.h b/src/utils.h index bb82570d6b..83f8e667e2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -42,6 +42,11 @@ class wxMouseEvent; class wxStyledTextCtrl; class wxWindow; +const std::string LRT_MARK = "\u202A"; +const std::string RTL_MARK = "\u202B"; + +bool IsCharRTL(wxChar c); + wxString PrettySize(int bytes); std::string float_to_string(double val, int precision = 3);