From: Steve Lamerton Date: Sat, 13 Aug 2011 14:53:46 +0000 (+0000) Subject: Add Run Script menu option to the sample. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/54883129aec601917279df47ca394f8eac3e98ab Add Run Script menu option to the sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68682 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/web/web.cpp b/samples/web/web.cpp index 99a275488b..dd40a0ca45 100644 --- a/samples/web/web.cpp +++ b/samples/web/web.cpp @@ -91,6 +91,7 @@ public: void OnMode(wxCommandEvent& evt); void OnZoomLayout(wxCommandEvent& evt); void OnHistory(wxCommandEvent& evt); + void OnRunScript(wxCommandEvent& evt); private: wxTextCtrl* m_url; @@ -236,7 +237,7 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") m_tools_enable_history = m_tools_history_menu->AppendCheckItem(wxID_ANY, _("Enable History")); m_tools_history_menu->AppendSeparator(); - wxMenuItem* history = m_tools_menu->AppendSubMenu(m_tools_history_menu, "History"); + m_tools_menu->AppendSubMenu(m_tools_history_menu, "History"); //Create an editing menu wxMenu* editmenu = new wxMenu(); @@ -252,6 +253,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") m_tools_menu->AppendSeparator(); m_tools_menu->AppendSubMenu(editmenu, "Edit"); + wxMenuItem* script = m_tools_menu->Append(wxID_ANY, _("Run Script")); + //By default we want to handle navigation and new windows m_tools_handle_navigation->Check(); m_tools_handle_new_window->Check(); @@ -322,6 +325,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") wxCommandEventHandler(WebFrame::OnRedo), NULL, this ); Connect(m_edit_mode->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WebFrame::OnMode), NULL, this ); + Connect(script->GetId(), wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(WebFrame::OnRunScript), NULL, this ); } void WebFrame::OnAnimationTimer(wxTimerEvent& WXUNUSED(evt)) @@ -677,6 +682,15 @@ void WebFrame::OnHistory(wxCommandEvent& evt) m_browser->LoadHistoryItem(m_histMenuItems[evt.GetId()]); } +void WebFrame::OnRunScript(wxCommandEvent& WXUNUSED(evt)) +{ + wxTextEntryDialog dialog(this, "Enter JavaScript to run.", wxGetTextFromUserPromptStr, "", wxOK|wxCANCEL|wxCENTRE|wxTE_MULTILINE); + if(dialog.ShowModal() == wxID_OK) + { + m_browser->RunScript(dialog.GetValue()); + } +} + /** * Callback invoked when a loading error occurs */