2
* Created on 17-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.actions.file;
10
import java.io.FileNotFoundException;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.TypedEvent;
14
import org.eclipse.swt.widgets.Shell;
15
import org.herac.tuxguitar.gui.TuxGuitar;
16
import org.herac.tuxguitar.gui.actions.Action;
17
import org.herac.tuxguitar.gui.editors.TablatureEditor;
18
import org.herac.tuxguitar.gui.helper.SyncThread;
19
import org.herac.tuxguitar.gui.util.ConfirmDialog;
20
import org.herac.tuxguitar.gui.util.FileChooser;
21
import org.herac.tuxguitar.io.exporter.ASCIITabOutputStream;
26
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
28
public class ExportASCIIAction extends Action {
29
public static final String NAME = "action.file.export-ascii";
31
public ExportASCIIAction(TablatureEditor tablatureEditor) {
32
super(NAME,tablatureEditor);
35
public boolean doAction(TypedEvent e) {
36
Shell parent = getEditor().getTablature().getShell();
37
String selectedName = FileChooser.instance().save(parent,FileChooser.EXPORT_ASCII_FORMAT);
38
if (selectedName != null) {
39
boolean canWrite = true;
40
if (!isSuportedFormat(selectedName)) {
41
selectedName += getDefaultExtension();
43
final String fileName = selectedName;
45
File file = new File(fileName);
47
ConfirmDialog confirm = new ConfirmDialog(getEditor().getTablature().getShell(), TuxGuitar.getProperty("replace-file-question"));
49
if (!confirm.confirm()) {
55
getEditor().getTablature().changeCursor(SWT.CURSOR_WAIT);
56
new SyncThread(new Runnable() {
58
if(!TuxGuitar.isDisposed()){
60
new ASCIITabOutputStream(fileName).writeSong(getSongManager().getSong());
61
getEditor().getTablature().changeCursor(SWT.CURSOR_ARROW);
62
} catch (FileNotFoundException e) {
74
private boolean isSuportedFormat(String fileName) {
75
return (fileName.endsWith(getDefaultExtension()));
78
private String getDefaultExtension() {