Java Code Examples for docking.widgets.OptionDialog#CANCEL_OPTION

The following examples show how to use docking.widgets.OptionDialog#CANCEL_OPTION . 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: ProgramSaveManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void saveAs(Program currentProgram, DomainFolder folder, String name) {
	DomainFile existingFile = folder.getFile(name);
	if (existingFile == currentProgram.getDomainFile()) {
		save(currentProgram);
		return;
	}
	if (existingFile != null) {
		String msg = "Program " + name + " already exists.\n" + "Do you want to overwrite it?";
		if (OptionDialog.showOptionDialog(tool.getToolFrame(), "Duplicate Name", msg,
			"Overwrite", OptionDialog.QUESTION_MESSAGE) == OptionDialog.CANCEL_OPTION) {
			return;
		}
	}
	tool.prepareToSave(currentProgram);
	SaveAsTask task = new SaveAsTask(currentProgram, folder, name, existingFile != null);
	new TaskLauncher(task, tool.getToolFrame());
}
 
Example 2
Source File: DeleteProjectFilesTask.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void showCheckedOutVersionedDialog(DomainFile file) throws CancelledException {
	if (checkedOutDialogBuilder == null) {

		//@formatter:off
		checkedOutDialogBuilder = 
			new OptionDialogBuilder("Delete Not Allowed")
			.addOption("OK")
			.addCancel()
			.setMessageType(OptionDialog.ERROR_MESSAGE)
			;
		//@formatter:on

		if (getFileCount() > 1) {
			checkedOutDialogBuilder.addDontShowAgainOption();
		}
	}

	String msg = "The file \"" + file.getName() +
		"\" is a versioned file that you have\n checked out. It can't be deleted!";
	checkedOutDialogBuilder.setMessage(msg);
	if (checkedOutDialogBuilder.show(parent) == OptionDialog.CANCEL_OPTION) {
		throw new CancelledException();
	}
}
 
Example 3
Source File: DataTypeManagerHandler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void saveAs(UndoableDomainObject undoableDomainObject, DomainFolder folder,
		String name) {
	DomainFile existingFile = folder.getFile(name);
	if (existingFile == undoableDomainObject.getDomainFile()) {
		save(undoableDomainObject);
		return;
	}
	if (existingFile != null) {
		String msg = "Program " + name + " already exists.\n" + "Do you want to overwrite it?";
		if (OptionDialog.showOptionDialog(tool.getToolFrame(), "Duplicate Name", msg,
			"Overwrite", OptionDialog.QUESTION_MESSAGE) == OptionDialog.CANCEL_OPTION) {
			return;
		}
	}
	tool.prepareToSave(undoableDomainObject);
	DomainObjectSaveAsTask task = new DomainObjectSaveAsTask(CONTENT_NAME, undoableDomainObject,
		folder, name, existingFile != null);
	new TaskLauncher(task, tool.getToolFrame());
}
 
Example 4
Source File: EquateTablePlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void deleteEquates(List<Equate> equates) {
	if (equates.isEmpty()) {
		return;
	}

	// create a string list of names of all equates to be removed...
	String[] equateNames = new String[equates.size()];
	StringBuffer equateList = new StringBuffer();
	for (int i = 0; i < equates.size(); ++i) {
		equateNames[i] = equates.get(i).getName();
		equateList.append(equateNames[i]);
		if (i < equates.size() - 1) {
			equateList.append(", ");
		}
	}
	String title = "Delete Equate" + (equates.size() > 1 ? "s" : "") + "?";
	String msg = "Do you really want to delete the equate" + (equates.size() > 1 ? "s" : "") +
		": " + equates + "  ?" + "\n\n   NOTE: All references will be removed.";

	int option = OptionDialog.showOptionDialog(provider.getComponent(), title, msg, "Delete",
		OptionDialog.QUESTION_MESSAGE);

	if (option != OptionDialog.CANCEL_OPTION) {
		tool.execute(new RemoveEquateCmd(equateNames, getTool()), currentProgram);
	}
}
 
