protected void importText() { if (!textEditor.isDisposed()) { FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Open"); String[] filterExt = { "*.txt;*.TXT" }; String[] filterNames = { "TXT files" }; fd.setFilterExtensions(filterExt); fd.setFilterNames(filterNames); String lastPath = Config.getInstance().getString(Config.LAST_OPEN_TEXT_PATH); if (lastPath != null && !lastPath.isEmpty()) fd.setFileName(lastPath); String selected = fd.open(); if (selected != null) { importTextFile(new File(selected)); Config.getInstance().putValue(Config.LAST_OPEN_TEXT_PATH, selected); try { Config.getInstance().save(); } catch (IOException e) { // The user do not NEED to know about this... } } } }
protected void updateFile () { final FileDialog dlg = new FileDialog ( getShell (), SWT.APPLICATION_MODAL | SWT.SAVE ); dlg.setFilterExtensions ( new String[] { Messages.FileSelectionPage_FilterExtension } ); dlg.setFilterNames ( new String[] { Messages.FileSelectionPage_FilterName } ); dlg.setOverwrite ( true ); dlg.setText ( Messages.FileSelectionPage_FileDialog_Text ); final String fileName = dlg.open (); if ( fileName == null ) { setFile ( null ); update (); } else { setFile ( new File ( fileName ) ); update (); } }
protected void openNewAudio() { FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Select the audio file"); String[] filterExt = { "*.wav;*.WAV;*.mp3;*.MP3", "*.*" }; String[] filterNames = { "WAV and MP3 files", "All files" }; fd.setFilterExtensions(filterExt); fd.setFilterNames(filterNames); String lastPath = Config.getInstance().getString(Config.LAST_OPEN_AUDIO_PATH); if (lastPath != null && lastPath.isEmpty()) fd.setFileName(lastPath); String selected = fd.open(); if (selected != null) { closePlayer(); openAudioFile(new File(selected)); Config.getInstance().putValue(Config.LAST_OPEN_AUDIO_PATH, selected); try { Config.getInstance().save(); } catch (IOException e) { // The user do not NEED to know about this... } } }
public void openTranscription() { if (!textEditor.isDisposed()) { FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Select the transcription file"); String[] filterExt = { "*.xpmt;*.XPMT" }; String[] filterNames = { "pmTrans transcription files" }; fd.setFilterExtensions(filterExt); fd.setFilterNames(filterNames); String lastPath = Config.getInstance().getString(Config.LAST_OPEN_TEXT_PATH); if (lastPath != null && !lastPath.isEmpty()) fd.setFileName(lastPath); String selected = fd.open(); if (selected != null) { openTranscriptionFile(new File(selected)); Config.getInstance().putValue(Config.LAST_OPEN_TEXT_PATH, selected); try { Config.getInstance().save(); } catch (IOException e) { // The user do not NEED to know about this... } } } }
protected void exportTextFile() { boolean done = false; while (!done) if (!textEditor.isDisposed()) { FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); fd.setFilterNames(new String[] { "Plain text file (*.txt)", "All Files (*.*)" }); fd.setFilterExtensions(new String[] { "*.txt", "*.*" }); String lastPath = Config.getInstance().getString(Config.LAST_EXPORT_TRANSCRIPTION_PATH); if (lastPath != null && !lastPath.isEmpty()) fd.setFileName(lastPath); String file = fd.open(); try { if (file != null) { Config.getInstance().putValue(Config.LAST_EXPORT_TRANSCRIPTION_PATH, file); File destFile = new File(file); boolean overwrite = true; if (destFile.exists()) overwrite = MessageDialog.openConfirm(shell, "Overwrite current file?", "Would you like to overwrite " + destFile.getName() + "?"); if (overwrite) { textEditor.exportText(new File(file)); done = true; } } else done = true; } catch (Exception e) { e.printStackTrace(); MessageBox diag = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK); diag.setMessage("Unable to export to file " + transcriptionFile.getPath()); diag.open(); } } }
protected void importTextFile(File f) { if (!textEditor.isDisposed()) { FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Import text"); fd.setFilterExtensions(new String[] { "*.txt;*.TXT" }); fd.setFilterNames(new String[] { "Plain text files (*.txt)" }); String selected = fd.open(); if (selected != null) { try { textEditor.importText(new File(selected)); } catch (IOException e) { e.printStackTrace(); MessageBox diag = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK); diag.setMessage("Unable to open file " + transcriptionFile.getPath()); diag.open(); } } } }
protected void selectFile () { final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN ); dlg.setFilterExtensions ( new String[] { "*.oscar", "*.json", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ dlg.setFilterNames ( new String[] { Messages.LocalDataPage_OSCARFilterDescription, Messages.LocalDataPage_JSONFilterDescription, Messages.LocalDataPage_AllFilterDescription } ); if ( this.fileName.getText ().length () > 0 ) { dlg.setFileName ( this.fileName.getText () ); } dlg.setFilterIndex ( 0 ); final String file = dlg.open (); if ( file != null ) { this.fileName.setText ( file ); loadFile (); } }
protected void handleLoadLocal () { final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN ); dlg.setFilterExtensions ( new String[] { "*.oscar", "*.json", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ dlg.setFilterNames ( new String[] { Messages.LocalDataPage_OSCARFilterDescription, Messages.LocalDataPage_JSONFilterDescription, Messages.LocalDataPage_AllFilterDescription } ); final String selectedFileName = getWizard ().getDialogSettings ().get ( "localDataPage.file" ); //$NON-NLS-1$ if ( selectedFileName != null && selectedFileName.length () > 0 ) { dlg.setFileName ( selectedFileName ); } dlg.setFilterIndex ( 0 ); final String file = dlg.open (); if ( file != null ) { getWizard ().getDialogSettings ().put ( "localDataPage.file", file ); //$NON-NLS-1$ loadFromLocalFile ( file ); } }
protected void handleSelectFile () { final FileDialog dlg = new FileDialog ( getShell (), SWT.SAVE ); dlg.setFilterExtensions ( new String[] { "*.oscar", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ dlg.setFilterNames ( new String[] { Messages.FileNamePage_OSCARFileType, Messages.FileNamePage_AllTypes } ); if ( this.fileName.getText ().length () > 0 ) { dlg.setFileName ( this.fileName.getText () ); } dlg.setFilterIndex ( 0 ); final String file = dlg.open (); if ( file != null ) { this.fileName.setText ( file ); getWizard ().getDialogSettings ().put ( "fileNamePage.file", file ); //$NON-NLS-1$ } }
protected void handleAdd () { final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN ); final String result = dlg.open (); if ( result != null ) { try { this.factory.addFile ( result ); } catch ( final Exception e ) { ErrorDialog.openError ( getShell (), "Error", "Failed to add file", StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ) ); } } }
protected void chooseFile () { final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN | SWT.MULTI ); dlg.setFilterExtensions ( new String[] { "*.xml", "*.*" } ); dlg.setFilterNames ( new String[] { "Eclipse NeoSCADA Exporter Files", "All files" } ); final String result = dlg.open (); if ( result != null ) { final File base = new File ( dlg.getFilterPath () ); for ( final String name : dlg.getFileNames () ) { this.fileText.setText ( new File ( base, name ).getAbsolutePath () ); } makeDirty (); } }
private static String getSaveFilePath(IEditorPart editorPart, GraphicalViewer viewer, int format) { FileDialog fileDialog = new FileDialog(editorPart.getEditorSite().getShell(), SWT.SAVE); String[] filterExtensions = new String[] { "*.jpeg", "*.bmp"/* * , "*.ico" , "*.png", "*.gif" */ }; if (format == SWT.IMAGE_BMP) filterExtensions = new String[] { "*.bmp" }; else if (format == SWT.IMAGE_JPEG) filterExtensions = new String[] { "*.jpeg" }; // else if (format == SWT.IMAGE_ICO) // filterExtensions = new String[] { "*.ico" }; fileDialog.setFilterExtensions(filterExtensions); return fileDialog.open(); }
/** * Handle SaveAs. */ protected void saveAs() { FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); fileDialog.setFilterPath(userPreferences.getSaveDirectory()); fileDialog.setFileName(Host.getFileName(disks[0].getFilename())); fileDialog.setText(textBundle.get("SaveDiskImageAsPrompt")); //$NON-NLS-1$ String fullpath = fileDialog.open(); userPreferences.setSaveDirectory(fileDialog.getFilterPath()); if (fullpath == null) { return; // user pressed cancel } try { disks[0].saveAs(fullpath); diskWindow.setStandardWindowTitle(); saveToolItem.setEnabled(disks[0].hasChanged()); } catch (IOException ex) { showSaveError(ex); } }
/** * Open the file dialog for the direct opening of a file. If a file is returned, * expand the directory tree accordingly. */ public void openFileDirectly() { FileDialog fileDialog = new FileDialog(this.shell, SWT.OPEN); String[] extensions = {"*.class", "*.jar", "*.war", "*.ear"}; String[] names = {"Class file (*.class)", "Jar archive (*.jar)", "War archive (*.war)", "Ear archive (*.ear)"}; fileDialog.setFilterExtensions(extensions); fileDialog.setFilterNames(names); String path = fileDialog.open(); if (path != null) { // First of all replace double backslashes against slashes. path = path.replace("\\\\", "\\"); // different handling of class and jar files if (JarFileEntry.isArchive(path) || (path.length() > 6 && path.substring(path.length() - 6).equals(".class"))) { // Browse through the directory tree. browseTroughTheDirectoryTree(path, null); } else { StaticGuiSupport.showMessageBox(FileSelectionComposite.this.shell, "Information", "This file cannot be processed.", SWT.OK | SWT.ICON_WARNING); } } }
@Override public void run() { ViewDataPreferencesVO viewDataPreferencesVO = debugDataViewer.getViewDataPreferences(); delimiter = viewDataPreferencesVO.getDelimiter(); quoteCharactor = viewDataPreferencesVO.getQuoteCharactor(); headerEnabled = viewDataPreferencesVO.getIncludeHeaders(); TableViewer tableViewer = debugDataViewer.getTableViewer(); List<RowData> eachRowData = getListOfRowData(tableViewer); List<String[]> exportedfileDataList = new ArrayList<String[]>(); TableColumn[] columns = tableViewer.getTable().getColumns(); if (headerEnabled != null) { addHeadersInList(tableViewer, exportedfileDataList, columns); } addRowsDataInList(tableViewer, eachRowData, exportedfileDataList); FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.SAVE); String filePath = getPathOfFileDialog(fileDialog); writeDataInFile(exportedfileDataList, filePath); }
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format. * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { FileDialog fileDialog = new FileDialog(canvas.getShell(), SWT.SAVE); String[] extensions = { "*.png" }; fileDialog.setFilterExtensions(extensions); String filename = fileDialog.open(); if (filename != null) { if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } //TODO replace getSize by getBounds ? ChartUtilities.saveChartAsPNG(new File(filename), this.chart, canvas.getSize().x, canvas.getSize().y); } }
public static void openTorrentTrackingOnly() { Utils.execSWTThread(new AERunnable() { @Override public void runSupport() { final Shell shell = Utils.findAnyShell(); if (shell == null) return; FileDialog fDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); fDialog.setFilterPath(getFilterPathTorrent()); fDialog .setFilterExtensions(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD }); fDialog.setFilterNames(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD }); fDialog.setText(MessageText.getString("MainWindow.dialog.choose.file")); String path = setFilterPathTorrent(fDialog.open()); if (path == null) return; TorrentOpener.openTorrentsForTracking(path, fDialog.getFileNames()); } }); }
public void exportBookList() { try { String ext = "*.csv"; String name = "CSV (Excel) File"; FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterNames(new String[]{name}); dialog.setFilterExtensions(new String[]{ext}); dialog.setFileName("books.csv"); String path = dialog.open(); if (path != null) { File f = new File(path); audibleGUI.audible.export(f); if (f.exists()) logger.info("exported books to: "+f.getAbsolutePath()); } } catch (Exception e) { MessageBoxFactory.showError(shell, e.getMessage()); } }
public void exportBookJSON() { try { String ext = "*.json"; String name = "JSON File"; FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterNames(new String[]{name}); dialog.setFilterExtensions(new String[]{ext}); dialog.setFileName("books.json"); String path = dialog.open(); if (path != null) { File f = new File(path); audibleGUI.audible.export(f); if (f.exists()) logger.info("exported books to: "+f.getAbsolutePath()); } } catch (Exception e) { MessageBoxFactory.showError(shell, e.getMessage()); } }
private void changeImage(boolean big){ NodeImageConfig currentNodeConfig=this.getCurrentNodeConfig(); if(currentNodeConfig==null)return; FileDialog dialog=new FileDialog(getShell()); if(big){ dialog.setText("请选择一张22*22px大小的png格式图标!"); }else{ dialog.setText("请选择一张16*16px大小的png格式图标!"); } dialog.setFilterExtensions(new String[]{"*.png"}); String fileName=dialog.open(); if(fileName==null){ return; } Image img=Activator.getImageFromLocal(fileName); if(big){ currentNodeConfig.setCustomImage(img); currentNodeConfig.setCustomImagePath(fileName); }else{ currentNodeConfig.setCustomSmallImage(img); currentNodeConfig.setCustomSmallImagePath(fileName); } tableViewer.refresh(); }
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format. * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { FileDialog fileDialog = new FileDialog(this.canvas.getShell(), SWT.SAVE); String[] extensions = {"*.png"}; fileDialog.setFilterExtensions(extensions); String filename = fileDialog.open(); if (filename != null) { if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } //TODO replace getSize by getBounds ? ChartUtilities.saveChartAsPNG(new File(filename), this.chart, this.canvas.getSize().x, this.canvas.getSize().y); } }
@Execute public void execute( @Optional @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Optional TerminologyService terminologyService, @Optional ETerminology terminology, @Optional IndexedCorpus indexedCorpus ) throws IOException { FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); fileDialog.setText("Exporting terminology "+ TerminologyPart.toPartLabel(terminology) +" to " + formatName); String path = fileDialog.open(); if(path != null) { if(withOptionDialog) { Dialog dialog = getDialog(shell); if(dialog.open() == Dialog.OK) export(shell, terminology, getExporter(dialog), indexedCorpus, path); } else // no option dialog export(shell, terminology, getExporter(), indexedCorpus, path); } }
private void browse() { final FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); String filename = fileDialog.open(); if (filename != null) { // If the filename has a space in it, put the filename in quotes. if (filename.indexOf(' ') > 0) { filename = "\"" + filename + "\""; //$NON-NLS-1$ //$NON-NLS-2$ } /* * If there's already a command string, just replace the first token * with the browse result. */ final String existingCommandAndArguments = commandText.getText(); if (existingCommandAndArguments.length() == 0) { commandText.setText(filename); } else { final String commandPart = WindowsStyleArgumentTokenizer.getRawFirstToken(existingCommandAndArguments); commandText.setText(filename + existingCommandAndArguments.substring(commandPart.length())); } } }
public static String promptForExportFile(final Shell shell) { final FileDialog dlg = new FileDialog(shell, SWT.SAVE); dlg.setFilterNames(new String[] { "*.zip" //$NON-NLS-1$ }); dlg.setFilterExtensions(new String[] { "*.zip" //$NON-NLS-1$ }); final SupportProvider supportProvider = SupportManager.getInstance().getSupportProviderCache().getSupportProvider(); if (supportProvider == null) { throw new IllegalStateException(); } final SimpleDateFormat dateFormat = new SimpleDateFormat(EXPORT_FILE_DATE_FORMAT); final String name = supportProvider.getExportFilenamePrefix() + dateFormat.format(new Date()) + ".zip"; //$NON-NLS-1$ dlg.setFileName(name); dlg.setText(Messages.getString("InternalSupportUtils.DialogTitle")); //$NON-NLS-1$ return dlg.open(); }
/** * @return */ protected String getNewJarZip() { final FileDialog dialog = new FileDialog(this.addJarZipButton.getShell()); if ((this.lastPath != null) && new File(this.lastPath).exists()) { dialog.setFilterPath(this.lastPath); } String file = dialog.open(); if (file != null) { file = file.trim(); if (file.length() == 0) { return null; } this.lastPath = new File(file).getAbsolutePath(); } return file; }
/** * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { PasswordSafeJFace app = PasswordSafeJFace.getApp(); FileDialog fod = new FileDialog(app.getShell(), SWT.OPEN); String fileName = fod.open(); if (fileName != null) { try { app.importFromText(fileName); } catch (Exception e) { app.displayErrorDialog( Messages.getString("ImportFromTextAction.ErrorDialog.Title"), Messages.getString("ImportFromTextAction.ErrorDialog.Message"), e); //$NON-NLS-1$ //$NON-NLS-2$ } } }
/** * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { PasswordSafeJFace app = PasswordSafeJFace.getApp(); FileDialog fod = new FileDialog(app.getShell(), SWT.OPEN); String fileName = fod.open(); if (fileName != null) { try { app.importFromXML(fileName); } catch (Exception e) { app.displayErrorDialog( Messages.getString("ImportFromXMLAction.ErrorDialog.Title"), Messages.getString("ImportFromXMLAction.ErrorDialog.Message"), e); //$NON-NLS-1$ //$NON-NLS-2$ } } }
/** * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { final PasswordSafeJFace app = PasswordSafeJFace.getApp(); PasswordDialog pw = new PasswordDialog(app.getShell()); pw.setVerified(false); StringBuilder password = pw.open(); if (password == null) return; // TODO: change pwsFile passphrase access to StringBuilder & use a // correct equals if (password.toString().equals(app.getPwsFile().getPassphrase())) { FileDialog fw = new FileDialog(app.getShell(), SWT.SAVE); String newFilename = fw.open(); if (newFilename != null) { app.exportToText(newFilename); } } else { app.setStatus(Messages.getString("ExportToTextAction.AbortedStatus")); //$NON-NLS-1$ log.warn("Aborted text export after wrong safe combination"); //$NON-NLS-1$ } }
public void widgetSelected( SelectionEvent event){ FileDialog fd = new FileDialog(st.getShell(), SWT.OPEN); fd.setText("Add File Parameter"); fd.setFilterExtensions(CoreConstants.FILE_FILTER_EXT); String file = fd.open(); if (file != null) { if (manager.isMultipart()) { st.setText(st.getText() + CoreConstants.FILE_PREFIX + file); } else { try { st.setText(readFileAsString(file)); } catch (IOException e) { // ignore } } // model.fireExecute(new ModelEvent(ModelEvent.BODY_FOCUS_LOST, // model)); // // force body to refresh itself // model.fireExecute(new ModelEvent(ModelEvent.PARAMS_FOCUS_LOST, // model)); } }
public void run(){ try { FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.SAVE); fileDialog.setFileName("http4e.jmx"); fileDialog.setFilterNames(new String[] { "JMeter File *.jmx (Run the script with \"jmeter-t.cmd\")" }); fileDialog.setFilterExtensions(new String[] { "*.jmx" }); fileDialog.setText("Save As JMeter script (Run the script with \"jmeter-t.cmd\")"); fileDialog.setFilterPath(getUserHomeDir()); String path = fileDialog.open(); if (path != null) { HdViewPart hdView = (HdViewPart) view; BaseUtils.writeJMX(path, hdView.getFolderView().getModel()); updateUserHomeDir(path); } } catch (Exception e) { ExceptionHandler.handle(e); } }
public void run(){ try { FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.SAVE); fileDialog.setFileName("sessions.http4e"); fileDialog.setFilterNames(new String[] { "HTTP4e File *.http4e (HTTP4e all tab sessions)" }); fileDialog.setFilterExtensions(new String[] { "*.http4e" }); fileDialog.setText("Save As HTTP4e replay script"); fileDialog.setFilterPath(getUserHomeDir()); String path = fileDialog.open(); if (path != null) { HdViewPart hdView = (HdViewPart) view; BaseUtils.writeHttp4eSessions(path, hdView.getFolderView().getModel()); updateUserHomeDir(path); } } catch (Exception e) { ExceptionHandler.handle(e); } }
public void hdlExportCsv() { if (model.resultData.getValue() == null || model.resultData.getValue().getRowCount() == 0) logging.Info("No data to export"); else { String delim = preferenceStore.getString(FtcPreferenceStore.KEY_CSV_DELIMITER); String quote = preferenceStore.getString(FtcPreferenceStore.KEY_CSV_QUOTECHAR); FileDialog dialog = new FileDialog(WorkbenchUtil.getShell(), SWT.SAVE); dialog.setFilterPath(preferenceStore.getString(FtcPreferenceStore.KEY_LAST_EXPORT_PATH)); dialog.setFilterNames(new String[] { "csv files", "All Files (*.*)" }); dialog.setFilterExtensions(new String[] { "*.csv", "*.*" }); String fullPath = dialog.open(); if (fullPath != null) { createCsv(delim, quote).write(model.resultData.getValue(), fullPath); preferenceStore.setValue(FtcPreferenceStore.KEY_LAST_EXPORT_PATH, new File(fullPath).getPath()); } } }
boolean saveText() { FileDialog fileDialog = new FileDialog(this, SWT.SAVE); if (lastDirectory != null) { fileDialog.setFilterPath(lastDirectory); } String selectedFile = fileDialog.open(); if (selectedFile == null) { System.out.println("File is not saved"); return false; } File file = new File(selectedFile); lastDirectory = file.getParent(); try { FileWriter writer = new FileWriter(file); writer.write(styledText.getText()); writer.close(); unsaved = false; return true; } catch (IOException e) { } return false; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); ImageView imageView = (ImageView) activePart; SWTImageCanvas imageCanvas = imageView.imageCanvas; if (imageCanvas == null) { return null; } Shell shell = HandlerUtil.getActiveShell(event); FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterExtensions(new String[] { "*.png", "*.*" }); dialog.setFilterNames(new String[] { "PNG Files", "All Files" }); String fileSelected = dialog.open(); if (fileSelected != null) { ImageLoader imageLoader = new ImageLoader(); imageLoader.data = new ImageData[] { imageCanvas.getImageData() }; System.out.println("Selected file: " + fileSelected); imageLoader.save(fileSelected, SWT.IMAGE_PNG); } return null; }
public boolean write(StyledText textArea, File file)// �˷����������ļ��л����п��ٱ����ļ� { File f = null; if (file == null) { FileDialog saveDialog = new FileDialog(black, SWT.SAVE); saveDialog.setFilterExtensions(filterExtensionsForSaveAs); saveDialog.open(); if (saveDialog.getFileName().length() > 0) { f = new File(saveDialog.getFilterPath() + "/" + saveDialog.getFileName()); // .setCurrentFileSaveLocation(fullScreenWord.getCurrentEditFile().getAbsolutePath()); } else { return false; } } else f = file; inputAndOutput(f, 1); return true; }
public void saveAllAsTextToOneFile() { if (b.fileindex.size() == 0) return; FileDialog fd = getFileDialog("����ΪTXT�ļ�", "", b, SWT.SAVE, new String[] { "*.txt" }); if (fd.getFileNames().length == 1) { File f = new File(fd.getFilterPath() + System.getProperty("file.separator") + fd.getFileName()); b.saveCurrentFile(false, false); findinfo_[] text = getAllTextFromProject(true, false); StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length; i++) { if (text[i].stringbuilder != null) sb.append(text[i].stringbuilder.toString()); } ioThread io = new ioThread(b); if (io.writeTextFile(f, sb.toString(), "utf-8")) getMessageBox("", "����ɹ�"); else getMessageBox("", "����ʧ��"); } }
public static ArrayList<String> showOpenFilesDialog(Shell shell, String title, String filterPath, String[] exts) { FileDialog fd = new FileDialog(shell, SWT.OPEN | SWT.MULTI); fd.setOverwrite(true); // prompt user if file exists! fd.setText(title); if (filterPath == null) filterPath = System.getProperty("user.dir"); fd.setFilterPath(filterPath); if (exts == null) exts = new String[]{"*.*"}; fd.setFilterExtensions(exts); ArrayList<String> files = new ArrayList<String>(); if (fd.open() != null) { String[] names = fd.getFileNames(); for (int i = 0, n = names.length; i < n; i++) { StringBuffer buf = new StringBuffer(fd.getFilterPath()); if (buf.charAt(buf.length() - 1) != File.separatorChar) buf.append(File.separatorChar); buf.append(names[i]); files.add(buf.toString()); } } System.out.println(files); return files; }
void menuOpenFile() { // Get the user to choose an image file. FileDialog fileChooser = new FileDialog(getShell(), SWT.OPEN); if (lastPath != null) { fileChooser.setFilterPath(lastPath); } fileChooser.setFilterExtensions(new String[] { "*.bmp; *.gif; *.ico; *.jpg; *.pcx; *.png; *.tif", "*.bmp", "*.gif", "*.ico", "*.jpg", "*.pcx", "*.png", "*.tif" }); fileChooser.setFilterNames(new String[] { ImageAnalyzer.bundle.getString("All_images") + " (bmp, gif, ico, jpg, pcx, png, tif)", "BMP (*.bmp)", "GIF (*.gif)", "ICO (*.ico)", "JPEG (*.jpg)", "PCX (*.pcx)", "PNG (*.png)", "TIFF (*.tif)" }); String filename = fileChooser.open(); lastPath = fileChooser.getFilterPath(); if (filename == null) { return; } menuOpenFile(filename); }