PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

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

#
Java | 94 lines | 55 code | 10 blank | 29 comment | 20 complexity | 31c77d07ab9c56ccce6d07bb5b00eed0 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. settingsDirectory = settingsDirectory.toLowerCase();
  55. }
  56. // XXX: does this really belong here?
  57. SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
  58. if(fileset instanceof DirectoryListSet)
  59. {
  60. DirectoryListSet dirset = (DirectoryListSet)fileset;
  61. String dir = MiscUtilities.resolveSymlinks(
  62. dirset.getDirectory());
  63. if(path.startsWith(dir))
  64. dirset.invalidateCachedList();
  65. }
  66. if(jEditHome != null && path.startsWith(jEditHome))
  67. path = path.substring(jEditHome.length());
  68. else if(settingsDirectory != null && path.startsWith(settingsDirectory))
  69. path = path.substring(settingsDirectory.length());
  70. else
  71. {
  72. // not in settings directory or jEdit home directory.
  73. // no need to reload anything.
  74. return;
  75. }
  76. if(path.startsWith(File.separator) || path.startsWith("/"))
  77. path = path.substring(1);
  78. if(path.startsWith("macros"))
  79. Macros.loadMacros();
  80. else if(path.startsWith("modes") && (path.endsWith(".xml")
  81. || path.endsWith("catalog")))
  82. jEdit.reloadModes();
  83. } //}}}
  84. }