From 358b2734daa70874a40e32abec50343784a04fc1 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 22 Jun 2010 00:03:16 +0000 Subject: [PATCH] Fix crash when pasting over Originally committed to SVN as r4562. --- aegisub/src/dialog_paste_over.cpp | 77 ++++++++----------------------- aegisub/src/dialog_paste_over.h | 33 ++----------- aegisub/src/subs_grid.cpp | 9 ++-- 3 files changed, 27 insertions(+), 92 deletions(-) diff --git a/aegisub/src/dialog_paste_over.cpp b/aegisub/src/dialog_paste_over.cpp index 387f883fd..8b101353d 100644 --- a/aegisub/src/dialog_paste_over.cpp +++ b/aegisub/src/dialog_paste_over.cpp @@ -34,9 +34,6 @@ /// @ingroup secondary_ui /// - -/////////// -// Headers #include "config.h" #ifndef AGI_PRE @@ -51,12 +48,21 @@ #include "main.h" #include "options.h" +/// Button IDs +enum { + Paste_Over_Times = 1620, + Paste_Over_Text, + Paste_Over_All, + Paste_Over_None +}; + /// @brief Constructor /// @param parent /// -DialogPasteOver::DialogPasteOver (wxWindow *parent) +DialogPasteOver::DialogPasteOver (wxWindow *parent, std::vector& options) : wxDialog (parent,-1,_("Select Fields to Paste Over"),wxDefaultPosition,wxDefaultSize) +, options(options) { // Script mode int mode = 1; // ASS @@ -89,9 +95,8 @@ DialogPasteOver::DialogPasteOver (wxWindow *parent) // Load checked items /// @todo This assumes a static set of fields. - std::vector choice_array; - OPT_GET("Tool/Paste Lines Over/Fields")->GetListBool(choice_array); - for (unsigned int i=0;iCheck(i,choice_array.at(i)); + OPT_GET("Tool/Paste Lines Over/Fields")->GetListBool(options); + for (unsigned int i=0;iCheck(i,options[i]); // Top buttons wxSizer *TopButtonSizer = new wxBoxSizer(wxHORIZONTAL); @@ -117,16 +122,10 @@ DialogPasteOver::DialogPasteOver (wxWindow *parent) Center(); } - - /// @brief Destructor -/// DialogPasteOver::~DialogPasteOver() { } - -/////////////// -// Event table BEGIN_EVENT_TABLE(DialogPasteOver, wxDialog) EVT_BUTTON(wxID_OK,DialogPasteOver::OnOK) EVT_BUTTON(wxID_CANCEL,DialogPasteOver::OnCancel) @@ -136,76 +135,40 @@ BEGIN_EVENT_TABLE(DialogPasteOver, wxDialog) EVT_BUTTON(Paste_Over_Times,DialogPasteOver::OnTimes) END_EVENT_TABLE() - - /// @brief OK pressed -/// @param event -/// -void DialogPasteOver::OnOK(wxCommandEvent &event) { - - std::vector map; +void DialogPasteOver::OnOK(wxCommandEvent &) { for (int i=0;i<10;i++) { - map[i] = ListBox->IsChecked(i); + options[i] = ListBox->IsChecked(i); } - OPT_SET("Tool/Paste Lines Over/Fields")->SetListBool(map); + OPT_SET("Tool/Paste Lines Over/Fields")->SetListBool(options); EndModal(1); } - - /// @brief Cancel pressed -/// @param event -/// -void DialogPasteOver::OnCancel(wxCommandEvent &event) { +void DialogPasteOver::OnCancel(wxCommandEvent &) { EndModal(0); } - - /// @brief Select Text -/// @param event -/// -void DialogPasteOver::OnText(wxCommandEvent &event) { +void DialogPasteOver::OnText(wxCommandEvent &) { for (int i=0;i<9;i++) ListBox->Check(i,false); ListBox->Check(9,true); } - - /// @brief Select Times -/// @param event -/// -void DialogPasteOver::OnTimes(wxCommandEvent &event) { +void DialogPasteOver::OnTimes(wxCommandEvent &) { for (int i=0;i<10;i++) ListBox->Check(i,false); ListBox->Check(1,true); ListBox->Check(2,true); } - - /// @brief Select All -/// @param event -/// -void DialogPasteOver::OnAll(wxCommandEvent &event) { +void DialogPasteOver::OnAll(wxCommandEvent &) { for (int i=0;i<10;i++) ListBox->Check(i,true); } - - /// @brief Select None -/// @param event -/// -void DialogPasteOver::OnNone(wxCommandEvent &event) { +void DialogPasteOver::OnNone(wxCommandEvent &) { for (int i=0;i<10;i++) ListBox->Check(i,false); } - - - -/// @brief Get options -/// -wxArrayInt DialogPasteOver::GetOptions() { - return options; -} - - diff --git a/aegisub/src/dialog_paste_over.h b/aegisub/src/dialog_paste_over.h index 61b84f15f..38044fb9a 100644 --- a/aegisub/src/dialog_paste_over.h +++ b/aegisub/src/dialog_paste_over.h @@ -34,12 +34,9 @@ /// @ingroup secondary_ui /// - - - -/////////// -// Headers #ifndef AGI_PRE +#include + #include #include #endif @@ -57,7 +54,7 @@ private: wxCheckListBox *ListBox; /// DOCME - wxArrayInt options; + std::vector& options; void OnOK(wxCommandEvent &event); void OnCancel(wxCommandEvent &event); @@ -67,30 +64,8 @@ private: void OnNone(wxCommandEvent &event); public: - DialogPasteOver(wxWindow *parent); + DialogPasteOver(wxWindow *parent, std::vector& options); ~DialogPasteOver(); - wxArrayInt GetOptions(); - DECLARE_EVENT_TABLE() }; - - -/////// -// IDs -enum { - - /// DOCME - Paste_Over_Times = 1620, - - /// DOCME - Paste_Over_Text, - - /// DOCME - Paste_Over_All, - - /// DOCME - Paste_Over_None -}; - - diff --git a/aegisub/src/subs_grid.cpp b/aegisub/src/subs_grid.cpp index c33d1f522..e2e4b86a9 100644 --- a/aegisub/src/subs_grid.cpp +++ b/aegisub/src/subs_grid.cpp @@ -1010,8 +1010,7 @@ void SubtitlesGrid::PasteLines(int n,bool pasteOver) { if (!data.empty()) { // Insert data int inserted = 0; - bool asked = false; - wxArrayInt pasteOverOptions; + std::vector pasteOverOptions; wxStringTokenizer token (data,_T("\r\n"),wxTOKEN_STRTOK); while (token.HasMoreTokens()) { // Convert data into an AssDialogue @@ -1037,14 +1036,12 @@ void SubtitlesGrid::PasteLines(int n,bool pasteOver) { if (pasteOver) { if (n+inserted < GetRows()) { // Get list of options to paste over, if not asked yet - if (asked == false) { - asked = true; - DialogPasteOver diag(NULL); + if (pasteOverOptions.empty()) { + DialogPasteOver diag(NULL, pasteOverOptions); if (!diag.ShowModal()) { delete curdiag; return; } - pasteOverOptions = diag.GetOptions(); } // Paste over