1
// -------------------------------------------------------------------------------- //
2
// Copyright (C) 2008-2013 J.Rios
5
// This Program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 3, or (at your option)
10
// This Program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; see the file LICENSE. If not, write to
17
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
// http://www.gnu.org/copyleft/gpl.html
20
// -------------------------------------------------------------------------------- //
21
#include "FileBrowser.h"
23
#include "Accelerators.h"
24
#include "AuiDockArt.h"
26
#include "FileRenamer.h"
28
#include "LibUpdate.h"
29
#include "MainFrame.h"
30
#include "PlayListAppend.h"
32
#include "TrackEdit.h"
35
#include <wx/aui/aui.h>
36
#include <wx/arrimpl.cpp>
37
#include <wx/artprov.h>
38
#include <wx/clipbrd.h>
40
WX_DEFINE_OBJARRAY(guFileItemArray);
42
// -------------------------------------------------------------------------------- //
43
guMediaViewer * FindMediaViewerByPath( guMainFrame * mainframe, const wxString curpath )
45
const guMediaCollectionArray &Collections = mainframe->GetMediaCollections();
47
int Count = Collections.Count();
48
for( Index = 0; Index < Count; Index++ )
50
const guMediaCollection & Collection = Collections[ Index ];
51
if( mainframe->IsCollectionActive( Collection.m_UniqueId ) )
54
int PathCount = Collection.m_Paths.Count();
55
for( PathIndex = 0; PathIndex < PathCount; PathIndex++ )
57
guLogMessage( wxT( "%s == %s" ), curpath.c_str(), Collection.m_Paths[ PathIndex ].c_str() );
58
if( curpath.StartsWith( Collection.m_Paths[ PathIndex ] ) )
60
return mainframe->FindCollectionMediaViewer( Collection.m_UniqueId );
68
// -------------------------------------------------------------------------------- //
70
// -------------------------------------------------------------------------------- //
71
BEGIN_EVENT_TABLE(guGenericDirCtrl, wxGenericDirCtrl)
72
EVT_TREE_BEGIN_LABEL_EDIT( wxID_ANY, guGenericDirCtrl::OnBeginRenameDir )
73
EVT_TREE_END_LABEL_EDIT( wxID_ANY, guGenericDirCtrl::OnEndRenameDir )
76
// -------------------------------------------------------------------------------- //
77
guGenericDirCtrl::guGenericDirCtrl( wxWindow * parent, guMainFrame * mainframe, const int showpaths ) :
78
wxGenericDirCtrl( parent, wxID_ANY, wxDirDialogDefaultFolderStr,
79
wxDefaultPosition, wxDefaultSize, wxDIRCTRL_SELECT_FIRST|wxDIRCTRL_DIR_ONLY|wxDIRCTRL_3D_INTERNAL|wxNO_BORDER|wxDIRCTRL_EDIT_LABELS ,
80
wxEmptyString, 0, wxTreeCtrlNameStr )
82
m_MainFrame = mainframe;
83
m_ShowPaths = showpaths;
84
m_FileBrowserDirCtrl = ( guFileBrowserDirCtrl * ) parent;
85
wxImageList * ImageList = GetTreeCtrl()->GetImageList();
86
ImageList->Add( guImage( guIMAGE_INDEX_tiny_library ) );
87
ImageList->Add( guImage( guIMAGE_INDEX_tiny_podcast ) );
88
ImageList->Add( guImage( guIMAGE_INDEX_tiny_record ) );
90
guConfig * Config = ( guConfig * ) guConfig::Get();
91
Config->RegisterObject( this );
93
Connect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guGenericDirCtrl::OnConfigUpdated ), NULL, this );
96
// -------------------------------------------------------------------------------- //
97
guGenericDirCtrl::~guGenericDirCtrl()
99
guConfig * Config = ( guConfig * ) guConfig::Get();
100
Config->UnRegisterObject( this );
102
Disconnect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guGenericDirCtrl::OnConfigUpdated ), NULL, this );
105
// -------------------------------------------------------------------------------- //
106
void guGenericDirCtrl::OnConfigUpdated( wxCommandEvent &event )
108
int Flags = event.GetInt();
109
if( Flags & ( guPREFERENCE_PAGE_FLAG_LIBRARY | guPREFERENCE_PAGE_FLAG_RECORD | guPREFERENCE_PAGE_FLAG_PODCASTS ) )
111
if( m_ShowPaths != guFILEBROWSER_SHOWPATH_SYSTEM )
113
wxString CurPath = GetPath();
120
// -------------------------------------------------------------------------------- //
121
void guGenericDirCtrl::SetupSections()
123
guConfig * Config = ( guConfig * ) guConfig::Get();
125
if( m_ShowPaths & guFILEBROWSER_SHOWPATH_LOCATIONS )
127
const guMediaCollectionArray & Collections = m_MainFrame->GetMediaCollections();
129
int Count = Collections.Count();
130
for( Index = 0; Index < Count; Index++ )
132
const guMediaCollection & Collection = Collections[ Index ];
133
if( m_MainFrame->IsCollectionActive( Collection.m_UniqueId ) )
136
int PathCount = Collection.m_Paths.Count();
137
for( PathIndex = 0; PathIndex < PathCount; PathIndex++ )
139
wxString LibName = Collection.m_Paths[ PathIndex ];
140
if( LibName.EndsWith( wxT( "/" ) ) )
141
LibName.RemoveLast();
142
AddSection( LibName, wxFileNameFromPath( LibName ), guDIR_IMAGE_INDEX_LIBRARY );
147
wxString Path = Config->ReadStr( wxT( "Path" ), wxEmptyString, wxT( "podcasts" ) );
148
if( !Path.IsEmpty() )
150
wxString Name = Path;
151
if( Name.EndsWith( wxT( "/" ) ) )
153
AddSection( Path, wxFileNameFromPath( Name ), guDIR_IMAGE_INDEX_PODCASTS );
156
Path = Config->ReadStr( wxT( "Path" ), wxEmptyString, wxT( "record" ) );
157
if( !Path.IsEmpty() )
159
wxString Name = Path;
160
if( Name.EndsWith( wxT( "/" ) ) )
162
AddSection( Path, wxFileNameFromPath( Name ), guDIR_IMAGE_INDEX_RECORDS );
165
else //if( m_ShowPaths & guFILEBROWSER_SHOWPATH_SYSTEM )
167
AddSection( wxT( "/" ), wxT( "/" ), guDIR_IMAGE_INDEX_FOLDER );
171
// -------------------------------------------------------------------------------- //
172
void guGenericDirCtrl::OnBeginRenameDir( wxTreeEvent &event )
174
OnBeginEditItem( event );
177
// -------------------------------------------------------------------------------- //
178
void guGenericDirCtrl::OnEndRenameDir( wxTreeEvent &event )
180
OnEndEditItem( event );
181
wxTreeCtrl * TreeCtrl = GetTreeCtrl();
182
TreeCtrl->SelectItem( m_RenameItemId );
183
m_FileBrowserDirCtrl->RenamedDir( m_RenameName, GetPath() );
186
// -------------------------------------------------------------------------------- //
187
void guGenericDirCtrl::FolderRename( void )
189
wxTreeCtrl * TreeCtrl = GetTreeCtrl();
190
m_RenameItemId = TreeCtrl->GetSelection();
191
m_RenameName = GetPath();
192
TreeCtrl->EditLabel( m_RenameItemId );
195
// -------------------------------------------------------------------------------- //
196
// guFileBrowserDirCtrl
197
// -------------------------------------------------------------------------------- //
198
guFileBrowserDirCtrl::guFileBrowserDirCtrl( wxWindow * parent, guMainFrame * mainframe, guDbLibrary * db, const wxString &dirpath ) :
199
wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER )
201
m_MainFrame = mainframe;
204
m_MediaViewer = NULL;
205
m_AddingFolder = false;
207
guConfig * Config = ( guConfig * ) guConfig::Get();
208
Config->RegisterObject( this );
210
wxBoxSizer * MainSizer;
211
MainSizer = new wxBoxSizer( wxVERTICAL );
213
int ShowPaths = Config->ReadNum( wxT( "ShowLibPaths" ), guFILEBROWSER_SHOWPATH_LOCATIONS, wxT( "filebrowser" ) );
214
m_DirCtrl = new guGenericDirCtrl( this, m_MainFrame, ShowPaths );
215
m_DirCtrl->ShowHidden( false );
216
SetPath( dirpath, FindMediaViewerByPath( m_MainFrame, dirpath ) );
217
MainSizer->Add( m_DirCtrl, 1, wxEXPAND, 5 );
219
wxBoxSizer * DirBtnSizer = new wxBoxSizer( wxHORIZONTAL );
222
DirBtnSizer->Add( 0, 0, 1, wxEXPAND, 5 );
224
m_ShowLibPathsBtn = new wxToggleBitmapButton( this, wxID_ANY, guImage( guIMAGE_INDEX_tiny_library ), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
225
m_ShowLibPathsBtn->SetToolTip( ShowPaths == guFILEBROWSER_SHOWPATH_SYSTEM ?
226
_( "See used locations" ) :
227
_( "See system files" ) );
228
m_ShowLibPathsBtn->SetValue( ShowPaths & guFILEBROWSER_SHOWPATH_LOCATIONS );
229
DirBtnSizer->Add( m_ShowLibPathsBtn, 0, wxTOP|wxBOTTOM|wxRIGHT, 5 );
231
MainSizer->Add( DirBtnSizer, 0, wxEXPAND, 5 );
233
this->SetSizer( MainSizer );
236
m_DirCtrl->Connect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( guFileBrowserDirCtrl::OnContextMenu ), NULL, this );
237
m_ShowLibPathsBtn->Connect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( guFileBrowserDirCtrl::OnShowLibPathsClick ), NULL, this );
239
Connect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guFileBrowserDirCtrl::OnConfigUpdated ), NULL, this );
241
CreateAcceleratorTable();
244
// -------------------------------------------------------------------------------- //
245
guFileBrowserDirCtrl::~guFileBrowserDirCtrl()
247
guConfig * Config = ( guConfig * ) guConfig::Get();
248
Config->UnRegisterObject( this );
250
Config->WriteNum( wxT( "ShowLibPaths" ), m_ShowLibPathsBtn->GetValue(), wxT( "filebrowser" ) );
251
m_DirCtrl->Disconnect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( guFileBrowserDirCtrl::OnContextMenu ), NULL, this );
252
m_ShowLibPathsBtn->Disconnect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( guFileBrowserDirCtrl::OnShowLibPathsClick ), NULL, this );
254
Disconnect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guFileBrowserDirCtrl::OnConfigUpdated ), NULL, this );
257
// -------------------------------------------------------------------------------- //
258
void guFileBrowserDirCtrl::OnConfigUpdated( wxCommandEvent &event )
260
int Flags = event.GetInt();
261
if( Flags & guPREFERENCE_PAGE_FLAG_ACCELERATORS )
263
CreateAcceleratorTable();
267
// -------------------------------------------------------------------------------- //
268
void guFileBrowserDirCtrl::CreateAcceleratorTable( void )
270
wxAcceleratorTable AccelTable;
271
wxArrayInt AliasAccelCmds;
272
wxArrayInt RealAccelCmds;
274
AliasAccelCmds.Add( ID_PLAYER_PLAYLIST_SAVE );
275
AliasAccelCmds.Add( ID_PLAYER_PLAYLIST_EDITTRACKS );
276
AliasAccelCmds.Add( ID_TRACKS_PLAY );
277
AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ALL );
278
AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_TRACK );
279
AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ALBUM );
280
AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ARTIST );
282
RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_SAVEPLAYLIST );
283
RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_EDITTRACKS );
284
RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_PLAY );
285
RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL );
286
RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_TRACK );
287
RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALBUM );
288
RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ARTIST );
290
if( guAccelDoAcceleratorTable( AliasAccelCmds, RealAccelCmds, AccelTable ) )
292
SetAcceleratorTable( AccelTable );
296
// -------------------------------------------------------------------------------- //
297
void AppendFolderCommands( wxMenu * menu )
302
wxMenuItem * MenuItem;
304
SubMenu = new wxMenu();
306
guConfig * Config = ( guConfig * ) guConfig::Get();
307
wxArrayString Commands = Config->ReadAStr( wxT( "Exec" ), wxEmptyString, wxT( "commands/execs" ) );
308
wxArrayString Names = Config->ReadAStr( wxT( "Name" ), wxEmptyString, wxT( "commands/names" ) );
309
if( ( Count = Commands.Count() ) )
311
for( Index = 0; Index < Count; Index++ )
313
if( ( Commands[ Index ].Find( wxT( "{bc}" ) ) == wxNOT_FOUND ) )
315
MenuItem = new wxMenuItem( menu, ID_COMMANDS_BASE + Index, Names[ Index ], Commands[ Index ] );
316
SubMenu->Append( MenuItem );
320
SubMenu->AppendSeparator();
324
MenuItem = new wxMenuItem( SubMenu, ID_MENU_PREFERENCES_COMMANDS, _( "Preferences" ), _( "Add commands in preferences" ) );
325
SubMenu->Append( MenuItem );
327
menu->AppendSubMenu( SubMenu, _( "Commands" ) );
330
// -------------------------------------------------------------------------------- //
331
void guFileBrowserDirCtrl::OnContextMenu( wxTreeEvent &event )
334
wxMenuItem * MenuItem;
336
wxPoint Point = event.GetPoint();
338
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_PLAY,
339
wxString( _( "Play" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_PLAY ),
340
_( "Play the selected folder" ) );
341
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_player_tiny_light_play ) );
342
Menu.Append( MenuItem );
344
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL,
345
wxString( _( "Enqueue" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ALL ),
346
_( "Add the selected folder to playlist" ) );
347
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
348
Menu.Append( MenuItem );
350
wxMenu * EnqueueMenu = new wxMenu();
352
MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_TRACK,
353
wxString( _( "Current Track" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_TRACK ),
354
_( "Add current selected tracks to playlist after the current track" ) );
355
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
356
EnqueueMenu->Append( MenuItem );
358
MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALBUM,
359
wxString( _( "Current Album" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ALBUM ),
360
_( "Add current selected tracks to playlist after the current album" ) );
361
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
362
EnqueueMenu->Append( MenuItem );
364
MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ARTIST,
365
wxString( _( "Current Artist" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ARTIST ),
366
_( "Add current selected tracks to playlist after the current artist" ) );
367
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
368
EnqueueMenu->Append( MenuItem );
370
Menu.Append( wxID_ANY, _( "Enqueue After" ), EnqueueMenu );
372
Menu.AppendSeparator();
374
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_EDITTRACKS,
375
wxString( _( "Edit Tracks" ) ) + guAccelGetCommandKeyCodeString( ID_PLAYER_PLAYLIST_EDITTRACKS ),
376
_( "Edit the tracks in the selected folder" ) );
377
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit ) );
378
Menu.Append( MenuItem );
380
Menu.AppendSeparator();
382
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_SAVEPLAYLIST,
383
wxString( _( "Save to Playlist" ) ) + guAccelGetCommandKeyCodeString( ID_PLAYER_PLAYLIST_SAVE ),
384
_( "Add the tracks in the selected folder to a playlist" ) );
385
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_doc_save ) );
386
Menu.Append( MenuItem );
388
Menu.AppendSeparator();
390
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_COPY,
392
_( "Copy the selected folder to clipboard" ) );
393
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit_copy ) );
394
Menu.Append( MenuItem );
395
//MenuItem->Enable( false );
397
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_PASTE,
399
_( "Paste to the selected folder" ) );
400
Menu.Append( MenuItem );
401
wxTheClipboard->UsePrimarySelection( false );
402
if( wxTheClipboard->Open() )
404
if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
406
wxFileDataObject data;
407
MenuItem->Enable( wxTheClipboard->GetData( data ) );
409
wxTheClipboard->Close();
412
Menu.AppendSeparator();
414
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_NEW, _( "New Folder" ), _( "Create a new folder" ) );
415
Menu.Append( MenuItem );
417
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_RENAME, _( "Rename" ), _( "Rename the selected folder" ) );
418
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit ) );
419
Menu.Append( MenuItem );
421
MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_DELETE, _( "Remove" ), _( "Remove the selected folder" ) );
422
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit_clear ) );
423
Menu.Append( MenuItem );
425
Menu.AppendSeparator();
427
m_MainFrame->CreateCopyToMenu( &Menu );
429
AppendFolderCommands( &Menu );
431
PopupMenu( &Menu, Point );
435
// -------------------------------------------------------------------------------- //
436
void guFileBrowserDirCtrl::RenamedDir( const wxString &oldname, const wxString &newname )
438
guLogMessage( wxT( "'%s' -> '%s' (%i)" ), oldname.c_str(), newname.c_str(), m_Db != NULL );
442
wxTreeCtrl * TreeCtrl = m_DirCtrl->GetTreeCtrl();
443
if( newname.IsEmpty() )
445
TreeCtrl->Delete( TreeCtrl->GetSelection() );
447
//m_DirCtrl->ReCreateTree();
448
m_AddingFolder = false;
452
if( oldname != newname )
455
m_Db->UpdatePaths( oldname, newname );
457
m_DefaultDb->UpdatePaths( oldname, newname );
462
// -------------------------------------------------------------------------------- //
463
void guFileBrowserDirCtrl::FolderNew( void )
465
wxTreeCtrl * TreeCtrl = m_DirCtrl->GetTreeCtrl();
466
wxTreeItemId FolderParent = TreeCtrl->GetSelection();
467
if( FolderParent.IsOk() )
469
m_AddingFolder = true;
471
wxString NewDirName = GetPath() + _( "New Folder" );
473
while( wxDirExists( NewDirName ) )
475
NewDirName = GetPath() + _( "New Folder" );
476
NewDirName += wxString::Format( wxT( "%i" ), Index++ );
479
if( wxMkdir( NewDirName, 0770 ) )
481
TreeCtrl->Collapse( FolderParent );
482
//TreeCtrl->Expand( m_AddFolderParent );
483
if( m_DirCtrl->ExpandPath( NewDirName ) )
485
wxTreeItemId Selected = TreeCtrl->GetSelection();
486
if( Selected.IsOk() )
488
wxTextCtrl * TextCtrl = TreeCtrl->EditLabel( Selected );
491
TextCtrl->SetSelection( -1, -1 );
496
guLogMessage( wxT( "No Selected item" ) );
502
guLogError( wxT( "Could not create the new directory" ) );
507
// -------------------------------------------------------------------------------- //
508
bool RemoveDirItems( const wxString &path, wxArrayString * deletefiles )
511
wxString CurPath = path;
512
if( !CurPath.EndsWith( wxT( "/" ) ) )
513
CurPath += wxT( "/" );
514
//guLogMessage( wxT( "Deleting folder %s" ), CurPath.c_str() );
515
wxDir Dir( CurPath );
518
if( Dir.GetFirst( &FileName, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN | wxDIR_DIRS | wxDIR_DOTDOT ) )
521
if( FileName != wxT( "." ) && FileName != wxT( ".." ) )
523
if( wxDirExists( CurPath + FileName ) )
525
if( !RemoveDirItems( CurPath + FileName, deletefiles ) )
527
//guLogMessage( wxT( "Removing Dir: %s" ), ( CurPath + FileName ).c_str() );
528
if( !wxRmdir( CurPath + FileName ) )
533
//guLogMessage( wxT( "Removing file: %s" ), ( CurPath + FileName ).c_str() );
534
if( !wxRemoveFile( CurPath + FileName ) )
536
deletefiles->Add( CurPath + FileName );
539
} while( Dir.GetNext( &FileName ) );
546
// -------------------------------------------------------------------------------- //
547
void guFileBrowserDirCtrl::FolderDelete( void )
549
wxTreeCtrl * TreeCtrl = m_DirCtrl->GetTreeCtrl();
550
wxTreeItemId FolderId = TreeCtrl->GetSelection();
551
wxDirItemData * FolderData = ( wxDirItemData * ) TreeCtrl->GetItemData( FolderId );
552
if( wxMessageBox( _( "Are you sure to delete the selected path ?" ),
554
wxICON_QUESTION | wxYES_NO, this ) == wxYES )
556
wxArrayString DeleteFiles;
557
if( RemoveDirItems( FolderData->m_path, &DeleteFiles ) && wxRmdir( FolderData->m_path ) )
559
TreeCtrl->Delete( FolderId );
563
wxMessageBox( _( "Error deleting the folder " ) + FolderData->m_path,
564
_( "Error" ), wxICON_ERROR | wxOK, this );
568
m_Db->CleanFiles( DeleteFiles );
570
m_DefaultDb->CleanFiles( DeleteFiles );
575
// -------------------------------------------------------------------------------- //
576
void guFileBrowserDirCtrl::OnShowLibPathsClick( wxCommandEvent& event )
578
int ShowPaths = m_ShowLibPathsBtn->GetValue();
580
wxString CurPath = GetPath();
581
m_DirCtrl->SetShowPaths( ShowPaths );
582
m_DirCtrl->ReCreateTree();
583
m_DirCtrl->SetPath( CurPath );
585
m_ShowLibPathsBtn->SetToolTip( ShowPaths == guFILEBROWSER_SHOWPATH_SYSTEM ?
586
_( "See used locations" ) :
587
_( "See system files" ) );
591
// -------------------------------------------------------------------------------- //
592
void guFileBrowserDirCtrl::CollectionsUpdated( void )
594
if( m_DirCtrl->GetShowPaths() & guFILEBROWSER_SHOWPATH_LOCATIONS )
596
wxString CurPath = GetPath();
597
m_DirCtrl->ReCreateTree();
598
m_DirCtrl->SetPath( CurPath );
602
// -------------------------------------------------------------------------------- //
603
void guFileBrowserDirCtrl::SetPath( const wxString &path, guMediaViewer * mediaviewer )
605
guLogMessage( wxT( "guFileBrowserDirCtrl::SetPath( %s )" ), path.c_str() );
606
m_MediaViewer = mediaviewer;
607
m_Db = mediaviewer ? mediaviewer->GetDb() : NULL;
608
m_DirCtrl->SetPath( path );
611
// -------------------------------------------------------------------------------- //
612
void guFileBrowserDirCtrl::SetMediaViewer( guMediaViewer * mediaviewer )
614
m_MediaViewer = mediaviewer;
615
m_Db = mediaviewer ? mediaviewer->GetDb() : NULL;
618
// -------------------------------------------------------------------------------- //
620
// -------------------------------------------------------------------------------- //
621
bool guAddDirItems( const wxString &path, wxArrayString &files )
624
wxString CurPath = path;
625
if( !CurPath.EndsWith( wxT( "/" ) ) )
626
CurPath += wxT( "/" );
627
guLogMessage( wxT( "Searching in folder %s" ), CurPath.c_str() );
628
wxDir Dir( CurPath );
631
if( Dir.GetFirst( &FileName, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN | wxDIR_DIRS | wxDIR_DOTDOT ) )
634
if( FileName != wxT( "." ) && FileName != wxT( ".." ) )
636
if( wxDirExists( CurPath + FileName ) )
638
if( !guAddDirItems( CurPath + FileName, files ) )
643
files.Add( CurPath + FileName );
646
} while( Dir.GetNext( &FileName ) );
653
// -------------------------------------------------------------------------------- //
654
guFilesListBox::guFilesListBox( wxWindow * parent, guDbLibrary * db ) :
655
guListView( parent, wxLB_MULTIPLE | guLISTVIEW_COLUMN_SELECT | guLISTVIEW_COLUMN_SORTING | guLISTVIEW_ALLOWDRAG )
659
guConfig * Config = ( guConfig * ) guConfig::Get();
660
Config->RegisterObject( this );
662
m_Order = Config->ReadNum( wxT( "Order" ), 0, wxT( "filebrowser" ) );
663
m_OrderDesc = Config->ReadNum( wxT( "OrderDesc" ), false, wxT( "filebrowser" ) );
667
wxArrayString ColumnNames = GetColumnNames();
669
int count = ColumnNames.Count();
670
for( index = 0; index < count; index++ )
672
ColId = Config->ReadNum( wxString::Format( wxT( "Id%u" ), index ), index, wxT( "filebrowser/columns/ids" ) );
674
ColName = ColumnNames[ ColId ];
676
ColName += ( ( ColId == m_Order ) ? ( m_OrderDesc ? wxT( " ▼" ) : wxT( " ▲" ) ) : wxEmptyString );
678
guListViewColumn * Column = new guListViewColumn(
681
Config->ReadNum( wxString::Format( wxT( "Width%u" ), index ), 80, wxT( "filebrowser/columns/widths" ) ),
682
Config->ReadBool( wxString::Format( wxT( "Show%u" ), index ), true, wxT( "filebrowser/columns/shows" ) )
684
InsertColumn( Column );
687
Connect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guFilesListBox::OnConfigUpdated ), NULL, this );
689
CreateAcceleratorTable();
695
// -------------------------------------------------------------------------------- //
696
guFilesListBox::~guFilesListBox()
698
guConfig * Config = ( guConfig * ) guConfig::Get();
699
Config->UnRegisterObject( this );
701
wxArrayString ColumnNames = GetColumnNames();
703
int count = ColumnNames.Count();
704
for( index = 0; index < count; index++ )
706
Config->WriteNum( wxString::Format( wxT( "Id%u" ), index ),
707
( * m_Columns )[ index ].m_Id, wxT( "filebrowser/columns/ids" ) );
708
Config->WriteNum( wxString::Format( wxT( "Width%u" ), index ),
709
( * m_Columns )[ index ].m_Width, wxT( "filebrowser/columns/widths" ) );
710
Config->WriteBool( wxString::Format( wxT( "Show%u" ), index ),
711
( * m_Columns )[ index ].m_Enabled, wxT( "filebrowser/columns/shows" ) );
714
Config->WriteNum( wxT( "Order" ), m_Order, wxT( "filebrowser" ) );
715
Config->WriteBool( wxT( "OrderDesc" ), m_OrderDesc, wxT( "filebrowser" ) );
717
Disconnect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guFilesListBox::OnConfigUpdated ), NULL, this );
720
// -------------------------------------------------------------------------------- //
721
void guFilesListBox::OnConfigUpdated( wxCommandEvent &event )
723
int Flags = event.GetInt();
724
if( Flags & guPREFERENCE_PAGE_FLAG_ACCELERATORS )
726
CreateAcceleratorTable();
730
// -------------------------------------------------------------------------------- //
731
void guFilesListBox::CreateAcceleratorTable( void )
733
wxAcceleratorTable AccelTable;
734
wxArrayInt AliasAccelCmds;
735
wxArrayInt RealAccelCmds;
737
AliasAccelCmds.Add( ID_PLAYER_PLAYLIST_SAVE );
738
AliasAccelCmds.Add( ID_PLAYER_PLAYLIST_EDITTRACKS );
739
AliasAccelCmds.Add( ID_TRACKS_PLAY );
740
AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ALL );
741
AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_TRACK );
742
AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ALBUM );
743
AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ARTIST );
745
RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_SAVEPLAYLIST );
746
RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_EDITTRACKS );
747
RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_PLAY );
748
RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL );
749
RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_TRACK );
750
RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALBUM );
751
RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ARTIST );
753
if( guAccelDoAcceleratorTable( AliasAccelCmds, RealAccelCmds, AccelTable ) )
755
SetAcceleratorTable( AccelTable );
759
// -------------------------------------------------------------------------------- //
760
wxArrayString guFilesListBox::GetColumnNames( void )
762
wxArrayString ColumnNames;
763
ColumnNames.Add( _( "Name" ) );
764
ColumnNames.Add( _( "Size" ) );
765
ColumnNames.Add( _( "Modified" ) );
769
// -------------------------------------------------------------------------------- //
770
wxString guFilesListBox::OnGetItemText( const int row, const int col ) const
772
// guLogMessage( wxT( "GetItem: %i %i" ), row, col );
773
// if( row < 0 || col < 0 )
774
// return wxEmptyString;
776
guFileItem * FileItem;
777
FileItem = &m_Files[ row ];
778
switch( ( * m_Columns )[ col ].m_Id )
780
// case guFILEBROWSER_COLUMN_TYPE :
781
// return wxEmptyString;
783
case guFILEBROWSER_COLUMN_NAME :
784
return FileItem->m_Name;
786
case guFILEBROWSER_COLUMN_SIZE :
787
return SizeToString( FileItem->m_Size );
789
case guFILEBROWSER_COLUMN_TIME :
792
FileTime.Set( ( time_t ) FileItem->m_Time );
793
return FileTime.FormatDate();
796
return wxEmptyString;
799
// -------------------------------------------------------------------------------- //
800
void guFilesListBox::DrawItem( wxDC &dc, const wxRect &rect, const int row, const int col ) const
802
if( ( * m_Columns )[ col ].m_Id == guFILEBROWSER_COLUMN_NAME )
804
guFileItem * FileItem = &m_Files[ row ];
805
dc.SetBackgroundMode( wxTRANSPARENT );
806
int ImageIndex = guDIR_IMAGE_INDEX_OTHER;
807
if( FileItem->m_Type == guFILEITEM_TYPE_FOLDER )
809
ImageIndex = guDIR_IMAGE_INDEX_FOLDER;
811
else if( FileItem->m_Type == guFILEITEM_TYPE_AUDIO )
813
ImageIndex = guDIR_IMAGE_INDEX_AUDIO;
815
else if( FileItem->m_Type == guFILEITEM_TYPE_IMAGE )
817
ImageIndex = guDIR_IMAGE_INDEX_IMAGE;
819
m_TreeImageList->Draw( ImageIndex, dc, rect.x + 1, rect.y + 1, wxIMAGELIST_DRAW_TRANSPARENT );
820
wxRect TextRect = rect;
821
TextRect.x += 20; // 16 + 4
822
TextRect.width -= 20;
823
guListView::DrawItem( dc, TextRect, row, col );
827
guListView::DrawItem( dc, rect, row, col );
832
// -------------------------------------------------------------------------------- //
833
void inline GetFileDetails( const wxString &filename, guFileItem * fileitem )
836
wxStat( filename, &St );
837
fileitem->m_Type = ( ( St.st_mode & S_IFMT ) == S_IFDIR ) ? 0 : 3;
838
fileitem->m_Size = St.st_size;
839
fileitem->m_Time = St.st_ctime;
842
//// -------------------------------------------------------------------------------- //
843
//static int wxCMPFUNC_CONV CompareFileTypeA( guFileItem ** item1, guFileItem ** item2 )
845
// if( ( * item1 )->m_Name == wxT( ".." ) )
847
// else if( ( * item2 )->m_Name == wxT( ".." ) )
850
// if( ( * item1 )->m_Type == ( * item2 )->m_Type )
852
// else if( ( * item1 )->m_Type > ( * item2 )->m_Type )
858
// -------------------------------------------------------------------------------- //
859
static int wxCMPFUNC_CONV CompareFileTypeD( guFileItem ** item1, guFileItem ** item2 )
861
if( ( * item1 )->m_Name == wxT( ".." ) )
863
else if( ( * item2 )->m_Name == wxT( ".." ) )
866
if( ( * item1 )->m_Type == ( * item2 )->m_Type )
868
else if( ( * item1 )->m_Type > ( * item2 )->m_Type )
874
// -------------------------------------------------------------------------------- //
875
static int wxCMPFUNC_CONV CompareFileNameA( guFileItem ** item1, guFileItem ** item2 )
877
int type = CompareFileTypeD( item1, item2 );
879
return ( * item1 )->m_Name.Cmp( ( * item2 )->m_Name );
883
// -------------------------------------------------------------------------------- //
884
static int wxCMPFUNC_CONV CompareFileNameD( guFileItem ** item1, guFileItem ** item2 )
886
int type = CompareFileTypeD( item1, item2 );
888
return ( * item2 )->m_Name.Cmp( ( * item1 )->m_Name );
892
// -------------------------------------------------------------------------------- //
893
static int wxCMPFUNC_CONV CompareFileSizeA( guFileItem ** item1, guFileItem ** item2 )
895
int type = CompareFileTypeD( item1, item2 );
898
if( ( * item1 )->m_Size == ( * item2 )->m_Size )
900
else if( ( * item1 )->m_Size > ( * item2 )->m_Size )
908
// -------------------------------------------------------------------------------- //
909
static int wxCMPFUNC_CONV CompareFileSizeD( guFileItem ** item1, guFileItem ** item2 )
911
int type = CompareFileTypeD( item1, item2 );
914
if( ( * item1 )->m_Size == ( * item2 )->m_Size )
916
else if( ( * item2 )->m_Size > ( * item1 )->m_Size )
924
// -------------------------------------------------------------------------------- //
925
static int wxCMPFUNC_CONV CompareFileTimeA( guFileItem ** item1, guFileItem ** item2 )
927
int type = CompareFileTypeD( item1, item2 );
930
if( ( * item1 )->m_Time == ( * item2 )->m_Time )
932
else if( ( * item1 )->m_Time > ( * item2 )->m_Time )
940
// -------------------------------------------------------------------------------- //
941
static int wxCMPFUNC_CONV CompareFileTimeD( guFileItem ** item1, guFileItem ** item2 )
943
int type = CompareFileTypeD( item1, item2 );
946
if( ( * item1 )->m_Time == ( * item2 )->m_Time )
948
else if( ( * item2 )->m_Time > ( * item1 )->m_Time )
956
// -------------------------------------------------------------------------------- //
957
int guFilesListBox::GetPathSordedItems( const wxString &path, guFileItemArray * items,
958
const int order, const bool orderdesc, const bool recursive ) const
960
wxString Path = path;
961
if( !Path.EndsWith( wxT( "/" ) ) )
963
if( !path.IsEmpty() && wxDirExists( Path ) )
969
if( Dir.GetFirst( &FileName, wxEmptyString, wxDIR_FILES | wxDIR_DIRS | wxDIR_DOTDOT ) )
972
if( FileName != wxT( "." ) )
974
if( recursive && wxDirExists( Path + FileName ) )
976
if( FileName != wxT( ".." ) )
978
GetPathSordedItems( Path + FileName, items, order, orderdesc, recursive );
983
guFileItem * FileItem = new guFileItem();
985
FileItem->m_Name = Path;
986
FileItem->m_Name += FileName;
987
GetFileDetails( Path + FileName, FileItem );
988
if( !wxDirExists( Path + FileName ) )
990
if( guIsValidAudioFile( FileName.Lower() ) )
991
FileItem->m_Type = guFILEITEM_TYPE_AUDIO;
992
else if( guIsValidImageFile( FileName.Lower() ) )
993
FileItem->m_Type = guFILEITEM_TYPE_IMAGE;
995
items->Add( FileItem );
998
} while( Dir.GetNext( &FileName ) );
1003
case guFILEBROWSER_COLUMN_NAME :
1005
items->Sort( orderdesc ? CompareFileNameD : CompareFileNameA );
1009
case guFILEBROWSER_COLUMN_SIZE :
1011
items->Sort( orderdesc ? CompareFileSizeD : CompareFileSizeA );
1015
case guFILEBROWSER_COLUMN_TIME :
1017
items->Sort( orderdesc ? CompareFileTimeD : CompareFileTimeA );
1023
return items->Count();
1026
// -------------------------------------------------------------------------------- //
1027
void guFilesListBox::GetItemsList( void )
1029
GetPathSordedItems( m_CurDir, &m_Files, m_Order, m_OrderDesc );
1031
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ID_MAINFRAME_UPDATE_SELINFO );
1032
AddPendingEvent( event );
1035
// -------------------------------------------------------------------------------- //
1036
void guFilesListBox::ReloadItems( bool reset )
1039
wxArrayInt Selection;
1040
int FirstVisible = 0;
1048
Selection = GetSelectedItems( false );
1049
FirstVisible = GetFirstVisibleLine();
1056
SetItemCount( m_Files.Count() );
1060
SetSelectedItems( Selection );
1061
ScrollToLine( FirstVisible );
1066
// -------------------------------------------------------------------------------- //
1067
void AppendItemsCommands( wxMenu * menu, int selcount, int seltype )
1072
wxMenuItem * MenuItem;
1074
SubMenu = new wxMenu();
1076
guLogMessage( wxT( "AppendItemCommands: %i %i" ), selcount, seltype );
1078
guConfig * Config = ( guConfig * ) guConfig::Get();
1079
wxArrayString Commands = Config->ReadAStr( wxT( "Exec" ), wxEmptyString, wxT( "commands/execs" ) );
1080
wxArrayString Names = Config->ReadAStr( wxT( "Name" ), wxEmptyString, wxT( "commands/names" ) );
1081
if( ( Count = Commands.Count() ) )
1083
for( Index = 0; Index < Count; Index++ )
1085
if( ( Commands[ Index ].Find( wxT( "{bc}" ) ) == wxNOT_FOUND ) ||
1086
( ( selcount == 1 ) && ( seltype == guFILEITEM_TYPE_IMAGE ) ) )
1088
MenuItem = new wxMenuItem( menu, ID_COMMANDS_BASE + Index, Names[ Index ], Commands[ Index ] );
1089
SubMenu->Append( MenuItem );
1093
SubMenu->AppendSeparator();
1097
MenuItem = new wxMenuItem( SubMenu, ID_MENU_PREFERENCES_COMMANDS, _( "Preferences" ), _( "Add commands in preferences" ) );
1098
SubMenu->Append( MenuItem );
1100
menu->AppendSubMenu( SubMenu, _( "Commands" ) );
1103
// -------------------------------------------------------------------------------- //
1104
void guFilesListBox::CreateContextMenu( wxMenu * Menu ) const
1106
wxMenuItem * MenuItem;
1107
wxArrayInt Selection = GetSelectedItems( false );
1109
if( ( SelCount = Selection.Count() ) )
1111
MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_PLAY,
1112
wxString( _( "Play" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_PLAY ),
1113
_( "Play current selected files" ) );
1114
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_player_tiny_light_play ) );
1115
Menu->Append( MenuItem );
1117
MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL,
1118
wxString( _( "Enqueue" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ALL ),
1119
_( "Add current selected files to playlist" ) );
1120
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
1121
Menu->Append( MenuItem );
1123
wxMenu * EnqueueMenu = new wxMenu();
1125
MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_TRACK,
1126
wxString( _( "Current Track" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_TRACK ),
1127
_( "Add current selected tracks to playlist after the current track" ) );
1128
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
1129
EnqueueMenu->Append( MenuItem );
1130
MenuItem->Enable( SelCount );
1132
MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALBUM,
1133
wxString( _( "Current Album" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ALBUM ),
1134
_( "Add current selected tracks to playlist after the current album" ) );
1135
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
1136
EnqueueMenu->Append( MenuItem );
1137
MenuItem->Enable( SelCount );
1139
MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ARTIST,
1140
wxString( _( "Current Artist" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ARTIST ),
1141
_( "Add current selected tracks to playlist after the current artist" ) );
1142
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
1143
EnqueueMenu->Append( MenuItem );
1144
MenuItem->Enable( SelCount );
1146
Menu->Append( wxID_ANY, _( "Enqueue After" ), EnqueueMenu );
1151
Menu->AppendSeparator();
1153
MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_EDITTRACKS,
1154
wxString( _( "Edit Tracks" ) ) + guAccelGetCommandKeyCodeString( ID_PLAYER_PLAYLIST_EDITTRACKS ),
1155
_( "Edit the current selected files" ) );
1156
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit ) );
1157
Menu->Append( MenuItem );
1159
Menu->AppendSeparator();
1161
MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_SAVEPLAYLIST,
1162
wxString( _( "Save to Playlist" ) ) + guAccelGetCommandKeyCodeString( ID_PLAYER_PLAYLIST_SAVE ),
1163
_( "Add the current selected tracks to a playlist" ) );
1164
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_doc_save ) );
1165
Menu->Append( MenuItem );
1168
Menu->AppendSeparator();
1170
MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_COPY, _( "Copy" ), _( "Copy the selected folder to clipboard" ) );
1171
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit_copy ) );
1172
Menu->Append( MenuItem );
1174
MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_PASTE, _( "Paste" ), _( "Paste to the selected dir" ) );
1175
Menu->Append( MenuItem );
1176
wxTheClipboard->UsePrimarySelection( false );
1177
if( wxTheClipboard->Open() )
1179
if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
1181
wxFileDataObject data;
1182
MenuItem->Enable( wxTheClipboard->GetData( data ) );
1184
wxTheClipboard->Close();
1189
Menu->AppendSeparator();
1191
MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_RENAME, _( "Rename Files" ), _( "Rename the current selected file" ) );
1192
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit ) );
1193
Menu->Append( MenuItem );
1195
MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_DELETE, _( "Remove" ), _( "Delete the selected files" ) );
1196
MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit_clear ) );
1197
Menu->Append( MenuItem );
1199
Menu->AppendSeparator();
1201
guMainFrame * MainFrame = ( guMainFrame * ) wxTheApp->GetTopWindow();
1202
MainFrame->CreateCopyToMenu( Menu );
1204
AppendItemsCommands( Menu, SelCount, SelCount ? GetType( Selection[ 0 ] ) : guFILEITEM_TYPE_FILE );
1208
// -------------------------------------------------------------------------------- //
1209
int inline guFilesListBox::GetItemId( const int row ) const
1214
// -------------------------------------------------------------------------------- //
1215
wxString inline guFilesListBox::GetItemName( const int row ) const
1217
return m_Files[ row ].m_Name;
1220
// -------------------------------------------------------------------------------- //
1221
void guFilesListBox::SetOrder( int columnid )
1223
if( m_Order != columnid )
1226
m_OrderDesc = ( columnid != 0 );
1229
m_OrderDesc = !m_OrderDesc;
1231
wxArrayString ColumnNames = GetColumnNames();
1234
int count = ColumnNames.Count();
1235
for( index = 0; index < count; index++ )
1237
CurColId = GetColumnId( index );
1238
SetColumnLabel( index,
1239
ColumnNames[ CurColId ] + ( ( CurColId == m_Order ) ?
1240
( m_OrderDesc ? wxT( " ▼" ) : wxT( " ▲" ) ) : wxEmptyString ) );
1246
// -------------------------------------------------------------------------------- //
1247
int guFilesListBox::GetSelectedSongs( guTrackArray * tracks, const bool isdrag ) const
1249
wxArrayString Files = GetSelectedFiles( true );
1250
return GetTracksFromFiles( Files, tracks );
1253
// -------------------------------------------------------------------------------- //
1254
int guFilesListBox::GetAllSongs( guTrackArray * tracks ) const
1256
wxArrayString Files = GetAllFiles( true );
1257
return GetTracksFromFiles( Files, tracks );
1260
// -------------------------------------------------------------------------------- //
1261
int guFilesListBox::GetTracksFromFiles( const wxArrayString &files, guTrackArray * tracks ) const
1265
if( ( Count = files.Count() ) )
1267
for( Index = 0; Index < Count; Index++ )
1269
wxString FileName = files[ Index ];
1270
//guLogMessage( wxT( "GetTracksFromFiles: %s" ), FileName.c_str() );
1271
wxURI Uri( FileName );
1273
if( Uri.IsReference() )
1275
if( guIsValidAudioFile( FileName ) )
1277
guTrack * Track = new guTrack();
1278
Track->m_FileName = FileName;
1280
if( !m_Db || !m_Db->FindTrackFile( FileName, Track ) )
1282
guPodcastItem PodcastItem;
1283
guMainFrame * MainFrame = ( guMainFrame * ) wxTheApp->GetTopWindow();
1284
guDbPodcasts * DbPodcasts = MainFrame->GetPodcastsDb();
1285
if( DbPodcasts->GetPodcastItemFile( FileName, &PodcastItem ) )
1292
if( Track->ReadFromFile( FileName ) )
1294
Track->m_Type = guTRACK_TYPE_NOTDB;
1298
guLogError( wxT( "Could not read tags from file '%s'" ), FileName.c_str() );
1303
tracks->Add( Track );
1308
return tracks->Count();
1311
// -------------------------------------------------------------------------------- //
1312
wxArrayString guFilesListBox::GetSelectedFiles( const bool recursive ) const
1314
wxArrayString Files;
1315
wxArrayInt Selection = GetSelectedItems( false );
1318
if( ( Count = Selection.Count() ) )
1320
for( Index = 0; Index < Count; Index++ )
1322
if( m_Files[ Selection[ Index ] ].m_Name != wxT( ".." ) )
1324
if( recursive && ( m_Files[ Selection[ Index ] ].m_Type == guFILEITEM_TYPE_FOLDER ) )
1326
//guAddDirItems( m_CurDir + m_Files[ Selection[ Index ] ].m_Name, Files );
1327
guFileItemArray DirFiles;
1328
if( GetPathSordedItems( m_CurDir + m_Files[ Selection[ Index ] ].m_Name,
1329
&DirFiles, m_Order, m_OrderDesc, true ) )
1332
int FileCount = DirFiles.Count();
1333
for( FileIndex = 0; FileIndex < FileCount; FileIndex++ )
1335
Files.Add( DirFiles[ FileIndex ].m_Name );
1341
Files.Add( m_CurDir + m_Files[ Selection[ Index ] ].m_Name );
1349
// -------------------------------------------------------------------------------- //
1350
wxArrayString guFilesListBox::GetAllFiles( const bool recursive ) const
1352
wxArrayString Files;
1354
int Count = m_Files.Count();
1357
for( Index = 0; Index < Count; Index++ )
1359
if( m_Files[ Index ].m_Name != wxT( ".." ) )
1361
if( recursive && ( m_Files[ Index ].m_Type == guFILEITEM_TYPE_FOLDER ) )
1363
//guAddDirItems( m_CurDir + m_Files[ Selection[ Index ] ].m_Name, Files );
1364
guFileItemArray DirFiles;
1365
if( GetPathSordedItems( m_CurDir + m_Files[ Index ].m_Name,
1366
&DirFiles, m_Order, m_OrderDesc, true ) )
1369
int FileCount = DirFiles.Count();
1370
for( FileIndex = 0; FileIndex < FileCount; FileIndex++ )
1372
Files.Add( DirFiles[ FileIndex ].m_Name );
1378
Files.Add( m_CurDir + m_Files[ Index ].m_Name );
1386
// -------------------------------------------------------------------------------- //
1387
int guFilesListBox::GetDragFiles( guDataObjectComposite * files )
1389
wxArrayString SelectFiles = GetSelectedFiles( true );
1391
int Count = SelectFiles.Count();
1392
for( Index = 0; Index < Count; Index++ )
1394
SelectFiles[ Index ] = guFileDnDEncode( SelectFiles[ Index ] );
1396
files->SetFiles( SelectFiles );
1400
// -------------------------------------------------------------------------------- //
1401
void guFilesListBox::SetPath( const wxString &path, guMediaViewer * mediaviewer )
1403
guLogMessage( wxT( "guFilesListBox::SetPath( %s )" ), path.c_str() );
1405
if( !m_CurDir.EndsWith( wxT( "/" ) ) )
1406
m_CurDir += wxT( "/" );
1407
m_MediaViewer = mediaviewer;
1408
m_Db = mediaviewer ? mediaviewer->GetDb() : NULL;
1412
// -------------------------------------------------------------------------------- //
1413
wxString guFilesListBox::GetPath( const int item, const bool absolute ) const
1416
//guLogMessage( wxT( "GetPath( %i )" ), item );
1421
return m_CurDir + m_Files[ item ].m_Name;
1425
if( m_Files[ item ].m_Name == wxT( ".." ) )
1427
RetVal = m_CurDir.BeforeLast( wxT( '/' ) ).BeforeLast( wxT( '/' ) );
1428
//guLogMessage( wxT( "1) Path : %s" ), RetVal.c_str() );
1432
wxFileName FileName( m_Files[ item ].m_Name );
1433
FileName.MakeAbsolute( m_CurDir );
1434
//guLogMessage( wxT( "Path : %s" ), FileName.GetFullPath().c_str() );
1435
return FileName.GetFullPath();
1438
return wxEmptyString;
1441
// -------------------------------------------------------------------------------- //
1442
int guFilesListBox::GetType( const int item ) const
1446
return m_Files[ item ].m_Type;
1451
// -------------------------------------------------------------------------------- //
1452
bool guFilesListBox::GetCounters( wxLongLong * count, wxLongLong * len, wxLongLong * size )
1456
* count = * len = * size = 0;
1457
Count = m_Files.Count();
1458
for( Index = 0; Index < Count; Index++ )
1460
if( m_Files[ Index ].m_Type == guFILEITEM_TYPE_FOLDER )
1462
if( ( m_Files[ Index ].m_Name != wxT( ".." ) ) )
1467
* size += m_Files[ Index ].m_Size;
1475
// -------------------------------------------------------------------------------- //
1476
// guFileBrowserFileCtrl
1477
// -------------------------------------------------------------------------------- //
1478
guFileBrowserFileCtrl::guFileBrowserFileCtrl( wxWindow * parent, guDbLibrary * db, guFileBrowserDirCtrl * dirctrl ) :
1479
wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxNO_BORDER )
1483
m_MediaViewer = NULL;
1484
m_DirCtrl = dirctrl;
1485
wxImageList * ImageList = dirctrl->GetImageList();
1486
ImageList->Add( wxArtProvider::GetBitmap( wxT( "audio-x-generic" ), wxART_OTHER, wxSize( 16, 16 ) ) );
1487
ImageList->Add( wxArtProvider::GetBitmap( wxT( "image-x-generic" ), wxART_OTHER, wxSize( 16, 16 ) ) );
1489
wxBoxSizer * MainSizer;
1490
MainSizer = new wxBoxSizer( wxVERTICAL );
1492
m_FilesListBox = new guFilesListBox( this, db );
1493
m_FilesListBox->SetTreeImageList( ImageList );
1494
MainSizer->Add( m_FilesListBox, 1, wxEXPAND, 5 );
1496
this->SetSizer( MainSizer );
1501
// -------------------------------------------------------------------------------- //
1502
guFileBrowserFileCtrl::~guFileBrowserFileCtrl()
1506
// -------------------------------------------------------------------------------- //
1507
void guFileBrowserFileCtrl::SetPath( const wxString &path, guMediaViewer * mediaviewer )
1509
guLogMessage( wxT( "guFileBrowserFileCtrl::SetPath( %s )" ), path.c_str() );
1510
m_MediaViewer = mediaviewer;
1511
m_Db = mediaviewer ? mediaviewer->GetDb() : NULL;
1512
m_FilesListBox->SetPath( path, mediaviewer );
1517
// -------------------------------------------------------------------------------- //
1519
// -------------------------------------------------------------------------------- //
1520
BEGIN_EVENT_TABLE( guFileBrowser, wxPanel )
1521
EVT_TREE_BEGIN_DRAG( wxID_ANY, guFileBrowser::OnDirBeginDrag)
1524
// -------------------------------------------------------------------------------- //
1525
guFileBrowser::guFileBrowser( wxWindow * parent, guMainFrame * mainframe, guDbLibrary * db, guPlayerPanel * playerpanel ) :
1526
guAuiManagerPanel( parent )
1528
m_MainFrame = mainframe;
1531
m_MediaViewer = NULL;
1532
m_PlayerPanel = playerpanel;
1534
guConfig * Config = ( guConfig * ) guConfig::Get();
1536
m_VisiblePanels = Config->ReadNum( wxT( "VisiblePanels" ), guPANEL_FILEBROWSER_VISIBLE_DEFAULT, wxT( "filebrowser" ) );
1539
wxString LastPath = Config->ReadStr( wxT( "Path" ), wxEmptyString, wxT( "filebrowser" ) );
1540
m_DirCtrl = new guFileBrowserDirCtrl( this, m_MainFrame, db, LastPath );
1541
guLogMessage( wxT( "LastPath: '%s'" ), LastPath.c_str() );
1543
m_AuiManager.AddPane( m_DirCtrl,
1544
wxAuiPaneInfo().Name( wxT( "FileBrowserDirCtrl" ) ).Caption( _( "Directories" ) ).
1545
MinSize( 60, 28 ).Row( 0 ).Layer( 0 ).Position( 0 ).
1546
CloseButton( false ).
1547
Dockable( true ).Left() );
1549
m_FilesCtrl = new guFileBrowserFileCtrl( this, db, m_DirCtrl );
1550
m_FilesCtrl->SetPath( LastPath, NULL );
1552
m_AuiManager.AddPane( m_FilesCtrl,
1553
wxAuiPaneInfo().Name( wxT( "FileBrowserFilesCtrl" ) ).
1554
Dockable( true ).CenterPane() );
1556
wxString FileBrowserLayout = Config->ReadStr( wxT( "LastLayout" ), wxEmptyString, wxT( "filebrowser" ) );
1557
if( Config->GetIgnoreLayouts() || FileBrowserLayout.IsEmpty() )
1559
m_VisiblePanels = guPANEL_FILEBROWSER_VISIBLE_DEFAULT;
1560
FileBrowserLayout = wxT( "layout2|name=FileBrowserDirCtrl;caption=" ) + wxString( _( "Directories" ) );
1561
FileBrowserLayout += wxT( ";state=2044;dir=4;layer=0;row=0;pos=0;prop=100000;bestw=60;besth=28;minw=60;minh=28;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|" );
1562
FileBrowserLayout += wxT( "name=FileBrowserFilesCtrl;caption=;state=768;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1| " );
1563
FileBrowserLayout += wxT( "dock_size(5,0,0)=10|dock_size(4,0,0)=266|" );
1564
//m_AuiManager.Update();
1567
m_AuiManager.LoadPerspective( FileBrowserLayout, true );
1569
m_DirCtrl->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( guFileBrowser::OnDirItemChanged ), NULL, this );
1570
m_FilesCtrl->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxListEventHandler( guFileBrowser::OnFileItemActivated ), NULL, this );
1571
m_FilesCtrl->Connect( wxEVT_COMMAND_LIST_COL_CLICK, wxListEventHandler( guFileBrowser::OnFilesColClick ), NULL, this );
1573
Connect( ID_FILESYSTEM_FOLDER_PLAY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderPlay ), NULL, this );
1574
Connect( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ARTIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderEnqueue ), NULL, this );
1575
Connect( ID_FILESYSTEM_FOLDER_NEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderNew ), NULL, this );
1576
Connect( ID_FILESYSTEM_FOLDER_RENAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderRename ), NULL, this );
1577
Connect( ID_FILESYSTEM_FOLDER_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderDelete ), NULL, this );
1578
Connect( ID_FILESYSTEM_FOLDER_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCopy ), NULL, this );
1579
Connect( ID_FILESYSTEM_FOLDER_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderPaste ), NULL, this );
1580
Connect( ID_FILESYSTEM_FOLDER_EDITTRACKS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderEditTracks ), NULL, this );
1581
Connect( ID_FILESYSTEM_FOLDER_SAVEPLAYLIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderSaveToPlayList ), NULL, this );
1582
m_DirCtrl->Connect( ID_COPYTO_BASE, ID_COPYTO_BASE + guCOPYTO_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCopyTo ), NULL, this );
1584
m_DirCtrl->Connect( ID_COMMANDS_BASE, ID_COMMANDS_BASE + guCOMMANDS_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCommand ), NULL, this );
1586
Connect( ID_FILESYSTEM_ITEMS_PLAY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsPlay ), NULL, this );
1587
Connect( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ARTIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsEnqueue ), NULL, this );
1588
Connect( ID_FILESYSTEM_ITEMS_EDITTRACKS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsEditTracks ), NULL, this );
1589
Connect( ID_FILESYSTEM_ITEMS_SAVEPLAYLIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsSaveToPlayList ), NULL, this );
1590
m_FilesCtrl->Connect( ID_COPYTO_BASE, ID_COPYTO_BASE + guCOPYTO_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCopyTo ), NULL, this );
1591
Connect( ID_FILESYSTEM_ITEMS_RENAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsRename ), NULL, this );
1592
Connect( ID_FILESYSTEM_ITEMS_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsDelete ), NULL, this );
1593
Connect( ID_FILESYSTEM_ITEMS_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCopy ), NULL, this );
1594
Connect( ID_FILESYSTEM_ITEMS_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsPaste ), NULL, this );
1596
m_FilesCtrl->Connect( ID_COMMANDS_BASE, ID_COMMANDS_BASE + guCOMMANDS_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCommand ), NULL, this );
1599
// -------------------------------------------------------------------------------- //
1600
guFileBrowser::~guFileBrowser()
1602
guConfig * Config = ( guConfig * ) guConfig::Get();
1603
Config->WriteNum( wxT( "VisiblePanels" ), m_VisiblePanels, wxT( "filebrowser" ) );
1604
Config->WriteStr( wxT( "LastLayout" ), m_AuiManager.SavePerspective(), wxT( "filebrowser" ) );
1605
Config->WriteStr( wxT( "Path" ), m_DirCtrl->GetPath(), wxT( "filebrowser" ) );
1607
m_DirCtrl->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( guFileBrowser::OnDirItemChanged ), NULL, this );
1608
m_FilesCtrl->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxListEventHandler( guFileBrowser::OnFileItemActivated ), NULL, this );
1609
m_FilesCtrl->Disconnect( wxEVT_COMMAND_LIST_COL_CLICK, wxListEventHandler( guFileBrowser::OnFilesColClick ), NULL, this );
1611
Disconnect( ID_FILESYSTEM_FOLDER_PLAY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderPlay ), NULL, this );
1612
Disconnect( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ARTIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderEnqueue ), NULL, this );
1613
Disconnect( ID_FILESYSTEM_FOLDER_NEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderNew ), NULL, this );
1614
Disconnect( ID_FILESYSTEM_FOLDER_RENAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderRename ), NULL, this );
1615
Disconnect( ID_FILESYSTEM_FOLDER_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderDelete ), NULL, this );
1616
Disconnect( ID_FILESYSTEM_FOLDER_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCopy ), NULL, this );
1617
Disconnect( ID_FILESYSTEM_FOLDER_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderPaste ), NULL, this );
1618
Disconnect( ID_FILESYSTEM_FOLDER_EDITTRACKS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderEditTracks ), NULL, this );
1619
Disconnect( ID_FILESYSTEM_FOLDER_SAVEPLAYLIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderSaveToPlayList ), NULL, this );
1620
m_DirCtrl->Disconnect( ID_COPYTO_BASE, ID_COPYTO_BASE + guCOPYTO_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCopyTo ), NULL, this );
1622
m_DirCtrl->Disconnect( ID_COMMANDS_BASE, ID_COMMANDS_BASE + guCOMMANDS_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCommand ), NULL, this );
1624
Disconnect( ID_FILESYSTEM_ITEMS_PLAY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsPlay ), NULL, this );
1625
Disconnect( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ARTIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsEnqueue ), NULL, this );
1626
Disconnect( ID_FILESYSTEM_ITEMS_EDITTRACKS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsEditTracks ), NULL, this );
1627
Disconnect( ID_FILESYSTEM_ITEMS_SAVEPLAYLIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsSaveToPlayList ), NULL, this );
1628
m_FilesCtrl->Disconnect( ID_COPYTO_BASE, ID_COPYTO_BASE + guCOPYTO_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCopyTo ), NULL, this );
1629
Disconnect( ID_FILESYSTEM_ITEMS_RENAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsRename ), NULL, this );
1630
Disconnect( ID_FILESYSTEM_ITEMS_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsDelete ), NULL, this );
1632
m_FilesCtrl->Disconnect( ID_COMMANDS_BASE, ID_COMMANDS_BASE + guCOMMANDS_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCommand ), NULL, this );
1636
// -------------------------------------------------------------------------------- //
1637
void guFileBrowser::OnDirItemChanged( wxTreeEvent &event )
1639
wxString CurPath = m_DirCtrl->GetPath();
1640
if( !CurPath.EndsWith( wxT( "/" ) ) )
1641
CurPath.Append( wxT( "/" ) );
1643
guLogMessage( wxT( "guFileBrowser::OnDirItemChanged( '%s' )" ), CurPath.c_str() );
1645
if( m_DirCtrl->GetShowPaths() & guFILEBROWSER_SHOWPATH_LOCATIONS )
1647
m_MediaViewer = FindMediaViewerByPath( m_MainFrame, CurPath );
1648
m_Db = m_MediaViewer ? m_MediaViewer->GetDb() : NULL;
1650
guLogMessage( wxT( "'%s' ==>> '%i' '%s'" ), CurPath.c_str(), m_MediaViewer != NULL, m_MediaViewer->GetName().c_str() );
1652
guLogMessage( wxT( "'%s' ==>> '%i' ''" ), CurPath.c_str(), m_MediaViewer != NULL );
1659
m_FilesCtrl->SetPath( CurPath, m_MediaViewer );
1660
m_DirCtrl->SetMediaViewer( m_MediaViewer );
1663
// -------------------------------------------------------------------------------- //
1664
void guFileBrowser::OnFileItemActivated( wxListEvent &Event )
1666
wxArrayInt Selection = m_FilesCtrl->GetSelectedItems( false );
1667
if( Selection.Count() )
1669
if( m_FilesCtrl->GetType( Selection[ 0 ] ) == guFILEITEM_TYPE_FOLDER )
1671
m_DirCtrl->SetPath( m_FilesCtrl->GetPath( Selection[ 0 ] ), m_MediaViewer );
1675
wxArrayString Files;
1676
Files.Add( m_FilesCtrl->GetPath( Selection[ 0 ] ) );
1678
guConfig * Config = ( guConfig * ) guConfig::Get();
1681
if( Config->ReadBool( wxT( "DefaultActionEnqueue" ), false , wxT( "general" )) )
1683
m_PlayerPanel->AddToPlayList( Files );
1687
m_PlayerPanel->SetPlayList( Files );
1695
// -------------------------------------------------------------------------------- //
1696
void guFileBrowser::OnFilesColClick( wxListEvent &event )
1698
int col = event.GetColumn();
1701
m_FilesCtrl->SetOrder( col );
1704
// -------------------------------------------------------------------------------- //
1705
void guFileBrowser::OnDirBeginDrag( wxTreeEvent &event )
1707
wxFileDataObject Files;
1709
wxArrayString FolderFiles = m_FilesCtrl->GetAllFiles( true );
1712
if( ( Count = FolderFiles.Count() ) )
1714
for( Index = 0; Index < Count; Index++ )
1716
Files.AddFile( FolderFiles[ Index ] );
1719
wxDropSource source( Files, this );
1721
wxDragResult Result = source.DoDragDrop();
1728
// -------------------------------------------------------------------------------- //
1729
void guFileBrowser::OnFolderPlay( wxCommandEvent &event )
1731
wxArrayString Files = m_FilesCtrl->GetAllFiles( true );
1732
m_PlayerPanel->SetPlayList( Files );
1735
// -------------------------------------------------------------------------------- //
1736
void guFileBrowser::OnFolderEnqueue( wxCommandEvent &event )
1738
wxArrayString Files = m_FilesCtrl->GetAllFiles( true );
1741
m_PlayerPanel->AddToPlayList( Files, true, event.GetId() - ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL );
1745
// -------------------------------------------------------------------------------- //
1746
void guFileBrowser::OnFolderNew( wxCommandEvent &event )
1748
m_DirCtrl->FolderNew();
1751
// -------------------------------------------------------------------------------- //
1752
void guFileBrowser::OnFolderRename( wxCommandEvent &event )
1754
m_DirCtrl->FolderRename();
1757
// -------------------------------------------------------------------------------- //
1758
void guFileBrowser::OnFolderDelete( wxCommandEvent &event )
1760
m_DirCtrl->FolderDelete();
1763
// -------------------------------------------------------------------------------- //
1764
void guFileBrowser::OnFolderCopy( wxCommandEvent &event )
1766
//guLogMessage( wxT( "OnFolderCopy" ) );
1767
wxTheClipboard->UsePrimarySelection( false );
1768
if( wxTheClipboard->Open() )
1770
wxTheClipboard->Clear();
1771
wxFileDataObject * FileObject = new wxFileDataObject();
1772
//wxCustomDataObject * GnomeCopiedObject = new wxCustomDataObject( wxDataFormat( wxT( "x-special/gnome-copied-files" ) ) );
1773
//wxCustomDataObject * UriListObject = new wxCustomDataObject( wxDataFormat( wxT( "text/uri-list" ) ) );
1774
wxTextDataObject * TextObject = new wxTextDataObject();
1775
wxDataObjectComposite * CompositeObject = new wxDataObjectComposite();
1777
wxString Path = m_DirCtrl->GetPath();
1778
Path.Replace( wxT( "#" ), wxT( "%23" ) );
1780
TextObject->SetText( Path );
1781
FileObject->AddFile( Path );
1783
//Path = wxT( "file://" ) + Path;
1784
//UriListObject->SetData( Path.Length(), Path.char_str() );
1786
//Path = wxT( "copy\n" ) + Path;
1787
//GnomeCopiedObject->SetData( Path.Length(), Path.char_str() );
1789
//guLogMessage( wxT( "Copy: '%s'" ), Path.c_str() );
1791
CompositeObject->Add( FileObject );
1792
//CompositeObject->Add( GnomeCopiedObject );
1793
//CompositeObject->Add( UriListObject );
1794
CompositeObject->Add( TextObject );
1796
//if( !wxTheClipboard->AddData( CustomObject ) )
1797
if( !wxTheClipboard->AddData( CompositeObject ) )
1798
//if( !wxTheClipboard->AddData( TextObject ) )
1802
//delete GnomeCopiedObject;
1803
//delete UriListObject;
1804
delete CompositeObject;
1805
guLogError( wxT( "Can't copy the folder to the clipboard" ) );
1807
guLogMessage( wxT( "Copied the data to the clipboard..." ) );
1808
wxTheClipboard->Close();
1812
guLogError( wxT( "Could not open the clipboard object" ) );
1816
// -------------------------------------------------------------------------------- //
1817
void guFileBrowser::OnFolderPaste( wxCommandEvent &event )
1819
guLogMessage( wxT( "OnFolderPaste" ) );
1820
wxTheClipboard->UsePrimarySelection( false );
1821
if( wxTheClipboard->Open() )
1824
// if( wxTheClipboard->IsSupported( wxDataFormat( wxT( "text/uri-list" ) ) ) )
1826
// guLogMessage( wxT( "Supported format uri-list.." ) );
1828
// wxCustomDataObject CustomDataObject( wxDataFormat( wxT( "text/uri-list" ) ) );
1829
// if( wxTheClipboard->GetData( CustomDataObject ) )
1831
// guLogMessage( wxT( "Custom Data: (%i) '%s'" ), CustomDataObject.GetSize(), wxString( ( const char * ) CustomDataObject.GetData(), wxConvUTF8 ).c_str() );
1835
// if( wxTheClipboard->IsSupported( wxDataFormat( wxT( "x-special/gnome-copied-files" ) ) ) )
1837
// guLogMessage( wxT( "Supported format x-special..." ) );
1839
// wxCustomDataObject CustomDataObject( wxDataFormat( wxT( "x-special/gnome-copied-files" ) ) ); //( wxT( "Supported format x-special..." ) );
1840
// if( wxTheClipboard->GetData( CustomDataObject ) )
1842
// guLogMessage( wxT( "Custom Data: (%i) '%s'" ), CustomDataObject.GetSize(), wxString( ( const char * ) CustomDataObject.GetData(), wxConvUTF8 ).c_str() );
1845
// else if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
1846
if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
1848
wxFileDataObject FileObject;
1849
if( wxTheClipboard->GetData( FileObject ) )
1851
wxArrayString Files = FileObject.GetFilenames();
1852
wxArrayString FromFiles;
1853
//guLogMessage( wxT( "Pasted: %s" ), Files[ 0 ].c_str() );
1855
int Count = Files.Count();
1856
for( Index = 0; Index < Count; Index++ )
1858
if( wxDirExists( Files[ Index ] ) )
1860
//wxFileName::Mkdir( m_DirCtrl->GetPath() + wxT( "/" ) + wxFileNameFromPath( Files[ Index ] ), 0770, wxPATH_MKDIR_FULL );
1862
guAddDirItems( Files[ Index ], FromFiles );
1865
int FromCount = FromFiles.Count();
1866
for( FromIndex = 0; FromIndex < FromCount; FromIndex++ )
1868
wxString DestName = FromFiles[ FromIndex ];
1869
DestName.Replace( wxPathOnly( Files[ Index ] ), m_DirCtrl->GetPath() );
1870
wxFileName::Mkdir( wxPathOnly( DestName ), 0770, wxPATH_MKDIR_FULL );
1871
guLogMessage( wxT( "Copy file %s to %s" ), FromFiles[ FromIndex ].c_str(), DestName.c_str() );
1872
wxCopyFile( FromFiles[ FromIndex ], DestName );
1878
wxCopyFile( Files[ Index ], m_DirCtrl->GetPath() + wxT( "/" ) + wxFileNameFromPath( Files[ Index ] ) );
1881
wxString CurPath = m_DirCtrl->GetPath();
1882
m_DirCtrl->CollapsePath( CurPath );
1883
m_DirCtrl->ExpandPath( CurPath );
1887
guLogError( wxT( "Can't paste the data from the clipboard" ) );
1891
wxTheClipboard->Close();
1895
guLogError( wxT( "Could not open the clipboard object" ) );
1899
// -------------------------------------------------------------------------------- //
1900
void guFileBrowser::OnFolderEditTracks( wxCommandEvent &event )
1902
guTrackArray Tracks;
1903
guImagePtrArray Images;
1904
wxArrayString Lyrics;
1905
wxArrayInt ChangedFlags;
1907
m_FilesCtrl->GetAllSongs( &Tracks );
1909
if( Tracks.Count() )
1911
guTrackEditor * TrackEditor = new guTrackEditor( this, m_Db ? m_Db : m_DefaultDb, &Tracks, &Images, &Lyrics, &ChangedFlags );
1915
if( TrackEditor->ShowModal() == wxID_OK )
1917
guUpdateTracks( Tracks, Images, Lyrics, ChangedFlags );
1919
m_Db->UpdateSongs( &Tracks, ChangedFlags );
1921
m_DefaultDb->UpdateSongs( &Tracks, ChangedFlags );
1922
//guUpdateLyrics( Tracks, Lyrics, ChangedFlags );
1923
//guUpdateImages( Tracks, Images, ChangedFlags );
1925
// Update the track in database, playlist, etc
1926
m_MainFrame->UpdatedTracks( guUPDATED_TRACKS_PLAYER_PLAYLIST, &Tracks );
1928
guImagePtrArrayClean( &Images );
1929
TrackEditor->Destroy();
1934
// -------------------------------------------------------------------------------- //
1935
void guFileBrowser::OnFolderSaveToPlayList( wxCommandEvent &event )
1937
guTrackArray Tracks;
1939
m_FilesCtrl->GetAllSongs( &Tracks );
1940
wxArrayInt TrackIds;
1942
int Count = Tracks.Count();
1943
for( Index = 0; Index < Count; Index++ )
1945
TrackIds.Add( Tracks[ Index ].m_SongId );
1948
if( m_Db && TrackIds.Count() )
1950
guListItems PlayLists;
1951
m_Db->GetPlayLists( &PlayLists,guPLAYLIST_TYPE_STATIC );
1952
guPlayListAppend * PlayListAppendDlg = new guPlayListAppend( m_MainFrame, m_Db, &TrackIds, &PlayLists );
1953
if( PlayListAppendDlg->ShowModal() == wxID_OK )
1955
int Selected = PlayListAppendDlg->GetSelectedPlayList();
1956
if( Selected == -1 )
1958
wxString PLName = PlayListAppendDlg->GetPlaylistName();
1959
if( PLName.IsEmpty() )
1961
PLName = _( "UnNamed" );
1963
m_Db->CreateStaticPlayList( PLName, TrackIds );
1967
int PLId = PlayLists[ Selected ].m_Id;
1968
wxArrayInt OldSongs;
1969
m_Db->GetPlayListSongIds( PLId, &OldSongs );
1970
if( PlayListAppendDlg->GetSelectedPosition() == 0 ) // BEGIN
1972
m_Db->UpdateStaticPlayList( PLId, TrackIds );
1973
m_Db->AppendStaticPlayList( PLId, OldSongs );
1977
m_Db->AppendStaticPlayList( PLId, TrackIds );
1981
m_MediaViewer->UpdatePlaylists();
1984
PlayListAppendDlg->Destroy();
1988
// -------------------------------------------------------------------------------- //
1989
void guFileBrowser::OnFolderCopyTo( wxCommandEvent &event )
1991
guTrackArray * Tracks = new guTrackArray();
1992
m_FilesCtrl->GetAllSongs( Tracks );
1994
int Index = event.GetId() - ID_COPYTO_BASE;
1995
if( Index >= guCOPYTO_DEVICE_BASE )
1997
Index -= guCOPYTO_DEVICE_BASE;
1998
event.SetId( ID_MAINFRAME_COPYTODEVICE_TRACKS );
2002
event.SetId( ID_MAINFRAME_COPYTO );
2004
event.SetInt( Index );
2005
event.SetClientData( ( void * ) Tracks );
2006
wxPostEvent( m_MainFrame, event );
2009
// -------------------------------------------------------------------------------- //
2010
void guFileBrowser::OnItemsPlay( wxCommandEvent &event )
2012
wxArrayString Files = m_FilesCtrl->GetSelectedFiles( true );
2015
int Count = Files.Count();
2016
for( Index = 0; Index < Count; Index++ )
2018
guLogMessage( wxT( "File%i: '%s'" ), Index, Files[ Index ].c_str() );
2022
m_PlayerPanel->SetPlayList( Files );
2026
// -------------------------------------------------------------------------------- //
2027
void guFileBrowser::OnItemsEnqueue( wxCommandEvent &event )
2029
wxArrayString Files = m_FilesCtrl->GetSelectedFiles( true );
2032
m_PlayerPanel->AddToPlayList( Files, true, event.GetId() - ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL );
2036
// -------------------------------------------------------------------------------- //
2037
void guFileBrowser::OnItemsEditTracks( wxCommandEvent &event )
2039
guTrackArray Tracks;
2040
guImagePtrArray Images;
2041
wxArrayString Lyrics;
2042
wxArrayInt ChangedFlags;
2044
m_FilesCtrl->GetSelectedSongs( &Tracks );
2046
if( Tracks.Count() )
2048
guTrackEditor * TrackEditor = new guTrackEditor( this, m_Db ? m_Db : m_DefaultDb, &Tracks, &Images, &Lyrics, &ChangedFlags );
2052
if( TrackEditor->ShowModal() == wxID_OK )
2054
guUpdateTracks( Tracks, Images, Lyrics, ChangedFlags );
2056
m_Db->UpdateSongs( &Tracks, ChangedFlags );
2058
m_DefaultDb->UpdateSongs( &Tracks, ChangedFlags );
2059
//guUpdateLyrics( Tracks, Lyrics, ChangedFlags );
2060
//guUpdateImages( Tracks, Images, ChangedFlags );
2062
// Update the track in database, playlist, etc
2063
m_MainFrame->UpdatedTracks( guUPDATED_TRACKS_PLAYER_PLAYLIST, &Tracks );
2065
guImagePtrArrayClean( &Images );
2066
TrackEditor->Destroy();
2071
// -------------------------------------------------------------------------------- //
2072
void guFileBrowser::OnItemsSaveToPlayList( wxCommandEvent &event )
2074
guTrackArray Tracks;
2075
m_FilesCtrl->GetSelectedSongs( &Tracks );
2077
wxArrayInt TrackIds;
2079
int Count = Tracks.Count();
2080
for( Index = 0; Index < Count; Index++ )
2082
TrackIds.Add( Tracks[ Index ].m_SongId );
2085
if( m_Db && TrackIds.Count() )
2087
guListItems PlayLists;
2088
m_Db->GetPlayLists( &PlayLists, guPLAYLIST_TYPE_STATIC );
2089
guPlayListAppend * PlayListAppendDlg = new guPlayListAppend( m_MainFrame, m_Db, &TrackIds, &PlayLists );
2090
if( PlayListAppendDlg->ShowModal() == wxID_OK )
2092
int Selected = PlayListAppendDlg->GetSelectedPlayList();
2093
if( Selected == -1 )
2095
wxString PLName = PlayListAppendDlg->GetPlaylistName();
2096
if( PLName.IsEmpty() )
2098
PLName = _( "UnNamed" );
2100
m_Db->CreateStaticPlayList( PLName, TrackIds );
2104
int PLId = PlayLists[ Selected ].m_Id;
2105
wxArrayInt OldSongs;
2106
m_Db->GetPlayListSongIds( PLId, &OldSongs );
2107
if( PlayListAppendDlg->GetSelectedPosition() == 0 ) // BEGIN
2109
m_Db->UpdateStaticPlayList( PLId, TrackIds );
2110
m_Db->AppendStaticPlayList( PLId, OldSongs );
2114
m_Db->AppendStaticPlayList( PLId, TrackIds );
2118
m_MediaViewer->UpdatePlaylists();
2121
PlayListAppendDlg->Destroy();
2125
// -------------------------------------------------------------------------------- //
2126
void guFileBrowser::OnItemsCopyTo( wxCommandEvent &event )
2128
guTrackArray * Tracks = new guTrackArray();
2129
m_FilesCtrl->GetSelectedSongs( Tracks );
2131
int Index = event.GetId() - ID_COPYTO_BASE;
2132
if( Index >= guCOPYTO_DEVICE_BASE )
2134
Index -= guCOPYTO_DEVICE_BASE;
2135
event.SetId( ID_MAINFRAME_COPYTODEVICE_TRACKS );
2139
event.SetId( ID_MAINFRAME_COPYTO );
2141
event.SetInt( Index );
2142
event.SetClientData( ( void * ) Tracks );
2143
wxPostEvent( m_MainFrame, event );
2146
// -------------------------------------------------------------------------------- //
2147
void guFileBrowser::OnItemsRename( wxCommandEvent &event )
2149
wxArrayString Files = m_FilesCtrl->GetSelectedFiles( true );
2152
guFileRenamer * FileRenamer = new guFileRenamer( this, m_Db ? m_Db : m_DefaultDb, Files );
2155
if( FileRenamer->ShowModal() == wxID_OK )
2157
wxArrayString RenamedFiles = FileRenamer->GetRenamedNames();
2159
int Count = RenamedFiles.Count();
2160
for( Index = 0; Index < Count; Index++ )
2162
if( Files[ Index ] != RenamedFiles[ Index ] )
2164
wxString NewDirName = wxPathOnly( RenamedFiles[ Index ] );
2165
if( !wxDirExists( NewDirName ) )
2167
wxFileName::Mkdir( NewDirName, 0770, wxPATH_MKDIR_FULL );
2170
//if( wxFileExists( Files[ Index ] ) )
2171
if( !guRenameFile( Files[ Index ], RenamedFiles[ Index ] ) )
2173
guLogError( wxT( "Could no rename '%s' to '%s'" ),
2174
Files[ Index ].c_str(),
2175
RenamedFiles[ Index ].c_str() );
2179
m_Db->UpdateTrackFileName( Files[ Index ], RenamedFiles[ Index ] );
2181
m_DefaultDb->UpdateTrackFileName( Files[ Index ], RenamedFiles[ Index ] );
2185
//m_DirCtrl->ExpandPath( m_DirCtrl->GetPath() );
2186
m_FilesCtrl->SetPath( m_DirCtrl->GetPath(), m_MediaViewer );
2188
FileRenamer->Destroy();
2193
// -------------------------------------------------------------------------------- //
2194
void guFileBrowser::OnItemsDelete( wxCommandEvent &event )
2196
wxArrayString Files = m_FilesCtrl->GetSelectedFiles();
2201
if( ( Count = Files.Count() ) )
2203
if( wxMessageBox( _( "Are you sure to delete the selected files ?" ),
2205
wxICON_QUESTION | wxYES_NO, this ) == wxYES )
2207
wxArrayString DeleteFiles;
2208
for( Index = 0; Index < Count; Index++ )
2210
if( wxDirExists( Files[ Index ] ) )
2212
Error = !RemoveDirItems( Files[ Index ], &DeleteFiles ) || !wxRmdir( Files[ Index ] );
2216
Error = !wxRemoveFile( Files[ Index ] );
2217
DeleteFiles.Add( Files[ Index ] );
2221
if( wxMessageBox( _( "There was an error deleting " ) + wxFileNameFromPath( Files[ Index ] ) +
2222
_( "\nContinue deleting?" ),
2224
wxICON_QUESTION | wxYES_NO, this ) == wxNO )
2231
wxString CurrentFolder = m_DirCtrl->GetPath();
2232
m_DirCtrl->CollapsePath( CurrentFolder );
2233
m_DirCtrl->ExpandPath( CurrentFolder );
2235
//m_Db->DoCleanUp();
2237
m_Db->CleanFiles( DeleteFiles );
2239
m_DefaultDb->CleanFiles( DeleteFiles );
2244
// -------------------------------------------------------------------------------- //
2245
void guFileBrowser::OnFolderCommand( wxCommandEvent &event )
2249
Index = event.GetId();
2251
guConfig * Config = ( guConfig * ) Config->Get();
2254
wxArrayString Commands = Config->ReadAStr( wxT( "Exec" ), wxEmptyString, wxT( "commands/execs" ) );
2256
Index -= ID_COMMANDS_BASE;
2257
wxString CurCmd = Commands[ Index ];
2258
if( CurCmd.Find( wxT( "{bp}" ) ) != wxNOT_FOUND )
2260
wxString DirPath = m_DirCtrl->GetPath();
2261
DirPath.Replace( wxT( " " ), wxT( "\\ " ) );
2262
CurCmd.Replace( wxT( "{bp}" ), DirPath );
2265
if( CurCmd.Find( wxT( "{tp}" ) ) != wxNOT_FOUND )
2268
wxArrayString Files = m_FilesCtrl->GetAllFiles( true );
2269
Count = Files.Count();
2270
for( Index = 0; Index < Count; Index++ )
2272
SongList += wxT( " \"" ) + Files[ Index ] + wxT( "\"" );
2274
CurCmd.Replace( wxT( "{tp}" ), SongList.Trim( false ) );
2277
//guLogMessage( wxT( "Execute Command '%s'" ), CurCmd.c_str() );
2278
guExecute( CurCmd );
2282
// -------------------------------------------------------------------------------- //
2283
void guFileBrowser::OnItemsCommand( wxCommandEvent &event )
2287
Index = event.GetId();
2289
guConfig * Config = ( guConfig * ) Config->Get();
2292
wxArrayString Commands = Config->ReadAStr( wxT( "Exec" ), wxEmptyString, wxT( "commands/execs" ) );
2294
Index -= ID_COMMANDS_BASE;
2295
wxString CurCmd = Commands[ Index ];
2296
if( CurCmd.Find( wxT( "{bp}" ) ) != wxNOT_FOUND )
2298
wxString DirPath = m_DirCtrl->GetPath();
2299
DirPath.Replace( wxT( " " ), wxT( "\\ " ) );
2300
CurCmd.Replace( wxT( "{bp}" ), DirPath );
2303
if( CurCmd.Find( wxT( "{bc}" ) ) != wxNOT_FOUND )
2306
wxArrayString Files = m_FilesCtrl->GetSelectedFiles( false );
2307
Count = Files.Count();
2308
for( Index = 0; Index < Count; Index++ )
2310
SongList += wxT( " \"" ) + Files[ Index ] + wxT( "\"" );
2312
CurCmd.Replace( wxT( "{bc}" ), SongList.Trim( false ) );
2315
if( CurCmd.Find( wxT( "{tp}" ) ) != wxNOT_FOUND )
2318
wxArrayString Files = m_FilesCtrl->GetSelectedFiles( true );
2319
Count = Files.Count();
2320
for( Index = 0; Index < Count; Index++ )
2322
SongList += wxT( " \"" ) + Files[ Index ] + wxT( "\"" );
2324
CurCmd.Replace( wxT( "{tp}" ), SongList.Trim( false ) );
2327
//guLogMessage( wxT( "Execute Command '%s'" ), CurCmd.c_str() );
2328
guExecute( CurCmd );
2332
// -------------------------------------------------------------------------------- //
2333
void guFileBrowser::OnItemsCopy( wxCommandEvent &event )
2335
wxArrayString Files = m_FilesCtrl->GetSelectedFiles( false );
2338
wxTheClipboard->UsePrimarySelection( false );
2339
if( wxTheClipboard->Open() )
2341
wxTheClipboard->Clear();
2342
wxFileDataObject * FileObject = new wxFileDataObject();
2343
wxTextDataObject * TextObject = new wxTextDataObject();
2344
wxDataObjectComposite * CompositeObject = new wxDataObjectComposite();
2348
int Count = Files.Count();
2349
for( Index = 0; Index < Count; Index++ )
2351
wxString CurFile = Files[ Index ];
2352
FilesText += ( FilesText.IsEmpty() ? wxT( "" ) : wxT( "\n" ) ) + CurFile;
2354
CurFile.Replace( wxT( "#" ), wxT( "%23" ) );
2355
FileObject->AddFile( CurFile );
2358
TextObject->SetText( FilesText );
2360
CompositeObject->Add( FileObject );
2361
CompositeObject->Add( TextObject );
2363
if( !wxTheClipboard->AddData( CompositeObject ) )
2367
delete CompositeObject;
2368
guLogError( wxT( "Can't copy the selected files to the clipboard" ) );
2370
wxTheClipboard->Close();
2374
guLogError( wxT( "Could not open the clipboard object" ) );
2379
// -------------------------------------------------------------------------------- //
2380
void guFileBrowser::OnItemsPaste( wxCommandEvent &event )
2382
wxString DestFolder;
2383
wxTheClipboard->UsePrimarySelection( false );
2384
if( wxTheClipboard->Open() )
2386
if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
2388
wxArrayString Selection = m_FilesCtrl->GetSelectedFiles( false );
2389
if( ( Selection.Count() == 1 ) && wxDirExists( Selection[ 0 ] ) )
2391
DestFolder = Selection[ 0 ];
2395
DestFolder = m_DirCtrl->GetPath();
2398
wxFileDataObject FileObject;
2399
if( wxTheClipboard->GetData( FileObject ) )
2401
wxArrayString Files = FileObject.GetFilenames();
2402
wxArrayString FromFiles;
2403
//guLogMessage( wxT( "Pasted: %s" ), Files[ 0 ].c_str() );
2405
int Count = Files.Count();
2406
for( Index = 0; Index < Count; Index++ )
2408
if( wxDirExists( Files[ Index ] ) )
2410
guAddDirItems( Files[ Index ], FromFiles );
2413
int FromCount = FromFiles.Count();
2414
for( FromIndex = 0; FromIndex < FromCount; FromIndex++ )
2416
wxString DestName = FromFiles[ FromIndex ];
2417
DestName.Replace( wxPathOnly( Files[ Index ] ), DestFolder );
2418
wxFileName::Mkdir( wxPathOnly( DestName ), 0770, wxPATH_MKDIR_FULL );
2419
guLogMessage( wxT( "Copy file %s to %s" ), FromFiles[ FromIndex ].c_str(), DestName.c_str() );
2420
wxCopyFile( FromFiles[ FromIndex ], DestName );
2425
wxCopyFile( Files[ Index ], m_DirCtrl->GetPath() + wxT( "/" ) + wxFileNameFromPath( Files[ Index ] ) );
2428
wxString CurPath = m_DirCtrl->GetPath();
2429
m_DirCtrl->CollapsePath( CurPath );
2430
m_DirCtrl->ExpandPath( CurPath );
2434
guLogError( wxT( "Can't paste the data from the clipboard" ) );
2437
wxTheClipboard->Close();
2441
guLogError( wxT( "Could not open the clipboard object" ) );
2445
// -------------------------------------------------------------------------------- //