| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  undo_redo.h                                                          */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-01-01 11:16:22 +01:00
										 |  |  | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #ifndef UNDO_REDO_H
 | 
					
						
							|  |  |  | #define UNDO_REDO_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/object.h"
 | 
					
						
							|  |  |  | #include "core/resource.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | class UndoRedo : public Object { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	GDCLASS(UndoRedo, Object); | 
					
						
							|  |  |  | 	OBJ_SAVE_TYPE(UndoRedo); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-08-17 17:14:51 -03:00
										 |  |  | 	enum MergeMode { | 
					
						
							|  |  |  | 		MERGE_DISABLE, | 
					
						
							|  |  |  | 		MERGE_ENDS, | 
					
						
							|  |  |  | 		MERGE_ALL | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	typedef void (*CommitNotifyCallback)(void *p_ud, const String &p_name); | 
					
						
							|  |  |  | 	Variant _add_do_method(const Variant **p_args, int p_argcount, Variant::CallError &r_error); | 
					
						
							|  |  |  | 	Variant _add_undo_method(const Variant **p_args, int p_argcount, Variant::CallError &r_error); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	typedef void (*MethodNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE); | 
					
						
							|  |  |  | 	typedef void (*PropertyNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value); | 
					
						
							| 
									
										
										
										
											2015-08-02 12:29:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | private: | 
					
						
							|  |  |  | 	struct Operation { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		enum Type { | 
					
						
							|  |  |  | 			TYPE_METHOD, | 
					
						
							|  |  |  | 			TYPE_PROPERTY, | 
					
						
							|  |  |  | 			TYPE_REFERENCE | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Type type; | 
					
						
							|  |  |  | 		Ref<Resource> resref; | 
					
						
							|  |  |  | 		ObjectID object; | 
					
						
							|  |  |  | 		String name; | 
					
						
							|  |  |  | 		Variant args[VARIANT_ARG_MAX]; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct Action { | 
					
						
							|  |  |  | 		String name; | 
					
						
							|  |  |  | 		List<Operation> do_ops; | 
					
						
							|  |  |  | 		List<Operation> undo_ops; | 
					
						
							| 
									
										
										
										
											2017-01-05 09:16:00 -03:00
										 |  |  | 		uint64_t last_tick; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Action> actions; | 
					
						
							|  |  |  | 	int current_action; | 
					
						
							|  |  |  | 	int action_level; | 
					
						
							| 
									
										
										
										
											2016-08-17 17:14:51 -03:00
										 |  |  | 	MergeMode merge_mode; | 
					
						
							| 
									
										
										
										
											2019-03-22 22:06:01 -03:00
										 |  |  | 	bool merging; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	uint64_t version; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void _pop_history_tail(); | 
					
						
							|  |  |  | 	void _process_operation_list(List<Operation>::Element *E); | 
					
						
							|  |  |  | 	void _discard_redo(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CommitNotifyCallback callback; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void *callback_ud; | 
					
						
							|  |  |  | 	void *method_callbck_ud; | 
					
						
							|  |  |  | 	void *prop_callback_ud; | 
					
						
							| 
									
										
										
										
											2015-08-02 12:29:37 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MethodNotifyCallback method_callback; | 
					
						
							|  |  |  | 	PropertyNotifyCallback property_callback; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 12:34:40 +02:00
										 |  |  | 	int committing; | 
					
						
							| 
									
										
										
										
											2019-03-03 17:53:59 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 21:55:47 +02:00
										 |  |  | protected: | 
					
						
							|  |  |  | 	static void _bind_methods(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void create_action(const String &p_name = "", MergeMode p_mode = MERGE_DISABLE); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void add_do_method(Object *p_object, const String &p_method, VARIANT_ARG_LIST); | 
					
						
							|  |  |  | 	void add_undo_method(Object *p_object, const String &p_method, VARIANT_ARG_LIST); | 
					
						
							|  |  |  | 	void add_do_property(Object *p_object, const String &p_property, const Variant &p_value); | 
					
						
							|  |  |  | 	void add_undo_property(Object *p_object, const String &p_property, const Variant &p_value); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void add_do_reference(Object *p_object); | 
					
						
							|  |  |  | 	void add_undo_reference(Object *p_object); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 12:34:40 +02:00
										 |  |  | 	bool is_committing_action() const; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-26 23:41:19 -03:00
										 |  |  | 	bool redo(); | 
					
						
							|  |  |  | 	bool undo(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	String get_current_action_name() const; | 
					
						
							| 
									
										
										
										
											2018-11-18 18:07:38 -02:00
										 |  |  | 	void clear_history(bool p_increase_version = true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 00:52:51 +01:00
										 |  |  | 	bool has_undo(); | 
					
						
							|  |  |  | 	bool has_redo(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	uint64_t get_version() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void set_method_notify_callback(MethodNotifyCallback p_method_callback, void *p_ud); | 
					
						
							|  |  |  | 	void set_property_notify_callback(PropertyNotifyCallback p_property_callback, void *p_ud); | 
					
						
							| 
									
										
										
										
											2015-08-02 12:29:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	UndoRedo(); | 
					
						
							|  |  |  | 	~UndoRedo(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | VARIANT_ENUM_CAST(UndoRedo::MergeMode); | 
					
						
							| 
									
										
										
										
											2016-08-17 17:14:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #endif // UNDO_REDO_H
 |