1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

bug 301732: When a Hello World project is created, open generated file automatically

Patch from Marc-Andre Laperle
This commit is contained in:
Andrew Gvozdev 2010-02-22 15:46:36 +00:00
parent a32879bdc0
commit 8a6292bcf4
8 changed files with 150 additions and 2 deletions

View file

@ -61,5 +61,14 @@
</complex-array>
</process>
<process type="org.eclipse.cdt.ui.OpenFiles">
<simple name="projectName" value="$(projectName)"/>
<complex-array name="files">
<element>
<simple name="target" value="$(sourceDir)/$(projectName).c"/>
</element>
</complex-array>
</process>
</template>

View file

@ -59,5 +59,14 @@
</complex-array>
</process>
<process type="org.eclipse.cdt.ui.OpenFiles">
<simple name="projectName" value="$(projectName)"/>
<complex-array name="files">
<element>
<simple name="target" value="$(sourceDir)/$(projectName).cpp"/>
</element>
</complex-array>
</process>
</template>

View file

@ -40,7 +40,16 @@
</element>
</complex-array>
</process>
<process type="org.eclipse.cdt.ui.OpenFiles">
<simple name="projectName" value="$(projectName)"/>
<complex-array name="files">
<element>
<simple name="target" value="$(projectName).cpp"/>
</element>
</complex-array>
</process>
<process type="org.eclipse.cdt.managedbuilder.gnu.ui.SimpleGNUMakefileGenerator">
<simple name="projectName" value="$(projectName)"/>
</process>

View file

@ -34,8 +34,8 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
org.eclipse.cdt.internal.ui.refactoring;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.dialogs;x-internal:=true,
org.eclipse.cdt.internal.ui.refactoring.extractconstant;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.extractfunction;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.hidemethod;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.implementmethod;x-friends:="org.eclipse.cdt.ui.tests",
@ -77,6 +77,7 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
org.eclipse.cdt.ui.templateengine,
org.eclipse.cdt.ui.templateengine.event,
org.eclipse.cdt.ui.templateengine.pages,
org.eclipse.cdt.ui.templateengine.processes,
org.eclipse.cdt.ui.templateengine.uitree,
org.eclipse.cdt.ui.templateengine.uitree.uiwidgets,
org.eclipse.cdt.ui.text,

View file

@ -3500,4 +3500,22 @@
</activeWhen>
</handler>
</extension>
<extension
point="org.eclipse.cdt.core.templateProcessTypes">
<processType
name="OpenFiles"
processRunner="org.eclipse.cdt.ui.templateengine.processes.OpenFiles">
<simple
name="projectName">
</simple>
<complexArray
name="files">
<baseType>
<simple
name="target">
</simple>
</baseType>
</complexArray>
</processType>
</extension>
</plugin>

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2010 Marc-Andre Laperle 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:
* Marc-Andre Laperle - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.templateengine.processes;
import org.eclipse.osgi.util.NLS;
/**
* @since 5.2
*/
public class Messages {
private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.templateengine.processes.messages"; //$NON-NLS-1$
private Messages() {
}
public static String OpenFiles_CannotOpen_error;
public static String OpenFiles_FileNotExist_error;
static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2010 Marc-Andre Laperle 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:
* Marc-Andre Laperle - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.templateengine.processes;
import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
/**
* This process opens files in the editor
*
* @since 5.2
*/
public class OpenFiles extends ProcessRunner {
/**
* This method opens a list of files in the editor
*/
@Override
public void process(TemplateCore template, ProcessArgument[] args, String processId,
IProgressMonitor monitor) throws ProcessFailureException {
ProcessArgument[][] files = args[1].getComplexArrayValue();
for (ProcessArgument[] file : files) {
String fileTargetPath = file[0].getSimpleValue();
String projectName = args[0].getSimpleValue();
IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IFile iFile = projectHandle.getFile(fileTargetPath);
if (iFile.exists()) {
try {
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
iFile);
} catch (PartInitException e) {
throw new ProcessFailureException(Messages.OpenFiles_CannotOpen_error + fileTargetPath);
}
}
else {
throw new ProcessFailureException(Messages.OpenFiles_FileNotExist_error + fileTargetPath);
}
}
}
}

View file

@ -0,0 +1,13 @@
###############################################################################
# Copyright (c) 2010 Marc-Andre Laperle 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:
# Marc-Andre Laperle - Initial API and implementation
###############################################################################
OpenFiles_CannotOpen_error=Open file failure: Cannot open file:
OpenFiles_FileNotExist_error=Open file failure: No such file exists: