Java Code Examples for ghidra.framework.model.DomainFolder#moveTo()

The following examples show how to use ghidra.framework.model.DomainFolder#moveTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PasteFileTask.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Move the given folder and all of its contents into a new parent folder.
 * <p>
 * Displays a error dialog if there was an exception
 * 
 * @param {@link DomainFolder folder} being moved
 * @param newParent destination
 */
private void moveFolder(DomainFolder folder, DomainFolder newParent) {

	String name = folder.getName();
	try {
		folder.moveTo(newParent);
		Msg.info(this, "Moved folder " + name + " to " + folder.toString());
	}
	catch (Exception e) {
		ClientUtil.handleException(repository, e, "Move Folder", tool.getToolFrame());
	}
}
 
Example 2
Source File: LocalTreeNodeHandler.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void handleFolderDrag(DomainFolder destFolder, int dropAction,
		DomainFolder sourceFolder, TaskMonitor monitor) {
	if (dropAction == DnDConstants.ACTION_COPY || !sourceFolder.isInWritableProject()) {
		CopyTask task = new CopyTask(destFolder, sourceFolder);
		task.run(monitor);
		return;
	}

	try {
		sourceFolder.moveTo(destFolder);
	}
	catch (DuplicateFileException dfe) {
		Msg.showError(this, dataTree, "Error Moving Folder",
			"Destination folder already contains a folder named \"" + sourceFolder.getName() +
				"\"");
	}
	catch (FileInUseException fiue) {
		String message = fiue.getMessage();
		if (message == null || message.length() == 0) {
			message = "Cannot move folder '" + sourceFolder.toString() + "' to '" +
				destFolder.toString() +
				"'\nsince it contains a file that is checked out or in use.";
		}
		Msg.showError(this, dataTree, "Error Moving Folder", message);
	}
	catch (IOException e) {
		Msg.showError(this, dataTree, "Error Moving Folder", "Cannot Move Folder", e);
	}
}
 
Example 3
Source File: GhidraFileTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testRenameFolder() throws IOException, InvalidNameException {
	createDB(sharedFS, "/a", "A");
	createDB(sharedFS, "/a", "B");
	refresh();

	DomainFolder folder = root.getFolder("a");
	folder.getFiles();// visit folder

	folder = folder.setName("C");
	assertEquals("C", folder.getName());

	DomainFile df = folder.getFile("A");
	assertNotNull(df);
	assertEquals("/C/A", df.getPathname());

	df = folder.getFile("B");
	assertNotNull(df);
	assertEquals("/C/B", df.getPathname());

	assertNull(root.getFolder("a"));

	GhidraFolder dFolder = root.createFolder("D");
	dFolder.getFiles();// visit folder

	folder = folder.moveTo(dFolder);

	df = folder.getFile("A");
	assertNotNull(df);
	assertEquals("/D/C/A", df.getPathname());

	df = folder.getFile("B");
	assertNotNull(df);
	assertEquals("/D/C/B", df.getPathname());

	assertNull(root.getFolder("C"));

}