summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorCalixte DENIZET <calixte@contrib.scilab.org>2011-04-21 17:16:09 +0200
committerVincent COUVERT <vincent.couvert@scilab.org>2011-05-06 11:11:54 +0200
commitb57bafc8e089d7be0aa4c99a5da64328580781e2 (patch)
tree53186608d8424bf12c37ac009cb84f8fedfd55ba /scilab/modules
parenta441ccc87520c803497d91b70b193e90ec2c350e (diff)
downloadscilab-b57bafc8e089d7be0aa4c99a5da64328580781e2.zip
scilab-b57bafc8e089d7be0aa4c99a5da64328580781e2.tar.gz
Bug 9340 fixed: Bad name was proposed when exporting in PDF
Change-Id: Ibfcc24263e4c4830f2e17fe39f63f8eeb4f678c9
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ExportAction.java43
1 files changed, 39 insertions, 4 deletions
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ExportAction.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ExportAction.java
index 6c42d34..e4d23fd 100644
--- a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ExportAction.java
+++ b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ExportAction.java
@@ -13,6 +13,8 @@
13package org.scilab.modules.scinotes.actions; 13package org.scilab.modules.scinotes.actions;
14 14
15import java.awt.Cursor; 15import java.awt.Cursor;
16import java.beans.PropertyChangeEvent;
17import java.beans.PropertyChangeListener;
16import java.io.File; 18import java.io.File;
17 19
18import javax.swing.JFileChooser; 20import javax.swing.JFileChooser;
@@ -46,6 +48,7 @@ public class ExportAction extends DefaultAction {
46 private static final String DOT = "."; 48 private static final String DOT = ".";
47 49
48 private boolean codeConverterLoaded; 50 private boolean codeConverterLoaded;
51 private File currentFile;
49 52
50 /** 53 /**
51 * Default constructor 54 * Default constructor
@@ -77,7 +80,7 @@ public class ExportAction extends DefaultAction {
77 SciFileFilter epsFilter = new SciFileFilter("*.eps", null, 2); 80 SciFileFilter epsFilter = new SciFileFilter("*.eps", null, 2);
78 SciFileFilter rtfFilter = new SciFileFilter("*.rtf", null, 3); 81 SciFileFilter rtfFilter = new SciFileFilter("*.rtf", null, 3);
79 82
80 SwingScilabFileChooser fileChooser = ((SwingScilabFileChooser) ScilabFileChooser.createFileChooser().getAsSimpleFileChooser()); 83 final SwingScilabFileChooser fileChooser = ((SwingScilabFileChooser) ScilabFileChooser.createFileChooser().getAsSimpleFileChooser());
81 84
82 fileChooser.setInitialDirectory(ConfigManager.getLastOpenedDirectory()); 85 fileChooser.setInitialDirectory(ConfigManager.getLastOpenedDirectory());
83 fileChooser.setAcceptAllFileFilterUsed(false); 86 fileChooser.setAcceptAllFileFilterUsed(false);
@@ -95,15 +98,47 @@ public class ExportAction extends DefaultAction {
95 fileChooser.setFileFilter(pdfFilter); 98 fileChooser.setFileFilter(pdfFilter);
96 fileChooser.setTitle(title); 99 fileChooser.setTitle(title);
97 100
101 fileChooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() {
102 public void propertyChange(PropertyChangeEvent e) {
103 Object val = e.getNewValue();
104 if (val != null && (val instanceof SciFileFilter)) {
105 String filter = ((SciFileFilter) val).getDescription();
106 String file = currentFile.getName();
107 int dotpos = file.lastIndexOf(".");
108 if (dotpos != -1) {
109 file = file.substring(0, dotpos);
110 }
111 dotpos = filter.lastIndexOf(".");
112 if (dotpos != -1) {
113 filter = filter.substring(dotpos, filter.length() - 1);
114 }
115 fileChooser.setSelectedFile(new File(file + filter));
116 }
117 }
118 });
119
120 fileChooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY , new PropertyChangeListener() {
121 public void propertyChange(PropertyChangeEvent e) {
122 Object val = e.getNewValue();
123 if (val != null && (val instanceof File)) {
124 currentFile = (File) val;
125 }
126 }
127 });
128
98 String name = getEditor().getTextPane().getName(); 129 String name = getEditor().getTextPane().getName();
99 if (name == null) { 130 if (name == null) {
100 name = ((ScilabDocument) getEditor().getTextPane().getDocument()).getFirstFunctionName(); 131 name = ((ScilabDocument) getEditor().getTextPane().getDocument()).getFirstFunctionName();
101 if (name != null) { 132 if (name == null) {
102 name += ".pdf"; 133 name = "";
103 } 134 }
104 } 135 }
105 136 int dotpos = name.lastIndexOf(".");
137 if (dotpos != -1) {
138 name = name.substring(0, dotpos);
139 }
106 if (name != null) { 140 if (name != null) {
141 name += ".pdf";
107 fileChooser.setSelectedFile(new File(name)); 142 fileChooser.setSelectedFile(new File(name));
108 } 143 }
109 144