X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8907154c1a8a6882c6797d1f16393ddfb23e7f3a..3cfcae3b4d5a8a84c19d74a211a97da47ffe0dc6:/samples/exec/exec.cpp diff --git a/samples/exec/exec.cpp b/samples/exec/exec.cpp index 13e9c0003d..1d334c8d3d 100644 --- a/samples/exec/exec.cpp +++ b/samples/exec/exec.cpp @@ -51,6 +51,7 @@ #include "wx/txtstrm.h" #include "wx/numdlg.h" +#include "wx/textdlg.h" #include "wx/ffile.h" #include "wx/process.h" @@ -97,6 +98,7 @@ public: void OnClear(wxCommandEvent& event); void OnSyncExec(wxCommandEvent& event); + void OnSyncNoEventsExec(wxCommandEvent& event); void OnAsyncExec(wxCommandEvent& event); void OnShell(wxCommandEvent& event); void OnExecWithRedirect(wxCommandEvent& event); @@ -105,6 +107,7 @@ public: void OnPOpen(wxCommandEvent& event); void OnFileExec(wxCommandEvent& event); + void OnOpenURL(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); @@ -298,10 +301,12 @@ enum Exec_Kill, Exec_ClearLog, Exec_SyncExec = 200, + Exec_SyncNoEventsExec, Exec_AsyncExec, Exec_Shell, Exec_POpen, Exec_OpenFile, + Exec_OpenURL, Exec_DDEExec, Exec_DDERequest, Exec_Redirect, @@ -330,6 +335,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Exec_ClearLog, MyFrame::OnClear) EVT_MENU(Exec_SyncExec, MyFrame::OnSyncExec) + EVT_MENU(Exec_SyncNoEventsExec, MyFrame::OnSyncNoEventsExec) EVT_MENU(Exec_AsyncExec, MyFrame::OnAsyncExec) EVT_MENU(Exec_Shell, MyFrame::OnShell) EVT_MENU(Exec_Redirect, MyFrame::OnExecWithRedirect) @@ -338,6 +344,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Exec_POpen, MyFrame::OnPOpen) EVT_MENU(Exec_OpenFile, MyFrame::OnFileExec) + EVT_MENU(Exec_OpenURL, MyFrame::OnOpenURL) #ifdef __WINDOWS__ EVT_MENU(Exec_DDEExec, MyFrame::OnDDEExec) @@ -382,6 +389,9 @@ IMPLEMENT_APP(MyApp) // `Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + // Create the main application window MyFrame *frame = new MyFrame(_T("Exec wxWidgets sample"), wxDefaultPosition, wxSize(500, 140)); @@ -430,6 +440,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) wxMenu *execMenu = new wxMenu; execMenu->Append(Exec_SyncExec, _T("Sync &execution...\tCtrl-E"), _T("Launch a program and return when it terminates")); + execMenu->Append(Exec_SyncNoEventsExec, _T("Sync execution and &block...\tCtrl-B"), + _T("Launch a program and block until it terminates")); execMenu->Append(Exec_AsyncExec, _T("&Async execution...\tCtrl-A"), _T("Launch a program and return immediately")); execMenu->Append(Exec_Shell, _T("Execute &shell command...\tCtrl-S"), @@ -445,6 +457,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) execMenu->AppendSeparator(); execMenu->Append(Exec_OpenFile, _T("Open &file...\tCtrl-F"), _T("Launch the command to open this kind of files")); + execMenu->Append(Exec_OpenURL, _T("Open &URL...\tCtrl-U"), + _T("Launch the default browser with the given URL")); #ifdef __WINDOWS__ execMenu->AppendSeparator(); execMenu->Append(Exec_DDEExec, _T("Execute command via &DDE...\tCtrl-D")); @@ -639,6 +653,25 @@ void MyFrame::OnSyncExec(wxCommandEvent& WXUNUSED(event)) m_cmdLast = cmd; } +void MyFrame::OnSyncNoEventsExec(wxCommandEvent& WXUNUSED(event)) +{ + wxString cmd = wxGetTextFromUser(_T("Enter the command: "), + DIALOG_TITLE, + m_cmdLast); + + if ( !cmd ) + return; + + wxLogStatus( _T("'%s' is running please wait..."), cmd.c_str() ); + + int code = wxExecute(cmd, wxEXEC_BLOCK); + + wxLogStatus(_T("Process '%s' terminated with exit code %d."), + cmd.c_str(), code); + + m_cmdLast = cmd; +} + void MyFrame::OnAsyncExec(wxCommandEvent& WXUNUSED(event)) { wxString cmd = wxGetTextFromUser(_T("Enter the command: "), @@ -774,6 +807,8 @@ void MyFrame::OnPOpen(wxCommandEvent& WXUNUSED(event)) return; } + wxLogVerbose(_T("PID of the new process: %ld"), process->GetPid()); + wxOutputStream *out = process->GetOutputStream(); if ( !out ) { @@ -798,8 +833,11 @@ void MyFrame::OnFileExec(wxCommandEvent& WXUNUSED(event)) wxString filename; #if wxUSE_FILEDLG - filename = wxLoadFileSelector(wxEmptyString, wxEmptyString, s_filename); -#endif // wxUSE_FILEDLG + filename = wxLoadFileSelector(_T("any file"), NULL, s_filename, this); +#else // !wxUSE_FILEDLG + filename = wxGetTextFromUser(_T("Enter the file name"), _T("exec sample"), + s_filename, this); +#endif // wxUSE_FILEDLG/!wxUSE_FILEDLG if ( filename.empty() ) return; @@ -829,6 +867,27 @@ void MyFrame::OnFileExec(wxCommandEvent& WXUNUSED(event)) DoAsyncExec(cmd); } +void MyFrame::OnOpenURL(wxCommandEvent& WXUNUSED(event)) +{ + static wxString s_filename; + + wxString filename = wxGetTextFromUser + ( + _T("Enter the URL"), + _T("exec sample"), + s_filename, + this + ); + + if ( filename.empty() ) + return; + + s_filename = filename; + + if ( !wxLaunchDefaultBrowser(s_filename) ) + wxLogError(_T("Failed to open URL \"%s\""), s_filename.c_str()); +} + // ---------------------------------------------------------------------------- // DDE stuff // ----------------------------------------------------------------------------