/jEdit/tags/jedit-4-3-pre14/org/gjt/sp/jedit/SettingsReloader.java

# · Java · 95 lines · 56 code · 10 blank · 29 comment · 22 complexity · 62873c7840f98ec24933f418f7abe3af MD5 · raw file

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