Java Code Examples for docking.widgets.OptionDialog#showYesNoDialog()

The following examples show how to use docking.widgets.OptionDialog#showYesNoDialog() . 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: RemoveMatchTagAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void removeTag(ActionContext context) {
	VTMatchContext matchContext = (VTMatchContext) context;

	ComponentProvider componentProvider = matchContext.getComponentProvider();
	JComponent component = componentProvider.getComponent();

	String message = "1 tag?";
	if (tagCount > 1) {
		message = tagCount + " tags?";
	}

	int choice =
		OptionDialog.showYesNoDialog(component, "Remove Match Tag?", "Remove " + message);
	if (choice == OptionDialog.NO_OPTION) {
		return;
	}

	List<VTMatch> matches = matchContext.getSelectedMatches();
	ClearMatchTagTask task = new ClearMatchTagTask(matchContext.getSession(), matches);
	new TaskLauncher(task, component);
}
 
Example 2
Source File: InterpreterComponentProvider.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Overridden so that we can add our custom actions for transient tools.
 */
@Override
public void setTransient() {
	DockingAction disposeAction = new DockingAction("Remove Interpreter", getName()) {
		@Override
		public void actionPerformed(ActionContext context) {
			int choice = OptionDialog.showYesNoDialog(panel, "Remove Interpreter?",
				"Are you sure you want to permanently close the interpreter?");
			if (choice == OptionDialog.NO_OPTION) {
				return;
			}

			InterpreterComponentProvider.this.dispose();
		}
	};
	disposeAction.setDescription("Remove interpreter from tool");
	disposeAction.setToolBarData(new ToolBarData(Icons.STOP_ICON, null));
	disposeAction.setEnabled(true);

	addLocalAction(disposeAction);
}
 
Example 3
Source File: TaskMonitorComponent.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param includeTextField if true, the dialog can display a status progressMessage with progress details
 * @param includeCancelButton if true, a cancel button will be displayed 
 */
public TaskMonitorComponent(boolean includeTextField, boolean includeCancelButton) {
	updateProgressPanelRunnable = () -> updateProgressPanel();
	updateCancelButtonRunnable = () -> updateCancelButton();
	updateToolTipRunnable = () -> updateToolTip();
	updateTimer = new Timer(250, e -> update());
	updateTimer.setRepeats(false);

	shouldCancelRunnable = () -> {
		int currentTaskID = taskID.get();

		boolean userSaysYes = OptionDialog.showYesNoDialog(TaskMonitorComponent.this, "Cancel?",
			"Do you really want to cancel " + getTaskName() + "?") == OptionDialog.OPTION_ONE;

		if (userSaysYes && currentTaskID == taskID.get()) {
			cancel();
		}
	};

	buildProgressPanel(includeTextField, includeCancelButton);
}
 
Example 4
Source File: TextEditorManagerPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public boolean removeTextFile(TextEditorComponentProvider editor, String textFileName) {
       if ( editor.isChanged() ) {
           JComponent parentComponent = editor.getComponent();
           if ( tool.isVisible( editor ) ) {
           	parentComponent = editor.getComponent();
           }
		int result = OptionDialog.showYesNoDialog( parentComponent, getName(),
       					"'"+textFileName+"' has been modified. Discard changes?");
           if (result != OptionDialog.OPTION_ONE) {
               return false;
           }
       }
       tool.removeComponentProvider( editor );
       editors.remove( editor );
       return true;
}
 
Example 5
Source File: EditExternalLocationPanel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private boolean validLocationName() {
	// Will this generate a duplicate name conflict?
	String extLibName = getExtLibName();
	if (extLibName == null || extLibName.length() == 0) {
		return true; // Any name is considered valid until we have a external library for it.
	}
	String locationName = getLocationName();
	if (locationName != null && locationName.length() > 0) {
		ExternalManager externalManager = program.getExternalManager();
		List<ExternalLocation> externalLocations =
			externalManager.getExternalLocations(extLibName, locationName);
		externalLocations.remove(externalLocation);
		if (!externalLocations.isEmpty()) {
			int result = OptionDialog.showYesNoDialog(null, "Duplicate External Name",
				"Another symbol named '" + locationName + "' already exists in the '" +
					extLibName + "' library. Are you sure you want to create another?");
			if (result == OptionDialog.NO_OPTION) {
				selectLocationName();
				return false;
			}
		}
	}
	return true;
}
 
