From 3be46934806feab883b74ad9b0ad21a5e6d08f8d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 1 Feb 2012 00:48:24 +0000 Subject: [PATCH] Uncrustify AssStyleStorage a bit Originally committed to SVN as r6413. --- aegisub/src/ass_style_storage.cpp | 80 +++++++++------------------- aegisub/src/ass_style_storage.h | 30 ++++++----- aegisub/src/dialog_style_manager.cpp | 59 +++++++------------- 3 files changed, 63 insertions(+), 106 deletions(-) diff --git a/aegisub/src/ass_style_storage.cpp b/aegisub/src/ass_style_storage.cpp index 29459977e..ba3c8da32 100644 --- a/aegisub/src/ass_style_storage.cpp +++ b/aegisub/src/ass_style_storage.cpp @@ -34,56 +34,47 @@ /// @ingroup style_editor /// - -//////////// -// Includes #include "config.h" +#include "ass_style_storage.h" + #ifndef AGI_PRE -#include +#include #endif -#include "ass_file.h" #include "ass_style.h" -#include "ass_style_storage.h" #include "standard_paths.h" #include "text_file_reader.h" #include "text_file_writer.h" +#include "utils.h" - -/// @brief Save styles to disk -/// @param name -/// @return -/// -void AssStyleStorage::Save(wxString name) { - if (name.IsEmpty()) return; - - TextFileWriter file(StandardPaths::DecodePath("?user/catalog/"+name+".sty"), "UTF-8"); - - for (std::list::iterator cur=style.begin();cur!=style.end();cur++) { - file.WriteLineToFile((*cur)->GetEntryData()); - } +AssStyleStorage::~AssStyleStorage() { + delete_clear(style); } +void AssStyleStorage::Save(wxString const& name) { + if (name.empty()) return; + wxString dirname = StandardPaths::DecodePath("?user/catalog/"); + if (!wxDirExists(dirname) && !wxMkdir(dirname)) + throw "Failed creating directory for style catalogs"; -/// @brief Load styles from disk -/// @param name -/// @return -/// -void AssStyleStorage::Load(wxString name) { - if (name.IsEmpty()) return; + TextFileWriter file(StandardPaths::DecodePath("?user/catalog/" + name + ".sty"), "UTF-8"); + for (std::list::iterator cur = style.begin(); cur != style.end(); ++cur) + file.WriteLineToFile((*cur)->GetEntryData()); +} + +void AssStyleStorage::Load(wxString const& name) { + if (name.empty()) return; Clear(); - TextFileReader file(StandardPaths::DecodePath("?user/catalog/"+name+".sty"), "UTF-8"); + TextFileReader file(StandardPaths::DecodePath("?user/catalog/" + name + ".sty"), "UTF-8"); - AssStyle *curStyle; while (file.HasMoreLines()) { wxString data = file.ReadLineFromFile(); - if (data.substr(0,6) == "Style:") { + if (data.StartsWith("Style:")) { try { - curStyle = new AssStyle(data); - style.push_back(curStyle); + style.push_back(new AssStyle(data)); } catch(...) { /* just ignore invalid lines for now */ } @@ -91,23 +82,10 @@ void AssStyleStorage::Load(wxString name) { } } - - -/// @brief Clear -/// void AssStyleStorage::Clear () { - using std::list; - for (list::iterator cur=style.begin();cur!=style.end();cur++) { - delete *cur; - } - style.clear(); + delete_clear(style); } - - -/// @brief Get names -/// @return -/// wxArrayString AssStyleStorage::GetNames() { wxArrayString names; for (std::list::iterator cur=style.begin();cur!=style.end();cur++) { @@ -116,16 +94,10 @@ wxArrayString AssStyleStorage::GetNames() { return names; } - - -/// @brief Get a style by name -/// @param name -/// AssStyle *AssStyleStorage::GetStyle(wxString name) { - for (std::list::iterator cur=style.begin();cur!=style.end();cur++) { - if ((*cur)->name == name) return *cur; + for (std::list::iterator cur = style.begin(); cur != style.end(); ++cur) { + if ((*cur)->name.CmpNoCase(name) == 0) + return *cur; } - return NULL; + return 0; } - - diff --git a/aegisub/src/ass_style_storage.h b/aegisub/src/ass_style_storage.h index 7e3ff00d8..6d2f88ea4 100644 --- a/aegisub/src/ass_style_storage.h +++ b/aegisub/src/ass_style_storage.h @@ -34,23 +34,14 @@ /// @ingroup style_editor /// - - - -//////////// -// Includes #ifndef AGI_PRE #include #include #endif - -////////////// -// Prototypes class AssStyle; - /// DOCME /// @class AssStyleStorage /// @brief DOCME @@ -58,13 +49,26 @@ class AssStyle; /// DOCME class AssStyleStorage { public: + ~AssStyleStorage(); - /// DOCME std::list style; + /// Get the names of all styles in this storage wxArrayString GetNames(); - AssStyle *GetStyle(wxString name); + + /// Delete all styles in this storage void Clear(); - void Save(wxString name); - void Load(wxString name); + + /// Get the style with the given name + /// @param name Case-insensitive style name + /// @return Style or NULL if the requested style is not found + AssStyle *GetStyle(wxString name); + + /// Save stored styles to a file + /// @param name Catalog name (note: not file name) + void Save(wxString const& name); + + /// Load stored styles from a file + /// @param name Catalog name (note: not file name) + void Load(wxString const& name); }; diff --git a/aegisub/src/dialog_style_manager.cpp b/aegisub/src/dialog_style_manager.cpp index 9082d2efe..9bf13cba1 100644 --- a/aegisub/src/dialog_style_manager.cpp +++ b/aegisub/src/dialog_style_manager.cpp @@ -253,26 +253,19 @@ DialogStyleManager::~DialogStyleManager() { if (sel != wxNOT_FOUND) { c->ass->SetScriptInfo("Last Style Storage",CatalogList->GetString(sel)); } - Store.Clear(); } /// @brief Load the catalog of stored styles -void DialogStyleManager::LoadCatalog () { +void DialogStyleManager::LoadCatalog() { CatalogList->Clear(); // Create catalog if it doesn't exist wxString dirname = StandardPaths::DecodePath("?user/catalog/"); if (!wxDirExists(dirname)) { - if (!wxMkdir(dirname)) { - throw "Failed creating directory for style catalogues"; - } - else { - // Create default style - Store.Clear(); - AssStyle *defstyle = new AssStyle; - Store.style.push_back(defstyle); - Store.Save("Default"); - } + // Create default style + Store.Clear(); + Store.style.push_back(new AssStyle); + Store.Save("Default"); } // Get dir @@ -319,10 +312,9 @@ void DialogStyleManager::LoadStorageStyles () { styleStorageMap.clear(); for (std::list::iterator cur=Store.style.begin();cur!=Store.style.end();cur++) { - if (AssStyle *style = *cur) { - StorageList->Append(style->name); - styleStorageMap.push_back(style); - } + AssStyle *style = *cur; + StorageList->Append(style->name); + styleStorageMap.push_back(style); } // Flag change @@ -440,12 +432,6 @@ void DialogStyleManager::OnCatalogNew (wxCommandEvent &) { StorageActions(true); // Save - wxString dirname = StandardPaths::DecodePath("?user/catalog/"); - if (!wxDirExists(dirname)) { - if (!wxMkdir(dirname)) { - throw "Failed creating directory for style catalogues"; - } - } Store.Save(name); } UpdateMoveButtons(); @@ -518,37 +504,32 @@ void DialogStyleManager::OnStorageChange (wxCommandEvent &) { } /// @brief Copy to Storage -void DialogStyleManager::OnCopyToStorage (wxCommandEvent &) { - using std::list; +void DialogStyleManager::OnCopyToStorage(wxCommandEvent &) { // Check if there is actually a storage if (!StorageNew->IsEnabled()) return; - list copied; + std::list copied; wxArrayInt selections; int n = CurrentList->GetSelections(selections); for (int i = 0; i < n; i++) { wxString styleName = CurrentList->GetString(selections[i]); bool addStyle = true; - - for (list::iterator style = Store.style.begin(); style != Store.style.end(); ++style) { - if ((*style)->name.CmpNoCase(styleName) == 0) { - addStyle = false; - if (wxYES == wxMessageBox(wxString::Format("There is already a style with the name \"%s\" on the current storage. Proceed and overwrite anyway?",styleName), "Style name collision.", wxYES_NO)) { - **style = *styleMap.at(selections[i]); - copied.push_back(styleName); - } - break; + + if (AssStyle *style = Store.GetStyle(styleName)) { + addStyle = false; + if (wxYES == wxMessageBox(wxString::Format("There is already a style with the name \"%s\" on the current storage. Proceed and overwrite anyway?",styleName), "Style name collision.", wxYES_NO)) { + *style = *styleMap.at(selections[i]); + copied.push_back(styleName); } } if (addStyle) { - AssStyle *temp = new AssStyle(*styleMap.at(selections[i])); - Store.style.push_back(temp); + Store.style.push_back(new AssStyle(*styleMap.at(selections[i]))); copied.push_back(styleName); } } Store.Save(CatalogList->GetString(CatalogList->GetSelection())); LoadStorageStyles(); - for (list::iterator name = copied.begin(); name != copied.end(); ++name) { + for (std::list::iterator name = copied.begin(); name != copied.end(); ++name) { StorageList->SetStringSelection(*name, true); } wxCommandEvent dummy; @@ -684,7 +665,7 @@ void DialogStyleManager::PasteToStorage() { while (st.HasMoreTokens()) { try { AssStyle *s = new AssStyle(st.GetNextToken().Trim(true)); - while (Store.GetStyle(s->name) != NULL) + while (Store.GetStyle(s->name)) s->name = "Copy of " + s->name; Store.style.push_back(s); @@ -998,7 +979,7 @@ void DialogStyleManager::MoveStyles(bool storage, int type) { if (storage) { // Rewrite storage Store.style.clear(); - for (unsigned int i=0;iGetString(CatalogList->GetSelection()));