~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/actions/file/SaveFileAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2007-02-04 01:41:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070204014123-9pv7okph0iaiqkvw
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on 17-dic-2005
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.gui.actions.file;
 
8
 
 
9
import java.io.File;
 
10
 
 
11
import org.eclipse.swt.SWT;
 
12
import org.eclipse.swt.events.TypedEvent;
 
13
import org.herac.tuxguitar.gui.TuxGuitar;
 
14
import org.herac.tuxguitar.gui.actions.Action;
 
15
import org.herac.tuxguitar.gui.editors.TablatureEditor;
 
16
import org.herac.tuxguitar.gui.helper.SyncThread;
 
17
 
 
18
/**
 
19
 * @author julian
 
20
 *
 
21
 * TODO To change the template for this generated type comment go to
 
22
 * Window - Preferences - Java - Code Style - Code Templates
 
23
 */
 
24
public class SaveFileAction extends Action{
 
25
    public static final String NAME = "action.file.save";
 
26
    
 
27
    public SaveFileAction(TablatureEditor tablatureEditor) {
 
28
        super(NAME,true,tablatureEditor);       
 
29
    }
 
30
 
 
31
    public boolean doAction(TypedEvent e) {     
 
32
        final String fileName = TuxGuitar.instance().getFileHistory().getFilePath() + File.separator + TuxGuitar.instance().getFileHistory().getFileName();
 
33
        
 
34
        if (TuxGuitar.instance().getFileHistory().isNewFile() || !isSuportedFormat(fileName)) {
 
35
                TuxGuitar.instance().getAction(SaveAsFileAction.NAME).process(e);
 
36
        }else{
 
37
            getEditor().getTablature().changeCursor(SWT.CURSOR_WAIT);
 
38
            new SyncThread(new Runnable() {
 
39
                public void run() {
 
40
                        if(!TuxGuitar.isDisposed()){
 
41
                                getEditor().getSongManager().save(fileName);
 
42
                        getEditor().getTablature().changeCursor(SWT.CURSOR_ARROW);
 
43
                    }
 
44
                }
 
45
            }).start();                                             
 
46
        }   
 
47
        
 
48
        return true;
 
49
    }
 
50
    
 
51
        private boolean isSuportedFormat(String fileName) {
 
52
                return (fileName.endsWith(".tg") || fileName.endsWith(".gp3") || fileName.endsWith(".gp4"));
 
53
        }
 
54
 
 
55
}