More wxFileDialog things
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3420 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -132,6 +132,7 @@ public:
|
|||||||
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
||||||
long style = 0,
|
long style = 0,
|
||||||
const wxPoint& pos = wxDefaultPosition);
|
const wxPoint& pos = wxDefaultPosition);
|
||||||
|
~wxFileDialog();
|
||||||
|
|
||||||
void SetMessage(const wxString& message) { m_message = message; }
|
void SetMessage(const wxString& message) { m_message = message; }
|
||||||
void SetPath(const wxString& path);
|
void SetPath(const wxString& path);
|
||||||
@@ -157,6 +158,8 @@ public:
|
|||||||
void OnHome( wxCommandEvent &event );
|
void OnHome( wxCommandEvent &event );
|
||||||
void OnListOk( wxCommandEvent &event );
|
void OnListOk( wxCommandEvent &event );
|
||||||
void OnNew( wxCommandEvent &event );
|
void OnNew( wxCommandEvent &event );
|
||||||
|
void OnChoice( wxCommandEvent &event );
|
||||||
|
void OnTextEnter( wxCommandEvent &event );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxString m_message;
|
wxString m_message;
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "wx/msgdlg.h"
|
#include "wx/msgdlg.h"
|
||||||
#include "wx/sizer.h"
|
#include "wx/sizer.h"
|
||||||
#include "wx/bmpbuttn.h"
|
#include "wx/bmpbuttn.h"
|
||||||
|
#include "wx/tokenzr.h"
|
||||||
|
|
||||||
#if wxUSE_TOOLTIPS
|
#if wxUSE_TOOLTIPS
|
||||||
#include "wx/tooltip.h"
|
#include "wx/tooltip.h"
|
||||||
@@ -344,8 +345,8 @@ void wxFileCtrl::Update()
|
|||||||
item.m_itemId++;
|
item.m_itemId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString res = m_dirName + _T("/") + m_wild;
|
wxString res = m_dirName + _T("/*");
|
||||||
wxString f( wxFindFirstFile( res.GetData(), 0 ) );
|
wxString f( wxFindFirstFile( res.GetData(), wxDIR ) );
|
||||||
while (!f.IsEmpty())
|
while (!f.IsEmpty())
|
||||||
{
|
{
|
||||||
res = wxFileNameFromPath( f );
|
res = wxFileNameFromPath( f );
|
||||||
@@ -358,6 +359,22 @@ void wxFileCtrl::Update()
|
|||||||
}
|
}
|
||||||
f = wxFindNextFile();
|
f = wxFindNextFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = m_dirName + _T("/") + m_wild;
|
||||||
|
f = wxFindFirstFile( res.GetData(), wxFILE );
|
||||||
|
while (!f.IsEmpty())
|
||||||
|
{
|
||||||
|
res = wxFileNameFromPath( f );
|
||||||
|
fd = new wxFileData( res, f );
|
||||||
|
wxString s = fd->GetName();
|
||||||
|
if (m_showHidden || (s[0] != _T('.')))
|
||||||
|
{
|
||||||
|
Add( fd, item );
|
||||||
|
item.m_itemId++;
|
||||||
|
}
|
||||||
|
f = wxFindNextFile();
|
||||||
|
}
|
||||||
|
|
||||||
SortItems( ListCompare, 0 );
|
SortItems( ListCompare, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,12 +522,14 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event )
|
|||||||
// wxFileDialog
|
// wxFileDialog
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#define ID_LIST_CTRL 5010
|
|
||||||
#define ID_LIST_MODE 5000
|
#define ID_LIST_MODE 5000
|
||||||
#define ID_REPORT_MODE 5001
|
#define ID_REPORT_MODE 5001
|
||||||
#define ID_UP_DIR 5005
|
#define ID_UP_DIR 5005
|
||||||
#define ID_PARENT_DIR 5006
|
#define ID_PARENT_DIR 5006
|
||||||
#define ID_NEW_DIR 5007
|
#define ID_NEW_DIR 5007
|
||||||
|
#define ID_CHOICE 5008
|
||||||
|
#define ID_TEXT 5009
|
||||||
|
#define ID_LIST_CTRL 5010
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
|
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
|
||||||
|
|
||||||
@@ -523,6 +542,8 @@ BEGIN_EVENT_TABLE(wxFileDialog,wxDialog)
|
|||||||
EVT_BUTTON(wxID_OK, wxFileDialog::OnListOk)
|
EVT_BUTTON(wxID_OK, wxFileDialog::OnListOk)
|
||||||
EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL, wxFileDialog::OnSelected)
|
EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL, wxFileDialog::OnSelected)
|
||||||
EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxFileDialog::OnActivated)
|
EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxFileDialog::OnActivated)
|
||||||
|
EVT_CHOICE(ID_CHOICE,wxFileDialog::OnChoice)
|
||||||
|
EVT_TEXT_ENTER(ID_TEXT,wxFileDialog::OnTextEnter)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
wxFileDialog::wxFileDialog(wxWindow *parent,
|
wxFileDialog::wxFileDialog(wxWindow *parent,
|
||||||
@@ -547,6 +568,28 @@ wxFileDialog::wxFileDialog(wxWindow *parent,
|
|||||||
m_wildCard = wildCard;
|
m_wildCard = wildCard;
|
||||||
m_filterIndex = 0;
|
m_filterIndex = 0;
|
||||||
|
|
||||||
|
// interpret wildcards
|
||||||
|
|
||||||
|
if (m_wildCard.IsEmpty())
|
||||||
|
m_wildCard = _("All files (*)|*");
|
||||||
|
|
||||||
|
wxStringTokenizer tokens( m_wildCard, _T("|") );
|
||||||
|
wxString firstWild;
|
||||||
|
wxString firstWildText;
|
||||||
|
if (tokens.CountTokens() == 1)
|
||||||
|
{
|
||||||
|
firstWildText = tokens.GetNextToken();
|
||||||
|
firstWild = firstWildText;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( tokens.CountTokens() % 2 == 0, _T("Wrong file type descripition") );
|
||||||
|
firstWildText = tokens.GetNextToken();
|
||||||
|
firstWild = tokens.GetNextToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
// layout
|
||||||
|
|
||||||
wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
|
||||||
wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
|
wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
@@ -589,23 +632,31 @@ wxFileDialog::wxFileDialog(wxWindow *parent,
|
|||||||
|
|
||||||
mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 );
|
mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 );
|
||||||
|
|
||||||
m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, "*", wxDefaultPosition, wxSize(440,180),
|
m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, firstWild, wxDefaultPosition, wxSize(440,180),
|
||||||
wxLC_LIST | wxSUNKEN_BORDER | wxLC_SINGLE_SEL );
|
wxLC_LIST | wxSUNKEN_BORDER | wxLC_SINGLE_SEL );
|
||||||
mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 );
|
mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 );
|
||||||
|
|
||||||
wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
|
wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
m_text = new wxTextCtrl( this, -1, m_fileName );
|
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( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
|
||||||
textsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
|
textsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
|
||||||
mainsizer->Add( textsizer, 0, wxEXPAND );
|
mainsizer->Add( textsizer, 0, wxEXPAND );
|
||||||
|
|
||||||
wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
|
wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
m_choice = new wxChoice( this, -1 );
|
m_choice = new wxChoice( this, ID_CHOICE );
|
||||||
m_choice->Append( "*.txt" );
|
|
||||||
choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 );
|
choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 );
|
||||||
choicesizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, wxCENTER | wxALL, 10 );
|
choicesizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, wxCENTER | wxALL, 10 );
|
||||||
mainsizer->Add( choicesizer, 0, wxEXPAND );
|
mainsizer->Add( choicesizer, 0, wxEXPAND );
|
||||||
|
|
||||||
|
m_choice->Append( firstWildText, (void*) new wxString( firstWild ) );
|
||||||
|
while (tokens.HasMoreTokens())
|
||||||
|
{
|
||||||
|
firstWildText = tokens.GetNextToken();
|
||||||
|
firstWild = tokens.GetNextToken();
|
||||||
|
m_choice->Append( firstWildText, (void*) new wxString( firstWild ) );
|
||||||
|
}
|
||||||
|
m_choice->SetSelection( 0 );
|
||||||
|
|
||||||
SetAutoLayout( TRUE );
|
SetAutoLayout( TRUE );
|
||||||
SetSizer( mainsizer );
|
SetSizer( mainsizer );
|
||||||
|
|
||||||
@@ -619,6 +670,16 @@ wxFileDialog::wxFileDialog(wxWindow *parent,
|
|||||||
wxEndBusyCursor();
|
wxEndBusyCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxFileDialog::~wxFileDialog()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxFileDialog::OnChoice( wxCommandEvent &event )
|
||||||
|
{
|
||||||
|
wxString *str = (wxString*) m_choice->GetClientData( event.GetInt() );
|
||||||
|
m_list->SetWild( *str );
|
||||||
|
}
|
||||||
|
|
||||||
void wxFileDialog::OnActivated( wxListEvent &WXUNUSED(event) )
|
void wxFileDialog::OnActivated( wxListEvent &WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
|
wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
|
||||||
@@ -626,9 +687,17 @@ void wxFileDialog::OnActivated( wxListEvent &WXUNUSED(event) )
|
|||||||
GetEventHandler()->ProcessEvent( cevent );
|
GetEventHandler()->ProcessEvent( cevent );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxFileDialog::OnTextEnter( wxCommandEvent &WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
|
||||||
|
cevent.SetEventObject( this );
|
||||||
|
GetEventHandler()->ProcessEvent( cevent );
|
||||||
|
}
|
||||||
|
|
||||||
void wxFileDialog::OnSelected( wxListEvent &event )
|
void wxFileDialog::OnSelected( wxListEvent &event )
|
||||||
{
|
{
|
||||||
m_text->SetValue( event.m_item.m_text );
|
if (FindFocus() == m_list)
|
||||||
|
m_text->SetValue( event.m_item.m_text );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileDialog::OnListOk( wxCommandEvent &event )
|
void wxFileDialog::OnListOk( wxCommandEvent &event )
|
||||||
@@ -637,6 +706,7 @@ void wxFileDialog::OnListOk( wxCommandEvent &event )
|
|||||||
wxString dir;
|
wxString dir;
|
||||||
m_list->GetDir( dir );
|
m_list->GetDir( dir );
|
||||||
if (filename.IsEmpty()) return;
|
if (filename.IsEmpty()) return;
|
||||||
|
if (filename == _T(".")) return;
|
||||||
|
|
||||||
if (filename == _T(".."))
|
if (filename == _T(".."))
|
||||||
{
|
{
|
||||||
@@ -645,6 +715,18 @@ void wxFileDialog::OnListOk( wxCommandEvent &event )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((filename.Find(_T('*')) != wxNOT_FOUND) ||
|
||||||
|
(filename.Find(_T('?')) != wxNOT_FOUND))
|
||||||
|
{
|
||||||
|
if (filename.Find(_T('/')) != wxNOT_FOUND)
|
||||||
|
{
|
||||||
|
wxMessageBox(_("Illegal file specification."), _("Error"), wxOK | wxICON_ERROR );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_list->SetWild( filename );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (dir != _T("/")) dir += _T("/");
|
if (dir != _T("/")) dir += _T("/");
|
||||||
dir += filename;
|
dir += filename;
|
||||||
filename = dir;
|
filename = dir;
|
||||||
@@ -672,8 +754,7 @@ void wxFileDialog::OnListOk( wxCommandEvent &event )
|
|||||||
{
|
{
|
||||||
if ( !wxFileExists( filename ) )
|
if ( !wxFileExists( filename ) )
|
||||||
{
|
{
|
||||||
wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK);
|
wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK | wxICON_ERROR );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1645,6 +1645,10 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
|
|||||||
m_usedKeys = TRUE;
|
m_usedKeys = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
extern wxWindow *g_focusWindow;
|
||||||
|
#endif
|
||||||
|
|
||||||
void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
|
void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
m_hasFocus = TRUE;
|
m_hasFocus = TRUE;
|
||||||
@@ -1652,6 +1656,10 @@ void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
|
|||||||
|
|
||||||
if (!GetParent()) return;
|
if (!GetParent()) return;
|
||||||
|
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
g_focusWindow = GetParent();
|
||||||
|
#endif
|
||||||
|
|
||||||
wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
|
wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
|
||||||
event.SetEventObject( GetParent() );
|
event.SetEventObject( GetParent() );
|
||||||
GetParent()->GetEventHandler()->ProcessEvent( event );
|
GetParent()->GetEventHandler()->ProcessEvent( event );
|
||||||
|
@@ -132,7 +132,7 @@ extern bool g_blockEventsOnDrag;
|
|||||||
extern bool g_blockEventsOnScroll;
|
extern bool g_blockEventsOnScroll;
|
||||||
extern wxCursor g_globalCursor;
|
extern wxCursor g_globalCursor;
|
||||||
static wxWindow *g_captureWindow = (wxWindow*) NULL;
|
static wxWindow *g_captureWindow = (wxWindow*) NULL;
|
||||||
static wxWindow *g_focusWindow = (wxWindow*) NULL;
|
wxWindow *g_focusWindow = (wxWindow*) NULL;
|
||||||
|
|
||||||
/* hack: we need something to pass to gtk_menu_popup, so we store the time of
|
/* hack: we need something to pass to gtk_menu_popup, so we store the time of
|
||||||
the last click here */
|
the last click here */
|
||||||
|
@@ -132,7 +132,7 @@ extern bool g_blockEventsOnDrag;
|
|||||||
extern bool g_blockEventsOnScroll;
|
extern bool g_blockEventsOnScroll;
|
||||||
extern wxCursor g_globalCursor;
|
extern wxCursor g_globalCursor;
|
||||||
static wxWindow *g_captureWindow = (wxWindow*) NULL;
|
static wxWindow *g_captureWindow = (wxWindow*) NULL;
|
||||||
static wxWindow *g_focusWindow = (wxWindow*) NULL;
|
wxWindow *g_focusWindow = (wxWindow*) NULL;
|
||||||
|
|
||||||
/* hack: we need something to pass to gtk_menu_popup, so we store the time of
|
/* hack: we need something to pass to gtk_menu_popup, so we store the time of
|
||||||
the last click here */
|
the last click here */
|
||||||
|
Reference in New Issue
Block a user