Java Code Examples for docking.widgets.filechooser.GhidraFileChooser#wasCancelled()
The following examples show how to use
docking.widgets.filechooser.GhidraFileChooser#wasCancelled() .
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: SaveImageAction.java From ghidra with Apache License 2.0 | 6 votes |
private static File getExportFile() { GhidraFileChooser chooser = new GhidraFileChooser(null); chooser.setTitle("Export Image As..."); chooser.setApproveButtonText("Save As"); chooser.setFileSelectionMode(GhidraFileChooserMode.FILES_ONLY); chooser.setMultiSelectionEnabled(false); File selected = chooser.getSelectedFile(true); if (chooser.wasCancelled()) { return null; } return selected; }
Example 2
Source File: ImportPatternFileActionListener.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { GhidraFileChooser fileChooser = new GhidraFileChooser(component); fileChooser.setFileSelectionMode(GhidraFileChooser.FILES_ONLY); fileChooser.setTitle("Select Pattern File"); String baseDir = Preferences.getProperty(XML_IMPORT_DIR_PROPERTY); if (baseDir != null) { fileChooser.setCurrentDirectory(new File(baseDir)); } ExtensionFileFilter xmlFilter = new ExtensionFileFilter("xml", "XML Files"); fileChooser.setFileFilter(xmlFilter); File patternFile = fileChooser.getSelectedFile(); if (fileChooser.wasCancelled() || patternFile == null) { return; } Preferences.setProperty(XML_IMPORT_DIR_PROPERTY, fileChooser.getCurrentDirectory().getAbsolutePath()); Preferences.store(); //only clear the patterns if new patterns are loaded from a file ResourceFile resource = new ResourceFile(patternFile); try { PatternPairSet pairSet = ClipboardPanel.parsePatternPairSet(resource); if (pairSet == null) { return; } plugin.clearPatterns(); for (DittedBitSequence pre : pairSet.getPreSequences()) { PatternInfoRowObject preRow = new PatternInfoRowObject(PatternType.PRE, pre, null); plugin.addPattern(preRow); } //post patterns can have alignment and context register restrictions processPostPatterns(pairSet); } catch (IOException | SAXException e1) { Msg.showError(this, component, "Import Error", "Error Importing file " + patternFile.getAbsolutePath(), e1); } plugin.updateClipboard(); }
Example 3
Source File: PdbSymbolServerPlugin.java From ghidra with Apache License 2.0 | 4 votes |
private File askForLocalStorageLocation() throws CancelledException { final GhidraFileChooser fileChooser = new GhidraFileChooser(tool.getActiveWindow()); // Need to store the variable in an array to allow the final variable to be reassigned. // Using an array prevents the compiler from warning about "The final local variable // cannot be assigned, since it is defined in an enclosing type." final File[] chosenDir = new File[1]; File testDirectory = null; // localDir is not null if we already parsed the _NT_SYMBOL_PATH environment var if (localDir != null) { testDirectory = localDir; } else { String userHome = System.getProperty("user.home"); String storedLocalDir = Preferences.getProperty(PdbParser.PDB_STORAGE_PROPERTY, userHome, true); testDirectory = new File(storedLocalDir); if (!testDirectory.exists()) { testDirectory = new File(userHome); } } final File storedDirectory = testDirectory; Runnable r = () -> { while (chosenDir[0] == null && !fileChooser.wasCancelled()) { fileChooser.setSelectedFile(storedDirectory); fileChooser.setTitle("Select Location to Save Retrieved File"); fileChooser.setApproveButtonText("OK"); fileChooser.setFileSelectionMode(GhidraFileChooserMode.DIRECTORIES_ONLY); chosenDir[0] = fileChooser.getSelectedFile(); if (chosenDir[0] != null) { if (!chosenDir[0].exists()) { Msg.showInfo(getClass(), null, "Directory does not exist", "The directory '" + chosenDir[0].getAbsolutePath() + "' does not exist. Please create it or choose a valid directory."); chosenDir[0] = null; } else if (chosenDir[0].isFile()) { Msg.showInfo(getClass(), null, "Invalid Directory", "The location '" + chosenDir[0].getAbsolutePath() + "' represents a file, not a directory. Please choose a directory."); chosenDir[0] = null; } } } }; SystemUtilities.runSwingNow(r); if (fileChooser.wasCancelled()) { throw new CancelledException(); } Preferences.setProperty(PdbParser.PDB_STORAGE_PROPERTY, chosenDir[0].getAbsolutePath()); return chosenDir[0]; }
Example 4
Source File: ExportPatternFileActionListener.java From ghidra with Apache License 2.0 | 4 votes |
@Override public void actionPerformed(ActionEvent e) { List<PatternInfoRowObject> selected = clipboardPanel.getLastSelectedObjects(); if (selected.isEmpty()) { return; } //scan through all of them: must be at least one pre-pattern and //at least one post-pattern boolean containsPostPattern = false; boolean containsPrePattern = false; for (PatternInfoRowObject row : selected) { if (row.getPatternType().equals(PatternType.FIRST)) { containsPostPattern = true; } if (row.getPatternType().equals(PatternType.PRE)) { containsPrePattern = true; } } if (!containsPostPattern) { Msg.showWarn(this, component, "No Post Pattern", "Selected patterns must contain at least one post pattern"); return; } if (!containsPrePattern) { Msg.showWarn(this, component, "No Pre Pattern", "Selected patterns must contain at least one pre pattern"); return; } boolean proceed = checkConsistencyForExport(selected); if (!proceed) { return; } GhidraFileChooser gFileChooser = new GhidraFileChooser(component); gFileChooser.setFileSelectionMode(GhidraFileChooser.FILES_ONLY); ExtensionFileFilter xmlFilter = new ExtensionFileFilter("xml", "XML Files"); gFileChooser.setFileFilter(xmlFilter); String baseDir = Preferences.getProperty(XML_EXPORT_DIR_PROPERTY); if (baseDir != null) { gFileChooser.setCurrentDirectory(new File(baseDir)); } gFileChooser.setTitle("Select Export File"); File outFile = gFileChooser.getSelectedFile(); if (gFileChooser.wasCancelled() || outFile == null) { return; } Preferences.setProperty(XML_EXPORT_DIR_PROPERTY, gFileChooser.getCurrentDirectory().getAbsolutePath()); Preferences.store(); BitsInputDialogComponentProvider bitsProvider = new BitsInputDialogComponentProvider(BITS_PROVIDER_MESSAGE); if (bitsProvider.isCanceled()) { return; } int totalBits = bitsProvider.getTotalBits(); int postBits = bitsProvider.getPostBits(); try { PatternInfoRowObject.exportXMLFile(selected, outFile, postBits, totalBits); } catch (IOException e1) { Msg.showError(this, component, "IO Error", "IO error exporting pattern xml file", e1); e1.printStackTrace(); } }