Example 6
Source File: AutoAnalysisManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
boolean askToAnalyze(PluginTool tool) {
	if (program == null) {
		return false;
	}
	//if program has just been instantiated, then we can analyze it.
	if (!program.canSave() && !program.isChanged()) {
		return false;
	}
	if (GhidraProgramUtilities.shouldAskToAnalyze(program)) {
		int answer = OptionDialog.showYesNoDialog(tool.getToolFrame(), "Analyze",
			"<html>" + HTMLUtilities.escapeHTML(program.getDomainFile().getName()) +
				" has not been analyzed. Would you like to analyze it now?");
		boolean analyzed = answer == OptionDialog.OPTION_ONE;
		GhidraProgramUtilities.setAnalyzedFlag(program, analyzed);
		return analyzed;
	}
	return false;
}
 
Example 7
Source File: GFileSystemExtractAllTask.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private boolean verifyRootOutputDir(String destDirName) {
	boolean isSameName = destDirName.equals(rootOutputDirectory.getName());
	File newRootOutputDir =
		isSameName ? rootOutputDirectory : new File(rootOutputDirectory, destDirName);
	if (newRootOutputDir.isFile()) {
		Msg.showError(this, parentComponent, "Export Destination Error",
			"Unable to export to " + newRootOutputDir + " as it is a file");
		return false;
	}
	if (newRootOutputDir.exists() && newRootOutputDir.list().length > 0) {
		int answer = OptionDialog.showYesNoDialog(parentComponent, "Verify Export Destination",
			newRootOutputDir.getAbsolutePath() + "\n" + "The directory is not empty." + "\n" +
				"Do you want to overwrite the contents?");
		if (answer == OptionDialog.NO_OPTION) {
			return false;
		}
	}
	rootOutputDirectory = newRootOutputDir;
	return true;
}
 
Example 8
Source File: UnpackageAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	// If lots of components, verify the user really wants to unpackage.
	int currentRowIndex =
		model.getSelection().getFieldRange(0).getStart().getIndex().intValue();
	int subComps = model.getNumSubComponents(currentRowIndex);
	if (subComps > 1000) {
		String question = "Are you sure you want to unpackage " + subComps + " components?";
		String title = "Continue with unpackage?";
		int response =
			OptionDialog.showYesNoDialog(model.getProvider().getComponent(), title, question);
		if (response != 1) { // User did not select yes.
			return;
		}
	}

	TaskLauncher.launchModal("Unpackaging Component",
		monitor -> doUnpackage(currentRowIndex, monitor));

	requestTableFocus();
}
 
Example 9
Source File: DebugDecompilerAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected void decompilerActionPerformed(DecompilerActionContext context) {
	JComponent parentComponent = context.getDecompilerPanel();
	GhidraFileChooser fileChooser = new GhidraFileChooser(parentComponent);
	fileChooser.setTitle("Please Choose Output File");
	fileChooser.setFileFilter(new ExtensionFileFilter(new String[] { "xml" }, "XML Files"));
	File file = fileChooser.getSelectedFile();
	if (file == null) {
		return;
	}
	if (file.exists()) {
		if (OptionDialog.showYesNoDialog(parentComponent, "Overwrite Existing File?",
			"Do you want to overwrite the existing file?") == OptionDialog.OPTION_TWO) {
			return;
		}
	}
	controller.setStatusMessage("Dumping debug info to " + file.getAbsolutePath());
	controller.refreshDisplay(controller.getProgram(), controller.getLocation(), file);
}
 
