filedlgg.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 1,603 行 · 第 1/4 页
CPP
1,603 行
return;
}
wxString new_name( wxPathOnly( fd->GetFilePath() ) );
new_name += wxFILE_SEP_PATH;
new_name += event.GetLabel();
wxLogNull log;
if (wxFileExists(new_name))
{
wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR );
dialog.ShowModal();
event.Veto();
}
if (wxRenameFile(fd->GetFilePath(),new_name))
{
fd->SetNewName( new_name, event.GetLabel() );
ignoreChanges = true;
SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
ignoreChanges = false;
UpdateItem( event.GetItem() );
EnsureVisible( event.GetItem() );
}
else
{
wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
dialog.ShowModal();
event.Veto();
}
}
void wxFileCtrl::OnListColClick( wxListEvent &event )
{
int col = event.GetColumn();
switch (col)
{
case wxFileData::FileList_Name :
case wxFileData::FileList_Size :
case wxFileData::FileList_Type :
case wxFileData::FileList_Time : break;
default : return;
}
if ((wxFileData::fileListFieldType)col == m_sort_field)
m_sort_foward = !m_sort_foward;
else
m_sort_field = (wxFileData::fileListFieldType)col;
SortItems(m_sort_field, m_sort_foward);
}
void wxFileCtrl::SortItems(wxFileData::fileListFieldType field, bool foward)
{
m_sort_field = field;
m_sort_foward = foward;
long sort_dir = foward ? 1 : -1;
switch (m_sort_field)
{
case wxFileData::FileList_Name :
{
wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataNameCompare, sort_dir);
break;
}
case wxFileData::FileList_Size :
{
wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataSizeCompare, sort_dir);
break;
}
case wxFileData::FileList_Type :
{
wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataTypeCompare, sort_dir);
break;
}
case wxFileData::FileList_Time :
{
wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataTimeCompare, sort_dir);
break;
}
default : break;
}
}
wxFileCtrl::~wxFileCtrl()
{
// Normally the data are freed via an EVT_LIST_DELETE_ALL_ITEMS event and
// wxFileCtrl::OnListDeleteAllItems. But if the event is generated after
// the destruction of the wxFileCtrl we need to free any data here:
FreeAllItemsData();
}
//-----------------------------------------------------------------------------
// wxGenericFileDialog
//-----------------------------------------------------------------------------
#define ID_LIST_MODE (wxID_FILEDLGG )
#define ID_REPORT_MODE (wxID_FILEDLGG + 1)
#define ID_UP_DIR (wxID_FILEDLGG + 5)
#define ID_PARENT_DIR (wxID_FILEDLGG + 6)
#define ID_NEW_DIR (wxID_FILEDLGG + 7)
#define ID_CHOICE (wxID_FILEDLGG + 8)
#define ID_TEXT (wxID_FILEDLGG + 9)
#define ID_LIST_CTRL (wxID_FILEDLGG + 10)
#define ID_CHECK (wxID_FILEDLGG + 12)
IMPLEMENT_DYNAMIC_CLASS(wxGenericFileDialog, wxFileDialogBase)
BEGIN_EVENT_TABLE(wxGenericFileDialog,wxDialog)
EVT_BUTTON(ID_LIST_MODE, wxGenericFileDialog::OnList)
EVT_BUTTON(ID_REPORT_MODE, wxGenericFileDialog::OnReport)
EVT_BUTTON(ID_UP_DIR, wxGenericFileDialog::OnUp)
EVT_BUTTON(ID_PARENT_DIR, wxGenericFileDialog::OnHome)
EVT_BUTTON(ID_NEW_DIR, wxGenericFileDialog::OnNew)
EVT_BUTTON(wxID_OK, wxGenericFileDialog::OnListOk)
EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL, wxGenericFileDialog::OnSelected)
EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxGenericFileDialog::OnActivated)
EVT_CHOICE(ID_CHOICE,wxGenericFileDialog::OnChoiceFilter)
EVT_TEXT_ENTER(ID_TEXT,wxGenericFileDialog::OnTextEnter)
EVT_TEXT(ID_TEXT,wxGenericFileDialog::OnTextChange)
EVT_CHECKBOX(ID_CHECK,wxGenericFileDialog::OnCheck)
END_EVENT_TABLE()
long wxGenericFileDialog::ms_lastViewStyle = wxLC_LIST;
bool wxGenericFileDialog::ms_lastShowHidden = false;
void wxGenericFileDialog::Init()
{
m_bypassGenericImpl = false;
m_choice = NULL;
m_text = NULL;
m_list = NULL;
m_check = NULL;
m_static = NULL;
m_upDirButton = NULL;
m_newDirButton = NULL;
}
wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
const wxString& message,
const wxString& defaultDir,
const wxString& defaultFile,
const wxString& wildCard,
long style,
const wxPoint& pos,
bool bypassGenericImpl ) : wxFileDialogBase()
{
Init();
Create( parent, message, defaultDir, defaultFile, wildCard, style, pos, bypassGenericImpl );
}
bool wxGenericFileDialog::Create( wxWindow *parent,
const wxString& message,
const wxString& defaultDir,
const wxString& defaultFile,
const wxString& wildCard,
long style,
const wxPoint& pos,
bool bypassGenericImpl )
{
m_bypassGenericImpl = bypassGenericImpl;
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile,
wildCard, style, pos))
{
return false;
}
if (m_bypassGenericImpl)
return true;
if (!wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ))
{
return false;
}
ignoreChanges = true;
if (wxConfig::Get(false))
{
wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ViewStyle"),
&ms_lastViewStyle);
wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ShowHidden"),
&ms_lastShowHidden);
}
if (m_dialogStyle == 0)
m_dialogStyle = wxOPEN;
if ((m_dialogStyle & wxMULTIPLE ) && !(m_dialogStyle & wxOPEN))
m_dialogStyle |= wxOPEN;
if ((m_dir.empty()) || (m_dir == wxT(".")))
{
m_dir = wxGetCwd();
if (m_dir.empty())
m_dir = wxFILE_SEP_PATH;
}
size_t len = m_dir.Len();
if ((len > 1) && (wxEndsWithPathSeparator(m_dir)))
m_dir.Remove( len-1, 1 );
m_path = m_dir;
m_path += wxFILE_SEP_PATH;
m_path += defaultFile;
m_filterExtension = wxEmptyString;
// layout
bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
wxBitmapButton *but;
but = new wxBitmapButton(this, ID_LIST_MODE,
wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_BUTTON));
#if wxUSE_TOOLTIPS
but->SetToolTip( _("View files as a list view") );
#endif
buttonsizer->Add( but, 0, wxALL, 5 );
but = new wxBitmapButton(this, ID_REPORT_MODE,
wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_BUTTON));
#if wxUSE_TOOLTIPS
but->SetToolTip( _("View files as a detailed view") );
#endif
buttonsizer->Add( but, 0, wxALL, 5 );
buttonsizer->Add( 30, 5, 1 );
m_upDirButton = new wxBitmapButton(this, ID_UP_DIR,
wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_BUTTON));
#if wxUSE_TOOLTIPS
m_upDirButton->SetToolTip( _("Go to parent directory") );
#endif
buttonsizer->Add( m_upDirButton, 0, wxALL, 5 );
#ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS...
but = new wxBitmapButton(this, ID_PARENT_DIR,
wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_BUTTON));
#if wxUSE_TOOLTIPS
but->SetToolTip( _("Go to home directory") );
#endif
buttonsizer->Add( but, 0, wxALL, 5);
buttonsizer->Add( 20, 20 );
#endif //!__DOS__
m_newDirButton = new wxBitmapButton(this, ID_NEW_DIR,
wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_BUTTON));
#if wxUSE_TOOLTIPS
m_newDirButton->SetToolTip( _("Create new directory") );
#endif
buttonsizer->Add( m_newDirButton, 0, wxALL, 5 );
if (is_pda)
mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 0 );
else
mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 );
wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL );
if (!is_pda)
staticsizer->Add( new wxStaticText( this, wxID_ANY, _("Current directory:") ), 0, wxRIGHT, 10 );
m_static = new wxStaticText( this, wxID_ANY, m_dir );
staticsizer->Add( m_static, 1 );
mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 );
long style2 = ms_lastViewStyle;
if ( !(m_dialogStyle & wxMULTIPLE) )
style2 |= wxLC_SINGLE_SEL;
#ifdef __WXWINCE__
style2 |= wxSIMPLE_BORDER;
#else
style2 |= wxSUNKEN_BORDER;
#endif
wxSize list_size(500,240);
if (is_pda) list_size = wxSize(50,80);
m_list = new wxFileCtrl( this, ID_LIST_CTRL,
wxEmptyString, ms_lastShowHidden,
wxDefaultPosition, list_size,
style2);
if (is_pda)
{
// PDAs have a different screen layout
mainsizer->Add( m_list, 1, wxEXPAND|wxSHRINK | wxLEFT|wxRIGHT, 5 );
wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER );
textsizer->Add( m_text, 1, wxCENTER | wxALL, 5 );
mainsizer->Add( textsizer, 0, wxEXPAND );
m_check = NULL;
m_choice = new wxChoice( this, ID_CHOICE );
textsizer->Add( m_choice, 1, wxCENTER|wxALL, 5 );
buttonsizer = new wxBoxSizer( wxHORIZONTAL );
buttonsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxALL, 5 );
buttonsizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 5 );
mainsizer->Add( buttonsizer, 0, wxALIGN_RIGHT );
}
else
{
mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 );
wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER );
textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
textsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
mainsizer->Add( textsizer, 0, wxEXPAND );
wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
m_choice = new wxChoice( this, ID_CHOICE );
choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 );
m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") );
m_check->SetValue( ms_lastShowHidden );
choicesizer->Add( m_check, 0, wxCENTER|wxALL, 10 );
choicesizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 10 );
mainsizer->Add( choicesizer, 0, wxEXPAND );
}
SetWildcard(wildCard);
SetAutoLayout( true );
SetSizer( mainsizer );
if (!is_pda)
{
mainsizer->Fit( this );
mainsizer->SetSizeHints( this );
Centre( wxBOTH );
}
m_text->SetFocus();
ignoreChanges = false;
return true;
}
wxGenericFileDialog::~wxGenericFileDialog()
{
ignoreChanges = true;
if (!m_bypassGenericImpl)
{
if (wxConfig::Get(false))
{
wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"),
ms_lastViewStyle);
wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"),
ms_lastShowHidden);
}
const int count = m_choice->GetCount();
for ( int i = 0; i < count; i++ )
{
delete (wxString *)m_choice->GetClientData(i);
}
}
}
int wxGenericFileDialog::ShowModal()
{
ignoreChanges = true;
m_list->GoToDir(m_dir);
UpdateControls();
m_text->SetValue(m_fileName);
ignoreChanges = false;
return wxDialog::ShowModal();
}
bool wxGenericFileDialog::Show( bool show )
{
// Called by ShowModal, so don't repeate the update
#ifndef __WIN32__
if (show)
{
m_list->GoToDir(m_dir);
UpdateControls();
m_text->SetValue(m_fileName);
}
#endif
return wxDialog::Show( show );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?