Skip to content

Commit

Permalink
Add option to disable wxSTC
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqr committed Apr 3, 2021
1 parent d2e1fe1 commit 347b26f
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 34 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ add_executable(Aegisub WIN32
src/string_codec.cpp
src/subs_controller.cpp
src/subs_edit_box.cpp
src/subs_edit_ctrl.cpp
src/subs_preview.cpp
src/subtitles_provider.cpp
src/subtitles_provider_libass.cpp
Expand Down Expand Up @@ -522,6 +521,11 @@ target_link_libraries(libaegisub PRIVATE "ICU::uc")
target_link_libraries(Aegisub PRIVATE "ICU::uc")

find_package(wxWidgets REQUIRED adv base core gl stc xml)
option(WITH_WXSTC "Enable wxStyledTextCtrl support" ON)
if(WITH_WXSTC)
target_compile_definitions(Aegisub PRIVATE "WITH_WXSTC")
target_sources(Aegisub PRIVATE src/subs_edit_ctrl.cpp)
endif()
include(${wxWidgets_USE_FILE})
target_link_libraries(Aegisub LINK_PRIVATE ${wxWidgets_LIBRARIES})

Expand Down Expand Up @@ -776,6 +780,7 @@ message(STATUS "\n"
" FFTW3: ${WITH_FFTW3}\n"
" Hunspell: ${WITH_HUNSPELL}\n"
" uchardet: ${WITH_UCHARDET}\n"
" wxStyledTextCtrl: ${WITH_WXSTC}\n"
" LuaJIT: bundled\n"
"\n"
"Options\n"
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ AS_IF([test x$with_agi_cv_wxstc = xno], AC_MSG_FAILURE([wxWidgets StyledTextCtrl
AS_IF([test x$enable_debug = xyes],
[AS_IF([$WX_CONFIG_PATH --debug],[AC_CXX_FLAG([-D_DEBUG])])])

AC_DEFINE(WITH_WXSTC, 1, [Enable wxStyledTextCtrl Support])

############################
# Precompiled Header Support
# Only works with gcc! (and clang)
Expand Down
31 changes: 17 additions & 14 deletions src/dialog_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ DialogTranslation::DialogTranslation(agi::Context *c)
, active_line_connection(c->selectionController->AddActiveLineListener(&DialogTranslation::OnActiveLineChanged, this))
, active_line(c->selectionController->GetActiveLine())
, line_count(c->ass->Events.size())
#ifdef WITH_WXSTC
, use_stc(OPT_GET("Subtitle/Use STC")->GetBool())
#endif
{
SetIcon(GETICON(translation_toolbutton_16));

Expand All @@ -92,19 +95,19 @@ DialogTranslation::DialogTranslation(agi::Context *c)
}

{
translated_text = new SubsTextEditCtrl(this, wxSize(320, 80), 0, nullptr);
translated_text->SetWrapMode(wxSTC_WRAP_WORD);
translated_text->SetMarginWidth(1, 0);
translated_text->SetFocus();
translated_text->Bind(wxEVT_CHAR_HOOK, &DialogTranslation::OnKeyDown, this);
translated_text_stc = new SubsTextEditCtrl(this, wxSize(320, 80), 0, nullptr);
translated_text_stc->SetWrapMode(wxSTC_WRAP_WORD);
translated_text_stc->SetMarginWidth(1, 0);
translated_text_stc->SetFocus();
translated_text_stc->Bind(wxEVT_CHAR_HOOK, &DialogTranslation::OnKeyDown, this);
#if wxCHECK_VERSION (3, 1, 0)
translated_text->CmdKeyAssign(wxSTC_KEY_RETURN, wxSTC_KEYMOD_SHIFT, wxSTC_CMD_NEWLINE);
translated_text_stc->CmdKeyAssign(wxSTC_KEY_RETURN, wxSTC_KEYMOD_SHIFT, wxSTC_CMD_NEWLINE);
#else
translated_text->CmdKeyAssign(wxSTC_KEY_RETURN, wxSTC_SCMOD_SHIFT, wxSTC_CMD_NEWLINE);
translated_text_stc->CmdKeyAssign(wxSTC_KEY_RETURN, wxSTC_SCMOD_SHIFT, wxSTC_CMD_NEWLINE);
#endif

wxSizer *translated_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Translation"));
translated_box->Add(translated_text, 1, wxEXPAND, 0);
translated_box->Add(translated_text_stc, 1, wxEXPAND, 0);
translation_sizer->Add(translated_box, 1, wxTOP|wxEXPAND, 5);
}
main_sizer->Add(translation_sizer, 1, wxALL | wxEXPAND, 5);
Expand Down Expand Up @@ -267,12 +270,12 @@ void DialogTranslation::UpdateDisplay() {

if (seek_video->IsChecked()) c->videoController->JumpToTime(active_line->Start);

translated_text->ClearAll();
translated_text->SetFocus();
translated_text_stc->ClearAll();
translated_text_stc->SetFocus();
}

void DialogTranslation::Commit(bool next) {
std::string new_value = translated_text->GetTextRaw().data();
std::string new_value = translated_text_stc->GetTextRaw().data();
boost::replace_all(new_value, "\r\n", "\\N");
boost::replace_all(new_value, "\r", "\\N");
boost::replace_all(new_value, "\n", "\\N");
Expand All @@ -296,7 +299,7 @@ void DialogTranslation::Commit(bool next) {

void DialogTranslation::InsertOriginal() {
auto const& text = blocks[cur_block]->GetText();
translated_text->AddTextRaw(text.data(), text.size());
translated_text_stc->AddTextRaw(text.data(), text.size());
}

void DialogTranslation::OnKeyDown(wxKeyEvent &evt) {
Expand All @@ -305,10 +308,10 @@ void DialogTranslation::OnKeyDown(wxKeyEvent &evt) {

void DialogTranslation::OnPlayVideoButton(wxCommandEvent &) {
c->videoController->PlayLine();
translated_text->SetFocus();
translated_text_stc->SetFocus();
}

void DialogTranslation::OnPlayAudioButton(wxCommandEvent &) {
cmd::call("audio/play/selection", c);
translated_text->SetFocus();
translated_text_stc->SetFocus();
}
6 changes: 5 additions & 1 deletion src/dialog_translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class DialogTranslation final : public wxDialog {

wxStaticText *line_number_display;
wxStyledTextCtrl *original_text;
SubsTextEditCtrl *translated_text;
#ifdef WITH_WXSTC
const bool use_stc;
SubsTextEditCtrl *translated_text_stc;
#endif
wxTextCtrl* translated_text_tc;
wxCheckBox *seek_video;

std::unique_ptr<PersistLocation> persist;
Expand Down
3 changes: 2 additions & 1 deletion src/libresrc/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@
"Show Original": false,
"Time Edit" : {
"Insert Mode" : true
}
},
"Use STC": true
},

"Subtitle Format" : {
Expand Down
3 changes: 2 additions & 1 deletion src/libresrc/osx/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@
"Show Original": false,
"Time Edit" : {
"Insert Mode" : true
}
},
"Use STC": true
},

"Subtitle Format" : {
Expand Down
2 changes: 1 addition & 1 deletion src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ void Interface(wxTreebook *book, Preferences *parent) {
auto p = new OptionPage(book, parent, _("Interface"));

auto edit_box = p->PageSizer(_("Edit Box"));
p->OptionAdd(edit_box, _("Use styled edit box"), "Subtitle/Use STC");
p->OptionAdd(edit_box, _("Enable call tips"), "App/Call Tips");
p->OptionAdd(edit_box, _("Overwrite in time boxes"), "Subtitle/Time Edit/Insert Mode");
p->CellSkip(edit_box);
p->OptionAdd(edit_box, _("Enable syntax highlighting"), "Subtitle/Highlight/Syntax");
p->OptionBrowse(edit_box, _("Dictionaries path"), "Path/Dictionary");
p->OptionFont(edit_box, "Subtitle/Edit Box/");
Expand Down
31 changes: 17 additions & 14 deletions src/subs_edit_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
: wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxRAISED_BORDER, "SubsEditBox")
, c(context)
, undo_timer(GetEventHandler())
#ifdef WITH_WXSTC
, use_stc(OPT_GET("Subtitle/Use STC")->GetBool())
#endif
{
using std::bind;

Expand Down Expand Up @@ -210,18 +213,18 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
main_sizer->Add(middle_right_sizer, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT | wxBOTTOM, 3));

// Text editor
edit_ctrl = new SubsTextEditCtrl(this, wxDefaultSize, wxBORDER_SUNKEN, c);
edit_ctrl->Bind(wxEVT_CHAR_HOOK, &SubsEditBox::OnKeyDown, this);
edit_ctrl_stc = new SubsTextEditCtrl(this, wxDefaultSize, wxBORDER_SUNKEN, c);
edit_ctrl_stc->Bind(wxEVT_CHAR_HOOK, &SubsEditBox::OnKeyDown, this);

secondary_editor = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN | wxTE_MULTILINE | wxTE_READONLY);
// Here we use the height of secondary_editor as the initial size of edit_ctrl,
// Here we use the height of secondary_editor as the initial size of edit_ctrl_stc,
// which is more reasonable than the default given by wxWidgets.
// See: https://trac.wxwidgets.org/ticket/18471#ticket
// https://github.com/wangqr/Aegisub/issues/4
edit_ctrl->SetInitialSize(secondary_editor->GetSize());
edit_ctrl_stc->SetInitialSize(secondary_editor->GetSize());

main_sizer->Add(secondary_editor, wxSizerFlags(1).Expand().Border(wxLEFT | wxRIGHT | wxBOTTOM, 3));
main_sizer->Add(edit_ctrl, wxSizerFlags(1).Expand().Border(wxLEFT | wxRIGHT | wxBOTTOM, 3));
main_sizer->Add(edit_ctrl_stc, wxSizerFlags(1).Expand().Border(wxLEFT | wxRIGHT | wxBOTTOM, 3));
main_sizer->Hide(secondary_editor);

bottom_sizer = new wxBoxSizer(wxHORIZONTAL);
Expand All @@ -234,8 +237,8 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)

SetSizerAndFit(main_sizer);

edit_ctrl->Bind(wxEVT_STC_MODIFIED, &SubsEditBox::OnChange, this);
edit_ctrl->SetModEventMask(wxSTC_MOD_INSERTTEXT | wxSTC_MOD_DELETETEXT | wxSTC_STARTACTION);
edit_ctrl_stc->Bind(wxEVT_STC_MODIFIED, &SubsEditBox::OnChange, this);
edit_ctrl_stc->SetModEventMask(wxSTC_MOD_INSERTTEXT | wxSTC_MOD_DELETETEXT | wxSTC_STARTACTION);

Bind(wxEVT_TEXT, &SubsEditBox::OnLayerEnter, this, layer->GetId());
Bind(wxEVT_SPINCTRL, &SubsEditBox::OnLayerEnter, this, layer->GetId());
Expand All @@ -256,8 +259,8 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
context->initialLineState->AddChangeListener(&SubsEditBox::OnLineInitialTextChanged, this),
});

context->textSelectionController->SetControl(edit_ctrl);
edit_ctrl->SetFocus();
context->textSelectionController->SetControl(edit_ctrl_stc);
edit_ctrl_stc->SetFocus();

bool show_original = OPT_GET("Subtitle/Show Original")->GetBool();
if (show_original) {
Expand Down Expand Up @@ -381,7 +384,7 @@ void SubsEditBox::UpdateFields(int type, bool repopulate_lists) {
}

if (type & AssFile::COMMIT_DIAG_TEXT) {
edit_ctrl->SetTextTo(line->Text);
edit_ctrl_stc->SetTextTo(line->Text);
UpdateCharacterCount(line->Text);
}

Expand Down Expand Up @@ -468,7 +471,7 @@ void SubsEditBox::OnKeyDown(wxKeyEvent &event) {
}

void SubsEditBox::OnChange(wxStyledTextEvent &event) {
if (line && edit_ctrl->GetTextRaw().data() != line->Text.get()) {
if (line && edit_ctrl_stc->GetTextRaw().data() != line->Text.get()) {
if (event.GetModificationType() & wxSTC_STARTACTION)
commit_id = -1;
CommitText(_("modify text"));
Expand Down Expand Up @@ -505,7 +508,7 @@ void SubsEditBox::SetSelectedRows(T AssDialogueBase::*field, wxString const& val
}

void SubsEditBox::CommitText(wxString const& desc) {
auto data = edit_ctrl->GetTextRaw();
auto data = edit_ctrl_stc->GetTextRaw();
SetSelectedRows(&AssDialogue::Text, boost::flyweight<std::string>(data.data(), data.length()), desc, AssFile::COMMIT_DIAG_TEXT, true);
}

Expand Down Expand Up @@ -605,7 +608,7 @@ void SubsEditBox::SetControlsState(bool state) {
Enable(state);
if (!state) {
wxEventBlocker blocker(this);
edit_ctrl->SetTextTo("");
edit_ctrl_stc->SetTextTo("");
}
}

Expand Down Expand Up @@ -656,7 +659,7 @@ void SubsEditBox::OnCommentChange(wxCommandEvent &evt) {

void SubsEditBox::CallCommand(const char *cmd_name) {
cmd::call(cmd_name, c);
edit_ctrl->SetFocus();
edit_ctrl_stc->SetFocus();
}

void SubsEditBox::UpdateCharacterCount(std::string const& text) {
Expand Down
6 changes: 5 additions & 1 deletion src/subs_edit_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ class SubsEditBox final : public wxPanel {

void SetDurationField();

SubsTextEditCtrl *edit_ctrl;
#ifdef WITH_WXSTC
const bool use_stc;
SubsTextEditCtrl *edit_ctrl_stc;
#endif
wxTextCtrl* edit_ctrl_tc;
wxTextCtrl *secondary_editor;

public:
Expand Down

0 comments on commit 347b26f

Please sign in to comment.