Added an "Import from script..." button to Styles Manager, to import styles directly from other subtitle files.

Originally committed to SVN as r625.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-26 04:48:53 +00:00
parent be8ebd8faa
commit 95059b79bf
8 changed files with 96 additions and 14 deletions

View file

@ -71,7 +71,7 @@ AssFile::~AssFile() {
///////////////////// /////////////////////
// Load generic subs // Load generic subs
void AssFile::Load (const wxString _filename,const wxString charset) { void AssFile::Load (const wxString _filename,const wxString charset,bool addToRecent) {
bool ok = true; bool ok = true;
try { try {
@ -137,7 +137,9 @@ void AssFile::Load (const wxString _filename,const wxString charset) {
AddComment(_T("Script generated by Aegisub ") + GetAegisubLongVersionString()); AddComment(_T("Script generated by Aegisub ") + GetAegisubLongVersionString());
AddComment(_T("http://www.aegisub.net")); AddComment(_T("http://www.aegisub.net"));
SetScriptInfo(_T("ScriptType"),_T("v4.00+")); SetScriptInfo(_T("ScriptType"),_T("v4.00+"));
AddToRecent(_filename);
// Add to recent
if (addToRecent) AddToRecent(_filename);
} }
@ -768,6 +770,16 @@ void AssFile::AddToRecent(wxString file) {
} }
///////////////////////////////
// List of supported wildcards
wxString AssFile::GetWildcardList(int mode) {
if (mode == 0) return _T("All Supported Types (*.ass,*.ssa,*.srt,*.txt,*.mkv,*.mks,*.mka)|*.ass;*.ssa;*.srt;*.txt;*.mkv;*.mks;*.mka|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt|Matroska (*.mkv,*.mks,*.mka)|*.mkv;*.mks;*.mka");
else if (mode == 1) return _T("Advanced Substation Alpha (*.ass)|*.ass");
else if (mode == 2) return _T("All Supported Types (*.ass,*.ssa,*.srt,*.txt,*.mkv,*.mks,*.mka)|*.ass;*.ssa;*.srt;*.txt|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt");
else return _T("");
}
//////////////////////////////////////////// ////////////////////////////////////////////
// Compress/decompress for storage on stack // Compress/decompress for storage on stack
void AssFile::CompressForStack(bool compress) { void AssFile::CompressForStack(bool compress) {

View file

@ -89,12 +89,13 @@ public:
wxArrayString GetStyles(); // Gets a list of all styles available wxArrayString GetStyles(); // Gets a list of all styles available
AssStyle *GetStyle(wxString name); // Gets style by its name AssStyle *GetStyle(wxString name); // Gets style by its name
wxString GetString(); wxString GetString(); // Returns the whole file as a single string
void Load(wxString file,wxString charset=_T("")); // Load from a file void Load(wxString file,wxString charset=_T(""),bool addToRecent=true); // Load from a file
void Save(wxString file,bool setfilename=false,bool addToRecent=true,const wxString encoding=_T("")); // Save to a file. Pass true to second argument if this isn't a copy void Save(wxString file,bool setfilename=false,bool addToRecent=true,const wxString encoding=_T("")); // Save to a file. Pass true to second argument if this isn't a copy
void Export(wxString file); // Saves exported copy, with effects applied void Export(wxString file); // Saves exported copy, with effects applied
void AddToRecent(wxString file); // Adds file name to list of recently opened files void AddToRecent(wxString file); // Adds file name to list of recently opened files
bool CanSave(); // Return true if the file can be saved in its current format bool CanSave(); // Returns true if the file can be saved in its current format
static wxString GetWildcardList(int mode); // Returns the list of wildcards supported (0 = open, 1 = save, 2 = export)
void GetResolution(int &w,int &h); // Get resolution void GetResolution(int &w,int &h); // Get resolution
int GetScriptInfoAsInt(const wxString key); // Returns the value in a [Script Info] key as int. int GetScriptInfoAsInt(const wxString key); // Returns the value in a [Script Info] key as int.

View file

@ -46,6 +46,7 @@ Please visit http://aegisub.net to download latest version
- Added two options ("Audio HD Cache Location" and "Audio HD Cache Name") that allows you to specify where to keep the audio cache. (AMZ) - Added two options ("Audio HD Cache Location" and "Audio HD Cache Name") that allows you to specify where to keep the audio cache. (AMZ)
- Flexibible audio cache names now allow you to have more than one copy of Aegisub open with audio loaded to HD cache. (AMZ) - Flexibible audio cache names now allow you to have more than one copy of Aegisub open with audio loaded to HD cache. (AMZ)
- Improved Splash Screen behavior to show up even if the program is frozen loading subtitles, and to center on the current display. (AMZ) - Improved Splash Screen behavior to show up even if the program is frozen loading subtitles, and to center on the current display. (AMZ)
- Added an "Import from script..." button to Styles Manager, to import styles directly from other subtitle files. (AMZ)
= 1.10 beta - 2006.08.07 =========================== = 1.10 beta - 2006.08.07 ===========================

View file

@ -183,7 +183,7 @@ END_EVENT_TABLE()
void DialogExport::OnProcess(wxCommandEvent &event) { void DialogExport::OnProcess(wxCommandEvent &event) {
// Get destination // Get destination
//wxString filename = wxFileSelector(_("Export subtitles file"),_T(""),_T(""),_T(""),_T("All Supported Types (*.ass,*.ssa,*.srt,*.prs)|*.ass;*.ssa;*.srt;*.prs|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt|Pre-Rendered Subtitles (*.prs)|*.prs"),wxSAVE | wxOVERWRITE_PROMPT,this); //wxString filename = wxFileSelector(_("Export subtitles file"),_T(""),_T(""),_T(""),_T("All Supported Types (*.ass,*.ssa,*.srt,*.prs)|*.ass;*.ssa;*.srt;*.prs|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt|Pre-Rendered Subtitles (*.prs)|*.prs"),wxSAVE | wxOVERWRITE_PROMPT,this);
wxString filename = wxFileSelector(_("Export subtitles file"),_T(""),_T(""),_T(""),_T("All Supported Types (*.ass,*.ssa,*.srt,*.txt)|*.ass;*.ssa;*.srt;*.txt|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt"),wxSAVE | wxOVERWRITE_PROMPT,this); wxString filename = wxFileSelector(_("Export subtitles file"),_T(""),_T(""),_T(""),AssFile::GetWildcardList(2),wxSAVE | wxOVERWRITE_PROMPT,this);
if (filename.empty()) return; if (filename.empty()) return;
// Add filters // Add filters

View file

@ -37,6 +37,8 @@
//////////// ////////////
// Includes // Includes
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/filedlg.h>
#include <wx/choicdlg.h>
#include "dialog_style_manager.h" #include "dialog_style_manager.h"
#include "dialog_style_editor.h" #include "dialog_style_editor.h"
#include "ass_style.h" #include "ass_style.h"
@ -101,6 +103,7 @@ DialogStyleManager::DialogStyleManager (wxWindow *parent,SubtitlesGrid *_grid)
CurrentBox->Add(CurrentList,0,wxEXPAND | wxALL,0); CurrentBox->Add(CurrentList,0,wxEXPAND | wxALL,0);
CurrentBox->Add(MoveToStorage,0,wxEXPAND | wxALL,0); CurrentBox->Add(MoveToStorage,0,wxEXPAND | wxALL,0);
CurrentBox->Add(CurrentButtons,0,wxEXPAND | wxALL,0); CurrentBox->Add(CurrentButtons,0,wxEXPAND | wxALL,0);
CurrentBox->Add(new wxButton(this, BUTTON_CURRENT_IMPORT, _("Import from script...")),0,wxEXPAND);
MoveToStorage->Disable(); MoveToStorage->Disable();
CurrentEdit->Disable(); CurrentEdit->Disable();
CurrentCopy->Disable(); CurrentCopy->Disable();
@ -108,8 +111,8 @@ DialogStyleManager::DialogStyleManager (wxWindow *parent,SubtitlesGrid *_grid)
// General layout // General layout
wxSizer *StylesSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *StylesSizer = new wxBoxSizer(wxHORIZONTAL);
StylesSizer->Add(StorageBox,0,wxRIGHT,5); StylesSizer->Add(StorageBox,0,wxRIGHT | wxEXPAND,5);
StylesSizer->Add(CurrentBox,0,wxLEFT,0); StylesSizer->Add(CurrentBox,0,wxLEFT | wxEXPAND,0);
wxButton *CloseButton = new wxButton(this, wxID_CLOSE, _T(""), wxDefaultPosition, wxSize(100,25)); wxButton *CloseButton = new wxButton(this, wxID_CLOSE, _T(""), wxDefaultPosition, wxSize(100,25));
MainSizer = new wxBoxSizer(wxVERTICAL); MainSizer = new wxBoxSizer(wxVERTICAL);
MainSizer->Add(CatalogBox,0,wxEXPAND | wxLEFT | wxRIGHT | wxTOP,5); MainSizer->Add(CatalogBox,0,wxEXPAND | wxLEFT | wxRIGHT | wxTOP,5);
@ -296,6 +299,7 @@ BEGIN_EVENT_TABLE(DialogStyleManager, wxDialog)
EVT_BUTTON(BUTTON_STORAGE_NEW, DialogStyleManager::OnStorageNew) EVT_BUTTON(BUTTON_STORAGE_NEW, DialogStyleManager::OnStorageNew)
EVT_BUTTON(BUTTON_CURRENT_DELETE, DialogStyleManager::OnCurrentDelete) EVT_BUTTON(BUTTON_CURRENT_DELETE, DialogStyleManager::OnCurrentDelete)
EVT_BUTTON(BUTTON_STORAGE_DELETE, DialogStyleManager::OnStorageDelete) EVT_BUTTON(BUTTON_STORAGE_DELETE, DialogStyleManager::OnStorageDelete)
EVT_BUTTON(BUTTON_CURRENT_IMPORT, DialogStyleManager::OnCurrentImport)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -493,7 +497,7 @@ void DialogStyleManager::OnCopyToCurrent (wxCommandEvent &event) {
int test = CurrentList->FindString(StorageList->GetString(selections[i])); int test = CurrentList->FindString(StorageList->GetString(selections[i]));
bool proceed = test==-1; bool proceed = test==-1;
if (!proceed) { if (!proceed) {
int answer = wxMessageBox(_T("There is already a style with that name on the current script. Proceed anyway?"),_T("Style name collision."),wxYES_NO); int answer = wxMessageBox(wxString::Format(_T("There is already a style with the name \"%s\" on the current script. Proceed anyway?"),StorageList->GetString(selections[i]).c_str()),_T("Style name collision."),wxYES_NO);
if (answer == wxYES) proceed = true; if (answer == wxYES) proceed = true;
} }
@ -647,10 +651,10 @@ void DialogStyleManager::OnCurrentDelete (wxCommandEvent &event) {
AssStyle *temp; AssStyle *temp;
for (int i=0;i<n;i++) { for (int i=0;i<n;i++) {
temp = styleMap.at(selections[i]); temp = styleMap.at(selections[i]);
AssFile::top->Line.remove(temp); grid->ass->Line.remove(temp);
delete temp; delete temp;
} }
LoadCurrentStyles(AssFile::top); LoadCurrentStyles(grid->ass);
// Set buttons // Set buttons
MoveToStorage->Enable(false); MoveToStorage->Enable(false);
@ -663,5 +667,67 @@ void DialogStyleManager::OnCurrentDelete (wxCommandEvent &event) {
} }
/////////////////////////////////////
// Import styles from another script
void DialogStyleManager::OnCurrentImport(wxCommandEvent &event) {
// Get file name
wxString path = Options.AsText(_T("Last open subtitles path"));
wxString filename = wxFileSelector(_("Open subtitles file"),path,_T(""),_T(""),AssFile::GetWildcardList(0),wxOPEN | wxFILE_MUST_EXIST);
if (!filename.IsEmpty()) {
// Save path
wxFileName filepath(filename);
Options.SetText(_T("Last open subtitles path"), filepath.GetPath());
Options.Save();
try {
// Load file
AssFile temp;
temp.Load(filename,_T(""),false);
// Get styles
wxArrayString styles = temp.GetStyles();
if (styles.Count() == 0 || (styles.Count() == 1 && styles[0] == _T("Default"))) {
wxMessageBox(_("There selected file has no available styles."),_("Error Importing Styles"),wxOK);
return;
}
// Get selection
wxArrayInt selections;
int res = wxGetMultipleChoices(selections,_("Choose styles to import:"),_("Import Styles"),styles);
if (res == -1 || selections.Count() == 0) return;
bool modified = false;
// Loop through selection
for (unsigned int i=0;i<selections.Count();i++) {
// Check if there is already a style with that name
int test = CurrentList->FindString(styles[selections[i]]);
if (test != wxNOT_FOUND) {
int answer = wxMessageBox(wxString::Format(_T("There is already a style with the name \"%s\" on the current script. Proceed anyway?"),styles[selections[i]].c_str()),_T("Style name collision."),wxYES_NO);
if (answer != wxYES) continue;
}
// Copy
modified = true;
AssStyle *tempStyle = new AssStyle;
*tempStyle = *temp.GetStyle(styles[selections[i]]);
AssFile::top->InsertStyle(tempStyle);
}
// Update
if (modified) {
LoadCurrentStyles(grid->ass);
grid->ass->FlagAsModified();
grid->CommitChanges();
}
}
catch (...) {
}
}
}
//////////////////
// I have no clue
int DialogStyleManager::lastx = -1; int DialogStyleManager::lastx = -1;
int DialogStyleManager::lasty = -1; int DialogStyleManager::lasty = -1;

View file

@ -106,6 +106,7 @@ public:
void OnCurrentNew (wxCommandEvent &event); void OnCurrentNew (wxCommandEvent &event);
void OnStorageDelete (wxCommandEvent &event); void OnStorageDelete (wxCommandEvent &event);
void OnCurrentDelete (wxCommandEvent &event); void OnCurrentDelete (wxCommandEvent &event);
void OnCurrentImport (wxCommandEvent &event);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
@ -126,6 +127,7 @@ enum {
BUTTON_CURRENT_EDIT, BUTTON_CURRENT_EDIT,
BUTTON_CURRENT_COPY, BUTTON_CURRENT_COPY,
BUTTON_CURRENT_DELETE, BUTTON_CURRENT_DELETE,
BUTTON_CURRENT_IMPORT,
LIST_CATALOG, LIST_CATALOG,
LIST_STORAGE, LIST_STORAGE,
LIST_CURRENT LIST_CURRENT

View file

@ -586,7 +586,7 @@ bool FrameMain::SaveSubtitles(bool saveas,bool withCharset) {
videoBox->videoDisplay->Stop(); videoBox->videoDisplay->Stop();
wxString path = Options.AsText(_T("Last open subtitles path")); wxString path = Options.AsText(_T("Last open subtitles path"));
wxFileName origPath(AssFile::top->filename); wxFileName origPath(AssFile::top->filename);
filename = wxFileSelector(_("Save subtitles file"),path,origPath.GetName() + _T(".ass"),_T("ass"),_T("Advanced Substation Alpha (*.ass)|*.ass"),wxSAVE | wxOVERWRITE_PROMPT,this); filename = wxFileSelector(_("Save subtitles file"),path,origPath.GetName() + _T(".ass"),_T("ass"),AssFile::GetWildcardList(1),wxSAVE | wxOVERWRITE_PROMPT,this);
} }
// Actually save // Actually save

View file

@ -572,7 +572,7 @@ void FrameMain::OnCloseAudio (wxCommandEvent& WXUNUSED(event)) {
// Open subtitles // Open subtitles
void FrameMain::OnOpenSubtitles(wxCommandEvent& WXUNUSED(event)) { void FrameMain::OnOpenSubtitles(wxCommandEvent& WXUNUSED(event)) {
wxString path = Options.AsText(_T("Last open subtitles path")); wxString path = Options.AsText(_T("Last open subtitles path"));
wxString filename = wxFileSelector(_("Open subtitles file"),path,_T(""),_T(""),_T("All Supported Types (*.ass,*.ssa,*.srt,*.txt,*.mkv,*.mks,*.mka)|*.ass;*.ssa;*.srt;*.txt;*.mkv;*.mks;*.mka|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt|Matroska (*.mkv,*.mks,*.mka)|*.mkv;*.mks;*.mka"),wxOPEN | wxFILE_MUST_EXIST); wxString filename = wxFileSelector(_("Open subtitles file"),path,_T(""),_T(""),AssFile::GetWildcardList(0),wxOPEN | wxFILE_MUST_EXIST);
if (!filename.empty()) { if (!filename.empty()) {
LoadSubtitles(filename); LoadSubtitles(filename);
wxFileName filepath(filename); wxFileName filepath(filename);
@ -590,7 +590,7 @@ void FrameMain::OnOpenSubtitlesCharset(wxCommandEvent& WXUNUSED(event)) {
wxString path = Options.AsText(_T("Last open subtitles path")); wxString path = Options.AsText(_T("Last open subtitles path"));
// Get options and load // Get options and load
wxString filename = wxFileSelector(_("Open subtitles file"),path,_T(""),_T(""),_T("All Supported Types (*.ass,*.ssa,*.srt,*.txt,*.mkv,*.mks,*.mka)|*.ass;*.ssa;*.srt;*.txt;*.mkv;*.mks;*.mka|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt|Matroska (*.mkv,*.mks,*.mka)|*.mkv;*.mks;*.mka"),wxOPEN | wxFILE_MUST_EXIST); wxString filename = wxFileSelector(_("Open subtitles file"),path,_T(""),_T(""),AssFile::GetWildcardList(0),wxOPEN | wxFILE_MUST_EXIST);
if (!filename.empty()) { if (!filename.empty()) {
wxString charset = wxGetSingleChoice(_("Choose charset code:"), _("Charset"),choices,this,-1, -1,true,250,200); wxString charset = wxGetSingleChoice(_("Choose charset code:"), _("Charset"),choices,this,-1, -1,true,250,200);
if (!charset.empty()) { if (!charset.empty()) {