From a260a998b3b65fc1abe503d1a1ba64c29ad96440 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 10 Oct 2011 20:59:04 +0000 Subject: [PATCH] Convert newlines to \N when pasting rather than trying to clean them up later Originally committed to SVN as r5727. --- aegisub/src/subs_edit_box.cpp | 11 ----------- aegisub/src/subs_edit_box.h | 1 - aegisub/src/subs_edit_ctrl.cpp | 36 +++++++++++++++++++++++++++++----- aegisub/src/subs_edit_ctrl.h | 4 +++- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index 58ca1bf04..bd7512361 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -292,7 +292,6 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context) bind_focus_handler(ActorBox, wxEVT_KILL_FOCUS, "Actor", "", grey); ActorBox->SetForegroundColour(grey); - TextEdit->Bind(wxEVT_STC_STYLENEEDED, &SubsEditBox::OnNeedStyle, this); TextEdit->Bind(wxEVT_STC_MODIFIED, &SubsEditBox::OnChange, this); TextEdit->SetModEventMask(wxSTC_MOD_INSERTTEXT | wxSTC_MOD_DELETETEXT); @@ -545,16 +544,6 @@ void SubsEditBox::OnSize(wxSizeEvent &evt) { evt.Skip(); } -void SubsEditBox::OnNeedStyle(wxStyledTextEvent &event) { - // Check if it needs to fix text - wxString text = TextEdit->GetText(); - if (text.Contains("\n") || text.Contains("\r")) { - TextEdit->SetTextTo(text); - } - // Just update style - else TextEdit->UpdateStyle(); -} - void SubsEditBox::OnFrameTimeRadio(wxCommandEvent &event) { bool byFrame = ByFrame->GetValue(); StartTime->SetByFrame(byFrame); diff --git a/aegisub/src/subs_edit_box.h b/aegisub/src/subs_edit_box.h index 3830a9f4a..aa0759f4b 100644 --- a/aegisub/src/subs_edit_box.h +++ b/aegisub/src/subs_edit_box.h @@ -131,7 +131,6 @@ class SubsEditBox : public wxPanel, protected SelectionListener { int commitId; wxString lastCommitType; - void OnNeedStyle(wxStyledTextEvent &event); void OnChange(wxStyledTextEvent &event); void OnKeyDown(wxKeyEvent &event); diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index f8c39e59d..b3712ad39 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -421,6 +421,8 @@ void SubsTextEditCtrl::UpdateStyle() { /// @brief Update call tip void SubsTextEditCtrl::UpdateCallTip(wxStyledTextEvent &) { + UpdateStyle(); + if (!OPT_GET("App/Call Tips")->GetBool()) return; // Get position and text @@ -666,10 +668,6 @@ void SubsTextEditCtrl::SetTextTo(wxString text) { SetEvtHandlerEnabled(false); Freeze(); - text.Replace("\r\n","\\N"); - text.Replace("\r","\\N"); - text.Replace("\n","\\N"); - int from=0,to=0; GetSelection(&from,&to); @@ -677,12 +675,40 @@ void SubsTextEditCtrl::SetTextTo(wxString text) { UpdateStyle(); // Restore selection - SetSelectionU(GetReverseUnicodePosition(from),GetReverseUnicodePosition(to)); + SetSelectionU(GetReverseUnicodePosition(from), GetReverseUnicodePosition(to)); SetEvtHandlerEnabled(true); Thaw(); } + +void SubsTextEditCtrl::Paste() { + wxString data; + if (wxTheClipboard->Open()) { + if (wxTheClipboard->IsSupported(wxDF_TEXT)) { + wxTextDataObject rawdata; + wxTheClipboard->GetData(rawdata); + data = rawdata.GetText(); + } + wxTheClipboard->Close(); + } + + data.Replace("\r\n", "\\N"); + data.Replace("\n", "\\N"); + data.Replace("\r", "\\N"); + + int from = GetReverseUnicodePosition(GetSelectionStart()); + int to = GetReverseUnicodePosition(GetSelectionEnd()); + + wxString old = GetText(); + SetText(old.Left(from) + data + old.Mid(to)); + + int sel_start = GetUnicodePosition(from + data.size()); + SetSelectionStart(sel_start); + SetSelectionEnd(sel_start); + UpdateStyle(); +} + void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) { if (!grid->GetActiveLine()) return; diff --git a/aegisub/src/subs_edit_ctrl.h b/aegisub/src/subs_edit_ctrl.h index 0fd934533..df5881f0f 100644 --- a/aegisub/src/subs_edit_ctrl.h +++ b/aegisub/src/subs_edit_ctrl.h @@ -95,12 +95,14 @@ class SubsTextEditCtrl : public ScintillaTextCtrl { void UpdateCallTip(wxStyledTextEvent &); void SetStyles(); + void UpdateStyle(); + public: SubsTextEditCtrl(wxWindow* parent, wxSize size, long style, SubtitlesGrid *grid); ~SubsTextEditCtrl(); void SetTextTo(wxString text); - void UpdateStyle(); + void Paste(); DECLARE_EVENT_TABLE() };