1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed initialization of the folder text box in the New Source File

dialog.
This commit is contained in:
sprigogin 2012-03-27 23:09:59 -04:00
parent faf497d361
commit e6f0a47c44

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 QNX Software Systems and others. * Copyright (c) 2004, 2012 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -70,6 +70,7 @@ import org.eclipse.cdt.internal.ui.preferences.CodeTemplatePreferencePage;
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider; import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
import org.eclipse.cdt.internal.ui.wizards.NewElementWizardPage; import org.eclipse.cdt.internal.ui.wizards.NewElementWizardPage;
import org.eclipse.cdt.internal.ui.wizards.SourceFolderSelectionDialog; import org.eclipse.cdt.internal.ui.wizards.SourceFolderSelectionDialog;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassWizardUtil;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ComboDialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ComboDialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
@ -83,14 +84,14 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
private static final int MAX_FIELD_CHARS = 50; private static final int MAX_FIELD_CHARS = 50;
private static final String NO_TEMPLATE = ""; //$NON-NLS-1$ private static final String NO_TEMPLATE = ""; //$NON-NLS-1$
private IWorkspaceRoot fWorkspaceRoot; private final IWorkspaceRoot fWorkspaceRoot;
// field IDs // field IDs
private static final int SOURCE_FOLDER_ID = 1; private static final int SOURCE_FOLDER_ID = 1;
protected static final int NEW_FILE_ID = 2; protected static final int NEW_FILE_ID = 2;
private static final int ALL_FIELDS = SOURCE_FOLDER_ID | NEW_FILE_ID; private static final int ALL_FIELDS = SOURCE_FOLDER_ID | NEW_FILE_ID;
int fLastFocusedField = 0; int fLastFocusedField = 0;
private StringButtonDialogField fSourceFolderDialogField; private final StringButtonDialogField fSourceFolderDialogField;
private IStatus fSourceFolderStatus; private IStatus fSourceFolderStatus;
private IStatus fNewFileStatus; private IStatus fNewFileStatus;
private final IStatus STATUS_OK = new StatusInfo(); private final IStatus STATUS_OK = new StatusInfo();
@ -383,28 +384,20 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
* @param elem the C element used to compute the initial folder * @param elem the C element used to compute the initial folder
*/ */
protected void initSourceFolder(ICElement elem) { protected void initSourceFolder(ICElement elem) {
ICContainer folder = null; IPath folderPath = null;
if (elem != null) { if (elem != null) {
folder = CModelUtil.getSourceFolder(elem); ICContainer folder = NewClassWizardUtil.getSourceFolder(elem);
if (folder == null) { if (folder == null) {
ICProject cproject = elem.getCProject(); ICProject cproject = elem.getCProject();
if (cproject != null) { if (cproject != null) {
try { folder = NewClassWizardUtil.getFirstSourceRoot(cproject);
if (cproject.exists()) {
ISourceRoot[] roots = cproject.getSourceRoots();
if (roots != null && roots.length > 0)
folder = roots[0];
}
} catch (CModelException e) {
CUIPlugin.log(e);
}
if (folder == null) {
folder = cproject.findSourceRoot(cproject.getResource());
} }
} }
if (folder != null) {
folderPath = folder.getResource().getFullPath();
} }
} }
setSourceFolderFullPath(folder != null ? folder.getResource().getFullPath() : null, false); setSourceFolderFullPath(folderPath, false);
} }
/** /**
@ -448,7 +441,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
} }
protected final class StatusFocusListener implements FocusListener { protected final class StatusFocusListener implements FocusListener {
private int fieldID; private final int fieldID;
public StatusFocusListener(int fieldID) { public StatusFocusListener(int fieldID) {
this.fieldID = fieldID; this.fieldID = fieldID;