From: Marko Luukkainen Date: Tue, 9 Jul 2019 15:24:34 +0000 (+0300) Subject: Limit the amount of file names shown in the text widget. X-Git-Tag: v1.43.0~136^2~138 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f015145947a0aaf44bd11f8dab45aef96feed149;p=simantics%2Fplatform.git Limit the amount of file names shown in the text widget. Also, prevent updating text widget when user is editing it. gitlab #311 Change-Id: I9be75957064680affea15344649fe2aa0f5b08d1 --- diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileOrDirectorySelectionWidget.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileOrDirectorySelectionWidget.java index d685b7af0..19390e566 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileOrDirectorySelectionWidget.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileOrDirectorySelectionWidget.java @@ -53,7 +53,7 @@ public abstract class FileOrDirectorySelectionWidget extends Composite{ public void widgetSelected(SelectionEvent e) { String[] name = openDialog(); if (name != null) { - setFilename(name); + setFilename(name,true); } } }); @@ -63,7 +63,11 @@ public abstract class FileOrDirectorySelectionWidget extends Composite{ @Override public void modifyText(ModifyEvent e) { String file = fileText.getText(); - setFilename(file.split(",")); + String files[] = file.split(","); + for (int i = 0; i < files.length; i++) { + files[i] = files[i].trim(); + } + setFilename(files, false); } }); @@ -74,14 +78,22 @@ public abstract class FileOrDirectorySelectionWidget extends Composite{ protected abstract boolean isValid(File file); protected void setFilename(String[] filename) { + setFilename(filename, true); + } + + protected void setFilename(String[] filename, boolean update) { String text = ""; - for (String s : filename) { - text += s + ","; + if (filename.length < 6) { + for (String s : filename) { + text += s + ","; + } + if (text.length() > 2) + text = text.substring(0, text.length() - 1); + } else { + text = filename[0] + " and " + (filename.length -1) + " other files."; } - if (text.length() > 2) - text = text.substring(0, text.length() - 1); - if (!text.equals(fileText.getText())) + if (update && !text.equals(fileText.getText())) fileText.setText(text); boolean accept = true; diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileSelectionWidget.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileSelectionWidget.java index 4acbf1cff..ef385ba0a 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileSelectionWidget.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileSelectionWidget.java @@ -23,6 +23,8 @@ public class FileSelectionWidget extends FileOrDirectorySelectionWidget { FileDialog dialog = new FileDialog(getShell(),style); dialog.setFilterExtensions(getFilterExtensions()); dialog.setFilterNames(getFilterNames()); + if (filename != null && filename.length == 1) + dialog.setFileName(filename[0]); String filename = dialog.open(); if (filename == null) return null;