Skip to content

Commit 8eef7dd

Browse files
dragonmacherghidra1
authored andcommitted
Tests - fixed ToolActionsManagerTest
1 parent 6d5c3fb commit 8eef7dd

File tree

3 files changed

+117
-212
lines changed

3 files changed

+117
-212
lines changed

Ghidra/Framework/Project/src/main/java/ghidra/framework/project/tool/ToolManagerImpl.java

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ private enum ToolSaveStatus {
7070

7171
private Map<String, ToolSaveStatus> toolStatusMap = new HashMap<>();
7272

73-
/**
74-
* creates a tool manager for the project
75-
*/
7673
public ToolManagerImpl(Project project) {
7774
this.project = project;
7875
this.toolChest = project.getLocalToolChest();
@@ -91,8 +88,7 @@ public ToolManagerImpl(Project project) {
9188
* Registers the new instance of the tool in the namesMap and returns the total number of
9289
* running instances of that tool
9390
* @param toolName the name of the tool being registers
94-
* @param tool the tool being registered.
95-
* @return the total number of running instances of the tool
91+
* @param tool the tool being registered
9692
*/
9793
private void registerTool(String toolName, Tool tool) {
9894
List<Tool> list = namesMap.get(toolName);
@@ -124,17 +120,11 @@ private void deregisterTool(String toolName, Tool tool) {
124120
tool.removePropertyChangeListener(this);
125121
}
126122

127-
/*
128-
* @see ghidra.framework.model.ToolManager#getActiveWorkspace()
129-
*/
130123
@Override
131124
public Workspace getActiveWorkspace() {
132125
return activeWorkspace;
133126
}
134127

135-
/*
136-
* @see ghidra.framework.model.ToolManager#getConsumerTools()
137-
*/
138128
@Override
139129
public Tool[] getConsumerTools() {
140130
ArrayList<Tool> consumers = new ArrayList<>(TYPICAL_NUM_TOOLS);
@@ -149,9 +139,6 @@ public Tool[] getConsumerTools() {
149139
return tools;
150140
}
151141

152-
/*
153-
* @see ghidra.framework.model.ToolManager#getProducerTools()
154-
*/
155142
@Override
156143
public Tool[] getProducerTools() {
157144
ArrayList<Tool> producers = new ArrayList<>(TYPICAL_NUM_TOOLS);
@@ -165,9 +152,6 @@ public Tool[] getProducerTools() {
165152
return producers.toArray(tools);
166153
}
167154

168-
/*
169-
* @see ghidra.framework.model.ToolManager#getRunningTools()
170-
*/
171155
@Override
172156
public Tool[] getRunningTools() {
173157
Workspace[] wsList = new Workspace[workspaces.size()];
@@ -200,9 +184,6 @@ public ToolConnection getConnection(Tool producer, Tool consumer) {
200184
return tc;
201185
}
202186

203-
/*
204-
* @see ghidra.framework.model.ToolManager#createWorkspace(java.lang.String)
205-
*/
206187
@Override
207188
public Workspace createWorkspace(String name) throws DuplicateNameException {
208189
// if passed in the default "untitled" name, or no name at all,
@@ -291,17 +272,15 @@ public void removeWorkspace(Workspace ws) {
291272
}
292273
}
293274

294-
/*
295-
* @see ghidra.framework.model.ToolManager#getWorkspaces()
296-
*/
297275
@Override
298276
public Workspace[] getWorkspaces() {
299277
Workspace[] wsList = new Workspace[workspaces.size()];
300278
return workspaces.toArray(wsList);
301279
}
302280

303281
/**
304-
* saves this object to an XML element.
282+
* Saves this object to an XML element
283+
* @return the element containing the tool XML
305284
*/
306285
public Element saveToXml() {
307286

@@ -378,6 +357,7 @@ public void restoreFromXml(Element root) {
378357
/**
379358
* Return whether any tools have changed, or if any tools were
380359
* added or removed from any of the workspaces.
360+
* @return true if any tools in this workspace have changed
381361
*/
382362
public boolean hasChanged() {
383363
// check the connections for changes
@@ -407,7 +387,8 @@ public void close() {
407387

408388
/**
409389
* Save the tools that are opened and changed, that will be brought back up when the project
410-
* is reopened.
390+
* is reopened
391+
* @return true if the session was saved
411392
*/
412393
public boolean saveSessionTools() {
413394
Set<String> keySet = namesMap.keySet();
@@ -483,9 +464,6 @@ public void dumpConnectionList() {
483464
}
484465
}
485466

486-
/*
487-
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
488-
*/
489467
@Override
490468
public void propertyChange(PropertyChangeEvent evt) {
491469

@@ -514,17 +492,11 @@ public void propertyChange(PropertyChangeEvent evt) {
514492
firePropertyChangeEvent(evt);
515493
}
516494

517-
/*
518-
* @see ghidra.framework.model.ToolManager#addWorkspaceChangeListener(ghidra.framework.model.WorkspaceChangeListener)
519-
*/
520495
@Override
521496
public void addWorkspaceChangeListener(WorkspaceChangeListener l) {
522497
changeListeners.add(l);
523498
}
524499

525-
/*
526-
* @see ghidra.framework.model.ToolManager#removeWorkspaceChangeListener(ghidra.framework.model.WorkspaceChangeListener)
527-
*/
528500
@Override
529501
public void removeWorkspaceChangeListener(WorkspaceChangeListener l) {
530502
changeListeners.remove(l);
@@ -543,18 +515,14 @@ public void clearWorkspaceChanged() {
543515
}
544516

545517
/**
546-
* Get any toolservices available from this tool.
518+
* Get any tool services available from this tool
547519
*
548520
* @return ToolServices list of tool services this tool can provide.
549521
*/
550522
public ToolServices getToolServices() {
551523
return toolServices;
552524
}
553525

554-
/*
555-
* (non-Javadoc)
556-
* @see ghidra.framework.model.ToolManager#toolChanged(ghidra.framework.model.Tool)
557-
*/
558526
@Override
559527
public void toolChanged(Tool tool) {
560528
updateConnectMap(tool);
@@ -565,6 +533,8 @@ public void toolChanged(Tool tool) {
565533
// restoring the front end tool.
566534
/**
567535
* Called by WorkspaceImpl when it is restoring its state.
536+
* @param toolName the name of the tool
537+
* @return the tool
568538
*/
569539
public Tool getTool(String toolName) {
570540
ToolTemplate template = toolServices.getToolChest().getToolTemplate(toolName);
@@ -663,7 +633,7 @@ void setWorkspaceChanged(WorkspaceImpl ws) {
663633
* @param ws workspace to rename
664634
* @param name new name of workspace
665635
*
666-
* @throws DuplicateNameException
636+
* @throws DuplicateNameException if there already exists a workspace by the given name
667637
*/
668638
void setWorkspaceName(Workspace ws, String name) throws DuplicateNameException {
669639

@@ -682,7 +652,7 @@ void setWorkspaceName(Workspace ws, String name) throws DuplicateNameException {
682652
}
683653
}
684654

685-
/**
655+
/*
686656
* Get a tool from the template; set the instance name.
687657
*/
688658
Tool getTool(Workspace ws, ToolTemplate template) {
@@ -693,7 +663,7 @@ Tool getTool(Workspace ws, ToolTemplate template) {
693663
return tool;
694664
}
695665

696-
/**
666+
/*
697667
* Called by the workspace when a tool is removed.
698668
*/
699669
void toolRemoved(Workspace ws, Tool tool) {
@@ -743,25 +713,17 @@ private void addNewTool(Tool tool, String toolName) {
743713
}
744714
catch (PropertyVetoException e) {
745715
// shouldn't happen
746-
Msg.showError(this, null, "Error", "set type name was vetoed", e);
716+
Msg.showError(this, null, "Error Setting Tool Name", "Set tool name was vetoed", e);
747717
}
748-
Msg.debug(this, "Loaded " + tool.getName());
749718
}
750719

751-
/**
752-
* Called when a tool is added.
753-
*/
754720
void fireToolAddedEvent(Workspace ws, Tool tool) {
755721
for (int i = 0; i < changeListeners.size(); i++) {
756722
WorkspaceChangeListener l = changeListeners.get(i);
757723
l.toolAdded(ws, tool);
758724
}
759725
}
760726

761-
/**
762-
* Remove all connection objects for the given tool.
763-
* @param tool
764-
*/
765727
@Override
766728
public void disconnectTool(Tool tool) {
767729
Iterator<String> keys = connectMap.keySet().iterator();
@@ -777,10 +739,6 @@ public void disconnectTool(Tool tool) {
777739
}
778740
}
779741

780-
/**
781-
* Update the connection map for the given tool.
782-
* @param tool
783-
*/
784742
private void updateConnectMap(Tool tool) {
785743
Iterator<String> keys = connectMap.keySet().iterator();
786744
Map<String, ToolConnectionImpl> map = new HashMap<>();

Ghidra/Framework/Project/src/main/java/ghidra/framework/project/tool/ToolServicesImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ private File chooseToolFile(ToolTemplate tool) {
102102
if (!exportFile.getName().endsWith(ToolUtils.TOOL_EXTENSION)) {
103103
exportFile = new File(exportFile.getAbsolutePath() + ToolUtils.TOOL_EXTENSION);
104104
}
105+
105106
if (exportFile.exists()) {
106107
int result = OptionDialog.showOptionDialog(null, "Overwrite?",
107-
"Overwrite existing file, " + exportFile.getName() + "?", "Overwrite",
108+
"Overwrite existing file: '" + exportFile.getName() + "'?", "Overwrite",
108109
OptionDialog.QUESTION_MESSAGE);
109110
if (result != OptionDialog.OPTION_ONE) {
110111
exportFile = null; // user chose not to overwrite

0 commit comments

Comments
 (0)