/** * Finds the next instance of the search string in the specified buffer. * * @param view The view * @param buffer The buffer * @param start Location where to start the search * @param firstTime See {@link * SearchMatcher#nextMatch(CharSequence,boolean,boolean,boolean,boolean)}. * @since jEdit 4.1pre7 */ public static boolean find( View view, Buffer buffer, int start, boolean firstTime, boolean reverse) throws Exception { EditBus.send(new PositionChanging(view.getEditPane())); SearchMatcher matcher = getSearchMatcher(); if (matcher == null) { view.getToolkit().beep(); return false; } CharSequence text; boolean startOfLine; boolean endOfLine; if (reverse) { text = new ReverseCharSequence(buffer.getSegment(0, start)); startOfLine = true; endOfLine = (buffer.getLineEndOffset(buffer.getLineOfOffset(start)) - 1 == start); } else { text = buffer.getSegment(start, buffer.getLength() - start); startOfLine = (buffer.getLineStartOffset(buffer.getLineOfOffset(start)) == start); endOfLine = true; } String noWordSep = buffer.getStringProperty("noWordSep"); matcher.setNoWordSep(noWordSep); SearchMatcher.Match match = matcher.nextMatch(text, startOfLine, endOfLine, firstTime, reverse); if (match != null) { jEdit.commitTemporary(buffer); view.setBuffer(buffer, true); JEditTextArea textArea = view.getTextArea(); if (reverse) { textArea.setSelection(new Selection.Range(start - match.end, start - match.start)); // make sure end of match is visible textArea.scrollTo(start - match.start, false); textArea.moveCaretPosition(start - match.end); } else { textArea.setSelection(new Selection.Range(start + match.start, start + match.end)); textArea.moveCaretPosition(start + match.end); // make sure start of match is visible textArea.scrollTo(start + match.start, false); } return true; } else return false; } // }}}
/** * @param restore Ignored unless no views are open * @param newView Open a new view? * @param newPlainView Open a new plain view? * @param parent The client's parent directory * @param args A list of files. Null entries are ignored, for convinience * @since jEdit 4.2pre1 */ public static Buffer handleClient( boolean restore, boolean newView, boolean newPlainView, String parent, String[] args) { // we have to deal with a huge range of possible border cases here. if (jEdit.getFirstView() == null) { // coming out of background mode. // no views open. // no buffers open if args empty. boolean hasBufferArgs = false; for (String arg : args) { if (arg != null) { hasBufferArgs = true; break; } } boolean restoreFiles = restore && jEdit.getBooleanProperty("restore") && (!hasBufferArgs || jEdit.getBooleanProperty("restore.cli")); View view = PerspectiveManager.loadPerspective(restoreFiles); Buffer buffer = jEdit.openFiles(view, parent, args); if (view == null) { if (buffer == null) buffer = jEdit.getFirstBuffer(); jEdit.newView(null, buffer); } else if (buffer != null) view.setBuffer(buffer, false); return buffer; } else if (newPlainView) { // no background mode, and opening a new view Buffer buffer = jEdit.openFiles(null, parent, args); if (buffer == null) buffer = jEdit.getFirstBuffer(); jEdit.newView(null, buffer, true); return buffer; } else if (newView) { // no background mode, and opening a new view Buffer buffer = jEdit.openFiles(null, parent, args); if (buffer == null) buffer = jEdit.getFirstBuffer(); jEdit.newView(jEdit.getActiveView(), buffer, false); return buffer; } else { // no background mode, and reusing existing view View view = jEdit.getActiveView(); Buffer buffer = jEdit.openFiles(view, parent, args); // Hack done to fix bringing the window to the front. // At least on windows, Frame.toFront() doesn't cut it. // Remove the isWindows check if it's broken under other // OSes too. if (jEdit.getBooleanProperty("server.brokenToFront")) view.setState(java.awt.Frame.ICONIFIED); // un-iconify using JDK 1.3 API view.setState(java.awt.Frame.NORMAL); view.requestFocus(); view.toFront(); // In some platforms (e.g. Windows), only setAlwaysOnTop works if (!view.isAlwaysOnTop()) { view.setAlwaysOnTop(true); view.setAlwaysOnTop(false); } return buffer; } } // }}}