/*********************************************************************

	FileDialog.cpp
				(C) Copyright 1999	TOSHIYUKI ARAI
				ALL RIGHTS RESERVED 
 ********************************************************************/

// SOL++2000

#include <sol\ApplicationView.h>
#include <sol\ScrolledText.h>
#include <sol\FileDialog.h>

#define ID_OPEN 1000
#define ID_SAVE 1001

class AppView :public ApplicationView {
	ScrolledText*   sctext;
	FileDialog*		filedlg;
	FileDialog*		savedlg;

	void	open(Action& action)
	{
		filedlg -> popup(action);
		if (action.getResult()) {
		//if(filedlg -> open()){
			sctext -> load(filedlg -> getFileName());
		}
	}

	void	save(Action& action)
	{
		savedlg -> popup(action);
		if (action.getResult()) {
			sctext -> save(savedlg -> getFileName());
		}
	}

  public:
	AppView(Application& applet, const char* name, Args& args)
		:ApplicationView(applet, name, args) 
	{
		Args ar;
		sctext = new ScrolledText(this, "", ar);

		add(sctext);

		ar.reset();
		ar.set(XmNaccessMode, FileDialog::OPEN);
		filedlg = new FileDialog(this, NULL, ar);

		ar.reset();
		ar.set(XmNaccessMode, FileDialog::SAVE);
		savedlg = new FileDialog(this, NULL, ar);

		addCallback(XmNmenuCallback, ID_OPEN, this,
			(Callback)&AppView::open, NULL);
		addCallback(XmNmenuCallback, ID_SAVE, this,
			(Callback)&AppView::save, NULL);

	}

	~AppView() 
	{
		delete sctext;
		delete filedlg;
		delete savedlg;
	}
};



void	Main(int argc, char** argv)
{
	const char* name = "AppView";
	Application applet(name, argc, argv);
	Args args;
	AppView appView(applet, name, args);
	appView.realize();
	applet.run();
}

//End of File1
//End of File2
//End of File3
//End of File4
//End of File5
