]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Limit the amount of file names shown in the text widget. 11/3011/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 9 Jul 2019 15:24:34 +0000 (18:24 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 9 Jul 2019 15:24:34 +0000 (18:24 +0300)
Also, prevent updating text widget when user is editing it.

gitlab #311

Change-Id: I9be75957064680affea15344649fe2aa0f5b08d1

bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileOrDirectorySelectionWidget.java
bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileSelectionWidget.java

index d685b7af05d5be6605d66ca7be7c74b1f4197857..19390e5667f82c6d3c4abab2f4eae943874efee9 100644 (file)
@@ -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;
index 4acbf1cff206bcfcb50b6a66499e7de9b5f2bb13..ef385ba0a425dc2fd2b2328e3311f023852aa89e 100644 (file)
@@ -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;