From: <mwl...@us...> - 2007-06-29 20:31:37
|
Revision: 408 http://svn.sourceforge.net/cishell/?rev=408&view=rev Author: mwlinnem Date: 2007-06-29 13:31:32 -0700 (Fri, 29 Jun 2007) Log Message: ----------- Fixed bug with suggested file names when saving. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2007-06-28 21:32:33 UTC (rev 407) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2007-06-29 20:31:32 UTC (rev 408) @@ -108,10 +108,9 @@ dialog.setText("Choose File"); String fileLabel = (String)data.getMetaData().get(DataProperty.LABEL); - String suggestedFileName = getFileName(fileLabel); + String suggestedFileName = getFileName(fileLabel); dialog.setFileName(suggestedFileName + "." + ext); -// String fileLabel = (String)data.getMetaData().get(DataProperty.LABEL); -// + // if (fileLabel == null) { // dialog.setFileName("*." + ext); // } else { @@ -179,14 +178,36 @@ } private String getFileName(String fileLabel) { + + //index variables will be -1 if index is not found. int descriptionEndIndex = fileLabel.lastIndexOf(":"); int filePathEndIndex = fileLabel.lastIndexOf(File.separator); - int extensionBeginIndex = fileLabel.indexOf("."); - + + //doesn't matter if either variable is -1, since startIndex will be + //zero and none of the string will be cut off the front. int startIndex = Math.max(descriptionEndIndex, filePathEndIndex) + 1; - int endIndex = Math.min(extensionBeginIndex, fileLabel.length()); - String fileName = fileLabel.substring(startIndex, endIndex); + String fileNameWithExtension = fileLabel.substring(startIndex); + + + //find the first character of the file name extension. + int extensionBeginIndex = fileNameWithExtension.indexOf("."); + + int endIndex; + + if (extensionBeginIndex != -1) { + //we found a period in the file name. + endIndex = extensionBeginIndex; //cut off everything after + //first period. + } else { + //we didn't find an extension on the file name. + endIndex = fileLabel.length(); // don't cut any off the end. + } + endIndex = Math.min(extensionBeginIndex, fileLabel.length()); + + String fileNameWithoutExtension = fileNameWithExtension.substring(0, endIndex); + + String fileName = fileNameWithoutExtension; return fileName; } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |