/jEdit/tags/jedit-4-2-pre3/org/gjt/sp/jedit/SettingsReloader.java

# · Java · 80 lines · 50 code · 8 blank · 22 comment · 23 complexity · 955ba563f609b3f00ca5ab0475d0e04e MD5 · raw file

  1. /*
  2. * SettingsReloader.java - Utility class reloads macros and modes when necessary
  3. * Copyright (C) 2001 Slava Pestov
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package org.gjt.sp.jedit;
  20. import java.io.File;
  21. import org.gjt.sp.jedit.msg.VFSUpdate;
  22. import org.gjt.sp.jedit.search.*;
  23. class SettingsReloader implements EBComponent
  24. {
  25. public void handleMessage(EBMessage msg)
  26. {
  27. if(msg instanceof VFSUpdate)
  28. {
  29. VFSUpdate vmsg = (VFSUpdate)msg;
  30. maybeReload(vmsg.getPath());
  31. }
  32. }
  33. private void maybeReload(String path)
  34. {
  35. // XXX: does this really belong here?
  36. SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
  37. if(fileset instanceof DirectoryListSet)
  38. {
  39. DirectoryListSet dirset = (DirectoryListSet)fileset;
  40. if(path.startsWith(dirset.getDirectory()))
  41. dirset.invalidateCachedList();
  42. }
  43. String jEditHome = jEdit.getJEditHome();
  44. String settingsDirectory = jEdit.getSettingsDirectory();
  45. // On Windows and MacOS, path names are case insensitive
  46. if(OperatingSystem.isDOSDerived() || OperatingSystem.isMacOS())
  47. {
  48. path = path.toLowerCase();
  49. if(jEditHome != null)
  50. jEditHome = jEditHome.toLowerCase();
  51. if(settingsDirectory != null)
  52. settingsDirectory = settingsDirectory.toLowerCase();
  53. }
  54. if(jEditHome != null && path.startsWith(jEditHome))
  55. path = path.substring(jEditHome.length());
  56. else if(settingsDirectory != null && path.startsWith(settingsDirectory))
  57. path = path.substring(settingsDirectory.length());
  58. else
  59. {
  60. // not in settings directory or jEdit home directory.
  61. // no need to reload anything.
  62. return;
  63. }
  64. if(path.startsWith(File.separator) || path.startsWith("/"))
  65. path = path.substring(1);
  66. if(path.startsWith("macros"))
  67. Macros.loadMacros();
  68. else if(path.startsWith("modes") && (path.endsWith(".xml")
  69. || path.endsWith("catalog")))
  70. jEdit.reloadModes();
  71. }
  72. }