| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 19 | ! Author(s): Harald Kornmayer 1/2001
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | #include "MBrowser.h"
|
|---|
| 27 |
|
|---|
| 28 | #include <iostream>
|
|---|
| 29 | #include <sys/stat.h> // S_ISDIR
|
|---|
| 30 |
|
|---|
| 31 | #include <TSystem.h> // gSystem
|
|---|
| 32 |
|
|---|
| 33 | #include <TGTab.h> // TGTab
|
|---|
| 34 | #include <TGMenu.h> // TGPopupMenu
|
|---|
| 35 | #include <TG3DLine.h> // TGHorizontal3DLine
|
|---|
| 36 | #include <TGButton.h> // TGTextButton
|
|---|
| 37 | #include <TGMsgBox.h> // TGMsgBox
|
|---|
| 38 | #include <TBrowser.h> // TBrowser
|
|---|
| 39 | #include <TGTextEntry.h> // TGTextEntry
|
|---|
| 40 | #include <TGFSComboBox.h> // TGFSComboBox, TGFSLboxEntry
|
|---|
| 41 | #include <TGProgressBar.h> // TGHProgressBar
|
|---|
| 42 | #include <TGFSContainer.h> // TGFileContainer
|
|---|
| 43 |
|
|---|
| 44 | #include "MGList.h"
|
|---|
| 45 |
|
|---|
| 46 | ClassImp(MBrowser);
|
|---|
| 47 |
|
|---|
| 48 | using namespace std;
|
|---|
| 49 |
|
|---|
| 50 | enum {
|
|---|
| 51 | kFileTBrowser,
|
|---|
| 52 | kFileClose,
|
|---|
| 53 | kButDirUp,
|
|---|
| 54 | kButListMode,
|
|---|
| 55 | kButDetailMode,
|
|---|
| 56 | kCBDirectory,
|
|---|
| 57 | kCBFilter,
|
|---|
| 58 | kTEFileName
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | void MBrowser::CreateMenuBar()
|
|---|
| 62 | {
|
|---|
| 63 | //
|
|---|
| 64 | // crate the menu bar
|
|---|
| 65 | //
|
|---|
| 66 | TGPopupMenu *filemenu = new TGPopupMenu(gClient->GetRoot());
|
|---|
| 67 | filemenu->AddEntry("Open &TBrowser", kFileTBrowser);
|
|---|
| 68 | filemenu->AddSeparator();
|
|---|
| 69 | filemenu->AddEntry("&Close", kFileClose);
|
|---|
| 70 | filemenu->Associate(this);
|
|---|
| 71 | fList->Add(filemenu);
|
|---|
| 72 |
|
|---|
| 73 | //
|
|---|
| 74 | // the button messages are handled by main frame (this)
|
|---|
| 75 | //
|
|---|
| 76 | TGLayoutHints *laymenubar = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 2, 2, 2, 2);
|
|---|
| 77 | TGLayoutHints *laymenuitem = new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0);
|
|---|
| 78 |
|
|---|
| 79 | fList->Add(laymenubar);
|
|---|
| 80 | fList->Add(laymenuitem);
|
|---|
| 81 |
|
|---|
| 82 | TGMenuBar *menubar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
|
|---|
| 83 | menubar->AddPopup("&File", filemenu, laymenuitem);
|
|---|
| 84 | AddFrame(menubar, laymenubar);
|
|---|
| 85 | fList->Add(menubar);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | void MBrowser::CreateUpperFrame(TGCompositeFrame *frametop)
|
|---|
| 89 | {
|
|---|
| 90 | TGLayoutHints *lay1 = new TGLayoutHints(kLHintsTop |kLHintsExpandX, 2, 2, 2, 0);
|
|---|
| 91 | TGLayoutHints *lay2 = new TGLayoutHints(kLHintsCenterY|kLHintsExpandX, 2, 2, 2, 2);
|
|---|
| 92 | TGLayoutHints *lay3 = new TGLayoutHints(kLHintsBottom |kLHintsExpandX, 2, 2, 0, 2);
|
|---|
| 93 | fList->Add(lay1);
|
|---|
| 94 | fList->Add(lay2);
|
|---|
| 95 | fList->Add(lay3);
|
|---|
| 96 |
|
|---|
| 97 | //
|
|---|
| 98 | // *********** Create Contents of frame top (upper part) **********
|
|---|
| 99 | //
|
|---|
| 100 | fTop1 = new TGHorizontalFrame(frametop, 500, 50);
|
|---|
| 101 | fTop2 = new TGHorizontalFrame(frametop, 500, 50);
|
|---|
| 102 | fTop3 = new TGHorizontalFrame(frametop, 500, 50);
|
|---|
| 103 |
|
|---|
| 104 | // FIXME: If I use TGLayoutHints the Progress Bar doesn't disappear!
|
|---|
| 105 | frametop->AddFrame(fTop1);//, lay1);
|
|---|
| 106 | frametop->AddFrame(fTop2);//, lay2);
|
|---|
| 107 | frametop->AddFrame(fTop3);//, lay3);
|
|---|
| 108 |
|
|---|
| 109 | fList->Add(fTop1);
|
|---|
| 110 | fList->Add(fTop2);
|
|---|
| 111 | fList->Add(fTop3);
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | void MBrowser::CreateDirListMenu(TGCompositeFrame *frame)
|
|---|
| 115 | {
|
|---|
| 116 | //
|
|---|
| 117 | // Layout Dir-Listbox and buttons in one row (frame)
|
|---|
| 118 | //
|
|---|
| 119 | // - layout:
|
|---|
| 120 | // alignment: top, left
|
|---|
| 121 | // padding: 5, 5, 5, 5
|
|---|
| 122 | //
|
|---|
| 123 | TGLayoutHints *laydir = new TGLayoutHints(kLHintsExpandX|kLHintsLeft|kLHintsCenterY); //, 5, 5, 5, 5);
|
|---|
| 124 | TGLayoutHints *layout = new TGLayoutHints(kLHintsRight|kLHintsCenterY, 10); //, 5, 5, 5);
|
|---|
| 125 |
|
|---|
| 126 | fList->Add(laydir);
|
|---|
| 127 | fList->Add(layout);
|
|---|
| 128 |
|
|---|
| 129 | //
|
|---|
| 130 | // Create Dir-Listbox and buttons in first frame
|
|---|
| 131 | //
|
|---|
| 132 | TGFSComboBox *dir = new TGFSComboBox(frame, kCBDirectory);
|
|---|
| 133 | dir->SetHeight(fEntry->GetHeight());
|
|---|
| 134 | dir->Associate(this);
|
|---|
| 135 | fList->Add(dir);
|
|---|
| 136 | frame->AddFrame(dir, laydir);
|
|---|
| 137 |
|
|---|
| 138 | const TGPicture *pic0 = fList->GetPicture("magic_t.xpm");
|
|---|
| 139 | if (!pic0)
|
|---|
| 140 | {
|
|---|
| 141 | TGTreeLBEntry *entry = new TGTreeLBEntry(dir->GetListBox()->GetContainer(),
|
|---|
| 142 | new TGString("/data/MAGIC"), pic0, 6000,
|
|---|
| 143 | new TGString("/data/MAGIC"));
|
|---|
| 144 | TGLayoutHints *laylb = new TGLayoutHints(kLHintsLeft|kLHintsTop, 14, 0, 0, 0);
|
|---|
| 145 | dir->AddEntry(entry, laylb);
|
|---|
| 146 | // Note necessary - deleted in ~TGLBContainer: fList->Add(laylb);
|
|---|
| 147 | fList->Add(entry);
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | //
|
|---|
| 151 | // Get the three picturs from the system (must be deleted by FreePicture)
|
|---|
| 152 | //
|
|---|
| 153 | const TGPicture *pic1 = fList->GetPicture("tb_list.xpm");
|
|---|
| 154 | if (pic1)
|
|---|
| 155 | {
|
|---|
| 156 | TGPictureButton *list = new TGPictureButton(frame, pic1, kButListMode);
|
|---|
| 157 | list->SetToolTipText("List Mode");
|
|---|
| 158 | list->SetState(kButtonUp);
|
|---|
| 159 | list->AllowStayDown(kTRUE);
|
|---|
| 160 | list->Associate(this);
|
|---|
| 161 | fList->Add(list);
|
|---|
| 162 | frame->AddFrame(list, layout);
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | const TGPicture *pic2 = fList->GetPicture("tb_details.xpm");
|
|---|
| 166 | if (pic2)
|
|---|
| 167 | {
|
|---|
| 168 | TGPictureButton *detail = new TGPictureButton(frame, pic2, kButDetailMode);
|
|---|
| 169 | detail->SetToolTipText("Details Mode");
|
|---|
| 170 | detail->SetState(kButtonEngaged);
|
|---|
| 171 | detail->AllowStayDown(kTRUE);
|
|---|
| 172 | detail->Associate(this);
|
|---|
| 173 | fList->Add(detail);
|
|---|
| 174 | frame->AddFrame(detail, layout);
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | const TGPicture *pic3 = fList->GetPicture("tb_uplevel.xpm");
|
|---|
| 178 | if (pic3)
|
|---|
| 179 | {
|
|---|
| 180 | TGPictureButton *cdup = new TGPictureButton(frame, pic3, kButDirUp);
|
|---|
| 181 | cdup->SetToolTipText("One Level up!");
|
|---|
| 182 | cdup->Associate(this);
|
|---|
| 183 | fList->Add(cdup);
|
|---|
| 184 | frame->AddFrame(cdup, layout);
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | void MBrowser::CreateDirListBox(TGCompositeFrame *frame)
|
|---|
| 189 | {
|
|---|
| 190 | //
|
|---|
| 191 | // Create file viewer (browser)
|
|---|
| 192 | //
|
|---|
| 193 | fFileView = new TGListView(frame, 540, 380);
|
|---|
| 194 | fList->Add(fFileView);
|
|---|
| 195 |
|
|---|
| 196 | TGViewPort *port = fFileView->GetViewPort();
|
|---|
| 197 | port->SetBackgroundColor(fgWhitePixel);
|
|---|
| 198 |
|
|---|
| 199 | fFileCont = new TGFileContainer(port, 100, 100, kVerticalFrame, fgWhitePixel);
|
|---|
| 200 | fList->Add(fFileCont);
|
|---|
| 201 |
|
|---|
| 202 | fFileView->SetContainer(fFileCont);
|
|---|
| 203 | fFileView->SetViewMode(kLVDetails);
|
|---|
| 204 |
|
|---|
| 205 | fFileCont->SetFilter("*.root");
|
|---|
| 206 | fFileCont->Associate(this);
|
|---|
| 207 | fFileCont->Sort(kSortByName);
|
|---|
| 208 |
|
|---|
| 209 | TGLayoutHints *layview = new TGLayoutHints(kLHintsTop|kLHintsExpandX|kLHintsExpandY); //, 5, 5, 5, 5);
|
|---|
| 210 | fList->Add(layview);
|
|---|
| 211 |
|
|---|
| 212 | frame->AddFrame(fFileView, layview);
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | void MBrowser::CreateTab1()
|
|---|
| 216 | {
|
|---|
| 217 | static const char *filters[] =
|
|---|
| 218 | {
|
|---|
| 219 | "*.root <root-files>",
|
|---|
| 220 | "* <All Files>",
|
|---|
| 221 | NULL
|
|---|
| 222 | };
|
|---|
| 223 |
|
|---|
| 224 | TGCompositeFrame *frame = CreateNewTab("Input File");
|
|---|
| 225 |
|
|---|
| 226 | //
|
|---|
| 227 | // Create three frames for the first tab
|
|---|
| 228 | //
|
|---|
| 229 | TGHorizontalFrame *tab1 = new TGHorizontalFrame(frame, 100, 100);
|
|---|
| 230 | TGVerticalFrame *tab2 = new TGVerticalFrame (frame, 100, 100);
|
|---|
| 231 |
|
|---|
| 232 | TGLayoutHints *laytab1 = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 10, 10, 10);
|
|---|
| 233 | TGLayoutHints *laytab2 = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 10, 10, 10, 10);
|
|---|
| 234 | TGLayoutHints *layfilter = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 10, 10, 10);
|
|---|
| 235 |
|
|---|
| 236 | fEntry = new TGTextEntry(frame, "", kTEFileName);
|
|---|
| 237 | fEntry->Associate(this);
|
|---|
| 238 |
|
|---|
| 239 | TGComboBox *filter = new TGComboBox(frame, kCBFilter);
|
|---|
| 240 | filter->SetHeight(fEntry->GetHeight());
|
|---|
| 241 | filter->Associate(this);
|
|---|
| 242 | for (int i=0; filters[i]; i++)
|
|---|
| 243 | filter->AddEntry(filters[i], i);
|
|---|
| 244 | filter->Select(0);
|
|---|
| 245 |
|
|---|
| 246 | frame->AddFrame(fEntry, laytab1);
|
|---|
| 247 | frame->AddFrame(tab1, laytab1);
|
|---|
| 248 | frame->AddFrame(filter, layfilter);
|
|---|
| 249 | frame->AddFrame(tab2, laytab2);
|
|---|
| 250 |
|
|---|
| 251 | CreateDirListMenu(tab1);
|
|---|
| 252 | CreateDirListBox(tab2);
|
|---|
| 253 |
|
|---|
| 254 | fList->Add(laytab1);
|
|---|
| 255 | fList->Add(laytab2);
|
|---|
| 256 | fList->Add(tab1);
|
|---|
| 257 | fList->Add(tab2);
|
|---|
| 258 | fList->Add(layfilter);
|
|---|
| 259 | fList->Add(fEntry);
|
|---|
| 260 | fList->Add(filter);
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | TGCompositeFrame *MBrowser::CreateNewTab(const char *name)
|
|---|
| 264 | {
|
|---|
| 265 | return fTabs->AddTab(name);
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | void MBrowser::CreateLowerFrame(TGCompositeFrame *framelow)
|
|---|
| 269 | {
|
|---|
| 270 | //
|
|---|
| 271 | // *********** Create Contents of frame low (downer part) **********
|
|---|
| 272 | //
|
|---|
| 273 |
|
|---|
| 274 | //
|
|---|
| 275 | // ----- Create Object holding the Tabs -----
|
|---|
| 276 | //
|
|---|
| 277 | fTabs = new TGTab(framelow, 400, 400);
|
|---|
| 278 | fList->Add(fTabs);
|
|---|
| 279 |
|
|---|
| 280 | TGLayoutHints *laytabs = new TGLayoutHints(kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
|
|---|
| 281 | fList->Add(laytabs);
|
|---|
| 282 |
|
|---|
| 283 | framelow->AddFrame(fTabs, laytabs);
|
|---|
| 284 |
|
|---|
| 285 | //
|
|---|
| 286 | // --- Create the first tab of the tabs ---
|
|---|
| 287 | //
|
|---|
| 288 | CreateTab1();
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | MBrowser::MBrowser(/*const TGWindow *main,*/ const TGWindow *p,
|
|---|
| 292 | const UInt_t w, const UInt_t h)
|
|---|
| 293 | //: TGTransientFrame(p?p:gClient->GetRoot(),
|
|---|
| 294 | // main?main:gClient->GetRoot(), w, h)
|
|---|
| 295 | : TGMainFrame(p?p:gClient->GetRoot(), w, h)
|
|---|
| 296 | {
|
|---|
| 297 | fList = new MGList;
|
|---|
| 298 | fList->SetOwner();
|
|---|
| 299 |
|
|---|
| 300 | CreateMenuBar();
|
|---|
| 301 |
|
|---|
| 302 | TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
|
|---|
| 303 | fList->Add(laylinesep);
|
|---|
| 304 |
|
|---|
| 305 | TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
|
|---|
| 306 | fList->Add(linesep);
|
|---|
| 307 | AddFrame(linesep, laylinesep);
|
|---|
| 308 |
|
|---|
| 309 | //
|
|---|
| 310 | // ---- Create the top window with a lot of buttons ----
|
|---|
| 311 | //
|
|---|
| 312 | TGLayoutHints *layframetop = new TGLayoutHints(kLHintsExpandX);
|
|---|
| 313 | fList->Add(layframetop);
|
|---|
| 314 |
|
|---|
| 315 | TGCompositeFrame *frametop = new TGCompositeFrame(this, 300, 100, kVerticalFrame);
|
|---|
| 316 | fList->Add(frametop);
|
|---|
| 317 | AddFrame(frametop, layframetop);
|
|---|
| 318 |
|
|---|
| 319 | linesep = new TGHorizontal3DLine(this);
|
|---|
| 320 | fList->Add(linesep);
|
|---|
| 321 | AddFrame(linesep, laylinesep);
|
|---|
| 322 |
|
|---|
| 323 | //
|
|---|
| 324 | // ---- Create the low window with a tabs in it ----
|
|---|
| 325 | //
|
|---|
| 326 | TGLayoutHints *layframelow = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
|
|---|
| 327 | fList->Add(layframelow);
|
|---|
| 328 |
|
|---|
| 329 | TGCompositeFrame *framelow = new TGCompositeFrame(this, 300, 100, kHorizontalFrame);
|
|---|
| 330 | fList->Add(framelow);
|
|---|
| 331 |
|
|---|
| 332 | AddFrame(framelow, layframelow);
|
|---|
| 333 |
|
|---|
| 334 | CreateUpperFrame(frametop);
|
|---|
| 335 | CreateLowerFrame(framelow);
|
|---|
| 336 |
|
|---|
| 337 | //
|
|---|
| 338 | // Map the window, set up the layout, etc.
|
|---|
| 339 | //
|
|---|
| 340 | ChangeDir();
|
|---|
| 341 | SetWMSizeHints(400, 350, 1000, 1000, 10, 10); // set the smallest and biggest size of the Main frame
|
|---|
| 342 | Move(rand()%100+50, rand()%100+50);
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 | MBrowser::~MBrowser()
|
|---|
| 347 | {
|
|---|
| 348 | delete fList;
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | TGProgressBar *MBrowser::CreateProgressBar(TGHorizontalFrame *frame)
|
|---|
| 352 | {
|
|---|
| 353 | static TGLayoutHints laybar(kLHintsCenterY|kLHintsRight/*|kLHintsExpandX*/,
|
|---|
| 354 | 10, 10);
|
|---|
| 355 |
|
|---|
| 356 | TGHProgressBar *bar=new TGHProgressBar(frame);
|
|---|
| 357 |
|
|---|
| 358 | bar->SetWidth(150);
|
|---|
| 359 | bar->ShowPosition();
|
|---|
| 360 |
|
|---|
| 361 | frame->AddFrame(bar, &laybar);
|
|---|
| 362 |
|
|---|
| 363 | Layout();
|
|---|
| 364 | MapSubwindows();
|
|---|
| 365 |
|
|---|
| 366 | return bar;
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | void MBrowser::DestroyProgressBar(TGProgressBar *bar)
|
|---|
| 370 | {
|
|---|
| 371 | TGHorizontalFrame *frame = (TGHorizontalFrame*)bar->GetParent();
|
|---|
| 372 |
|
|---|
| 373 | frame->RemoveFrame(bar);
|
|---|
| 374 |
|
|---|
| 375 | Layout();
|
|---|
| 376 | MapSubwindows();
|
|---|
| 377 |
|
|---|
| 378 | delete bar;
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | void MBrowser::CloseWindow()
|
|---|
| 382 | {
|
|---|
| 383 | // Got close message for this MainFrame. Calls parent CloseWindow()
|
|---|
| 384 | // (which destroys the window) and terminate the application.
|
|---|
| 385 | // The close message is generated by the window manager when its close
|
|---|
| 386 | // window menu item is selected.
|
|---|
| 387 |
|
|---|
| 388 | delete this;
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | Bool_t MBrowser::InputFileSelected()
|
|---|
| 392 | {
|
|---|
| 393 | //
|
|---|
| 394 | // Checks if there is a selected input root file
|
|---|
| 395 | //
|
|---|
| 396 | return !fInputFile.IsNull(); //[0]!='\0';
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | void MBrowser::DisplError(const char *txt)
|
|---|
| 400 | {
|
|---|
| 401 | Int_t retval;
|
|---|
| 402 | new TGMsgBox(fClient->GetRoot(), this, "Error!", txt,
|
|---|
| 403 | kMBIconExclamation, 4, &retval);
|
|---|
| 404 | }
|
|---|
| 405 |
|
|---|
| 406 | void MBrowser::DisplWarning(const char *txt)
|
|---|
| 407 | {
|
|---|
| 408 | Int_t retval;
|
|---|
| 409 | new TGMsgBox(fClient->GetRoot(), this, "Warning!", txt,
|
|---|
| 410 | kMBIconExclamation, 4, &retval);
|
|---|
| 411 | }
|
|---|
| 412 |
|
|---|
| 413 | void MBrowser::DisplInfo(const char *txt)
|
|---|
| 414 | {
|
|---|
| 415 | Int_t retval;
|
|---|
| 416 | new TGMsgBox(fClient->GetRoot(), this, "Information!", txt,
|
|---|
| 417 | kMBIconExclamation, 4, &retval);
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | void MBrowser::ChangeDir(const char *txt)
|
|---|
| 421 | {
|
|---|
| 422 | fFileCont->ChangeDirectory(txt?txt:gSystem->WorkingDirectory());
|
|---|
| 423 |
|
|---|
| 424 | const char *dir = fFileCont->GetDirectory();
|
|---|
| 425 |
|
|---|
| 426 | TGFSComboBox *cbox = (TGFSComboBox*)fList->FindWidget(kCBDirectory);
|
|---|
| 427 | if (cbox)
|
|---|
| 428 | cbox->Update(dir);
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | void MBrowser::SetFileName(TString name)
|
|---|
| 432 | {
|
|---|
| 433 | if (name[0]!='/')
|
|---|
| 434 | {
|
|---|
| 435 | name.Insert(0, "/");
|
|---|
| 436 | name.Insert(0, fFileCont->GetDirectory());
|
|---|
| 437 | }
|
|---|
| 438 |
|
|---|
| 439 | if (gSystem->AccessPathName(name, kFileExists))
|
|---|
| 440 | return;
|
|---|
| 441 |
|
|---|
| 442 | if (name.EndsWith(".root", TString::kIgnoreCase))
|
|---|
| 443 | fInputFile = name;
|
|---|
| 444 |
|
|---|
| 445 | fEntry->SetText(gSystem->BaseName(name));
|
|---|
| 446 |
|
|---|
| 447 | ChangeDir(gSystem->DirName(name));
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | void MBrowser::SetDir()
|
|---|
| 451 | {
|
|---|
| 452 | TGFSComboBox *cbox = (TGFSComboBox*)fList->FindWidget(kCBDirectory);
|
|---|
| 453 | if(!cbox)
|
|---|
| 454 | return;
|
|---|
| 455 |
|
|---|
| 456 | const TGTreeLBEntry *entry = (TGTreeLBEntry*)cbox->GetSelectedEntry();
|
|---|
| 457 |
|
|---|
| 458 | ChangeDir(entry->GetPath()->GetString());
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | void MBrowser::SetFilter()
|
|---|
| 462 | {
|
|---|
| 463 | //
|
|---|
| 464 | // Try to get widget from list
|
|---|
| 465 | //
|
|---|
| 466 | TGComboBox *filter = (TGComboBox*)fList->FindWidget(kCBFilter);
|
|---|
| 467 | if (!filter)
|
|---|
| 468 | return;
|
|---|
| 469 |
|
|---|
| 470 | //
|
|---|
| 471 | // Get the selected text from the list box
|
|---|
| 472 | //
|
|---|
| 473 | const TGTextLBEntry *selected = (TGTextLBEntry*)filter->GetListBox()->GetSelectedEntry();
|
|---|
| 474 |
|
|---|
| 475 | //
|
|---|
| 476 | // find filter and remove leading spaces
|
|---|
| 477 | //
|
|---|
| 478 | TString txt = selected->GetText()->GetString();
|
|---|
| 479 | if (txt.First('<') < 0)
|
|---|
| 480 | return;
|
|---|
| 481 |
|
|---|
| 482 | //
|
|---|
| 483 | // Set new filter and refresh the file container
|
|---|
| 484 | //
|
|---|
| 485 | txt.Remove(txt.First('<'));
|
|---|
| 486 |
|
|---|
| 487 | TString ftxt = txt.Strip();
|
|---|
| 488 | fFileCont->SetFilter(ftxt);
|
|---|
| 489 | fFileCont->DisplayDirectory();
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | void MBrowser::SetViewMode(const Int_t mode)
|
|---|
| 493 | {
|
|---|
| 494 | fFileView->SetViewMode(mode ? kLVList : kLVDetails);
|
|---|
| 495 |
|
|---|
| 496 | TGButton *but = (TGButton*)fList->FindWidget(mode);
|
|---|
| 497 | if(!but)
|
|---|
| 498 | return;
|
|---|
| 499 |
|
|---|
| 500 | but->SetState(kButtonUp);
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | // --------------------------------------------------------------------------
|
|---|
| 504 | //
|
|---|
| 505 | // Process events generated by the gui elements in the frame.
|
|---|
| 506 | //
|
|---|
| 507 | Bool_t MBrowser::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
|
|---|
| 508 | {
|
|---|
| 509 | switch (GET_MSG(msg))
|
|---|
| 510 | {
|
|---|
| 511 | case kC_TEXTENTRY:
|
|---|
| 512 | if (GET_SUBMSG(msg)!=kTE_ENTER)
|
|---|
| 513 | return kTRUE;
|
|---|
| 514 |
|
|---|
| 515 | SetFileName(fEntry->GetText());
|
|---|
| 516 | return kTRUE;
|
|---|
| 517 |
|
|---|
| 518 | case kC_COMMAND:
|
|---|
| 519 | switch (GET_SUBMSG(msg))
|
|---|
| 520 | {
|
|---|
| 521 | case kCM_MENU:
|
|---|
| 522 | switch (parm1)
|
|---|
| 523 | {
|
|---|
| 524 | case kFileClose:
|
|---|
| 525 | CloseWindow();
|
|---|
| 526 | return kTRUE;
|
|---|
| 527 |
|
|---|
| 528 | case kFileTBrowser:
|
|---|
| 529 | new TBrowser();
|
|---|
| 530 | return kTRUE;
|
|---|
| 531 | }
|
|---|
| 532 | return kTRUE;
|
|---|
| 533 |
|
|---|
| 534 | case kCM_BUTTON:
|
|---|
| 535 | switch (parm1)
|
|---|
| 536 | {
|
|---|
| 537 | case kButDirUp:
|
|---|
| 538 | //
|
|---|
| 539 | // goto the parent directory
|
|---|
| 540 | //
|
|---|
| 541 | ChangeDir("..");
|
|---|
| 542 | return kTRUE;
|
|---|
| 543 |
|
|---|
| 544 | case kButListMode:
|
|---|
| 545 | case kButDetailMode:
|
|---|
| 546 | SetViewMode(parm1);
|
|---|
| 547 | return kTRUE;
|
|---|
| 548 | }
|
|---|
| 549 | return kTRUE;
|
|---|
| 550 |
|
|---|
| 551 | case kCM_COMBOBOX:
|
|---|
| 552 | switch (parm1)
|
|---|
| 553 | {
|
|---|
| 554 | case kCBDirectory:
|
|---|
| 555 | SetDir();
|
|---|
| 556 | return kTRUE;
|
|---|
| 557 | case kCBFilter:
|
|---|
| 558 | SetFilter();
|
|---|
| 559 | return kTRUE;
|
|---|
| 560 | }
|
|---|
| 561 | return kTRUE;
|
|---|
| 562 | }
|
|---|
| 563 | return kTRUE;
|
|---|
| 564 |
|
|---|
| 565 | case kC_CONTAINER:
|
|---|
| 566 | switch (GET_SUBMSG(msg))
|
|---|
| 567 | {
|
|---|
| 568 |
|
|---|
| 569 | // case kCT_ITEMCLICK:
|
|---|
| 570 | // printf ("itemclick\n");
|
|---|
| 571 | // break;
|
|---|
| 572 |
|
|---|
| 573 | case kCT_ITEMDBLCLICK:
|
|---|
| 574 | //
|
|---|
| 575 | // process the double click in the file view container
|
|---|
| 576 | //
|
|---|
| 577 | if (parm1 != kButton1 || fFileCont->NumSelected() != 1)
|
|---|
| 578 | return kTRUE;
|
|---|
| 579 |
|
|---|
| 580 | //
|
|---|
| 581 | // one file selected
|
|---|
| 582 | //
|
|---|
| 583 | void *dummy = NULL;
|
|---|
| 584 | const TGFileItem *item = (TGFileItem *)fFileCont->GetNextSelected(&dummy);
|
|---|
| 585 |
|
|---|
| 586 | const char *str = item->GetItemName()->GetString();
|
|---|
| 587 |
|
|---|
| 588 | //
|
|---|
| 589 | // if the user choose a directory
|
|---|
| 590 | // change to this directory
|
|---|
| 591 | //
|
|---|
| 592 | if (S_ISDIR(item->GetType()))
|
|---|
| 593 | {
|
|---|
| 594 | ChangeDir(str);
|
|---|
| 595 | return kTRUE;
|
|---|
| 596 | }
|
|---|
| 597 |
|
|---|
| 598 | SetFileName(str);
|
|---|
| 599 | return kTRUE;
|
|---|
| 600 | }
|
|---|
| 601 | }
|
|---|
| 602 | return kTRUE;
|
|---|
| 603 | }
|
|---|