From be1a78cd90002aa3ad267505dac984389c638bec Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 30 Mar 2011 18:22:05 +0000 Subject: [PATCH] bug 341362: C/C++ General > Paths & Symbols > Include Files > Add... > File system... file filter is broken --- .../cdt/ui/newui/AbstractCPropertyTab.java | 12 ++++- .../org/eclipse/cdt/ui/newui/ExpDialog.java | 9 +++- .../eclipse/cdt/ui/newui/IncludeDialog.java | 44 ++++++++++++++----- .../eclipse/cdt/ui/newui/IncludeFileTab.java | 20 ++++++--- .../org/eclipse/cdt/ui/newui/LibraryTab.java | 15 ++++--- 5 files changed, 77 insertions(+), 23 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java index 273a4e73d95..2ff7b9cd963 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractCPropertyTab.java @@ -414,11 +414,21 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab { public static String getFileSystemFileDialog(Shell shell, String text) { FileDialog dialog = new FileDialog(shell); if(text != null && text.trim().length() != 0) dialog.setFilterPath(text); - dialog.setFilterExtensions(new String[] {"*.a;*.so;*.dll;*.lib"}); //$NON-NLS-1$ dialog.setText(FILESYSTEM_FILE_DIALOG_TITLE); return dialog.open(); } + /** + * @since 5.3 + */ + public static String getFileSystemFileDialog(Shell shell, String text, String[] filter) { + FileDialog dialog = new FileDialog(shell); + if(text != null && text.trim().length() != 0) dialog.setFilterPath(text); + dialog.setFilterExtensions(filter); + dialog.setText(FILESYSTEM_FILE_DIALOG_TITLE); + return dialog.open(); + } + public static String getVariableDialog(Shell shell, ICConfigurationDescription cfgd) { ICdtVariableManager vm = CCorePlugin.getDefault().getCdtVariableManager(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpDialog.java index afed4790cb2..45d01e9ffe1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpDialog.java @@ -282,10 +282,15 @@ public class ExpDialog extends AbstractPropertyDialog { } } else if (e.widget.equals(b_file)) { if (kind == ICSettingEntry.INCLUDE_PATH || - kind == ICSettingEntry.LIBRARY_PATH) + kind == ICSettingEntry.LIBRARY_PATH) { s = AbstractCPropertyTab.getFileSystemDirDialog(shell, txt2.getText()); - else + } else if (kind==ICSettingEntry.INCLUDE_FILE) { + s = AbstractCPropertyTab.getFileSystemFileDialog(shell, txt2.getText(), IncludeDialog.FILTER_INCLUDE_FILE); + } else if (kind==ICSettingEntry.LIBRARY_FILE) { + s = AbstractCPropertyTab.getFileSystemFileDialog(shell, txt2.getText(), IncludeDialog.FILTER_LIBRARY_FILE); + } else { s = AbstractCPropertyTab.getFileSystemFileDialog(shell, txt2.getText()); + } if (s != null) { txt2.setText(s); c_wsp.setSelection(false); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/IncludeDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/IncludeDialog.java index 5fa27b424cd..e97b30895ac 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/IncludeDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/IncludeDialog.java @@ -34,9 +34,16 @@ import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.internal.ui.newui.Messages; /** + * A combined dialog which allows selecting file or folder from workspace or filesystem + * and some more features. The dialog is used on "Paths and Symbols" properties page. + * Note that currently it is used not only for include files/folders but for library + * files/folders as well. + * * @noextend This class is not intended to be subclassed by clients. */ public class IncludeDialog extends AbstractPropertyDialog { + static final String[] FILTER_INCLUDE_FILE = new String[] {"*.h;*.hpp", "*"}; //$NON-NLS-1$ //$NON-NLS-2$ + static final String[] FILTER_LIBRARY_FILE = new String[] {"*.a;*.so;*.dll;*.lib", "*"}; //$NON-NLS-1$ //$NON-NLS-2$ public String sdata; private Button b_add2confs; private Button b_add2langs; @@ -50,6 +57,7 @@ public class IncludeDialog extends AbstractPropertyDialog { private Button c_wsp; private ICConfigurationDescription cfgd; private boolean isWsp = false; + private int kind = 0; static final int NEW_FILE = 0; static final int NEW_DIR = 1; @@ -59,14 +67,24 @@ public class IncludeDialog extends AbstractPropertyDialog { static final int DIR_MASK = 1; static final int OLD_MASK = 2; - public IncludeDialog(Shell parent, int _mode, - String title, String _data, ICConfigurationDescription _cfgd, int flags) { + /** + * @since 5.3 + */ + public IncludeDialog(Shell parent, int mode, String title, String data, + ICConfigurationDescription cfgd, int flags, int kind) { + super(parent, title); - mode = _mode; - sdata = _data; - cfgd = _cfgd; - if (flags == ICSettingEntry.VALUE_WORKSPACE_PATH) - isWsp = true; + this.mode = mode; + this.sdata = data; + this.cfgd = cfgd; + this.isWsp = (flags == ICSettingEntry.VALUE_WORKSPACE_PATH); + this.kind = kind; + } + + public IncludeDialog(Shell parent, int mode, String title, String data, + ICConfigurationDescription cfgd, int flags) { + + this(parent, mode, title, data, cfgd, flags, 0); } @Override @@ -193,10 +211,16 @@ public class IncludeDialog extends AbstractPropertyDialog { c_wsp.setImage(getWspImage(c_wsp.getSelection())); } } else if (e.widget.equals(b_file)) { - if ((mode & DIR_MASK)== DIR_MASK) + if ((mode & DIR_MASK)== DIR_MASK) { s = AbstractCPropertyTab.getFileSystemDirDialog(shell, text.getText()); - else - s = AbstractCPropertyTab.getFileSystemFileDialog(shell, text.getText()); + } else { + if (kind==ICSettingEntry.INCLUDE_FILE) + s = AbstractCPropertyTab.getFileSystemFileDialog(shell, text.getText(), FILTER_INCLUDE_FILE); + else if (kind==ICSettingEntry.LIBRARY_FILE) + s = AbstractCPropertyTab.getFileSystemFileDialog(shell, text.getText(), FILTER_LIBRARY_FILE); + else + s = AbstractCPropertyTab.getFileSystemFileDialog(shell, text.getText()); + } if (s != null) { text.setText(s); c_wsp.setSelection(false); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/IncludeFileTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/IncludeFileTab.java index d5dcac386ae..a494da528a3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/IncludeFileTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/IncludeFileTab.java @@ -53,8 +53,14 @@ public class IncludeFileTab extends AbstractLangsListTab { @Override public ICLanguageSettingEntry doAdd() { - IncludeDialog dlg = new IncludeDialog(usercomp.getShell(), IncludeDialog.NEW_FILE, Messages.IncludeFileTab_1, - EMPTY_STR, getResDesc().getConfiguration(), 0); + IncludeDialog dlg = new IncludeDialog( + usercomp.getShell(), + IncludeDialog.NEW_FILE, + Messages.IncludeFileTab_1, + EMPTY_STR, + getResDesc().getConfiguration(), + 0, + ICSettingEntry.INCLUDE_FILE); if (dlg.open() && dlg.text1.trim().length() > 0) { toAllCfgs = dlg.check1; toAllLang = dlg.check3; @@ -69,10 +75,14 @@ public class IncludeFileTab extends AbstractLangsListTab { @Override public ICLanguageSettingEntry doEdit(ICLanguageSettingEntry ent) { - IncludeDialog dlg = new IncludeDialog(usercomp.getShell(), IncludeDialog.OLD_FILE, + IncludeDialog dlg = new IncludeDialog( + usercomp.getShell(), + IncludeDialog.OLD_FILE, Messages.IncludeFileTab_2, - ent.getValue(), getResDesc().getConfiguration(), - (ent.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH)); + ent.getValue(), + getResDesc().getConfiguration(), + ent.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH, + ICSettingEntry.INCLUDE_FILE); if (dlg.open()) { int flags = 0; if (dlg.check2) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryTab.java index 9f47bee0f7f..9292bfed764 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryTab.java @@ -48,8 +48,11 @@ public class LibraryTab extends AbstractLangsListTab implements IPathEntryStoreL public ICLanguageSettingEntry doAdd() { IncludeDialog dlg = new IncludeDialog( usercomp.getShell(), IncludeDialog.NEW_FILE, - Messages.LibraryTab_1, - EMPTY_STR, getResDesc().getConfiguration(), 0); + Messages.LibraryTab_1, + EMPTY_STR, + getResDesc().getConfiguration(), + 0, + ICSettingEntry.LIBRARY_FILE); if (dlg.open() && dlg.text1.trim().length() > 0 ) { toAllCfgs = dlg.check1; toAllLang = dlg.check3; @@ -64,9 +67,11 @@ public class LibraryTab extends AbstractLangsListTab implements IPathEntryStoreL public ICLanguageSettingEntry doEdit(ICLanguageSettingEntry ent) { IncludeDialog dlg = new IncludeDialog( usercomp.getShell(), IncludeDialog.OLD_FILE, - Messages.LibraryTab_2, - ent.getValue(), getResDesc().getConfiguration(), - (ent.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH)); + Messages.LibraryTab_2, + ent.getValue(), + getResDesc().getConfiguration(), + ent.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH, + ICSettingEntry.LIBRARY_FILE); if (dlg.open() && dlg.text1.trim().length() > 0 ) { int flags = 0; if (dlg.check2) flags = ICSettingEntry.VALUE_WORKSPACE_PATH;