mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	callback for showing action buttons when device is connected/disconnected
This commit is contained in:
		
							parent
							
								
									7e97576e56
								
							
						
					
					
						commit
						53f04b4bfd
					
				
					 3 changed files with 26 additions and 3 deletions
				
			
		|  | @ -2199,6 +2199,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) | |||
| 
 | ||||
|     // Initialize the Undo / Redo stack with a first snapshot.
 | ||||
|     this->take_snapshot(_(L("New Project"))); | ||||
| 
 | ||||
| 	//void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const
 | ||||
| 	RemovableDriveManager::get_instance().set_drive_count_changed_callback(std::bind(&Plater::priv::show_action_buttons, this, std::placeholders::_1)); | ||||
| } | ||||
| 
 | ||||
| Plater::priv::~priv() | ||||
|  | @ -4159,6 +4162,7 @@ void Plater::priv::update_object_menu() | |||
| 
 | ||||
| void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const | ||||
| { | ||||
| 	RemovableDriveManager::get_instance().set_plater_ready_to_slice(is_ready_to_slice); | ||||
|     wxWindowUpdateLocker noUpdater(sidebar); | ||||
|     const auto prin_host_opt = config->option<ConfigOptionString>("print_host"); | ||||
|     const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty(); | ||||
|  |  | |||
|  | @ -414,7 +414,8 @@ RemovableDriveManager::RemovableDriveManager(): | |||
| 	m_last_save_name(""), | ||||
| 	m_last_save_path_verified(false), | ||||
| 	m_is_writing(false), | ||||
| 	m_did_eject(false) | ||||
| 	m_did_eject(false), | ||||
| 	m_plater_ready_to_slice(true) | ||||
| #if __APPLE__ | ||||
| 	, m_rdmmm(new RDMMMWrapper()) | ||||
| #endif | ||||
|  | @ -495,6 +496,10 @@ std::vector<DriveData> RemovableDriveManager::get_all_drives() | |||
| } | ||||
| void RemovableDriveManager::check_and_notify() | ||||
| { | ||||
| 	if(m_drive_count_changed_callback) | ||||
| 	{ | ||||
| 		m_drive_count_changed_callback(m_plater_ready_to_slice); | ||||
| 	} | ||||
| 	if(m_callbacks.size() != 0 && m_drives_count > m_current_drives.size() && m_last_save_path_verified && !is_drive_mounted(m_last_save_path)) | ||||
| 	{ | ||||
| 		for (auto it = m_callbacks.begin(); it != m_callbacks.end(); ++it) | ||||
|  | @ -507,10 +512,18 @@ void RemovableDriveManager::add_remove_callback(std::function<void()> callback) | |||
| { | ||||
| 	m_callbacks.push_back(callback); | ||||
| } | ||||
| void  RemovableDriveManager::erase_callbacks() | ||||
| void RemovableDriveManager::erase_callbacks() | ||||
| { | ||||
| 	m_callbacks.clear(); | ||||
| } | ||||
| void RemovableDriveManager::set_drive_count_changed_callback(std::function<void(const bool)> callback) | ||||
| { | ||||
| 	m_drive_count_changed_callback = callback; | ||||
| } | ||||
| void RemovableDriveManager::set_plater_ready_to_slice(bool b) | ||||
| { | ||||
| 	m_plater_ready_to_slice = b; | ||||
| } | ||||
| void RemovableDriveManager::set_last_save_path(const std::string& path) | ||||
| { | ||||
| 	m_last_save_path_verified = false; | ||||
|  |  | |||
|  | @ -46,8 +46,12 @@ public: | |||
| 	bool is_path_on_removable_drive(const std::string &path); | ||||
| 	// callback will notify only if device with last save path was removed
 | ||||
| 	void add_remove_callback(std::function<void()> callback); | ||||
| 	// erases all callbacks added by add_callback()
 | ||||
| 	// erases all remove callbacks added by add_remove_callback()
 | ||||
| 	void erase_callbacks();  | ||||
| 	//drive_count_changed callback is called on every added or removed device
 | ||||
| 	void set_drive_count_changed_callback(std::function<void(const bool)> callback); | ||||
| 	//thi serves to set correct value for drive_count_changed callback
 | ||||
| 	void set_plater_ready_to_slice(bool b); | ||||
| 	// marks one of the eveices in vector as last used
 | ||||
| 	void set_last_save_path(const std::string &path); | ||||
| 	void verify_last_save_path(); | ||||
|  | @ -71,6 +75,7 @@ private: | |||
| 
 | ||||
| 	std::vector<DriveData> m_current_drives; | ||||
| 	std::vector<std::function<void()>> m_callbacks; | ||||
| 	std::function<void(const bool)> m_drive_count_changed_callback; | ||||
| 	size_t m_drives_count; | ||||
| 	long m_last_update; | ||||
| 	std::string m_last_save_path; | ||||
|  | @ -78,6 +83,7 @@ private: | |||
| 	std::string m_last_save_name; | ||||
| 	bool m_is_writing;//on device
 | ||||
| 	bool m_did_eject; | ||||
| 	bool m_plater_ready_to_slice; | ||||
| #if _WIN32 | ||||
| 	//registers for notifications by creating invisible window
 | ||||
| 	void register_window(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 David Kocik
						David Kocik