Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

FileMenu.cxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "EventDisplayBase/FileMenu.h"
00009 #include <cstdlib>
00010 #include <string>
00011 #include <iostream>
00012 #include "TGMsgBox.h"
00013 #include "TGMenu.h"
00014 #include "TGLayout.h"
00015 #include "TGFileDialog.h"
00016 #include "EventDisplayBase/evdb.h"
00017 #include "EventDisplayBase/PrintDialog.h"
00018 #include "EventDisplayBase/IoModule.h"
00019 using namespace evdb;
00020 
00021 // Define ID codes for the actions on the file menu
00022 enum {
00023   kM_FILE_OPEN,
00024   kM_FILE_SAVE,
00025   kM_FILE_SAVEAS,
00026   kM_FILE_CLOSE,
00027   kM_FILE_PRINT,
00028   kM_FILE_QUIT
00029 };
00030 
00031 //......................................................................
00032 
00033 FileMenu::FileMenu(TGMenuBar* menubar, TGMainFrame* mf) :
00034   fMainFrame(mf)
00035 {
00036   fFileMenu = new TGPopupMenu(gClient->GetRoot());
00037   fLayout   = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00038   
00039   // Create the list of functions. Associate each which a command code
00040   fFileMenu->AddEntry("&Open File...", kM_FILE_OPEN);
00041   fFileMenu->AddEntry("&Save",         kM_FILE_SAVE);
00042   fFileMenu->AddEntry("S&ave as...",   kM_FILE_SAVEAS);
00043   fFileMenu->AddSeparator();
00044   fFileMenu->AddEntry("&Print",        kM_FILE_PRINT);
00045   fFileMenu->AddSeparator();
00046   fFileMenu->AddEntry("&Quit",         kM_FILE_QUIT);
00047   
00048   fFileMenu->Connect("Activated(Int_t)",
00049                      "evdb::FileMenu",this,"HandleMenu(int)");
00050   
00051   // Attach the menu to the menu bar
00052   menubar->AddPopup("&File",fFileMenu,fLayout);
00053 }
00054 
00055 //......................................................................
00056 
00057 FileMenu::~FileMenu() 
00058 {
00059   if (fLayout)   { delete fLayout;   fLayout   = 0; }
00060   if (fFileMenu) { delete fFileMenu; fFileMenu = 0; }
00061 }
00062 
00063 //......................................................................
00064 
00065 void FileMenu::HandleMenu(int menu) 
00066 {
00067   switch(menu) {
00068   case kM_FILE_OPEN:   this->Open();   break;
00069   case kM_FILE_SAVE:   this->Save();   break;
00070   case kM_FILE_SAVEAS: this->SaveAs(); break;
00071   case kM_FILE_PRINT:  this->Print();  break;
00072   case kM_FILE_QUIT:   this->Quit(); break;
00073   default: this->NoImpl("??"); break;
00074   }
00075 }
00076 
00077 //......................................................................
00078 
00079 int FileMenu::Open() 
00080 {
00081   static TString dir(""); // Static so that directory remembers where
00082                           // we were last time
00083   const char* filetypes[] = { "ROOT files",  "*.root",
00084                               "All files",   "*",
00085                               0,             0 };
00086   TGFileInfo finfo;
00087   
00088   finfo.fFileTypes = filetypes;
00089   finfo.fIniDir    = StrDup(dir.Data());
00090   
00091   new TGFileDialog(evdb::TopWindow(),evdb::TopWindow(),kFDOpen, &finfo);
00092   
00093   // Add the file to the list of files in the IoModule. Make it the
00094   // current file
00095   IoModule::Instance()->AddFile(finfo.fFilename);
00096   IoModule::Instance()->GoToFile(finfo.fFilename);
00097   IoModule::Instance()->Reload();
00098   
00099   return 1;
00100 }
00101 
00102 //......................................................................
00103 
00104 int FileMenu::Save() 
00105 {
00106   this->NoImpl("Save");
00107   return 0;
00108 }
00109 
00110 //......................................................................
00111 
00112 int FileMenu::SaveAs() 
00113 {
00114   this->NoImpl("SaveAs");
00115   return 0;
00116 }
00117 
00118 //......................................................................
00119 
00120 int FileMenu::Print() 
00121 {
00122   new PrintDialog();
00123   return 1;
00124 }
00125 
00126 //......................................................................
00127 
00128 int FileMenu::Quit()
00129 {
00130   std::cout << "\n";
00131   exit(0);
00132 }
00133 
00134 //......................................................................
00135 
00136 int FileMenu::NoImpl(const char* method) 
00137 {
00138   std::string s;
00139   s = "Sorry action '"; s += method; s+= "' is not implemented.\n";
00140   // Why isn't this a memory leak? Dunno, but its seems the TG classes
00141   // are all managed by TGClient which takes care of deletion
00142   new TGMsgBox(evdb::TopWindow(), fMainFrame,
00143                "No implementation",s.c_str(),kMBIconExclamation);
00144   return 0;
00145 }
00146 

Generated on Sat Oct 11 02:35:27 2008 for NOvA Offline by  doxygen 1.3.9.1