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