+void MyFrame::OnFileExec(wxCommandEvent& event)
+{
+ static wxString s_filename;
+
+ wxString filename = wxLoadFileSelector(_T("file"), _T(""), s_filename);
+ if ( !filename )
+ return;
+
+ s_filename = filename;
+
+ wxString ext = filename.AfterFirst(_T('.'));
+ wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
+ if ( !ft )
+ {
+ wxLogError(_T("Impossible to determine the file type for extension '%s'"),
+ ext.c_str());
+ return;
+ }
+
+ wxString cmd;
+ bool ok = ft->GetOpenCommand(&cmd,
+ wxFileType::MessageParameters(filename, _T("")));
+ delete ft;
+ if ( !ok )
+ {
+ wxLogError(_T("Impossible to find out how to open files of extension '%s'"),
+ ext.c_str());
+ return;
+ }
+
+ DoAsyncExec(cmd);
+}
+
+// ----------------------------------------------------------------------------
+// DDE stuff
+// ----------------------------------------------------------------------------
+
+#ifdef __WINDOWS__
+
+bool MyFrame::GetDDEServer()
+{
+ wxString server = wxGetTextFromUser(_T("Server to connect to:"),
+ DIALOG_TITLE, m_server);
+ if ( !server )
+ return FALSE;
+
+ m_server = server;
+
+ wxString topic = wxGetTextFromUser(_T("DDE topic:"), DIALOG_TITLE, m_topic);
+ if ( !topic )
+ return FALSE;
+
+ m_topic = topic;
+
+ wxString cmd = wxGetTextFromUser(_T("DDE command:"), DIALOG_TITLE, m_cmdDde);
+ if ( !cmd )
+ return FALSE;
+
+ m_cmdDde = cmd;
+
+ return TRUE;
+}
+
+void MyFrame::OnDDEExec(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !GetDDEServer() )
+ return;
+
+ wxDDEClient client;
+ wxConnectionBase *conn = client.MakeConnection("", m_server, m_topic);
+ if ( !conn )
+ {
+ wxLogError(_T("Failed to connect to the DDE server '%s'."),
+ m_server.c_str());
+ }
+ else
+ {
+ if ( !conn->Execute(m_cmdDde) )
+ {
+ wxLogError(_T("Failed to execute command '%s' via DDE."),
+ m_cmdDde.c_str());
+ }
+ else
+ {
+ wxLogStatus(_T("Successfully executed DDE command"));
+ }
+ }
+}
+
+void MyFrame::OnDDERequest(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !GetDDEServer() )
+ return;
+
+ wxDDEClient client;
+ wxConnectionBase *conn = client.MakeConnection("", m_server, m_topic);
+ if ( !conn )
+ {
+ wxLogError(_T("Failed to connect to the DDE server '%s'."),
+ m_server.c_str());
+ }
+ else
+ {
+ if ( !conn->Request(m_cmdDde) )
+ {
+ wxLogError(_T("Failed to send request '%s' via DDE."),
+ m_cmdDde.c_str());
+ }
+ else
+ {
+ wxLogStatus(_T("Successfully sent DDE request."));
+ }
+ }
+}
+
+#endif // __WINDOWS__
+
+// ----------------------------------------------------------------------------
+// various helpers
+// ----------------------------------------------------------------------------
+
+// input polling
+void MyFrame::OnIdle(wxIdleEvent& event)
+{
+ size_t count = m_running.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ if ( m_running[n]->HasInput() )
+ {
+ event.RequestMore();
+ }
+ }
+}
+
+void MyFrame::OnProcessTerminated(MyPipedProcess *process)
+{
+ m_running.Remove(process);
+}
+
+
+void MyFrame::ShowOutput(const wxString& cmd,
+ const wxArrayString& output,
+ const wxString& title)
+{
+ size_t count = output.GetCount();
+ if ( !count )
+ return;
+
+ m_lbox->Append(wxString::Format(_T("--- %s of '%s' ---"),
+ title.c_str(), cmd.c_str()));
+
+ for ( size_t n = 0; n < count; n++ )
+ {
+ m_lbox->Append(output[n]);
+ }
+
+ m_lbox->Append(_T("--- End of output ---"));
+}
+