From 97ef2c67d17965b777db26863113e42dd468e5cb Mon Sep 17 00:00:00 2001 From: David Inglis Date: Tue, 16 Sep 2003 18:18:36 +0000 Subject: [PATCH] prompt for convertion on statup if workspace contains old make projects --- build/org.eclipse.cdt.make.ui/plugin.xml | 7 ++- .../cdt/make/internal/ui/MakeUIPlugin.java | 43 +++++++++++++++++-- .../ui/actions/UpdateMakeProjectAction.java | 27 ++++++++++++ .../wizards/UpdateMakeProjectWizardPage.java | 33 ++------------ 4 files changed, 76 insertions(+), 34 deletions(-) diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index 4c3f4646ae5..688845b6254 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -271,10 +271,15 @@ name="Makefile Editor" icon="icons/ctool16/makefile.gif" filenames="Makefile,makefile" - contributorClass="org.eclipse.cdt.make.internal.ui.editor.MakefileEditorActionContributor" + contributorClass="org.eclipse.cdt.make.internal.ui.editor.MakefileEditorActionContributor" class="org.eclipse.cdt.make.internal.ui.editor.MakefileEditor" id="org.eclipse.cdt.make.editor"> + + + + diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java index 64b2bbf653f..776b3f4eb8d 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java @@ -4,6 +4,8 @@ import java.lang.reflect.InvocationTargetException; import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.eclipse.cdt.make.ui.actions.UpdateMakeProjectAction; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -11,15 +13,18 @@ import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IStartup; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.plugin.AbstractUIPlugin; /** * The main plugin class to be used in the desktop. */ -public class MakeUIPlugin extends AbstractUIPlugin { +public class MakeUIPlugin extends AbstractUIPlugin implements IStartup { //The shared instance. private static MakeUIPlugin plugin; //Resource bundle. @@ -63,7 +68,7 @@ public class MakeUIPlugin extends AbstractUIPlugin { public static IWorkbenchWindow getActiveWorkbenchWindow() { return getDefault().getWorkbench().getActiveWorkbenchWindow(); } - + /** * Returns the string from the plugin's resource bundle, * or 'key' if not found. @@ -146,7 +151,7 @@ public class MakeUIPlugin extends AbstractUIPlugin { status = new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.OK, e.getMessage(), e); log(status); } - + /** * Utility method with conventions */ @@ -178,4 +183,36 @@ public class MakeUIPlugin extends AbstractUIPlugin { } ErrorDialog.openError(shell, title, message, status); } + + public void earlyStartup() { + final IProject[] oldProject = UpdateMakeProjectAction.getOldProjects(); + if (oldProject.length > 0) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + if (MessageDialog + .openQuestion( + getShell(), + "Update make projects", + "Older 'make' projects have been detected in your workspace. \n" + + "These projects are no longer supported, " + + "would you like to convert these now?") + == true) { + ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell()); + UpdateMakeProjectAction.run(false, pd, oldProject); + } + } + }); + } + return; + + } + + protected Shell getShell() { + if (getActiveWorkbenchShell() != null) { + return getActiveWorkbenchShell(); + } else { + IWorkbenchWindow[] windows = getDefault().getWorkbench().getWorkbenchWindows(); + return windows[0].getShell(); + } + } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/UpdateMakeProjectAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/UpdateMakeProjectAction.java index 3796b7be2b2..ef40d60f61e 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/UpdateMakeProjectAction.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/actions/UpdateMakeProjectAction.java @@ -10,6 +10,7 @@ package org.eclipse.cdt.make.ui.actions; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Vector; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICProject; @@ -21,9 +22,11 @@ import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.ui.wizards.UpdateMakeProjectWizard; +import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceProxy; import org.eclipse.core.resources.IResourceProxyVisitor; @@ -83,6 +86,30 @@ public class UpdateMakeProjectAction implements IWorkbenchWindowActionDelegate { } } + + public static IProject[] getOldProjects() { + IProject[] project = MakeUIPlugin.getWorkspace().getRoot().getProjects(); + Vector result = new Vector(); + try { + for (int i = 0; i < project.length; i++) { + if (project[i].isAccessible()) { + IProjectDescription desc = project[i].getDescription(); + ICommand builder[] = desc.getBuildSpec(); + for (int j = 0; j < builder.length; j++) { + if (builder[j].getBuilderName().equals(MakeCorePlugin.OLD_BUILDER_ID)) { + result.add(project[i]); + break; + } + } + } + } + } catch (CoreException e) { + MakeUIPlugin.logException(e); + } + + return (IProject[]) result.toArray(new IProject[result.size()]); + } + static public void run(boolean fork, IRunnableContext context, final IProject[] projects) { try { diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/UpdateMakeProjectWizardPage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/UpdateMakeProjectWizardPage.java index 7fe625ac5e7..497fb0b8e0d 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/UpdateMakeProjectWizardPage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/wizards/UpdateMakeProjectWizardPage.java @@ -8,16 +8,11 @@ ***********************************************************************/ package org.eclipse.cdt.make.ui.wizards; -import java.util.Vector; - -import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.internal.ui.part.WizardCheckboxTablePart; import org.eclipse.cdt.make.internal.ui.wizards.StatusWizardPage; -import org.eclipse.core.resources.ICommand; +import org.eclipse.cdt.make.ui.actions.UpdateMakeProjectAction; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.CheckboxTableViewer; @@ -41,7 +36,7 @@ public class UpdateMakeProjectWizardPage extends StatusWizardPage { public class MakeProjectContentProvider implements IStructuredContentProvider { public Object[] getElements(Object parent) { - return getProjects(); + return UpdateMakeProjectAction.getOldProjects(); } public void dispose() { @@ -112,31 +107,9 @@ public class UpdateMakeProjectWizardPage extends StatusWizardPage { updateStatus(genStatus); } - protected IProject[] getProjects() { - IProject[] project = MakeUIPlugin.getWorkspace().getRoot().getProjects(); - Vector result = new Vector(); - try { - for (int i = 0; i < project.length; i++) { - if (project[i].isAccessible()) { - IProjectDescription desc = project[i].getDescription(); - ICommand builder[] = desc.getBuildSpec(); - for (int j = 0; j < builder.length; j++) { - if (builder[j].getBuilderName().equals(MakeCorePlugin.OLD_BUILDER_ID)) { - result.add(project[i]); - break; - } - } - } - } - } catch (CoreException e) { - MakeUIPlugin.logException(e); - } - - return (IProject[]) result.toArray(new IProject[result.size()]); - } private IStatus validatePlugins() { - Object[] allModels = getProjects(); + Object[] allModels = UpdateMakeProjectAction.getOldProjects(); if (allModels == null || allModels.length == 0) { return createStatus(IStatus.ERROR, "No projects to update"); }