mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-19 23:12:35 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49e135c8e3 |
@@ -8,6 +8,7 @@
|
|||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <wx/event.h>
|
#include <wx/event.h>
|
||||||
|
#include <wx/uri.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -55,6 +56,14 @@ wxString web_base_url()
|
|||||||
return wxString("file://") + from_u8(dir) + "/";
|
return wxString("file://") + from_u8(dir) + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Whether a loaded document is the plugin HTML's own base URL. The web view reports the URL it
|
||||||
|
// parsed, so any fragment the page navigated to is ignored and the escaping it applies to what the
|
||||||
|
// resources path holds (a space, a non-ASCII character) is undone first.
|
||||||
|
bool is_content_url(const wxString& url)
|
||||||
|
{
|
||||||
|
return wxURI::Unescape(url.BeforeFirst('#')) == web_base_url();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PluginWebDialog::PluginWebDialog(wxWindow* parent,
|
PluginWebDialog::PluginWebDialog(wxWindow* parent,
|
||||||
@@ -89,6 +98,7 @@ PluginWebDialog::PluginWebDialog(wxWindow* parent,
|
|||||||
// missing/blocked bootstrap resource (e.g. a packaged build) still triggers it.
|
// missing/blocked bootstrap resource (e.g. a packaged build) still triggers it.
|
||||||
Bind(wxEVT_WEBVIEW_LOADED, &PluginWebDialog::on_bootstrap_event, this, wv->GetId());
|
Bind(wxEVT_WEBVIEW_LOADED, &PluginWebDialog::on_bootstrap_event, this, wv->GetId());
|
||||||
Bind(wxEVT_WEBVIEW_ERROR, &PluginWebDialog::on_bootstrap_event, this, wv->GetId());
|
Bind(wxEVT_WEBVIEW_ERROR, &PluginWebDialog::on_bootstrap_event, this, wv->GetId());
|
||||||
|
Bind(wxEVT_WEBVIEW_NAVIGATED, &PluginWebDialog::on_navigated, this, wv->GetId());
|
||||||
}
|
}
|
||||||
Bind(wxEVT_CLOSE_WINDOW, &PluginWebDialog::on_close_window, this);
|
Bind(wxEVT_CLOSE_WINDOW, &PluginWebDialog::on_close_window, this);
|
||||||
}
|
}
|
||||||
@@ -139,19 +149,41 @@ void PluginWebDialog::destroy_for_plugin(PluginWebDialog* dialog)
|
|||||||
|
|
||||||
void PluginWebDialog::on_bootstrap_event(wxWebViewEvent& event)
|
void PluginWebDialog::on_bootstrap_event(wxWebViewEvent& event)
|
||||||
{
|
{
|
||||||
// The first bootstrap load (or its error) triggers the swap to plugin HTML;
|
const bool loaded = event.GetEventType() == wxEVT_WEBVIEW_LOADED;
|
||||||
// the resulting plugin-page load is ignored (guarded by m_content_loaded).
|
// The first bootstrap load (or its error) triggers the swap to plugin HTML.
|
||||||
load_plugin_content();
|
if (!m_content_loaded)
|
||||||
|
load_plugin_content();
|
||||||
|
// WebKit reloads the SetPage base URL rather than the injected page, and the injected document
|
||||||
|
// reports that same URL, so a load of it that is not the swap we started is a browser reload and
|
||||||
|
// the plugin HTML has to be put back. A page the plugin linked to reports its own URL and is left
|
||||||
|
// alone. A navigation that fails is reported against the document that stayed, base URL and all,
|
||||||
|
// so the reload also has to have committed; nothing commits for a failure. The Edge backend
|
||||||
|
// ignores the base URL, so nothing matches there, and WebView2 reloads SetPage content from its
|
||||||
|
// own history entry anyway.
|
||||||
|
else if (is_content_url(event.GetURL())) {
|
||||||
|
if (m_own_page_load)
|
||||||
|
m_own_page_load = false;
|
||||||
|
else if (loaded && m_content_navigated)
|
||||||
|
load_plugin_content();
|
||||||
|
}
|
||||||
|
if (loaded)
|
||||||
|
m_content_navigated = false;
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginWebDialog::on_navigated(wxWebViewEvent& event)
|
||||||
|
{
|
||||||
|
m_content_navigated = is_content_url(event.GetURL());
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginWebDialog::load_plugin_content()
|
void PluginWebDialog::load_plugin_content()
|
||||||
{
|
{
|
||||||
if (m_content_loaded)
|
|
||||||
return;
|
|
||||||
m_content_loaded = true;
|
m_content_loaded = true;
|
||||||
if (wxWebView* wv = browser())
|
if (wxWebView* wv = browser()) {
|
||||||
|
m_own_page_load = true;
|
||||||
wv->SetPage(wxString::FromUTF8(m_html), web_base_url());
|
wv->SetPage(wxString::FromUTF8(m_html), web_base_url());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginWebDialog::on_script_message(const nlohmann::json& payload)
|
void PluginWebDialog::on_script_message(const nlohmann::json& payload)
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void on_bootstrap_event(wxWebViewEvent& event);
|
void on_bootstrap_event(wxWebViewEvent& event);
|
||||||
|
void on_navigated(wxWebViewEvent& event);
|
||||||
void load_plugin_content();
|
void load_plugin_content();
|
||||||
void on_close_window(wxCloseEvent& event);
|
void on_close_window(wxCloseEvent& event);
|
||||||
void fire_submit(const nlohmann::json& data);
|
void fire_submit(const nlohmann::json& data);
|
||||||
@@ -72,6 +73,8 @@ private:
|
|||||||
|
|
||||||
std::string m_html;
|
std::string m_html;
|
||||||
bool m_content_loaded{false};
|
bool m_content_loaded{false};
|
||||||
|
bool m_own_page_load{false}; // a SetPage of the plugin HTML is in flight
|
||||||
|
bool m_content_navigated{false}; // a navigation to the base URL has committed
|
||||||
bool m_open{true};
|
bool m_open{true};
|
||||||
bool m_close_fired{false};
|
bool m_close_fired{false};
|
||||||
std::optional<nlohmann::json> m_result;
|
std::optional<nlohmann::json> m_result;
|
||||||
|
|||||||
@@ -891,7 +891,7 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
|
|||||||
top_title_temp_v->Add(top_title_temp_h, 1, wxALIGN_CENTER, 0);
|
top_title_temp_v->Add(top_title_temp_h, 1, wxALIGN_CENTER, 0);
|
||||||
m_panel_temp->SetSizer(top_title_temp_v);
|
m_panel_temp->SetSizer(top_title_temp_v);
|
||||||
m_panel_temp->Layout();
|
m_panel_temp->Layout();
|
||||||
m_sizer_top->Add(m_panel_temp, 0, wxALIGN_CENTER, 0);
|
m_sizer_top->Add(m_panel_temp, 1, wxALIGN_CENTER, 0);
|
||||||
|
|
||||||
title_block_middle = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
title_block_middle = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||||
title_block_middle->SetBackgroundColour(wxColour(172, 172, 172));
|
title_block_middle->SetBackgroundColour(wxColour(172, 172, 172));
|
||||||
@@ -935,12 +935,11 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
|
|||||||
m_panel_newv->Layout();
|
m_panel_newv->Layout();
|
||||||
m_sizer_top->Add(m_panel_newv, 0, wxALIGN_CENTER, 0);
|
m_sizer_top->Add(m_panel_newv, 0, wxALIGN_CENTER, 0);
|
||||||
//m_sizer_top->Add(top_title_newv, 1, wxALIGN_CENTER, 0);
|
//m_sizer_top->Add(top_title_newv, 1, wxALIGN_CENTER, 0);
|
||||||
m_sizer_top->AddStretchSpacer();
|
|
||||||
|
|
||||||
m_table_top->SetSizer(m_sizer_top);
|
m_table_top->SetSizer(m_sizer_top);
|
||||||
m_table_top->Layout();
|
m_table_top->Layout();
|
||||||
m_sizer_top->Fit(m_table_top);
|
m_sizer_top->Fit(m_table_top);
|
||||||
m_sizer_tab->Add(m_table_top, 0, wxEXPAND, 0);
|
m_sizer_tab->Add(m_table_top, 1, 0, 0);
|
||||||
|
|
||||||
m_scrolledWindow = new wxScrolledWindow(m_panel_tab, wxID_ANY, wxDefaultPosition, UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE, wxNO_BORDER|wxVSCROLL);
|
m_scrolledWindow = new wxScrolledWindow(m_panel_tab, wxID_ANY, wxDefaultPosition, UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE, wxNO_BORDER|wxVSCROLL);
|
||||||
m_scrolledWindow->SetScrollRate(0, 5);
|
m_scrolledWindow->SetScrollRate(0, 5);
|
||||||
|
|||||||
Reference in New Issue
Block a user