#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>

#include <WSCfileSelect.h>
#include <WSCtextField.h>
#include <WSCmessageDialog.h>

//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
extern WSCstring backup; //export from m12ep.cpp
extern WSCtextField* newtext_001;
extern WSCbaseDialog* newwin000;

void m14ep(WSCbase* object){
  //do something...

  WSCfileSelect* fs = WSGIappFileSelect();
  fs->setProperty(WSNmaskFileName,"");
  fs->setProperty(WSNdefaultPosition,True);
  long ret = fs->popup();
  if (ret == WS_DIALOG_OK){
    long ret = WSGFreplaceTextFile(fs->getFileName(),
                      newtext_001->getProperty(WSNlabelString),
                      False);
    if (ret == WS_OK){
      backup = newtext_001->getProperty(WSNlabelString);
      newtext_001->setProperty(WSNuserString,fs->getFileName());
      WSCstring title;
      title << "NotePad: " << (char*)fs->getFileName();
      newwin000->setProperty(WSNtitleString,title);
    }else{
      WSCmessageDialog* msg = WSGIappMessageDialog();
      WSCstring message;
      message << "file: " << fs->getFileName() << " に\n"
              << "保存することが出来ませんでした。";
      msg->setProperty(WSNdefaultPosition,True);
      msg->setProperty(WSNwidth,400);
      msg->setProperty(WSNheight,130);
      msg->setProperty(WSNlabelString,message);
      msg->popup();
    }
  }
}
static WSCfunctionRegister  op("m14ep",(void*)m14ep);
