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/
/// @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"
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"
2013-06-09 16:53:07 +02:00
# include "charset_detect.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"
2013-01-07 02:50:09 +01:00
# include "options.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"
2013-01-26 02:57:46 +01:00
# include "subs_controller.h"
2012-10-12 05:08:38 +02:00
# include "subtitle_format.h"
2012-10-25 17:13:13 +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
2013-01-04 16:01:50 +01:00
# include <libaegisub/fs.h>
2013-01-30 04:35:37 +01:00
# include <libaegisub/path.h>
2012-11-05 17:20:58 +01:00
# include <libaegisub/of_type_adaptor.h>
2013-08-09 05:36:12 +02:00
# include <libaegisub/split.h>
2013-06-08 06:19:40 +02:00
# include <libaegisub/util.h>
2012-11-05 17:20:58 +01:00
2013-01-04 16:01:50 +01:00
# include <algorithm>
# include <boost/algorithm/string/trim.hpp>
# include <functional>
# include <wx/bmpbuttn.h>
# include <wx/filename.h>
2013-07-08 23:43:43 +02:00
# include <wx/fontenum.h>
2013-01-04 16:01:50 +01:00
# include <wx/intl.h>
# include <wx/msgdlg.h>
# include <wx/sizer.h>
# include <wx/textdlg.h>
# include <wx/choicdlg.h> // Keep this last so wxUSE_CHOICEDLG is set.
2012-09-25 01:35:27 +02:00
using std : : placeholders : : _1 ;
2012-03-07 23:40:15 +01:00
2012-03-08 05:17:36 +01:00
namespace {
wxBitmapButton * add_bitmap_button ( wxWindow * parent , wxSizer * sizer , wxBitmap const & img , wxString const & tooltip ) {
2012-02-01 01:48:50 +01:00
wxBitmapButton * btn = new wxBitmapButton ( parent , - 1 , img ) ;
btn - > SetToolTip ( tooltip ) ;
sizer - > Add ( btn , wxSizerFlags ( ) . Expand ( ) ) ;
return btn ;
}
2012-03-08 05:17:36 +01:00
wxSizer * make_move_buttons ( wxWindow * parent , wxButton * * up , wxButton * * down , wxButton * * top , wxButton * * bottom , wxButton * * sort ) {
2012-02-01 01:48:50 +01:00
wxSizer * sizer = new wxBoxSizer ( wxVERTICAL ) ;
sizer - > AddStretchSpacer ( 1 ) ;
2012-02-07 02:22:32 +01:00
* 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 " ) ) ;
2012-02-01 01:48:50 +01:00
sizer - > AddStretchSpacer ( 1 ) ;
return sizer ;
}
2012-03-08 05:17:36 +01:00
wxSizer * make_edit_buttons ( wxWindow * parent , wxString move_label , wxButton * * move , wxButton * * nw , wxButton * * edit , wxButton * * copy , wxButton * * del ) {
2012-02-01 01:48:50 +01:00
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 ;
}
2012-03-08 05:17:36 +01:00
template < class Func >
2012-12-30 01:32:36 +01:00
std : : string unique_name ( Func name_checker , std : : string const & source_name ) {
2012-03-08 05:17:36 +01:00
if ( name_checker ( source_name ) ) {
2012-12-30 01:32:36 +01:00
std : : string name = from_wx ( wxString : : Format ( _ ( " %s - Copy " ) , to_wx ( source_name ) ) ) ;
2012-03-08 05:17:36 +01:00
for ( int i = 2 ; name_checker ( name ) ; + + i )
2012-12-30 01:32:36 +01:00
name = from_wx ( wxString : : Format ( _ ( " %s - Copy (%d) " ) , to_wx ( source_name ) , i ) ) ;
2012-03-08 05:17:36 +01:00
return name ;
}
return source_name ;
}
template < class Func1 , class Func2 >
void add_styles ( Func1 name_checker , Func2 style_adder ) {
2013-08-09 05:36:12 +02:00
auto cb = GetClipboard ( ) ;
2013-12-23 15:50:30 +01:00
int failed_to_parse = 0 ;
2013-08-09 05:36:12 +02:00
for ( auto tok : agi : : Split ( cb , ' \n ' ) ) {
tok = boost : : trim_copy ( tok ) ;
if ( tok . empty ( ) ) continue ;
2012-03-08 05:17:36 +01:00
try {
2013-08-09 05:36:12 +02:00
AssStyle * s = new AssStyle ( agi : : str ( tok ) ) ;
2012-03-08 05:17:36 +01:00
s - > name = unique_name ( name_checker , s - > name ) ;
style_adder ( s ) ;
}
catch ( . . . ) {
2013-12-23 15:50:30 +01:00
+ + failed_to_parse ;
2012-03-08 05:17:36 +01:00
}
}
2013-12-23 15:50:30 +01:00
if ( failed_to_parse )
wxMessageBox ( _ ( " Could not parse style " ) , _ ( " Could not parse style " ) , wxOK | wxICON_EXCLAMATION ) ;
2012-03-08 05:17:36 +01:00
}
int confirm_delete ( int n , wxWindow * parent , wxString const & title ) {
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 ) ;
return wxMessageBox ( message , title , wxYES_NO | wxICON_EXCLAMATION , parent ) ;
}
int get_single_sel ( wxListBox * lb ) {
wxArrayInt selections ;
int n = lb - > GetSelections ( selections ) ;
return n = = 1 ? selections [ 0 ] : - 1 ;
}
}
2012-02-01 01:48:50 +01:00
DialogStyleManager : : DialogStyleManager ( agi : : Context * context )
2012-02-07 21:42:44 +01:00
: wxDialog ( context - > parent , - 1 , _ ( " Styles Manager " ) )
2011-01-16 08:17:36 +01:00
, c ( context )
2012-03-08 05:17:36 +01:00
, commit_connection ( c - > ass - > AddCommitListener ( & DialogStyleManager : : LoadCurrentStyles , this ) )
2012-10-05 05:22:54 +02:00
, active_line_connection ( c - > selectionController - > AddActiveLineListener ( & DialogStyleManager : : OnActiveLineChanged , this ) )
2013-07-08 23:43:43 +02:00
, font_list ( std : : async ( std : : launch : : async , [ ] ( ) - > wxArrayString {
wxArrayString fontList = wxFontEnumerator : : GetFacenames ( ) ;
fontList . Sort ( ) ;
return fontList ;
} ) )
2006-01-16 22:02:54 +01:00
{
2012-09-25 01:35:27 +02:00
using std : : bind ;
2012-04-03 22:40:24 +02:00
SetIcon ( GETICON ( style_toolbutton_16 ) ) ;
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-11-13 17:51:01 +01:00
CatalogList = new wxComboBox ( this , - 1 , " " , wxDefaultPosition , wxSize ( - 1 , - 1 ) , 0 , nullptr , wxCB_READONLY ) ;
2012-02-01 01:48:50 +01:00
wxButton * CatalogNew = new wxButton ( this , - 1 , _ ( " New " ) ) ;
2012-03-08 05:17:17 +01:00
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-11-13 17:51:01 +01:00
StorageList = new wxListBox ( this , - 1 , wxDefaultPosition , wxSize ( 240 , 250 ) , 0 , nullptr , 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 ) ;
2012-11-13 17:51:01 +01:00
CurrentList = new wxListBox ( this , - 1 , wxDefaultPosition , wxSize ( 240 , 250 ) , 0 , nullptr , 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 " ) ) ;
2013-12-12 03:25:13 +01:00
Bind ( wxEVT_BUTTON , 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
2012-02-01 01:48:50 +01:00
SetSizerAndFit ( MainSizer ) ;
2006-01-16 22:02:54 +01:00
// Position window
2013-06-10 15:58:13 +02:00
persist = agi : : util : : make_unique < PersistLocation > ( this , " Tool/Style Manager " ) ;
2006-01-16 22:02:54 +01:00
// Populate lists
LoadCatalog ( ) ;
2012-03-08 05:17:36 +01:00
LoadCurrentStyles ( AssFile : : COMMIT_STYLES | AssFile : : COMMIT_DIAG_META ) ;
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
2013-12-12 03:25:13 +01:00
StorageMoveUp - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , true , 0 ) ) ;
StorageMoveTop - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , true , 1 ) ) ;
StorageMoveDown - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , true , 2 ) ) ;
StorageMoveBottom - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , true , 3 ) ) ;
StorageSort - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , true , 4 ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
CurrentMoveUp - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , false , 0 ) ) ;
CurrentMoveTop - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , false , 1 ) ) ;
CurrentMoveDown - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , false , 2 ) ) ;
CurrentMoveBottom - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , false , 3 ) ) ;
CurrentSort - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : MoveStyles , this , false , 4 ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
CatalogNew - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCatalogNew , this ) ) ;
CatalogDelete - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCatalogDelete , this ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
StorageNew - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnStorageNew , this ) ) ;
StorageEdit - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnStorageEdit , this ) ) ;
StorageCopy - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnStorageCopy , this ) ) ;
StorageDelete - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnStorageDelete , this ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
CurrentNew - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCurrentNew , this ) ) ;
CurrentEdit - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCurrentEdit , this ) ) ;
CurrentCopy - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCurrentCopy , this ) ) ;
CurrentDelete - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCurrentDelete , this ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
CurrentImport - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCurrentImport , this ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
MoveToLocal - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCopyToCurrent , this ) ) ;
MoveToStorage - > Bind ( wxEVT_BUTTON , bind ( & DialogStyleManager : : OnCopyToStorage , this ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
CatalogList - > Bind ( wxEVT_COMBOBOX , bind ( & DialogStyleManager : : OnChangeCatalog , this ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
StorageList - > Bind ( wxEVT_LISTBOX , bind ( & DialogStyleManager : : UpdateButtons , this ) ) ;
StorageList - > Bind ( wxEVT_LISTBOX_DCLICK , bind ( & DialogStyleManager : : OnStorageEdit , this ) ) ;
2012-02-01 01:48:50 +01:00
2013-12-12 03:25:13 +01:00
CurrentList - > Bind ( wxEVT_LISTBOX , bind ( & DialogStyleManager : : UpdateButtons , this ) ) ;
CurrentList - > Bind ( wxEVT_LISTBOX_DCLICK , bind ( & DialogStyleManager : : OnCurrentEdit , this ) ) ;
2006-01-16 22:02:54 +01:00
}
DialogStyleManager : : ~ DialogStyleManager ( ) {
}
2012-03-08 05:17:36 +01:00
void DialogStyleManager : : LoadCurrentStyles ( int commit_type ) {
if ( commit_type & AssFile : : COMMIT_STYLES | | commit_type = = AssFile : : COMMIT_NEW ) {
CurrentList - > Clear ( ) ;
styleMap . clear ( ) ;
2012-11-05 17:20:58 +01:00
for ( auto style : c - > ass - > Line | agi : : of_type < AssStyle > ( ) ) {
2012-12-30 01:32:36 +01:00
CurrentList - > Append ( to_wx ( style - > name ) ) ;
2012-11-05 17:20:58 +01:00
styleMap . push_back ( style ) ;
2012-03-08 05:17:36 +01:00
}
}
if ( commit_type & AssFile : : COMMIT_DIAG_META ) {
AssDialogue * dia = c - > selectionController - > GetActiveLine ( ) ;
2012-03-08 05:17:42 +01:00
CurrentList - > DeselectAll ( ) ;
2012-03-08 05:17:36 +01:00
if ( dia & & commit_type ! = AssFile : : COMMIT_NEW )
2013-01-04 16:01:50 +01:00
CurrentList - > SetStringSelection ( to_wx ( dia - > Style ) ) ;
2012-03-08 05:17:36 +01:00
else
CurrentList - > SetSelection ( 0 ) ;
}
UpdateButtons ( ) ;
}
2012-03-08 05:17:42 +01:00
void DialogStyleManager : : OnActiveLineChanged ( AssDialogue * new_line ) {
if ( new_line ) {
CurrentList - > DeselectAll ( ) ;
2013-01-04 16:01:50 +01:00
CurrentList - > SetStringSelection ( to_wx ( new_line - > Style ) ) ;
2012-03-08 05:17:42 +01:00
UpdateButtons ( ) ;
}
}
2012-03-08 05:17:36 +01:00
void DialogStyleManager : : UpdateStorage ( ) {
Store . Save ( ) ;
StorageList - > Clear ( ) ;
2012-12-30 01:32:36 +01:00
StorageList - > Append ( to_wx ( Store . GetNames ( ) ) ) ;
2012-03-08 05:17:36 +01:00
UpdateButtons ( ) ;
}
void DialogStyleManager : : OnChangeCatalog ( ) {
2013-01-04 16:01:50 +01:00
std : : string catalog ( from_wx ( CatalogList - > GetStringSelection ( ) ) ) ;
c - > ass - > SetScriptInfo ( " Last Style Storage " , catalog ) ;
2013-02-07 17:31:08 +01:00
Store . Load ( config : : path - > Decode ( " ?user/catalog/ " + catalog + " .sty " ) ) ;
2012-03-08 05:17:36 +01:00
UpdateStorage ( ) ;
}
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
2013-01-30 04:35:37 +01:00
for ( auto const & file : agi : : fs : : DirectoryIterator ( config : : path - > Decode ( " ?user/catalog/ " ) , " *.sty " ) )
2013-01-04 16:01:50 +01:00
CatalogList - > Append ( agi : : fs : : path ( file ) . stem ( ) . wstring ( ) ) ;
2012-02-01 01:48:50 +01:00
// Create a default storage if there are none
2012-05-13 02:57:34 +02:00
if ( CatalogList - > IsListEmpty ( ) ) {
2013-02-07 17:31:08 +01:00
Store . Load ( config : : path - > Decode ( " ?user/catalog/Default.sty " ) ) ;
2013-06-08 06:19:40 +02:00
Store . push_back ( agi : : util : : make_unique < AssStyle > ( ) ) ;
2012-05-13 02:57:34 +02:00
Store . Save ( ) ;
2012-02-01 01:48:50 +01:00
CatalogList - > Append ( " Default " ) ;
2012-05-13 02:57:34 +02:00
}
2006-01-16 22:02:54 +01:00
// Set to default if available
2013-01-04 16:01:50 +01:00
std : : string pickStyle = c - > ass - > GetScriptInfo ( " Last Style Storage " ) ;
2012-02-01 01:48:50 +01:00
if ( pickStyle . empty ( ) )
pickStyle = " Default " ;
2013-01-04 16:01:50 +01:00
int opt = CatalogList - > FindString ( to_wx ( pickStyle ) , false ) ;
2012-03-08 05:17:17 +01:00
if ( opt ! = wxNOT_FOUND )
2006-01-16 22:02:54 +01:00
CatalogList - > SetSelection ( opt ) ;
2012-03-08 05:17:17 +01:00
else
CatalogList - > SetSelection ( 0 ) ;
OnChangeCatalog ( ) ;
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 ) ;
2012-03-08 05:17:36 +01:00
if ( ! name ) return ;
// Remove bad characters from the name
2012-05-15 15:40:10 +02:00
wxString badchars = wxFileName : : GetForbiddenChars ( wxPATH_DOS ) ;
2012-03-08 05:17:36 +01:00
int badchars_removed = 0 ;
2012-11-04 04:53:03 +01:00
for ( wxUniCharRef chr : name ) {
if ( badchars . find ( chr ) ! = badchars . npos ) {
chr = ' _ ' ;
2012-03-08 05:17:36 +01:00
+ + badchars_removed ;
2006-11-23 20:08:46 +01:00
}
2012-03-08 05:17:36 +01:00
}
2006-11-23 20:08:46 +01:00
2012-03-08 05:17:36 +01: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 ) {
2012-03-29 01:59:19 +02:00
wxMessageBox ( _ ( " A catalog with that name already exists. " ) , _ ( " Catalog name conflict " ) , wxOK | wxICON_ERROR | wxCENTER ) ;
2012-03-08 05:17:36 +01:00
return ;
}
2006-01-16 22:02:54 +01:00
2012-03-08 05:17:36 +01:00
// Warn about bad characters
if ( badchars_removed ) {
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-01-16 22:02:54 +01:00
}
2012-03-08 05:17:36 +01:00
// Add to list of storages
CatalogList - > Append ( name ) ;
CatalogList - > SetStringSelection ( name ) ;
OnChangeCatalog ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnCatalogDelete ( ) {
2012-03-08 05:17:17 +01:00
if ( CatalogList - > GetCount ( ) = = 1 ) return ;
wxString name = CatalogList - > GetStringSelection ( ) ;
wxString message = wxString : : Format ( _ ( " Are you sure you want to delete the storage \" %s \" from the catalog? " ) , name ) ;
int option = wxMessageBox ( message , _ ( " Confirm delete " ) , wxYES_NO | wxICON_EXCLAMATION , this ) ;
if ( option = = wxYES ) {
2013-01-30 04:35:37 +01:00
agi : : fs : : Remove ( config : : path - > Decode ( " ?user/catalog/ " + from_wx ( name ) + " .sty " ) ) ;
2012-03-08 05:17:17 +01:00
CatalogList - > Delete ( CatalogList - > GetSelection ( ) ) ;
CatalogList - > SetSelection ( 0 ) ;
OnChangeCatalog ( ) ;
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
wxArrayInt selections ;
int n = CurrentList - > GetSelections ( selections ) ;
2012-11-28 16:46:33 +01:00
wxArrayString copied ;
copied . reserve ( n ) ;
2009-07-18 04:52:46 +02:00
for ( int i = 0 ; i < n ; i + + ) {
wxString styleName = CurrentList - > GetString ( selections [ i ] ) ;
2012-02-01 01:48:24 +01:00
2012-12-30 01:32:36 +01:00
if ( AssStyle * style = Store . GetStyle ( from_wx ( styleName ) ) ) {
if ( wxYES = = wxMessageBox ( wxString : : Format ( _ ( " There is already a style with the name \" %s \" in the current storage. Overwrite? " ) , styleName ) , _ ( " Style name collision " ) , wxYES_NO ) ) {
2012-02-01 01:48:24 +01:00
* 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
}
2012-03-08 05:17:36 +01:00
else {
2013-06-08 06:19:40 +02:00
Store . push_back ( agi : : util : : make_unique < 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
}
}
2012-03-08 05:17:29 +01:00
UpdateStorage ( ) ;
2012-11-04 04:53:03 +01:00
for ( auto const & style_name : copied )
StorageList - > SetStringSelection ( style_name , true ) ;
2012-03-08 05:17:29 +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 : : OnCopyToCurrent ( ) {
2006-01-16 22:02:54 +01:00
wxArrayInt selections ;
int n = StorageList - > GetSelections ( selections ) ;
2012-11-28 16:46:33 +01:00
wxArrayString copied ;
copied . reserve ( n ) ;
2009-07-18 04:52:46 +02:00
for ( int i = 0 ; i < n ; i + + ) {
wxString styleName = StorageList - > GetString ( selections [ i ] ) ;
2012-12-30 01:32:36 +01:00
if ( AssStyle * style = c - > ass - > GetStyle ( from_wx ( styleName ) ) ) {
if ( wxYES = = wxMessageBox ( wxString : : Format ( _ ( " There is already a style with the name \" %s \" in the current script. Overwrite? " ) , styleName ) , _ ( " Style name collision " ) , wxYES_NO ) ) {
* style = * Store [ selections [ i ] ] ;
copied . push_back ( styleName ) ;
2009-07-18 04:52:46 +02:00
}
2006-12-17 21:30:59 +01:00
}
2012-12-30 01:32:36 +01:00
else {
2012-11-22 17:14:34 +01:00
c - > ass - > InsertLine ( new AssStyle ( * Store [ selections [ i ] ] ) ) ;
2010-04-24 23:48:06 +02:00
copied . push_back ( styleName ) ;
2006-01-16 22:02:54 +01:00
}
}
2012-03-08 05:17:36 +01:00
c - > ass - > Commit ( _ ( " style copy " ) , AssFile : : COMMIT_STYLES ) ;
2012-03-07 23:40:15 +01:00
2012-03-08 05:17:36 +01:00
CurrentList - > DeselectAll ( ) ;
2012-11-04 04:53:03 +01:00
for ( auto const & style_name : copied )
CurrentList - > SetStringSelection ( style_name , true ) ;
2012-03-08 05:17:36 +01:00
UpdateButtons ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-03-08 05:17:29 +01:00
template < class T >
void DialogStyleManager : : CopyToClipboard ( wxListBox * list , T const & v ) {
2007-02-06 04:25:14 +01:00
wxArrayInt selections ;
list - > GetSelections ( selections ) ;
2013-08-09 05:18:12 +02:00
std : : string data ;
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 ( ) ;
2013-08-09 05:18:12 +02:00
data + = s - > GetEntryData ( ) ;
2007-02-06 04:25:14 +01:00
}
2012-10-25 17:13:13 +02:00
SetClipboard ( data ) ;
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 (
2012-09-25 03:15:20 +02:00
std : : bind ( & AssFile : : GetStyle , c - > ass , _1 ) ,
2012-11-22 17:14:34 +01:00
std : : bind ( & AssFile : : InsertLine , c - > ass , _1 ) ) ;
2007-02-06 04:25:14 +01:00
2012-02-01 01:48:50 +01:00
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 (
2012-09-25 03:15:20 +02:00
std : : bind ( & AssStyleStorage : : GetStyle , & Store , _1 ) ,
2013-06-08 06:19:40 +02:00
[ = ] ( AssStyle * s ) { Store . push_back ( std : : unique_ptr < AssStyle > ( s ) ) ; } ) ;
2007-09-02 21:31:17 +02:00
2012-03-08 05:17:29 +01:00
UpdateStorage ( ) ;
2012-12-30 01:32:36 +01:00
StorageList - > SetStringSelection ( to_wx ( Store . back ( ) - > name ) ) ;
2012-03-08 05:17:29 +01:00
UpdateButtons ( ) ;
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-12-30 01:32:36 +01:00
void DialogStyleManager : : ShowStorageEditor ( AssStyle * style , std : : string const & new_name ) {
2013-07-08 23:43:43 +02:00
DialogStyleEditor editor ( this , style , c , & Store , new_name , font_list . get ( ) ) ;
2012-03-08 05:17:36 +01:00
if ( editor . ShowModal ( ) ) {
UpdateStorage ( ) ;
2012-12-30 01:32:36 +01:00
StorageList - > SetStringSelection ( to_wx ( editor . GetStyleName ( ) ) ) ;
2012-03-08 05:17:36 +01:00
UpdateButtons ( ) ;
}
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : OnStorageNew ( ) {
2013-07-08 23:43:43 +02:00
ShowStorageEditor ( nullptr ) ;
2006-01-16 22:02:54 +01:00
}
2012-03-08 05:17:36 +01:00
void DialogStyleManager : : OnStorageEdit ( ) {
int sel = get_single_sel ( StorageList ) ;
if ( sel = = - 1 ) return ;
ShowStorageEditor ( Store [ sel ] ) ;
2006-01-16 22:02:54 +01:00
}
2012-03-08 05:17:36 +01:00
void DialogStyleManager : : OnStorageCopy ( ) {
int sel = get_single_sel ( StorageList ) ;
if ( sel = = - 1 ) return ;
ShowStorageEditor ( Store [ sel ] ,
2012-09-25 03:15:20 +02:00
unique_name ( std : : bind ( & AssStyleStorage : : GetStyle , & Store , _1 ) , Store [ sel ] - > name ) ) ;
2012-02-01 01:48:50 +01:00
}
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 ) {
2012-03-08 05:17:29 +01:00
for ( int i = 0 ; i < n ; i + + )
Store . Delete ( selections [ i ] - i ) ;
UpdateStorage ( ) ;
2006-01-16 22:02:54 +01:00
}
}
2012-12-30 01:32:36 +01:00
void DialogStyleManager : : ShowCurrentEditor ( AssStyle * style , std : : string const & new_name ) {
2013-07-08 23:43:43 +02:00
DialogStyleEditor editor ( this , style , c , nullptr , new_name , font_list . get ( ) ) ;
2012-03-08 05:17:36 +01:00
if ( editor . ShowModal ( ) ) {
CurrentList - > DeselectAll ( ) ;
2012-12-30 01:32:36 +01:00
CurrentList - > SetStringSelection ( to_wx ( editor . GetStyleName ( ) ) ) ;
2012-03-08 05:17:36 +01:00
UpdateButtons ( ) ;
}
}
void DialogStyleManager : : OnCurrentNew ( ) {
2013-07-08 23:43:43 +02:00
ShowCurrentEditor ( nullptr ) ;
2012-03-08 05:17:36 +01:00
}
void DialogStyleManager : : OnCurrentEdit ( ) {
int sel = get_single_sel ( CurrentList ) ;
if ( sel = = - 1 ) return ;
ShowCurrentEditor ( styleMap [ sel ] ) ;
}
void DialogStyleManager : : OnCurrentCopy ( ) {
int sel = get_single_sel ( CurrentList ) ;
if ( sel = = - 1 ) return ;
ShowCurrentEditor ( styleMap [ sel ] ,
2012-09-25 03:15:20 +02:00
unique_name ( std : : bind ( & AssFile : : GetStyle , c - > ass , _1 ) , styleMap [ sel ] - > name ) ) ;
2012-03-08 05:17:36 +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 ) {
2012-10-12 19:16:39 +02:00
for ( int i = 0 ; i < n ; i + + ) {
delete styleMap . at ( selections [ i ] ) ;
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
void DialogStyleManager : : OnCurrentImport ( ) {
2013-01-22 05:27:56 +01:00
auto filename = OpenFileSelector ( _ ( " Open subtitles file " ) , " Path/Last/Subtitles " , " " , " " , SubtitleFormat : : GetWildcards ( 0 ) , this ) ;
if ( filename . empty ( ) ) return ;
2006-12-26 05:48:53 +01:00
2013-06-09 16:53:07 +02:00
std : : string charset ;
try {
charset = CharSetDetect : : GetEncoding ( filename ) ;
}
catch ( agi : : UserCancelException const & ) {
return ;
}
2012-03-08 05:17:36 +01:00
AssFile temp ;
try {
2013-10-05 15:58:15 +02:00
auto reader = SubtitleFormat : : GetReader ( filename , charset ) ;
2013-01-26 02:57:46 +01:00
if ( ! reader )
wxMessageBox ( " Unsupported subtitle format " , " Error " , wxOK | wxICON_ERROR | wxCENTER , this ) ;
else
2013-06-09 16:53:07 +02:00
reader - > ReadFile ( & temp , filename , charset ) ;
2012-03-08 05:17:36 +01:00
}
2012-10-12 05:18:47 +02:00
catch ( agi : : Exception const & err ) {
2012-12-23 00:18:38 +01:00
wxMessageBox ( to_wx ( err . GetChainedMessage ( ) ) , " Error " , wxOK | wxICON_ERROR | wxCENTER , this ) ;
2012-10-12 05:18:47 +02:00
}
2012-03-08 05:17:36 +01:00
catch ( . . . ) {
2012-10-12 05:18:47 +02:00
wxMessageBox ( " Unknown error " , " Error " , wxOK | wxICON_ERROR | wxCENTER , this ) ;
2012-03-08 05:17:36 +01:00
return ;
}
2006-12-26 05:48:53 +01:00
2012-03-08 05:17:36 +01:00
// Get styles
2013-01-22 05:27:56 +01:00
auto styles = temp . GetStyles ( ) ;
2012-03-08 05:17:36 +01:00
if ( styles . empty ( ) ) {
wxMessageBox ( _ ( " The selected file has no available styles. " ) , _ ( " Error Importing Styles " ) ) ;
return ;
}
2006-12-26 05:48:53 +01:00
2012-03-08 05:17:36 +01:00
// Get selection
wxArrayInt selections ;
2012-12-30 01:32:36 +01:00
int res = GetSelectedChoices ( this , selections , _ ( " Choose styles to import: " ) , _ ( " Import Styles " ) , to_wx ( styles ) ) ;
2012-03-08 05:17:36 +01:00
if ( res = = - 1 | | selections . empty ( ) ) return ;
bool modified = false ;
// Loop through selection
2012-11-04 04:53:03 +01:00
for ( auto const & sel : selections ) {
2012-03-08 05:17:36 +01:00
// Check if there is already a style with that name
2012-12-30 01:32:36 +01:00
if ( AssStyle * existing = c - > ass - > GetStyle ( styles [ sel ] ) ) {
2012-03-08 05:17:36 +01:00
int answer = wxMessageBox (
2012-11-04 04:53:03 +01:00
wxString : : Format ( _ ( " There is already a style with the name \" %s \" in the current script. Overwrite? " ) , styles [ sel ] ) ,
2012-03-08 05:17:36 +01:00
_ ( " Style name collision " ) ,
wxYES_NO ) ;
if ( answer = = wxYES ) {
2006-12-26 05:48:53 +01:00
modified = true ;
2012-12-30 01:32:36 +01:00
* existing = * temp . GetStyle ( styles [ sel ] ) ;
2006-12-26 05:48:53 +01:00
}
2012-03-08 05:17:36 +01:00
continue ;
2006-12-26 05:48:53 +01:00
}
2012-03-08 05:17:36 +01:00
// Copy
modified = true ;
2012-12-30 01:32:36 +01:00
c - > ass - > InsertLine ( temp . GetStyle ( styles [ sel ] ) - > Clone ( ) ) ;
2006-12-26 05:48:53 +01:00
}
2012-03-08 05:17:36 +01:00
// Update
if ( modified )
c - > ass - > Commit ( _ ( " style import " ) , AssFile : : COMMIT_STYLES ) ;
2006-12-26 05:48:53 +01:00
}
2012-02-01 01:48:50 +01:00
void DialogStyleManager : : UpdateButtons ( ) {
2012-03-08 05:17:17 +01:00
CatalogDelete - > Enable ( CatalogList - > GetCount ( ) > 1 ) ;
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
}
2013-06-08 06:19:40 +02:00
struct cmp_name {
template < typename T >
bool operator ( ) ( T const & lft , T const & rgt ) const { return lft - > name < rgt - > name ; }
} ;
2012-03-08 05:17:29 +01:00
template < class Cont >
static void do_move ( Cont & styls , int type , int & first , int & last , bool storage ) {
2012-12-23 00:35:13 +01:00
auto begin = styls . begin ( ) ;
2006-12-26 22:45:23 +01:00
// Move up
if ( type = = 0 ) {
2012-03-08 05:17:29 +01:00
if ( first = = 0 ) return ;
rotate ( begin + first - 1 , begin + first , begin + last + 1 ) ;
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 ) {
2012-03-08 05:17:29 +01:00
rotate ( begin , begin + first , begin + last + 1 ) ;
2012-02-01 01:48:50 +01:00
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 ) {
2012-03-09 01:23:53 +01:00
if ( last + 1 = = ( int ) styls . size ( ) ) return ;
2012-03-08 05:17:29 +01:00
rotate ( begin + first , begin + last + 1 , begin + last + 2 ) ;
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 ) {
2012-03-08 05:17:29 +01:00
rotate ( begin + first , begin + last + 1 , styls . end ( ) ) ;
2012-02-01 01:48:50 +01:00
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 ) {
2012-03-29 01:59:19 +02:00
int res = wxMessageBox ( _ ( " Are you sure? This cannot be undone! " ) , _ ( " Sort styles " ) , wxYES_NO | wxCENTER ) ;
2006-12-26 23:28:44 +01:00
if ( res = = wxNO ) return ;
}
2013-06-08 06:19:40 +02:00
sort ( styls . begin ( ) , styls . end ( ) , cmp_name ( ) ) ;
2006-12-26 23:28:44 +01:00
first = 0 ;
last = 0 ;
}
2012-03-08 05:17:29 +01:00
}
void DialogStyleManager : : MoveStyles ( bool storage , int type ) {
wxListBox * list = storage ? StorageList : CurrentList ;
// Get selection
wxArrayInt sels ;
int n = list - > GetSelections ( sels ) ;
if ( n = = 0 & & type ! = 4 ) return ;
2012-03-29 01:59:10 +02:00
int first = 0 , last = 0 ;
if ( n ) {
first = sels . front ( ) ;
last = sels . back ( ) ;
}
2006-12-26 23:28:44 +01:00
2006-12-26 22:45:23 +01:00
if ( storage ) {
2012-03-08 05:17:29 +01:00
do_move ( Store , type , first , last , true ) ;
UpdateStorage ( ) ;
2006-12-26 22:45:23 +01:00
}
else {
2012-03-08 05:17:29 +01:00
do_move ( styleMap , type , first , last , false ) ;
2006-12-26 22:45:23 +01:00
// Replace styles
2013-01-04 16:01:50 +01:00
size_t curn = 0 ;
2012-11-21 16:32:04 +01:00
for ( auto it = c - > ass - > Line . begin ( ) ; it ! = c - > ass - > Line . end ( ) ; + + it ) {
if ( ! dynamic_cast < AssStyle * > ( & * it ) ) continue ;
auto new_style_at_pos = c - > ass - > Line . iterator_to ( * styleMap [ curn ] ) ;
EntryList : : node_algorithms : : swap_nodes ( it . pointed_node ( ) , new_style_at_pos . pointed_node ( ) ) ;
if ( + + curn = = styleMap . size ( ) ) break ;
it = new_style_at_pos ;
2006-12-26 22:45:23 +01:00
}
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-03-08 05:17:29 +01:00
for ( int i = 0 ; i < ( int ) list - > GetCount ( ) ; + + i ) {
2012-02-01 01:48:50 +01:00
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 )
2012-03-08 05:17:29 +01:00
CopyToClipboard ( StorageList , Store ) ;
2012-02-01 01:48:50 +01:00
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
}
}