diff options
author | Michael Valenta | 2007-09-12 14:02:58 +0000 |
---|---|---|
committer | Michael Valenta | 2007-09-12 14:02:58 +0000 |
commit | e36dc30036c051e090d960c48862e2748bc9ae3a (patch) | |
tree | 78e5c7c743f72447bc74865c50ca0fb3fe638888 /bundles | |
parent | 22b877756e97b633c174a5012c69811b03c3dc08 (diff) | |
download | eclipse.platform.team-e36dc30036c051e090d960c48862e2748bc9ae3a.tar.gz eclipse.platform.team-e36dc30036c051e090d960c48862e2748bc9ae3a.tar.xz eclipse.platform.team-e36dc30036c051e090d960c48862e2748bc9ae3a.zip |
Bug 199239 [Sync Info] Indicate issues when adding a file with spaces in it's name to .cvsignore
Diffstat (limited to 'bundles')
3 files changed, 184 insertions, 40 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java index 2ec126a1b..073e6ecf2 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java @@ -746,9 +746,13 @@ public class CVSUIMessages extends NLS { public static String CVSProjectSetSerializer_Confirm_Overwrite_Project_8; public static String CVSProjectSetSerializer_The_project__0__already_exists__Do_you_wish_to_overwrite_it__9; - public static String IgnoreResourcesDialog_titleSingle; - public static String IgnoreResourcesDialog_titleMany; - public static String IgnoreResourcesDialog_prompt; + public static String IgnoreResourcesDialog_dialogTitle; + public static String IgnoreResourcesDialog_title; + public static String IgnoreResourcesDialog_messageSingle; + public static String IgnoreResourcesDialog_messageMany; + public static String IgnoreResourcesDialog_filesWithSpaceWarningMessage; + public static String IgnoreResourcesDialog_filesWithSpaceWarning; + public static String IgnoreResourcesDialog_filesWithNoExtensionWarningMessage; public static String IgnoreResourcesDialog_addNameEntryButton; public static String IgnoreResourcesDialog_addNameEntryExample; public static String IgnoreResourcesDialog_addExtensionEntryButton; diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/IgnoreResourcesDialog.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/IgnoreResourcesDialog.java index 045737523..041b1e36a 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/IgnoreResourcesDialog.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/IgnoreResourcesDialog.java @@ -12,17 +12,17 @@ package org.eclipse.team.internal.ccvs.ui; import org.eclipse.core.resources.IResource; import org.eclipse.jface.dialogs.*; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.resource.JFaceColors; +import org.eclipse.jface.fieldassist.*; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.*; import org.eclipse.team.internal.ccvs.core.util.FileNameMatcher; import org.eclipse.ui.PlatformUI; -public class IgnoreResourcesDialog extends TrayDialog { +public class IgnoreResourcesDialog extends TitleAreaDialog { // resources that should be ignored private IResource[] resources; @@ -40,13 +40,22 @@ public class IgnoreResourcesDialog extends TrayDialog { private Button addExtensionEntryButton; private Button addCustomEntryButton; private Text customEntryText; - private Label statusMessageLabel; private int selectedAction; private String customPattern; // layout controls private static final int LABEL_INDENT_WIDTH = 32; + + /** + * Image for title area + */ + private Image dlgTitleImage = null; + + // to avoid an error/warning message at startup default values are as below + private boolean resourceWithSpaces = false; + private boolean allResourecesHaveExtensions = true; + private boolean allResourcesWithSpacesHaveExtensions = true; /** * Creates a new dialog for ignoring resources. @@ -58,9 +67,9 @@ public class IgnoreResourcesDialog extends TrayDialog { this.resources = resources; IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings(); - this.settings = workbenchSettings.getSection("IgnoreResourcesDialog");//$NON-NLS-1$ + this.settings = workbenchSettings.getSection("IgnoreResourcesDialog"); //$NON-NLS-1$ if (settings == null) { - this.settings = workbenchSettings.addNewSection("IgnoreResourcesDialog");//$NON-NLS-1$ + this.settings = workbenchSettings.addNewSection("IgnoreResourcesDialog"); //$NON-NLS-1$ } try { @@ -68,6 +77,10 @@ public class IgnoreResourcesDialog extends TrayDialog { } catch (NumberFormatException e) { selectedAction = ADD_NAME_ENTRY; } + + resourceWithSpaces = checkForResourcesWithSpaces(); + allResourecesHaveExtensions = checkIfAllResourcesHaveExtensions(); + allResourcesWithSpacesHaveExtensions = checkIfAllResourcesWithSpacesHaveExtensions(); } /** @@ -103,11 +116,7 @@ public class IgnoreResourcesDialog extends TrayDialog { */ protected void configureShell(Shell newShell) { super.configureShell(newShell); - if (resources.length == 1) { - newShell.setText(NLS.bind(CVSUIMessages.IgnoreResourcesDialog_titleSingle, new String[] { resources[0].getName() })); - } else { - newShell.setText(NLS.bind(CVSUIMessages.IgnoreResourcesDialog_titleMany, new String[] { Integer.toString(resources.length) })); - } + newShell.setText(CVSUIMessages.IgnoreResourcesDialog_dialogTitle); } /* (non-Javadoc) @@ -115,7 +124,13 @@ public class IgnoreResourcesDialog extends TrayDialog { */ protected Control createContents(Composite parent) { Control control = super.createContents(parent); + dlgTitleImage = CVSUIPlugin.getPlugin().getImageDescriptor( + ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION).createImage(); + setTitleImage(dlgTitleImage); updateEnablements(); + setTitle(CVSUIMessages.IgnoreResourcesDialog_title); + setErrorMessage(null); + setDefaultMessage(); return control; } @@ -123,13 +138,18 @@ public class IgnoreResourcesDialog extends TrayDialog { * Method declared on Dialog. */ protected Control createDialogArea(Composite parent) { - Composite top = new Composite(parent, SWT.NONE); - top.setLayout(new GridLayout()); + Composite top = new Composite((Composite) super + .createDialogArea(parent), SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + top.setLayout(layout); + top.setLayoutData(new GridData(GridData.FILL_BOTH)); PlatformUI.getWorkbench().getHelpSystem().setHelp(top, IHelpContextIds.ADD_TO_CVSIGNORE); - createIndentedLabel(top, CVSUIMessages.IgnoreResourcesDialog_prompt, 0); - Listener selectionListener = new Listener() { public void handleEvent(Event event) { updateEnablements(); @@ -144,23 +164,67 @@ public class IgnoreResourcesDialog extends TrayDialog { addNameEntryButton = createRadioButton(top, CVSUIMessages.IgnoreResourcesDialog_addNameEntryButton); addNameEntryButton.addListener(SWT.Selection, selectionListener); addNameEntryButton.setSelection(selectedAction == ADD_NAME_ENTRY); - createIndentedLabel(top, CVSUIMessages.IgnoreResourcesDialog_addNameEntryExample, LABEL_INDENT_WIDTH); + Label addNameEntryLabel = createIndentedLabel(top, CVSUIMessages.IgnoreResourcesDialog_addNameEntryExample, LABEL_INDENT_WIDTH); addExtensionEntryButton = createRadioButton(top, CVSUIMessages.IgnoreResourcesDialog_addExtensionEntryButton); addExtensionEntryButton.addListener(SWT.Selection, selectionListener); addExtensionEntryButton.setSelection(selectedAction == ADD_EXTENSION_ENTRY); - createIndentedLabel(top, CVSUIMessages.IgnoreResourcesDialog_addExtensionEntryExample, LABEL_INDENT_WIDTH); + Label addExtensionEntryLabel = createIndentedLabel(top, CVSUIMessages.IgnoreResourcesDialog_addExtensionEntryExample, LABEL_INDENT_WIDTH); addCustomEntryButton = createRadioButton(top, CVSUIMessages.IgnoreResourcesDialog_addCustomEntryButton); addCustomEntryButton.addListener(SWT.Selection, selectionListener); addCustomEntryButton.setSelection(selectedAction == ADD_CUSTOM_ENTRY); createIndentedLabel(top, CVSUIMessages.IgnoreResourcesDialog_addCustomEntryExample, LABEL_INDENT_WIDTH); - customEntryText = createIndentedText(top, resources[0].getName(), LABEL_INDENT_WIDTH); + if (resourceWithSpaces) { + customEntryText = createIndentedText(top, getResourceWithSpace() + .getName().replaceAll(" ", "?"), LABEL_INDENT_WIDTH); //$NON-NLS-1$ //$NON-NLS-2$ + ControlDecoration customEntryTextDecoration = new ControlDecoration( + customEntryText, SWT.TOP | SWT.LEAD); + FieldDecorationRegistry registry = FieldDecorationRegistry + .getDefault(); + FieldDecoration infoDecoration = registry + .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION); + customEntryTextDecoration.setImage(infoDecoration.getImage()); + customEntryTextDecoration + .setDescriptionText(CVSUIMessages.IgnoreResourcesDialog_filesWithSpaceWarning); + customEntryTextDecoration.setShowOnlyOnFocus(false); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalIndent = LABEL_INDENT_WIDTH + + FieldDecorationRegistry.getDefault() + .getMaximumDecorationWidth(); + customEntryText.setLayoutData(gridData); + customEntryText.setFocus(); + + addNameEntryButton.setEnabled(false); + addNameEntryLabel.setEnabled(false); + // switch selection to "Custom pattern" + if (!addCustomEntryButton.getSelection()) { + addNameEntryButton.setSelection(false); + addCustomEntryButton.setSelection(true); + selectedAction = ADD_CUSTOM_ENTRY; + } + + // when there is at least one resource without extension with spaces + // we should disable the "Wildcard extension" option + if (!allResourcesWithSpacesHaveExtensions) { + addExtensionEntryButton.setEnabled(false); + addExtensionEntryLabel.setEnabled(false); + // switch selection to "Custom pattern" which is always enabled + addExtensionEntryButton.setSelection(false); + addCustomEntryButton.setSelection(true); + selectedAction = ADD_CUSTOM_ENTRY; + } + + } else { + customEntryText = createIndentedText(top, resources[0].getName(), + LABEL_INDENT_WIDTH); + } + customEntryText.addListener(SWT.Modify, modifyListener); - statusMessageLabel = createIndentedLabel(top, "", 0); //$NON-NLS-1$ - Dialog.applyDialogFont(parent); + applyDialogFont(top); + return top; } @@ -224,18 +288,90 @@ public class IgnoreResourcesDialog extends TrayDialog { return; } } - } + if (resourceWithSpaces) { + setWarning(CVSUIMessages.IgnoreResourcesDialog_filesWithSpaceWarningMessage); + return; + } + } else if (selectedAction == ADD_EXTENSION_ENTRY && !allResourecesHaveExtensions) { + setWarning(CVSUIMessages.IgnoreResourcesDialog_filesWithNoExtensionWarningMessage); + return; + } setError(null); } + /** + * Sets an error message on the dialog. + * + * @param text + * A message to set. If <code>null</code> the error message + * will be cleared. + */ private void setError(String text) { - if (text == null) { - statusMessageLabel.setText(""); //$NON-NLS-1$ - getButton(IDialogConstants.OK_ID).setEnabled(true); + setErrorMessage(text); + // set a non-error message + if (text == null) + setDefaultMessage(); + getButton(IDialogConstants.OK_ID).setEnabled(text == null); + } + + private void setWarning(String text) { + setError(null); + setMessage(text, IMessageProvider.WARNING); + } + + private void setDefaultMessage() { + if (resources.length == 1) { + setMessage(NLS.bind( + CVSUIMessages.IgnoreResourcesDialog_messageSingle, + new String[] { resources[0].getName() })); } else { - statusMessageLabel.setText(text); - statusMessageLabel.setForeground(JFaceColors.getErrorText(getShell().getDisplay())); - getButton(IDialogConstants.OK_ID).setEnabled(false); + setMessage(NLS.bind( + CVSUIMessages.IgnoreResourcesDialog_messageMany, + new String[] { Integer.toString(resources.length) })); + } + } + + /** + * Check whether at least one of the given resources names contain a space. + * + * @param resources + * Array of resources to check. + * @return <code>true</code> if a resource filename containing space has + * been found, <code>false</code> otherwise. + */ + private boolean checkForResourcesWithSpaces() { + return getResourceWithSpace() != null; + } + + private IResource getResourceWithSpace() { + for (int i = 0; i < resources.length; i++) { + if (resources[i].getName().indexOf(" ") != -1) //$NON-NLS-1$ + return resources[i]; + } + return null; + } + + private boolean checkIfAllResourcesWithSpacesHaveExtensions() { + for (int i = 0; i < resources.length; i++) { + if (resources[i].getName().indexOf(" ") != -1 && resources[i].getFileExtension() == null) //$NON-NLS-1$ + return false; } + return true; } + + private boolean checkIfAllResourcesHaveExtensions() { + for (int i = 0; i < resources.length; i++) { + if (resources[i].getFileExtension() != null) + return true; + } + // couldn't find a resource with an extension + return false; + } + + public boolean close() { + if (dlgTitleImage != null) { + dlgTitleImage.dispose(); + } + return super.close(); + } } diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties index 4c0ff52fd..efa484c53 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties @@ -724,17 +724,21 @@ CVSRepositoryPropertiesPage_useCustomLabel=Use a custom &label: CVSProjectSetSerializer_Confirm_Overwrite_Project_8=Confirm Overwrite Project CVSProjectSetSerializer_The_project__0__already_exists__Do_you_wish_to_overwrite_it__9=The project {0} already exists. Do you wish to overwrite it? -IgnoreResourcesDialog_titleSingle=Add {0} to .cvsignore -IgnoreResourcesDialog_titleMany=Add {0} resources to .cvsignore -IgnoreResourcesDialog_prompt=Select what to add to the .cvsignore file(s): -IgnoreResourcesDialog_addNameEntryButton=Resource(s) by name -IgnoreResourcesDialog_addNameEntryExample=Examples: file1.so, file2.so, .rcfile, bin -IgnoreResourcesDialog_addExtensionEntryButton=Wildcard extension -IgnoreResourcesDialog_addExtensionEntryExample=Examples: *.so, *.rcfile, bin -IgnoreResourcesDialog_addCustomEntryButton=Custom pattern -IgnoreResourcesDialog_addCustomEntryExample=The wildcard characters '*' and '?' are permitted. +IgnoreResourcesDialog_dialogTitle=Add to .cvsignore +IgnoreResourcesDialog_title=.cvsignore +IgnoreResourcesDialog_messageSingle=You have chosen to ignore ''{0}''. Select what to add to the .cvsignore file. +IgnoreResourcesDialog_messageMany=You have chosen to ignore {0} resources. Select what to add to the .cvsignore file(s). +IgnoreResourcesDialog_filesWithSpaceWarningMessage=You want to ignore at least one filename which contains a space. +IgnoreResourcesDialog_filesWithSpaceWarning=There is no direct way to add a filename with spaces to a .cvsignore file,\nbut you can use a pattern with ? as initially suggested. However, please be aware\nthat this could potentially ignore other files which matches the pattern. +IgnoreResourcesDialog_filesWithNoExtensionWarningMessage=You want to ignore at least one with no extension. It's name will be used instead. +IgnoreResourcesDialog_addNameEntryButton=&Resource(s) by name +IgnoreResourcesDialog_addNameEntryExample=&Examples: file1.so, file2.so, .rcfile, bin +IgnoreResourcesDialog_addExtensionEntryButton=&Wildcard extension +IgnoreResourcesDialog_addExtensionEntryExample=E&xamples: *.so, *.rcfile, bin +IgnoreResourcesDialog_addCustomEntryButton=&Custom pattern +IgnoreResourcesDialog_addCustomEntryExample=&The wildcard characters '*' and '?' are permitted. IgnoreResourcesDialog_patternMustNotBeEmpty=Pattern must not be empty. -IgnoreResourcesDialog_patternDoesNotMatchFile=Pattern does not match all selected resources: e.g. {0} +IgnoreResourcesDialog_patternDoesNotMatchFile=Pattern does not match all selected resources: e.g. ''{0}''. CVSProjectPropertiesPage_You_can_change_the_sharing_of_this_project_to_another_repository_location__However__this_is_only_possible_if_the_new_location_is___compatible____on_the_same_host_with_the_same_repository_path___1=You can change the sharing of this project to another repository location. However, this is only possible if the new location is \"compatible\" (on the same host with the same repository path). |