fix(editor): reset undo history on load/new
This commit is contained in:
parent
ed5aa597ad
commit
d3ea7cc0cd
5 changed files with 25 additions and 10 deletions
|
@ -124,8 +124,6 @@ SurfaceType Part::surfaceFromFace(NormalId face) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float Part::GetSurfaceParamA(Vector3 face) {
|
float Part::GetSurfaceParamA(Vector3 face) {
|
||||||
// printVec(face);
|
|
||||||
// printf("Enum: %d\n", faceFromNormal(face));
|
|
||||||
switch (faceFromNormal(face)) {
|
switch (faceFromNormal(face)) {
|
||||||
case Top: return topParamA;
|
case Top: return topParamA;
|
||||||
case Bottom: return bottomParamA;
|
case Bottom: return bottomParamA;
|
||||||
|
|
|
@ -382,7 +382,6 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
||||||
initialAssembly = PartAssembly::FromSelection(gDataModel->GetService<Selection>());
|
initialAssembly = PartAssembly::FromSelection(gDataModel->GetService<Selection>());
|
||||||
initialFrame = initialAssembly.assemblyOrigin();
|
initialFrame = initialAssembly.assemblyOrigin();
|
||||||
initialTransforms = PartAssembly::FromSelection(gDataModel->GetService<Selection>()).GetCurrentTransforms();
|
initialTransforms = PartAssembly::FromSelection(gDataModel->GetService<Selection>()).GetCurrentTransforms();
|
||||||
printf("%ld\n", initialTransforms.size());
|
|
||||||
isMouseDragging = true;
|
isMouseDragging = true;
|
||||||
draggingHandle = handle;
|
draggingHandle = handle;
|
||||||
startLinearTransform(evt);
|
startLinearTransform(evt);
|
||||||
|
|
|
@ -108,9 +108,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui->actionUndo->setEnabled(false);
|
ui->actionUndo->setEnabled(false);
|
||||||
ui->actionRedo->setEnabled(false);
|
ui->actionRedo->setEnabled(false);
|
||||||
|
|
||||||
undoManager.SetUndoStateListener([&](bool canUndo, bool canRedo) {
|
undoManager.SetUndoStateListener([&]() {
|
||||||
ui->actionUndo->setEnabled(canUndo);
|
updateToolbars();
|
||||||
ui->actionRedo->setEnabled(canRedo);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,6 +233,11 @@ void MainWindow::connectActionHandlers() {
|
||||||
gDataModel->Init();
|
gDataModel->Init();
|
||||||
ui->explorerView->updateRoot(gDataModel);
|
ui->explorerView->updateRoot(gDataModel);
|
||||||
|
|
||||||
|
// Reset running state
|
||||||
|
placeDocument->setRunState(RUN_STOPPED);
|
||||||
|
undoManager.Reset();
|
||||||
|
updateToolbars();
|
||||||
|
|
||||||
// Baseplate
|
// Baseplate
|
||||||
gWorkspace()->AddChild(placeDocument->placeWidget->lastPart = Part::New({
|
gWorkspace()->AddChild(placeDocument->placeWidget->lastPart = Part::New({
|
||||||
.position = glm::vec3(0, -5, 0),
|
.position = glm::vec3(0, -5, 0),
|
||||||
|
@ -279,6 +283,7 @@ void MainWindow::connectActionHandlers() {
|
||||||
|
|
||||||
// Reset running state
|
// Reset running state
|
||||||
placeDocument->setRunState(RUN_STOPPED);
|
placeDocument->setRunState(RUN_STOPPED);
|
||||||
|
undoManager.Reset();
|
||||||
updateToolbars();
|
updateToolbars();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -546,6 +551,9 @@ void MainWindow::updateToolbars() {
|
||||||
ui->actionRunSimulation->setEnabled(placeDocument->runState() != RUN_RUNNING);
|
ui->actionRunSimulation->setEnabled(placeDocument->runState() != RUN_RUNNING);
|
||||||
ui->actionPauseSimulation->setEnabled(placeDocument->runState() == RUN_RUNNING);
|
ui->actionPauseSimulation->setEnabled(placeDocument->runState() == RUN_RUNNING);
|
||||||
ui->actionStopSimulation->setEnabled(placeDocument->runState() != RUN_STOPPED);
|
ui->actionStopSimulation->setEnabled(placeDocument->runState() != RUN_STOPPED);
|
||||||
|
|
||||||
|
ui->actionUndo->setEnabled(undoManager.CanUndo() && placeDocument->runState() == RUN_STOPPED);
|
||||||
|
ui->actionRedo->setEnabled(undoManager.CanRedo() && placeDocument->runState() == RUN_STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> MainWindow::openFileDialog(QString filter, QString defaultExtension, QFileDialog::AcceptMode acceptMode, QString title) {
|
std::optional<std::string> MainWindow::openFileDialog(QString filter, QString defaultExtension, QFileDialog::AcceptMode acceptMode, QString title) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ void UndoHistory::PushState(UndoState state) {
|
||||||
undoHistory.erase(undoHistory.begin(), undoHistory.begin()+maxBufferSize-(int)undoHistory.size()-1);
|
undoHistory.erase(undoHistory.begin(), undoHistory.begin()+maxBufferSize-(int)undoHistory.size()-1);
|
||||||
|
|
||||||
undoHistory.push_back(state);
|
undoHistory.push_back(state);
|
||||||
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
|
undoStateListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UndoHistory::Undo() {
|
void UndoHistory::Undo() {
|
||||||
|
@ -38,7 +38,7 @@ void UndoHistory::Undo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
processingUndo = false;
|
processingUndo = false;
|
||||||
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
|
undoStateListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UndoHistory::Redo() {
|
void UndoHistory::Redo() {
|
||||||
|
@ -66,7 +66,14 @@ void UndoHistory::Redo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
processingUndo = false;
|
processingUndo = false;
|
||||||
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
|
undoStateListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoHistory::Reset() {
|
||||||
|
processingUndo = false;
|
||||||
|
undoHistory.clear();
|
||||||
|
redoHistory = {};
|
||||||
|
undoStateListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UndoHistory::SetUndoStateListener(UndoStateChangedListener listener) {
|
void UndoHistory::SetUndoStateListener(UndoStateChangedListener listener) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ struct UndoStateSelectionChanged {
|
||||||
|
|
||||||
typedef std::variant<UndoStatePropertyChanged, UndoStateInstanceCreated, UndoStateInstanceRemoved, UndoStateInstanceReparented, UndoStateSelectionChanged> UndoStateChange;
|
typedef std::variant<UndoStatePropertyChanged, UndoStateInstanceCreated, UndoStateInstanceRemoved, UndoStateInstanceReparented, UndoStateSelectionChanged> UndoStateChange;
|
||||||
typedef std::vector<UndoStateChange> UndoState;
|
typedef std::vector<UndoStateChange> UndoState;
|
||||||
typedef std::function<void(bool canUndo, bool canRedo)> UndoStateChangedListener;
|
typedef std::function<void()> UndoStateChangedListener;
|
||||||
|
|
||||||
class UndoHistory {
|
class UndoHistory {
|
||||||
// Ignore PushState requests
|
// Ignore PushState requests
|
||||||
|
@ -53,6 +53,9 @@ public:
|
||||||
void PushState(UndoState);
|
void PushState(UndoState);
|
||||||
void Undo();
|
void Undo();
|
||||||
void Redo();
|
void Redo();
|
||||||
|
void Reset();
|
||||||
|
inline bool CanUndo() { return !undoHistory.empty(); }
|
||||||
|
inline bool CanRedo() { return !redoHistory.empty(); }
|
||||||
|
|
||||||
void SetUndoStateListener(UndoStateChangedListener listener);
|
void SetUndoStateListener(UndoStateChangedListener listener);
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue