Separate UI state info from functional ASS info headers a bit
Prefix script info entries that are just storing Aegisub UI state with "Aegisub ", and use a separate AssFile method to get/set them.
This commit is contained in:
parent
62114d45f5
commit
1cdd461023
6 changed files with 30 additions and 12 deletions
|
@ -136,6 +136,21 @@ int AssFile::GetScriptInfoAsInt(std::string const& key) const {
|
||||||
return atoi(GetScriptInfo(key).c_str());
|
return atoi(GetScriptInfo(key).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string AssFile::GetUIState(std::string const& key) const {
|
||||||
|
auto value = GetScriptInfo("Aegisub " + key);
|
||||||
|
if (value.empty())
|
||||||
|
value = GetScriptInfo(key);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AssFile::GetUIStateAsInt(std::string const& key) const {
|
||||||
|
return atoi(GetUIState(key).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssFile::SaveUIState(std::string const& key, std::string const& value) {
|
||||||
|
SetScriptInfo("Aegisub " + key, value);
|
||||||
|
}
|
||||||
|
|
||||||
void AssFile::SetScriptInfo(std::string const& key, std::string const& value) {
|
void AssFile::SetScriptInfo(std::string const& key, std::string const& value) {
|
||||||
for (auto info : Line | agi::of_type<AssInfo>()) {
|
for (auto info : Line | agi::of_type<AssInfo>()) {
|
||||||
if (boost::iequals(key, info->Key())) {
|
if (boost::iequals(key, info->Key())) {
|
||||||
|
|
|
@ -95,6 +95,9 @@ public:
|
||||||
std::string GetScriptInfo(std::string const& key) const;
|
std::string GetScriptInfo(std::string const& key) const;
|
||||||
/// Set the value of a [Script Info] key. Adds it if it doesn't exist.
|
/// Set the value of a [Script Info] key. Adds it if it doesn't exist.
|
||||||
void SetScriptInfo(std::string const& key, std::string const& value);
|
void SetScriptInfo(std::string const& key, std::string const& value);
|
||||||
|
std::string GetUIState(std::string const& key) const;
|
||||||
|
int GetUIStateAsInt(std::string const& key) const;
|
||||||
|
void SaveUIState(std::string const& key, std::string const& value);
|
||||||
|
|
||||||
/// Type of changes made in a commit
|
/// Type of changes made in a commit
|
||||||
enum CommitType {
|
enum CommitType {
|
||||||
|
|
|
@ -187,7 +187,7 @@ void BaseGrid::OnSubtitlesOpen() {
|
||||||
UpdateMaps();
|
UpdateMaps();
|
||||||
|
|
||||||
if (GetRows()) {
|
if (GetRows()) {
|
||||||
int row = context->ass->GetScriptInfoAsInt("Active Line");
|
int row = context->ass->GetUIStateAsInt("Active Line");
|
||||||
if (row < 0 || row >= GetRows())
|
if (row < 0 || row >= GetRows())
|
||||||
row = 0;
|
row = 0;
|
||||||
|
|
||||||
|
@ -195,15 +195,15 @@ void BaseGrid::OnSubtitlesOpen() {
|
||||||
SelectRow(row);
|
SelectRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollTo(context->ass->GetScriptInfoAsInt("Scroll Position"));
|
ScrollTo(context->ass->GetUIStateAsInt("Scroll Position"));
|
||||||
|
|
||||||
EndBatch();
|
EndBatch();
|
||||||
SetColumnWidths();
|
SetColumnWidths();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseGrid::OnSubtitlesSave() {
|
void BaseGrid::OnSubtitlesSave() {
|
||||||
context->ass->SetScriptInfo("Scroll Position", std::to_string(yPos));
|
context->ass->SaveUIState("Scroll Position", std::to_string(yPos));
|
||||||
context->ass->SetScriptInfo("Active Line", std::to_string(GetDialogueIndex(active_line)));
|
context->ass->SaveUIState("Active Line", std::to_string(GetDialogueIndex(active_line)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseGrid::OnShowColMenu(wxCommandEvent &event) {
|
void BaseGrid::OnShowColMenu(wxCommandEvent &event) {
|
||||||
|
|
|
@ -616,9 +616,9 @@ void FrameMain::OnSubtitlesOpen() {
|
||||||
if (videoChanged) {
|
if (videoChanged) {
|
||||||
context->videoController->SetVideo(video);
|
context->videoController->SetVideo(video);
|
||||||
if (context->videoController->IsLoaded()) {
|
if (context->videoController->IsLoaded()) {
|
||||||
context->videoController->JumpToFrame(context->ass->GetScriptInfoAsInt("Video Position"));
|
context->videoController->JumpToFrame(context->ass->GetUIStateAsInt("Video Position"));
|
||||||
|
|
||||||
std::string arString = context->ass->GetScriptInfo("Video Aspect Ratio");
|
std::string arString = context->ass->GetUIState("Video Aspect Ratio");
|
||||||
if (boost::starts_with(arString, "c")) {
|
if (boost::starts_with(arString, "c")) {
|
||||||
double ar = 0.;
|
double ar = 0.;
|
||||||
agi::util::try_parse(arString.substr(1), &ar);
|
agi::util::try_parse(arString.substr(1), &ar);
|
||||||
|
@ -631,7 +631,7 @@ void FrameMain::OnSubtitlesOpen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
double videoZoom = 0.;
|
double videoZoom = 0.;
|
||||||
if (agi::util::try_parse(context->ass->GetScriptInfo("Video Zoom Percent"), &videoZoom))
|
if (agi::util::try_parse(context->ass->GetUIState("Video Zoom Percent"), &videoZoom))
|
||||||
context->videoDisplay->SetZoom(videoZoom);
|
context->videoDisplay->SetZoom(videoZoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,8 +248,8 @@ void VideoContext::OnSubtitlesSave() {
|
||||||
|
|
||||||
if (!IsLoaded()) {
|
if (!IsLoaded()) {
|
||||||
context->ass->SetScriptInfo("Video File", "");
|
context->ass->SetScriptInfo("Video File", "");
|
||||||
context->ass->SetScriptInfo("Video Aspect Ratio", "");
|
context->ass->SaveUIState("Video Aspect Ratio", "");
|
||||||
context->ass->SetScriptInfo("Video Position", "");
|
context->ass->SaveUIState("Video Position", "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,8 +261,8 @@ void VideoContext::OnSubtitlesSave() {
|
||||||
|
|
||||||
context->ass->SetScriptInfo("Video File", config::path->MakeRelative(video_filename, "?script").generic_string());
|
context->ass->SetScriptInfo("Video File", config::path->MakeRelative(video_filename, "?script").generic_string());
|
||||||
context->ass->SetScriptInfo("YCbCr Matrix", video_provider->GetColorSpace());
|
context->ass->SetScriptInfo("YCbCr Matrix", video_provider->GetColorSpace());
|
||||||
context->ass->SetScriptInfo("Video Aspect Ratio", ar);
|
context->ass->SaveUIState("Video Aspect Ratio", ar);
|
||||||
context->ass->SetScriptInfo("Video Position", std::to_string(frame_n));
|
context->ass->SaveUIState("Video Position", std::to_string(frame_n));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoContext::JumpToFrame(int n) {
|
void VideoContext::JumpToFrame(int n) {
|
||||||
|
|
|
@ -435,5 +435,5 @@ void VideoDisplay::Unload() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoDisplay::OnSubtitlesSave() {
|
void VideoDisplay::OnSubtitlesSave() {
|
||||||
con->ass->SetScriptInfo("Video Zoom Percent", std::to_string(zoomValue));
|
con->ass->SaveUIState("Video Zoom Percent", std::to_string(zoomValue));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue