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

# · Java · 94 lines · 54 code · 11 blank · 29 comment · 21 complexity · ef9bf81b0db319f5453465658f9e5d97 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.EditBus.EBHandler;
  26. import org.gjt.sp.jedit.io.VFS;
  27. import org.gjt.sp.jedit.io.VFSManager;
  28. import org.gjt.sp.jedit.msg.VFSUpdate;
  29. import org.gjt.sp.jedit.search.*;
  30. //}}}
  31. class SettingsReloader
  32. {
  33. //{{{ handleMessage() method
  34. @EBHandler
  35. public void handleVFSUpdate(VFSUpdate vmsg)
  36. {
  37. maybeReload(vmsg.getPath());
  38. } //}}}
  39. //{{{ maybeReload() method
  40. private void maybeReload(String path)
  41. {
  42. String jEditHome = jEdit.getJEditHome();
  43. String settingsDirectory = jEdit.getSettingsDirectory();
  44. if(!MiscUtilities.isURL(path))
  45. path = MiscUtilities.resolveSymlinks(path);
  46. // On Windows and MacOS, path names are case insensitive
  47. if((VFSManager.getVFSForPath(path).getCapabilities()
  48. & VFS.CASE_INSENSITIVE_CAP) != 0)
  49. {
  50. path = path.toLowerCase();
  51. jEditHome = jEditHome.toLowerCase();
  52. if(settingsDirectory != null)
  53. settingsDirectory = settingsDirectory.toLowerCase();
  54. }
  55. // XXX: does this really belong here?
  56. SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
  57. if(fileset instanceof DirectoryListSet)
  58. {
  59. DirectoryListSet dirset = (DirectoryListSet)fileset;
  60. String dir = MiscUtilities.resolveSymlinks(
  61. dirset.getDirectory());
  62. if(path.startsWith(dir))
  63. dirset.invalidateCachedList();
  64. }
  65. if(jEditHome != null && path.startsWith(jEditHome))
  66. path = path.substring(jEditHome.length());
  67. else if(settingsDirectory != null && path.startsWith(settingsDirectory))
  68. path = path.substring(settingsDirectory.length());
  69. else
  70. {
  71. // not in settings directory or jEdit home directory.
  72. // no need to reload anything.
  73. return;
  74. }
  75. if(path.startsWith(File.separator) || path.startsWith("/"))
  76. path = path.substring(1);
  77. if(path.startsWith("macros"))
  78. Macros.loadMacros();
  79. else if(path.startsWith("modes") && (path.endsWith(".xml")
  80. || path.endsWith("catalog")))
  81. jEdit.reloadModes();
  82. } //}}}
  83. }