OSX: Clean-up of opening as G-codeviewer on startup.
This commit is contained in:
parent
09755987fe
commit
44565315bf
@ -1654,58 +1654,42 @@ bool GUI_App::OnExceptionInMainLoop()
|
|||||||
// to a G-code viewer.
|
// to a G-code viewer.
|
||||||
void GUI_App::OSXStoreOpenFiles(const wxArrayString &fileNames)
|
void GUI_App::OSXStoreOpenFiles(const wxArrayString &fileNames)
|
||||||
{
|
{
|
||||||
wxArrayString other_files;
|
size_t num_gcodes = 0;
|
||||||
std::vector<wxString> gcode_files;
|
for (const wxString &filename : fileNames) {
|
||||||
const std::regex pattern_gcode_drop(".*[.](gcode|g)", std::regex::icase);
|
wxString fn = filename.Upper();
|
||||||
for (const auto& filename : fileNames) {
|
if (fn.EndsWith(".G") || fn.EndsWith(".GCODE"))
|
||||||
boost::filesystem::path path(into_path(filename));
|
++ num_gcodes;
|
||||||
if (std::regex_match(path.string(), pattern_gcode_drop))
|
|
||||||
gcode_files.emplace_back(filename);
|
|
||||||
else
|
|
||||||
other_files.Add(filename);
|
|
||||||
}
|
}
|
||||||
if (! gcode_files.empty()) {
|
if (fileNames.size() == num_gcodes) {
|
||||||
// Drag & Dropping a G-code onto PrusaSlicer. Switch PrusaSlicer to G-code viewer mode.
|
// Opening PrusaSlicer by drag & dropping a G-Code onto PrusaSlicer icon in Finder,
|
||||||
//FIXME Switch application to G-code viewer mode?
|
// just G-codes were passed. Switch to G-code viewer mode.
|
||||||
wxMessageBox("PrusaSlicer on early startup", wxString::Format("Switching to G-code viewer for %s", gcode_files.front()), wxICON_INFORMATION);
|
|
||||||
m_app_mode = EAppMode::GCodeViewer;
|
m_app_mode = EAppMode::GCodeViewer;
|
||||||
}
|
}
|
||||||
wxApp::OSXStoreOpenFiles(other_files);
|
wxApp::OSXStoreOpenFiles(fileNames);
|
||||||
}
|
|
||||||
void GUI_App::MacNewFile()
|
|
||||||
{
|
|
||||||
m_mac_initialized = true;
|
|
||||||
}
|
}
|
||||||
// wxWidgets override to get an event on open files.
|
// wxWidgets override to get an event on open files.
|
||||||
void GUI_App::MacOpenFiles(const wxArrayString &fileNames)
|
void GUI_App::MacOpenFiles(const wxArrayString &fileNames)
|
||||||
{
|
{
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
std::vector<wxString> gcode_files;
|
std::vector<wxString> gcode_files;
|
||||||
const std::regex pattern_gcode_drop(".*[.](gcode|g)", std::regex::icase);
|
|
||||||
for (const auto& filename : fileNames) {
|
for (const auto& filename : fileNames) {
|
||||||
boost::filesystem::path path(into_path(filename));
|
wxString fn = filename.Upper();
|
||||||
if (std::regex_match(path.string(), pattern_gcode_drop))
|
if (fn.EndsWith(".G") || fn.EndsWith(".GCODE"))
|
||||||
gcode_files.emplace_back(filename);
|
gcode_files.emplace_back(filename);
|
||||||
else
|
else
|
||||||
files.emplace_back(path.string());
|
files.emplace_back(into_u8(filename));
|
||||||
}
|
}
|
||||||
|
if (m_app_mode == EAppMode::GCodeViewer) {
|
||||||
|
// Running in G-code viewer.
|
||||||
|
// Load the first G-code into the G-code viewer.
|
||||||
|
if (! gcode_files.empty())
|
||||||
|
this->plater()->load_gcode(gcode_files.front());
|
||||||
|
} else {
|
||||||
if (! files.empty())
|
if (! files.empty())
|
||||||
this->plater()->load_files(files, true, true);
|
this->plater()->load_files(files, true, true);
|
||||||
if (! files.empty() || m_mac_initialized) {
|
|
||||||
// Opening a G-code after the PrusaSlicer application was initalized.
|
|
||||||
// Start a new G-code viewer instance for each G-code file.
|
|
||||||
for (const wxString &filename : gcode_files)
|
for (const wxString &filename : gcode_files)
|
||||||
start_new_gcodeviewer(&filename);
|
start_new_gcodeviewer(&filename);
|
||||||
} else if (! gcode_files.empty()) {
|
|
||||||
assert(! m_mac_initialized);
|
|
||||||
assert(m_app_mode == EAppMode::GCodeViewer);
|
|
||||||
// Drag & Dropping a G-code onto PrusaSlicer. Switch PrusaSlicer to G-code viewer mode.
|
|
||||||
//FIXME Switch application to G-code viewer mode?
|
|
||||||
wxMessageBox("PrusaSlicer on startup", wxString::Format("Switching to G-code viewer for %s", gcode_files.front()), wxICON_INFORMATION);
|
|
||||||
// Load the G-code into the G-code viewer.
|
|
||||||
this->plater()->load_gcode(gcode_files.front());
|
|
||||||
}
|
}
|
||||||
m_mac_initialized = true;
|
|
||||||
}
|
}
|
||||||
#endif /* __APPLE */
|
#endif /* __APPLE */
|
||||||
|
|
||||||
|
@ -106,9 +106,6 @@ private:
|
|||||||
#endif // ENABLE_GCODE_VIEWER
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
|
|
||||||
bool m_initialized { false };
|
bool m_initialized { false };
|
||||||
#ifdef __APPLE__
|
|
||||||
bool m_mac_initialized { false };
|
|
||||||
#endif // __APPLE__
|
|
||||||
bool app_conf_exists{ false };
|
bool app_conf_exists{ false };
|
||||||
#if ENABLE_GCODE_VIEWER
|
#if ENABLE_GCODE_VIEWER
|
||||||
EAppMode m_app_mode{ EAppMode::Editor };
|
EAppMode m_app_mode{ EAppMode::Editor };
|
||||||
@ -251,8 +248,6 @@ public:
|
|||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
void OSXStoreOpenFiles(const wxArrayString &files) override;
|
void OSXStoreOpenFiles(const wxArrayString &files) override;
|
||||||
// Called if there is no file to open.
|
|
||||||
void MacNewFile();
|
|
||||||
// wxWidgets override to get an event on open files.
|
// wxWidgets override to get an event on open files.
|
||||||
void MacOpenFiles(const wxArrayString &fileNames) override;
|
void MacOpenFiles(const wxArrayString &fileNames) override;
|
||||||
#endif /* __APPLE */
|
#endif /* __APPLE */
|
||||||
|
Loading…
Reference in New Issue
Block a user