Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "filebrowser.h"
Toshihiro Shimizu 890ddd
#include "thumbnail.h"
Toshihiro Shimizu 890ddd
#include "thumbnailviewer.h"
Toshihiro Shimizu 890ddd
#include "tw/treeview.h"
Toshihiro Shimizu 890ddd
#include "tw/colors.h"
Toshihiro Shimizu 890ddd
#include "tw/button.h"
Toshihiro Shimizu 890ddd
#include "tw/scrollbar.h"
Toshihiro Shimizu 890ddd
#include "tw/mainshell.h"
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tenv.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
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "filebrowser_icons.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DirectoryBrowser : public ThumbnailViewer {
Shinya Kitaoka 120a6e
  TFilePath m_filepath;
Shinya Kitaoka 120a6e
  vector<string> m_fileTypes;</string>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  GenericFileBrowserAction *m_fileSelChangeAction;
Shinya Kitaoka 120a6e
  GenericFileBrowserAction *m_fileDblClickAction;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DirectoryBrowser(TWidget *parent, const vector<string> &fileTypes)</string>
Shinya Kitaoka 120a6e
      : ThumbnailViewer(parent)
Shinya Kitaoka 120a6e
      , m_fileSelChangeAction(0)
Shinya Kitaoka 120a6e
      , m_fileDblClickAction(0)
Shinya Kitaoka 120a6e
      , m_fileTypes(fileTypes) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~DirectoryBrowser() {
Shinya Kitaoka 120a6e
    if (m_fileSelChangeAction) delete m_fileSelChangeAction;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_fileDblClickAction) delete m_fileDblClickAction;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setPath(const TFilePath &filepath);