Example 5
Source File: StackEditorModel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private boolean avoidApplyingConflictingData() {
	if (!hasChanges()) {
		return true; // nothing to do (probably can't get here)
	}

	if (!stackChangedExternally) {
		return false; // not conflicts; nothing to avoid
	}

	int choice = OptionDialog.showOptionDialogWithCancelAsDefaultButton(provider.getComponent(),
		"Overwrite Program Changes?",
		"<html>The function's stack data has changed outside of this<br>" +
			"Stack Editor Provider.<br><BR>" +
			"Would you like to overwrite the external changes with your changes?",
		"Overwrite", OptionDialog.WARNING_MESSAGE);

	if (choice == OptionDialog.CANCEL_OPTION) {
		return true;
	}

	return false;
}
 
Example 6
Source File: ManagePluginsDialog.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected void escapeCallback() {
	if (isNewTool && tool.hasConfigChanged()) {
		String title = "New Tool Not Saved";
		String message = "New Tool has not been saved to your Tool Chest.";
		int result = OptionDialog.showOptionDialog(rootPanel, title,
			message + "\nDo you want to save it now?", "&Yes", "&No",
			OptionDialog.QUESTION_MESSAGE);
		if (result == OptionDialog.CANCEL_OPTION) {
			return;
		}
		if (result == OptionDialog.OPTION_ONE) {
			save();
		}
	}
	ClassSearcher.removeChangeListener(this);
	close();
}
 
Example 7
Source File: SetStackDepthChangeAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void setStackDepthChange(final Program program, final Address address,
		final int newStackDepthChange, final Address callToAddress) {

	if (callToAddress == null) {
		setStackDepthChange(program, address, newStackDepthChange);
		return;
	}
	int result = showPurgeQuestionDialog(funcPlugin.getTool(), address, callToAddress);
	switch (result) {
		case OptionDialog.OPTION_ONE: // Local (SetStackDepthChange)
			setStackDepthChange(program, address, newStackDepthChange);
			break;
		case OptionDialog.OPTION_TWO: // Global (SetFunctionPurge)
			setFunctionPurge(program, address, newStackDepthChange, callToAddress);
			break;
		case OptionDialog.CANCEL_OPTION: // Cancel
			break;
	}
}
 
Example 8
Source File: CParserPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void parse(String[] filenames, String options) {
	if (currentProgram == null) {
		Msg.showInfo(getClass(), parseDialog.getComponent(), "No Open Program",
			"A program must be open to \"Parse to Program\"");
		return;
	}
	int result = OptionDialog.showOptionDialog(parseDialog.getComponent(), "Confirm",
		"Parse C source to \"" + currentProgram.getDomainFile().getName() + "\"?", "Continue");

	if (result == OptionDialog.CANCEL_OPTION) {
		return;
	}
	CParserTask parseTask =
		new CParserTask(this, filenames, options, currentProgram.getDataTypeManager());

	tool.execute(parseTask);
}
 
Example 9
Source File: ReferencesPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean confirmPossibleReferenceRemoval(CodeUnit fromCodeUnit, int opIndex,
		Reference oldRef) {

	if (oldRef == null) {
		Reference[] refs = fromCodeUnit.getProgram().getReferenceManager().getReferencesFrom(
			fromCodeUnit.getMinAddress(), opIndex);
		if (refs.length != 0) {
			oldRef = refs[0];
		}
		else {
			return true;
		}
	}

	String curType;
	if (oldRef.isStackReference()) {
		curType = "Stack reference";
	}
	else if (oldRef.getToAddress().isRegisterAddress()) {
		curType = "Register reference";
	}
	else if (oldRef.isExternalReference()) {
		curType = "External reference";
	}
	else {
		curType = "Memory reference(s)";
	}

	JComponent parent = editRefDialog.getComponent();
	int choice = OptionDialog.showOptionDialog(parent, "Reference Removal Confirmation",
		"Warning! existing " + curType + " will be removed.", "Continue",
		OptionDialog.WARNING_MESSAGE);
	return (choice != OptionDialog.CANCEL_OPTION);
}
 
