Make the style manager dialog select the new styles when copying styles between the current script and storage, and fix a few cases where buttons were incorrectly enabled or disabled. Updates #1186.

Originally committed to SVN as r4244.
This commit is contained in:
Thomas Goyne 2010-04-24 21:48:06 +00:00
parent de459275a1
commit 5f82c5bb02

View file

@ -35,8 +35,6 @@
///
////////////
// Includes
#include "config.h"
#ifndef AGI_PRE
@ -226,10 +224,7 @@ DialogStyleManager::DialogStyleManager (wxWindow *parent,SubtitlesGrid *_grid)
UpdateMoveButtons();
}
/// @brief Destructor
///
DialogStyleManager::~DialogStyleManager() {
int sel = CatalogList->GetSelection();
if (sel != wxNOT_FOUND) {
@ -241,12 +236,8 @@ DialogStyleManager::~DialogStyleManager() {
Store.Clear();
}
/// @brief Loads the catalog
///
/// @brief Load the catalog of stored styles
void DialogStyleManager::LoadCatalog () {
// Clear
CatalogList->Clear();
// Create catalog if it doesn't exist
@ -288,51 +279,36 @@ void DialogStyleManager::LoadCatalog () {
}
}
/// @brief Loads style list
/// @param subs
///
/// @brief Load the list of styles from a subtitle file
void DialogStyleManager::LoadCurrentStyles (AssFile *subs) {
using std::list;
AssStyle *style;
// Reset
CurrentList->Clear();
styleMap.clear();
// Add styles
for (list<AssEntry*>::iterator cur=subs->Line.begin();cur!=subs->Line.end();cur++) {
style = AssEntry::GetAsStyle(*cur);
if (style) {
if (style->Valid) {
CurrentList->Append(style->name);
styleMap.push_back(style);
}
if (style && style->Valid) {
CurrentList->Append(style->name);
styleMap.push_back(style);
}
}
UpdateMoveButtons();
}
/// @brief DOCME
///
/// @brief Load the list of styles from the currently active storage
void DialogStyleManager::LoadStorageStyles () {
using std::list;
AssStyle *style;
// Reset
StorageList->Clear();
styleStorageMap.clear();
// Add styles
for (list<AssStyle*>::iterator cur=Store.style.begin();cur!=Store.style.end();cur++) {
style = *cur;
if (style) {
if (style->Valid) {
StorageList->Append(style->name);
styleStorageMap.push_back(style);
}
AssStyle *style = *cur;
if (style && style->Valid) {
StorageList->Append(style->name);
styleStorageMap.push_back(style);
}
}
@ -342,11 +318,7 @@ void DialogStyleManager::LoadStorageStyles () {
UpdateMoveButtons();
}
/// @brief Enables or disables storage actions
/// @param state
///
void DialogStyleManager::StorageActions (bool state) {
StorageList->Enable(state);
MoveToLocal->Enable(state);
@ -362,7 +334,6 @@ void DialogStyleManager::StorageActions (bool state) {
UpdateMoveButtons();
}
///////////////
// Event table
BEGIN_EVENT_TABLE(DialogStyleManager, wxDialog)
@ -401,21 +372,14 @@ END_EVENT_TABLE()
//////////
// Events
/// @brief Close
/// @param event
///
void DialogStyleManager::OnClose (wxCommandEvent &event) {
void DialogStyleManager::OnClose (wxCommandEvent &) {
GetPosition(&lastx, &lasty);
Close();
}
/// @brief Change catalog entry
/// @param event
///
void DialogStyleManager::OnChangeCatalog (wxCommandEvent &event) {
void DialogStyleManager::OnChangeCatalog (wxCommandEvent &) {
int sel = CatalogList->GetSelection();
if (sel != wxNOT_FOUND) {
StorageActions(true);
@ -430,13 +394,8 @@ void DialogStyleManager::OnChangeCatalog (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief New catalog entry
/// @param event
/// @return
///
void DialogStyleManager::OnCatalogNew (wxCommandEvent &event) {
/// @brief New catalog entry button
void DialogStyleManager::OnCatalogNew (wxCommandEvent &) {
wxString name = wxGetTextFromUser(_("New storage name:"), _("New catalog entry"), _T(""), this);
if (!name.empty()) {
// Remove bad characters from the name
@ -481,12 +440,8 @@ void DialogStyleManager::OnCatalogNew (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Catalog delete
/// @param event
///
void DialogStyleManager::OnCatalogDelete (wxCommandEvent &event) {
void DialogStyleManager::OnCatalogDelete (wxCommandEvent &) {
int sel = CatalogList->GetSelection();
if (sel != wxNOT_FOUND) {
wxString name = CatalogList->GetString(sel);
@ -502,58 +457,37 @@ void DialogStyleManager::OnCatalogDelete (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Edit style on storage
/// @param event
///
void DialogStyleManager::OnStorageEdit (wxCommandEvent &event) {
void DialogStyleManager::OnStorageEdit (wxCommandEvent &) {
wxArrayInt selections;
int n = StorageList->GetSelections(selections);
AssStyle *temp;
if (n == 1) {
temp = styleStorageMap.at(selections[0]);
DialogStyleEditor editor(this,temp,grid,false,&Store);
int modified = editor.ShowModal();
if (modified) {
//LoadStorageStyles();
StorageList->SetString(selections[0],temp->name);
AssStyle *selStyle = styleStorageMap[selections[0]];
DialogStyleEditor editor(this,selStyle,grid,false,&Store);
if (editor.ShowModal()) {
StorageList->SetString(selections[0],selStyle->name);
Store.Save(CatalogList->GetString(CatalogList->GetSelection()));
}
}
else if (n > 1) {
}
UpdateMoveButtons();
}
/// @brief Edit style on current script
/// @param event
///
void DialogStyleManager::OnCurrentEdit (wxCommandEvent &event) {
void DialogStyleManager::OnCurrentEdit (wxCommandEvent &) {
wxArrayInt selections;
int n = CurrentList->GetSelections(selections);
AssStyle *temp;
if (n == 1) {
temp = styleMap.at(selections[0]);
DialogStyleEditor editor(this,temp,grid,true,&Store);
int modified = editor.ShowModal();
if (modified) {
CurrentList->SetString(selections[0],temp->name);
AssStyle *selStyle = styleMap[selections[0]];
DialogStyleEditor editor(this,selStyle,grid,false,&Store);
if (editor.ShowModal()) {
CurrentList->SetString(selections[0],selStyle->name);
}
}
else if (n > 1) {
}
UpdateMoveButtons();
}
/// @brief Selection on current script changed
/// @param event
///
void DialogStyleManager::OnCurrentChange (wxCommandEvent &event) {
void DialogStyleManager::OnCurrentChange (wxCommandEvent &) {
wxArrayInt selections;
int n = CurrentList->GetSelections(selections);
@ -564,12 +498,8 @@ void DialogStyleManager::OnCurrentChange (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Selection on storage changed
/// @param event
///
void DialogStyleManager::OnStorageChange (wxCommandEvent &event) {
void DialogStyleManager::OnStorageChange (wxCommandEvent &) {
wxArrayInt selections;
int n = StorageList->GetSelections(selections);
@ -580,29 +510,25 @@ void DialogStyleManager::OnStorageChange (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Copy to Storage
/// @param event
/// @return
///
void DialogStyleManager::OnCopyToStorage (wxCommandEvent &event) {
void DialogStyleManager::OnCopyToStorage (wxCommandEvent &) {
using std::list;
// Check if there is actually a storage
if (!StorageNew->IsEnabled()) {
return;
}
if (!StorageNew->IsEnabled()) return;
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 (std::list<AssStyle *>::iterator style = Store.style.begin(); style != Store.style.end(); ++style) {
for (list<AssStyle *>::iterator style = Store.style.begin(); style != Store.style.end(); ++style) {
if ((*style)->name.CmpNoCase(styleName) == 0) {
addStyle = false;
if (wxYES == wxMessageBox(wxString::Format(_T("There is already a style with the name \"%s\" on the current storage. Proceed and overwrite anyway?"),styleName.c_str()), _T("Style name collision."), wxYES_NO)) {
**style = *styleMap.at(selections[i]);
copied.push_back(styleName);
}
break;
}
@ -610,19 +536,22 @@ void DialogStyleManager::OnCopyToStorage (wxCommandEvent &event) {
if (addStyle) {
AssStyle *temp = new AssStyle(*styleMap.at(selections[i]));
Store.style.push_back(temp);
copied.push_back(styleName);
}
}
Store.Save(CatalogList->GetString(CatalogList->GetSelection()));
LoadStorageStyles();
UpdateMoveButtons();
for (list<wxString>::iterator name = copied.begin(); name != copied.end(); ++name) {
StorageList->SetStringSelection(*name, true);
}
wxCommandEvent dummy;
OnStorageChange(dummy);
}
/// @brief Copy to Current
/// @param event
///
void DialogStyleManager::OnCopyToCurrent (wxCommandEvent &event) {
void DialogStyleManager::OnCopyToCurrent (wxCommandEvent &) {
using std::list;
list<wxString> copied;
wxArrayInt selections;
int n = StorageList->GetSelections(selections);
for (int i = 0; i < n; i++) {
@ -634,6 +563,7 @@ void DialogStyleManager::OnCopyToCurrent (wxCommandEvent &event) {
addStyle = false;
if (wxYES == wxMessageBox(wxString::Format(_T("There is already a style with the name \"%s\" on the current script. Proceed and overwrite anyway?"),styleName.c_str()), _T("Style name collision."), wxYES_NO)) {
**style = *styleStorageMap.at(selections[i]);
copied.push_back(styleName);
}
break;
}
@ -641,20 +571,21 @@ void DialogStyleManager::OnCopyToCurrent (wxCommandEvent &event) {
if (addStyle) {
AssStyle *temp = new AssStyle(*styleStorageMap.at(selections[i]));
AssFile::top->InsertStyle(temp);
copied.push_back(styleName);
}
}
LoadCurrentStyles(AssFile::top);
for (list<wxString>::iterator name = copied.begin(); name != copied.end(); ++name) {
CurrentList->SetStringSelection(*name, true);
}
grid->ass->FlagAsModified(_("style copy"));
grid->CommitChanges();
UpdateMoveButtons();
wxCommandEvent dummy;
OnCurrentChange(dummy);
}
/// @brief Storage make copy
/// @param event
///
void DialogStyleManager::OnStorageCopy (wxCommandEvent &event) {
void DialogStyleManager::OnStorageCopy (wxCommandEvent &) {
wxArrayInt selections;
StorageList->GetSelections(selections);
if (selections.size() == 0) return;
@ -676,12 +607,8 @@ void DialogStyleManager::OnStorageCopy (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Current make copy
/// @param event
///
void DialogStyleManager::OnCurrentCopy (wxCommandEvent &event) {
void DialogStyleManager::OnCurrentCopy (wxCommandEvent &) {
wxArrayInt selections;
CurrentList->GetSelections(selections);
if (selections.size() == 0) return;
@ -705,12 +632,9 @@ void DialogStyleManager::OnCurrentCopy (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Copy to clipboard
/// @param list
/// @param v
///
void DialogStyleManager::CopyToClipboard (wxListBox *list, std::vector<AssStyle*> v) {
wxString data = _T("");
AssStyle *s;
@ -731,7 +655,6 @@ void DialogStyleManager::CopyToClipboard (wxListBox *list, std::vector<AssStyle*
}
/// @brief Paste from clipboard
///
void DialogStyleManager::PasteToCurrent() {
wxString data = _T("");
@ -772,7 +695,6 @@ void DialogStyleManager::PasteToCurrent() {
}
/// @brief DOCME
///
void DialogStyleManager::PasteToStorage() {
wxString data = _T("");
@ -808,14 +730,11 @@ void DialogStyleManager::PasteToStorage() {
delete s;
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
}
}
}
/// @brief Storage new
/// @param event
///
void DialogStyleManager::OnStorageNew (wxCommandEvent &event) {
void DialogStyleManager::OnStorageNew (wxCommandEvent &) {
AssStyle *temp = new AssStyle;
DialogStyleEditor editor(this,temp,grid,false,&Store,true);
@ -829,12 +748,8 @@ void DialogStyleManager::OnStorageNew (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Current new
/// @param event
///
void DialogStyleManager::OnCurrentNew (wxCommandEvent &event) {
void DialogStyleManager::OnCurrentNew (wxCommandEvent &) {
AssStyle *temp = new AssStyle;
DialogStyleEditor editor(this,temp,grid,true,&Store,true);
@ -847,12 +762,8 @@ void DialogStyleManager::OnCurrentNew (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Storage delete
/// @param event
///
void DialogStyleManager::OnStorageDelete (wxCommandEvent &event) {
void DialogStyleManager::OnStorageDelete (wxCommandEvent &) {
wxArrayInt selections;
int n = StorageList->GetSelections(selections);
@ -877,18 +788,15 @@ void DialogStyleManager::OnStorageDelete (wxCommandEvent &event) {
// Set buttons
MoveToLocal->Enable(false);
StorageEdit->Enable(false);
StorageCopy->Enable(false);
StorageDelete->Enable(false);
}
UpdateMoveButtons();
}
/// @brief Current delete
/// @param event
///
void DialogStyleManager::OnCurrentDelete (wxCommandEvent &event) {
void DialogStyleManager::OnCurrentDelete (wxCommandEvent &) {
wxArrayInt selections;
int n = CurrentList->GetSelections(selections);
@ -912,6 +820,7 @@ void DialogStyleManager::OnCurrentDelete (wxCommandEvent &event) {
// Set buttons
MoveToStorage->Enable(false);
CurrentEdit->Enable(false);
CurrentCopy->Enable(false);
CurrentDelete->Enable(false);
@ -921,13 +830,8 @@ void DialogStyleManager::OnCurrentDelete (wxCommandEvent &event) {
UpdateMoveButtons();
}
/// @brief Import styles from another script
/// @param event
/// @return
///
void DialogStyleManager::OnCurrentImport(wxCommandEvent &event) {
void DialogStyleManager::OnCurrentImport(wxCommandEvent &) {
// Get file name
wxString path = Options.AsText(_T("Last open subtitles path"));
wxString filename = wxFileSelector(_("Open subtitles file"),path,_T(""),_T(""),AssFile::GetWildcardList(0),wxFD_OPEN | wxFD_FILE_MUST_EXIST);
@ -992,10 +896,7 @@ void DialogStyleManager::OnCurrentImport(wxCommandEvent &event) {
}
}
/// @brief Update move buttons
///
/// @brief Enable or disable the move buttons
void DialogStyleManager::UpdateMoveButtons() {
// Get storage selection
wxArrayInt sels;
@ -1010,14 +911,10 @@ void DialogStyleManager::UpdateMoveButtons() {
// Check if selection is continuous
bool contStor = true;
if (n) {
int last = sels[0];
for (int i=1;i<n;i++) {
if (sels[i] != last+1) {
contStor = false;
break;
}
last = sels[i];
for (int i = 1; i < n; ++i) {
if (sels[i] != sels[i-1]+1) {
contStor = false;
break;
}
}
@ -1033,14 +930,10 @@ void DialogStyleManager::UpdateMoveButtons() {
// Check if selection is continuous
bool contCurr = true;
if (n) {
int last = sels[0];
for (int i=1;i<n;i++) {
if (sels[i] != last+1) {
contCurr = false;
break;
}
last = sels[i];
for (int i = 1; i < n; ++i) {
if (sels[i] != sels[i-1]+1) {
contCurr = false;
break;
}
}
@ -1057,64 +950,20 @@ void DialogStyleManager::UpdateMoveButtons() {
CurrentSort->Enable(itemsCurr > 1);
}
/// @brief Move events
/// @param event
///
void DialogStyleManager::OnStorageMoveUp (wxCommandEvent &event) { MoveStyles(true,0); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnStorageMoveTop (wxCommandEvent &event) { MoveStyles(true,1); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnStorageMoveDown (wxCommandEvent &event) { MoveStyles(true,2); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnStorageMoveBottom (wxCommandEvent &event) { MoveStyles(true,3); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnStorageSort (wxCommandEvent &event) { MoveStyles(true,4); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnCurrentMoveUp (wxCommandEvent &event) { MoveStyles(false,0); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnCurrentMoveTop (wxCommandEvent &event) { MoveStyles(false,1); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnCurrentMoveDown (wxCommandEvent &event) { MoveStyles(false,2); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnCurrentMoveBottom (wxCommandEvent &event) { MoveStyles(false,3); }
/// @brief DOCME
/// @param event
///
void DialogStyleManager::OnCurrentSort (wxCommandEvent &event) { MoveStyles(false,4); }
void DialogStyleManager::OnStorageMoveUp (wxCommandEvent &) { MoveStyles(true,0); }
void DialogStyleManager::OnStorageMoveTop (wxCommandEvent &) { MoveStyles(true,1); }
void DialogStyleManager::OnStorageMoveDown (wxCommandEvent &) { MoveStyles(true,2); }
void DialogStyleManager::OnStorageMoveBottom (wxCommandEvent &) { MoveStyles(true,3); }
void DialogStyleManager::OnStorageSort (wxCommandEvent &) { MoveStyles(true,4); }
void DialogStyleManager::OnCurrentMoveUp (wxCommandEvent &) { MoveStyles(false,0); }
void DialogStyleManager::OnCurrentMoveTop (wxCommandEvent &) { MoveStyles(false,1); }
void DialogStyleManager::OnCurrentMoveDown (wxCommandEvent &) { MoveStyles(false,2); }
void DialogStyleManager::OnCurrentMoveBottom (wxCommandEvent &) { MoveStyles(false,3); }
void DialogStyleManager::OnCurrentSort (wxCommandEvent &) { MoveStyles(false,4); }
/// @brief Move function
/// @param storage
/// @param type
/// @return
///
void DialogStyleManager::MoveStyles(bool storage, int type) {
// Variables
AssFile *subs = AssFile::top;
@ -1253,11 +1102,7 @@ void DialogStyleManager::MoveStyles(bool storage, int type) {
UpdateMoveButtons();
}
/// @brief Keydown event
/// @param event
///
void DialogStyleManager::OnKeyDown(wxKeyEvent &event) {
wxCommandEvent evt;
switch(event.GetKeyCode()) {
@ -1306,7 +1151,6 @@ void DialogStyleManager::OnKeyDown(wxKeyEvent &event) {
}
break;
}
}
@ -1320,7 +1164,6 @@ int DialogStyleManager::lasty = -1;
/// @brief DialogStyleManagerEvent stuff
/// @param ctrl
///
DialogStyleManagerEvent::DialogStyleManagerEvent(DialogStyleManager *ctrl) {
control = ctrl;
}
@ -1328,14 +1171,7 @@ BEGIN_EVENT_TABLE(DialogStyleManagerEvent, wxEvtHandler)
EVT_KEY_DOWN(DialogStyleManagerEvent::OnKeyDown)
END_EVENT_TABLE()
/// @brief DOCME
/// @param event
///
void DialogStyleManagerEvent::OnKeyDown(wxKeyEvent &event) {
control->OnKeyDown(event); //we need to access controls, so rather than make the controls public...
}