From c7d0ce60eefd12981c4ca4ab967d0aa29bc82a70 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 17 Oct 2011 22:00:58 +0000 Subject: [PATCH] Make the style editor commit its own changes. Fixes some issues where changes made in the style editor would fail to update the rest of the program. Originally committed to SVN as r5754. --- aegisub/src/dialog_style_editor.cpp | 48 +++++++++++------- aegisub/src/dialog_style_editor.h | 36 +++++++------- aegisub/src/dialog_style_manager.cpp | 74 ++++++---------------------- 3 files changed, 64 insertions(+), 94 deletions(-) diff --git a/aegisub/src/dialog_style_editor.cpp b/aegisub/src/dialog_style_editor.cpp index 261f42051..e30d98de6 100644 --- a/aegisub/src/dialog_style_editor.cpp +++ b/aegisub/src/dialog_style_editor.cpp @@ -78,15 +78,25 @@ static wxTextCtrl *num_text_ctrl(wxWindow *parent, double value, wxSize size = w return new wxTextCtrl(parent, -1, "", wxDefaultPosition, size, 0, NumValidator(wxString::Format("%0.3g", value), true, false)); } -DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *style, agi::Context *c, bool local, AssStyleStorage *store, bool newStyle) +DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store, bool copy_style) : wxDialog (parent, -1, _("Style Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, "DialogStyleEditor") , c(c) -, isLocal(local) -, isNew(newStyle) +, is_new(false) , style(style) -, work(new AssStyle(*style)) , store(store) { + if (copy_style) { + is_new = true; + style = this->style = new AssStyle(*style); + style->name += _(" - Copy"); + } + else if (!style) { + is_new = true; + style = this->style = new AssStyle; + } + + work.reset(new AssStyle(*style)); + SetIcon(BitmapToIcon(GETIMAGE(style_toolbutton_24))); // Prepare control values @@ -331,31 +341,30 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *style, agi::Co colorButton[i]->Bind(wxEVT_COMMAND_BUTTON_CLICKED, bind(&DialogStyleEditor::OnSetColor, this, i + 1, std::tr1::placeholders::_1)); } -DialogStyleEditor::~DialogStyleEditor () { +DialogStyleEditor::~DialogStyleEditor() { + if (is_new) + delete style; } /// @brief Update appearances of a renamed style in \r tags -void ReplaceStyle(wxString tag, int, AssOverrideParameter* param, void *userData) { +static void ReplaceStyle(wxString tag, int, AssOverrideParameter* param, void *userData) { wxArrayString strings = *((wxArrayString*)userData); if (tag == "\\r" && param->GetType() == VARDATA_TEXT && param->Get() == strings[0]) { param->Set(strings[1]); } } -/// @brief Maybe apply changs and maybe close the dialog -/// @param apply Should changes be applied? -/// @param close Should the dialog be closed? -void DialogStyleEditor::Apply (bool apply, bool close) { +void DialogStyleEditor::Apply(bool apply, bool close) { if (apply) { wxString newStyleName = StyleName->GetValue(); // Get list of existing styles - wxArrayString styles = isLocal ? c->ass->GetStyles() : store->GetNames(); + wxArrayString styles = store ? store->GetNames() : c->ass->GetStyles(); // Check if style name is unique for (unsigned int i=0;iass->GetStyle(styles[i]) != style)) || (!isLocal && (store->GetStyle(styles[i]) != style))) { + if ((store && store->GetStyle(styles[i]) != style) || c->ass->GetStyle(styles[i]) != style) { wxMessageBox("There is already a style with this name. Please choose another name.", "Style name conflict.", wxICON_ERROR|wxOK); return; } @@ -365,11 +374,9 @@ void DialogStyleEditor::Apply (bool apply, bool close) { // Style name change bool did_rename = false; if (work->name != newStyleName) { - if (!isNew && isLocal) { + if (!store && !is_new && work->name != "Default") { // See if user wants to update style name through script - int answer = wxNO; - if (work->name != "Default") - answer = wxMessageBox(_("Do you want to change all instances of this style in the script to this new name?"), _("Update script?"), wxYES_NO | wxCANCEL); + int answer = wxMessageBox(_("Do you want to change all instances of this style in the script to this new name?"), _("Update script?"), wxYES_NO | wxCANCEL); if (answer == wxCANCEL) return; @@ -397,7 +404,14 @@ void DialogStyleEditor::Apply (bool apply, bool close) { *style = *work; style->UpdateData(); - if (isLocal) + if (is_new) { + if (store) + store->style.push_back(style); + else + c->ass->InsertStyle(style); + is_new = false; + } + if (!store) c->ass->Commit(_("style change"), AssFile::COMMIT_STYLES | (did_rename ? AssFile::COMMIT_DIAG_FULL : 0)); // Update preview diff --git a/aegisub/src/dialog_style_editor.h b/aegisub/src/dialog_style_editor.h index 524918d4d..28cddf59f 100644 --- a/aegisub/src/dialog_style_editor.h +++ b/aegisub/src/dialog_style_editor.h @@ -1,4 +1,4 @@ -// Copyright (c) 2005, Rodrigo Braz Monteiro +// Copyright(c) 2005, Rodrigo Braz Monteiro // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -18,10 +18,10 @@ // 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 +// 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) +// 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. // @@ -60,13 +60,10 @@ class DialogStyleEditor : public wxDialog { agi::Context *c; agi::scoped_ptr persist; - /// DOCME - bool isLocal; - /// If true, the style was just created and so the user should not be /// asked if they want to change any existing lines should they rename /// the style - bool isNew; + bool is_new; /// DOCME AssStyle *style; @@ -140,21 +137,24 @@ class DialogStyleEditor : public wxDialog { /// DOCME SubtitlesPreview *SubsPreview; - void SetBitmapColor (int n,wxColour color); - int AlignToControl (int n); - int ControlToAlign (int n); - void UpdateWorkStyle (); + void SetBitmapColor(int n,wxColour color); + int AlignToControl(int n); + int ControlToAlign(int n); + void UpdateWorkStyle(); - void OnChildFocus (wxChildFocusEvent &event); - void OnCommandPreviewUpdate (wxCommandEvent &event); + void OnChildFocus(wxChildFocusEvent &event); + void OnCommandPreviewUpdate(wxCommandEvent &event); - void OnPreviewTextChange (wxCommandEvent &event); - void OnPreviewColourChange (wxCommandEvent &event); + void OnPreviewTextChange(wxCommandEvent &event); + void OnPreviewColourChange(wxCommandEvent &event); - void Apply (bool apply,bool close); - void OnSetColor (int n, wxCommandEvent& evt); + /// @brief Maybe apply changes and maybe close the dialog + /// @param apply Should changes be applied? + /// @param close Should the dialog be closed? + void Apply(bool apply,bool close); + void OnSetColor(int n, wxCommandEvent& evt); public: - DialogStyleEditor(wxWindow *parent,AssStyle *style, agi::Context *c,bool local,AssStyleStorage *store,bool newStyle=false); + DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store, bool copy_style); ~DialogStyleEditor(); }; diff --git a/aegisub/src/dialog_style_manager.cpp b/aegisub/src/dialog_style_manager.cpp index e4495407b..d72a846c5 100644 --- a/aegisub/src/dialog_style_manager.cpp +++ b/aegisub/src/dialog_style_manager.cpp @@ -481,11 +481,9 @@ void DialogStyleManager::OnStorageEdit (wxCommandEvent &) { int n = StorageList->GetSelections(selections); if (n == 1) { AssStyle *selStyle = styleStorageMap[selections[0]]; - DialogStyleEditor editor(this,selStyle,c,false,&Store); - if (editor.ShowModal()) { - StorageList->SetString(selections[0],selStyle->name); - Store.Save(CatalogList->GetString(CatalogList->GetSelection())); - } + DialogStyleEditor(this, selStyle, c, &Store, false).ShowModal(); + StorageList->SetString(selections[0],selStyle->name); + Store.Save(CatalogList->GetString(CatalogList->GetSelection())); } UpdateMoveButtons(); } @@ -496,10 +494,8 @@ void DialogStyleManager::OnCurrentEdit (wxCommandEvent &) { int n = CurrentList->GetSelections(selections); if (n == 1) { AssStyle *selStyle = styleMap[selections[0]]; - DialogStyleEditor editor(this,selStyle,c,true,&Store); - if (editor.ShowModal()) { - CurrentList->SetString(selections[0],selStyle->name); - } + DialogStyleEditor(this, selStyle, c, 0, false).ShowModal(); + CurrentList->SetString(selections[0],selStyle->name); } UpdateMoveButtons(); } @@ -606,21 +602,10 @@ void DialogStyleManager::OnStorageCopy (wxCommandEvent &) { wxArrayInt selections; StorageList->GetSelections(selections); if (selections.size() == 0) return; - AssStyle *temp = new AssStyle(*(styleStorageMap.at(selections[0]))); - wxString newName = _("Copy of "); - newName += temp->name; - temp->name = newName; - - DialogStyleEditor editor(this,temp,c,false,&Store,true); - int modified = editor.ShowModal(); - if (modified) { - Store.style.push_back(temp); - Store.Save(CatalogList->GetString(CatalogList->GetSelection())); - LoadStorageStyles(); - StorageList->SetStringSelection(temp->name); // the copy/delete/copy-to-local buttons stay disabled after this? - } - else delete temp; + DialogStyleEditor(this, styleStorageMap[selections[0]], c, &Store, true).ShowModal(); + Store.Save(CatalogList->GetString(CatalogList->GetSelection())); + LoadStorageStyles(); UpdateMoveButtons(); } @@ -630,21 +615,8 @@ void DialogStyleManager::OnCurrentCopy (wxCommandEvent &) { CurrentList->GetSelections(selections); if (selections.size() == 0) return; - AssStyle *temp = new AssStyle(styleMap.at(selections[0])->GetEntryData()); - wxString newName = _("Copy of "); - newName += temp->name; - temp->name = newName; - - DialogStyleEditor editor(this,temp,c,true,&Store,true); - int modified = editor.ShowModal(); - if (modified) { - c->ass->InsertStyle(temp); - LoadCurrentStyles(c->ass); - CurrentList->SetStringSelection(temp->name); // but even without this, the copy/delete/copy-to-storage buttons stay enabled? - } - else delete temp; - - c->ass->Commit(_("style copy"), AssFile::COMMIT_STYLES); + DialogStyleEditor(this, styleMap[selections[0]], c, 0, true).ShowModal(); + LoadCurrentStyles(c->ass); UpdateMoveButtons(); } @@ -750,32 +722,16 @@ void DialogStyleManager::PasteToStorage() { /// @brief Storage new void DialogStyleManager::OnStorageNew (wxCommandEvent &) { - AssStyle *temp = new AssStyle; - - DialogStyleEditor editor(this,temp,c,false,&Store,true); - int modified = editor.ShowModal(); - if (modified) { - Store.style.push_back(temp); - Store.Save(CatalogList->GetString(CatalogList->GetSelection())); - LoadStorageStyles(); - StorageList->SetStringSelection(temp->name); - } - else delete temp; + DialogStyleEditor(this, 0, c, &Store, false).ShowModal(); + Store.Save(CatalogList->GetString(CatalogList->GetSelection())); + LoadStorageStyles(); UpdateMoveButtons(); } /// @brief Current new void DialogStyleManager::OnCurrentNew (wxCommandEvent &) { - AssStyle *temp = new AssStyle; - - DialogStyleEditor editor(this,temp,c,true,&Store,true); - int modified = editor.ShowModal(); - if (modified) { - c->ass->InsertStyle(temp); - LoadCurrentStyles(c->ass); - CurrentList->SetStringSelection(temp->name); - } - else delete temp; + DialogStyleEditor(this,0, c, 0, false).ShowModal(); + LoadCurrentStyles(c->ass); UpdateMoveButtons(); }