KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > SettingsReloader


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
23 package org.gjt.sp.jedit;
24
25 //{{{ Imports
26
import java.io.File JavaDoc;
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 class SettingsReloader implements EBComponent
34 {
35     //{{{ handleMessage() method
36
public void handleMessage(EBMessage msg)
37     {
38         if(msg instanceof VFSUpdate)
39         {
40             VFSUpdate vmsg = (VFSUpdate)msg;
41             maybeReload(vmsg.getPath());
42         }
43     } //}}}
44

45     //{{{ maybeReload() method
46
private void maybeReload(String JavaDoc path)
47     {
48         String JavaDoc jEditHome = jEdit.getJEditHome();
49         String JavaDoc settingsDirectory = jEdit.getSettingsDirectory();
50
51         if(!MiscUtilities.isURL(path))
52             path = MiscUtilities.resolveSymlinks(path);
53
54         // On Windows and MacOS, path names are case insensitive
55
if((VFSManager.getVFSForPath(path).getCapabilities()
56             & VFS.CASE_INSENSITIVE_CAP) != 0)
57         {
58             path = path.toLowerCase();
59             jEditHome = jEditHome.toLowerCase();
60             settingsDirectory = settingsDirectory.toLowerCase();
61         }
62
63         // XXX: does this really belong here?
64
SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
65         if(fileset instanceof DirectoryListSet)
66         {
67             DirectoryListSet dirset = (DirectoryListSet)fileset;
68             String JavaDoc dir = MiscUtilities.resolveSymlinks(
69                 dirset.getDirectory());
70             if(path.startsWith(dir))
71                 dirset.invalidateCachedList();
72         }
73
74         if(jEditHome != null && path.startsWith(jEditHome))
75             path = path.substring(jEditHome.length());
76         else if(settingsDirectory != null && path.startsWith(settingsDirectory))
77             path = path.substring(settingsDirectory.length());
78         else
79         {
80             // not in settings directory or jEdit home directory.
81
// no need to reload anything.
82
return;
83         }
84
85         if(path.startsWith(File.separator) || path.startsWith("/"))
86             path = path.substring(1);
87
88         if(path.startsWith("macros"))
89             Macros.loadMacros();
90         else if(path.startsWith("modes") && (path.endsWith(".xml")
91             || path.endsWith("catalog")))
92             jEdit.reloadModes();
93     } //}}}
94
}
95
Popular Tags