From d90ff4e22acf0ed4aa32bcaa2b51a957047de714 Mon Sep 17 00:00:00 2001 From: THARAGESHWARAN-SATHYAMOORTHY Date: Fri, 16 Jun 2023 11:14:10 +0530 Subject: [PATCH] Fixed undo and redo while opening file from imports and gallery --- .../SchematicEditor/Helper/ToolbarTools.js | 17 +++++++++++++++++ .../SchematicEditor/SchematicToolbar.js | 2 ++ 2 files changed, 19 insertions(+) diff --git a/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js b/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js index 7b7da98da..a79ac0c9d 100644 --- a/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js +++ b/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js @@ -8,6 +8,17 @@ import * as actions from '../../../redux/actions/actions' import ComponentParameters from './ComponentParametersData' var graph var undoManager +export { undoManager }; + +let fileOpenedSuccessfully = false; + +export function setFileOpenedStatus(status) { + fileOpenedSuccessfully = status; +} + +export function getFileOpenedStatus() { + return fileOpenedSuccessfully; +} const { mxPrintPreview, @@ -65,6 +76,11 @@ const checkWireChange = (changes) => { // UNDO export function Undo() { + if (fileOpenedSuccessfully) { + undoManager.clear(); // Clear the undoManager + fileOpenedSuccessfully = false; + } + // undoManager.clear() if (undoManager.indexOfNextAdd === 0) { // Nothing to undo return @@ -1061,6 +1077,7 @@ export function renderGalleryXML(xml) { graph.removeCells(graph.getChildVertices(graph.getDefaultParent())) graph.view.refresh() var xmlDoc = mxUtils.parseXml(xml) + setFileOpenedStatus(true); parseXmlToGraph(xmlDoc, graph) } // Certain Variables need to be Defined before Saving the Circuit, XML Wire Connections does that diff --git a/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js b/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js index e2803127d..96f068fa0 100644 --- a/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js +++ b/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js @@ -42,6 +42,7 @@ import queryString from 'query-string' import { RotateLeft } from '@material-ui/icons' import AddPhotoAlternateIcon from '@material-ui/icons/AddPhotoAlternate' import { fetchRole } from '../../redux/actions/authActions' +import { setFileOpenedStatus } from './Helper/ToolbarTools'; import { NetlistModal, @@ -630,6 +631,7 @@ export default function SchematicToolbar ({ setMessage('Unsupported file error !') handleSnacClick() } else { + setFileOpenedStatus(true); // Set flag to indicate successful file opening dispatch(openLocalSch(obj)) } }