mirror of https://github.com/odrling/Aegisub
Copy styles from Default catalog to new files
This commit is contained in:
parent
3260a5fa1a
commit
f45f73151e
|
@ -20,9 +20,12 @@
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
#include "ass_info.h"
|
#include "ass_info.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
|
#include "ass_style_storage.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <libaegisub/fs.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/algorithm/string/case_conv.hpp>
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
@ -36,7 +39,7 @@ AssFile::~AssFile() {
|
||||||
Events.clear_and_dispose([](AssDialogue *e) { delete e; });
|
Events.clear_and_dispose([](AssDialogue *e) { delete e; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFile::LoadDefault(bool include_dialogue_line) {
|
void AssFile::LoadDefault(bool include_dialogue_line, agi::fs::path const& style_catalog_file) {
|
||||||
Info.emplace_back("Title", "Default Aegisub file");
|
Info.emplace_back("Title", "Default Aegisub file");
|
||||||
Info.emplace_back("ScriptType", "v4.00+");
|
Info.emplace_back("ScriptType", "v4.00+");
|
||||||
Info.emplace_back("WrapStyle", "0");
|
Info.emplace_back("WrapStyle", "0");
|
||||||
|
@ -47,8 +50,16 @@ void AssFile::LoadDefault(bool include_dialogue_line) {
|
||||||
}
|
}
|
||||||
Info.emplace_back("YCbCr Matrix", "None");
|
Info.emplace_back("YCbCr Matrix", "None");
|
||||||
|
|
||||||
|
// Add default style
|
||||||
Styles.push_back(*new AssStyle);
|
Styles.push_back(*new AssStyle);
|
||||||
|
|
||||||
|
// Add/replace any catalog styles requested
|
||||||
|
if (!style_catalog_file.empty() && agi::fs::FileExists(style_catalog_file)) {
|
||||||
|
AssStyleStorage catalog;
|
||||||
|
catalog.Load(style_catalog_file);
|
||||||
|
catalog.ReplaceIntoFile(*this);
|
||||||
|
}
|
||||||
|
|
||||||
if (include_dialogue_line)
|
if (include_dialogue_line)
|
||||||
Events.push_back(*new AssDialogue);
|
Events.push_back(*new AssDialogue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public:
|
||||||
|
|
||||||
/// @brief Load default file
|
/// @brief Load default file
|
||||||
/// @param defline Add a blank line to the file
|
/// @param defline Add a blank line to the file
|
||||||
void LoadDefault(bool defline=true);
|
void LoadDefault(bool defline = true, agi::fs::path const& style_catalog_file = agi::fs::path());
|
||||||
/// Attach a file to the ass file
|
/// Attach a file to the ass file
|
||||||
void InsertAttachment(agi::fs::path const& filename);
|
void InsertAttachment(agi::fs::path const& filename);
|
||||||
/// Get the names of all of the styles available
|
/// Get the names of all of the styles available
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "ass_style_storage.h"
|
#include "ass_style_storage.h"
|
||||||
|
|
||||||
|
#include "ass_file.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
|
|
||||||
#include <libaegisub/fs.h>
|
#include <libaegisub/fs.h>
|
||||||
|
@ -96,3 +97,16 @@ AssStyle *AssStyleStorage::GetStyle(std::string const& name) {
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssStyleStorage::ReplaceIntoFile(AssFile &file) {
|
||||||
|
std::vector<AssStyle*> replaced_styles;
|
||||||
|
for (auto const& s : style) {
|
||||||
|
AssStyle *existing_style = file.GetStyle(s->name);
|
||||||
|
if (existing_style)
|
||||||
|
replaced_styles.push_back(existing_style);
|
||||||
|
file.Styles.push_back(*new AssStyle(*s));
|
||||||
|
}
|
||||||
|
for (auto s : replaced_styles)
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class AssFile;
|
||||||
class AssStyle;
|
class AssStyle;
|
||||||
|
|
||||||
class AssStyleStorage {
|
class AssStyleStorage {
|
||||||
|
@ -77,4 +78,8 @@ public:
|
||||||
/// Load stored styles from a file
|
/// Load stored styles from a file
|
||||||
/// @param filename Catalog filename. Does not have to exist.
|
/// @param filename Catalog filename. Does not have to exist.
|
||||||
void Load(agi::fs::path const& filename);
|
void Load(agi::fs::path const& filename);
|
||||||
|
|
||||||
|
/// Insert all styles into a file, replacing existing styles with the same names
|
||||||
|
/// @param file File to replace styles in
|
||||||
|
void ReplaceIntoFile(AssFile &file);
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_info.h"
|
#include "ass_info.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
|
#include "ass_style_storage.h"
|
||||||
#include "charset_detect.h"
|
#include "charset_detect.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "command/command.h"
|
#include "command/command.h"
|
||||||
|
@ -290,7 +291,7 @@ void SubsController::Close() {
|
||||||
filename.clear();
|
filename.clear();
|
||||||
AssFile blank;
|
AssFile blank;
|
||||||
blank.swap(*context->ass);
|
blank.swap(*context->ass);
|
||||||
context->ass->LoadDefault();
|
context->ass->LoadDefault(true, config::path->Decode("?user/catalog/Default.sty"));
|
||||||
context->ass->Commit("", AssFile::COMMIT_NEW);
|
context->ass->Commit("", AssFile::COMMIT_NEW);
|
||||||
FileOpen(filename);
|
FileOpen(filename);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue