From 8f0eef8f36683a17b1749f52784efc7bbd2f576d Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 11 Dec 2019 14:53:28 +0100 Subject: [PATCH] eject button functionality --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 6 +++--- src/slic3r/GUI/RemovableDriveManager.cpp | 24 +++++++++++++++++------ src/slic3r/GUI/RemovableDriveManager.hpp | 5 +++-- src/slic3r/GUI/RemovableDriveManagerMM.mm | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index e13701f61..786a5901e 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -275,7 +275,7 @@ bool GUI_App::on_init_inner() this->obj_manipul()->update_if_dirty(); - //RemovableDriveManager::get_instance().update(wxGetLocalTime()); + RemovableDriveManager::get_instance().update(wxGetLocalTime(), true); // Preset updating & Configwizard are done after the above initializations, diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ed60066e5..7edf657be 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4694,7 +4694,7 @@ void Plater::export_gcode() { if (!RemovableDriveManager::get_instance().is_path_on_removable_drive(start_dir)) { - start_dir = RemovableDriveManager::get_instance().get_last_drive_path(); + start_dir = RemovableDriveManager::get_instance().get_drive_path(); } } wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _(L("Save G-code file as:")) : _(L("Save SL1 file as:")), @@ -4995,11 +4995,11 @@ void Plater::send_gcode() void Plater::eject_drive() { - if (GUI::RemovableDriveManager::get_instance().update()) + if (GUI::RemovableDriveManager::get_instance().update(0, true)) { RemovableDriveManager::get_instance().erase_callbacks(); RemovableDriveManager::get_instance().add_callback(std::bind(&Plater::drive_ejected_callback, this)); - RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_drive_path()); + RemovableDriveManager::get_instance().eject_drive(RemovableDriveManager::get_instance().get_last_save_path()); } } void Plater::drive_ejected_callback() diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 1a964f889..49bf59e11 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -198,15 +198,16 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP DEVICE_NOTIFY_WINDOW_HANDLE // type of recipient handle ); break; + /* case WM_DEVICECHANGE: { if(wParam == DBT_DEVICEREMOVECOMPLETE) { - std::cout << "WM_DEVICECHANGE\n"; - RemovableDriveManager::get_instance().update(); +- RemovableDriveManager::get_instance().update(0, true); } } break; + */ default: // Send all other messages on to the default windows handler. lRet = DefWindowProc(hWnd, message, wParam, lParam); @@ -403,7 +404,7 @@ RemovableDriveManager::RemovableDriveManager(): void RemovableDriveManager::init() { - add_callback([](void) { RemovableDriveManager::get_instance().print(); }); + //add_callback([](void) { RemovableDriveManager::get_instance().print(); }); #if _WIN32 register_window(); #elif __APPLE__ @@ -441,8 +442,18 @@ bool RemovableDriveManager::is_drive_mounted(const std::string &path) } return false; } - -std::string RemovableDriveManager::get_last_drive_path() +std::string RemovableDriveManager::get_drive_path() +{ + if (m_current_drives.size() == 0) + { + reset_last_save_path(); + return ""; + } + if (m_last_save_path != "") + return m_last_save_path; + return m_current_drives.back().path; +} +std::string RemovableDriveManager::get_last_save_path() { return m_last_save_path; } @@ -456,7 +467,7 @@ void RemovableDriveManager::check_and_notify() if(m_drives_count != m_current_drives.size()) { //std::cout<<" vs "<< m_current_drives.size(); - if(m_drives_count > m_current_drives.size() && m_last_save_path != "" && !is_drive_mounted(m_last_save_path)) + if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path != "" && !is_drive_mounted(m_last_save_path)) { for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) { @@ -485,6 +496,7 @@ void RemovableDriveManager::set_last_save_path(const std::string& path) } bool RemovableDriveManager::is_last_drive_removed() { + m_drives_count = m_current_drives.size(); if(m_last_save_path == "") { return true; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index f41294001..49df41482 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -32,10 +32,11 @@ public: //update() searches for removable devices, returns false if empty. void init(); - bool update(const long time = 0, bool check = true); //time = 0 is forced update, time expects wxGetLocalTime() + bool update(const long time = 0, bool check = false); //time = 0 is forced update, time expects wxGetLocalTime() bool is_drive_mounted(const std::string &path); void eject_drive(const std::string &path); - std::string get_last_drive_path(); + std::string get_last_save_path(); + std::string get_drive_path(); std::vector get_all_drives(); bool is_path_on_removable_drive(const std::string &path); void add_callback(std::function callback); // callback will notify only if device with last save path was removed diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index d32b7b278..7a1108541 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -17,7 +17,7 @@ -(void) on_device_unmount: (NSNotification*) notification { NSLog(@"on device change"); - Slic3r::GUI::RemovableDriveManager::get_instance().update(); + Slic3r::GUI::RemovableDriveManager::get_instance().update(0,true); } -(void) add_unmount_observer {