Example 10
Source File: FSUtilities.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static void displayCryptoException(Object originator, Component parent, String title,
		String message, CryptoException ce) {
	String ce_msg = ce.getMessage();
	if (ce_msg.contains("Install the JCE")) {
		File javaHomeDir = new File(System.getProperty("java.home"));
		File libSecurityDir = new File(new File(javaHomeDir, "lib"), "security");
		//@formatter:off
			if (OptionDialog.showYesNoDialog(parent, title,
				"<html><div style='margin-bottom: 20pt'>A problem with the Java crypto subsystem was encountered:</div>" +
					"<div style='font-weight: bold; margin-bottom: 20pt; margin-left: 50pt'>" + ce_msg + "</div>" +
					"<div style='margin-bottom: 20pt'>Which caused:</div>" +
					"<div style='font-weight: bold; margin-bottom: 20pt; margin-left: 50pt'>" + message + "</div>" +
					"<div style='margin-bottom: 20pt'>This may be fixed by installing the unlimited strength JCE into your JRE's \"lib/security\" directory.</div>" +
					"<div style='margin-bottom: 20pt'>The unlimited strength JCE should be available from the same download location as your JRE.</div>" +
					"<div>Display your JRE's \"lib/security\" directory?</div></html>") == OptionDialog.YES_OPTION) {
			//@formatter:on
			try {
				FileUtilities.openNative(libSecurityDir);
			}
			catch (IOException e) {
				Msg.showError(originator, parent, "Problem starting explorer",
					"Problem starting file explorer: " + e.getMessage());
			}
		}
		return;
	}
	Msg.showWarn(originator, parent, title, message + ": " + ce_msg);
}
 
Example 11
Source File: AnalysisPanel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void restoreDefaults() {
	int answer = OptionDialog.showYesNoDialog(this, "Restore Default Analysis Options",
		"Do you really want to restore the analysis options to the default values?");
	if (answer == OptionDialog.YES_OPTION) {
		AutoAnalysisManager manager = AutoAnalysisManager.getAnalysisManager(programs.get(0));
		manager.restoreDefaultOptions();
		editorStateFactory.clearAll();
		load();
	}
}
 
Example 12
Source File: ExportToCAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void decompilerActionPerformed(DecompilerActionContext context) {

	File file = getFile(context.getDecompilerPanel());
	if (file == null) {
		return;
	}

	if (file.exists()) {
		if (OptionDialog.showYesNoDialog(context.getDecompilerPanel(),
			"Overwrite Existing File?",
			"Do you want to overwrite the existing file?") == OptionDialog.OPTION_TWO) {
			return;
		}
	}

	try {
		PrintWriter writer = new PrintWriter(new FileOutputStream(file));
		ClangTokenGroup grp = context.getCCodeModel();
		PrettyPrinter printer = new PrettyPrinter(context.getFunction(), grp);
		DecompiledFunction decompFunc = printer.print(true);
		writer.write(decompFunc.getC());
		writer.close();
		context.setStatusMessage(
			"Successfully exported function(s) to " + file.getAbsolutePath());
	}
	catch (IOException e) {
		Msg.showError(getClass(), context.getDecompilerPanel(), "Export to C Failed",
			"Error exporting to C: " + e);
	}
}
 
Example 13
Source File: DisassociateDataTypeAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean confirmOperation(List<DataTypeNode> nodes) {
	String message = "This will <b>permanently</b> disassociate these datatypes" +
		" from the archive.<br><br>Are you sure you want to <b><u>disassociate</u></b> " +
		nodes.size() + " datatype(s)?";
	String asHtml = HTMLUtilities.wrapAsHTML(message);
	int result = OptionDialog.showYesNoDialog(plugin.getTool().getToolFrame(),
		"Confirm Disassociate", asHtml);
	return result == OptionDialog.YES_OPTION;
}
 
