diff options
Diffstat (limited to 'org.eclipse.ui.intro')
6 files changed, 290 insertions, 3 deletions
diff --git a/org.eclipse.ui.intro/META-INF/MANIFEST.MF b/org.eclipse.ui.intro/META-INF/MANIFEST.MF index c779013a2..e96b98d1e 100644 --- a/org.eclipse.ui.intro/META-INF/MANIFEST.MF +++ b/org.eclipse.ui.intro/META-INF/MANIFEST.MF @@ -17,7 +17,8 @@ Export-Package: org.eclipse.ui.internal.intro.impl;x-friends:="org.eclipse.ui.in org.eclipse.ui.internal.intro.impl.presentations;x-friends:="org.eclipse.ua.tests", org.eclipse.ui.internal.intro.impl.swt;x-internal:=true, org.eclipse.ui.internal.intro.impl.util;x-internal:=true, - org.eclipse.ui.intro.config + org.eclipse.ui.intro.config, + org.eclipse.ui.intro.contentproviders Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.help;bundle-version="[3.4.0,4.0.0)", org.eclipse.help.base;bundle-version="[3.4.0,4.0.0)";resolution:=optional, diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/Messages.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/Messages.java index 903c1ff5c..3a472c002 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/Messages.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/Messages.java @@ -54,5 +54,8 @@ public class Messages extends NLS { // ------- public static String IntroPart_openExternal_tooltip; public static String IntroPart_showContentButton_tooltip; + + //Always Welcome Checkbox + public static String AlwaysWelcomeCheckbox_Text; } diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/Messages.properties b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/Messages.properties index 64723446a..b58535aa3 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/Messages.properties +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/Messages.properties @@ -54,3 +54,7 @@ IntroLaunchBar_restore_tooltip=Restore Welcome # ------- IntroPart_showContentButton_tooltip = Show Intro Tree IntroPart_openExternal_tooltip = Open External Browser + + +#Always welcome checkbox +AlwaysWelcomeCheckbox_Text=Always show Welcome at start up diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/ReopenUtil.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/ReopenUtil.java new file mode 100644 index 000000000..eef39a1dc --- /dev/null +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/ReopenUtil.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.internal.intro.impl.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.ui.XMLMemento; +import org.eclipse.ui.internal.intro.impl.IntroPlugin; + +/** + * Utility class which manages the pseudo preference which determines whether + * Intro should always open on startup + */ + +public class ReopenUtil { + + private static final String STATE = "state"; //$NON-NLS-1$ + private static final String REOPEN = "reopen"; //$NON-NLS-1$ + + public static boolean isReopenPreferenceInitialized() { + return readMemento() != null; + } + + public static void setReopenPreference(boolean reopen) { + XMLMemento memento = XMLMemento.createWriteRoot(STATE); + memento.putBoolean(REOPEN, reopen); + saveMemento(memento); + } + + public static boolean isReopenPreference() { + XMLMemento memento = readMemento(); + if (memento == null) { + return false; + } + return memento.getBoolean(REOPEN).booleanValue(); + } + + private static XMLMemento readMemento() { + XMLMemento memento; + InputStreamReader reader = null; + + try { + // Read the cheatsheet state file. + final File stateFile = getStateFile(); + + FileInputStream input = new FileInputStream(stateFile); + reader = new InputStreamReader(input, "utf-8"); //$NON-NLS-1$ + memento = XMLMemento.createReadRoot(reader); + + + } catch (FileNotFoundException e) { + memento = null; + // Do nothing, the file will not exist the first time the workbench in used. + } catch (Exception e) { + memento = null; + } finally { + try { + if (reader != null) + reader.close(); + } catch (IOException e) { + // Not much to do, just catch the exception and keep going. + } + } + return memento; + } + + private static void saveMemento(XMLMemento memento) { + // Save the IMemento to a file. + File stateFile = getStateFile(); + OutputStreamWriter writer = null; + try { + FileOutputStream stream = new FileOutputStream(stateFile); + writer = new OutputStreamWriter(stream, "utf-8"); //$NON-NLS-1$ + memento.save(writer); + } catch (IOException e) { + stateFile.delete(); + } finally { + try { + if (writer != null) + writer.close(); + } catch (IOException e) { + + } + } + } + + private static File getStateFile() { + IPath path = IntroPlugin.getDefault().getStateLocation(); + path = path.append("introstate"); //$NON-NLS-1$ + File stateFile = path.toFile(); + return stateFile; + } + +} diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/CustomizableIntroPart.java b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/CustomizableIntroPart.java index 063d4b66e..6c791062c 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/CustomizableIntroPart.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/config/CustomizableIntroPart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -22,7 +22,9 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IMemento; +import org.eclipse.ui.IWorkbenchPreferenceConstants; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.intro.impl.IIntroConstants; import org.eclipse.ui.internal.intro.impl.IntroPlugin; import org.eclipse.ui.internal.intro.impl.Messages; @@ -35,6 +37,7 @@ import org.eclipse.ui.internal.intro.impl.parts.StandbyPart; import org.eclipse.ui.internal.intro.impl.presentations.BrowserIntroPartImplementation; import org.eclipse.ui.internal.intro.impl.util.DialogUtil; import org.eclipse.ui.internal.intro.impl.util.Log; +import org.eclipse.ui.internal.intro.impl.util.ReopenUtil; import org.eclipse.ui.intro.IIntroSite; import org.eclipse.ui.part.IntroPart; @@ -152,8 +155,15 @@ public final class CustomizableIntroPart extends IntroPart implements model = extensionPointManager.getCurrentModel(); if (model != null && model.hasValidConfig()) { + + boolean startAtHomePage = ReopenUtil.isReopenPreference(); + if (startAtHomePage) { + PlatformUI.getPreferenceStore().setValue( + IWorkbenchPreferenceConstants.SHOW_INTRO, true); + memento = null; + } // we have a valid config contribution, get presentation. Make sure - // you pass corret memento. + // you pass correct memento. presentation = model.getPresentation(); if (presentation != null) presentation.init(this, getMemento(memento, diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/AlwaysWelcomeCheckbox.java b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/AlwaysWelcomeCheckbox.java new file mode 100644 index 000000000..d79ca8bc4 --- /dev/null +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/intro/contentproviders/AlwaysWelcomeCheckbox.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.intro.contentproviders; + +import java.io.PrintWriter; +import java.util.Properties; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchPreferenceConstants; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.internal.intro.impl.Messages; +import org.eclipse.ui.internal.intro.impl.util.ReopenUtil; +import org.eclipse.ui.intro.IIntroSite; +import org.eclipse.ui.intro.config.IIntroAction; +import org.eclipse.ui.intro.config.IIntroContentProvider; +import org.eclipse.ui.intro.config.IIntroContentProviderSite; +import org.eclipse.ui.PlatformUI; +/** + * + * Class which contributes a checkbox to an intro page which allows welcome to show + * on startup. If the checkbox is checked the home page of intro will be shown the next + * time the Eclipse application starts up. This class may be subclassed to override + * the text for the checkbox label. + * + * Implements the IIntroContentProvider to create the checkbox ui, and the + * org.eclipse.ui.intro.config.IIntroAction interface for handling checkbox click events. + * + * @since 3.3 + */ +public class AlwaysWelcomeCheckbox implements IIntroContentProvider,IIntroAction { + + public final static String ALWAYS_SHOW_INTRO = "alwaysShowIntro"; //$NON-NLS-1$ + + private boolean disposed = false; + + /** + * Override this method to change the default text used for the checkbox + * + * @return String label for the checkbox + * + * @since 3.3 + * + */ + protected String getText() + { + // Default text + return Messages.AlwaysWelcomeCheckbox_Text; + } + + + public void createContent(String id, PrintWriter out) { + + boolean alwaysShowIntro = getAlwaysShowIntroPref(); + + // Use an IIntroAction url that points back to this class - + // particularly invoking run(). + // This url is 'activated' using the onClick event. + out.print("<div id=\""+id+"\"><input type=\"checkbox\" "+ //$NON-NLS-1$//$NON-NLS-2$ + "onClick=window.location="+ //$NON-NLS-1$ + "\"http://org.eclipse.ui.intro/runAction?"+ //$NON-NLS-1$ + "pluginId=org.eclipse.platform&"+ //$NON-NLS-1$ + "class="+this.getClass().getName()+"\" "); //$NON-NLS-1$ //$NON-NLS-2$ + + if (alwaysShowIntro) + { + out.print(" checked=\"checked\""); //$NON-NLS-1$ + + PlatformUI.getPreferenceStore().setValue( + IWorkbenchPreferenceConstants.SHOW_INTRO, alwaysShowIntro); + } + + out.println("/>"+getText()+"</div>"); //$NON-NLS-1$//$NON-NLS-2$ + } + + + public void createContent(String id, Composite parent, FormToolkit toolkit) { + if (disposed) + return; + + boolean alwaysShowIntro = getAlwaysShowIntroPref(); + + Button checkBox = new Button(parent,SWT.CHECK); + toolkit.adapt((Control)checkBox,false,false); + + checkBox.setText(getText()); + checkBox.setSelection(alwaysShowIntro); + checkBox.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e){ + reverseShowIntroState(); + } + }); + + if (alwaysShowIntro) + PlatformUI.getPreferenceStore().setValue( + IWorkbenchPreferenceConstants.SHOW_INTRO, alwaysShowIntro); + } + + public void dispose() { + disposed = true; + } + + public void init(IIntroContentProviderSite site) { + } + + /** + * Method called when box is clicked in html (swt is handled with a + * SelectionAdapter - both methods call reverseShowIntroState()) + */ + public void run(IIntroSite site, Properties params) { + reverseShowIntroState(); + } + + /** + * Method reverses preference ALWAYS_SHOW_INTRO due to checkbox selection change + * + */ + private void reverseShowIntroState() + { + // Retrieve current state of IUniversalIntroConst.ALWAYS_SHOW_INTRO, change it, and save it back + // to both ALWAYS_SHOW_INTRO and SHOW_INTRO + boolean alwaysShowIntro = !getAlwaysShowIntroPref(); + + // local preference store + setAlwaysShowIntroPref(alwaysShowIntro); + + // workbench preference store + PlatformUI.getPreferenceStore().setValue( + IWorkbenchPreferenceConstants.SHOW_INTRO, alwaysShowIntro); + + } + + public boolean getAlwaysShowIntroPref() + { + // If uninitialized, we will default to true (box will be checked) + if (!ReopenUtil.isReopenPreferenceInitialized()) { + setAlwaysShowIntroPref(true); + } + return ReopenUtil.isReopenPreference(); + } + + public void setAlwaysShowIntroPref(boolean val) + { + ReopenUtil.setReopenPreference(val); + } +} |