From ccabf8ec15858a8a5052e9de54cee9f3f6005fa7 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Tue, 26 Dec 2006 22:28:44 +0000 Subject: [PATCH] Added sorting functionality to Styles Manager, for both storage and current script. Originally committed to SVN as r631. --- core/changelog.txt | 1 + core/dialog_style_manager.cpp | 47 +++++++++++++++++++++++++++++++++-- core/dialog_style_manager.h | 6 +++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/core/changelog.txt b/core/changelog.txt index 295b3c98c..8d9be01f2 100644 --- a/core/changelog.txt +++ b/core/changelog.txt @@ -48,6 +48,7 @@ Please visit http://aegisub.net to download latest version - 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) - Added buttons to Styles Manager to move styles up, down, to top or to bottom, on both storage and current script. (AMZ) +- Added sorting functionality to Styles Manager, for both storage and current script. (AMZ) = 1.10 beta - 2006.08.07 =========================== diff --git a/core/dialog_style_manager.cpp b/core/dialog_style_manager.cpp index ede243ba0..c342b6ad0 100644 --- a/core/dialog_style_manager.cpp +++ b/core/dialog_style_manager.cpp @@ -84,10 +84,12 @@ DialogStyleManager::DialogStyleManager (wxWindow *parent,SubtitlesGrid *_grid) StorageMoveDown = new wxButton(this, BUTTON_STORAGE_DOWN, _("Down"), wxDefaultPosition, wxSize(40,25)); StorageMoveTop = new wxButton(this, BUTTON_STORAGE_TOP, _("Top"), wxDefaultPosition, wxSize(40,25)); StorageMoveBottom = new wxButton(this, BUTTON_STORAGE_BOTTOM, _("Bottom"), wxDefaultPosition, wxSize(40,25)); + StorageSort = new wxButton(this, BUTTON_STORAGE_SORT, _("Sort"), wxDefaultPosition, wxSize(40,25)); StorageButtonsLow->Add(StorageMoveTop,1,wxEXPAND | wxALL,0); StorageButtonsLow->Add(StorageMoveUp,1,wxEXPAND | wxALL,0); StorageButtonsLow->Add(StorageMoveDown,1,wxEXPAND | wxALL,0); StorageButtonsLow->Add(StorageMoveBottom,1,wxEXPAND | wxALL,0); + StorageButtonsLow->Add(StorageSort,1,wxEXPAND | wxALL,0); StorageBox->Add(StorageList,0,wxEXPAND | wxALL,0); StorageBox->Add(MoveToLocal,0,wxEXPAND | wxALL,0); StorageBox->Add(StorageButtons,0,wxEXPAND | wxALL,0); @@ -115,10 +117,12 @@ DialogStyleManager::DialogStyleManager (wxWindow *parent,SubtitlesGrid *_grid) CurrentMoveDown = new wxButton(this, BUTTON_CURRENT_DOWN, _("Down"), wxDefaultPosition, wxSize(40,25)); CurrentMoveTop = new wxButton(this, BUTTON_CURRENT_TOP, _("Top"), wxDefaultPosition, wxSize(40,25)); CurrentMoveBottom = new wxButton(this, BUTTON_CURRENT_BOTTOM, _("Bottom"), wxDefaultPosition, wxSize(40,25)); + CurrentSort = new wxButton(this, BUTTON_CURRENT_SORT, _("Sort"), wxDefaultPosition, wxSize(40,25)); CurrentButtonsLow->Add(CurrentMoveTop,1,wxEXPAND | wxALL,0); CurrentButtonsLow->Add(CurrentMoveUp,1,wxEXPAND | wxALL,0); CurrentButtonsLow->Add(CurrentMoveDown,1,wxEXPAND | wxALL,0); CurrentButtonsLow->Add(CurrentMoveBottom,1,wxEXPAND | wxALL,0); + CurrentButtonsLow->Add(CurrentSort,1,wxEXPAND | wxALL,0); CurrentBox->Add(CurrentList,0,wxEXPAND | wxALL,0); CurrentBox->Add(MoveToStorage,0,wxEXPAND | wxALL,0); CurrentBox->Add(CurrentButtons,0,wxEXPAND | wxALL,0); @@ -328,10 +332,12 @@ BEGIN_EVENT_TABLE(DialogStyleManager, wxDialog) EVT_BUTTON(BUTTON_CURRENT_TOP, DialogStyleManager::OnCurrentMoveTop) EVT_BUTTON(BUTTON_CURRENT_DOWN, DialogStyleManager::OnCurrentMoveDown) EVT_BUTTON(BUTTON_CURRENT_BOTTOM, DialogStyleManager::OnCurrentMoveBottom) + EVT_BUTTON(BUTTON_CURRENT_SORT, DialogStyleManager::OnCurrentSort) EVT_BUTTON(BUTTON_STORAGE_UP, DialogStyleManager::OnStorageMoveUp) EVT_BUTTON(BUTTON_STORAGE_TOP, DialogStyleManager::OnStorageMoveTop) EVT_BUTTON(BUTTON_STORAGE_DOWN, DialogStyleManager::OnStorageMoveDown) EVT_BUTTON(BUTTON_STORAGE_BOTTOM, DialogStyleManager::OnStorageMoveBottom) + EVT_BUTTON(BUTTON_STORAGE_SORT, DialogStyleManager::OnStorageSort) END_EVENT_TABLE() @@ -829,10 +835,12 @@ void DialogStyleManager::UpdateMoveButtons() { StorageMoveTop->Enable(contStor && firstStor > 0); StorageMoveDown->Enable(contStor && lastStor != -1 && lastStor < itemsStor-1); StorageMoveBottom->Enable(contStor && lastStor != -1 && lastStor < itemsStor-1); + StorageSort->Enable(itemsStor > 1); CurrentMoveUp->Enable(contCurr && firstCurr > 0); CurrentMoveTop->Enable(contCurr && firstCurr > 0); CurrentMoveDown->Enable(contCurr && lastCurr != -1 && lastCurr < itemsCurr-1); CurrentMoveBottom->Enable(contCurr && lastCurr != -1 && lastCurr < itemsCurr-1); + CurrentSort->Enable(itemsCurr > 1); } @@ -842,10 +850,12 @@ void DialogStyleManager::OnStorageMoveUp (wxCommandEvent &event) { MoveStyles(tr void DialogStyleManager::OnStorageMoveTop (wxCommandEvent &event) { MoveStyles(true,1); } void DialogStyleManager::OnStorageMoveDown (wxCommandEvent &event) { MoveStyles(true,2); } void DialogStyleManager::OnStorageMoveBottom (wxCommandEvent &event) { MoveStyles(true,3); } +void DialogStyleManager::OnStorageSort (wxCommandEvent &event) { MoveStyles(true,4); } void DialogStyleManager::OnCurrentMoveUp (wxCommandEvent &event) { MoveStyles(false,0); } void DialogStyleManager::OnCurrentMoveTop (wxCommandEvent &event) { MoveStyles(false,1); } void DialogStyleManager::OnCurrentMoveDown (wxCommandEvent &event) { MoveStyles(false,2); } void DialogStyleManager::OnCurrentMoveBottom (wxCommandEvent &event) { MoveStyles(false,3); } +void DialogStyleManager::OnCurrentSort (wxCommandEvent &event) { MoveStyles(false,4); } ///////////////// @@ -860,8 +870,12 @@ void DialogStyleManager::MoveStyles(bool storage, int type) { // Get selection wxArrayInt sels; int n = list->GetSelections(sels); - int first = sels[0]; - int last = sels[n-1]; + int first = -1;; + int last = -1; + if (n) { + first = sels[0]; + last = sels[n-1]; + } // Get total style count int nStyles = list->GetCount(); @@ -910,6 +924,35 @@ void DialogStyleManager::MoveStyles(bool storage, int type) { last = nStyles-1; } + // Sort + if (type == 4) { + // Get confirmation + if (storage) { + int res = wxMessageBox(_("Are you sure? This cannot be undone!"),_("Sort styles"),wxYES_NO); + if (res == wxNO) return; + } + + // Get sorted list + wxArrayString stylNames; + for (int i=0;iat(i)->name.Lower()); + stylNames.Sort(); + AssStyle *curStyl; + + // Find each and copy it + for (int i=0;iat(j); + if (curStyl->name.Lower() == stylNames[i]) { + styls.push_back(curStyl); + } + } + } + + // Zero selection + first = 0; + last = 0; + } + // Storage if (storage) { // Rewrite storage diff --git a/core/dialog_style_manager.h b/core/dialog_style_manager.h index 5fb883bf1..64eb9dc94 100644 --- a/core/dialog_style_manager.h +++ b/core/dialog_style_manager.h @@ -73,6 +73,7 @@ private: wxButton *StorageMoveDown; wxButton *StorageMoveTop; wxButton *StorageMoveBottom; + wxButton *StorageSort; wxButton *MoveToStorage; wxButton *CurrentNew; wxButton *CurrentEdit; @@ -82,6 +83,7 @@ private: wxButton *CurrentMoveDown; wxButton *CurrentMoveTop; wxButton *CurrentMoveBottom; + wxButton *CurrentSort; AssStyleStorage Store; @@ -110,6 +112,7 @@ public: void OnCurrentMoveDown (wxCommandEvent &event); void OnCurrentMoveTop (wxCommandEvent &event); void OnCurrentMoveBottom (wxCommandEvent &event); + void OnCurrentSort (wxCommandEvent &event); void OnStorageChange (wxCommandEvent &event); void OnCurrentChange (wxCommandEvent &event); void OnCopyToStorage (wxCommandEvent &event); @@ -122,6 +125,7 @@ public: void OnStorageMoveDown (wxCommandEvent &event); void OnStorageMoveTop (wxCommandEvent &event); void OnStorageMoveBottom (wxCommandEvent &event); + void OnStorageSort (wxCommandEvent &event); void OnStorageDelete (wxCommandEvent &event); void OnCurrentDelete (wxCommandEvent &event); void OnCurrentImport (wxCommandEvent &event); @@ -144,6 +148,7 @@ enum { BUTTON_STORAGE_DOWN, BUTTON_STORAGE_TOP, BUTTON_STORAGE_BOTTOM, + BUTTON_STORAGE_SORT, BUTTON_CURRENT_COPYTO, BUTTON_CURRENT_NEW, BUTTON_CURRENT_EDIT, @@ -154,6 +159,7 @@ enum { BUTTON_CURRENT_DOWN, BUTTON_CURRENT_TOP, BUTTON_CURRENT_BOTTOM, + BUTTON_CURRENT_SORT, LIST_CATALOG, LIST_STORAGE, LIST_CURRENT