mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:52:44 +00:00 
			
		
		
		
	 fc5cab5c21
			
		
	
	
		fc5cab5c21
		
	
	
	
	
		
			
			This is easily identifiable by anyone who uses Duration::now_monotonic, and any downstream users of that data.
		
			
				
	
	
		
			50 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  * Copyright (c) 2022, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/Function.h>
 | |
| #include <AK/Time.h>
 | |
| #include <AK/Vector.h>
 | |
| #include <LibGUI/Forward.h>
 | |
| 
 | |
| namespace GUI {
 | |
| 
 | |
| class UndoStack {
 | |
| public:
 | |
|     UndoStack() = default;
 | |
|     ~UndoStack() = default;
 | |
| 
 | |
|     void push(NonnullOwnPtr<Command>);
 | |
|     ErrorOr<void> try_push(NonnullOwnPtr<Command>);
 | |
| 
 | |
|     bool can_undo() const;
 | |
|     bool can_redo() const;
 | |
| 
 | |
|     void undo();
 | |
|     void redo();
 | |
| 
 | |
|     void set_current_unmodified();
 | |
|     bool is_current_modified() const;
 | |
| 
 | |
|     Optional<MonotonicTime> last_unmodified_timestamp() const { return m_last_unmodified_timestamp; }
 | |
| 
 | |
|     void clear();
 | |
| 
 | |
|     Optional<DeprecatedString> undo_action_text() const;
 | |
|     Optional<DeprecatedString> redo_action_text() const;
 | |
| 
 | |
|     Function<void()> on_state_change;
 | |
| 
 | |
| private:
 | |
|     Vector<NonnullOwnPtr<Command>> m_stack;
 | |
|     size_t m_stack_index { 0 };
 | |
|     Optional<size_t> m_clean_index;
 | |
|     Optional<MonotonicTime> m_last_unmodified_timestamp;
 | |
| };
 | |
| 
 | |
| }
 |