GP-2261 Corrected issues affecting Change History dialog when

file/folder pathname changes are made.
This commit is contained in:
ghidra1 2022-06-29 18:55:41 -04:00
parent 22af19c500
commit 895fd3ee44
4 changed files with 47 additions and 30 deletions

View file

@ -15,8 +15,7 @@
*/
package ghidra.framework.data;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.*;
import javax.swing.Icon;
@ -56,7 +55,7 @@ public class GhidraFile implements DomainFile {
return fileManager.getUserFileSystem();
}
private GhidraFileData getFileData() throws IOException {
private GhidraFileData getFileData() throws FileNotFoundException, IOException {
return parent.getFileData(name);
}

View file

@ -16,11 +16,10 @@
package ghidra.framework.main.datatree;
import java.awt.event.MouseEvent;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.List;
import javax.swing.SwingUtilities;
import docking.ActionContext;
import docking.DialogComponentProvider;
import docking.action.DockingActionIf;
@ -34,7 +33,7 @@ import ghidra.util.HelpLocation;
public class VersionHistoryDialog extends DialogComponentProvider implements ProjectListener {
private VersionHistoryPanel versionPanel;
private MyFolderListener listener = new MyFolderListener();
private MyFolderListener listener;
private List<DockingActionIf> popupActions = Collections.emptyList();
public VersionHistoryDialog(DomainFile domainFile) {
@ -42,7 +41,7 @@ public class VersionHistoryDialog extends DialogComponentProvider implements Pro
super("Version History", false);
FrontEndTool frontEndTool = AppInfo.getFrontEndTool();
setHelpLocation(new HelpLocation(GenericHelpTopics.VERSION_CONTROL, "Show_History"));
versionPanel = new VersionHistoryPanel(frontEndTool, domainFile, true);
versionPanel = new VersionHistoryPanel(frontEndTool, null, true);
addWorkPanel(versionPanel);
addDismissButton();
@ -59,6 +58,7 @@ public class VersionHistoryDialog extends DialogComponentProvider implements Pro
Project project = frontEndTool.getProject();
if (project != null && df != null) {
setTitle("Version History for " + df.getName());
listener = new MyFolderListener();
project.getProjectData().addDomainFolderChangeListener(listener);
}
}
@ -79,11 +79,21 @@ public class VersionHistoryDialog extends DialogComponentProvider implements Pro
for (DockingActionIf action : popupActions) {
removeAction(action);
}
FrontEndTool frontEndTool = AppInfo.getFrontEndTool();
frontEndTool.removeProjectListener(this);
if (listener != null) {
Project project = frontEndTool.getProject();
if (project != null) {
project.getProjectData().removeDomainFolderChangeListener(listener);
}
listener = null;
}
}
@Override
public void projectClosed(Project project) {
dismissCallback();
close();
}
@Override
@ -102,35 +112,35 @@ public class VersionHistoryDialog extends DialogComponentProvider implements Pro
if (isFolder) {
affectedOldPath += FileSystem.SEPARATOR;
if (path.startsWith(affectedOldPath) && !versionPanel.getDomainFile().exists()) {
dismissCallback();
close();
}
}
else if (affectedOldPath.equals(path)) {
if (affectedNewPath == null) {
dismissCallback();
}
else {
versionPanel.refresh();
}
close();
}
}
@Override
public void domainFileStatusChanged(DomainFile file, boolean fileIDset) {
if (file.equals(versionPanel.getDomainFile())) {
versionPanel.refresh();
try {
versionPanel.refresh();
}
catch (FileNotFoundException e) {
close();
}
}
}
@Override
public void domainFileRemoved(DomainFolder parentFolder, String name, String fileID) {
DomainFile domainFile = versionPanel.getDomainFile();
if (parentFolder.equals(domainFile.getParent()) && domainFile.getName().equals(name)) {
// must be done later otherwise concurrent mod exception occurs
// in the domain folder notification of listeners.
SwingUtilities.invokeLater(() -> dismissCallback());
if (domainFile != null && parentFolder.equals(domainFile.getParent()) &&
domainFile.getName().equals(name)) {
close();
}
}
}
@Override

View file

@ -20,6 +20,7 @@ import java.awt.datatransfer.Transferable;
import java.awt.dnd.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
@ -93,15 +94,20 @@ public class VersionHistoryPanel extends JPanel implements Draggable {
}
/**
* Set the domain file to show its history
* Set the domain file to show its history.
* If file not found a null file will be set.
* @param domainFile the file
*/
public void setDomainFile(DomainFile domainFile) {
this.domainFile = domainFile;
if (domainFile != null) {
this.domainFilePath = domainFile.getPathname();
this.domainFilePath = domainFile != null ? domainFile.getPathname() : null;
try {
refresh();
}
catch (FileNotFoundException e) {
this.domainFile = null;
this.domainFilePath = null;
}
refresh();
}
/**
@ -306,7 +312,7 @@ public class VersionHistoryPanel extends JPanel implements Draggable {
messageType) == OptionDialog.OPTION_ONE;
}
void refresh() {
void refresh() throws FileNotFoundException {
try {
Version[] history = null;
if (domainFile != null) {
@ -317,6 +323,9 @@ public class VersionHistoryPanel extends JPanel implements Draggable {
}
tableModel.refresh(history);
}
catch (FileNotFoundException e) {
throw e;
}
catch (IOException e) {
ClientUtil.handleException(tool.getProject().getRepository(), e, "Get Version History",
this);

View file

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,10 +15,10 @@
*/
package ghidra.framework.model;
import ghidra.framework.store.FileSystem;
import java.lang.reflect.Method;
import ghidra.framework.store.FileSystem;
/**
* Adapter for the domain folder change listener.
* @see DomainFolderChangeListener for details regarding listener use
@ -102,13 +101,13 @@ public abstract class DomainFolderListenerAdapter implements DomainFolderChangeL
@Override
public void domainFolderRenamed(DomainFolder folder, String oldName) {
if (enableStateChangeCallback)
stateChanged(getPathname(folder.getParent(), oldName), folder.getPathname(), true);
stateChanged(folder.getPathname(), getPathname(folder.getParent(), oldName), true);
}
@Override
public void domainFileRenamed(DomainFile file, String oldName) {
if (enableStateChangeCallback)
stateChanged(getPathname(file.getParent(), oldName), file.getPathname(), false);
stateChanged(file.getPathname(), getPathname(file.getParent(), oldName), false);
}
@Override