Example 14
Source File: FileFormatsPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a crypto key file template based on the specified files under the GTree node.
 *
 * @param fsrl FSRL of a child file of the container that the crypto will be associated with
 * @param node GTree node with children that will be iterated
 */
private void createCryptoTemplate(FSRL fsrl, FSBRootNode node) {
	try {
		String fsContainerName = fsrl.getFS().getContainer().getName();
		CryptoKeyFileTemplateWriter writer = new CryptoKeyFileTemplateWriter(fsContainerName);
		if (writer.exists()) {
			int answer = OptionDialog.showYesNoDialog(getTool().getActiveWindow(),
				"WARNING!! Crypto Key File Already Exists",
				"WARNING!!" + "\n" + "The crypto key file already exists. " +
					"Are you really sure that you want to overwrite it?");
			if (answer == OptionDialog.NO_OPTION) {
				return;
			}
		}
		writer.open();
		try {
			// gTree.expandAll( node );
			writeFile(writer, node.getChildren());
		}
		finally {
			writer.close();
		}
	}
	catch (IOException e) {
		FSUtilities.displayException(this, getTool().getActiveWindow(),
			"Error writing crypt key file", e.getMessage(), e);
	}

}
 
Example 15
Source File: GhidraScriptComponentProvider.java    From ghidra with Apache License 2.0 5 votes vote down vote up
void deleteScript() {
	ResourceFile script = getSelectedScript();
	if (script == null) {
		return;
	}
	ResourceFile directory = script.getParentFile();

	Path path = GhidraScriptUtil.getScriptPath(directory);
	if (path == null || path.isReadOnly()) {
		Msg.showWarn(getClass(), getComponent(), getName(),
			"Unable to delete scripts in '" + directory + "'.");
		return;
	}

	int result = OptionDialog.showYesNoDialog(getComponent(), getName(),
		"Are you sure you want to delete script '" + script.getName() + "'?");
	if (result == OptionDialog.OPTION_ONE) {
		if (removeScript(script)) {
			GhidraScriptProvider provider = GhidraScriptUtil.getProvider(script);
			if (provider.deleteScript(script)) {
				restoreSelection(script);
			}
			else {
				Msg.showInfo(getClass(), getComponent(), getName(),
					"Unable to delete script '" + script.getName() + "'" + "\n" +
						"Please verify the file permissions.");
			}
		}
	}
}
 
Example 16
Source File: GhidraTool.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Looks for extensions that have been installed since the last time this tool
 * was launched. If any are found, and if those extensions contain plugins, the user is
 * notified and given the chance to install them.
 *
 */
public void checkForNewExtensions() {

	// 1. First remove any extensions that are in the tool preferences that are no longer
	//    installed. This will happen if the user installs an extension, launches
	//    a tool, then uninstalls the extension.
	removeUninstalledExtensions();

	// 2. Now figure out which extensions have been added.
	Set<ExtensionDetails> newExtensions =
		ExtensionUtils.getExtensionsInstalledSinceLastToolLaunch(this);

	// 3. Get a list of all plugins contained in those extensions. If there are none, then
	//    either none of the extensions has any plugins, or Ghidra hasn't been restarted since
	//    installing the extension(s), so none of the plugin classes have been loaded. In
	//    either case, there is nothing more to do.
	List<Class<?>> newPlugins = PluginUtils.findLoadedPlugins(newExtensions);
	if (newPlugins.isEmpty()) {
		return;
	}

	// 4. Notify the user there are new plugins.
	int option = OptionDialog.showYesNoDialog(getActiveWindow(), "New Plugins Found!",
		"New extension plugins detected. Would you like to configure them?");
	if (option == OptionDialog.YES_OPTION) {
		List<PluginDescription> pluginDescriptions =
			PluginUtils.getPluginDescriptions(this, newPlugins);
		PluginInstallerDialog pluginInstaller =
			new PluginInstallerDialog("New Plugins Found!", this, pluginDescriptions);
		showDialog(pluginInstaller);
	}

	// 5. Update the preference file to reflect the new extensions now known to this tool.
	addInstalledExtensions(newExtensions);
}
 
