| author | Da Risk <da_risk@geekorum.com> |
| Wed, 12 Jan 2022 17:29:59 -0400 | |
| changeset 882 | 7a74abf66c49 |
| parent 846 | ac0863af5ef6 |
| child 943 | 298742859784 |
| permissions | -rw-r--r-- |
|
137
5464f07a306c
Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
1 |
/* |
| 0 | 2 |
* Geekttrss is a RSS feed reader application on the Android Platform. |
3 |
* |
|
| 882 | 4 |
* Copyright (C) 2017-2022 by Frederic-Charles Barthelery. |
| 0 | 5 |
* |
6 |
* This file is part of Geekttrss. |
|
7 |
* |
|
8 |
* Geekttrss is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* Geekttrss is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with Geekttrss. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
|
21 |
package com.geekorum.ttrss.session |
|
22 |
||
23 |
/** |
|
24 |
* Simple interface for an Action that can be done and undone. |
|
25 |
*/ |
|
26 |
interface Action {
|
|
27 |
/** |
|
28 |
* Execute the action. |
|
29 |
*/ |
|
30 |
fun execute() |
|
31 |
||
32 |
/** |
|
33 |
* Undo the previously executed action. |
|
34 |
*/ |
|
35 |
fun undo() |
|
36 |
} |
|
37 |
||
38 |
/** |
|
39 |
* Allows to keep track of Actions that you may want to undo. |
|
40 |
*/ |
|
41 |
class UndoManager<in T : Action> {
|
|
42 |
||
43 |
private val actions = mutableListOf<T>() |
|
44 |
||
45 |
val nbActions get() = actions.size |
|
46 |
||
47 |
fun recordAction(action: T) {
|
|
48 |
actions += action |
|
49 |
} |
|
50 |
||
51 |
fun undoAll() {
|
|
52 |
for (action in actions.reversed()) {
|
|
53 |
action.undo() |
|
54 |
} |
|
55 |
actions.clear() |
|
56 |
} |
|
57 |
||
58 |
fun clear() {
|
|
59 |
actions.clear() |
|
60 |
} |
|
61 |
||
62 |
} |