Skip to content

Commit

Permalink
atomic feedback context for project save
Browse files Browse the repository at this point in the history
Also delete unused method
  • Loading branch information
garfieldnate committed Sep 6, 2024
1 parent f434342 commit 014c6ab
Showing 1 changed file with 57 additions and 83 deletions.
140 changes: 57 additions & 83 deletions src/main/java/edu/umich/soar/visualsoar/mainframe/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1393,34 +1393,6 @@ public void closeProject() {
setTitle("VisualSoar");
}

/**
* Attempts to open a new project by creating a new OperatorWindow
* @param file .vsa project file that is to be opened
* @see OperatorWindow
*/
public void tryOpenProject (File file, boolean readOnly) throws IOException
{
operatorWindow = new OperatorWindow(file, readOnly);

operatorDesktopSplit.setLeftComponent(operatorWindow);

projectActionsEnable(true);

//Set and monitor the divider position
operDividerSetup();

//Update the title to include the project name
setTitle(file.getName().replaceAll(".vsa", ""));

//Reopen windows that were open last time
Cfg.readCfgFile(this);

//Configure read-only status
setReadOnly(readOnly);

}//tryOpenProject


public void openProject(@NotNull File vsaFile, boolean readOnly) {
//Get rid of the old project (if it exists)
if (operatorWindow != null) {
Expand Down Expand Up @@ -2102,62 +2074,64 @@ public void copyAllFiles(String oldFolder,

public void actionPerformed(ActionEvent e)
{
SaveProjectAsDialog spad = new SaveProjectAsDialog(MainFrame.getMainFrame());
spad.setVisible(true);

OperatorRootNode root = (OperatorRootNode)(operatorWindow.getModel().getRoot());
File oldProjectFile = new File(root.getProjectFile());
String oldProjPath = root.getFolderName();

if (spad.wasApproved())
{
String newName = spad.getNewAgentName();
String newRootPath = spad.getNewAgentPath();
String newProjPath = newRootPath + File.separator + newName;
if(OperatorWindow.isProjectNameValid(newName))
{
operatorWindow.saveProjectAs(newName, newRootPath);

// Regenerate the *_source.soar files in the old project
try {
OperatorWindow oldOpWin = new OperatorWindow(oldProjectFile, false);
OperatorRootNode oldOrn = (OperatorRootNode)oldOpWin.getModel().getRoot();
oldOrn.startSourcing();
}
catch (IOException exception) {
JOptionPane.showMessageDialog(MainFrame.this,
exception.getMessage(),
"Agent Export Error",
JOptionPane.ERROR_MESSAGE);
return;
}

copyAllFiles(oldProjPath, newProjPath, root);

JInternalFrame[] jif = desktopPane.getAllFrames();
for (JInternalFrame jInternalFrame : jif) {
if (jInternalFrame instanceof RuleEditor) {
RuleEditor oldRuleEditor = (RuleEditor) jInternalFrame;
OperatorNode newNode = oldRuleEditor.getNode();
oldRuleEditor.fileRenamed(newNode.getFileName()); // Update the Rule editor with the correct updated file name
}
}
saveAllFilesAction.perform(); // Save all open Rule Editors to the new project directory
exportAgentAction.perform();
saveDataMapAndProjectAction.perform(); // Save DataMap and Project file (.vsa)

//Set the title bar to include the project name
setTitle(newName);
try (FeedbackManager.AtomicContext ignored = getFeedbackManager().beginAtomicContext()) {
SaveProjectAsDialog spad = new SaveProjectAsDialog(MainFrame.getMainFrame());
spad.setVisible(true);

OperatorRootNode root = (OperatorRootNode) (operatorWindow.getModel().getRoot());
File oldProjectFile = new File(root.getProjectFile());
String oldProjPath = root.getFolderName();

if (spad.wasApproved()) {
String newName = spad.getNewAgentName();
String newRootPath = spad.getNewAgentPath();
String newProjPath = newRootPath + File.separator + newName;
if (OperatorWindow.isProjectNameValid(newName)) {
operatorWindow.saveProjectAs(newName, newRootPath);

// Regenerate the *_source.soar files in the old project
try {
OperatorWindow oldOpWin = new OperatorWindow(oldProjectFile, false);
OperatorRootNode oldOrn = (OperatorRootNode) oldOpWin.getModel().getRoot();
oldOrn.startSourcing();
} catch (IOException exception) {
JOptionPane.showMessageDialog(
MainFrame.this,
exception.getMessage(),
"Agent Export Error",
JOptionPane.ERROR_MESSAGE);
return;
}

}
else
{
JOptionPane.showMessageDialog(MainFrame.this,
"That is not a valid name for the project",
"Invalid Name",
JOptionPane.ERROR_MESSAGE);
}
}
copyAllFiles(oldProjPath, newProjPath, root);

JInternalFrame[] jif = desktopPane.getAllFrames();
for (JInternalFrame jInternalFrame : jif) {
if (jInternalFrame instanceof RuleEditor) {
RuleEditor oldRuleEditor = (RuleEditor) jInternalFrame;
OperatorNode newNode = oldRuleEditor.getNode();
oldRuleEditor.fileRenamed(
newNode
.getFileName()); // Update the Rule editor with the correct updated file
// name
}
}
saveAllFilesAction.perform(); // Save all open Rule Editors to the new project directory
exportAgentAction.perform();
saveDataMapAndProjectAction.perform(); // Save DataMap and Project file (.vsa)

// Set the title bar to include the project name
setTitle(newName);

} else {
JOptionPane.showMessageDialog(
MainFrame.this,
"That is not a valid name for the project",
"Invalid Name",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
}//class SaveProjectAsAction

Expand Down

0 comments on commit 014c6ab

Please sign in to comment.