PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 70 lines | 42 code | 7 blank | 21 comment | 22 complexity | ff0c405b5fb5827e07994e6d6d91d563 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. * 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. class SettingsReloader implements EBComponent
  23. {
  24. public void handleMessage(EBMessage msg)
  25. {
  26. if(msg instanceof VFSUpdate)
  27. {
  28. VFSUpdate vmsg = (VFSUpdate)msg;
  29. maybeReload(vmsg.getPath());
  30. }
  31. }
  32. private void maybeReload(String path)
  33. {
  34. String jEditHome = jEdit.getJEditHome();
  35. String settingsDirectory = jEdit.getSettingsDirectory();
  36. String osName = System.getProperty("os.name");
  37. // On Windows and MacOS, path names are case insensitive
  38. if(osName.indexOf("Windows") != -1 || osName.indexOf("Mac") != -1)
  39. {
  40. path = path.toLowerCase();
  41. if(jEditHome != null)
  42. jEditHome = jEditHome.toLowerCase();
  43. if(settingsDirectory != null)
  44. settingsDirectory = settingsDirectory.toLowerCase();
  45. }
  46. if(jEditHome != null && path.startsWith(jEditHome))
  47. path = path.substring(jEditHome.length());
  48. else if(settingsDirectory != null && path.startsWith(settingsDirectory))
  49. path = path.substring(settingsDirectory.length());
  50. else
  51. {
  52. // not in settings directory or jEdit home directory.
  53. // no need to reload anything.
  54. return;
  55. }
  56. if(path.startsWith(File.separator) || path.startsWith("/"))
  57. path = path.substring(1);
  58. if(path.startsWith("macros"))
  59. Macros.loadMacros();
  60. else if(path.endsWith(".xml") || path.endsWith("modes" + File.separator + "catalog"))
  61. jEdit.reloadModes();
  62. }
  63. }