SOL9 Sample: FileDialog

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * FileDialog.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



// SOL++2000 
// 2000.02.18

#define COMMONCONTROLS_V6

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

#include "MenuID.h"

namespace SOL {

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

  void  open(Action& action)
  {
    filedlg.popup(action);
    if (action.getResult()) {
      TCHAR* filename = filedlg.getFileName();

      sctext.load(filename);
      TCHAR title[MAX_PATH*2];
      _stprintf_s(title, CountOf(title), _T("Opened:%s - FileDialog"), filename);
      setText(title);
    }
  }

  void  save(Action& action)
  {
    savedlg.popup(action);
    if (action.getResult()) {
      TCHAR* filename = savedlg.getFileName();
      sctext.save(savedlg.getFileName());
      TCHAR title[MAX_PATH*2];
      _stprintf_s(title, CountOf(title), _T("Saved:%s - FileDialog"), filename);
      setText(title);

    }
  }

  public:
  AppView(Application& applet, const TCHAR* name, Args& args)
    :ApplicationView(applet, name, args) 
  {
    Args ar;
    sctext.create(this, _T(""), ar);

    add(&sctext);

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

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

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

}


void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  try {

    Application applet(name, argc, argv);
    Args args;
    AppView appView(applet, name, args);
    appView.realize();
    applet.run();

  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  }
}

Last modified: 1 Feb 2017

Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.