/* $Id: SaveActionListener.java 786 2013-11-08 00:34:05Z minao $ */
package smart_gs.swingui.toolbar.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import smart_gs.debugprint.Debugprint;
import smart_gs.swingui.WorkspaceWindow;
import webdav.WebDavListenerAction;

public class SaveActionListener implements ActionListener {
	protected int mode = 0;
	
	public SaveActionListener(int mode){
		this.mode = mode;
	}

	public void actionPerformed(ActionEvent e) {		
		if(mode == 1){
			WebDavListenerAction webDavListenerAction = new WebDavListenerAction();
			webDavListenerAction.save();
		}else if(mode == 2){
			Debugprint.from();
			Debugprint.message("Save mode: " + mode);
			WorkspaceWindow window = WorkspaceWindow.getInstance();
			boolean ans = false;
			if (window.getCurrentProject() == null) {
				ans = window.saveAll(window.getCurrentFile());
			} else {
				ans = window.saveProject();
			}
			if( ans == false ) return;
			window.unlock();
			window.setLastsave(0);
		}else{
			Debugprint.from();
			Debugprint.message("Save mode: " + mode);
			WorkspaceWindow window = WorkspaceWindow.getInstance();
//			20101107 shayashi introduced the assignment for clarity
			boolean ans;
			if (window.getCurrentProject() == null) {
				ans = window.saveAll();
			} else {

				//ans = window.saveProject();
				ans = false;
			}
			if( ans == false ) return;
			window.unlock();
			window.setLastsave(0);
		}
	}
}