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;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.TypedEvent;
14
import org.herac.tuxguitar.gui.TuxGuitar;
15
import org.herac.tuxguitar.gui.actions.Action;
16
import org.herac.tuxguitar.gui.actions.ActionLock;
17
import org.herac.tuxguitar.gui.helper.SyncThread;
18
import org.herac.tuxguitar.gui.util.ConfirmDialog;
19
import org.herac.tuxguitar.gui.util.FileChooser;
20
import org.herac.tuxguitar.io.base.TGFileFormatManager;
25
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
27
public class OpenFileAction extends Action {
28
public static final String NAME = "action.file.open";
30
public OpenFileAction() {
31
super(NAME, AUTO_LOCK | AUTO_UPDATE | KEY_BINDING_AVAILABLE);
34
protected int execute(final TypedEvent event){
35
TuxGuitar.instance().getPlayer().reset();
37
final Object data = event.widget.getData();
38
if(TuxGuitar.instance().getFileHistory().isUnsavedFile()){
39
ConfirmDialog confirm = new ConfirmDialog(TuxGuitar.getProperty("file.save-changes-question"));
40
confirm.setDefaultStatus( ConfirmDialog.STATUS_CANCEL );
41
int status = confirm.confirm(ConfirmDialog.BUTTON_YES | ConfirmDialog.BUTTON_NO | ConfirmDialog.BUTTON_CANCEL, ConfirmDialog.BUTTON_YES);
42
if(status == ConfirmDialog.STATUS_CANCEL){
45
if(status == ConfirmDialog.STATUS_YES){
46
final String fileName = FileActionUtils.getFileName();
50
TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
51
new Thread(new Runnable() {
53
if(!TuxGuitar.isDisposed()){
54
FileActionUtils.save(fileName);
55
new SyncThread(new Runnable() {
57
if(!TuxGuitar.isDisposed()){
58
TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
74
protected void openFile(Object data){
75
final URL url = getOpenFileName(data);
80
TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
81
new Thread(new Runnable() {
83
if(!TuxGuitar.isDisposed()){
84
FileActionUtils.open(url);
85
TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
92
protected URL getOpenFileName(Object data){
94
if(data instanceof URL){
95
TuxGuitar.instance().getFileHistory().setChooserPath( (URL)data );
98
String path = FileChooser.instance().open(TuxGuitar.instance().getShell(),TGFileFormatManager.instance().getInputFormats());
100
File file = new File(path);
101
return file.toURI().toURL();
103
}catch(Throwable throwable){
104
throwable.printStackTrace();
b'\\ No newline at end of file'