4b6aefbd83f61583e229ebcdca39644b3c5820f5
[phpeclipse.git] /
1 /*
2  * Copyright (c) 2002-2004 Roberto Gonzalez Rocha and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     Roberto Gonzalez Rocha - Initial version
10  *     Igor Malinin - refactoring, minor changes
11  *
12  * $Id: XMLPreferenceInitializer.java,v 1.3 2006-10-21 23:14:13 pombredanne Exp $
13  */
14 package net.sourceforge.phpeclipse.xml.ui.internal.preferences;
15
16 /*import java.io.InputStream;
17 import java.util.Enumeration;
18 import java.util.PropertyResourceBundle;
19 */
20 import net.sourceforge.phpdt.core.JavaCore;
21 import net.sourceforge.phpdt.ui.PreferenceConstants;
22 import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
23
24 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
25 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
26 import net.sourceforge.phpeclipse.ui.WebUI;
27 import net.sourceforge.phpeclipse.ui.preferences.ITextStylePreferences;
28 //import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
29 import net.sourceforge.phpeclipse.xml.ui.text.IXMLSyntaxConstants;
30
31 //import org.eclipse.core.runtime.Path;
32 import org.eclipse.core.runtime.Platform;
33 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
34 import org.eclipse.jface.preference.IPreferenceStore;
35 import org.eclipse.jface.preference.PreferenceConverter;
36 import org.eclipse.swt.SWT;
37 import org.eclipse.swt.graphics.RGB;
38 import org.eclipse.swt.widgets.Display;
39 import org.eclipse.ui.texteditor.AbstractTextEditor;
40
41 /**
42  * @author Igor Malinin
43  */
44 public class XMLPreferenceInitializer extends AbstractPreferenceInitializer implements IPreferenceConstants {
45         /*
46          * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
47          */
48         public void initializeDefaultPreferences() {
49                 final IPreferenceStore store = /*XMLPlugin*/WebUI.getDefault()
50                                 .getPreferenceStore();
51                 final Display display = Display.getDefault();
52
53                 // TODO: ChainedPreferenceStore does not work for preferences preview
54
55                 display.syncExec(new Runnable() {
56                         public void run() {
57                                 PreferenceConverter.setDefault(store,
58                                                 AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, display
59                                                                 .getSystemColor(SWT.COLOR_LIST_FOREGROUND)
60                                                                 .getRGB());
61                         }
62                 });
63
64                 store.setDefault(
65                                 AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT,
66                                 true);
67
68                 display.syncExec(new Runnable() {
69                         public void run() {
70                                 PreferenceConverter.setDefault(store,
71                                                 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, display
72                                                                 .getSystemColor(SWT.COLOR_LIST_BACKGROUND)
73                                                                 .getRGB());
74                         }
75                 });
76
77                 store.setDefault(
78                                 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT,
79                                 true);
80
81                 // end of common preferences
82
83                 setDefault(store, IXMLSyntaxConstants.XML_DEFAULT, "0,0,0",
84                                 ITextStylePreferences.STYLE_NORMAL);
85
86                 setDefault(store, IXMLSyntaxConstants.XML_TAG, "127,0,127",
87                                 ITextStylePreferences.STYLE_NORMAL);
88
89                 setDefault(store, IXMLSyntaxConstants.XML_ATT_NAME, "0,127,0",
90                                 ITextStylePreferences.STYLE_NORMAL);
91
92                 setDefault(store, IXMLSyntaxConstants.XML_ATT_VALUE, "0,0,255",
93                                 ITextStylePreferences.STYLE_NORMAL);
94
95                 setDefault(store, IXMLSyntaxConstants.XML_ENTITY, "127,127,0",
96                                 ITextStylePreferences.STYLE_NORMAL);
97
98                 setDefault(store, IXMLSyntaxConstants.XML_CDATA, "127,127,0",
99                                 ITextStylePreferences.STYLE_NORMAL);
100
101                 setDefault(store, IXMLSyntaxConstants.XML_PI, "127,127,127",
102                                 ITextStylePreferences.STYLE_BOLD);
103
104                 setDefault(store, IXMLSyntaxConstants.XML_COMMENT, "127,0,0",
105                                 ITextStylePreferences.STYLE_NORMAL);
106
107                 setDefault(store, IXMLSyntaxConstants.XML_DECL, "127,0,127",
108                                 ITextStylePreferences.STYLE_BOLD);
109
110                 setDefault(store, IXMLSyntaxConstants.XML_SMARTY, "255,0,127",
111                                 ITextStylePreferences.STYLE_BOLD);
112
113                 setDefault(store, IXMLSyntaxConstants.DTD_CONDITIONAL, "127,127,0",
114                                 ITextStylePreferences.STYLE_BOLD);
115
116                 String operatingSystem = Platform.getOS();
117                 // maxosx, linux, solaris, win32,...
118                 try {
119                         /*InputStream is = getDefault()
120                                         .openStream(
121                                                         new Path("prefs/default_" + operatingSystem
122                                                                         + ".properties"));
123                         PropertyResourceBundle resourceBundle = new PropertyResourceBundle(
124                                         is);
125                         Enumeration e = resourceBundle.getKeys();
126                         String key;
127                         while (e.hasMoreElements()) {
128                                 key = (String) e.nextElement();
129                                 store.setDefault(key, resourceBundle.getString(key));
130                         }*/
131                 } catch (Exception e) {
132                         // no default properties found
133                         if (operatingSystem.equals(Platform.OS_WIN32)) {
134                                 // store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
135                                 // store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php
136                                 // -l -f {0}");
137                                 // store.setDefault(MYSQL_RUN_PREF,
138                                 // "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
139                                 // store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
140                                 // store.setDefault(XAMPP_START_PREF,
141                                 // "c:\\xampp\\xampp_start.exe");
142                                 // store.setDefault(XAMPP_STOP_PREF,
143                                 // "c:\\xampp\\xampp_stop.exe");
144                                 // store.setDefault(
145                                 // ETC_HOSTS_PATH_PREF,
146                                 // "c:\\windows\\system32\\drivers\\etc\\hosts");
147                         } else {
148                                 // store.setDefault(PHP_RUN_PREF, "/apache/php/php");
149                                 // store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f
150                                 // {0}");
151                                 // store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
152                                 // store.setDefault(APACHE_RUN_PREF, "/apache/apache");
153                                 // store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
154                                 // store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
155                         }
156                         // store.setDefault(MYSQL_PREF, "--standalone");
157                         // store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot
158                         // \"{0}\"\"");
159                         // store.setDefault(APACHE_STOP_PREF, "-k shutdown");
160                         // store.setDefault(APACHE_RESTART_PREF, "-k restart");
161                         // store.setDefault(MYSQL_START_BACKGROUND, "true");
162                         // store.setDefault(APACHE_START_BACKGROUND, "true");
163                         // store.setDefault(APACHE_STOP_BACKGROUND, "true");
164                         // store.setDefault(APACHE_RESTART_BACKGROUND, "true");
165                 }
166                 store.setDefault(PHP_USERDEF_XMLFILE, "");
167                 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
168                 PreferenceConverter.setDefault(store, PHP_KEYWORD,
169                                 PHPColorProvider.KEYWORD);
170                 PreferenceConverter.setDefault(store, PHP_VARIABLE,
171                                 PHPColorProvider.VARIABLE);
172                 PreferenceConverter.setDefault(store, PHP_VARIABLE_DOLLAR,
173                                 PHPColorProvider.VARIABLE);
174                 /*PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
175                                 PHPColorProvider.FUNCTION_NAME);*/
176
177                 setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME,
178                                 ITextStylePreferences.STYLE_BOLD);
179                 
180                 PreferenceConverter.setDefault(store, PHP_CONSTANT,
181                                 PHPColorProvider.CONSTANT);
182                 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
183                 PreferenceConverter.setDefault(store, PHP_DEFAULT,
184                                 PHPColorProvider.DEFAULT);
185                 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
186                                 PHPColorProvider.PHPDOC_KEYWORD);
187                 
188                 PreferenceConverter.setDefault(store, PHPDOC_TAG,
189                                 PHPColorProvider.PHPDOC_TAG);
190                 PreferenceConverter.setDefault(store, PHPDOC_LINK,
191                                 PHPColorProvider.PHPDOC_LINK);
192                 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
193                                 PHPColorProvider.PHPDOC_DEFAULT);
194
195                 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR,
196                                 new RGB(127, 0, 85));
197                 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
198                 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
199
200                 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR,
201                                 new RGB(0, 0, 0));
202                 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
203                 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
204
205                 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR,
206                                 new RGB(0, 0, 0));
207                 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
208                 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
209
210                 
211                 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR,
212                                 new RGB(127, 0, 85));
213                 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
214                 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
215
216                 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR,
217                                 new RGB(0, 0, 0));
218                 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
219                 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
220
221                 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR,
222                                 new RGB(0, 0, 0));
223                 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
224                 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
225
226                 // this will initialize the static fields in the syntaxrdr class
227                 new PHPSyntaxRdr();
228                 JavaCore.initializeDefaultPluginPreferences();
229                 PreferenceConstants.initializeDefaultValues(store);
230         }
231
232         private static void setDefault(IPreferenceStore store, String constant,
233                         String color, String style) {
234                 store.setDefault(constant + ITextStylePreferences.SUFFIX_FOREGROUND,
235                                 color);
236                 store.setDefault(constant + ITextStylePreferences.SUFFIX_STYLE, style);
237         }
238 }