1998-05-20 10:01:55 -04:00
|
|
|
/*
|
|
|
|
* Program: wxFile
|
|
|
|
*
|
|
|
|
* Author: Robert Roebling
|
|
|
|
*
|
|
|
|
* Copyright: (C) 1997, GNU (Robert Roebling)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "wxFile.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wxFile.h"
|
|
|
|
#include "wx/dnd.h"
|
|
|
|
|
|
|
|
#include "delete.xpm"
|
|
|
|
#include "home.xpm"
|
|
|
|
#include "prev.xpm"
|
|
|
|
#include "fileopen.xpm"
|
|
|
|
#include "exit.xpm"
|
|
|
|
#include "listview.xpm"
|
|
|
|
#include "iconview.xpm"
|
|
|
|
#include "reportview.xpm"
|
|
|
|
#include "treeview.xpm"
|
|
|
|
#include "commanderview.xpm"
|
|
|
|
#include "singleview.xpm"
|
|
|
|
#include "save.xpm"
|
|
|
|
#include "search.xpm"
|
|
|
|
#include "help.xpm"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// main program
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
const int ID_FILECTRL = 1000;
|
|
|
|
const int ID_DIRCTRL = 1001;
|
|
|
|
const int ID_TOOLBAR = 1002;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
const int ID_QUIT = 100;
|
|
|
|
const int ID_ABOUT = 101;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
const int ID_LIST = 200;
|
|
|
|
const int ID_REPORT = 201;
|
|
|
|
const int ID_ICON = 202;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
const int ID_SINGLE = 203;
|
|
|
|
const int ID_TREE = 204;
|
|
|
|
const int ID_COMMANDER = 205;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
const int ID_HOME = 400;
|
|
|
|
const int ID_PARENT = 401;
|
|
|
|
const int ID_MOUNT = 402;
|
|
|
|
const int ID_SEARCH = 403;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
const int ID_DELETE = 501;
|
|
|
|
const int ID_MD = 502;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
|
|
|
EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU (ID_QUIT, MyFrame::OnCommand)
|
|
|
|
EVT_MENU (ID_HOME, MyFrame::OnCommand)
|
|
|
|
EVT_MENU (ID_PARENT, MyFrame::OnCommand)
|
|
|
|
EVT_MENU (ID_LIST, MyFrame::OnView)
|
|
|
|
EVT_MENU (ID_REPORT, MyFrame::OnView)
|
|
|
|
EVT_MENU (ID_ICON, MyFrame::OnView)
|
1998-07-24 15:05:25 -04:00
|
|
|
EVT_MENU (ID_TREE, MyFrame::OnView)
|
|
|
|
EVT_MENU (ID_SINGLE, MyFrame::OnView)
|
|
|
|
EVT_MENU (ID_COMMANDER, MyFrame::OnView)
|
1998-05-20 10:01:55 -04:00
|
|
|
EVT_LIST_KEY_DOWN (ID_FILECTRL, MyFrame::OnListKeyDown)
|
|
|
|
EVT_LIST_DELETE_ITEM (ID_FILECTRL, MyFrame::OnListDeleteItem)
|
|
|
|
EVT_LIST_END_LABEL_EDIT (ID_FILECTRL, MyFrame::OnListEndLabelEdit)
|
|
|
|
EVT_LIST_BEGIN_DRAG (ID_FILECTRL, MyFrame::OnListDrag)
|
|
|
|
EVT_TREE_KEY_DOWN (ID_DIRCTRL, MyFrame::OnTreeKeyDown)
|
|
|
|
EVT_TREE_SEL_CHANGED (ID_DIRCTRL, MyFrame::OnTreeSelected)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MyFrame::MyFrame(void) :
|
1998-08-22 23:22:56 -04:00
|
|
|
wxFrame( (wxFrame *) NULL, -1, (char *) "wxFile", wxPoint(20,20), wxSize(470,360) )
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
|
|
|
wxMenu *file_menu = new wxMenu( "Menu 1" );
|
|
|
|
file_menu->Append( ID_ABOUT, "About..");
|
|
|
|
file_menu->Append( ID_QUIT, "Exit");
|
|
|
|
|
|
|
|
wxMenu *view_menu = new wxMenu( "Menu 2" );
|
|
|
|
view_menu->Append( ID_LIST, "List mode");
|
|
|
|
view_menu->Append( ID_REPORT, "Report mode");
|
|
|
|
view_menu->Append( ID_ICON, "Icon mode");
|
|
|
|
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar();
|
|
|
|
menu_bar->Append(file_menu, "File" );
|
|
|
|
menu_bar->Append(view_menu, "View" );
|
|
|
|
menu_bar->Show( TRUE );
|
|
|
|
|
|
|
|
SetMenuBar( menu_bar );
|
|
|
|
|
|
|
|
CreateStatusBar( 2 );
|
|
|
|
|
|
|
|
SetStatusText( "Welcome", 0 );
|
|
|
|
SetStatusText( "wxFile v0.2 by Robert Roebling.", 1 );
|
|
|
|
|
1998-07-29 04:07:45 -04:00
|
|
|
wxToolBar *m_tb = CreateToolBar();
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->SetMargins( 2, 2 );
|
|
|
|
|
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_QUIT, wxBitmap( exit_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Exit wxFile" );
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_PARENT, wxBitmap( prev_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Go to parent directory" );
|
|
|
|
m_tb->AddTool( ID_HOME, wxBitmap( home_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Go to home directory" );
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_DELETE, wxBitmap( delete_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Delete file" );
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_MD, wxBitmap( fileopen_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Create directory" );
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_LIST, wxBitmap( listview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "List view" );
|
|
|
|
m_tb->AddTool( ID_REPORT, wxBitmap( reportview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Report view" );
|
|
|
|
m_tb->AddTool( ID_ICON, wxBitmap( iconview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Icon view" );
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_TREE, wxBitmap( treeview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Tree view" );
|
|
|
|
m_tb->AddTool( ID_COMMANDER, wxBitmap( commanderview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Commander view" );
|
|
|
|
m_tb->AddTool( ID_SINGLE, wxBitmap( singleview_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Single view" );
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_MOUNT, wxBitmap( search_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Mount devices" );
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_SEARCH, wxBitmap( save_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "Find file(s)" );
|
1998-05-20 10:01:55 -04:00
|
|
|
m_tb->AddSeparator();
|
1998-08-22 23:22:56 -04:00
|
|
|
m_tb->AddTool( ID_ABOUT, wxBitmap( help_xpm ), wxNullBitmap, FALSE, -1, -1, (wxObject *) NULL, "About wxFile" );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-29 04:07:45 -04:00
|
|
|
m_tb->Realize();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
m_splitter = new wxSplitterWindow( this, -1, wxPoint(0,0), wxSize(400,300), wxSP_3D );
|
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
m_leftFile = (wxFileCtrl *) NULL;
|
1998-05-20 10:01:55 -04:00
|
|
|
m_dir = new wxDirCtrl( m_splitter, ID_DIRCTRL, "/", wxPoint(10,45), wxSize(200,330) );
|
|
|
|
|
|
|
|
wxString homepath( "/home" );
|
1998-09-10 07:41:14 -04:00
|
|
|
wxString str;
|
|
|
|
wxGetHomeDir( & str );
|
|
|
|
homepath = str;
|
1998-05-20 10:01:55 -04:00
|
|
|
m_rightFile = new wxFileCtrl( m_splitter, ID_FILECTRL, homepath, wxPoint(220,5), wxSize(200,330) );
|
|
|
|
|
|
|
|
m_leftFile = new wxFileCtrl( m_splitter, ID_FILECTRL, homepath, wxPoint(0,5), wxSize(200,330) );
|
|
|
|
m_leftFile->Show( FALSE );
|
|
|
|
|
|
|
|
m_leftFile->m_lastFocus = m_rightFile;
|
|
|
|
|
|
|
|
int x = 0;
|
1998-08-22 23:22:56 -04:00
|
|
|
GetClientSize( &x, (int *) NULL );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
m_splitter->SplitVertically( m_dir, m_rightFile, x / 3 );
|
|
|
|
m_splitter->SetMinimumPaneSize( 10 );
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnView( wxCommandEvent &event )
|
|
|
|
{
|
|
|
|
int x = 0;
|
1998-08-22 23:22:56 -04:00
|
|
|
GetClientSize( &x, (int *) NULL );
|
1998-05-20 10:01:55 -04:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case ID_LIST:
|
|
|
|
m_rightFile->ChangeToListMode();
|
|
|
|
if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
|
|
|
|
m_leftFile->ChangeToListMode();
|
|
|
|
break;
|
|
|
|
case ID_REPORT:
|
|
|
|
m_rightFile->ChangeToReportMode();
|
|
|
|
if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
|
|
|
|
m_leftFile->ChangeToReportMode();
|
|
|
|
break;
|
|
|
|
case ID_ICON:
|
|
|
|
m_rightFile->ChangeToIconMode();
|
|
|
|
if (m_splitter->IsSplit() && (m_splitter->GetWindow1() == m_leftFile))
|
|
|
|
m_leftFile->ChangeToIconMode();
|
|
|
|
break;
|
|
|
|
case ID_TREE:
|
|
|
|
if (m_splitter->IsSplit())
|
|
|
|
{
|
|
|
|
if (m_splitter->GetWindow1() != m_dir)
|
|
|
|
{
|
|
|
|
m_splitter->Unsplit( m_leftFile );
|
|
|
|
m_dir->Show(TRUE);
|
|
|
|
m_splitter->SplitVertically( m_dir, m_rightFile, x/3 );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dir->Show(TRUE);
|
|
|
|
m_splitter->SplitVertically( m_dir, m_rightFile, x/3 );
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case ID_SINGLE:
|
|
|
|
if (m_splitter->IsSplit()) m_splitter->Unsplit( m_splitter->GetWindow1() );
|
|
|
|
break;
|
|
|
|
case ID_COMMANDER:
|
|
|
|
if (m_splitter->IsSplit())
|
|
|
|
{
|
|
|
|
if (m_splitter->GetWindow1() != m_leftFile)
|
|
|
|
{
|
|
|
|
m_splitter->Unsplit( m_dir );
|
|
|
|
m_leftFile->ChangeToListMode();
|
|
|
|
m_rightFile->ChangeToListMode();
|
|
|
|
m_leftFile->Show(TRUE);
|
|
|
|
m_splitter->SplitVertically( m_leftFile, m_rightFile, x/2 );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_leftFile->ChangeToListMode();
|
|
|
|
m_rightFile->ChangeToListMode();
|
|
|
|
m_leftFile->Show(TRUE);
|
|
|
|
m_splitter->SplitVertically( m_leftFile, m_rightFile, x/2 );
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnCommand( wxCommandEvent &event )
|
|
|
|
{
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case ID_QUIT:
|
|
|
|
Close( TRUE );
|
|
|
|
break;
|
|
|
|
case ID_HOME:
|
|
|
|
m_leftFile->m_lastFocus->GoToHomeDir();
|
|
|
|
break;
|
|
|
|
case ID_PARENT:
|
|
|
|
m_leftFile->m_lastFocus->GoToParentDir();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
wxDialog dialog( this, -1, "About wxFile", wxPoint(100,100), wxSize(540,350), wxDIALOG_MODAL );
|
|
|
|
|
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
dialog.GetSize( &w, &h );
|
|
|
|
|
|
|
|
int x = 30;
|
|
|
|
int y = 20;
|
|
|
|
int step = 20;
|
|
|
|
|
|
|
|
(void)new wxStaticBox( &dialog, -1, (const char*)NULL, wxPoint(10,10), wxSize(w-20,h-80) );
|
|
|
|
|
|
|
|
(void)new wxStaticText( &dialog, -1, "wxFile v0.1", wxPoint(240,y) );
|
|
|
|
y += 2*step-10;
|
|
|
|
|
|
|
|
(void)new wxStaticText( &dialog, -1, "Written by Robert Roebling, 1998.", wxPoint(x,y) );
|
|
|
|
y += 2*step;
|
|
|
|
|
|
|
|
(void)new wxStaticText( &dialog, -1,
|
|
|
|
"wxFile uses wxGTK, the GTK port of the wxWindows GUI-library.", wxPoint(x,y) );
|
|
|
|
y += step;
|
|
|
|
(void)new wxStaticText( &dialog, -1, "http://www.freiburg.linux.de/~wxxt", wxPoint(x+50,y) );
|
|
|
|
y += step;
|
|
|
|
(void)new wxStaticText( &dialog, -1, "http://web.ukonline.co.uk/julian.smart/wxwin", wxPoint(x+50,y) );
|
|
|
|
y += 2*step;
|
|
|
|
|
|
|
|
(void)new wxStaticText( &dialog, -1, "wxFile Copyright: GPL.", wxPoint(x,y) );
|
|
|
|
y += 2*step;
|
|
|
|
(void)new wxStaticText( &dialog, -1, "For questions concerning wxGTK, you may mail to:", wxPoint(x,y) );
|
|
|
|
y += step;
|
|
|
|
(void)new wxStaticText( &dialog, -1, "roebling@ruf.uni-freiburg.de", wxPoint(x+50,y) );
|
|
|
|
|
|
|
|
(void) new wxButton( &dialog, wxID_OK, "Return", wxPoint(w/2-40,h-50), wxSize(80,30) );
|
|
|
|
|
1998-07-31 16:04:04 -04:00
|
|
|
dialog.Fit();
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
dialog.ShowModal();
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnListKeyDown( wxListEvent &event )
|
|
|
|
{
|
|
|
|
m_rightFile->m_lastFocus->OnListKeyDown( event );
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnListDeleteItem( wxListEvent &event )
|
|
|
|
{
|
|
|
|
m_rightFile->m_lastFocus->OnListDeleteItem( event );
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnListEndLabelEdit( wxListEvent &event )
|
|
|
|
{
|
|
|
|
m_rightFile->m_lastFocus->OnListEndLabelEdit( event );
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnListDrag( wxListEvent &event )
|
|
|
|
{
|
1998-07-27 16:50:48 -04:00
|
|
|
wxFileDataObject data;
|
|
|
|
data.AddFile( "/home/karl/test.txt" );
|
|
|
|
|
|
|
|
wxDropSource drag( data, m_leftFile->m_lastFocus );
|
|
|
|
drag.DoDragDrop();
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnTreeSelected( wxTreeEvent &event )
|
|
|
|
{
|
|
|
|
wxDirInfo *info = (wxDirInfo*) event.m_item.m_data;
|
1998-07-10 19:08:39 -04:00
|
|
|
if (info) SetStatusText( info->GetPath() );
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void MyFrame::OnTreeKeyDown( wxTreeEvent &event )
|
|
|
|
{
|
|
|
|
wxDirInfo *info = (wxDirInfo*) event.m_item.m_data;
|
1998-07-10 19:08:39 -04:00
|
|
|
if (info) m_rightFile->GoToDir( info->GetPath() );
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MyApp::MyApp(void) :
|
|
|
|
wxApp( )
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
bool MyApp::OnInit(void)
|
|
|
|
{
|
|
|
|
wxFrame *frame = new MyFrame();
|
|
|
|
frame->Show( TRUE );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|