LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
FileMenu.cxx
Go to the documentation of this file.
11 
12 #include <cstdlib>
13 #include <string>
14 #include <iostream>
15 
16 #include "TGMsgBox.h"
17 #include "TGMenu.h"
18 #include "TGLayout.h"
19 #include "TGFileDialog.h"
20 
21 namespace evdb{
22  // Define ID codes for the actions on the file menu
23  enum {
30  };
31 
32 
33  //......................................................................
34 
35  FileMenu::FileMenu(TGMenuBar* menubar, TGMainFrame* mf) :
36  fMainFrame(mf)
37  {
38  fFileMenu = new TGPopupMenu(gClient->GetRoot());
39  fLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
40 
41  // Create the list of functions. Associate each which a command code
42  fFileMenu->AddEntry("&Open File...", kM_FILE_OPEN);
43  fFileMenu->AddEntry("&Save", kM_FILE_SAVE);
44  fFileMenu->AddEntry("S&ave as...", kM_FILE_SAVEAS);
45  fFileMenu->AddSeparator();
46  fFileMenu->AddEntry("&Print", kM_FILE_PRINT);
47  fFileMenu->AddSeparator();
48  fFileMenu->AddEntry("&Quit", kM_FILE_QUIT);
49 
50  fFileMenu->Connect("Activated(Int_t)",
51  "evdb::FileMenu",this,"HandleFileMenu(int)");
52 
53  // Attach the menu to the menu bar
54  menubar->AddPopup("&File",fFileMenu,fLayout);
55  }
56 
57  //......................................................................
58 
60  {
61  if (fLayout) { delete fLayout; fLayout = 0; }
62  if (fFileMenu) { delete fFileMenu; fFileMenu = 0; }
63  }
64 
65  //......................................................................
66 
67  void FileMenu::HandleFileMenu(int menu)
68  {
69  switch(menu) {
70  case kM_FILE_OPEN: this->Open(); break;
71  case kM_FILE_SAVE: this->Save(); break;
72  case kM_FILE_SAVEAS: this->SaveAs(); break;
73  case kM_FILE_PRINT: this->Print(); break;
74  case kM_FILE_QUIT: this->Quit(); break;
75  default: this->NoImpl("??"); break;
76  }
77  }
78 
79  //......................................................................
80 
82  {
83  static TString dir(""); // Static so that directory remembers where
84  // we were last time
85  const char* filetypes[] = { "ROOT files", "*.root",
86  "All files", "*",
87  0, 0 };
88  TGFileInfo finfo;
89 
90  finfo.fFileTypes = filetypes;
91  finfo.fIniDir = StrDup(dir.Data());
92 
93  new TGFileDialog(evdb::TopWindow(),evdb::TopWindow(),kFDOpen, &finfo);
94 
95  return 1;
96  }
97 
98  //......................................................................
99 
101  {
102  this->NoImpl("Save");
103  return 0;
104  }
105 
106  //......................................................................
107 
109  {
110  this->NoImpl("SaveAs");
111  return 0;
112  }
113 
114  //......................................................................
115 
117  {
118  new PrintDialog();
119  return 1;
120  }
121 
122  //......................................................................
123 
125  {
126  std::cout << "\n";
127  exit(0);
128  }
129 
130  //......................................................................
131 
132  int FileMenu::NoImpl(const char* method)
133  {
134  std::string s;
135  s = "Sorry action '"; s += method; s+= "' is not implemented.\n";
136  // Why isn't this a memory leak? Dunno, but its seems the TG classes
137  // are all managed by TGClient which takes care of deletion
138  new TGMsgBox(evdb::TopWindow(), fMainFrame,
139  "No implementation",s.c_str(),kMBIconExclamation);
140  return 0;
141  }
142 }// end evdb namespace
TGPopupMenu * fFileMenu
The file menu.
Definition: FileMenu.h:40
Manage all things related to colors for the event display.
virtual ~FileMenu()
Definition: FileMenu.cxx:59
Pop up dialog for printing.
TGLayoutHints * fLayout
How to layout the menu.
Definition: FileMenu.h:41
TGMainFrame * fMainFrame
Main graphics frame.
Definition: FileMenu.h:39
The file pull down menu.
const TGWindow * TopWindow()
Definition: evdb.cxx:12
TDirectory * dir
Definition: macro.C:5
int NoImpl(const char *m)
Definition: FileMenu.cxx:132
void HandleFileMenu(int menu)
Definition: FileMenu.cxx:67
FileMenu(TGMenuBar *menubar, TGMainFrame *mf)
Definition: FileMenu.cxx:35