Uncrustify AssStyleStorage a bit
Originally committed to SVN as r6413.
This commit is contained in:
parent
ac5af24014
commit
3be4693480
3 changed files with 63 additions and 106 deletions
|
@ -34,56 +34,47 @@
|
|||
/// @ingroup style_editor
|
||||
///
|
||||
|
||||
|
||||
////////////
|
||||
// Includes
|
||||
#include "config.h"
|
||||
|
||||
#include "ass_style_storage.h"
|
||||
|
||||
#ifndef AGI_PRE
|
||||
#include <fstream>
|
||||
#include <tr1/functional>
|
||||
#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"
|
||||
|
||||
AssStyleStorage::~AssStyleStorage() {
|
||||
delete_clear(style);
|
||||
}
|
||||
|
||||
/// @brief Save styles to disk
|
||||
/// @param name
|
||||
/// @return
|
||||
///
|
||||
void AssStyleStorage::Save(wxString name) {
|
||||
if (name.IsEmpty()) return;
|
||||
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";
|
||||
|
||||
TextFileWriter file(StandardPaths::DecodePath("?user/catalog/" + name + ".sty"), "UTF-8");
|
||||
|
||||
for (std::list<AssStyle*>::iterator cur=style.begin();cur!=style.end();cur++) {
|
||||
for (std::list<AssStyle*>::iterator cur = style.begin(); cur != style.end(); ++cur)
|
||||
file.WriteLineToFile((*cur)->GetEntryData());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Load styles from disk
|
||||
/// @param name
|
||||
/// @return
|
||||
///
|
||||
void AssStyleStorage::Load(wxString name) {
|
||||
if (name.IsEmpty()) return;
|
||||
void AssStyleStorage::Load(wxString const& name) {
|
||||
if (name.empty()) return;
|
||||
Clear();
|
||||
|
||||
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<AssStyle*>::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<AssStyle*>::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<AssStyle*>::iterator cur=style.begin();cur!=style.end();cur++) {
|
||||
if ((*cur)->name == name) return *cur;
|
||||
for (std::list<AssStyle*>::iterator cur = style.begin(); cur != style.end(); ++cur) {
|
||||
if ((*cur)->name.CmpNoCase(name) == 0)
|
||||
return *cur;
|
||||
}
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,23 +34,14 @@
|
|||
/// @ingroup style_editor
|
||||
///
|
||||
|
||||
|
||||
|
||||
|
||||
////////////
|
||||
// Includes
|
||||
#ifndef AGI_PRE
|
||||
#include <list>
|
||||
|
||||
#include <wx/arrstr.h>
|
||||
#endif
|
||||
|
||||
|
||||
//////////////
|
||||
// Prototypes
|
||||
class AssStyle;
|
||||
|
||||
|
||||
/// DOCME
|
||||
/// @class AssStyleStorage
|
||||
/// @brief DOCME
|
||||
|
@ -58,13 +49,26 @@ class AssStyle;
|
|||
/// DOCME
|
||||
class AssStyleStorage {
|
||||
public:
|
||||
~AssStyleStorage();
|
||||
|
||||
/// DOCME
|
||||
std::list<AssStyle*> 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);
|
||||
};
|
||||
|
|
|
@ -253,7 +253,6 @@ DialogStyleManager::~DialogStyleManager() {
|
|||
if (sel != wxNOT_FOUND) {
|
||||
c->ass->SetScriptInfo("Last Style Storage",CatalogList->GetString(sel));
|
||||
}
|
||||
Store.Clear();
|
||||
}
|
||||
|
||||
/// @brief Load the catalog of stored styles
|
||||
|
@ -263,17 +262,11 @@ void DialogStyleManager::LoadCatalog () {
|
|||
// 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.style.push_back(new AssStyle);
|
||||
Store.Save("Default");
|
||||
}
|
||||
}
|
||||
|
||||
// Get dir
|
||||
dirname = StandardPaths::DecodePath("?user/catalog/*.sty");
|
||||
|
@ -319,11 +312,10 @@ void DialogStyleManager::LoadStorageStyles () {
|
|||
styleStorageMap.clear();
|
||||
|
||||
for (std::list<AssStyle*>::iterator cur=Store.style.begin();cur!=Store.style.end();cur++) {
|
||||
if (AssStyle *style = *cur) {
|
||||
AssStyle *style = *cur;
|
||||
StorageList->Append(style->name);
|
||||
styleStorageMap.push_back(style);
|
||||
}
|
||||
}
|
||||
|
||||
// Flag change
|
||||
wxCommandEvent dummy;
|
||||
|
@ -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();
|
||||
|
@ -519,36 +505,31 @@ void DialogStyleManager::OnStorageChange (wxCommandEvent &) {
|
|||
|
||||
/// @brief Copy to Storage
|
||||
void DialogStyleManager::OnCopyToStorage(wxCommandEvent &) {
|
||||
using std::list;
|
||||
// Check if there is actually a storage
|
||||
if (!StorageNew->IsEnabled()) return;
|
||||
|
||||
list<wxString> copied;
|
||||
std::list<wxString> 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<AssStyle *>::iterator style = Store.style.begin(); style != Store.style.end(); ++style) {
|
||||
if ((*style)->name.CmpNoCase(styleName) == 0) {
|
||||
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]);
|
||||
*style = *styleMap.at(selections[i]);
|
||||
copied.push_back(styleName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
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<wxString>::iterator name = copied.begin(); name != copied.end(); ++name) {
|
||||
for (std::list<wxString>::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;i<styls.size();i++) Store.style.push_back(styls[i]);
|
||||
copy(styls.begin(), styls.end(), back_inserter(Store.style));
|
||||
|
||||
// Save storage
|
||||
Store.Save(CatalogList->GetString(CatalogList->GetSelection()));
|
||||
|
|
Loading…
Reference in a new issue