Example 17
Source File: MemoryMapModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void revertBlockToUnitialized(MemoryBlock block) {
	int result = OptionDialog.showYesNoDialog(provider.getComponent(),
		"Confirm Setting Block To Unitialized",
		"Are you sure you want to remove the bytes from this block? \n\n" +
			"This will result in removing all functions, instructions, data,\n" +
			"and outgoing references from the block!");

	if (result == OptionDialog.NO_OPTION) {
		return;
	}
	UninitializedBlockCmd cmd = new UninitializedBlockCmd(program, block);
	provider.getTool().executeBackgroundCommand(cmd, program);
}
 
Example 18
Source File: GhidraScriptEditorComponentProvider.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private boolean saveAs() {
	HelpLocation help = new HelpLocation(plugin.getName(), saveAction.getName());
	SaveDialog dialog =
		new SaveDialog(getComponent(), "Save Script", provider, scriptSourceFile, help);
	if (dialog.isCancelled()) {
		return false;
	}

	ResourceFile saveAsFile = dialog.getFile();
	boolean exists = saveAsFile.exists();
	if (exists) {
		int result = OptionDialog.showYesNoDialog(getComponent(), getName(),
			"Do you want to OVERWRITE the following script:\n" + saveAsFile.getName());
		if (result != OptionDialog.OPTION_ONE) {
			return false;
		}
	}

	provider.checkNewScriptDirectoryEnablement(saveAsFile);

	try {
		String str = textArea.getText();
		str = str.replaceAll(GhidraScriptUtil.getBaseName(scriptSourceFile),
			GhidraScriptUtil.getBaseName(saveAsFile));
		textArea.setText(str);

		PrintWriter writer = new PrintWriter(new FileWriter(saveAsFile.getFile(false)));
		writer.print(str);
		writer.close();

		provider.switchEditor(scriptSourceFile, saveAsFile);
		scriptSourceFile = saveAsFile;

		title = saveAsFile.getName();

		clearChanges();

		provider.sortScripts();
		return true;
	}
	catch (IOException e) {
		Msg.showError(getClass(), getComponent(), "Error saving as script", e.getMessage());
		return false;
	}
}
 
Example 19
Source File: PdbSymbolServerPlugin.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void tryToLoadPdb(File downloadedPdb, Program currentProgram) {

		// Only ask to load PDB if file type is applicable for current OS
		if (fileType == PdbFileType.PDB && !PdbParser.onWindows) {
			return;
		}

		String htmlString =
			HTMLUtilities.toWrappedHTML("Would you like to apply the following PDB:\n\n" +
				downloadedPdb.getAbsolutePath() + "\n\n to " + currentProgram.getName() + "?");

		int response = OptionDialog.showYesNoDialog(null, "Load PDB?", htmlString);

		switch (response) {
			case 0:
				// User cancelled
				return;

			case 1:
				// Yes -- do nothing here
				break;

			case 2:
				// No
				return;

			default:
				// do nothing
		}

		tool.setStatusInfo("");

		try {
			DataTypeManagerService service = tool.getService(DataTypeManagerService.class);
			if (service == null) {
				Msg.showWarn(getClass(), null, "Load PDB",
					"Unable to locate DataTypeService in the current tool.");
				return;
			}

			TaskLauncher.launch(new LoadPdbTask(currentProgram, downloadedPdb, service));
		}
		catch (Exception pe) {
			Msg.showError(getClass(), null, "Error", pe.getMessage());
		}
	}
 
Example 20
Source File: SyncAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private boolean confirmOperation(List<DataTypeSyncInfo> selectedList) {
	int result = OptionDialog.showYesNoDialog(plugin.getTool().getToolFrame(),
		"Confirm " + getOperationName(), getConfirmationMessage(selectedList));
	return result == OptionDialog.YES_OPTION;
}