home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm7.zip / listrun.cpp < prev    next >
C/C++ Source or Header  |  1999-06-12  |  6KB  |  189 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1998,1999  Paul Elliott
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     Paul Elliott
  20.     PMB # 181
  21.     11900 Metric Blvd Ste. J
  22.     Austin Tx 78758-3117
  23.     pelliott@io.com
  24. *    HISTORY
  25. *     APR 1999 Paul Elliott               Check for unknown exception is not needed with IBMCPP V40
  26. */
  27. #include "listrun.hpp"          // declares DisplayFile function
  28. #include "list.hpp"             // declares list frame object.
  29. #include "listthrd.hpp"         // list thread starter.
  30. #include "timeshow.hpp"         // show a window for a while.
  31. #include "exwmbox.hpp"         // Message box exception handler for a window.
  32.  
  33. #include <stdlib.h>
  34.  
  35. #include <istring.hpp>
  36. #include <ifiledlg.hpp>
  37.  
  38. #include "listpm.h"
  39. #include "IsDir.hpp"
  40.  
  41. #if __TOS_OS2__
  42. #define INCL_WINERRORS
  43. #include <pmerr.h>
  44. #endif
  45.  
  46.  
  47. // This code is is called to display a file in a frame window
  48. // on the current thread!
  49. void DisplayFile( IString file )
  50. {
  51.    ExcWinMsgBox       embox;      // message box exception function.
  52.  
  53.    // handle excetion on windows.
  54.    IWindow::setExceptionFunction( &embox );
  55.  
  56.    try
  57.    {
  58.  
  59.       // if we have been asked to list a directory.
  60.       if ( IsDir(file) )
  61.       {
  62.           // space for the fullfile name in the dialog.
  63.           char fullfile[_MAX_PATH];
  64.  
  65.           // create the fullpath of the current file.
  66.           _fullpath(fullfile,file,sizeof(fullfile));
  67.  
  68.           // space to store the parts of the current file.
  69.           char drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
  70.  
  71.           // split the file into parts.
  72.           _splitpath(fullfile,drive,dir,fname,ext);
  73.  
  74.           // space to store desired file
  75.           char usepath[_MAX_PATH];
  76.  
  77.           // make a wild card file path.
  78.           _makepath(usepath,drive,dir,"*","");
  79.  
  80.  
  81.           // settings for the dialog.
  82.           IFileDialog::Settings fsettings;
  83.  
  84.           // set files to chose from. all
  85.           fsettings.setFileName( IString(fullfile) + "\\*" );
  86.  
  87.           // set the initial drive discovered.
  88.           fsettings.setInitialDrive(drive);
  89.  
  90.           // set the title of this dialog.
  91.           fsettings.setTitle(STR_TITLEREPLACE);
  92.  
  93.           // This is an open dialog, choose amoung existing files.
  94.           fsettings.setOpenDialog();
  95.  
  96.  
  97.           // returned OK, is it directroy name of file which is chosen.
  98.           Boolean is_dir , ok ;
  99.           IString chosen_file;
  100.  
  101.           do
  102.           {
  103.              // create the dialog.
  104.              IFileDialog dlg( IWindow::desktopWindow(),
  105.                 IWindow::desktopWindow(),
  106.                 IFileDialog::defaultStyle() | IFileDialog::multiSelection ,
  107.                 fsettings);
  108.              // constructor will return when dialog has run to completion.
  109.  
  110.              ok =  dlg.pressedOK();
  111.  
  112.              if ( ok ) chosen_file = dlg.fileName();
  113.  
  114.              // requested file is a directory.
  115.              is_dir =  dlg.pressedOK() && IsDir( dlg.fileName() ) &&
  116.                        ( dlg.selectedFileCount() == 1 ) ;
  117.  
  118.              if (is_dir) fsettings.setFileName( ( chosen_file + "\\*" ) );
  119.              else if ( ok)
  120.              {
  121.                  // for each file selected by the dialog.
  122.                  for(int i=0; i< dlg.selectedFileCount() ; i++)
  123.                  {
  124.  
  125.                     // start a whole new thread to handle the new frame.
  126.                     // the new ListThreadFn will be stored in a managed pointer
  127.                     // and will be destroyed when the thread exits!
  128.                     IThread list ( new ListThreadFn ( dlg.fileName(i) ) );
  129.                  };
  130.                  return;
  131.              };
  132.  
  133.           } while ( is_dir );
  134.       };
  135.  
  136.       // display copyright;
  137.       {
  138.            IFrameWindow copy(DLG_COPYRIGHT);
  139.            copy.setFocus();
  140.            // display for 1/2 second.
  141.            TimShow(copy,500);
  142.       };
  143.  
  144.  
  145.       // declare frame window which displays file
  146.       ListFrame list(file);
  147.  
  148.       // process messages on this thread.
  149.       IThread::current().processMsgs();
  150.    }
  151.  
  152.  
  153.    // catch exceptions that might have been thrown when showing frame.
  154.    catch(IException& exc)
  155.    {
  156.       long error = exc.errorId();
  157.       #ifdef DEBUG
  158.       const char * exctext = exc.text();
  159.       for ( int i=0; i < exc.locationCount() ; i++)
  160.       {
  161.          const IExceptionLocation & loc = * exc.locationAtIndex(i);
  162.          const char * file_name = loc.fileName();
  163.          const char * function_name = loc.functionName();
  164.          long ln = loc.lineNumber();
  165.  
  166.  
  167.          // set debugger break point here for debugging.
  168.          int k=i;
  169.       };
  170.       int kk=__IBMCPP__;
  171.       #endif // DEBUG
  172.       switch (error)
  173.       {
  174.       //#if __TOS_OS2__
  175.       //case PMERR_INVALID_HACCEL:     // I do not know why this exception happens
  176.       //  return;       // but it must be ignored to avoid error message.
  177.       //  break;
  178.       //#endif
  179.  
  180.         default:
  181.           // display exception in error message.
  182.           IMessageBox ( IWindow::desktopWindow() )
  183.             .show(exc);
  184.       };
  185.       throw;
  186.    };
  187.  
  188. };
  189.