Example 10
Source File: ProgramSaveManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean handleChangedProgram(Program currentProgram) {
	if (!currentProgram.isChanged()) {
		return true;
	}
	DomainFile df = currentProgram.getDomainFile();

	String filename = df.getName();

	if (!df.isInWritableProject()) {
		return OptionDialog.showOptionDialog(tool.getToolFrame(), "Program Changed",
			HTMLUtilities.lineWrapWithHTMLLineBreaks(
				"<html>Viewed file '" + HTMLUtilities.escapeHTML(filename) +
					"' has been changed.  \n" + "If you continue, your changes will be lost!"),
			"Continue", OptionDialog.QUESTION_MESSAGE) != OptionDialog.CANCEL_OPTION;
	}

	if (df.isReadOnly()) {
		return OptionDialog.showOptionDialog(tool.getToolFrame(), "Program Changed",
			HTMLUtilities.lineWrapWithHTMLLineBreaks(
				"<html>Read-only file '" + HTMLUtilities.escapeHTML(filename) +
					"' has been changed.  \n" + "If you continue, your changes will be lost!"),
			"Continue", OptionDialog.QUESTION_MESSAGE) != OptionDialog.CANCEL_OPTION;

	}

	int result = OptionDialog.showOptionDialog(tool.getToolFrame(), "Save Program?",
		HTMLUtilities.lineWrapWithHTMLLineBreaks("<html>" + HTMLUtilities.escapeHTML(filename) +
			" has changed.\nDo you want to save it?"),
		"&Save", "Do&n't Save", OptionDialog.QUESTION_MESSAGE);

	if (result == OptionDialog.CANCEL_OPTION) {
		return false;
	}
	if (result == OptionDialog.OPTION_ONE) {
		SaveFileTask task = new SaveFileTask(currentProgram.getDomainFile());
		new TaskLauncher(task, tool.getToolFrame());
	}
	return true;
}
 
Example 11
Source File: TagListPanel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes any selected tags from the system. 
 */
protected void deleteSelectedTags() {

	List<FunctionTag> selectedTags = getSelectedTags();

	if (selectedTags.isEmpty()) {
		return;
	}

	// Show a confirmation message - users may not be aware that deleting a tag is more
	// than just removing it from a function.
	int option = OptionDialog.showOptionDialog(this, "Function Tag Delete",
		"Are you sure? \nThis will delete the tag from all functions in the program.", "OK",
		OptionDialog.WARNING_MESSAGE);

	switch (option) {
		case OptionDialog.OPTION_ONE:
			for (FunctionTag tag : selectedTags) {
				Command cmd = new DeleteFunctionTagCmd(tag.getName());
				tool.execute(cmd, program);
			}
			break;
		case OptionDialog.CANCEL_OPTION:
			// do nothing
			break;
	}
}
 
Example 12
Source File: EnumEditorProvider.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if the new changes to the enum will affect equates based off of it.
 * @param editedEnum the enum to check for conflicts with
 * @param dtm the data type manager that this enum lies within
 * @return true if the enum should save its changes; otherwise, false
 */
private boolean resolveEquateConflicts(Enum editedEnum, DataTypeManager dtm) {

	Program program = plugin.getProgram();
	if (program == null) {
		// No open program; data type not from the program archive.
		return true;
	}

	EquateTable et = program.getEquateTable();
	Set<String> oldFieldConflicts = new HashSet<>();
	Set<String> conflictingEquates = new HashSet<>();

	for (Equate eq : CollectionUtils.asIterable(et.getEquates())) {
		if (eq.isEnumBased() && originalEnum.getUniversalID().equals(eq.getEnumUUID()) &&
			editedEnum.getName(eq.getValue()) == null) {
			oldFieldConflicts.add(originalEnum.getName(eq.getValue()));
			conflictingEquates.add(eq.getName());
		}
	}
	if (conflictingEquates.isEmpty()) {
		return true;
	}
	switch (showOptionDialog(editedEnum, oldFieldConflicts)) {
		case OptionDialog.OPTION_ONE:
			removeEquates(et, conflictingEquates);
		case OptionDialog.OPTION_TWO:
			return true;
		case OptionDialog.CANCEL_OPTION:
		default:
			return false;
	}
}
 
Example 13
Source File: PdbSymbolServerPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean askIncludePeHeaderPdbPath() throws CancelledException {
	//@formatter:off
	int choice = OptionDialog.showOptionDialog(
		null,
		"PE-specified PDB Path",
		"Unsafe: Include PE-specified PDB Path in search for existing PDB",
		"Yes",
		"No");
	//@formatter:on

	if (choice == OptionDialog.CANCEL_OPTION) {
		throw new CancelledException();
	}
	return (choice == OptionDialog.OPTION_ONE);
}
 