Shinya Kitaoka 120a6e
  void setFilter(const vector<string> &fileTypes);</string>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TFilePath getPath() const { return m_filepath; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onDoubleClick(int index);
Shinya Kitaoka 120a6e
  void onSelect(int index);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setFileSelChangeAction(GenericFileBrowserAction *action) {
Shinya Kitaoka 120a6e
    m_fileSelChangeAction = action;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setFileDblClickAction(GenericFileBrowserAction *action) {
Shinya Kitaoka 120a6e
    m_fileDblClickAction = action;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DirectoryBrowser::setPath(const TFilePath &filepath) {
Shinya Kitaoka 120a6e
  m_filepath = filepath;
Shinya Kitaoka 120a6e
  loadDirectory(filepath, m_fileTypes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DirectoryBrowser::setFilter(const vector<string> &fileTypes) {</string>
Shinya Kitaoka 120a6e
  m_fileTypes = fileTypes;
Shinya Kitaoka 120a6e
  if (!m_filepath.isEmpty()) loadDirectory(m_filepath, m_fileTypes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DirectoryBrowser::onDoubleClick(int index) {
Shinya Kitaoka 120a6e
  Thumbnail *thumbnail = getItem(index);
Shinya Kitaoka 120a6e
  if (thumbnail->getType() != Thumbnail::SCENE) return;
Shinya Kitaoka 120a6e
  TFilePath path =
Shinya Kitaoka 120a6e
      thumbnail->getPath().getParentDir() + (thumbnail->getName() + "_files");
Shinya Kitaoka 120a6e
  setPath(path);
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DirectoryBrowser::onSelect(int index) {
Shinya Kitaoka 120a6e
  if (index != -1) {
Shinya Kitaoka 120a6e
    Thumbnail *thumbnail = getItem(index);
Shinya Kitaoka 120a6e
    if (m_fileSelChangeAction)
Shinya Kitaoka 120a6e
      m_fileSelChangeAction->sendCommand(thumbnail->getPath());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class MyTreeViewItem : public TTreeViewItem {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  MyTreeViewItem(TTreeViewItemParent *parent) : TTreeViewItem(parent) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDimension getIconSize() const { return TDimension(26, 26); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void drawIcon(TTreeView *w, const TPoint &origin) {
Shinya Kitaoka 120a6e
    TRect rect(origin, getIconSize());
Shinya Kitaoka 120a6e
    w->setColor(TWidget::Black);
Shinya Kitaoka 120a6e
    w->drawRect(rect);
Shinya Kitaoka 120a6e
    rect = rect.enlarge(-4);
Shinya Kitaoka 120a6e
    w->setColor(Red);
Shinya Kitaoka 120a6e
    w->drawRect(rect);
Shinya Kitaoka 120a6e
    w->setColor(Blue);
Shinya Kitaoka 120a6e
    w->fillRect(rect.enlarge(-1));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void drawName(TTreeView *w, const TPoint &origin) {
Shinya Kitaoka 120a6e
    string name         = toString(getName());
Shinya Kitaoka 120a6e
    TDimension textSize = w->getTextSize(name);
Shinya Kitaoka 120a6e
    TDimension iconSize = getIconSize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TPoint pos = origin;
Shinya Kitaoka 120a6e
    pos.x += iconSize.lx;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (isSelected()) {
Shinya Kitaoka 120a6e
      w->setColor(ToonzHighlightColor);
Shinya Kitaoka 120a6e
      w->fillRect(pos.x + 2, pos.y + 2, pos.x + textSize.lx + 8,
Shinya Kitaoka 120a6e
                  pos.y + iconSize.ly - 1 - 2);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    w->setColor(TWidget::Black);
Shinya Kitaoka 120a6e
    w->drawText(pos + TPoint(5, iconSize.ly / 2 - textSize.ly / 2), name);
Toshihiro Shimizu 890ddd
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
void draw(TTreeView *w, const TPoint &origin) {
Shinya Kitaoka 120a6e
drawIcon(w,origin);
Shinya Kitaoka 120a6e
drawName(w,origin);
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class MyTreeView : public TTreeView {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  MyTreeView(TWidget *parent, string name = "MyTreeView")
Shinya Kitaoka 120a6e
      : TTreeView(parent, name) {
Shinya Kitaoka 120a6e
    setBackgroundColor(White);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void drawButton(const TPoint &p, bool open) {
Shinya Kitaoka 120a6e
    int r1 = 3, r2 = 1;
Shinya Kitaoka 120a6e
    TRect rect(p.x - r1, p.y - r1, p.x + r1, p.y + r1);
Shinya Kitaoka 120a6e
    setColor(getBackgroundColor());
Shinya Kitaoka 120a6e
    fillRect(rect.enlarge(-1));
Shinya Kitaoka 120a6e
    setColor(Gray210);
Shinya Kitaoka 120a6e
    drawRect(rect);
Shinya Kitaoka 120a6e
    setColor(Black);
Shinya Kitaoka 120a6e
    drawLine(p.x - r2, p.y, p.x + r2, p.y);
Shinya Kitaoka 120a6e
    if (!open) drawLine(p.x, p.y - r2, p.x, p.y + r2);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class SimpleFileItem : public MyTreeViewItem {
Shinya Kitaoka 120a6e
  TFilePath m_path;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SimpleFileItem(TTreeViewItemParent *parent, const TFilePath &path)
Shinya Kitaoka 120a6e
      : MyTreeViewItem(parent), m_path(path) {
Shinya Kitaoka 120a6e
    setIsLeaf(true);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  wstring getName() const { return m_path.withoutParentDir().getWideString(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFilePath getPath() const { return m_path; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool caseInsensitiveLessThan(const TFilePath &fp1, const TFilePath &fp2) {
Shinya Kitaoka 120a6e
  return (stricmp(toString(fp1.getWideString()).c_str(),
Shinya Kitaoka 120a6e
                  toString(fp2.getWideString()).c_str()) < 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class FileFolderItem : public MyTreeViewItem {
Shinya Kitaoka 120a6e
  TFilePath m_path;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FileFolderItem(TTreeViewItemParent *parent, const TFilePath &path)
Shinya Kitaoka 120a6e
      : MyTreeViewItem(parent), m_path(path) {}
Shinya Kitaoka 120a6e
  wstring getName() const {
Shinya Kitaoka 120a6e
    return m_path.isRoot() ? m_path.getWideString()
Shinya Kitaoka 120a6e
                           : m_path.withoutParentDir().getWideString();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDimension getIconSize() const { return TDimension(16, 16); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onOpen() {
Shinya Kitaoka 120a6e
    clearItems();
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      TFilePathSet fps = TSystem::readDirectory(m_path);
Shinya Kitaoka 120a6e
      fps.sort(caseInsensitiveLessThan);
Shinya Kitaoka 120a6e
      for (TFilePathSet::iterator it = fps.begin(); it != fps.end(); it++) {
Shinya Kitaoka 120a6e
        if (TFileStatus(*it).isDirectory()) new FileFolderItem(this, *it);
Shinya Kitaoka 120a6e
        // else
Shinya Kitaoka 120a6e
        //  new SimpleFileItem(this, *it);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } catch (TException &e) {
Shinya Kitaoka 120a6e
      TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TFilePath getPath() const { return m_path; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void drawIcon(TTreeView *w, const TPoint &origin) {
Shinya Kitaoka 120a6e
    w->rectwrite(isOpen() ? openfolder : closedfolder, origin);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class MyComputerFolder : public MyTreeViewItem {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  MyComputerFolder(TTreeViewItemParent *parent) : MyTreeViewItem(parent) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  wstring getName() const { return toWideString("My Computer"); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onOpen() {
Shinya Kitaoka 120a6e
    clearItems();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TFilePathSet fps = TSystem::getDisks();
Shinya Kitaoka 120a6e
    for (TFilePathSet::iterator it = fps.begin(); it != fps.end(); it++) {
Shinya Kitaoka 120a6e
      TTreeViewItem *item = new FileFolderItem(this, *it);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void drawIcon(TTreeView *w, const TPoint &origin) {
Shinya Kitaoka 120a6e
    w->rectwrite(mycomputer, origin);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class HistoryFolder : public MyTreeViewItem {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  HistoryFolder(TTreeViewItemParent *parent) : MyTreeViewItem(parent) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  wstring getName() const { return toWideString("History"); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onOpen() { clearItems(); }
Shinya Kitaoka 120a6e
  void drawIcon(TTreeView *w, const TPoint &origin) {
Shinya Kitaoka 120a6e
    w->rectwrite(history, origin);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class LibraryFolder : public MyTreeViewItem {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  LibraryFolder(TTreeViewItemParent *parent) : MyTreeViewItem(parent) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  wstring getName() const { return toWideString("Library"); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onOpen() {
Shinya Kitaoka 120a6e
    clearItems();
Shinya Kitaoka 120a6e
    TFilePath root = TEnv::getRootDir();
Shinya Kitaoka 120a6e
    new FileFolderItem(this, root + "patterns");
Shinya Kitaoka 120a6e
    new FileFolderItem(this, root + "images");
Shinya Kitaoka 120a6e
    new FileFolderItem(this, root + "scenes");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void drawIcon(TTreeView *w, const TPoint &origin) {
Shinya Kitaoka 120a6e
    w->rectwrite(library, origin);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class WorkFolder : public FileFolderItem {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  WorkFolder(TTreeViewItemParent *parent)
Shinya Kitaoka 120a6e
      : FileFolderItem(parent, TEnv::getRootDir() + "work") {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDimension getIconSize() const { return TDimension(24, 24); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  wstring getName() const { return toWideString("Work"); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void drawIcon(TTreeView *w, const TPoint &origin) {
Shinya Kitaoka 120a6e
    w->rectwrite(workinprogress, origin);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class FileFolderTreeView : public MyTreeView {
Shinya Kitaoka 120a6e
  DirectoryBrowser *m_viewer;
Shinya Kitaoka 120a6e
  TTreeViewItem *m_myComputer;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FileFolderTreeView(TWidget *parent, DirectoryBrowser *viewer)
Shinya Kitaoka 120a6e
      : MyTreeView(parent), m_viewer(viewer) {
Shinya Kitaoka 120a6e
    m_myComputer = new MyComputerFolder(this);
Shinya Kitaoka 120a6e
    m_myComputer->open();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
new HistoryFolder(this);
Shinya Kitaoka 120a6e
new LibraryFolder(this);
Shinya Kitaoka 120a6e
new WorkFolder(this);
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void leftButtonDoubleClick(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void onSelect(TTreeViewItem *item);
Shinya Kitaoka 120a6e
  void setCurrentDir(const TFilePath &dirPath);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileFolderTreeView::leftButtonDoubleClick(const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  TTreeViewItem *item = getSelectedItem();
Shinya Kitaoka 120a6e
  if (item) {
Shinya Kitaoka 120a6e
    if (!item->isOpen())
Shinya Kitaoka 120a6e
      item->open();
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      item->close();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    updateVisibleItems();
Shinya Kitaoka 120a6e
    invalidate();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileFolderTreeView::onSelect(TTreeViewItem *item) {
Shinya Kitaoka 120a6e
  FileFolderItem *folder = dynamic_cast<filefolderitem *="">(item);</filefolderitem>
Shinya Kitaoka 120a6e
  if (folder && folder->getPath() != m_viewer->getPath()) {
Shinya Kitaoka 120a6e
    TFilePath path = folder->getPath();
Shinya Kitaoka 120a6e
    m_viewer->setPath(path);
Shinya Kitaoka 120a6e
    m_viewer->invalidate();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TTreeViewItem *openChild(TTreeViewItem *folder, const TFilePath &childPath) {
Shinya Kitaoka 120a6e
  int count = folder->getItemCount();
Shinya Kitaoka 120a6e
  for (int i = 0; i < count; ++i) {
Shinya Kitaoka 120a6e
    FileFolderItem *item = dynamic_cast<filefolderitem *="">(folder->getItem(i));</filefolderitem>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (item && item->getPath() == childPath) {
Shinya Kitaoka 120a6e
      item->open();
Shinya Kitaoka 120a6e
      return item;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileFolderTreeView::setCurrentDir(const TFilePath &dirPath) {
Shinya Kitaoka 120a6e
  assert(TFileStatus(dirPath).isDirectory());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  list<tfilepath> ancestors;</tfilepath>
Shinya Kitaoka 120a6e
  ancestors.push_back(dirPath);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!dirPath.isRoot()) {
Shinya Kitaoka 120a6e
    TFilePath fp = dirPath;
Shinya Kitaoka 120a6e
    while (!(fp = fp.getParentDir()).isRoot()) ancestors.push_front(fp);
Shinya Kitaoka 120a6e
    ancestors.push_front(fp);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TTreeViewItem *folder = m_myComputer;
Shinya Kitaoka 120a6e
  while (!ancestors.empty() && folder) {
Shinya Kitaoka 120a6e
    TFilePath fp = ancestors.front();
Shinya Kitaoka 120a6e
    folder       = openChild(folder, fp);
Shinya Kitaoka 120a6e
    ancestors.pop_front();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (folder) {
Shinya Kitaoka 120a6e
    updateVisibleItems();
Shinya Kitaoka 120a6e
    select(folder);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TRect rect;
Shinya Kitaoka 120a6e
    getPlacement(m_selectedItemIndex, rect);
Shinya Kitaoka 120a6e
    int y = rect.getP00().y;
Shinya Kitaoka 120a6e
    if (y <= 0)
Shinya Kitaoka 120a6e
      y = m_yoffset - y;
Shinya Kitaoka 120a6e
    else if (y > getLy())
Shinya Kitaoka 120a6e
      y = m_yoffset - (rect.y1 - getLy());
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      y = m_yoffset;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    scrollToY(y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    updateScrollbars();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
};  // anonymous namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class FileBrowser::Data {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Data() {}
Shinya Kitaoka 120a6e
  ~Data() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  FileFolderTreeView *m_tree;
Shinya Kitaoka 120a6e
  DirectoryBrowser *m_panel;
Shinya Kitaoka 120a6e
  TScrollbar *m_panelScb, *m_treeVscb, *m_treeHscb;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TIconButton *m_upButton, *m_createFolderButton, *m_deleteFileButton;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  vector<string> m_fileTypes;</string>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FileBrowser::FileBrowser(TWidget *parent, string name,
Shinya Kitaoka 120a6e
                         const vector<string> &fileTypes)</string>
Shinya Kitaoka 120a6e
    : TWidget(parent, name), m_data(new Data()) {
Shinya Kitaoka 120a6e
  m_data->m_fileTypes = fileTypes;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_panel = new DirectoryBrowser(this, fileTypes);
Shinya Kitaoka 120a6e
  m_data->m_tree  = new FileFolderTreeView(this, m_data->m_panel);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_panelScb = new TScrollbar(this);
Shinya Kitaoka 120a6e
  m_data->m_treeHscb = new TScrollbar(this);
Shinya Kitaoka 120a6e
  m_data->m_treeVscb = new TScrollbar(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_panel->setScrollbars(0, m_data->m_panelScb);
Shinya Kitaoka 120a6e
  m_data->m_tree->setScrollbars(m_data->m_treeHscb, m_data->m_treeVscb);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setBackgroundColor(Gray210);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_upButton = new TIconButton(this, parentfolder);
Shinya Kitaoka 120a6e
  tconnect(*m_data->m_upButton, this, &FileBrowser::selectParentDirectory);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_createFolderButton = new TIconButton(this, newfolder);
Shinya Kitaoka 120a6e
  m_data->m_deleteFileButton   = new TIconButton(this, trash);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FileBrowser::~FileBrowser() { delete m_data; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowser::setFilter(const vector<string> &fileTypes) {</string>
Shinya Kitaoka 120a6e
  m_data->m_fileTypes = fileTypes;
Shinya Kitaoka 120a6e
  m_data->m_panel->setFilter(fileTypes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowser::draw() {
Shinya Kitaoka 120a6e
  setColor(White);
Shinya Kitaoka 120a6e
  fillRect(0, 0, 4, getLy() - 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPoint p;
Shinya Kitaoka 120a6e
  p = m_data->m_treeVscb->getGeometry().getP11();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setColor(Gray150);
Shinya Kitaoka 120a6e
  drawLine(p.x + 1, 1, p.x + 1, p.y);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  p = m_data->m_panel->getGeometry().getP01();
Shinya Kitaoka 120a6e
  drawLine(p.x - 1, 1, p.x - 1, p.y);
Shinya Kitaoka 120a6e
  drawLine(p.x - 1, p.y + 1, getLx() - 2, p.y + 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowser::configureNotify(const TDimension &d) {
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
TRect rect = getBounds();
Shinya Kitaoka 120a6e
int x = 200;
Shinya Kitaoka 120a6e
int w = 15;
Shinya Kitaoka 120a6e
int xa = x-w-4;
Shinya Kitaoka 120a6e
TDimension scbSize(w, rect.getLy());
Shinya Kitaoka 120a6e
m_data->m_tree->setGeometry(rect.x0,rect.y0,xa-1,rect.y1);
Shinya Kitaoka 120a6e
m_data->m_treeVscb->setGeometry(TPoint(xa,rect.y0),scbSize);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
m_data->m_treeHscb->setGeometry(rect.x0, rect.y0,
Shinya Kitaoka 120a6e
x-1-scbSize,rect.y0+scbSize-1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int buttonBarHeight = 30;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
rect.y1 -= buttonBarHeight;
Shinya Kitaoka 120a6e
scbSize.ly -= buttonBarHeight;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
m_data->m_panel->setGeometry(x,rect.y0,rect.x1-w,rect.y1);
Shinya Kitaoka 120a6e
m_data->m_panelScb->setGeometry(TPoint(rect.x1-w+1,rect.y0),scbSize);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int y = rect.y1+4;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
m_data->m_upButton->setPosition(x-1, y);
Shinya Kitaoka 120a6e
m_data->m_createFolderButton->setPosition(x+25, y);
Shinya Kitaoka 120a6e
m_data->m_deleteFileButton->setPosition(rect.x1-26, y);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
invalidate();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const int scbSize = 15;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRect rect = getBounds();
Shinya Kitaoka 120a6e
  int x      = 196;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_tree->setGeometry(rect.x0, rect.y0 + scbSize, x - 1 - scbSize,
Shinya Kitaoka 120a6e
                              rect.y1);
Shinya Kitaoka 120a6e
  m_data->m_treeVscb->setGeometry(x - scbSize, rect.y0 + scbSize, x - 1,
Shinya Kitaoka 120a6e
                                  rect.y1);
Shinya Kitaoka 120a6e
  m_data->m_treeHscb->setGeometry(rect.x0, rect.y0, x - 1 - scbSize,
Shinya Kitaoka 120a6e
                                  rect.y0 + scbSize - 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int buttonBarHeight = 29;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  rect.y1 -= buttonBarHeight;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_panel->setGeometry(x + 4, rect.y0, rect.x1 - scbSize, rect.y1);
Shinya Kitaoka 120a6e
  m_data->m_panelScb->setGeometry(rect.x1 - scbSize + 1, rect.y0, rect.x1,
Shinya Kitaoka 120a6e
                                  rect.y1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int y = rect.y1 + 4;
Shinya Kitaoka 120a6e
  x += 4;
Shinya Kitaoka 120a6e
  m_data->m_upButton->setPosition(x - 1, y);
Shinya Kitaoka 120a6e
  m_data->m_createFolderButton->setPosition(x + 25, y);
Shinya Kitaoka 120a6e
  m_data->m_deleteFileButton->setPosition(rect.x1 - 26, y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_data->m_upButton->invalidate();
Shinya Kitaoka 120a6e
  m_data->m_createFolderButton->invalidate();
Shinya Kitaoka 120a6e
  m_data->m_deleteFileButton->invalidate();
Shinya Kitaoka 120a6e
  m_data->m_treeVscb->invalidate();
Shinya Kitaoka 120a6e
  m_data->m_treeHscb->invalidate();
Shinya Kitaoka 120a6e
  m_data->m_tree->invalidate();
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowser::setBackgroundColor(const TGuiColor &color) {
Shinya Kitaoka 120a6e
  TWidget::setBackgroundColor(color);
Shinya Kitaoka 120a6e
  m_data->m_panel->setBackgroundColor(color);
Shinya Kitaoka 120a6e
  m_data->m_tree->setBackgroundColor(color);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowser::setFileSelChangeAction(GenericFileBrowserAction *action) {
Shinya Kitaoka 120a6e
  m_data->m_panel->setFileSelChangeAction(action);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowser::setFileDblClickAction(GenericFileBrowserAction *action) {
Shinya Kitaoka 120a6e
  m_data->m_panel->setFileDblClickAction(action);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath FileBrowser::getCurrentDir() const {
Shinya Kitaoka 120a6e
  FileFolderItem *item =
Shinya Kitaoka 120a6e
      dynamic_cast<filefolderitem *="">(m_data->m_tree->getSelectedItem());</filefolderitem>
Shinya Kitaoka 120a6e
  if (item)
Shinya Kitaoka 120a6e
    return item->getPath();
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return TFilePath();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowser::setCurrentDir(const TFilePath &dirPath) {
Shinya Kitaoka 120a6e
  m_data->m_tree->setCurrentDir(dirPath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileBrowser::selectParentDirectory() { m_data->m_tree->selectParent(); }