eject button functionality

This commit is contained in:
David Kocik 2019-12-11 14:53:28 +01:00
parent f5e3750d23
commit 8f0eef8f36
5 changed files with 26 additions and 13 deletions

View file

@ -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,

View file

@ -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()

View file

@ -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;

View file

@ -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<DriveData> get_all_drives();
bool is_path_on_removable_drive(const std::string &path);
void add_callback(std::function<void()> callback); // callback will notify only if device with last save path was removed

View file

@ -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
{