|
10 | 10 | function RmlUiCommandWindow:Initialize() |
11 | 11 | self.document = SB.rmlui:LoadDocument(self.rmlPath, false) |
12 | 12 | self:BindEvents() |
13 | | - Log.Notice("Command Window initialized (RmlUi stub)") |
| 13 | + SB.commandManager:addListener(self) |
| 14 | + Log.Notice("Command Window initialized (RmlUi)") |
14 | 15 | return true |
15 | 16 | end |
16 | 17 |
|
@@ -50,33 +51,94 @@ function RmlUiCommandWindow:Hide() |
50 | 51 | end |
51 | 52 |
|
52 | 53 | function RmlUiCommandWindow:OnUndo() |
53 | | - Log.Notice("Undo command (not implemented)") |
54 | | - -- TODO: Execute UndoCommand |
| 54 | + SB.commandManager:execute(UndoCommand()) |
55 | 55 | end |
56 | 56 |
|
57 | 57 | function RmlUiCommandWindow:OnRedo() |
58 | | - Log.Notice("Redo command (not implemented)") |
59 | | - -- TODO: Execute RedoCommand |
| 58 | + SB.commandManager:execute(RedoCommand()) |
60 | 59 | end |
61 | 60 |
|
62 | 61 | function RmlUiCommandWindow:OnClearHistory() |
63 | | - Log.Notice("Clear history (not implemented)") |
64 | | - -- TODO: Execute ClearUndoRedoCommand |
| 62 | + SB.commandManager:execute(ClearUndoRedoCommand()) |
65 | 63 | end |
66 | 64 |
|
67 | 65 | function RmlUiCommandWindow:PushCommand(display) |
68 | 66 | self.count = self.count + 1 |
69 | | - Log.Notice("Command executed: " .. display) |
70 | | - -- TODO: Add command to list display |
| 67 | + local id = self.count |
| 68 | + Log.Debug("do", id) |
| 69 | + |
| 70 | + local commandList = self.document:GetElementById("command-list") |
| 71 | + if commandList then |
| 72 | + local itemDiv = self.document:CreateElement("div") |
| 73 | + itemDiv:SetAttribute("class", "command-item") |
| 74 | + itemDiv:SetAttribute("id", "cmd-" .. id) |
| 75 | + itemDiv.inner_rml = tostring(id) .. " " .. display |
| 76 | + commandList:AppendChild(itemDiv) |
| 77 | + |
| 78 | + -- Scroll to bottom |
| 79 | + commandList.scroll_top = commandList.scroll_height |
| 80 | + end |
| 81 | +end |
| 82 | + |
| 83 | +function RmlUiCommandWindow:UndoCommand() |
| 84 | + Log.Debug("undo", self.count - self.undoCount) |
| 85 | + local cmdItem = self.document:GetElementById("cmd-" .. (self.count - self.undoCount)) |
| 86 | + if cmdItem then |
| 87 | + cmdItem:AddClass("undone") |
| 88 | + end |
| 89 | + self.undoCount = self.undoCount + 1 |
| 90 | +end |
| 91 | + |
| 92 | +function RmlUiCommandWindow:RedoCommand() |
| 93 | + Log.Debug("redo", self.count - self.undoCount + 1) |
| 94 | + local cmdItem = self.document:GetElementById("cmd-" .. (self.count - self.undoCount + 1)) |
| 95 | + if cmdItem then |
| 96 | + cmdItem:RemoveClass("undone") |
| 97 | + end |
| 98 | + self.undoCount = self.undoCount - 1 |
71 | 99 | end |
72 | 100 |
|
73 | 101 | function RmlUiCommandWindow:OnCommandExecuted(cmdIDs, isUndo, isRedo, display) |
74 | | - -- Stub for command manager listener |
75 | 102 | if isUndo then |
76 | | - self.undoCount = self.undoCount + 1 |
| 103 | + self:UndoCommand() |
77 | 104 | elseif isRedo then |
78 | | - self.undoCount = self.undoCount - 1 |
| 105 | + self:RedoCommand() |
79 | 106 | else |
80 | 107 | self:PushCommand(display) |
81 | 108 | end |
82 | 109 | end |
| 110 | + |
| 111 | +function RmlUiCommandWindow:OnRemoveFirstUndo() |
| 112 | + Log.Debug("remundo", self.removedCount + 1) |
| 113 | + self.removedCount = self.removedCount + 1 |
| 114 | + local cmdItem = self.document:GetElementById("cmd-" .. self.removedCount) |
| 115 | + if cmdItem then |
| 116 | + cmdItem.parent_node:RemoveChild(cmdItem) |
| 117 | + end |
| 118 | +end |
| 119 | + |
| 120 | +function RmlUiCommandWindow:OnRemoveFirstRedo() |
| 121 | + Log.Debug(LOG.DEBUG, "remredo") |
| 122 | + local cmdItem = self.document:GetElementById("cmd-" .. self.count) |
| 123 | + if cmdItem then |
| 124 | + cmdItem.parent_node:RemoveChild(cmdItem) |
| 125 | + end |
| 126 | + self.count = self.count - 1 |
| 127 | + self.undoCount = self.undoCount - 1 |
| 128 | +end |
| 129 | + |
| 130 | +function RmlUiCommandWindow:OnClearUndoStack() |
| 131 | + Log.Debug("clearundostack") |
| 132 | + while self.removedCount ~= self.count do |
| 133 | + self:OnRemoveFirstUndo() |
| 134 | + end |
| 135 | + Log.Debug("clearundostackend") |
| 136 | +end |
| 137 | + |
| 138 | +function RmlUiCommandWindow:OnClearRedoStack() |
| 139 | + Log.Debug("clearredostack") |
| 140 | + while self.undoCount ~= 0 do |
| 141 | + self:OnRemoveFirstRedo() |
| 142 | + end |
| 143 | + Log.Debug("clearredostackend") |
| 144 | +end |
0 commit comments