Advertisement
Guest User

Untitled

a guest
May 21st, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.03 KB | None | 0 0
  1. /**
  2. * PSPad Todo script
  3. * (c) by Carney
  4. *
  5. * First enhancement by BadBoy 2009.
  6. * Version 1.00 by BadBoy 21/3/2010.
  7. * Changes:
  8. * -Project file count processing was wrong, resulting in missed files.
  9. * -Added CVS filtering.
  10. * -Improved menus.
  11. * -Added hotkey.
  12. * -Added extraction from the current file.
  13. * -Removed some unnecessary code.
  14. *
  15. * NOTE:
  16. * Project ToDos are retrieved even if you don't currently have a project open.
  17. * If any project has been opened in PsPad before running this script,
  18. * extracting project ToDos will retrieve the ToDo entries for the last
  19. * project that was opened. PsPad always knows about the last project,
  20. * even if you haven't opened one in the current session and
  21. * projectFilesCount()and projectFiles() always return data relating
  22. * to that project i.e. PsPad considers it to be open even if you're not
  23. * currently showing the Project Manager.
  24. *
  25. * Version 1.1 by V.Pshentsov <pshentsoff@gmail.com> 22.03.2012 14:55:07
  26. * Changes:
  27. * - Color syntax highlighting added (Syntax\ToDoListJS.INI).
  28. * - Any statements or regular expressions is now supported - you asked
  29. * by input box what statements you need to get. You can press 'Cancel' button
  30. * on input box or <Esc> to cancel script execution.
  31. * Examples:
  32. * "TODO:" - gets all strings started with "TODO:"
  33. * "TODO:|LOOK:" - gets all with "TODO:" or "LOOK:"
  34. * & so on...
  35. * - Line numbers added at log output.
  36. * - Too long file paths shortened from begining to maximum characters length.
  37. * - Some bugs fixed.
  38. *
  39. */
  40.  
  41. var module_name = "TodoListJS";
  42. var module_ver = "1.1";
  43. var module_title = "TodoListJS";
  44.  
  45. function openScript() {
  46. var obj1 = newEditor();
  47. obj1.openFile(moduleFileName("TodoListJS"));
  48. }
  49.  
  50. function findTodos(fs, filename, restr) {
  51. var txt = "";
  52. var r, re, line;
  53. var i = 0;
  54. var fr;
  55. var filename_maxlen = 60;
  56. var filename_str;
  57.  
  58. if(filename.length > filename_maxlen) {
  59. filename_str = '...'+filename.substr(filename.length-filename_maxlen, filename_maxlen);
  60. } else {
  61. filename_str = filename;
  62. }
  63.  
  64. re = new RegExp(restr);
  65. fr = fs.GetFile(filename).OpenAsTextStream(1, 0);
  66.  
  67. while (!fr.AtEndOfStream) {
  68. line = fr.ReadLine();
  69. i++;
  70. r = line.search(re);
  71. if (r != -1) {
  72. txt = txt.concat(i +" : "+ filename_str +" : "+ line.substr(r) + "\n");
  73. }
  74. }
  75. fr.Close( );
  76.  
  77. return txt;
  78. }
  79.  
  80. function todoListFile() {
  81.  
  82. var restr = "TODO:";
  83. restr = inputText("Current file todos. Enter word sentence or RegExp:", restr);
  84. if(!restr) return;
  85.  
  86. var fs = new ActiveXObject("Scripting.FileSystemObject")
  87. var data = "";
  88. var fr;
  89. var todos = "";
  90.  
  91. var editor = newEditor();
  92. editor.assignActiveEditor();
  93. fr = editor.fileName();
  94. if (fs.FileExists(fr)) {
  95. todos = findTodos(fs, fr, restr);
  96. if (todos != "") {
  97. data = data.concat(todos);
  98. }
  99. }
  100. print(data);
  101. }
  102.  
  103. function todoListAllFiles() {
  104. var restr = "TODO:";
  105. restr = inputText("Opened files todos. Enter word sentence or RegExp:", restr);
  106. if(!restr) return;
  107.  
  108. var fs = new ActiveXObject("Scripting.FileSystemObject")
  109. var data = "";
  110. var fr;
  111. var todos = "";
  112. var i = 0;
  113.  
  114. var editor = newEditor();
  115. while(i < editorsCount()){
  116. editor.assignEditorByIndex(i)
  117. fr = editor.fileName();
  118. if (fs.FileExists(fr)) {
  119. todos = findTodos(fs, fr, restr);
  120. if (todos != "") {
  121. data = data.concat(todos);
  122. }
  123. }
  124. i++;
  125. }
  126. print(data);
  127. }
  128.  
  129. function todoListProject() {
  130.  
  131. var restr = "TODO:";
  132. restr = inputText("Project files todos. Enter word sentence or RegExp:", restr);
  133. if(!restr) return;
  134.  
  135. var fs = new ActiveXObject("Scripting.FileSystemObject")
  136. var data = "";
  137. var fr;
  138. var i = 0; // Project file count.
  139. var j = 0; // Project file and folder count.
  140. var todos = "";
  141. var r;
  142.  
  143. //I'm already know what is this project is =)
  144. //var text = new String(projectFileName());
  145. //data = "Project: " + text.substring(text.lastIndexOf('\\') + 1, text.lastIndexOf('.')) + "\n";
  146. //data = data.concat("------------------------------------------------------------------------\n");
  147. var svn = new RegExp(".svn");
  148. var cvs = new RegExp("CVS");
  149. var git = new RegExp(".git");
  150. // projectFilesCount() returns a count of the files in a project, however
  151. // projectFiles(j) returns folders and files! Seems like a bug.
  152. var projfc = projectFilesCount();
  153. while(i < projfc) {
  154. fr = projectFiles(j);
  155. j++;
  156.  
  157. //echo(i+" of "+projfc+" files processed.\nCurrent is ["+fr+"]\nNext is ["+projectFiles(j)+"]");
  158. //Break if end of projectFiles array arrived, but counter 'i' still smaller than bug function result
  159. if(!fr.length) {
  160. //echo('Break at #'+j+': ['+fr+'].');
  161. break;
  162. }
  163. //We can simply skip all project folders
  164. if(!fs.FileExists(fr)) {
  165. //echo('Skip #'+j+': ['+fr+'] - not a file.');
  166. continue;
  167. }
  168.  
  169. // Skip SVN directories.
  170. r = fr.search(svn);
  171. if (r != -1) {
  172. if (fr && fs.FileExists(fr)) {
  173. // It's a file, increment the file count.
  174. i++;
  175. }
  176. continue;
  177. }
  178. // Skip CVS directories.
  179. r = fr.search(cvs);
  180. if (r != -1) {
  181. if (fr && fs.FileExists(fr)) {
  182. // It's a file, increment the file count.
  183. i++;
  184. }
  185. continue;
  186. }
  187. // Skip GIT directories.
  188. r = fr.search(git);
  189. if (r != -1) {
  190. if (fr && fs.FileExists(fr)) {
  191. // It's a file, increment the file count.
  192. i++;
  193. }
  194. continue;
  195. }
  196.  
  197. // It's a file.
  198. if (fr && fs.FileExists(fr)) {
  199. todos = findTodos(fs, fr, restr);
  200. if (todos != "") {
  201. data = data.concat(todos);
  202. }
  203. i++;
  204. }
  205.  
  206. }
  207.  
  208. print(data);
  209. }
  210.  
  211. function print(data) {
  212. var lines = new Array();
  213. var line = "";
  214. var c = 0;
  215.  
  216. logClear(); // clearing log window
  217. lines = data.split('\n');
  218.  
  219. for (var x in lines) {
  220.  
  221. if(lines[x]) {
  222. c++;
  223. line = lines[x];
  224. } else {
  225. line = "\n";
  226. }
  227.  
  228. logAddLine(line); // printing the result to the log
  229. }
  230. }
  231.  
  232. function about() {
  233. /* Extension description, how to use, license,
  234. open source project web address, and developer
  235. credits.
  236. */
  237.  
  238. echo(
  239. "\n" + module_name + " " + module_ver + "\n\n" +
  240. "PSPad Todo script\n\n" +
  241. "by Carney,\n" +
  242. "enhanced by BadBoy,\n" +
  243. "enhanced by V.Pshentsov.\n\n" +
  244. "This script looks for some \"TODO\" statements in the\n" +
  245. "current project, opened files or current file and displays'em in the log.\n" +
  246. "Also added syntax highlighting in .\\Syntax\\ToDoListJS.INI\n"+
  247. "Your statements should start with\n\n" +
  248. "TODO, DONE, UNDONE, ERROR, BUG, FEATURE, IMPORTANT, LOOK with \':\' or \'!\'\n" +
  249. "in order to be found.\n"+
  250. "Example: \"TODO:\", \"ERROR!\" and so on.\n"+
  251. "You are free and easy to add your own statements at all."
  252. );
  253. return;
  254. }
  255.  
  256. function progressDone(fs, fr) {
  257. var result = new Array();
  258. var r, re, line;
  259. var i = 0;
  260. var fr;
  261. //TODO: ~ 23.03.2012 10:56:07 array of "done","todo" word to search for
  262. re = new RegExp(restr);
  263. fr = fs.GetFile(filename).OpenAsTextStream(1, 0);
  264.  
  265. while (!fr.AtEndOfStream) {
  266. line = fr.ReadLine();
  267. r = line.search(re);
  268. if (r != -1) {
  269. //TODO: ~ 23.03.2012 10:56:26 count each of 3 word groups to result array
  270. }
  271. }
  272. fr.Close( );
  273.  
  274. return result;
  275. }
  276.  
  277. function progressDoneFile() {
  278.  
  279. var fs = new ActiveXObject("Scripting.FileSystemObject")
  280. var data = "";
  281. var fr;
  282. var todos = "";
  283.  
  284. var editor = newEditor();
  285. editor.assignActiveEditor();
  286. fr = editor.fileName();
  287. if (fs.FileExists(fr)) {
  288. todos = findTodos(fs, fr, restr);
  289. if (todos != "") {
  290. data = data.concat(todos);
  291. }
  292. }
  293. print(data);
  294. }
  295.  
  296. function Init() {
  297. addMenuItem("View &current file ToDos", "ToDo list", "todoListFile", "CTRL+ALT+C");
  298. addMenuItem("View all open file ToDo&s", "ToDo list", "todoListAllFiles", "CTRL+ALT+S");
  299. addMenuItem("View project To&Dos", "ToDo list", "todoListProject", "CTRL+ALT+D");
  300. addMenuItem("-","ToDo list","",""); // Menu divider
  301. addMenuItem("Edit this script", "ToDo list", "openScript");
  302. addMenuItem("About", "ToDo list", "about");
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement