Skip to content

Commit

Permalink
BROKEN Undo proof step renames
Browse files Browse the repository at this point in the history
It does undo the change but it doesn't rerender the proof panel
immediately which is not a great user experience
  • Loading branch information
Will Cashman committed Nov 27, 2023
1 parent d4aef56 commit bc43991
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
10 changes: 10 additions & 0 deletions zxlive/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ def update_graph_view(self, select_new: bool = False) -> None:
# we could store "dirty flags" for each node/edge.
self.graph_view.update_graph(self.g, select_new)

@dataclass
class UndoableChange(BaseCommand):
undo: Callable[[], None]
redo: Callable[[], None]

def undo(self) -> None:
self.undo(self)

def redo(self) -> None:
self.redo(self)

@dataclass
class SetGraph(BaseCommand):
Expand Down
5 changes: 2 additions & 3 deletions zxlive/common.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import os
from enum import IntEnum
from typing import Final
from typing import Final, Callable
from typing_extensions import TypeAlias

from PySide6.QtCore import QSettings
from PySide6.QtGui import QColor
from PySide6.QtGui import QColor, QUndoCommand

import pyzx

_ROOT = os.path.abspath(os.path.dirname(__file__))


def get_data(path: str) -> str:
return os.path.join(os.environ.get("_MEIPASS", _ROOT), path)

Expand Down
11 changes: 9 additions & 2 deletions zxlive/proof_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from . import animations as anims
from .base_panel import BasePanel, ToolbarSection
from .commands import AddRewriteStep, GoToRewriteStep, MoveNodeInStep
from .commands import AddRewriteStep, GoToRewriteStep, MoveNodeInStep, UndoableChange
from .common import (ET, VT, GraphT, get_data,
pos_from_view, pos_to_view, colors)
from .dialogs import show_error_msg
Expand Down Expand Up @@ -77,9 +77,16 @@ def __doubleClickHandler(self, index: QModelIndex | QPersistentModelIndex):
new_name, ok = QInputDialog.getText(
self, "Rename proof step", "Enter display name of proof step"
)

if ok:
# Subtract 1 from index since the START step isn't part of the model
index.model().rename_step(index.row()-1, new_name)
old_name = self.proof_model.steps[index.row()-1].display_name
self.undo_stack.push(UndoableChange(self,
lambda: self.proof_model.rename_step(index.row()-1, old_name),
lambda: self.proof_model.rename_step(index.row()-1, new_name)
))

self.proof_model.rename_step(index.row()-1,new_name)

def _toolbar_sections(self) -> Iterator[ToolbarSection]:
icon_size = QSize(32, 32)
Expand Down

0 comments on commit bc43991

Please sign in to comment.