forked from mia/Aegisub
Kill ScintillaTextCtrl and just always use the UTF-8 methods
Trivially improves performance and reduces the opportunities for wxSTC to fuck up.
This commit is contained in:
parent
e6b495dc1b
commit
060536824b
10 changed files with 27 additions and 164 deletions
|
@ -184,7 +184,6 @@
|
|||
<ClInclude Include="$(SrcDir)preferences_base.h" />
|
||||
<ClInclude Include="$(SrcDir)project.h" />
|
||||
<ClInclude Include="$(SrcDir)resolution_resampler.h" />
|
||||
<ClInclude Include="$(SrcDir)scintilla_text_ctrl.h" />
|
||||
<ClInclude Include="$(SrcDir)search_replace_engine.h" />
|
||||
<ClInclude Include="$(SrcDir)selection_controller.h" />
|
||||
<ClInclude Include="$(SrcDir)spellchecker_hunspell.h" />
|
||||
|
@ -376,7 +375,6 @@
|
|||
<ClCompile Include="$(SrcDir)preferences_base.cpp" />
|
||||
<ClCompile Include="$(SrcDir)project.cpp" />
|
||||
<ClCompile Include="$(SrcDir)resolution_resampler.cpp" />
|
||||
<ClCompile Include="$(SrcDir)scintilla_text_ctrl.cpp" />
|
||||
<ClCompile Include="$(SrcDir)search_replace_engine.cpp" />
|
||||
<ClCompile Include="$(SrcDir)selection_controller.cpp" />
|
||||
<ClCompile Include="$(SrcDir)spellchecker.cpp" />
|
||||
|
|
|
@ -390,9 +390,6 @@
|
|||
<ClInclude Include="$(SrcDir)base_grid.h">
|
||||
<Filter>Main UI\Grid</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(SrcDir)scintilla_text_ctrl.h">
|
||||
<Filter>Main UI\Edit box</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(SrcDir)selection_controller.h">
|
||||
<Filter>Main UI\Grid</Filter>
|
||||
</ClInclude>
|
||||
|
@ -926,9 +923,6 @@
|
|||
<ClCompile Include="$(SrcDir)selection_controller.cpp">
|
||||
<Filter>Main UI\Grid</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)scintilla_text_ctrl.cpp">
|
||||
<Filter>Main UI\Edit box</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)subs_edit_box.cpp">
|
||||
<Filter>Main UI\Edit box</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -208,7 +208,6 @@ SRC += \
|
|||
preferences_base.cpp \
|
||||
project.cpp \
|
||||
resolution_resampler.cpp \
|
||||
scintilla_text_ctrl.cpp \
|
||||
search_replace_engine.cpp \
|
||||
selection_controller.cpp \
|
||||
spellchecker.cpp \
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "include/aegisub/context.h"
|
||||
#include "libresrc/libresrc.h"
|
||||
#include "options.h"
|
||||
#include "scintilla_text_ctrl.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <libaegisub/dispatch.h>
|
||||
|
@ -52,7 +51,7 @@ namespace {
|
|||
class DialogFontsCollector final : public wxDialog {
|
||||
AssFile *subs;
|
||||
|
||||
ScintillaTextCtrl *collection_log;
|
||||
wxStyledTextCtrl *collection_log;
|
||||
wxButton *close_btn;
|
||||
wxButton *dest_browse_button;
|
||||
wxButton *start_btn;
|
||||
|
@ -250,7 +249,7 @@ DialogFontsCollector::DialogFontsCollector(agi::Context *c)
|
|||
destination_box->Add(dest_browse_sizer, wxSizerFlags().Expand());
|
||||
|
||||
wxStaticBoxSizer *log_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Log"));
|
||||
collection_log = new ScintillaTextCtrl(this, -1, "", wxDefaultPosition, wxSize(600, 300));
|
||||
collection_log = new wxStyledTextCtrl(this, -1, wxDefaultPosition, wxSize(600, 300));
|
||||
collection_log->SetWrapMode(wxSTC_WRAP_WORD);
|
||||
collection_log->SetMarginWidth(1, 0);
|
||||
collection_log->SetReadOnly(true);
|
||||
|
@ -384,13 +383,14 @@ void DialogFontsCollector::OnRadio(wxCommandEvent &) {
|
|||
void DialogFontsCollector::OnAddText(wxThreadEvent &event) {
|
||||
std::pair<int, wxString> str = event.GetPayload<std::pair<int, wxString>>();
|
||||
collection_log->SetReadOnly(false);
|
||||
int pos = collection_log->GetReverseUnicodePosition(collection_log->GetLength());
|
||||
collection_log->AppendText(str.second);
|
||||
int pos = collection_log->GetLength();
|
||||
auto const& utf8 = str.second.utf8_str();
|
||||
collection_log->AppendTextRaw(utf8.data(), utf8.length());
|
||||
if (str.first) {
|
||||
collection_log->StartUnicodeStyling(pos, 31);
|
||||
collection_log->SetUnicodeStyling(pos, str.second.size(), str.first);
|
||||
collection_log->StartStyling(pos, 31);
|
||||
collection_log->SetStyling(utf8.length(), str.first);
|
||||
}
|
||||
collection_log->GotoPos(pos);
|
||||
collection_log->GotoPos(pos + utf8.length());
|
||||
collection_log->SetReadOnly(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,12 +41,14 @@
|
|||
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
#include <wx/checkbox.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/stc/stc.h>
|
||||
|
||||
static void add_hotkey(wxSizer *sizer, wxWindow *parent, const char *command, wxString const& text) {
|
||||
sizer->Add(new wxStaticText(parent, -1, text));
|
||||
|
@ -77,7 +79,7 @@ DialogTranslation::DialogTranslation(agi::Context *c)
|
|||
line_number_display = new wxStaticText(this, -1, "");
|
||||
original_box->Add(line_number_display, 0, wxBOTTOM, 5);
|
||||
|
||||
original_text = new ScintillaTextCtrl(this, -1, "", wxDefaultPosition, wxSize(320, 80));
|
||||
original_text = new wxStyledTextCtrl(this, -1, wxDefaultPosition, wxSize(320, 80));
|
||||
original_text->SetWrapMode(wxSTC_WRAP_WORD);
|
||||
original_text->SetMarginWidth(1, 0);
|
||||
original_text->StyleSetForeground(1, wxColour(10, 60, 200));
|
||||
|
@ -163,8 +165,7 @@ DialogTranslation::DialogTranslation(agi::Context *c)
|
|||
UpdateDisplay();
|
||||
}
|
||||
|
||||
DialogTranslation::~DialogTranslation() {
|
||||
}
|
||||
DialogTranslation::~DialogTranslation() { }
|
||||
|
||||
void DialogTranslation::OnActiveLineChanged(AssDialogue *new_line) {
|
||||
if (switching_lines) return;
|
||||
|
@ -243,9 +244,8 @@ void DialogTranslation::UpdateDisplay() {
|
|||
int initial_pos = original_text->GetLength();
|
||||
original_text->AppendTextRaw(block->GetText().c_str());
|
||||
if (i == cur_block) {
|
||||
int cur_size = original_text->GetReverseUnicodePosition(initial_pos);
|
||||
original_text->StartUnicodeStyling(cur_size);
|
||||
original_text->SetUnicodeStyling(cur_size, block->GetText().size(), 1);
|
||||
original_text->StartStyling(initial_pos, 31);
|
||||
original_text->SetStyling(block->GetText().size(), 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -262,11 +262,11 @@ void DialogTranslation::UpdateDisplay() {
|
|||
}
|
||||
|
||||
void DialogTranslation::Commit(bool next) {
|
||||
wxString new_value = translated_text->GetValue();
|
||||
new_value.Replace("\r\n", "\\N");
|
||||
new_value.Replace("\r", "\\N");
|
||||
new_value.Replace("\n", "\\N");
|
||||
*blocks[cur_block] = AssDialogueBlockPlain(from_wx(new_value));
|
||||
std::string new_value = translated_text->GetTextRaw().data();
|
||||
boost::replace_all(new_value, "\r\n", "\\N");
|
||||
boost::replace_all(new_value, "\r", "\\N");
|
||||
boost::replace_all(new_value, "\n", "\\N");
|
||||
*blocks[cur_block] = AssDialogueBlockPlain(new_value);
|
||||
active_line->UpdateText(blocks);
|
||||
|
||||
file_change_connection.Block();
|
||||
|
@ -285,7 +285,8 @@ void DialogTranslation::Commit(bool next) {
|
|||
}
|
||||
|
||||
void DialogTranslation::InsertOriginal() {
|
||||
translated_text->AddText(to_wx(blocks[cur_block]->GetText()));
|
||||
auto const& text = blocks[cur_block]->GetText();
|
||||
translated_text->AddTextRaw(text.data(), text.size());
|
||||
}
|
||||
|
||||
void DialogTranslation::OnKeyDown(wxKeyEvent &evt) {
|
||||
|
|
|
@ -14,10 +14,6 @@
|
|||
//
|
||||
// Aegisub Project http://www.aegisub.org/
|
||||
|
||||
/// @file dialog_translation.h
|
||||
/// @see dialog_translation.cpp
|
||||
/// @ingroup tools_ui
|
||||
|
||||
#include <libaegisub/exception.h>
|
||||
#include <libaegisub/signal.h>
|
||||
|
||||
|
@ -29,10 +25,10 @@ namespace agi { struct Context; }
|
|||
class AssDialogue;
|
||||
class AssDialogueBlock;
|
||||
class PersistLocation;
|
||||
class ScintillaTextCtrl;
|
||||
class SubsTextEditCtrl;
|
||||
class wxStaticText;
|
||||
class wxCheckBox;
|
||||
class wxStaticText;
|
||||
class wxStyledTextCtrl;
|
||||
|
||||
/// Assistant for translating subtitles in one language to another language
|
||||
class DialogTranslation final : public wxDialog {
|
||||
|
@ -55,7 +51,7 @@ class DialogTranslation final : public wxDialog {
|
|||
bool switching_lines = false;
|
||||
|
||||
wxStaticText *line_number_display;
|
||||
ScintillaTextCtrl *original_text;
|
||||
wxStyledTextCtrl *original_text;
|
||||
SubsTextEditCtrl *translated_text;
|
||||
wxCheckBox *seek_video;
|
||||
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
// Copyright (c) 2007, Rodrigo Braz Monteiro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Aegisub Project http://www.aegisub.org/
|
||||
|
||||
/// @file scintilla_text_ctrl.cpp
|
||||
/// @brief Customised version of wxStyledTextControl used for main edit box
|
||||
/// @ingroup custom_control
|
||||
///
|
||||
|
||||
#include "scintilla_text_ctrl.h"
|
||||
#include "utils.h"
|
||||
|
||||
ScintillaTextCtrl::ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style)
|
||||
: wxStyledTextCtrl(parent, id, pos, size, style, value)
|
||||
{
|
||||
Bind(wxEVT_MOUSEWHEEL, &ScintillaTextCtrl::OnMouseWheel, this);
|
||||
}
|
||||
|
||||
/// @brief Get unicode-compatible position
|
||||
int ScintillaTextCtrl::GetUnicodePosition(int pos) {
|
||||
return GetText().Left(pos).utf8_str().length();
|
||||
}
|
||||
|
||||
/// @brief Reverse unicode-compatible position
|
||||
int ScintillaTextCtrl::GetReverseUnicodePosition(int pos) {
|
||||
wxCharBuffer buffer = GetTextRaw();
|
||||
return wxString::FromUTF8(buffer.data(), std::min<int>(pos, buffer.length())).length();
|
||||
}
|
||||
|
||||
/// @brief Start unicode-safe styling
|
||||
void ScintillaTextCtrl::StartUnicodeStyling(int start,int mask) {
|
||||
StartStyling(GetUnicodePosition(start),mask);
|
||||
// Cache the text for styling as GetText is hideously slow
|
||||
text = GetText();
|
||||
}
|
||||
|
||||
/// @brief Unicode-safe styling
|
||||
void ScintillaTextCtrl::SetUnicodeStyling(int start,int length,int style) {
|
||||
// Get the real length
|
||||
int len = text.Mid(start, length).utf8_str().length();
|
||||
|
||||
SetStyling(len,style);
|
||||
}
|
||||
|
||||
void ScintillaTextCtrl::OnMouseWheel(wxMouseEvent& evt) {
|
||||
if (ForwardMouseWheelEvent(this, evt)) {
|
||||
// Skip the event so that wxSTC's default mouse wheel handler is hit
|
||||
evt.Skip();
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright (c) 2007, Rodrigo Braz Monteiro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Aegisub Project http://www.aegisub.org/
|
||||
|
||||
#include <wx/stc/stc.h>
|
||||
|
||||
class ScintillaTextCtrl : public wxStyledTextCtrl {
|
||||
wxString text;
|
||||
|
||||
void OnMouseWheel(wxMouseEvent& evt);
|
||||
public:
|
||||
int GetUnicodePosition(int pos);
|
||||
int GetReverseUnicodePosition(int pos);
|
||||
|
||||
void StartUnicodeStyling(int start,int mask=31);
|
||||
void SetUnicodeStyling(int start,int length,int style);
|
||||
|
||||
ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxString(), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
|
||||
};
|
|
@ -27,11 +27,6 @@
|
|||
//
|
||||
// Aegisub Project http://www.aegisub.org/
|
||||
|
||||
/// @file subs_edit_ctrl.cpp
|
||||
/// @brief Main subtitle editing text control
|
||||
/// @ingroup main_ui
|
||||
///
|
||||
|
||||
#include "subs_edit_ctrl.h"
|
||||
|
||||
#include "ass_dialogue.h"
|
||||
|
@ -82,7 +77,7 @@ enum {
|
|||
};
|
||||
|
||||
SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, agi::Context *context)
|
||||
: ScintillaTextCtrl(parent, -1, "", wxDefaultPosition, wsize, style)
|
||||
: wxStyledTextCtrl(parent, -1, wxDefaultPosition, wsize, style)
|
||||
, spellchecker(SpellCheckerFactory::GetSpellChecker())
|
||||
, thesaurus(agi::make_unique<Thesaurus>())
|
||||
, context(context)
|
||||
|
|
|
@ -27,11 +27,10 @@
|
|||
//
|
||||
// Aegisub Project http://www.aegisub.org/
|
||||
|
||||
#include "scintilla_text_ctrl.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <wx/stc/stc.h>
|
||||
|
||||
class Thesaurus;
|
||||
namespace agi {
|
||||
|
@ -43,7 +42,7 @@ namespace agi {
|
|||
|
||||
/// @class SubsTextEditCtrl
|
||||
/// @brief A Scintilla control with spell checking and syntax highlighting
|
||||
class SubsTextEditCtrl final : public ScintillaTextCtrl {
|
||||
class SubsTextEditCtrl final : public wxStyledTextCtrl {
|
||||
/// Backend spellchecker to use
|
||||
std::unique_ptr<agi::SpellChecker> spellchecker;
|
||||
|
||||
|
|
Loading…
Reference in a new issue