opendir.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. [WorkbenchPluginAttribute("Open Dir", "Just for testing", "ctrl+-", "", {"ScriptEditor"})]
  2. class OpenDirPlugin: WorkbenchPlugin
  3. {
  4. override void Run()
  5. {
  6. ScriptEditor mod = Workbench.GetModule("ScriptEditor");
  7. if (mod)
  8. {
  9. string file;
  10. string absPath;
  11. if (mod.GetCurrentFile(file) && Workbench.GetAbsolutePath(file, absPath))
  12. {
  13. if (absPath.Length() < 2) return;
  14. absPath.Replace("\\", "/");
  15. if (absPath[1] != ":")
  16. {
  17. string cwd;
  18. Workbench.GetCwd(cwd);
  19. absPath = cwd + "/" + absPath;
  20. }
  21. int index = absPath.IndexOf("/");
  22. int last_index = index;
  23. while(index != -1)
  24. {
  25. last_index = index;
  26. index = absPath.IndexOfFrom(last_index + 1, "/");
  27. }
  28. if (last_index == -1) return;
  29. string path = absPath.Substring(0, last_index);
  30. string command;
  31. command.Replace("$path", path);
  32. //Print(path);
  33. //Workbench.RunCmd(command);
  34. Workbench.RunCmd("cmd /c \"start " + path +"\"");
  35. }
  36. }
  37. }
  38. override void Configure()
  39. {
  40. Workbench.ScriptDialog("Configure OpenDir", "Usage: \n$path - will be replaced with file name", this);
  41. }
  42. [ButtonAttribute("OK")]
  43. void OkButton() {}
  44. }