SOL9 Sample: SolExplorer

SOL9 2.0 Samples

1 Screenshot


2 Source code

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



// SOL++2000 
// 2000.07.01

#define COMMONCONTROLS_V6

#include <sol\ApplicationView.h>
#include <sol\Thread.h>
#include <sol\SplitPane.h>
#include <sol\IconedDirTree.h>
#include <sol\IconedFileList.h>
#include "resource.h"

namespace SOL {

// class DirScanner

class DirScanner  :public Object {
private:
  IconedDirTree*  treev;

public:
  DirScanner() 
  { 
  }

public:
  void  setDirTree(IconedDirTree* tree) { 
      treev = tree;
  }

public:
  // 
  void scan()
  {
    TCHAR path[10];

    HTREEITEM item = (HTREEITEM)TVI_FIRST;

    TCHAR cdir[_MAX_PATH];
    ::GetCurrentDirectory(CountOf(cdir), cdir);
    TCHAR* p = (TCHAR*)strchr(cdir, ':');
    if(p++) {
      *p = ZERO;
    }
    
    treev->setRedraw(FALSE);
    
    treev->deleteAllItems();

    DWORD d = ::GetLogicalDrives();
    for (int i = 0; i<26; i++) {
      if (d & 1) {
        _stprintf_s(path, CountOf(path), _T("%c:"), 'A'+i);
        int id1 = 0;
        int id2 = 0;
        item = treev -> addItemWithIcon(NULL, item, path);

        treev -> findDirectories(item, path, 0, 2);
        treev -> sortChildren(item, TRUE);
        //2009/10/14 strcmp -> stricmp
        if (stricmp(path, cdir) == 0) {
          treev -> expand(item, TVE_EXPAND);
        }
      }
      d = d >> 1;
    }
    treev->setRedraw(TRUE);
  }
};


// class SolExplorer

class SolExplorer :public ApplicationView {
private:
  SplitPane     pane;
  IconedDirTree  treev;
  IconedFileList files;

  HTREEITEM selectedItem;

public:
  /**
   * Constructor
   */
  SolExplorer(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name, 
      args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1))
      .set(XmNstyle, WS_CLIPCHILDREN))
  {
    selectedItem = NULL;

    Args ar;
    ar.set(XmNdirection, SplitPane::HORIZONTAL);
    pane.create(this, NULL, ar);
    add(pane);

    ar.reset();
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle, (ulong)(TVS_HASBUTTONS|TVS_SHOWSELALWAYS));
            //|TVS_HASLINES|TVS_LINESATROOT));
    treev.create(&pane, NULL, ar);
    pane.add(&treev);
        
    ar.reset();
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle,  (ulong)LVS_SORTASCENDING | LVS_REPORT);
    files.create(&pane, NULL, ar);
    //2012/07/24
    DWORD dwStyle = files.getExtendedViewStyle() | LVS_EX_FULLROWSELECT;
    files.setExtendedViewStyle(dwStyle);

    files.addCallback(XmNdoubleClickCallback, this,
      (Callback)&SolExplorer::fileSelected, NULL);

    files.addCallback(XmNreturnCallback, this,
      (Callback)&SolExplorer::fileSelected, NULL);

    pane.add(&files);
    pane.setSashPosition(200);

    treev.addCallback(XmNitemExpandingCallback, this, 
      (Callback)&SolExplorer::expanding, NULL);
  
    treev.addCallback(XmNselChangedCallback, this, 
      (Callback)&SolExplorer::selChanged, NULL);

    addCallback(XmNmenuCallback, IDM_REFRESH, this, 
      (Callback)&SolExplorer::refresh, NULL);

    addCallback(XmNmenuCallback, IDM_EXIT, this, 
      (Callback)&SolExplorer::exit, NULL);

    addCallback(XmNmenuCallback, IDM_VERSION, this, 
      (Callback)&SolExplorer::version, NULL);

    addEventHandler(WM_CLOSE, this, 
      (Handler)&SolExplorer::close, NULL);

    restorePlacement();

    DirScanner scanner;
    scanner.setDirTree(&treev);
    scanner.scan();
  }

