fix bug 11195. prompt before switching perspective on Qt/Symbian project creation
--- a/project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/project/ui/ProjectUIPlugin.java Wed Apr 28 15:24:53 2010 -0500
+++ b/project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/project/ui/ProjectUIPlugin.java Fri Apr 30 12:40:56 2010 -0500
@@ -16,6 +16,33 @@
*/
package com.nokia.carbide.cpp.internal.project.ui;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IStartup;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.internal.ide.IDEInternalPreferences;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.resources.ProjectExplorer;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.progress.UIJob;
+import org.osgi.framework.BundleContext;
+
import com.nokia.carbide.cpp.internal.api.project.core.ProjectCorePluginUtility;
import com.nokia.carbide.cpp.internal.api.project.core.ResourceChangeListener;
import com.nokia.carbide.cpp.internal.project.ui.dialogs.MMPSelectionResolver;
@@ -23,21 +50,6 @@
import com.nokia.carbide.cpp.internal.project.ui.preferences.PreferenceConstants;
import com.nokia.cpp.internal.api.utils.core.Logging;
-import org.eclipse.cdt.ui.CUIPlugin;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.*;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.ui.*;
-import org.eclipse.ui.navigator.CommonNavigator;
-import org.eclipse.ui.navigator.resources.ProjectExplorer;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.eclipse.ui.progress.UIJob;
-import org.osgi.framework.BundleContext;
-
/**
* The activator class controls the plug-in life cycle
*/
@@ -178,11 +190,52 @@
}
final IPerspectiveDescriptor perspective = workbench.getPerspectiveRegistry().findPerspectiveWithId("com.nokia.carbide.cpp.CarbideCppPerspective"); //$NON-NLS-1$
+
+ IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
+ if (page != null)
+ {
+ if (page.getPerspective().getId().equals(perspective.getId()))
+ return; // already on the default perspective for this projects
+ }
+
final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
+
if (activePage != null) {
job = new UIJob(""){ //$NON-NLS-1$
public IStatus runInUIThread(IProgressMonitor monitor) {
- activePage.setPerspective(perspective);
+ boolean switchToDefaultPerspective = false;
+ IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
+ if (store != null){
+ String promptSetting = store.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);
+ if ((promptSetting.equals(MessageDialogWithToggle.ALWAYS)) ){
+ switchToDefaultPerspective = true;
+ }
+ else if ((promptSetting.equals(MessageDialogWithToggle.PROMPT))) {
+ MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(
+ null,
+ Messages.getString("PerspectiveSwitchDialog_Title"),
+ Messages.getString("PerspectiveSwitchDialog_Query"),
+ Messages.getString("PerspectiveSwitchDialog_RememberDecisionText"),
+ false,
+ null,
+ null);
+
+ boolean toggleState = toggleDialog.getToggleState();
+ switchToDefaultPerspective = toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
+
+ // set the store
+ if (toggleState){
+ if (switchToDefaultPerspective)
+ store.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE, MessageDialogWithToggle.ALWAYS);
+ else
+ store.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE, MessageDialogWithToggle.NEVER);
+ }
+ }
+ }
+
+ if (switchToDefaultPerspective){
+ activePage.setPerspective(perspective);
+ }
return Status.OK_STATUS;
}};
job.setSystem(true);
--- a/project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/project/ui/messages.properties Wed Apr 28 15:24:53 2010 -0500
+++ b/project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/project/ui/messages.properties Fri Apr 30 12:40:56 2010 -0500
@@ -104,3 +104,7 @@
CreateSourceFolders.DialogMessage=Select the mmp files to update with this change:\n· add user include path\n
OnDeviceSetupDialog.Title=On-Device Setup
+PerspectiveSwitchDialog_Title=Confirm Perspective Switch
+PerspectiveSwitchDialog_Query=The type of project you are creating is associated with the Carbide C/C++ perspective.\n\nDo you want to switch to this perspective now?
+PerspectiveSwitchDialog_RememberDecisionText=&Remember my decision
+
--- a/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/QtUIPlugin.java Wed Apr 28 15:24:53 2010 -0500
+++ b/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/QtUIPlugin.java Fri Apr 30 12:40:56 2010 -0500
@@ -23,10 +23,15 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.internal.ide.IDEInternalPreferences;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.progress.UIJob;
import org.osgi.framework.BundleContext;
@@ -40,6 +45,7 @@
import com.nokia.carbide.cpp.internal.api.sdk.ISDKManagerLoadedHook;
import com.nokia.carbide.cpp.internal.qt.core.QtCorePlugin;
import com.nokia.carbide.cpp.internal.qt.core.QtSDKUtils;
+import com.nokia.carbide.cpp.internal.qt.ui.wizard.Messages;
import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
public class QtUIPlugin extends AbstractUIPlugin implements ICarbideConfigurationChangedListener, ISDKManagerLoadedHook {
@@ -128,14 +134,48 @@
IWorkbenchWindow windows[] = workbench.getWorkbenchWindows();
activeWorkbenchWindow = windows[0];
}
-
final IPerspectiveDescriptor perspective = workbench.getPerspectiveRegistry().findPerspectiveWithId("com.trolltech.qtcppproject.QtCppPerspective"); //$NON-NLS-1$
final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
+
if (activePage != null) {
UIJob job = new UIJob(""){ //$NON-NLS-1$
public IStatus runInUIThread(IProgressMonitor monitor) {
- activePage.setPerspective(perspective);
+ boolean switchToDefaultPerspective = false;
+ IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
+
+ if (store != null){
+ String promptSetting = store.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);
+ if ((promptSetting.equals(MessageDialogWithToggle.ALWAYS)) ){
+ switchToDefaultPerspective = true;
+ }
+ else if ((promptSetting.equals(MessageDialogWithToggle.PROMPT))) {
+ MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(
+ null,
+ Messages.PerspectiveSwitchDialog_Title,
+ Messages.PerspectiveSwitchDialog_Query,
+ Messages.PerspectiveSwitchDialog_RememberDecisionText,
+ false,
+ null,
+ null);
+
+ boolean toggleState = toggleDialog.getToggleState();
+ switchToDefaultPerspective = toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
+
+ // set the store
+ if (toggleState){
+ if (switchToDefaultPerspective)
+ store.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE, MessageDialogWithToggle.ALWAYS);
+ else
+ store.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE, MessageDialogWithToggle.NEVER);
+ }
+ }
+ }
+
+ if (switchToDefaultPerspective){
+ activePage.setPerspective(perspective);
+ }
+
return Status.OK_STATUS;
}};
job.setSystem(true);
--- a/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/wizard/Messages.java Wed Apr 28 15:24:53 2010 -0500
+++ b/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/wizard/Messages.java Fri Apr 30 12:40:56 2010 -0500
@@ -121,6 +121,12 @@
public static String QtBuildTargetsPage_noQtConfigsError;
+ public static String PerspectiveSwitchDialog_Title;
+
+ public static String PerspectiveSwitchDialog_Query;
+
+ public static String PerspectiveSwitchDialog_RememberDecisionText;
+
static {
// initialize resource bundle
--- a/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/wizard/messages.properties Wed Apr 28 15:24:53 2010 -0500
+++ b/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/wizard/messages.properties Fri Apr 30 12:40:56 2010 -0500
@@ -52,3 +52,8 @@
QtBuildTargetsPage_filterCheckboxText=Filter build configurations that don't contain Qt support
QtBuildTargetsPage_filterCheckboxToolTip=Filters any build configurations that don't contain the Qt libraries
QtBuildTargetsPage_noQtConfigsError=No SDK's were found that contain Qt support
+
+PerspectiveSwitchDialog_Title=Confirm Perspective Switch
+PerspectiveSwitchDialog_Query=The type of project you are creating is associated with the Qt C++ perspective.\n\nDo you want to switch to this perspective now?
+PerspectiveSwitchDialog_RememberDecisionText=&Remember my decision
+