From 6acc1fc112e9b8c020fd0b9c46694b1dc0185c9e Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 6 Oct 2020 11:07:49 +0200 Subject: [PATCH] WIP: Opening a G-code in PrusaSlicer at Drag & Drop onto the application icon in Finder. --- src/slic3r/GUI/GUI_App.cpp | 20 +++++++++++++++++++- src/slic3r/GUI/GUI_App.hpp | 7 ++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9ee4ca2ab..f15655e2b 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1620,20 +1620,38 @@ bool GUI_App::OnExceptionInMainLoop() } #ifdef __APPLE__ +void GUI_App::MacNewFile() +{ + wxDocManager::GetDocumentManager()->CreateNewDocument(); + m_mac_initialized = true; +} // wxWidgets override to get an event on open files. void GUI_App::MacOpenFiles(const wxArrayString &fileNames) { std::vector files; + std::vector gcode_files; const std::regex pattern_gcode_drop(".*[.](gcode|g)", std::regex::icase); for (const auto& filename : fileNames) { boost::filesystem::path path(into_path(filename)); if (std::regex_match(path.string(), pattern_gcode_drop)) - start_new_gcodeviewer(&filename); + gcode_files.emplace_back(filename); else files.emplace_back(path.string()); } if (! files.empty()) 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) + start_new_gcodeviewer(&filename); + } else if (! gcode_files.empty()) { + assert(! m_mac_initialized); + // 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); + } + m_mac_initialized = true; } #endif /* __APPLE */ diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 68c9b2efd..53eef2518 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -106,6 +106,9 @@ private: #endif // ENABLE_GCODE_VIEWER bool m_initialized { false }; +#ifdef __APPLE__ + bool m_mac_initialized { false }; +#endif // __APPLE__ bool app_conf_exists{ false }; #if ENABLE_GCODE_VIEWER EAppMode m_app_mode{ EAppMode::Editor }; @@ -119,7 +122,7 @@ private: wxFont m_bold_font; wxFont m_normal_font; - int m_em_unit; // width of a "m"-symbol in pixels for current system font + int m_em_unit; // width of a "m"-symbol in pixels for current system font // Note: for 100% Scale m_em_unit = 10 -> it's a good enough coefficient for a size setting of controls std::unique_ptr m_wxLocale; @@ -247,6 +250,8 @@ public: virtual bool OnExceptionInMainLoop() override; #ifdef __APPLE__ + // Called if there is no file to open. + void MacNewFile(); // wxWidgets override to get an event on open files. void MacOpenFiles(const wxArrayString &fileNames) override; #endif /* __APPLE */