scripttableviewer.h

Go to the documentation of this file.
00001 #ifndef SCRIPT_TABLE_VIEWER_HEADER_INCLUDED_p
00002 #define SCRIPT_TABLE_VIEWER_HEADER_INCLUDED_p
00003 //
00004 // Copyright 2010, Lowell Boggs Jr.
00005 //
00006 // This file or directory, containing source code for a computer program,
00007 // is Copyrighted by Lowell Boggs, Jr.  987 Regency Drive, Lewisville
00008 // TX (USA), 75067.  You may use, copy, modify, and distribute this
00009 // source file without charge or obligation so long as you agree to
00010 // the following:
00011 //
00012 //  1.  You must indemnify Lowell Boggs against any and all financial
00013 //      obligations caused by its use, misuse, function, or malfunction.
00014 //      Further, you acknowledge that there is no warranty of any kind,
00015 //      whatsoever.
00016 //
00017 //  2.  You agree not to attempt to patent any portion of this original
00018 //      work -- though you may attempt to patent your own extensions to
00019 //      it if you so choose.
00020 //
00021 //  3.  You keep this copyright notice with the file and all copies
00022 //      of the file and do not change it anyway except language translation.
00023 //
00024 // You are responsible for enforcing your own compliance with these
00025 // conditions and may not use this source file if you cannot agree to the
00026 // above terms and conditions.
00027 
00028 #include <cxxtls/tableeditor.h>
00029 #include <map>
00030 
00031 namespace cxxtls
00032 {
00033 
00034 class ScriptTableViewer
00035 : public TableEditor
00070 {
00071     std::string        scriptname_;
00072     std::string        fileError_;
00073     bool               keyKludge_;  // previous input key was ^X
00074     std::string        title_;      // displayed in top row of viewport
00075 
00076     std::vector<int>   invocationKeys_;  // keys that trigger script reinvocations 
00077 
00078     std::string        directory_; // current directory where script should run
00079 
00080     struct SessionInfo
00081     {
00082 
00083          std::map<std::string,std::string> options_;  
00084 
00085          CursorInfo  startCursorPosition_;
00086 
00087          std::string commandLine_;  
00088 
00089 
00090 
00091 
00092 
00093          std::vector< std::pair<size_t, size_t> > returnedCells_; 
00128 
00129 
00130          SessionInfo()
00131          :  startCursorPosition_(0,0,false)
00132          {
00133          }
00134 
00135          bool isPopup() const { return !returnedCells_.empty(); }
00137 
00138 
00139     };
00140 
00141     std::vector<SessionInfo> sessions_;  // Each level of script invocation is a session.
00142                                          // For example, the top level session is the invocation of the
00143                                          // script with parameters.  The table entries returned are selectable.
00144                                          // When a section of made from this table, session two is born.
00145                                          // When the user presses q from session 2, session 1 is restored.
00146                                          // 
00147 
00148     std::vector<std::pair<TableViewer, std::string> > prevScreenLayouts_;  
00149         // copies of the TableViewer contents, used to quickly
00150         // restore screen layouts after pages are exited.
00151 
00152 
00153     void handleReturnedCells();
00155 
00156 public:
00157 
00158     ScriptTableViewer(ViewerManager *vm,
00159               std::string const &scriptName,
00160               std::string        directory=std::string()
00161              );
00177     
00178     bool ok() const { return fileError_.empty(); }
00181     
00182     std::string const &error() const { return fileError_; }
00184     
00185     virtual ~ScriptTableViewer();
00186 
00187 
00188 
00189     virtual std::string const &application_name() const; 
00190     virtual std::string description() const;             
00191     static Viewer* app(ViewerManager*vm, std::string &fullname);
00197 
00198 
00199     virtual bool handle_event( CursorWindow::input_event const * e,
00200                              CursorWindow::viewport          * vp
00201                            );
00204 
00205     virtual void help();  
00206 
00207     void populateTable(std::string const &scriptParms, CursorWindow::viewport *vp=0);
00219 
00220     void invokeCommand(CursorWindow::viewport *vp, int cmdKey);
00221 
00222     void restartSession(CursorWindow::viewport *vp);
00223 
00224     virtual void repaintTitle(CursorWindow::viewport *vp);
00225 
00226     void setDir(std::string const &dir) { directory_ = dir; } 
00227 
00228 
00229     bool fieldExecutable(size_t tableRow, size_t tableCol) const
00240 
00241     {
00242        if(    tableRow >= rows_.size()
00243           ||  tableCol >= cols_.size()
00244          )
00245             return false; // invalid table location
00246 
00247        return rows_[tableRow].executable_ && cols_[tableCol].executable_;
00248     }
00249 
00250     bool fieldExecutable(CursorInfo const &cur) const
00260     {
00261       return fieldExecutable(cur.row_, cur.col_);
00262     }
00263 
00264     bool showPopup(CursorWindow::viewport *vp,
00265                    std::string const &definition, 
00266                    std::vector< std::pair<std::string,std::string> > &userInputs
00267                   );
00290                                               
00291     void saveScreenLayout()
00293     {
00294        prevScreenLayouts_.push_back( std::pair<TableViewer,std::string>(*this,title_) );
00295     }
00296 
00297     void restoreSavedScreenLayout()
00300     {
00301        TableViewer &me = *this;
00302        
00303        me     = prevScreenLayouts_.back().first;
00304        title_ = prevScreenLayouts_.back().second;
00305 
00306        prevScreenLayouts_.pop_back();
00307 
00308     }
00309 
00310     void discardSavedScreenLayout()
00312     {
00313        prevScreenLayouts_.pop_back();
00314     }
00315 
00316 };
00317 } // namespace cxxtls
00318 #endif
Generated on Wed Feb 29 22:50:04 2012 for CXXUtilities by  doxygen 1.6.3