28
28
#include " Encoding.h"
29
29
#include " LanguageManager.h"
30
30
#include " ConfigManager.h"
31
+ #include " UndoRedoManager.h"
31
32
32
33
#include < algorithm>
33
34
#include < bitset>
@@ -86,6 +87,7 @@ HWND MultiReplace::hDebugWnd = NULL;
86
87
bool MultiReplace::_isShuttingDown = false ;
87
88
static LanguageManager& LM = LanguageManager::instance();
88
89
static ConfigManager& CFG = ConfigManager::instance();
90
+ static UndoRedoManager& URM = UndoRedoManager::instance();
89
91
90
92
#pragma warning(disable: 6262)
91
93
@@ -816,34 +818,6 @@ void MultiReplace::updateUseListState(bool isUpdate)
816
818
817
819
#pragma region Undo stack
818
820
819
- void MultiReplace::undo () {
820
- if (!undoStack.empty ()) {
821
- // Get the last action
822
- UndoRedoAction action = undoStack.back ();
823
- undoStack.pop_back ();
824
-
825
- // Execute the undo action
826
- action.undoAction ();
827
-
828
- // Push the action onto the redoStack
829
- redoStack.push_back (action);
830
- }
831
- }
832
-
833
- void MultiReplace::redo () {
834
- if (!redoStack.empty ()) {
835
- // Get the last action
836
- UndoRedoAction action = redoStack.back ();
837
- redoStack.pop_back ();
838
-
839
- // Execute the redo action
840
- action.redoAction ();
841
-
842
- // Push the action back onto the undoStack
843
- undoStack.push_back (action);
844
- }
845
- }
846
-
847
821
void MultiReplace::addItemsToReplaceList (const std::vector<ReplaceItemData>& items, size_t insertPosition = std::numeric_limits<size_t >::max()) {
848
822
// Determine the insert position
849
823
if (insertPosition > replaceListData.size ()) {
@@ -860,9 +834,6 @@ void MultiReplace::addItemsToReplaceList(const std::vector<ReplaceItemData>& ite
860
834
ListView_SetItemCountEx (_replaceListView, static_cast <int >(replaceListData.size ()), LVSICF_NOINVALIDATEALL);
861
835
InvalidateRect (_replaceListView, NULL , TRUE );
862
836
863
- // Clear the redoStack since a new action invalidates the redo history
864
- redoStack.clear ();
865
-
866
837
// Create undo and redo actions
867
838
UndoRedoAction action;
868
839
@@ -904,7 +875,7 @@ void MultiReplace::addItemsToReplaceList(const std::vector<ReplaceItemData>& ite
904
875
};
905
876
906
877
// Push the action onto the undoStack
907
- undoStack. push_back (action);
878
+ URM. push (action. undoAction , action. redoAction , L" Add items " );
908
879
}
909
880
910
881
void MultiReplace::removeItemsFromReplaceList (const std::vector<size_t >& indicesToRemove) {
@@ -925,9 +896,6 @@ void MultiReplace::removeItemsFromReplaceList(const std::vector<size_t>& indices
925
896
ListView_SetItemCountEx (_replaceListView, static_cast <int >(replaceListData.size ()), LVSICF_NOINVALIDATEALL);
926
897
InvalidateRect (_replaceListView, NULL , TRUE );
927
898
928
- // Clear redoStack since a new action invalidates redo history
929
- redoStack.clear ();
930
-
931
899
// Create undo and redo actions
932
900
UndoRedoAction action;
933
901
@@ -994,7 +962,7 @@ void MultiReplace::removeItemsFromReplaceList(const std::vector<size_t>& indices
994
962
};
995
963
996
964
// Push the action to the undoStack
997
- undoStack. push_back (action);
965
+ URM. push (action. undoAction , action. redoAction , L" Remove items " );
998
966
}
999
967
1000
968
void MultiReplace::modifyItemInReplaceList (size_t index, const ReplaceItemData& newData) {
@@ -1007,9 +975,6 @@ void MultiReplace::modifyItemInReplaceList(size_t index, const ReplaceItemData&
1007
975
// Update the ListView item
1008
976
updateListViewItem (index);
1009
977
1010
- // Clear the redoStack
1011
- redoStack.clear ();
1012
-
1013
978
// Create Undo/Redo actions
1014
979
UndoRedoAction action;
1015
980
@@ -1046,7 +1011,7 @@ void MultiReplace::modifyItemInReplaceList(size_t index, const ReplaceItemData&
1046
1011
};
1047
1012
1048
1013
// Push the action onto the undoStack
1049
- undoStack. push_back (action);
1014
+ URM. push (action. undoAction , action. redoAction , L" Modify item " );
1050
1015
}
1051
1016
1052
1017
bool MultiReplace::moveItemsInReplaceList (std::vector<size_t >& indices, Direction direction) {
@@ -1084,9 +1049,6 @@ bool MultiReplace::moveItemsInReplaceList(std::vector<size_t>& indices, Directio
1084
1049
ListView_SetItemCountEx (_replaceListView, static_cast <int >(replaceListData.size ()), LVSICF_NOINVALIDATEALL);
1085
1050
InvalidateRect (_replaceListView, NULL , TRUE );
1086
1051
1087
- // Clear the redoStack to invalidate future actions
1088
- redoStack.clear ();
1089
-
1090
1052
// Create Undo/Redo actions
1091
1053
UndoRedoAction action;
1092
1054
@@ -1139,7 +1101,7 @@ bool MultiReplace::moveItemsInReplaceList(std::vector<size_t>& indices, Directio
1139
1101
};
1140
1102
1141
1103
// Push the action onto the undoStack
1142
- undoStack. push_back (action);
1104
+ URM. push (action. undoAction , action. redoAction , L" Move items " );
1143
1105
1144
1106
// Deselect all items
1145
1107
ListView_SetItemState (_replaceListView, -1 , 0 , LVIS_SELECTED);
@@ -1206,7 +1168,7 @@ void MultiReplace::sortItemsInReplaceList(const std::vector<size_t>& originalOrd
1206
1168
};
1207
1169
1208
1170
// Push the action onto the undo stack
1209
- undoStack. push_back (action);
1171
+ URM. push (action. undoAction , action. redoAction , L" Sort items " );
1210
1172
}
1211
1173
1212
1174
void MultiReplace::scrollToIndices (size_t firstIndex, size_t lastIndex) {
@@ -2689,8 +2651,8 @@ MenuState MultiReplace::checkMenuConditions(POINT ptScreen) {
2689
2651
state.allEnabled = (enabledCount == ListView_GetSelectedCount (_replaceListView));
2690
2652
state.allDisabled = (disabledCount == ListView_GetSelectedCount (_replaceListView));
2691
2653
2692
- state.canUndo = !undoStack. empty ();
2693
- state.canRedo = !redoStack. empty ();
2654
+ state.canUndo = URM. canUndo ();
2655
+ state.canRedo = URM. canRedo ();
2694
2656
2695
2657
return state;
2696
2658
}
@@ -2730,11 +2692,11 @@ void MultiReplace::performItemAction(POINT pt, ItemAction action) {
2730
2692
2731
2693
switch (action) {
2732
2694
case ItemAction::Undo:
2733
- undo ();
2695
+ URM. undo ();
2734
2696
showListFilePath ();
2735
2697
break ;
2736
2698
case ItemAction::Redo:
2737
- redo ();
2699
+ URM. redo ();
2738
2700
showListFilePath ();
2739
2701
break ;
2740
2702
case ItemAction::Search:
@@ -3451,10 +3413,10 @@ INT_PTR CALLBACK MultiReplace::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
3451
3413
if (GetKeyState (VK_CONTROL) & 0x8000 ) { // If Ctrl is pressed
3452
3414
switch (pnkd->wVKey ) {
3453
3415
case ' Z' : // Ctrl+Z for Undo
3454
- undo ();
3416
+ URM. undo ();
3455
3417
break ;
3456
3418
case ' Y' : // Ctrl+Y for Redo
3457
- redo ();
3419
+ URM. redo ();
3458
3420
break ;
3459
3421
case ' F' : // Ctrl+F for Search in List
3460
3422
performItemAction (_contextMenuClickPoint, ItemAction::Search);
@@ -8641,9 +8603,6 @@ void MultiReplace::setSelections(bool select, bool onlySelected) {
8641
8603
updateListViewItem (index);
8642
8604
}
8643
8605
8644
- // Clear the redoStack
8645
- redoStack.clear ();
8646
-
8647
8606
// Create Undo/Redo actions
8648
8607
UndoRedoAction action;
8649
8608
@@ -8666,7 +8625,7 @@ void MultiReplace::setSelections(bool select, bool onlySelected) {
8666
8625
};
8667
8626
8668
8627
// Push the action onto the undoStack
8669
- undoStack. push_back (action);
8628
+ URM. push (action. undoAction , action. redoAction , L" Set enabled " );
8670
8629
8671
8630
// Show Select Statisics
8672
8631
showListFilePath ();
@@ -9528,8 +9487,7 @@ void MultiReplace::loadListFromCsv(const std::wstring& filePath) {
9528
9487
originalListHash = computeListHash (replaceListData);
9529
9488
9530
9489
// Clear Undo and Redo stacks
9531
- undoStack.clear ();
9532
- redoStack.clear ();
9490
+ URM.clear ();
9533
9491
9534
9492
// Update the ListView
9535
9493
ListView_SetItemCountEx (_replaceListView, static_cast <int >(replaceListData.size ()), LVSICF_NOINVALIDATEALL);
0 commit comments