/** * Default constructor * * @param editor the editor where to open a file * @param uuid the tab uuid */ public SearchFile(SciNotes editor, String uuid) { super(SciNotesMessages.SEARCHINFILES, uuid == null ? UUID.randomUUID().toString() : uuid); this.editor = editor; editor.addSearchInFiles(this); ConfigSciNotesManager.saveSearchInFilesState(editor.getPersistentId(), getPersistentId()); initTab(); restoreSearchFile(); WindowsConfigurationManager.restorationFinished(this); }
/** Called when the results are available */ @Override public synchronized void done() { SearchManager.MatchingPositions pos = getResults(); if (pos == null) { if (component != null) { component.firePropertyChange(SEARCHDONE, false, true); } return; } SearchFile searchFile = editor.getSearchInFiles(); final SearchFile sf; if (searchFile == null) { editor.addSearchInFiles(); sf = editor.getSearchInFiles(); } else { sf = searchFile; } sf.fillTab( pos, base, recursive, ignoreCR, filePattern, fileCaseSensitive, wordPattern, wordCaseSensitive, wholeWord, regexp); sf.setMyBackgroundSearch(this); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { sf.getJTree().addSelectionRow(0); sf.getJTree().requestFocus(); long time = getElapsedTime(); sf.getInfoBar() .setText(String.format(SciNotesMessages.ELAPSEDTIME, ((double) time) / 1000)); } }); if (component != null) { component.firePropertyChange(SEARCHDONE, false, true); } }
private void saveSearchFile() { if (mySearch != null) { try { FileWriter fwriter = new FileWriter( ScilabConstants.SCIHOME.toString() + File.separator + getPersistentId() + ".xml"); BufferedWriter buffer = new BufferedWriter(fwriter); buffer.append("<SearchResults editor=\"" + editor.getUUID() + "\""); buffer.append(" base=\"" + mySearch.base + "\""); buffer.append(" recursive=\"" + mySearch.recursive + "\""); buffer.append(" ignoreCR=\"" + mySearch.ignoreCR + "\""); buffer.append( " filePattern=\"" + ScilabXMLUtilities.getXMLString(mySearch.filePattern) + "\""); buffer.append(" fileCaseSensitive=\"" + mySearch.fileCaseSensitive + "\""); if (mySearch.wordPattern != null && !mySearch.wordPattern.isEmpty()) { buffer.append( " wordPattern=\"" + ScilabXMLUtilities.getXMLString(mySearch.wordPattern) + "\""); } buffer.append(" wordCaseSensitive=\"" + mySearch.wordCaseSensitive + "\""); buffer.append(" wholeWord=\"" + mySearch.wholeWord + "\""); buffer.append(" regexp=\"" + mySearch.regexp + "\""); buffer.append(">\n"); mySearch.getResults().toXML(buffer, 1); buffer.append("</SearchResults>"); buffer.close(); } catch (Exception e) { e.printStackTrace(); } } }
/** * If the user hits ENTER key or double-click on a node, the corresponding file is open in * SciNotes. * * @param editor the editor where to open the file * @param the word pattern used * @param path the path of the node */ private static void validNode(SciNotes editor, final Pattern pat, TreePath path) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObj = node.getUserObject(); int lineNumber = -1; String fileName = null; boolean line = false; if (userObj instanceof SearchManager.MatchingPositions) { SearchManager.MatchingPositions pos = (SearchManager.MatchingPositions) userObj; lineNumber = 0; if (!pos.isDirectory()) { fileName = pos.getFileName(); } } else if (userObj instanceof SearchManager.Line) { SearchManager.Line l = (SearchManager.Line) userObj; lineNumber = l.getNumber(); fileName = ((SearchManager.MatchingPositions) ((DefaultMutableTreeNode) node.getParent()).getUserObject()) .getFileName(); line = true; } if (fileName != null) { final boolean fline = !line; final int ln = lineNumber; if (lineNumber != -1) { editor.openFile(fileName, 0, null); final ScilabEditorPane sep = editor.getTextPane(); if (sep.getName().equals(fileName)) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { sep.highlightWords(pat, fline); if (ln != 0) { sep.scrollTextToLineNumber(ln, false, false, true); } } }); } } } }
/** Try to add a SciNotes toolbar */ public void changeToolBar() { SwingScilabWindow win = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this); Set<SwingScilabTab> set = win.getDockingPort().getDockables(); for (SwingScilabTab tab : set) { if (tab == editor) { addToolBar(editor.getToolBar()); break; } } }
private static void setState(int state) { boolean[] states = SciNotesLineNumberPanel.getState(state); SciNotesOptions.getSciNotesDisplay().showLineNumbers = states[0]; SciNotesOptions.getSciNotesDisplay().whereami = states[1]; XConfiguration.set( XConfiguration.getXConfigurationDocument(), SciNotesOptions.DISPLAYPATH + "/@show-line-numbers", Boolean.toString(states[0])); XConfiguration.set( XConfiguration.getXConfigurationDocument(), SciNotesOptions.DISPLAYPATH + "/@whereami", Boolean.toString(states[1])); SciNotes.setWhereamiLineNumbering(); }
/** Initialize the tab */ private void initTab() { final TextBox infobar = ScilabTextBox.createTextBox(); setWindowIcon("system-search"); updateUI(); CommonCallBack callback = new CommonCallBack(null) { @Override public void callBack() { ClosingOperationsManager.startClosingOperation((SwingScilabTab) SearchFile.this); } @Override public void actionPerformed(ActionEvent e) { callBack(); } }; setCallback(callback); MenuBar menubar = ScilabMenuBar.createMenuBar(); Menu fileMenu = ScilabMenu.createMenu(); fileMenu.setText(SciNotesMessages.FILE); fileMenu.setMnemonic('F'); MenuItem menu = ScilabMenuItem.createMenuItem(); menu.setCallback(callback); ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()) .setAccelerator(SciNotes.getActionKeys().get("scinotes-exit")); menu.setText(SciNotesMessages.EXIT); fileMenu.add(menu); menubar.add(fileMenu); addMenuBar(menubar); addInfoBar(infobar); setPreferredSize(new Dimension(650, 250)); }
/** Close the current window */ public void closeSearchInFiles() { saveSearchFile(); editor.removeSearchInFiles(); editor = null; parentWindow = null; }