Example 14
Source File: PdbSymbolServerPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private PdbFileType askForFileExtension() throws CancelledException {
	//@formatter:off
	int choice = OptionDialog.showOptionDialog(
		null,
		"pdb or pdb.xml",
		"Download a .pdb or .pdb.xml file? (.pdb.xml can be processed on non-Windows systems)",
		"PDB",
		"XML");
	//@formatter:on

	if (choice == OptionDialog.CANCEL_OPTION) {
		throw new CancelledException();
	}
	return (choice == OptionDialog.OPTION_ONE) ? PdbFileType.PDB : PdbFileType.XML;
}
 
Example 15
Source File: PluginTool.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/** 
 * Called when it is time to save the tool.  Handles auto-saving logic.
 * @return true if a save happened
 */
protected boolean doSaveTool() {
	if (toolServices.canAutoSave(this)) {
		saveTool();
	}
	else {
		if (configChangedFlag) {
			int result = OptionDialog.showOptionDialog(getToolFrame(), SAVE_DIALOG_TITLE,
				"This tool has changed.  There are/were multiple instances of this tool\n" +
					"running and Ghidra cannot determine if this tool instance should\n" +
					"automatically be saved.  Do you want to save the configuration of this tool\n" +
					"instance?",
				"Save", "Save As...", "Don't Save", OptionDialog.WARNING_MESSAGE);
			if (result == OptionDialog.CANCEL_OPTION) {
				return false;
			}
			if (result == OptionDialog.OPTION_ONE) {
				saveTool();
			}
			else if (result == OptionDialog.OPTION_TWO) {
				boolean didSave = saveToolAs();
				if (!didSave) {
					return doSaveTool();
				}
			}
			// option 3 is don't save; just exit
		}
	}
	return true;
}
 
Example 16
Source File: FrontEndPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
boolean confirmDelete(String message) {
	int option = OptionDialog.showOptionDialogWithCancelAsDefaultButton(tool.getToolFrame(),
		"Confirm Delete", "Are you sure you want to delete\n" + message, "Delete",
		OptionDialog.QUESTION_MESSAGE);

	return (option != OptionDialog.CANCEL_OPTION);
}
 
Example 17
Source File: ArchiveUtils.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public static boolean canClose(Archive archive, Component component) {
	if (!archive.isChanged()) {
		return true;
	}
	int result =
		OptionDialog.showYesNoCancelDialog(component, "Save Archive?", "Datatype Archive \"" +
			archive.getName() + "\" has been changed.\n Do you want to save the changes?");

	if (result == OptionDialog.CANCEL_OPTION) {
		return false;
	}
	if (result == OptionDialog.NO_OPTION) {
		if (archive instanceof FileArchive) {
			// Release the write lock without saving. Returns file archive to its unedited state.
			try {
				((FileArchive) archive).releaseWriteLock();
			}
			catch (IOException e) {
				Msg.showError(log, component, "Unable to release File Archive write lock.",
					e.getMessage(), e);
				return false;
			}
		}
		return true;
	}

	return saveArchive(archive, component);
}
 
Example 18
Source File: GoToHelper.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void createExternalAssociation(Program program, String extProgName) {
	int result = OptionDialog.showOptionDialog(null, "No Program Association",
		"The external program name \"" + extProgName +
			"\" is not associated with a Ghidra Program\n" +
			"Would you like to create an association?",
		"Create Association", OptionDialog.QUESTION_MESSAGE);
	if (result == OptionDialog.CANCEL_OPTION) {
		return;
	}
	final DataTreeDialog dialog = new DataTreeDialog(null,
		"Choose External Program (" + extProgName + ")", DataTreeDialog.OPEN);

	dialog.setSearchText(extProgName);
	dialog.setHelpLocation(new HelpLocation("ReferencesPlugin", "ChooseExternalProgram"));
	tool.showDialog(dialog);
	DomainFile domainFile = dialog.getDomainFile();
	if (dialog.wasCancelled() || domainFile == null) {
		return;
	}
	String pathName = domainFile.toString();
	ExternalManager externalManager = program.getExternalManager();
	String externalLibraryPath = externalManager.getExternalLibraryPath(extProgName);
	if (!pathName.equals(externalLibraryPath)) {
		Command cmd = new SetExternalNameCmd(extProgName, domainFile.getPathname());
		tool.execute(cmd, program);
	}
}
 
