📄 cvslibrary.java
字号:
* @param state */ public static void setState(Library lib, State state) { CVSLibrary cvslib = CVSLibraries.get(lib); if (cvslib == null && state == State.ADDED) { // if state is added, CVSLibrary should be created addLibrary(lib, true); cvslib = CVSLibraries.get(lib); } if (cvslib == null) return; if (state == null) return; if (cvslib.type != FileType.DELIB) { cvslib.libState = state; return; } for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell cell = it.next(); State currentState = cvslib.cellStates.get(cell); // When cell is not in CVS and doing commit of library, // do not set state of unknown cells to NONE if (currentState == State.UNKNOWN) continue; cvslib.cellStates.put(cell, state); } } // ------------------ Color Mapping for Explorer Tree ----------------- public static Color getColor(Library lib) { return getColor(getState(lib)); } public static Color getColor(Cell cell) { return getColor(getState(cell)); } public static State getState(Library lib) { CVSLibrary cvslib = CVSLibraries.get(lib); if (cvslib == null) return State.UNKNOWN; if (cvslib.type != FileType.DELIB) { return cvslib.libState; } Set<State> states = new TreeSet<State>(); for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell cell = it.next(); State state = cvslib.cellStates.get(cell); if (state == null) continue; states.add(state); } Iterator<State> it = states.iterator(); if (it.hasNext()) return it.next(); return State.UNKNOWN; } public static State getState(Cell cell) { CVSLibrary cvslib = CVSLibraries.get(cell.getLibrary()); if (cvslib == null) return State.UNKNOWN; if (!CVS.isDELIB(cell.getLibrary())) { // return state for library return cvslib.libState; } State state = cvslib.cellStates.get(cell); if (state == null) return State.UNKNOWN; return state; } public static Color getColor(Cell.CellGroup cg) { Set<State> states = new TreeSet<State>(); for (Iterator<Cell> it = cg.getCells(); it.hasNext(); ) { Cell cell = it.next(); State state = getState(cell); states.add(state); } return getColor(states); } public static Color getColor(State state) { if (state == State.NONE) return Color.black; if (state == State.UPDATE) return Color.magenta; if (state == State.MODIFIED) return Color.blue; if (state == State.CONFLICT) return Color.red; if (state == State.ADDED) return Color.green; if (state == State.REMOVED) return Color.green; if (state == State.PATCHED) return Color.black; if (state == State.UNKNOWN) return Color.lightGray; return Color.black; } public static Color getColor(Set<State> states) { Iterator<State> it = states.iterator(); if (it.hasNext()) return getColor(it.next()); return Color.black; } // -------------------- Editing tracking --------------------- public static void setEditing(Cell cell, boolean editing) { CVSLibrary cvslib = CVSLibraries.get(cell.getLibrary()); if (cvslib == null) return; if (editing) { cvslib.editing.put(cell, cell); } else { cvslib.editing.remove(cell); } } public static boolean isEditing(Cell cell) { CVSLibrary cvslib = CVSLibraries.get(cell.getLibrary()); if (cvslib == null) return false; return cvslib.editing.containsKey(cell); } public static void setEditing(Library lib, boolean editing) { CVSLibrary cvslib = CVSLibraries.get(lib); if (cvslib == null) return; if (!CVS.isDELIB(lib)) cvslib.libEditing = editing; else { if (editing = false) cvslib.editing.clear(); } } public static boolean isEditing(Library lib) { CVSLibrary cvslib = CVSLibraries.get(lib); if (cvslib == null) return false; if (!CVS.isDELIB(lib)) return cvslib.libEditing; else { return !cvslib.editing.isEmpty(); } } /** * Method called when saving a library, BEFORE the library * file(s) are written. * @param lib */ public static void savingLibrary(Library lib) { // When doing "save as", library type may change. Update library type here URL libFile = lib.getLibFile(); if (libFile != null) { FileType type = OpenFile.getOpenFileType(libFile.getFile(), FileType.JELIB); CVSLibrary cvslib = CVSLibraries.get(lib); if (cvslib != null) { if (cvslib.type != type) { // remove and re-add removeLibrary(lib); addLibrary(lib); } } } } /** * Hook for after a DELIB library was saved. This will do a CVS remove * on any cells files that have been deleted (renamed). * Note that this method is currently called only after a DELIB has been * written, not after any other type of library. * @param lib * @param deletedCellFiles */ public static void savedLibrary(Library lib, List<String> deletedCellFiles, List<String> writtenCellFiles) { List<Library> libs = new ArrayList<Library>(); libs.add(lib); String useDir = CVS.getUseDir(libs, null); if (CVS.isInCVS(lib) && CVS.isDELIB(lib)) { StringBuffer buf = new StringBuffer(); for (String s : deletedCellFiles) { File file = new File(s); if (CVS.isFileInCVS(file) && !file.exists()) { // original file should have been renamed to .deleted, // issue remove on deleted file if (s.startsWith(useDir)) buf.append(s.substring(useDir.length()+1)+" "); else buf.append(s+" "); } } String arg = buf.toString(); if (!arg.trim().equals("")) { //System.out.println("Removing deleted cells from CVS"); int exitVal = CVS.runCVSCommand("-q remove "+arg, "Removing deleted cells from CVS", useDir, System.out); if (exitVal != 0) { System.out.println(" Error running CVS remove command (exit status "+exitVal+")"); return; } // run the commit, because if it is left in "remove" state, a new cell of the // same name cannot be added and committed. exitVal = CVS.runCVSCommandWithQuotes("-q commit -m \"Automatic commit of removed cell file by Electric\" "+arg, "Committing removed files to CVS", useDir, System.out); // since the file has been deleted and marked for removal, future updates // will not recreate the file. However, a final commit is required to fully remove it, // but this is not really necessary. } // add any new cell files to cvs, if library is in cvs buf = new StringBuffer(); for (String s : writtenCellFiles) { File file = new File(s); File parent = file.getParentFile(); if (!CVS.isFileInCVS(parent) && parent.exists()) { // for old style delib with cell file subdirs if (parent.getAbsolutePath().startsWith(useDir)) buf.append(parent.getAbsolutePath().substring(useDir.length()+1)+" "); else buf.append(parent.getAbsolutePath()+" "); } if (!CVS.isFileInCVS(file) && file.exists()) { if (s.startsWith(useDir)) buf.append(s.substring(useDir.length()+1)+" "); else buf.append(s+" "); } } arg = buf.toString(); if (!arg.trim().equals("")) { int exitVal = CVS.runCVSCommand("-q add "+buf.toString(), "Adding new cells to CVS", useDir, System.out); if (exitVal != 0) { System.out.println(" Error running CVS add command (exit status "+exitVal+")"); return; } } } // run update on the library to see if there are now any conflicts, and // recolor added cells if (CVS.isInCVS(lib)) { Update.statusNoJob(libs, null, false); } } /** * Command to run after saving library for non-delib type libraries * @param lib the library */ public static void savedLibrary(Library lib) { // run update on the library to see if there are now any conflicts, and // recolor added cells List<Library> libs = new ArrayList<Library>(); libs.add(lib); if (CVS.isInCVS(lib)) { Update.statusNoJob(libs, null, false); } } /** * Method called when closing library. Should be called * after library is closed. * @param lib */ public static void closeLibrary(Library lib) { removeLibrary(lib); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -