Remove AssStyleStorage's dependencies on other Aegisub classes
This commit is contained in:
parent
2bad9029cb
commit
14afce006e
3 changed files with 24 additions and 23 deletions
|
@ -37,41 +37,39 @@
|
|||
#include "ass_style_storage.h"
|
||||
|
||||
#include "ass_style.h"
|
||||
#include "options.h"
|
||||
#include "text_file_reader.h"
|
||||
#include "text_file_writer.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <libaegisub/fs.h>
|
||||
#include <libaegisub/path.h>
|
||||
#include <libaegisub/io.h>
|
||||
#include <libaegisub/line_iterator.h>
|
||||
#include <libaegisub/util.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
AssStyleStorage::~AssStyleStorage() {
|
||||
delete_clear(style);
|
||||
agi::util::delete_clear(style);
|
||||
}
|
||||
|
||||
void AssStyleStorage::Save() const {
|
||||
if (storage_name.empty()) return;
|
||||
if (file.empty()) return;
|
||||
|
||||
agi::fs::CreateDirectory(config::path->Decode("?user/catalog/"));
|
||||
agi::fs::CreateDirectory(file.parent_path());
|
||||
|
||||
agi::io::Save out(file);
|
||||
out.Get() << "\xEF\xBB\xBF";
|
||||
|
||||
TextFileWriter file(config::path->Decode("?user/catalog/" + storage_name + ".sty"), "UTF-8");
|
||||
for (const AssStyle *cur : style)
|
||||
file.WriteLineToFile(cur->GetEntryData());
|
||||
out.Get() << cur->GetEntryData() << std::endl;
|
||||
}
|
||||
|
||||
void AssStyleStorage::Load(std::string const& name) {
|
||||
storage_name = name;
|
||||
void AssStyleStorage::Load(agi::fs::path const& filename) {
|
||||
file = filename;
|
||||
Clear();
|
||||
|
||||
try {
|
||||
TextFileReader file(config::path->Decode("?user/catalog/" + name + ".sty"), "UTF-8");
|
||||
|
||||
while (file.HasMoreLines()) {
|
||||
std::unique_ptr<std::ifstream> in(agi::io::Open(file));
|
||||
for (auto const& line : agi::line_iterator<std::string>(*in)) {
|
||||
try {
|
||||
style.push_back(new AssStyle(file.ReadLineFromFile()));
|
||||
style.push_back(new AssStyle(line));
|
||||
} catch(...) {
|
||||
/* just ignore invalid lines for now */
|
||||
}
|
||||
|
@ -83,7 +81,7 @@ void AssStyleStorage::Load(std::string const& name) {
|
|||
}
|
||||
|
||||
void AssStyleStorage::Clear() {
|
||||
delete_clear(style);
|
||||
agi::util::delete_clear(style);
|
||||
}
|
||||
|
||||
void AssStyleStorage::Delete(int idx) {
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
/// @ingroup style_editor
|
||||
///
|
||||
|
||||
#include <libaegisub/fs_fwd.h>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -39,7 +42,7 @@
|
|||
class AssStyle;
|
||||
|
||||
class AssStyleStorage {
|
||||
std::string storage_name;
|
||||
agi::fs::path file;
|
||||
std::deque<AssStyle*> style;
|
||||
|
||||
public:
|
||||
|
@ -74,6 +77,6 @@ public:
|
|||
void Save() const;
|
||||
|
||||
/// Load stored styles from a file
|
||||
/// @param name Catalog name (note: not file name)
|
||||
void Load(std::string const& name);
|
||||
/// @param filename Catalog filename. Does not have to exist.
|
||||
void Load(agi::fs::path const& filename);
|
||||
};
|
||||
|
|
|
@ -314,7 +314,7 @@ void DialogStyleManager::UpdateStorage() {
|
|||
void DialogStyleManager::OnChangeCatalog() {
|
||||
std::string catalog(from_wx(CatalogList->GetStringSelection()));
|
||||
c->ass->SetScriptInfo("Last Style Storage", catalog);
|
||||
Store.Load(catalog);
|
||||
Store.Load(config::path->Decode("?user/catalog/" + catalog + ".sty"));
|
||||
UpdateStorage();
|
||||
}
|
||||
|
||||
|
@ -327,7 +327,7 @@ void DialogStyleManager::LoadCatalog() {
|
|||
|
||||
// Create a default storage if there are none
|
||||
if (CatalogList->IsListEmpty()) {
|
||||
Store.Load("Default");
|
||||
Store.Load(config::path->Decode("?user/catalog/Default.sty"));
|
||||
Store.push_back(new AssStyle);
|
||||
Store.Save();
|
||||
CatalogList->Append("Default");
|
||||
|
|
Loading…
Reference in a new issue