package nak.nakloidGUI.actions.files;

import java.io.IOException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;

import nak.nakloidGUI.NakloidGUI;
import nak.nakloidGUI.actions.AbstractAction;
import nak.nakloidGUI.coredata.CoreData;
import nak.nakloidGUI.gui.MainWindow;

public class SaveAsAction extends AbstractAction {
	final String[] ext = {"*.nar"};
	final String [] filterNames = {"Nakloid Archive (*.nar)"};

	public SaveAsAction(MainWindow mainWindow, CoreData coreData) {
		super(mainWindow, coreData);
		setText("名前を付けて保存@Shift+Ctrl+S");
		setAccelerator(SWT.CTRL+'A');
	}

	@Override
	public void run() {
		FileDialog openDialog = new FileDialog(mainWindow.getShell(), SWT.SAVE);
		openDialog.setFilterExtensions(ext);
		openDialog.setFilterNames(filterNames);
		String strPath = openDialog.open();
		if (strPath==null || strPath.isEmpty()) {
			return;
		}
		NakloidGUI.preferenceStore.setValue("workspace.path_nar", strPath);
		try {
			NakloidGUI.preferenceStore.save();
		} catch (IOException e) {}
		mainWindow.saveAction.run();
	}
}

@@ -51,21 +51,90 @@
 .io.
-IOException;%0A
+File;%0Aimport java.io.IOException;%0A%0Aimport org.eclipse.jface.dialogs.MessageDialog;
 %0Aimp
@@ -872,16 +872,45 @@
 %09String 
+strPath;%0A%09%09while (true) %7B%0A%09%09%09
 strPath 
@@ -930,16 +930,17 @@
 open();%0A
+%09
 %09%09if (st
@@ -982,16 +982,17 @@
 %0A%09%09%09
+%09
 return;%0A
 %09%09%7D%0A
@@ -987,16 +987,198 @@
 return;%0A
+%09%09%09%7D%0A%09%09%09File tmpFile = new File(strPath);%0A%09%09%09if (!tmpFile.exists() %7C%7C MessageDialog.openConfirm(mainWindow.getShell(), %22NakloidGUI%22, %22%E9%81%B8%E6%8A%9E%E3%81%95%E3%82%8C%E3%81%9F%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AF%E6%97%A2%E3%81%AB%E5%AD%98%E5%9C%A8%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%E4%B8%8A%E6%9B%B8%E3%81%8D%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B%EF%BC%9F%22)) %7B%0A%09%09%09%09break;%0A%09%09%09%7D%0A
 %09%09%7D%0A%09%09Na

improve save_as action