📄 filemenu.java
字号:
doneOpeningLibrary(showThisCell); if (type == FileType.DAIS) { long endTime = System.currentTimeMillis(); float finalTime = (endTime - startTime) / 1000F; long end = com.sun.electric.Main.getMemoryUsage(); long amt = (end-startMemory)/1024/1024; System.out.println("*** DAIS INPUT TOOK " + finalTime + " seconds, " + amt + " megabytes"); } } } /** * Method to clean up from opening a library. * Called from the "terminateOK()" method of a job. */ private static void doneOpeningLibrary(final Cell cell) { if (cell == null) System.out.println("No current cell in this library"); else if (!Job.BATCHMODE) { CreateCellWindow creator = new CreateCellWindow(cell); if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(creator); } else { creator.run(); } } SwingUtilities.invokeLater(new Runnable() { public void run() { // Redo explorer trees to add new library WindowFrame.wantToRedoLibraryTree(); WindowFrame.wantToOpenCurrentLibrary(true, cell); }}); } /** * Class to display a new window. */ public static class CreateCellWindow implements Runnable { private Cell cell; public CreateCellWindow(Cell cell) { this.cell = cell; } public void run() { // check if edit window open with null cell, use that one if exists for (Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); WindowContent content = wf.getContent(); if (content.getCell() == null) { wf.setCellWindow(cell, null); //wf.requestFocus(); ToolBar.setSaveLibraryButton(); return; } } WindowFrame.createEditWindow(cell); // no clean for now. ToolBar.setSaveLibraryButton(); } } /** * This method implements the command to import a file to a library * It is interactive, and pops up a dialog box. */ public static void importToCurrentCellCommand(FileType type) { String fileName = null; if (type == FileType.DAIS) { fileName = OpenFile.chooseDirectory(type.getDescription()); } else { fileName = OpenFile.chooseInputFile(type, null); } if (fileName != null) { // start a job to do the input URL fileURL = TextUtils.makeURLToFile(fileName); //import to the current library new ImportLibrary(fileURL, type); } } /** * This method implements the command to import a library (Readable Dump or JELIB format). * It is interactive, and pops up a dialog box. */ public static void importLibraryCommand(FileType type) { String fileName = null; if (type == FileType.DAIS) { fileName = OpenFile.chooseDirectory(type.getDescription()); } else { fileName = OpenFile.chooseInputFile(type, null); } if (fileName != null) { // start a job to do the input URL fileURL = TextUtils.makeURLToFile(fileName); String libName = TextUtils.getFileNameWithoutExtension(fileURL); Library deleteLib = Library.findLibrary(libName); RenameAndSaveLibraryTask saveTask = null; if (deleteLib != null) { // library already exists, prompt for save Collection<RenameAndSaveLibraryTask> librariesToSave = preventLoss(deleteLib, 2); if (librariesToSave == null) return; if (!librariesToSave.isEmpty()) { assert librariesToSave.size() == 1; saveTask = librariesToSave.iterator().next(); assert saveTask.lib == deleteLib; } WindowFrame.removeLibraryReferences(deleteLib); } if (type == FileType.ELIB || type == FileType.READABLEDUMP) new ReadLibrary(fileURL, type, null, deleteLib, saveTask, null); else new ImportLibrary(fileURL, type, deleteLib, saveTask); } } public static void closeLibraryCommand(Library lib) { if (lib == null) return; Set<Cell> found = Library.findReferenceInCell(lib); // if all references are from the clipboard, request that the clipboard be cleared, too boolean clearClipboard = false, nonClipboard = false; for (Cell cell : found) { if (cell.getLibrary().isHidden()) clearClipboard = true; else nonClipboard = true; } // You can't close it because there are open cells that refer to library elements if (nonClipboard) { System.out.println("Cannot close " + lib + ":"); System.out.print("\t Cells "); for (Cell cell : found) { System.out.print("'" + cell.getName() + "'(" + cell.getLibrary().getName() + ") "); } System.out.println("refer to it."); return; } RenameAndSaveLibraryTask saveTask = null; Collection<RenameAndSaveLibraryTask> librariesToSave = preventLoss(lib, 1); if (librariesToSave == null) return; if (!librariesToSave.isEmpty()) { assert librariesToSave.size() == 1; saveTask = librariesToSave.iterator().next(); assert saveTask.lib == lib; } WindowFrame.removeLibraryReferences(lib); new CloseLibrary(lib, saveTask, clearClipboard); } private static class CloseLibrary extends Job { private Library lib; private RenameAndSaveLibraryTask saveTask; private boolean clearClipboard; public CloseLibrary(Library lib, RenameAndSaveLibraryTask saveTask, boolean clearClipboard) { super("Close "+lib, User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.lib = lib; this.saveTask = saveTask; this.clearClipboard = clearClipboard; startJob(); } public boolean doIt() throws JobException { if (clearClipboard) { Clipboard.clear(); } // save the library if (saveTask != null) { assert lib == saveTask.lib; saveTask.renameAndSave(); lib = saveTask.lib; } if (lib.kill("delete")) { System.out.println("Library '" + lib.getName() + "' closed"); } return true; } public void terminateOK() { // set some other library to be current if (Library.getCurrent() == null) { List<Library> remainingLibs = Library.getVisibleLibraries(); if (remainingLibs.size() > 0) User.setCurrentLibrary(remainingLibs.get(0)); } WindowFrame.wantToRedoTitleNames(); EditWindow.repaintAll(); // Disable save icon if no more libraries are open ToolBar.setSaveLibraryButton(); } } /** * This method implements the command to save a library. * It is interactive, and pops up a dialog box. * @param lib the Library to save. * @return true if library saved, false otherwise. */ public static boolean saveLibraryCommand(Library lib) { return lib != null && saveLibraryCommand(lib, FileType.DEFAULTLIB, false, true, false); } /** * This method implements the command to save a library. * It is interactive, and pops up a dialog box. * @param lib the Library to save. * @param type the format of the library (OpenFile.Type.ELIB, OpenFile.Type.READABLEDUMP, or OpenFile.Type.JELIB). * @param compatibleWith6 true to write a library that is compatible with version 6 Electric. * @param forceToType * @param saveAs true if this is a "save as" and should always prompt for a file name. * @return true if library saved, false otherwise. */ public static boolean saveLibraryCommand(Library lib, FileType type, boolean compatibleWith6, boolean forceToType, boolean saveAs) { RenameAndSaveLibraryTask task = saveLibraryRequest(lib, type, compatibleWith6, forceToType, saveAs); if (task == null) return false; // save the library new SaveLibrary(task); return true; } /** * This method ask user anout details to save a library. * It is interactive, and pops up a dialog box. * @param lib the Library to save. * @param type the format of the library (OpenFile.Type.ELIB, OpenFile.Type.READABLEDUMP, or OpenFile.Type.JELIB). * @param compatibleWith6 true to write a library that is compatible with version 6 Electric. * @param forceToType * @param saveAs true if this is a "save as" and should always prompt for a file name. * @return save details if library saved, null otherwise. */ public static RenameAndSaveLibraryTask saveLibraryRequest(Library lib, FileType type, boolean compatibleWith6, boolean forceToType, boolean saveAs) { // scan for Dummy Cells, warn user that they still exist List<String> dummyCells = new ArrayList<String>(); dummyCells.add("WARNING: "+lib+" contains the following Dummy cells:"); for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell c = it.next(); if (c.getVar(LibraryFiles.IO_DUMMY_OBJECT) != null) { dummyCells.add(" "+c.noLibDescribe()); } } if (dummyCells.size() > 1) { dummyCells.add("Do you really want to write this library?"); String [] options = {"Continue Writing", "Cancel" }; String message = dummyCells.toString(); int val = Job.getUserInterface().askForChoice(message, "Dummy Cells Found in "+lib, options, options[1]); if (val == 1) return null; } String [] extensions = type.getExtensions(); String extension = extensions[0]; String fileName = null; if (!saveAs && lib.isFromDisk()) { if (type == FileType.JELIB || type == FileType.DELIB || (type == FileType.ELIB && !compatibleWith6)) { fileName = lib.getLibFile().getPath(); if (forceToType) { type = OpenFile.getOpenFileType(fileName, FileType.DEFAULTLIB); } } // check to see that file is writable if (fileName != null) { File file = new File(fileName); if (file.exists() && !file.canWrite()) fileName = null;/* try { if (!file.createNewFile()) fileName = null; } catch (java.io.IOException e) { System.out.println(e.getMessage()); fileName = null; }*/ } } if (fileName == null) { fileName = OpenFile.chooseOutputFile(FileType.libraryTypes, null, lib.getName() + "." + extension); if (fileName == null) return null; type = getLibraryFormat(fileName, type); } return new RenameAndSaveLibraryTask(lib, fileName, type, compatibleWith6); } private static void saveOldJelib() { String currentDir = User.getWorkingDirectory(); System.out.println("Saving libraries in oldJelib directory under " + currentDir); System.out.flush(); File oldJelibDir = new File(currentDir, "oldJelib"); if (!oldJelibDir.exists() && !oldJelibDir.mkdir()) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), new String [] {"Could not create oldJelib directory", oldJelibDir.getAbsolutePath()}, "Error creating oldJelib directory", JOptionPane.ERROR_MESSAGE); return; } Output.writePanicSnapshot(EDatabase.clientDatabase().backupUnsafe(), oldJelibDir, true); } /** * Class to save a library in a new thread. * For a non-interactive script, use SaveLibrary job = new SaveLibrary(filename). * Saves as an elib. */ private static class SaveLibrary extends Job { private RenameAndSaveLibraryTask task; private IdMapper idMapper; public SaveLibrary(RenameAndSaveLibraryTask task) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -