ENH:close dialog by pressing esc key

Change-Id: Ib883e7119699e06f63c61dd083ad761ba58bc19c
This commit is contained in:
liz.li 2022-08-15 19:15:51 +08:00 committed by Lane.Wei
parent 03f62ed9ae
commit 121dccc59c
7 changed files with 92 additions and 3 deletions

View file

@ -146,4 +146,22 @@
</div> </div>
</body> </body>
<script>
document.onkeydown = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e.keyCode == 27)
ClosePage();
if (window.event) {
try { e.keyCode = 0; } catch (e) { }
e.returnValue = false;
}
};
window.addEventListener('wheel', function (event) {
if (event.ctrlKey === true || event.metaKey) {
event.preventDefault();
}
}, { passive: false });
</script>
</html> </html>

View file

@ -99,4 +99,17 @@
</body> </body>
<script>
document.onkeydown = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e.keyCode == 27)
ClosePage();
if (window.event) {
try { e.keyCode = 0; } catch (e) { }
e.returnValue = false;
}
};
</script>
</html> </html>

View file

@ -0,0 +1,21 @@
function ClosePage() {
var tSend = {};
tSend['sequence_id'] = Math.round(new Date() / 1000);
tSend['command'] = "close_page";
SendWXMessage(JSON.stringify(tSend));
}
document.onkeydown = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (window.event) {
try { e.keyCode = 0; } catch (e) { }
e.returnValue = false;
}
};
window.addEventListener('wheel', function (event) {
if (event.ctrlKey === true || event.metaKey) {
event.preventDefault();
}
}, { passive: false });

View file

@ -189,6 +189,19 @@ public:
event.Skip(); event.Skip();
on_sys_color_changed(); on_sys_color_changed();
}); });
if (std::is_same<wxDialog, P>::value) {
this->Bind(wxEVT_CHAR_HOOK, [this](wxKeyEvent& e) {
if (e.GetKeyCode() == WXK_ESCAPE) {
//if (this->IsModal())
// this->EndModal(wxID_CANCEL);
//else
this->Close();
}
else
e.Skip();
});
}
} }
virtual ~DPIAware() {} virtual ~DPIAware() {}

View file

@ -77,7 +77,18 @@ GuideFrame::GuideFrame(GUI_App *pGUI, long style)
//int screenwidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X, NULL); //int screenwidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X, NULL);
//int MaxY = (screenheight - pSize.y) > 0 ? (screenheight - pSize.y) / 2 : 0; //int MaxY = (screenheight - pSize.y) > 0 ? (screenheight - pSize.y) / 2 : 0;
//MoveWindow(this->m_hWnd, (screenwidth - pSize.x) / 2, MaxY, pSize.x, pSize.y, TRUE); //MoveWindow(this->m_hWnd, (screenwidth - pSize.x) / 2, MaxY, pSize.x, pSize.y, TRUE);
#ifdef __WXMSW__
this->Bind(wxEVT_CHAR_HOOK, [this](wxKeyEvent& e) {
if ((m_page == BBL_FILAMENT_ONLY || m_page == BBL_MODELS_ONLY) && e.GetKeyCode() == WXK_ESCAPE) {
if (this->IsModal())
this->EndModal(wxID_CANCEL);
else
this->Close();
}
else
e.Skip();
});
#endif
// Connect the webview events // Connect the webview events
Bind(wxEVT_WEBVIEW_NAVIGATING, &GuideFrame::OnNavigationRequest, this, m_browser->GetId()); Bind(wxEVT_WEBVIEW_NAVIGATING, &GuideFrame::OnNavigationRequest, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_NAVIGATED, &GuideFrame::OnNavigationComplete, this, m_browser->GetId()); Bind(wxEVT_WEBVIEW_NAVIGATED, &GuideFrame::OnNavigationComplete, this, m_browser->GetId());
@ -121,6 +132,7 @@ void GuideFrame::load_url(wxString &url)
wxString GuideFrame::SetStartPage(GuidePage startpage, bool load) wxString GuideFrame::SetStartPage(GuidePage startpage, bool load)
{ {
m_page = startpage;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(" enter, load=%1%, start_page=%2%")%load%int(startpage); BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(" enter, load=%1%, start_page=%2%")%load%int(startpage);
//wxLogMessage("GUIDE: webpage_1 %s", (boost::filesystem::path(resources_dir()) / "web\\guide\\1\\index.html").make_preferred().string().c_str() ); //wxLogMessage("GUIDE: webpage_1 %s", (boost::filesystem::path(resources_dir()) / "web\\guide\\1\\index.html").make_preferred().string().c_str() );
wxString TargetUrl = from_u8( (boost::filesystem::path(resources_dir()) / "web/guide/1/index.html").make_preferred().string() ); wxString TargetUrl = from_u8( (boost::filesystem::path(resources_dir()) / "web/guide/1/index.html").make_preferred().string() );
@ -274,7 +286,9 @@ void GuideFrame::OnScriptMessage(wxWebViewEvent &evt)
json j = json::parse(strInput); json j = json::parse(strInput);
wxString strCmd = j["command"]; wxString strCmd = j["command"];
if (strCmd == "close_page") {
this->EndModal(wxID_CANCEL);
}
if (strCmd == "user_clause") { if (strCmd == "user_clause") {
wxString strAction = j["data"]["action"]; wxString strAction = j["data"]["action"];

View file

@ -47,7 +47,7 @@ public:
BBL_FILAMENTS, BBL_FILAMENTS,
BBL_FILAMENT_ONLY, BBL_FILAMENT_ONLY,
BBL_MODELS_ONLY BBL_MODELS_ONLY
}; }m_page;
//Web Function //Web Function
void load_url(wxString &url); void load_url(wxString &url);

View file

@ -172,6 +172,16 @@ WipingDialog::WipingDialog(wxWindow* parent, const std::vector<float>& matrix, c
this->FindWindowById(wxID_RESET, this)->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { m_panel_wiping->calc_flushing_volumes(); }); this->FindWindowById(wxID_RESET, this)->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { m_panel_wiping->calc_flushing_volumes(); });
} }
this->Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& e) { EndModal(wxCANCEL); }); this->Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& e) { EndModal(wxCANCEL); });
this->Bind(wxEVT_CHAR_HOOK, [this](wxKeyEvent& e) {
if (e.GetKeyCode() == WXK_ESCAPE) {
if (this->IsModal())
this->EndModal(wxID_CANCEL);
else
this->Close();
}
else
e.Skip();
});
} }
void WipingPanel::create_panels(wxWindow* parent, const int num) { void WipingPanel::create_panels(wxWindow* parent, const int num) {