Example 19
Source File: CommitSingleDataTypeAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	GTree gTree = (GTree) context.getContextObject();
	TreePath[] selectionPaths = gTree.getSelectionPaths();
	if (selectionPaths == null || selectionPaths.length != 1) {
		return;
	}
	GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
	if (!(node instanceof DataTypeNode)) {
		return;
	}
	DataTypeNode dataTypeNode = (DataTypeNode) node;
	DataType dataType = dataTypeNode.getDataType();
	DataTypeManager dtm = dataType.getDataTypeManager();
	DataTypeManagerHandler handler = plugin.getDataTypeManagerHandler();
	DataTypeSyncState syncStatus = DataTypeSynchronizer.getSyncStatus(handler, dataType);

	if (syncStatus == DataTypeSyncState.CONFLICT) {
		int result = OptionDialog.showOptionDialog(gTree, "Lose Changes in Archive?",
			"This data type has changes in the archive that will be\n" +
				"overwritten if you commit this data type",
			"Continue?", OptionDialog.WARNING_MESSAGE);
		if (result == OptionDialog.CANCEL_OPTION) {
			return;
		}
	}
	SourceArchive sourceArchive = dataType.getSourceArchive();
	DataTypeManager sourceDTM =
		plugin.getDataTypeManagerHandler().getDataTypeManager(sourceArchive);
	if (sourceDTM == null) {
		Msg.showInfo(getClass(), gTree, "Commit Failed",
			"Source Archive not open: " + sourceArchive.getName());
		return;
	}
	if (!sourceDTM.isUpdatable()) {
		DataTypeUtils.showUnmodifiableArchiveErrorMessage(gTree, "Commit Failed!", sourceDTM);
		return;
	}
	if (!dataType.getDataTypeManager().isUpdatable()) {
		DataTypeUtils.showUnmodifiableArchiveErrorMessage(gTree, "Commit Failed",
			dataType.getDataTypeManager());
		return;
	}
	plugin.commit(dataType);

	// Source archive data type manager was already checked for null above.
	DataTypeSynchronizer synchronizer = new DataTypeSynchronizer(handler, dtm, sourceArchive);
	synchronizer.reSyncOutOfSyncInTimeOnlyDataTypes();
}
 
Example 20
Source File: ProjectDataDeleteTask.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public void run(TaskMonitor monitor) {

	// Check all files directly given to this task
	if (!preprocessStartFilesAndFolders(monitor)) {
		return;
	}

	// If there are problems, ask the user what to do
	if (!failPreprocessReadOnly.isEmpty()) {
		int option = OptionDialog.showOptionDialog(parentComponent, "Delete Read-only Files?",
			"<html>There were " + failPreprocessReadOnly.size() +
				" read-only files found in the requested set of files.  Override the read-only status and delete?",
			"Delete Read-only Files", "Continue and Skip Read-only Files",
			OptionDialog.QUESTION_MESSAGE);
		switch (option) {
			case OptionDialog.OPTION_ONE:// Delete read-only files
				for (DomainFile f : failPreprocessReadOnly) {
					filesToDelete.put(f, null);
				}
				readOnlyOverride.addAll(failPreprocessReadOnly);
				failPreprocessReadOnly.clear();
				break;
			case OptionDialog.OPTION_TWO:// Continue and skip
				// nada
				break;
			case OptionDialog.CANCEL_OPTION:
				// stop delete task
				return;
		}
	}
	if (!failPreprocessCheckedOut.isEmpty()) {
		if (!confirmUserSkipFailedPreprocessedFiles()) {
			return;
		}
	}

	if (filesToDelete.isEmpty() && foldersToDelete.isEmpty()) {
		Msg.showInfo(this, parentComponent, "Delete finished", "Nothing to do, finished.");
		return;
	}

	if (!confirmDeleteFiles()) {
		return;
	}

	try {
		deleteFiles(monitor);
		deleteFolders(monitor);
	}
	catch (CancelledException ce) {
		Msg.info(this, "Canceled delete");
	}

	if (hasErrors()) {
		showErrorSummary(monitor.isCancelled());
	}
}