1 /*******************************************************************************
2 * Copyright (c) 2010 Broadcom Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Alex Collins (Broadcom Corp.) - Initial implementation
10 *******************************************************************************/
11 package org.eclipse.cdt.internal.ui.preferences;
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.jface.preference.BooleanFieldEditor;
16 import org.eclipse.jface.preference.FieldEditorPreferencePage;
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.jface.preference.StringButtonFieldEditor;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.FileDialog;
22 import org.eclipse.ui.IWorkbench;
23 import org.eclipse.ui.IWorkbenchPreferencePage;
25 import org.eclipse.cdt.internal.ui.buildconsole.BuildConsoleManager;
26 import org.eclipse.cdt.internal.ui.buildconsole.GlobalBuildConsoleManager;
29 * Preference page for build logging options, such as whether the
30 * global build console should be logged and, if so, where.
32 public class GlobalBuildLogPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
33 public GlobalBuildLogPreferencePage() {
35 setPreferenceStore(GlobalBuildConsoleManager.getBuildLogPreferenceStore());
39 * A file path field with choose button that does not require the chosen file to exist.
41 static private class FilePathEditor extends StringButtonFieldEditor {
42 public FilePathEditor(String name, String label, Composite parent) {
43 super(name, label, parent);
47 protected String changePressed() {
48 FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
49 dialog.setText(getLabelText());
50 String fileName = super.oldValue;
51 IPath logFolder = new Path(fileName).removeLastSegments(1);
52 dialog.setFilterPath(logFolder.toOSString());
58 protected void createFieldEditors() {
59 Composite parent = getFieldEditorParent();
60 BooleanFieldEditor keepLog = new BooleanFieldEditor(BuildConsoleManager.KEY_KEEP_LOG,
61 PreferencesMessages.GlobalBuildLogPreferencePage_EnableLogging, parent);
63 FilePathEditor logLocation = new FilePathEditor(BuildConsoleManager.KEY_LOG_LOCATION,
64 PreferencesMessages.GlobalBuildLogPreferencePage_LogLocation, parent);
65 addField(logLocation);
68 public void init(IWorkbench workbench) {
69 initDefaults(GlobalBuildConsoleManager.getBuildLogPreferenceStore());
72 public static void initDefaults(IPreferenceStore prefs) {
73 prefs.setDefault(BuildConsoleManager.KEY_KEEP_LOG, BuildConsoleManager.CONSOLE_KEEP_LOG_DEFAULT);
74 prefs.setDefault(BuildConsoleManager.KEY_LOG_LOCATION,
75 GlobalBuildConsoleManager.getDefaultConsoleLogLocation());