home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm4.zip / source / listrun.cpp < prev    next >
C/C++ Source or Header  |  1998-04-22  |  6KB  |  178 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1998  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.     11900 Metric Blvd #J-181
  21.     Austin Tx 78758-3117
  22.     pelliott@io.com
  23. */
  24. #include "listrun.hpp"          // declares DisplayFile function
  25. #include "list.hpp"             // declares list frame object.
  26. #include "listthrd.hpp"         // list thread starter.
  27. #include "timeshow.hpp"         // show a window for a while.
  28. #include "exwmbox.hpp"         // Message box exception handler for a window.
  29.  
  30. #include <stdlib.h>
  31.  
  32. #include <istring.hpp>
  33. #include <ifiledlg.hpp>
  34.  
  35. #include "listpm.h"
  36. #include "IsDir.hpp"
  37.  
  38. // This code is is called to display a file in a frame window
  39. // on the current thread!
  40. void DisplayFile( IString file )
  41. {
  42.    ExcWinMsgBox       embox;      // message box exception function.
  43.  
  44.    // handle excetion on windows.
  45.    IWindow::setExceptionFunction( &embox );
  46.  
  47.    try
  48.    {
  49.  
  50.       // if we have been asked to list a directory.
  51.       if ( IsDir(file) )
  52.       {
  53.           // space for the fullfile name in the dialog.
  54.           char fullfile[_MAX_PATH];
  55.  
  56.           // create the fullpath of the current file.
  57.           _fullpath(fullfile,file,sizeof(fullfile));
  58.  
  59.           // space to store the parts of the current file.
  60.           char drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
  61.  
  62.           // split the file into parts.
  63.           _splitpath(fullfile,drive,dir,fname,ext);
  64.  
  65.           // space to store desired file
  66.           char usepath[_MAX_PATH];
  67.  
  68.           // make a wild card file path.
  69.           _makepath(usepath,drive,dir,"*","");
  70.  
  71.  
  72.           // settings for the dialog.
  73.           IFileDialog::Settings fsettings;
  74.  
  75.           // set files to chose from. all
  76.           fsettings.setFileName( IString(fullfile) + "\\*" );
  77.  
  78.           // set the initial drive discovered.
  79.           fsettings.setInitialDrive(drive);
  80.  
  81.           // set the title of this dialog.
  82.           fsettings.setTitle(STR_TITLEREPLACE);
  83.  
  84.           // This is an open dialog, choose amoung existing files.
  85.           fsettings.setOpenDialog();
  86.  
  87.  
  88.           // returned OK, is it directroy name of file which is chosen.
  89.           Boolean is_dir , ok ;
  90.           IString chosen_file;
  91.  
  92.           do
  93.           {
  94.              // create the dialog.
  95.              IFileDialog dlg( IWindow::desktopWindow(),
  96.                 IWindow::desktopWindow(),
  97.                 IFileDialog::defaultStyle() | IFileDialog::multiSelection ,
  98.                 fsettings);
  99.              // constructor will return when dialog has run to completion.
  100.  
  101.              ok =  dlg.pressedOK();
  102.  
  103.              if ( ok ) chosen_file = dlg.fileName();
  104.  
  105.              // requested file is a directory.
  106.              is_dir =  dlg.pressedOK() && IsDir( dlg.fileName() ) &&
  107.                        ( dlg.selectedFileCount() == 1 ) ;
  108.  
  109.              if (is_dir) fsettings.setFileName( ( chosen_file + "\\*" ) );
  110.              else if ( ok)
  111.              {
  112.                  // for each file selected by the dialog.
  113.                  for(int i=0; i< dlg.selectedFileCount() ; i++)
  114.                  {
  115.  
  116.                     // start a whole new thread to handle the new frame.
  117.                     // the new ListThreadFn will be stored in a managed pointer
  118.                     // and will be destroyed when the thread exits!
  119.                     IThread list ( new ListThreadFn ( dlg.fileName(i) ) );
  120.                  };
  121.                  return;
  122.              };
  123.  
  124.           } while ( is_dir );
  125.       };
  126.  
  127.       // display copyright;
  128.       {
  129.            IFrameWindow copy(DLG_COPYRIGHT);
  130.            copy.setFocus();
  131.            // display for 1/2 second.
  132.            TimShow(copy,500);
  133.       };
  134.  
  135.  
  136.       // declare frame window which displays file
  137.       ListFrame list(file);
  138.  
  139.       // process messages on this thread.
  140.       IThread::current().processMsgs();
  141.    }
  142.  
  143.  
  144.    // catch exceptions that might have been thrown when showing frame.
  145.    catch(IException& exc)
  146.    {
  147.       long error = exc.errorId();
  148.       #ifdef DEBUG
  149.       const char * exctext = exc.text();
  150.       for ( int i=0; i < exc.locationCount() ; i++)
  151.       {
  152.          const IExceptionLocation & loc = * exc.locationAtIndex(i);
  153.          const char * file_name = loc.fileName();
  154.          const char * function_name = loc.functionName();
  155.          long ln = loc.lineNumber();
  156.  
  157.  
  158.          // set debugger break point here for debugging.
  159.          int k=i;
  160.       };
  161.       #endif // DEBUG
  162.       switch (error)
  163.       {
  164.        // #if 0
  165.        case 0x101a:     // I do not know why this exception happens
  166.           return;       // but it must be ignored to avoid error message.
  167.           break;
  168.        // #endif
  169.        default:
  170.           // display exception in error message.
  171.           IMessageBox ( IWindow::desktopWindow() )
  172.             .show(exc);
  173.       };
  174.       throw;
  175.    };
  176.  
  177. };
  178.