01: /*
02: * SettingsReloader.java - Utility class reloads macros and modes when necessary
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 2001, 2003 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * 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:
23: package org.gjt.sp.jedit;
24:
25: //{{{ Imports
26: import java.io.File;
27: import org.gjt.sp.jedit.io.VFS;
28: import org.gjt.sp.jedit.io.VFSManager;
29: import org.gjt.sp.jedit.msg.VFSUpdate;
30: import org.gjt.sp.jedit.search.*;
31:
32: //}}}
33:
34: class SettingsReloader implements EBComponent {
35: //{{{ handleMessage() method
36: public void handleMessage(EBMessage msg) {
37: if (msg instanceof VFSUpdate) {
38: VFSUpdate vmsg = (VFSUpdate) msg;
39: maybeReload(vmsg.getPath());
40: }
41: } //}}}
42:
43: //{{{ maybeReload() method
44: private void maybeReload(String path) {
45: String jEditHome = jEdit.getJEditHome();
46: String settingsDirectory = jEdit.getSettingsDirectory();
47:
48: if (!MiscUtilities.isURL(path))
49: path = MiscUtilities.resolveSymlinks(path);
50:
51: // On Windows and MacOS, path names are case insensitive
52: if ((VFSManager.getVFSForPath(path).getCapabilities() & VFS.CASE_INSENSITIVE_CAP) != 0) {
53: path = path.toLowerCase();
54: jEditHome = jEditHome.toLowerCase();
55: if (settingsDirectory != null)
56: settingsDirectory = settingsDirectory.toLowerCase();
57: }
58:
59: // XXX: does this really belong here?
60: SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
61: if (fileset instanceof DirectoryListSet) {
62: DirectoryListSet dirset = (DirectoryListSet) fileset;
63: String dir = MiscUtilities.resolveSymlinks(dirset
64: .getDirectory());
65: if (path.startsWith(dir))
66: dirset.invalidateCachedList();
67: }
68:
69: if (jEditHome != null && path.startsWith(jEditHome))
70: path = path.substring(jEditHome.length());
71: else if (settingsDirectory != null
72: && path.startsWith(settingsDirectory))
73: path = path.substring(settingsDirectory.length());
74: else {
75: // not in settings directory or jEdit home directory.
76: // no need to reload anything.
77: return;
78: }
79:
80: if (path.startsWith(File.separator) || path.startsWith("/"))
81: path = path.substring(1);
82:
83: if (path.startsWith("macros"))
84: Macros.loadMacros();
85: else if (path.startsWith("modes")
86: && (path.endsWith(".xml") || path.endsWith("catalog")))
87: jEdit.reloadModes();
88: } //}}}
89: }
|