You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2012/07/27 17:22:42 UTC

svn commit: r1366416 - in /pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra: TerraFileBrowserSheetSkin.java terra_file_browser_sheet_skin.bxml

Author: smartini
Date: Fri Jul 27 15:22:41 2012
New Revision: 1366416

URL: http://svn.apache.org/viewvc?rev=1366416&view=rev
Log:
PIVOT-865: Crash in TerraFileBrowserSheetSkin when specifying a relative path and file name in the SAVE_AS mode text input field.
This is also a follow-on to PIVOT-825 which was an earlier case of a crash here.

Modified:
    pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSheetSkin.java
    pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.bxml

Modified: pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSheetSkin.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSheetSkin.java?rev=1366416&r1=1366415&r2=1366416&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSheetSkin.java (original)
+++ pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSheetSkin.java Fri Jul 27 15:22:41 2012
@@ -36,6 +36,7 @@ import org.apache.pivot.wtk.FileBrowser;
 import org.apache.pivot.wtk.FileBrowserListener;
 import org.apache.pivot.wtk.FileBrowserSheet;
 import org.apache.pivot.wtk.FileBrowserSheetListener;
+import org.apache.pivot.wtk.Form;
 import org.apache.pivot.wtk.Mouse;
 import org.apache.pivot.wtk.PushButton;
 import org.apache.pivot.wtk.Sheet;
@@ -109,6 +110,7 @@ public class TerraFileBrowserSheetSkin e
         saveAsTextInput.getTextInputContentListeners().add(new TextInputContentListener.Adapter() {
             @Override
             public void textChanged(TextInput textInput) {
+                Form.clearFlag(saveAsBoxPane);
                 updateOKButtonState();
             }
         });
@@ -263,7 +265,7 @@ public class TerraFileBrowserSheetSkin e
 
     @Override
     public Vote previewSheetClose(final Sheet sheet, final boolean result) {
-        Vote vote;
+        Vote vote = null;
 
         if (result
             && !okButton.isEnabled()) {
@@ -285,27 +287,61 @@ public class TerraFileBrowserSheetSkin e
 
                     case SAVE_AS: {
                         String fileName = saveAsTextInput.getText();
+                        // Contents of the entry field could be:
+                        // 1. Just a new file name in the current root directory
+                        // 2. A relative or absolute path that is an existing directory
+                        //    to navigate to
+                        // 3. A relative or absolute path including the new file name
+                        //    in an existing directory
+                        // So, first make it an absolute path
                         File selectedFile = new File(fileName);
-                        File parentFile = selectedFile.getParentFile();
-                        if (parentFile == null) {
+                        if (!selectedFile.isAbsolute() && !fileName.startsWith(File.separator)) {
                             selectedFile = new File(fileBrowser.getRootDirectory(), fileName);
                         } else {
-                            if (parentFile.isAbsolute() || parentFile.getPath().startsWith(File.separator)) {
-                                fileBrowserSheet.setRootDirectory(parentFile.getAbsoluteFile());
+                            selectedFile = selectedFile.getAbsoluteFile();
+                        }
+                        if (selectedFile.exists() && selectedFile.isDirectory()) {
+                            try {
+                                File root = selectedFile.getCanonicalFile();
+                                fileBrowserSheet.setRootDirectory(root);
+                                fileBrowser.setRootDirectory(root);
+                                saveAsTextInput.setText("");
+                            } catch (IOException ioe) {
+                                Form.setFlag(saveAsBoxPane, new Form.Flag());
+                            }
+                            selectedFile = null;
+                            vote = Vote.DENY;
+                        } else {
+                            File root = selectedFile.getParentFile();
+                            if (root != null && root.exists() && root.isDirectory()) {
+                                try {
+                                    fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
+                                    selectedFile = new File(selectedFile.getName());
+                                }
+                                catch (IOException ioe) {
+                                    Form.setFlag(saveAsBoxPane, new Form.Flag());
+                                    selectedFile = null;
+                                    vote = Vote.DENY;
+                                }
                             } else {
-                                fileBrowserSheet.setRootDirectory(new File(fileBrowser.getRootDirectory(), parentFile.getName()));
-                                selectedFile = new File(selectedFile.getName());
+                                // Could be an error message here ("Directory does not exist")
+                                Form.setFlag(saveAsBoxPane, new Form.Flag());
+                                selectedFile = null;
+                                vote = Vote.DENY;
                             }
                         }
-                        fileBrowserSheet.setSelectedFiles(new ArrayList<File>(selectedFile));
+                        if (selectedFile != null) {
+                            fileBrowserSheet.setSelectedFiles(new ArrayList<File>(selectedFile));
+                        }
                         break;
                     }
                 }
 
                 updatingSelection = false;
             }
-
-            vote = super.previewSheetClose(sheet, result);
+            if (vote == null) {
+                vote = super.previewSheetClose(sheet, result);
+            }
         }
 
         return vote;

Modified: pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.bxml
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.bxml?rev=1366416&r1=1366415&r2=1366416&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.bxml (original)
+++ pivot/branches/2.0.x/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.bxml Fri Jul 27 15:22:41 2012
@@ -25,13 +25,17 @@ limitations under the License.
         </columns>
 
         <TablePane.Row height="-1">
-            <BoxPane bxml:id="saveAsBoxPane" orientation="vertical" styles="{fill:true}">
-                <BoxPane styles="{verticalAlignment:'center'}">
-                    <Label text="%saveAs"/>
-                    <TextInput bxml:id="saveAsTextInput" textSize="32"/>
-                </BoxPane>
-                <Separator styles="{padding:2}"/>
-            </BoxPane>
+            <Form>
+                <Form.Section>
+                    <BoxPane bxml:id="saveAsBoxPane" orientation="vertical" styles="{fill:true}">
+                        <BoxPane styles="{verticalAlignment:'center'}">
+                            <Label text="%saveAs"/>
+                            <TextInput bxml:id="saveAsTextInput" textSize="32"/>
+                        </BoxPane>
+                        <Separator styles="{padding:2}"/>
+                    </BoxPane>
+                </Form.Section>
+            </Form>
         </TablePane.Row>
 
         <TablePane.Row height="1*">