?? write_hypersearch_results.bsh
字號:
/* * Write_HyperSearch_Results.bsh - a BeanShell macro script * for the jEdit text editor - writes the contents of the * "HyperSearch Results" window to a new text buffer * Copyright (C) 2001 John Gellene * jgellene@nyc.rr.com * http://community.jedit.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with the jEdit program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Notes on use: * * The macro operates by dumping the contents of the HyperSearch Results * window into a simple text report format. Because the HyperSearchResults * object does not know the search parameters that produced its data, the * parameters must be retrieved from the SearchAndReplace object. If those * parameters have changed since the HyperSearch, the report header will not be * accurate (although the body of the report will not be affected). A simple * test checks whether the HyperSearch flag is set before running the dumping * routines. To be completely reliable, the macro should be run immediately * after a HyperSearch. * * $Id: Write_HyperSearch_Results.bsh,v 1.3 2003/01/10 19:48:18 spestov Exp $ * * Checked for jEdit 4.0 API * Adapted and checked for jEdit 4.1 API by Rudi Widmann * */import java.text.SimpleDateFormat;import javax.swing.tree.*;void writeHyperSearchResults(){ title = "Write HyperSearch results"; hsearch = view.getDockableWindowManager() .getDockable("hypersearch-results"); if(hsearch == null) { JOptionPane.showMessageDialog(view, "The \"HyperSearch Results\" window is not open.", title, JOptionPane.ERROR_MESSAGE); return; } if(jEdit.getBooleanProperty("search.hypersearch.toggle") == false) { answer = JOptionPane.showConfirmDialog(view, "Search settings have changed;\nthe report may not be accurate." + "\nDo you wish to proceed?", title, JOptionPane.YES_NO_OPTION); if(answer != JOptionPane.YES_OPTION) return; } /******************************************************************* * Hyper search result tree structure * root * + searchNode * + fileNode * + results * + fileNode * + results * + searchNode * + fileNode * + results *******************************************************************/ jEdit.newFile(view); writeHeader(); treeModel = hsearch.getTreeModel(); root = treeModel.getRoot(); rootChildCount = root.getChildCount(); if(rootChildCount == 0) { textArea.setSelectedText( "Search items not found\n\nEnd of report\n"); } else { searchNode = root.getFirstChild(); for(int i = 0; i < rootChildCount; ++i) { super.fileCount = 0; super.hitCount = 0; writeSearchHeader(searchNode); if (i == rootChildCount-1) writeSearchParameters(); // write only for last result super.searchCount++; searchChildCount = searchNode.getChildCount(); if(searchChildCount == 0) { textArea.setSelectedText( "Search term not found\n\nEnd of report\n"); } fileNode = searchNode.getFirstChild(); for(int j = 0; j < searchChildCount; ++j) { writeResultsForFile(fileNode); fileNode = fileNode.getNextSibling(); } searchNode = searchNode.getNextSibling(); writeFileFooter(); } writeFooter(); }}void writeSearchHeader( node){ node = (DefaultMutableTreeNode)node; if(node == null) return; childCount = node.getChildCount(); if( childCount == 0) return; sb.setLength(0); sb.append("Results for search item: \""); sb.append(node.getUserObject().toString()); sb.append("\"\n\n"); textArea.setSelectedText(sb.toString());}void writeResultsForFile( node){ node = (DefaultMutableTreeNode)node; if(node == null) return; childCount = node.getChildCount(); if( childCount == 0) return; ++super.fileCount; super.hitCount += childCount; obj = node.getUserObject(); sb.setLength(0); sb.append("\tMatched file:\n\t"); sb.append(node.getUserObject().toString()); sb.append("\n\n"); lineNode = (DefaultMutableTreeNode)node.getFirstChild(); if(lineNode == null) return; for( int i = 0; i < childCount; ++i) { if(lineNode == null) { sb.append("\t\tNull node for i = " + String.valueOf(i)); } else { sb.append("\t\tline "); sb.append(lineNode.getUserObject().toString()); } sb.append('\n'); lineNode = lineNode.getNextSibling(); } sb.append("\n\tNumber of occurrences: "); sb.append(String.valueOf(childCount)); sb.append("\n\n"); textArea.setSelectedText(sb.toString());}void writeHeader(){ sb.append("Hypersearch report written on "); SimpleDateFormat f = new SimpleDateFormat("EE MMM d, yyyy h:mm a z"); sb.append(f.format( new Date())); sb.append("\n\n"); textArea.setSelectedText(sb.toString());}void writeSearchParameters(){ sb.setLength(0); sb.append("\tUsed search parameters for "); if(SearchAndReplace.getRegexp()) sb.append("regular expression: "); else sb.append("search term: "); sb.append(SearchAndReplace.getSearchString()); sb.append(" (case "); if(SearchAndReplace.getIgnoreCase()) sb.append("in"); sb.append("sensitive)\n"); sb.append("\tSearch conducted on "); sb.append(writeSearchFileSetType()); sb.append('\n'); sb.append('\n'); textArea.setSelectedText(sb.toString());}void writeFileFooter(){ sb.setLength(0); sb.append("\tTotal of "); sb.append(String.valueOf(hitCount)); sb.append(" occurrences found in "); sb.append(String.valueOf(fileCount)); sb.append(" files\n\n"); textArea.setSelectedText(sb.toString());}void writeFooter(){ sb.setLength(0); sb.append("Total of "); sb.append(String.valueOf(searchCount)); sb.append(" search results reported \n\nEnd of report\n"); textArea.setSelectedText(sb.toString());}String writeSearchFileSetType(){ result = new StringBuffer(); fileSet = SearchAndReplace.getSearchFileSet(); if(fileSet instanceof CurrentBufferSet) result.append("current buffer"); else if(fileSet instanceof AllBufferSet) result.append("all open buffers with file mask '") .append(((AllBufferSet)fileSet).getFileFilter()) .append('\''); else if(fileSet instanceof DirectoryListSet) { fileSet = (DirectoryListSet)fileSet; result.append("all files in \n") .append(fileSet.getDirectory()) .append('\n'); if(fileSet.isRecursive()) result.append("(and subdirectories) "); result.append("with file mask '") .append(fileSet.getFileFilter()) .append('\''); } else result.append("unknown file set"); return result.toString();}sb = new StringBuffer();searchCount = 0;fileCount = 0;hitCount = 0;writeHyperSearchResults();/* Macro index data (in DocBook format)<listitem> <para><filename>Write_HyperSearch_Results.bsh</filename></para> <abstract><para> This macro writes the contents of the <quote>HyperSearch Results</quote> window to a new text buffer. </para></abstract> <para> The macro employs a simple text report format. Since the HyperSearch window's object does not maintain the search settings that produced the displayed results, the macro examines the current settings in the <classname>SearchAndReplace</classname> object. It confirms that the HyperSearch option is selected before writing the report. However, the only way to be sure that the report's contents are completely accurate is to run the macro immediately after a HyperSearch. </para></listitem>*/// end Write_HyperSearch_Results.bsh
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -