Convert newlines to \N when pasting rather than trying to clean them up later

Originally committed to SVN as r5727.
This commit is contained in:
Thomas Goyne 2011-10-10 20:59:04 +00:00
parent 6e30ff633c
commit a260a998b3
4 changed files with 34 additions and 18 deletions

View File

@ -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);

View File

@ -131,7 +131,6 @@ class SubsEditBox : public wxPanel, protected SelectionListener<AssDialogue> {
int commitId;
wxString lastCommitType;
void OnNeedStyle(wxStyledTextEvent &event);
void OnChange(wxStyledTextEvent &event);
void OnKeyDown(wxKeyEvent &event);

View File

@ -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;

View File

@ -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()
};