2006-01-16 22:02:54 +01:00
// Copyright (c) 2005, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
2009-07-29 07:43:02 +02:00
// Aegisub Project http://www.aegisub.org/
2006-01-16 22:02:54 +01:00
//
2009-07-29 07:43:02 +02:00
// $Id$
/// @file dialog_style_manager.cpp
/// @brief Style Manager dialogue box and partial logic
/// @ingroup style_editor
2006-01-16 22:02:54 +01:00
2009-01-04 07:31:48 +01:00
# include "config.h"
2012-02-01 01:48:50 +01:00
# include "dialog_style_manager.h"
2009-09-10 15:06:40 +02:00
# ifndef AGI_PRE
2012-02-01 01:48:42 +01:00
# include <tr1/functional>
2011-10-10 21:30:11 +02:00
# include <wx/bmpbuttn.h>
2007-09-12 01:22:26 +02:00
# include <wx/clipbrd.h>
2009-09-10 15:06:40 +02:00
# include <wx/filedlg.h>
# include <wx/filename.h>
# include <wx/intl.h>
2011-07-16 08:42:55 +02:00
# include <wx/msgdlg.h>
# include <wx/textdlg.h>
2007-09-12 01:22:26 +02:00
# include <wx/tokenzr.h>
2009-09-11 00:48:29 +02:00
# include <wx/choicdlg.h> // Keep this last so wxUSE_CHOICEDLG is set.
2009-09-10 15:06:40 +02:00
# endif
2006-10-20 00:53:06 +02:00
# include "ass_dialogue.h"
2009-09-10 15:06:40 +02:00
# include "ass_file.h"
# include "ass_style.h"
2010-05-21 03:13:36 +02:00
# include "compat.h"
2010-08-10 03:47:29 +02:00
# include "dialog_selected_choices.h"
2009-09-10 15:06:40 +02:00
# include "dialog_style_editor.h"
2011-01-16 08:17:36 +01:00
# include "include/aegisub/context.h"
2009-09-10 15:06:40 +02:00
# include "help_button.h"
# include "libresrc/libresrc.h"
2010-05-21 03:13:36 +02:00
# include "main.h"
2011-07-27 07:36:24 +02:00
# include "persist_location.h"
2010-12-08 04:36:10 +01:00
# include "selection_controller.h"
2009-09-10 15:06:40 +02:00
# include "standard_paths.h"
2007-07-05 01:09:40 +02:00
# include "utils.h"
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
2012-02-01 01:48:50 +01:00
static wxBitmapButton * add_bitmap_button ( wxWindow * parent , wxSizer * sizer , wxBitmap const & img , wxString const & tooltip ) {
wxBitmapButton * btn = new wxBitmapButton ( parent , - 1 , img ) ;
btn - > SetToolTip ( tooltip ) ;
sizer - > Add ( btn , wxSizerFlags ( ) . Expand ( ) ) ;
return btn ;
}
static wxSizer * make_move_buttons ( wxWindow * parent , wxButton * * up , wxButton * * down , wxButton * * top , wxButton * * bottom , wxButton * * sort ) {
wxSizer * sizer = new wxBoxSizer ( wxVERTICAL ) ;
sizer - > AddStretchSpacer ( 1 ) ;
* up = add_bitmap_button ( parent , sizer , GETIMAGE ( arrow_up_24 ) , _ ( " Move style up. " ) ) ;
* down = add_bitmap_button ( parent , sizer , GETIMAGE ( arrow_down_24 ) , _ ( " Move style down. " ) ) ;
* top = add_bitmap_button ( parent , sizer , GETIMAGE ( arrow_up_stop_24 ) , _ ( " Move style to top. " ) ) ;
* bottom = add_bitmap_button ( parent , sizer , GETIMAGE ( arrow_down_stop_24 ) , _ ( " Move style to bottom. " ) ) ;
* sort = add_bitmap_button ( parent , sizer , GETIMAGE ( arrow_sort_24 ) , _ ( " Sort styles alphabetically. " ) ) ;
sizer - > AddStretchSpacer ( 1 ) ;
return sizer ;
}
static wxSizer * make_edit_buttons ( wxWindow * parent , wxString move_label , wxButton * * move , wxButton * * nw , wxButton * * edit , wxButton * * copy , wxButton * * del ) {
wxSizer * sizer = new wxBoxSizer ( wxHORIZONTAL ) ;
* move = new wxButton ( parent , - 1 , move_label ) ;
* nw = new wxButton ( parent , - 1 , _ ( " &New " ) ) ;
* edit = new wxButton ( parent , - 1 , _ ( " &Edit " ) ) ;
* copy = new wxButton ( parent , - 1 , _ ( " &Copy " ) ) ;
* del = new wxButton ( parent , - 1 , _ ( " &Delete " ) ) ;
sizer - > Add ( * nw , wxSizerFlags ( 1 ) . Expand ( ) . Border ( wxRIGHT ) ) ;
sizer - > Add ( * edit , wxSizerFlags ( 1 ) . Expand ( ) . Border ( wxRIGHT ) ) ;
sizer - > Add ( * copy , wxSizerFlags ( 1 ) . Expand ( ) . Border ( wxRIGHT ) ) ;
sizer - > Add ( * del , wxSizerFlags ( 1 ) . Expand ( ) ) ;
return sizer ;
}
DialogStyleManager : : DialogStyleManager ( agi : : Context * context )
2011-09-28 21:43:11 +02:00
: wxDialog ( context - > parent , - 1 , _ ( " Styles Manager " ) , wxDefaultPosition , wxDefaultSize , wxDEFAULT_DIALOG_STYLE , " DialogStylesManager " )
2011-01-16 08:17:36 +01:00
, c ( context )
2006-01-16 22:02:54 +01:00
{
2012-02-01 01:48:50 +01:00
using std : : tr1 : : bind ;
2009-07-25 06:49:59 +02:00
SetIcon ( BitmapToIcon ( GETIMAGE ( style_toolbutton_24 ) ) ) ;
2007-06-28 22:29:56 +02:00
2006-01-16 22:02:54 +01:00
// Catalog
wxSizer * CatalogBox = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Catalog of available storages " ) ) ;
2012-02-01 01:48:50 +01:00
CatalogList = new wxComboBox ( this , - 1 , " " , wxDefaultPosition , wxSize ( - 1 , - 1 ) , 0 , NULL , wxCB_READONLY | wxCB_READONLY , wxDefaultValidator , " Catalog List " ) ;
wxButton * CatalogNew = new wxButton ( this , - 1 , _ ( " New " ) ) ;
wxButton * CatalogDelete = new wxButton ( this , - 1 , _ ( " Delete " ) ) ;
2006-01-16 22:02:54 +01:00
CatalogBox - > Add ( CatalogList , 1 , wxEXPAND | wxRIGHT | wxALIGN_RIGHT , 5 ) ;
CatalogBox - > Add ( CatalogNew , 0 , wxRIGHT , 5 ) ;
CatalogBox - > Add ( CatalogDelete , 0 , 0 , 0 ) ;
// Storage styles list
2012-02-01 01:48:50 +01:00
wxSizer * StorageButtons = make_edit_buttons ( this , _ ( " Copy to ¤t script -> " ) , & MoveToLocal , & StorageNew , & StorageEdit , & StorageCopy , & StorageDelete ) ;
2007-07-02 08:18:28 +02:00
wxSizer * StorageListSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2012-02-01 01:48:50 +01:00
StorageList = new wxListBox ( this , - 1 , wxDefaultPosition , wxSize ( 240 , 250 ) , 0 , NULL , wxLB_EXTENDED ) ;
2007-07-02 08:18:28 +02:00
StorageListSizer - > Add ( StorageList , 1 , wxEXPAND | wxRIGHT , 0 ) ;
2012-02-01 01:48:50 +01:00
StorageListSizer - > Add ( make_move_buttons ( this , & StorageMoveUp , & StorageMoveDown , & StorageMoveTop , & StorageMoveBottom , & StorageSort ) , wxSizerFlags ( ) . Expand ( ) ) ;
wxSizer * StorageBox = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( " Storage " ) ) ;
2007-07-02 08:18:28 +02:00
StorageBox - > Add ( StorageListSizer , 1 , wxEXPAND | wxBOTTOM , 5 ) ;
StorageBox - > Add ( MoveToLocal , 0 , wxEXPAND | wxBOTTOM , 5 ) ;
StorageBox - > Add ( StorageButtons , 0 , wxEXPAND | wxBOTTOM , 0 ) ;
2006-01-16 22:02:54 +01:00
// Local styles list
2012-02-01 01:48:50 +01:00
wxButton * CurrentImport = new wxButton ( this , - 1 , _ ( " &Import from script... " ) ) ;
wxSizer * CurrentButtons = make_edit_buttons ( this , _ ( " <- Copy to &storage " ) , & MoveToStorage , & CurrentNew , & CurrentEdit , & CurrentCopy , & CurrentDelete ) ;
2007-07-02 08:18:28 +02:00
wxSizer * MoveImportSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2007-08-16 01:17:42 +02:00
MoveImportSizer - > Add ( MoveToStorage , 1 , wxEXPAND | wxRIGHT , 5 ) ;
2012-02-01 01:48:50 +01:00
MoveImportSizer - > Add ( CurrentImport , 1 , wxEXPAND , 0 ) ;
wxSizer * CurrentListSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
CurrentList = new wxListBox ( this , - 1 , wxDefaultPosition , wxSize ( 240 , 250 ) , 0 , NULL , wxLB_EXTENDED ) ;
2007-07-02 08:18:28 +02:00
CurrentListSizer - > Add ( CurrentList , 1 , wxEXPAND | wxRIGHT , 0 ) ;
2012-02-01 01:48:50 +01:00
CurrentListSizer - > Add ( make_move_buttons ( this , & CurrentMoveUp , & CurrentMoveDown , & CurrentMoveTop , & CurrentMoveBottom , & CurrentSort ) , wxSizerFlags ( ) . Expand ( ) ) ;
wxSizer * CurrentBox = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( " Current script " ) ) ;
2007-07-02 08:18:28 +02:00
CurrentBox - > Add ( CurrentListSizer , 1 , wxEXPAND | wxBOTTOM , 5 ) ;
CurrentBox - > Add ( MoveImportSizer , 0 , wxEXPAND | wxBOTTOM , 5 ) ;
CurrentBox - > Add ( CurrentButtons , 0 , wxEXPAND | wxBOTTOM , 0 ) ;
2006-01-16 22:02:54 +01:00
2007-06-23 09:27:09 +02:00
// Buttons
2012-02-01 01:48:42 +01:00
wxStdDialogButtonSizer * buttonSizer = CreateStdDialogButtonSizer ( wxCANCEL | wxHELP ) ;
buttonSizer - > GetCancelButton ( ) - > SetLabel ( _ ( " Close " ) ) ;
2012-02-01 01:48:50 +01:00
Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & HelpButton : : OpenPage , " Styles Manager " ) , wxID_HELP ) ;
2007-06-23 09:27:09 +02:00
2006-01-16 22:02:54 +01:00
// General layout
wxSizer * StylesSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2006-12-26 05:48:53 +01:00
StylesSizer - > Add ( StorageBox , 0 , wxRIGHT | wxEXPAND , 5 ) ;
StylesSizer - > Add ( CurrentBox , 0 , wxLEFT | wxEXPAND , 0 ) ;
2012-02-01 01:48:50 +01:00
wxSizer * MainSizer = new wxBoxSizer ( wxVERTICAL ) ;
2006-01-16 22:02:54 +01:00
MainSizer - > Add ( CatalogBox , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxTOP , 5 ) ;
2007-06-23 09:27:09 +02:00
MainSizer - > Add ( StylesSizer , 1 , wxEXPAND | wxALL , 5 ) ;
MainSizer - > Add ( buttonSizer , 0 , wxBOTTOM | wxEXPAND , 5 ) ;
2006-01-16 22:02:54 +01:00
// Set sizer
2012-02-01 01:48:50 +01:00
SetSizerAndFit ( MainSizer ) ;
2006-01-16 22:02:54 +01:00
// Position window
2011-07-27 07:36:24 +02:00
persist . reset ( new PersistLocation ( this , " Tool/Style Manager " ) ) ;
2006-01-16 22:02:54 +01:00
// Populate lists
LoadCatalog ( ) ;
2011-01-16 08:17:36 +01:00
LoadCurrentStyles ( c - > ass ) ;
2006-10-20 00:53:06 +02:00
2007-02-05 20:09:45 +01:00
//Set key handlers for lists
2011-01-16 08:17:36 +01:00
CatalogList - > Bind ( wxEVT_KEY_DOWN , & DialogStyleManager : : OnKeyDown , this ) ;
StorageList - > Bind ( wxEVT_KEY_DOWN , & DialogStyleManager : : OnKeyDown , this ) ;
CurrentList - > Bind ( wxEVT_KEY_DOWN , & DialogStyleManager : : OnKeyDown , this ) ;
2007-02-05 20:09:45 +01:00
2006-10-20 00:53:06 +02:00
// Select default item
2012-02-01 19:47:10 +01:00
if ( AssDialogue * dia = context - > selectionController - > GetActiveLine ( ) )
CurrentList - > SetStringSelection ( dia - > Style ) ;
else
CurrentList - > SetSelection ( 0 ) ;
2006-10-20 00:53:06 +02:00
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
StorageMoveUp - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , true , 0 ) ) ;
StorageMoveTop - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , true , 1 ) ) ;
StorageMoveDown - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , true , 2 ) ) ;
StorageMoveBottom - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , true , 3 ) ) ;
StorageSort - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , true , 4 ) ) ;
CurrentMoveUp - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , false , 0 ) ) ;
CurrentMoveTop - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , false , 1 ) ) ;
CurrentMoveDown - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , false , 2 ) ) ;
CurrentMoveBottom - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , false , 3 ) ) ;
CurrentSort - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : MoveStyles , this , false , 4 ) ) ;
CatalogNew - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCatalogNew , this ) ) ;
CatalogDelete - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCatalogDelete , this ) ) ;
StorageNew - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnStorageNew , this ) ) ;
StorageEdit - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnStorageEdit , this ) ) ;
StorageCopy - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnStorageCopy , this ) ) ;
StorageDelete - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnStorageDelete , this ) ) ;
CurrentNew - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCurrentNew , this ) ) ;
CurrentEdit - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCurrentEdit , this ) ) ;
CurrentCopy - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCurrentCopy , this ) ) ;
CurrentDelete - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCurrentDelete , this ) ) ;
CurrentImport - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCurrentImport , this ) ) ;
MoveToLocal - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCopyToCurrent , this ) ) ;
MoveToStorage - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , bind ( & DialogStyleManager : : OnCopyToStorage , this ) ) ;
CatalogList - > Bind ( wxEVT_COMMAND_COMBOBOX_SELECTED , bind ( & DialogStyleManager : : OnChangeCatalog , this ) ) ;
StorageList - > Bind ( wxEVT_COMMAND_LISTBOX_SELECTED , bind ( & DialogStyleManager : : UpdateButtons , this ) ) ;
StorageList - > Bind ( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED , bind ( & DialogStyleManager : : OnStorageEdit , this ) ) ;
CurrentList - > Bind ( wxEVT_COMMAND_LISTBOX_SELECTED , bind ( & DialogStyleManager : : UpdateButtons , this ) ) ;
CurrentList - > Bind ( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED , bind ( & DialogStyleManager : : OnCurrentEdit , this ) ) ;
2006-01-16 22:02:54 +01:00
}
DialogStyleManager : : ~ DialogStyleManager ( ) {
int sel = CatalogList - > GetSelection ( ) ;
2012-02-01 01:48:50 +01:00
if ( sel ! = wxNOT_FOUND )
c - > ass - > SetScriptInfo ( " Last Style Storage " , CatalogList - > GetString ( sel ) ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:24 +01:00
void DialogStyleManager : : LoadCatalog ( ) {
2006-01-16 22:02:54 +01:00
CatalogList - > Clear ( ) ;
2012-02-01 01:48:50 +01:00
// Get saved style catalogs
wxString dirname = StandardPaths : : DecodePath ( " ?user/catalog/*.sty " ) ;
for ( wxString curfile = wxFindFirstFile ( dirname , wxFILE ) ; ! curfile . empty ( ) ; curfile = wxFindNextFile ( ) )
CatalogList - > Append ( wxFileName ( curfile ) . GetName ( ) ) ;
// Create a default storage if there are none
if ( CatalogList - > IsListEmpty ( ) ) {
2012-02-01 01:48:24 +01:00
Store . Clear ( ) ;
Store . style . push_back ( new AssStyle ) ;
Store . Save ( " Default " ) ;
2012-02-01 01:48:50 +01:00
CatalogList - > Append ( " Default " ) ;
2006-01-16 22:02:54 +01:00
}
// Set to default if available
StorageActions ( false ) ;
2011-09-28 21:43:11 +02:00
wxString pickStyle = c - > ass - > GetScriptInfo ( " Last Style Storage " ) ;
2012-02-01 01:48:50 +01:00
if ( pickStyle . empty ( ) )
pickStyle = " Default " ;
2008-09-06 13:35:36 +02:00
int opt = CatalogList - > FindString ( pickStyle , false ) ;
2006-01-16 22:02:54 +01:00
if ( opt ! = wxNOT_FOUND ) {
CatalogList - > SetSelection ( opt ) ;
2012-02-01 01:48:50 +01:00
OnChangeCatalog ( ) ;
2006-01-16 22:02:54 +01:00
}
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : LoadCurrentStyles ( AssFile * subs ) {
2006-01-16 22:02:54 +01:00
CurrentList - > Clear ( ) ;
styleMap . clear ( ) ;
2011-12-22 22:14:51 +01:00
for ( std : : list < AssEntry * > : : iterator cur = subs - > Line . begin ( ) ; cur ! = subs - > Line . end ( ) ; cur + + ) {
if ( AssStyle * style = dynamic_cast < AssStyle * > ( * cur ) ) {
2010-04-24 23:48:06 +02:00
CurrentList - > Append ( style - > name ) ;
styleMap . push_back ( style ) ;
2006-01-16 22:02:54 +01:00
}
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : LoadStorageStyles ( ) {
2006-01-16 22:02:54 +01:00
StorageList - > Clear ( ) ;
styleStorageMap . clear ( ) ;
2011-12-22 22:14:51 +01:00
for ( std : : list < AssStyle * > : : iterator cur = Store . style . begin ( ) ; cur ! = Store . style . end ( ) ; cur + + ) {
2012-02-01 01:48:24 +01:00
AssStyle * style = * cur ;
StorageList - > Append ( style - > name ) ;
styleStorageMap . push_back ( style ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : StorageActions ( bool state ) {
2006-01-16 22:02:54 +01:00
StorageList - > Enable ( state ) ;
MoveToLocal - > Enable ( state ) ;
StorageNew - > Enable ( state ) ;
StorageCopy - > Enable ( state ) ;
StorageDelete - > Enable ( state ) ;
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnChangeCatalog ( ) {
2006-01-16 22:02:54 +01:00
int sel = CatalogList - > GetSelection ( ) ;
if ( sel ! = wxNOT_FOUND ) {
StorageActions ( true ) ;
Store . Load ( CatalogList - > GetString ( sel ) ) ;
LoadStorageStyles ( ) ;
}
else {
StorageActions ( false ) ;
Store . Clear ( ) ;
LoadStorageStyles ( ) ;
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCatalogNew ( ) {
2011-09-28 21:43:11 +02:00
wxString name = wxGetTextFromUser ( _ ( " New storage name: " ) , _ ( " New catalog entry " ) , " " , this ) ;
2006-01-16 22:02:54 +01:00
if ( ! name . empty ( ) ) {
2006-11-23 20:08:46 +01:00
// Remove bad characters from the name
wxString badchars = wxFileName : : GetForbiddenChars ( ) ;
int badchars_removed = 0 ;
for ( size_t i = 0 ; i < name . Length ( ) ; + + i ) {
for ( size_t j = 0 ; j < badchars . Length ( ) ; + + j ) {
if ( name [ i ] = = badchars [ j ] ) {
2011-09-28 21:43:11 +02:00
name [ i ] = ' _ ' ;
2006-11-23 20:08:46 +01:00
+ + badchars_removed ;
}
}
}
2007-04-08 02:10:42 +02:00
2008-09-06 13:35:36 +02:00
// Make sure that there is no storage with the same name (case insensitive search since Windows filenames are case insensitive)
if ( CatalogList - > FindString ( name , false ) ! = wxNOT_FOUND ) {
2009-07-24 04:10:41 +02:00
wxMessageBox ( _ ( " A catalog with that name already exists. " ) , _ ( " Catalog name conflict " ) , wxICON_ERROR | wxOK ) ;
2007-04-08 02:10:42 +02:00
return ;
}
// Warn about bad characters
2006-11-23 20:08:46 +01:00
if ( badchars_removed > 0 ) {
2011-09-28 21:43:48 +02:00
wxMessageBox ( wxString : : Format ( _ ( " The specified catalog name contains one or more illegal characters. They have been replaced with underscores instead. \n The catalog has been renamed to \" %s \" . " ) , name ) , _ ( " Invalid characters " ) ) ;
2006-11-23 20:08:46 +01:00
}
2007-04-08 02:10:42 +02:00
// Add to list of storages
2006-01-16 22:02:54 +01:00
Store . Clear ( ) ;
StorageList - > Clear ( ) ;
CatalogList - > Append ( name ) ;
CatalogList - > SetStringSelection ( name ) ;
StorageActions ( true ) ;
Store . Save ( name ) ;
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCatalogDelete ( ) {
2006-01-16 22:02:54 +01:00
int sel = CatalogList - > GetSelection ( ) ;
if ( sel ! = wxNOT_FOUND ) {
wxString name = CatalogList - > GetString ( sel ) ;
2011-09-28 21:43:48 +02:00
wxString message = wxString : : Format ( _ ( " Are you sure you want to delete the storage \" %s \" from the catalog? " ) , name ) ;
2006-01-16 22:02:54 +01:00
int option = wxMessageBox ( message , _ ( " Confirm delete " ) , wxYES_NO | wxICON_EXCLAMATION , this ) ;
if ( option = = wxYES ) {
2011-09-28 21:43:11 +02:00
wxRemoveFile ( StandardPaths : : DecodePath ( " ?user/catalog/ " + name + " .sty " ) ) ;
2006-01-16 22:02:54 +01:00
CatalogList - > Delete ( sel ) ;
StorageList - > Clear ( ) ;
StorageActions ( false ) ;
}
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnStorageEdit ( ) {
2006-01-16 22:02:54 +01:00
wxArrayInt selections ;
int n = StorageList - > GetSelections ( selections ) ;
if ( n = = 1 ) {
2010-04-24 23:48:06 +02:00
AssStyle * selStyle = styleStorageMap [ selections [ 0 ] ] ;
2011-10-18 00:00:58 +02:00
DialogStyleEditor ( this , selStyle , c , & Store , false ) . ShowModal ( ) ;
StorageList - > SetString ( selections [ 0 ] , selStyle - > name ) ;
Store . Save ( CatalogList - > GetString ( CatalogList - > GetSelection ( ) ) ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCurrentEdit ( ) {
2006-01-16 22:02:54 +01:00
wxArrayInt selections ;
int n = CurrentList - > GetSelections ( selections ) ;
if ( n = = 1 ) {
2010-04-24 23:48:06 +02:00
AssStyle * selStyle = styleMap [ selections [ 0 ] ] ;
2011-10-18 00:00:58 +02:00
DialogStyleEditor ( this , selStyle , c , 0 , false ) . ShowModal ( ) ;
CurrentList - > SetString ( selections [ 0 ] , selStyle - > name ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCopyToStorage ( ) {
2006-01-16 22:02:54 +01:00
// Check if there is actually a storage
2010-04-24 23:48:06 +02:00
if ( ! StorageNew - > IsEnabled ( ) ) return ;
2006-01-16 22:02:54 +01:00
2012-02-01 01:48:24 +01:00
std : : list < wxString > copied ;
2006-01-16 22:02:54 +01:00
wxArrayInt selections ;
int n = CurrentList - > GetSelections ( selections ) ;
2009-07-18 04:52:46 +02:00
for ( int i = 0 ; i < n ; i + + ) {
wxString styleName = CurrentList - > GetString ( selections [ i ] ) ;
bool addStyle = true ;
2012-02-01 01:48:24 +01:00
if ( AssStyle * style = Store . GetStyle ( styleName ) ) {
addStyle = false ;
if ( wxYES = = wxMessageBox ( wxString : : Format ( " There is already a style with the name \" %s \" on the current storage. Proceed and overwrite anyway? " , styleName ) , " Style name collision. " , wxYES_NO ) ) {
* style = * styleMap . at ( selections [ i ] ) ;
copied . push_back ( styleName ) ;
2008-01-13 07:42:34 +01:00
}
2009-07-18 04:52:46 +02:00
}
if ( addStyle ) {
2012-02-01 01:48:24 +01:00
Store . style . push_back ( new AssStyle ( * styleMap . at ( selections [ i ] ) ) ) ;
2010-04-24 23:48:06 +02:00
copied . push_back ( styleName ) ;
2006-01-16 22:02:54 +01:00
}
}
Store . Save ( CatalogList - > GetString ( CatalogList - > GetSelection ( ) ) ) ;
LoadStorageStyles ( ) ;
2012-02-01 01:48:24 +01:00
for ( std : : list < wxString > : : iterator name = copied . begin ( ) ; name ! = copied . end ( ) ; + + name ) {
2010-04-24 23:48:06 +02:00
StorageList - > SetStringSelection ( * name , true ) ;
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCopyToCurrent ( ) {
std : : list < wxString > copied ;
2006-01-16 22:02:54 +01:00
wxArrayInt selections ;
int n = StorageList - > GetSelections ( selections ) ;
2009-07-18 04:52:46 +02:00
for ( int i = 0 ; i < n ; i + + ) {
wxString styleName = StorageList - > GetString ( selections [ i ] ) ;
bool addStyle = true ;
for ( std : : vector < AssStyle * > : : iterator style = styleMap . begin ( ) ; style ! = styleMap . end ( ) ; + + style ) {
if ( ( * style ) - > name . CmpNoCase ( styleName ) = = 0 ) {
addStyle = false ;
2011-09-28 21:43:48 +02:00
if ( wxYES = = wxMessageBox ( wxString : : Format ( " There is already a style with the name \" %s \" on the current script. Proceed and overwrite anyway? " , styleName ) , " Style name collision. " , wxYES_NO ) ) {
2009-07-18 04:52:46 +02:00
* * style = * styleStorageMap . at ( selections [ i ] ) ;
2010-04-24 23:48:06 +02:00
copied . push_back ( styleName ) ;
2009-07-18 04:52:46 +02:00
}
break ;
}
2006-12-17 21:30:59 +01:00
}
2009-07-18 04:52:46 +02:00
if ( addStyle ) {
2012-02-01 01:48:50 +01:00
c - > ass - > InsertStyle ( new AssStyle ( * styleStorageMap . at ( selections [ i ] ) ) ) ;
2010-04-24 23:48:06 +02:00
copied . push_back ( styleName ) ;
2006-01-16 22:02:54 +01:00
}
}
2011-01-16 08:17:36 +01:00
LoadCurrentStyles ( c - > ass ) ;
2012-02-01 01:48:50 +01:00
for ( std : : list < wxString > : : iterator name = copied . begin ( ) ; name ! = copied . end ( ) ; + + name ) {
2010-04-24 23:48:06 +02:00
CurrentList - > SetStringSelection ( * name , true ) ;
}
2011-09-15 07:16:32 +02:00
c - > ass - > Commit ( _ ( " style copy " ) , AssFile : : COMMIT_STYLES ) ;
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnStorageCopy ( ) {
2006-01-16 22:02:54 +01:00
wxArrayInt selections ;
2007-01-27 00:42:19 +01:00
StorageList - > GetSelections ( selections ) ;
2012-02-01 01:48:50 +01:00
if ( selections . empty ( ) ) return ;
2006-01-16 22:02:54 +01:00
2011-10-18 00:00:58 +02:00
DialogStyleEditor ( this , styleStorageMap [ selections [ 0 ] ] , c , & Store , true ) . ShowModal ( ) ;
Store . Save ( CatalogList - > GetString ( CatalogList - > GetSelection ( ) ) ) ;
LoadStorageStyles ( ) ;
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCurrentCopy ( ) {
2006-01-16 22:02:54 +01:00
wxArrayInt selections ;
2007-01-27 00:42:19 +01:00
CurrentList - > GetSelections ( selections ) ;
2012-02-01 01:48:50 +01:00
if ( selections . empty ( ) ) return ;
2006-01-16 22:02:54 +01:00
2011-10-18 00:00:58 +02:00
DialogStyleEditor ( this , styleMap [ selections [ 0 ] ] , c , 0 , true ) . ShowModal ( ) ;
LoadCurrentStyles ( c - > ass ) ;
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : CopyToClipboard ( wxListBox * list , std : : vector < AssStyle * > v ) {
2012-01-31 01:44:43 +01:00
wxString data ;
2007-02-06 04:25:14 +01:00
wxArrayInt selections ;
list - > GetSelections ( selections ) ;
2012-02-01 01:48:50 +01:00
for ( size_t i = 0 ; i < selections . size ( ) ; + + i ) {
if ( i ) data + = " \r \n " ;
AssStyle * s = v [ selections [ i ] ] ;
2007-02-06 04:25:14 +01:00
s - > UpdateData ( ) ;
data + = s - > GetEntryData ( ) ;
}
if ( wxTheClipboard - > Open ( ) ) {
wxTheClipboard - > SetData ( new wxTextDataObject ( data ) ) ;
wxTheClipboard - > Close ( ) ;
}
}
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
2012-02-01 01:48:50 +01:00
static wxString get_clipboard_text ( ) {
wxString text ;
2007-02-06 04:25:14 +01:00
if ( wxTheClipboard - > Open ( ) ) {
if ( wxTheClipboard - > IsSupported ( wxDF_TEXT ) ) {
wxTextDataObject rawdata ;
wxTheClipboard - > GetData ( rawdata ) ;
2012-02-01 01:48:50 +01:00
text = rawdata . GetText ( ) ;
2007-02-06 04:25:14 +01:00
}
wxTheClipboard - > Close ( ) ;
}
2012-02-01 01:48:50 +01:00
return text ;
}
2007-02-06 04:25:14 +01:00
2012-02-01 01:48:50 +01:00
template < class Func1 , class Func2 >
static void add_styles ( Func1 name_checker , Func2 style_adder ) {
wxStringTokenizer st ( get_clipboard_text ( ) , ' \n ' ) ;
2007-02-06 04:25:14 +01:00
while ( st . HasMoreTokens ( ) ) {
2007-09-02 21:31:17 +02:00
try {
2011-12-22 22:14:51 +01:00
AssStyle * s = new AssStyle ( st . GetNextToken ( ) . Trim ( true ) ) ;
2012-02-01 01:48:50 +01:00
while ( name_checker ( s - > name ) )
2011-12-22 22:14:51 +01:00
s - > name = " Copy of " + s - > name ;
2012-02-01 01:48:50 +01:00
style_adder ( s ) ;
2007-09-02 21:31:17 +02:00
}
catch ( . . . ) {
2012-02-01 01:48:50 +01:00
wxMessageBox ( _ ( " Could not parse style " ) , _ ( " Could not parse style " ) , wxOK | wxICON_EXCLAMATION ) ;
2007-02-06 04:25:14 +01:00
}
}
}
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : PasteToCurrent ( ) {
add_styles (
bind ( & AssFile : : GetStyle , c - > ass , std : : tr1 : : placeholders : : _1 ) ,
bind ( & AssFile : : InsertStyle , c - > ass , std : : tr1 : : placeholders : : _1 ) ) ;
2007-02-06 04:25:14 +01:00
2012-02-01 01:48:50 +01:00
LoadCurrentStyles ( c - > ass ) ;
c - > ass - > Commit ( _ ( " style paste " ) , AssFile : : COMMIT_STYLES ) ;
}
2007-09-02 21:31:17 +02:00
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : PasteToStorage ( ) {
add_styles (
bind ( & AssStyleStorage : : GetStyle , & Store , std : : tr1 : : placeholders : : _1 ) ,
bind ( & std : : list < AssStyle * > : : push_back , & Store . style , std : : tr1 : : placeholders : : _1 ) ) ;
2007-09-02 21:31:17 +02:00
2012-02-01 01:48:50 +01:00
Store . Save ( CatalogList - > GetString ( CatalogList - > GetSelection ( ) ) ) ;
LoadStorageStyles ( ) ;
StorageList - > SetStringSelection ( Store . style . back ( ) - > name ) ;
2007-02-06 04:25:14 +01:00
}
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnStorageNew ( ) {
2011-10-18 00:00:58 +02:00
DialogStyleEditor ( this , 0 , c , & Store , false ) . ShowModal ( ) ;
Store . Save ( CatalogList - > GetString ( CatalogList - > GetSelection ( ) ) ) ;
LoadStorageStyles ( ) ;
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCurrentNew ( ) {
2011-10-18 00:00:58 +02:00
DialogStyleEditor ( this , 0 , c , 0 , false ) . ShowModal ( ) ;
LoadCurrentStyles ( c - > ass ) ;
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
static int confirm_delete ( int n , wxWindow * parent , wxString const & title ) {
2011-11-25 20:26:48 +01:00
wxString message = n = = 1 ?
_ ( " Are you sure you want to delete this style? " ) :
wxString : : Format ( _ ( " Are you sure you want to delete these %d styles? " ) , n ) ;
2012-02-01 01:48:50 +01:00
return wxMessageBox ( message , title , wxYES_NO | wxICON_EXCLAMATION , parent ) ;
}
2006-01-16 22:02:54 +01:00
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnStorageDelete ( ) {
wxArrayInt selections ;
int n = StorageList - > GetSelections ( selections ) ;
if ( confirm_delete ( n , this , _ ( " Confirm delete from storage " ) ) = = wxYES ) {
2006-01-16 22:02:54 +01:00
for ( int i = 0 ; i < n ; i + + ) {
2011-11-25 20:26:48 +01:00
AssStyle * temp = styleStorageMap . at ( selections [ i ] ) ;
2006-01-16 22:02:54 +01:00
Store . style . remove ( temp ) ;
delete temp ;
}
Store . Save ( CatalogList - > GetString ( CatalogList - > GetSelection ( ) ) ) ;
LoadStorageStyles ( ) ;
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCurrentDelete ( ) {
2006-01-16 22:02:54 +01:00
wxArrayInt selections ;
int n = CurrentList - > GetSelections ( selections ) ;
2012-02-01 01:48:50 +01:00
if ( confirm_delete ( n , this , _ ( " Confirm delete from current " ) ) = = wxYES ) {
2006-01-16 22:02:54 +01:00
for ( int i = 0 ; i < n ; i + + ) {
2011-11-25 20:26:48 +01:00
AssStyle * temp = styleMap . at ( selections [ i ] ) ;
2011-01-16 08:17:36 +01:00
c - > ass - > Line . remove ( temp ) ;
2006-01-16 22:02:54 +01:00
delete temp ;
}
2011-01-16 08:17:36 +01:00
LoadCurrentStyles ( c - > ass ) ;
2006-01-16 22:02:54 +01:00
2011-09-15 07:16:32 +02:00
c - > ass - > Commit ( _ ( " style delete " ) , AssFile : : COMMIT_STYLES ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCurrentImport ( ) {
2006-12-26 05:48:53 +01:00
// Get file name
2010-05-21 03:13:36 +02:00
wxString path = lagi_wxString ( OPT_GET ( " Path/Last/Subtitles " ) - > GetString ( ) ) ;
2011-09-28 21:43:11 +02:00
wxString filename = wxFileSelector ( _ ( " Open subtitles file " ) , path , " " , " " , AssFile : : GetWildcardList ( 0 ) , wxFD_OPEN | wxFD_FILE_MUST_EXIST ) ;
2006-12-26 05:48:53 +01:00
if ( ! filename . IsEmpty ( ) ) {
// Save path
wxFileName filepath ( filename ) ;
2010-05-21 03:13:36 +02:00
OPT_SET ( " Path/Last/Subtitles " ) - > SetString ( STD_STR ( filepath . GetPath ( ) ) ) ;
2006-12-26 05:48:53 +01:00
try {
// Load file
AssFile temp ;
2011-09-28 21:43:11 +02:00
temp . Load ( filename , " " , false ) ;
2006-12-26 05:48:53 +01:00
// Get styles
wxArrayString styles = temp . GetStyles ( ) ;
2011-12-22 22:25:00 +01:00
if ( styles . empty ( ) ) {
2008-01-17 21:30:44 +01:00
wxMessageBox ( _ ( " The selected file has no available styles. " ) , _ ( " Error Importing Styles " ) , wxOK ) ;
2006-12-26 05:48:53 +01:00
return ;
}
// Get selection
wxArrayInt selections ;
2010-08-10 03:47:29 +02:00
int res = GetSelectedChoices ( this , selections , _ ( " Choose styles to import: " ) , _ ( " Import Styles " ) , styles ) ;
2006-12-26 05:48:53 +01:00
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
2008-09-06 13:35:36 +02:00
int test = CurrentList - > FindString ( styles [ selections [ i ] ] , false ) ;
2006-12-26 05:48:53 +01:00
if ( test ! = wxNOT_FOUND ) {
2011-09-28 21:43:48 +02:00
int answer = wxMessageBox ( wxString : : Format ( " There is already a style with the name \" %s \" on the current script. Overwrite? " , styles [ selections [ i ] ] ) , " Style name collision. " , wxYES_NO ) ;
2007-07-27 07:58:55 +02:00
if ( answer = = wxYES ) {
// Overwrite
modified = true ;
2008-09-06 13:35:36 +02:00
// The GetString->FindString mess is a silly workaround for the fact that to vsfilter
// (and the duplicate check a few lines above), style names aren't case sensitive, but to the
// rest of Aegisub they are.
2011-01-16 08:17:36 +01:00
* ( c - > ass - > GetStyle ( CurrentList - > GetString ( CurrentList - > FindString ( styles [ selections [ i ] ] , false ) ) ) ) = * temp . GetStyle ( styles [ selections [ i ] ] ) ;
2007-07-27 07:58:55 +02:00
}
continue ;
2006-12-26 05:48:53 +01:00
}
// Copy
modified = true ;
AssStyle * tempStyle = new AssStyle ;
* tempStyle = * temp . GetStyle ( styles [ selections [ i ] ] ) ;
2011-01-16 08:17:36 +01:00
c - > ass - > InsertStyle ( tempStyle ) ;
2006-12-26 05:48:53 +01:00
}
// Update
if ( modified ) {
2011-01-16 08:17:36 +01:00
LoadCurrentStyles ( c - > ass ) ;
2011-09-15 07:16:32 +02:00
c - > ass - > Commit ( _ ( " style import " ) , AssFile : : COMMIT_STYLES ) ;
2006-12-26 05:48:53 +01:00
}
}
catch ( . . . ) {
}
}
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : UpdateButtons ( ) {
2006-12-26 22:45:23 +01:00
// Get storage selection
wxArrayInt sels ;
int n = StorageList - > GetSelections ( sels ) ;
2012-02-01 01:48:50 +01:00
StorageEdit - > Enable ( n = = 1 ) ;
StorageCopy - > Enable ( n = = 1 ) ;
StorageDelete - > Enable ( n > 0 ) ;
MoveToLocal - > Enable ( n > 0 ) ;
2006-12-26 22:45:23 +01:00
int firstStor = - 1 ;
int lastStor = - 1 ;
if ( n ) {
firstStor = sels [ 0 ] ;
lastStor = sels [ n - 1 ] ;
}
2006-12-26 23:02:17 +01:00
// Check if selection is continuous
bool contStor = true ;
2010-04-24 23:48:06 +02:00
for ( int i = 1 ; i < n ; + + i ) {
if ( sels [ i ] ! = sels [ i - 1 ] + 1 ) {
contStor = false ;
break ;
2006-12-26 23:02:17 +01:00
}
}
2012-02-01 01:48:50 +01:00
int itemsStor = StorageList - > GetCount ( ) ;
StorageMoveUp - > Enable ( contStor & & firstStor > 0 ) ;
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 ) ;
2006-12-26 22:45:23 +01:00
// Get current selection
n = CurrentList - > GetSelections ( sels ) ;
2012-02-01 01:48:50 +01:00
CurrentEdit - > Enable ( n = = 1 ) ;
CurrentCopy - > Enable ( n = = 1 ) ;
CurrentDelete - > Enable ( n > 0 ) ;
MoveToStorage - > Enable ( n > 0 ) ;
2006-12-26 22:45:23 +01:00
int firstCurr = - 1 ;
int lastCurr = - 1 ;
if ( n ) {
firstCurr = sels [ 0 ] ;
lastCurr = sels [ n - 1 ] ;
}
2006-12-26 23:02:17 +01:00
// Check if selection is continuous
bool contCurr = true ;
2010-04-24 23:48:06 +02:00
for ( int i = 1 ; i < n ; + + i ) {
if ( sels [ i ] ! = sels [ i - 1 ] + 1 ) {
contCurr = false ;
break ;
2006-12-26 23:02:17 +01:00
}
}
2012-02-01 01:48:50 +01:00
int itemsCurr = CurrentList - > GetCount ( ) ;
2006-12-26 23:02:17 +01:00
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 ) ;
2006-12-26 23:28:44 +01:00
CurrentSort - > Enable ( itemsCurr > 1 ) ;
2006-12-26 22:45:23 +01:00
}
2012-02-01 01:48:50 +01:00
static bool cmp_style_name ( const AssStyle * lft , const AssStyle * rgt ) {
return lft - > name < rgt - > name ;
}
2006-12-26 22:45:23 +01:00
void DialogStyleManager : : MoveStyles ( bool storage , int type ) {
2012-02-01 01:48:50 +01:00
wxListBox * list = storage ? StorageList : CurrentList ;
2006-12-26 22:45:23 +01:00
// Get selection
wxArrayInt sels ;
int n = list - > GetSelections ( sels ) ;
2012-02-01 01:48:50 +01:00
if ( n = = 0 & & type ! = 4 ) return ;
2006-12-26 22:45:23 +01:00
2012-02-01 01:48:50 +01:00
int first = sels . front ( ) ;
int last = sels . back ( ) ;
2006-12-26 22:45:23 +01:00
// Get styles
2012-02-01 01:48:50 +01:00
std : : vector < AssStyle * > & styls = storage ? styleStorageMap : styleMap ;
2006-12-26 22:45:23 +01:00
// Move up
if ( type = = 0 ) {
2012-02-01 01:48:50 +01:00
AssStyle * rem = styls [ first - 1 ] ;
styls . erase ( styls . begin ( ) + first - 1 ) ;
styls . insert ( styls . begin ( ) + last , rem ) ;
2006-12-26 22:45:23 +01:00
first - - ;
last - - ;
}
// Move to top
2012-02-01 01:48:50 +01:00
else if ( type = = 1 ) {
std : : vector < AssStyle * > tmp ( styls . begin ( ) + first , styls . begin ( ) + last + 1 ) ;
styls . erase ( styls . begin ( ) + first , styls . begin ( ) + last + 1 ) ;
styls . insert ( styls . begin ( ) , tmp . begin ( ) , tmp . end ( ) ) ;
last = last - first ;
2006-12-26 22:45:23 +01:00
first = 0 ;
}
// Move down
2012-02-01 01:48:50 +01:00
else if ( type = = 2 ) {
AssStyle * rem = styls [ last + 1 ] ;
styls . erase ( styls . begin ( ) + last + 1 ) ;
styls . insert ( styls . begin ( ) + first , rem ) ;
2006-12-26 22:45:23 +01:00
first + + ;
last + + ;
}
// Move to bottom
2012-02-01 01:48:50 +01:00
else if ( type = = 3 ) {
std : : vector < AssStyle * > tmp ( styls . begin ( ) + first , styls . begin ( ) + last + 1 ) ;
styls . erase ( styls . begin ( ) + first , styls . begin ( ) + last + 1 ) ;
styls . insert ( styls . end ( ) , tmp . begin ( ) , tmp . end ( ) ) ;
first = styls . size ( ) - ( last - first + 1 ) ;
last = styls . size ( ) - 1 ;
2006-12-26 22:45:23 +01:00
}
2006-12-26 23:28:44 +01:00
// Sort
2012-02-01 01:48:50 +01:00
else if ( type = = 4 ) {
2006-12-26 23:28:44 +01:00
// Get confirmation
if ( storage ) {
int res = wxMessageBox ( _ ( " Are you sure? This cannot be undone! " ) , _ ( " Sort styles " ) , wxYES_NO ) ;
if ( res = = wxNO ) return ;
}
2012-02-01 01:48:50 +01:00
sort ( styls . begin ( ) , styls . end ( ) , cmp_style_name ) ;
2006-12-26 23:28:44 +01:00
first = 0 ;
last = 0 ;
}
2006-12-26 22:45:23 +01:00
// Storage
if ( storage ) {
Store . style . clear ( ) ;
2012-02-01 01:48:24 +01:00
copy ( styls . begin ( ) , styls . end ( ) , back_inserter ( Store . style ) ) ;
2006-12-26 22:45:23 +01:00
Store . Save ( CatalogList - > GetString ( CatalogList - > GetSelection ( ) ) ) ;
}
// Current
else {
// Replace styles
entryIter next ;
int curn = 0 ;
2012-02-01 01:48:50 +01:00
for ( entryIter cur = c - > ass - > Line . begin ( ) ; cur ! = c - > ass - > Line . end ( ) ; cur = next ) {
2006-12-26 22:45:23 +01:00
next = cur ;
next + + ;
2012-02-01 01:48:50 +01:00
if ( dynamic_cast < AssStyle * > ( * cur ) ) {
c - > ass - > Line . insert ( cur , styls [ curn ] ) ;
2011-01-16 08:17:36 +01:00
c - > ass - > Line . erase ( cur ) ;
2006-12-26 22:45:23 +01:00
curn + + ;
}
}
2011-09-15 07:16:32 +02:00
c - > ass - > Commit ( _ ( " style move " ) , AssFile : : COMMIT_STYLES ) ;
2006-12-26 22:45:23 +01:00
}
2012-02-01 01:48:50 +01:00
for ( int i = 0 ; i < ( int ) styls . size ( ) ; + + i ) {
list - > SetString ( i , styls [ i ] - > name ) ;
if ( i < first | | i > last )
list - > Deselect ( i ) ;
else
list - > Select ( i ) ;
2006-12-26 22:45:23 +01:00
}
2012-02-01 01:48:50 +01:00
UpdateButtons ( ) ;
2006-12-26 22:45:23 +01:00
}
2007-02-05 20:09:45 +01:00
void DialogStyleManager : : OnKeyDown ( wxKeyEvent & event ) {
2012-02-01 01:48:50 +01:00
wxWindow * focus = wxWindow : : FindFocus ( ) ;
2007-02-05 20:09:45 +01:00
switch ( event . GetKeyCode ( ) ) {
case WXK_DELETE :
2012-02-01 01:48:50 +01:00
if ( focus = = StorageList )
OnStorageDelete ( ) ;
else if ( focus = = CurrentList )
OnCurrentDelete ( ) ;
2007-02-05 20:09:45 +01:00
break ;
2007-02-06 04:25:14 +01:00
case ' C ' :
case ' c ' :
2007-09-22 00:56:44 +02:00
if ( event . CmdDown ( ) ) {
2012-02-01 01:48:50 +01:00
if ( focus = = StorageList )
CopyToClipboard ( StorageList , styleStorageMap ) ;
else if ( focus = = CurrentList )
CopyToClipboard ( CurrentList , styleMap ) ;
2007-02-06 04:25:14 +01:00
}
break ;
case ' V ' :
case ' v ' :
2007-09-22 00:56:44 +02:00
if ( event . CmdDown ( ) ) {
2012-02-01 01:48:50 +01:00
if ( focus = = StorageList )
2007-02-06 04:25:14 +01:00
PasteToStorage ( ) ;
2012-02-01 01:48:50 +01:00
else if ( focus = = CurrentList )
PasteToCurrent ( ) ;
2007-02-06 04:25:14 +01:00
}
2012-02-01 01:48:33 +01:00
break ;
default :
event . Skip ( ) ;
2007-02-06 04:25:14 +01:00
break ;
2007-02-05 20:09:45 +01:00
}
}