Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "filebrowserpopup.h"
Toshihiro Shimizu 890ddd
#include "filebrowser.h"
Toshihiro Shimizu 890ddd
#include "tlevel_io.h"
Toshihiro Shimizu 890ddd
#include "tw/button.h"
Toshihiro Shimizu 890ddd
#include "tw/textfield.h"
Toshihiro Shimizu 890ddd
#include "tw/label.h"
Toshihiro Shimizu 890ddd
#include "tw/colors.h"
Toshihiro Shimizu 890ddd
#include "tw/mainshell.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tw/message.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace TwConsts;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class FileBrowserPopup::Data {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Data() : m_okAction(0) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  FileBrowserPopup *m_popup;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  FileBrowser *m_fileBrowser;
Shinya Kitaoka 120a6e
  TButton *m_okButton;
Shinya Kitaoka 120a6e
  TButton *m_cancelButton;
Shinya Kitaoka 120a6e
  TLabel *m_fileLabel;
Shinya Kitaoka 120a6e
  TTextField *m_file;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFilePath m_currentFile;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TGenericFileBrowserPopupAction *m_okAction;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void initPopup(const vector<string> &fileTypes);</string>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void onOk();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void onFileSelChange(const TFilePath &fp) {
Shinya Kitaoka 120a6e
    m_currentFile = fp;
Shinya Kitaoka 120a6e
    m_file->setText(fp.withoutParentDir().getWideString());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//                , m_importTrayH(120)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowserPopup::Data::initPopup(const vector<string> &fileTypes) {</string>
Shinya Kitaoka 120a6e
  m_fileBrowser = new FileBrowser(m_popup, "fileBrowser", fileTypes);
Shinya Kitaoka 120a6e
  m_fileBrowser->setBackgroundColor(Gray240);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_fileBrowser->setFileSelChangeAction(
Shinya Kitaoka 120a6e
      new FileBrowserAction<filebrowserpopup::data>(</filebrowserpopup::data>
Shinya Kitaoka 120a6e
          this, &FileBrowserPopup::Data::onFileSelChange));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_okButton     = new TButton(m_popup, "Ok");
Shinya Kitaoka 120a6e
  m_cancelButton = new TButton(m_popup, "Cancel");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tconnect<tpopup>(*(m_cancelButton), m_popup, &TPopup::close);</tpopup>
Shinya Kitaoka 120a6e
  tconnect<filebrowserpopup::data>(*(m_okButton), this,</filebrowserpopup::data>
Shinya Kitaoka 120a6e
                                   &FileBrowserPopup::Data::onOk);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_fileLabel = new TLabel(m_popup, "File");
Shinya Kitaoka 120a6e
  m_file      = new TTextField(m_popup);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowserPopup::Data::onOk() {
Shinya Kitaoka 120a6e
  assert(m_okAction);
Shinya Kitaoka 120a6e
  string file = toString(m_file->getText());
Shinya Kitaoka 120a6e
  if (file != "") {
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      m_okAction->sendCommand(m_fileBrowser->getCurrentDir() + file);
Shinya Kitaoka 120a6e
      m_popup->close();
Shinya Kitaoka 120a6e
    } catch (TException &e) {
Shinya Kitaoka 120a6e
      TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FileBrowserPopup::FileBrowserPopup(TWidget *parent)
Shinya Kitaoka 120a6e
    : TPopup(parent, "fileBrowserPopup"), m_data(new Data()) {
Shinya Kitaoka 120a6e
  m_data->m_popup = this;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_isMenu = false;
Shinya Kitaoka 120a6e
  setSize(640, 400);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  vector<string> fileTypes;</string>
Shinya Kitaoka 120a6e
  TImageReader::getSupportedFormats(fileTypes);
Shinya Kitaoka 120a6e
  TLevelReader::getSupportedFormats(fileTypes);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->initPopup(fileTypes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FileBrowserPopup::FileBrowserPopup(TWidget *parent,
Shinya Kitaoka 120a6e
                                   const vector<string> &fileTypes)</string>
Shinya Kitaoka 120a6e
    : TPopup(parent, "fileBrowserPopup"), m_data(new Data()) {
Shinya Kitaoka 120a6e
  m_data->m_popup = this;
Shinya Kitaoka 120a6e
  m_isMenu        = false;
Shinya Kitaoka 120a6e
  setSize(640, 400);
Shinya Kitaoka 120a6e
  m_data->initPopup(fileTypes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FileBrowserPopup::~FileBrowserPopup() { delete m_data; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDimension FileBrowserPopup::getPreferredSize() const {
Shinya Kitaoka 120a6e
  return TDimension(640, 400);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowserPopup::configureNotify(const TDimension &d) {
Shinya Kitaoka 120a6e
  int y = 4;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_fileLabel->setGeometry(10 /*100*/, y, 60 /*150*/, y + 20);
Shinya Kitaoka 120a6e
  m_data->m_file->setGeometry(65 /*155*/, y, d.lx - 220, y + 20);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_okButton->setGeometry(d.lx - 200, y, d.lx - 150, y + 20);
Shinya Kitaoka 120a6e
  m_data->m_cancelButton->setGeometry(d.lx - 130, y, d.lx - 80, y + 20);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  y += 20 + 4;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int x = 200;
Shinya Kitaoka 120a6e
  // m_importTray->setGeometry(x,y,d.lx-1,y+m_importTrayH-4);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // y = y + (m_importTrayH + 8);
Shinya Kitaoka 120a6e
  m_data->m_fileBrowser->setGeometry(0, y, d.lx - 1, d.ly - 10);
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowserPopup::popup(const TPoint &p) {
Shinya Kitaoka 120a6e
  m_data->m_currentFile = TFilePath();
Shinya Kitaoka 120a6e
  TPopup::popup(p);
Shinya Kitaoka 120a6e
  setCaption("File Browser");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowserPopup::draw() {
Shinya Kitaoka 120a6e
  int y = 10 + 20 + 4 /*+ m_importTrayH*/;
Shinya Kitaoka 120a6e
  setColor(Gray150);
Shinya Kitaoka 120a6e
  draw3DRect(TRect(TPoint(0, y), TDimension(getSize().lx - 1, 6)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowserPopup::setOkAction(TGenericFileBrowserPopupAction *action) {
Shinya Kitaoka 120a6e
  m_data->m_okAction = action;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowserPopup::setCurrentDir(const TFilePath &dirPath) {
Shinya Kitaoka 120a6e
  m_data->m_fileBrowser->setCurrentDir(dirPath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowserPopup::setFilter(const vector<string> &fileTypes) {</string>
Shinya Kitaoka 120a6e
  m_data->m_fileBrowser->setFilter(fileTypes);
Toshihiro Shimizu 890ddd
}