private:
  void version(Action& action)
  {
    showMessageDialog(_T("Version"),
      _T("SolExplorer Version 1.0.0.3\r\nCopyright(C) 2008-2012 Antillia.com"),
      MB_OK|MB_ICONINFORMATION);
  }

private:
  void refresh(Action& action)
  {

    DirScanner scanner;
    scanner.setDirTree(&treev);
    scanner.scan();
    
    files.deleteAllItems();
    setText(_T("SolExplorer"));

  }

private:
  void fileSelected(Action& action)
  {
    String fileName = "";
    String filePath = "";

    if (files.getSelectedFilePath(fileName, filePath)) {
      const TCHAR* tfilePath = (const TCHAR*)filePath;
      //
      if (tfilePath) {
        if (GetFileAttributes(tfilePath) & FILE_ATTRIBUTE_DIRECTORY) {
          //If a directory item in the listview  were selected, expand the corresponding
          // item on treeview.

          //Try to expand current treenode.
          treev.expand(selectedItem, TVE_EXPAND|TVE_EXPANDPARTIAL);
          //Find an HTREEITEM corresponding to the selected folder name (fileName) in listview.
          HTREEITEM hChildItem = treev.findDirectChildItem(selectedItem, (const TCHAR*)fileName);
          
          if (hChildItem) {
            treev.select(hChildItem, TVGN_CARET);
          }
        }
        else {
          //If it were a file, call ShellExecuteEx to execute the file or an associated program
          SHELLEXECUTEINFO sei;
          ::ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
          sei.cbSize = sizeof(SHELLEXECUTEINFO);
          sei.lpFile = tfilePath;
          sei.nShow  = SW_SHOWNORMAL;
          ::ShellExecuteEx(&sei);
        }
      }
    }
  }

private:
  long close(Event& event)
  {
    // Never forget to call detachImageList method on Windows95/98.
    treev.detachImageList();
    files.detachImageList();

    savePlacement();
    return defaultProc(event);
  }

private:
  void expanding(Action& action)
  {               
    Event& event = action.getEvent();  
    NM_TREEVIEW* nmtreev = (NM_TREEVIEW*)event.getLParam();
    HTREEITEM htreeItem = nmtreev->itemNew.hItem;
    //20/15/12/12
    StringBufferT<TCHAR> dir;
    // Get fullpathname of the selected node
    treev.getHierachy(htreeItem, dir, _T("\\"));

    treev.setRedraw(FALSE);

    // Delete all children
    treev.deleteChildren(htreeItem);

    // Builde a tree for the subdirectory
    treev.findDirectories(htreeItem, dir, 0, 2);
    treev.sortChildren(htreeItem, TRUE);

    treev.setRedraw(TRUE);

  }

private:
  void selChanged(Action& action)
  {
    Event& event = action.getEvent();
    NM_TREEVIEW* nmtr  = (NM_TREEVIEW*)event.getLParam();
    TV_ITEM tvItem     = nmtr -> itemNew;
    HTREEITEM hselItem = tvItem.hItem;
    
    selectedItem = hselItem;

    //TCHAR dir[MAX_PATH*2];
    //dir[0] = ZERO;
    StringBufferT<TCHAR> dir;
    treev.getHierachy(hselItem, dir, _T("\\"));

    files.findFiles(dir);
  
    TCHAR title[MAX_PATH*2];
    _stprintf_s(title, CountOf(title), _T("%s - SolExplorer"), dir.getBuffer());
    setText(title);
  
  }

};

}

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

  try {
    Application applet(name, argc, argv);

    Args args;
    args.set(XmNclassStyle, 0);
    SolExplorer explorer(applet, name, args);
    explorer.realize();

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


Last modified: 1 Feb 2017

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