Logo ROOT   6.10/09
Reference Guide
TGFileBrowser.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Bertrand Bellenot 26/09/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TROOT.h"
13 #include "TSystem.h"
14 #include "TApplication.h"
15 #include "TGClient.h"
16 #include "TGListTree.h"
17 #include "TGLayout.h"
18 #include "TGComboBox.h"
19 #include "TContextMenu.h"
20 #include "TGTextEntry.h"
21 #include "TGTab.h"
22 #include "TGLabel.h"
23 #include "TSystemDirectory.h"
24 #include "TGMimeTypes.h"
25 #include "TClass.h"
26 #include "TQClass.h"
27 #include "TDataMember.h"
28 #include "TMethod.h"
29 #include "TMethodArg.h"
30 #include "TRealData.h"
31 #include "TInterpreter.h"
32 #include "TRegexp.h"
33 #include "TEnv.h"
34 #include "TImage.h"
35 #include "TBrowser.h"
36 #include "TRemoteObject.h"
37 #include "TKey.h"
38 #include "TKeyMapFile.h"
39 #include "TVirtualPad.h"
40 #include "Getline.h"
41 #include <time.h>
42 #include <string.h>
43 #include <stdlib.h>
44 
45 #include "TGFileBrowser.h"
46 #include "TRootBrowser.h"
47 #include "TGInputDialog.h"
48 
49 #include "TVirtualPadEditor.h"
50 #include "TGedEditor.h"
51 #include "TBaseClass.h"
52 
53 #include "RConfigure.h"
54 
55 #ifdef WIN32
56 const char rootdir[] = "\\";
57 #else
58 const char rootdir[] = "/";
59 #endif
60 
61 const char *filters[] = {
62  "",
63  "*.*",
64  "*.[C|c|h]*",
65  "*.root",
66  "*.txt"
67 };
68 
69 //_____________________________________________________________________________
70 //
71 // TCursorSwitcher
72 //
73 // Helper class used to change the cursor in a method and restore the
74 // original one when going out of the method scope.
75 //_____________________________________________________________________________
76 
77 ///////////////////////////////////////////////////////////////////////////////
78 class TCursorSwitcher {
79 private:
80  TGWindow *fW1;
81  TGWindow *fW2;
82 public:
83  TCursorSwitcher(TGWindow *w1, TGWindow *w2) : fW1(w1), fW2(w2) {
84  if (w1) gVirtualX->SetCursor(w1->GetId(), gVirtualX->CreateCursor(kWatch));
85  if (w2) gVirtualX->SetCursor(w2->GetId(), gVirtualX->CreateCursor(kWatch));
86  }
87  ~TCursorSwitcher() {
88  if (fW1) gVirtualX->SetCursor(fW1->GetId(), gVirtualX->CreateCursor(kPointer));
89  if (fW2) gVirtualX->SetCursor(fW2->GetId(), gVirtualX->CreateCursor(kPointer));
90  }
91 };
92 
93 //_____________________________________________________________________________
94 //
95 // TGFileBrowser
96 //
97 // System file browser, used as TRootBrowser plug-in.
98 // This class is the real core of the ROOT browser.
99 //_____________________________________________________________________________
100 
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// TGFileBrowser constructor.
105 
107  : TGMainFrame(p, w, h), TBrowserImp(b), fNewBrowser(0)
108 {
109  if (p && p != gClient->GetDefaultRoot())
110  fNewBrowser = (TRootBrowser *)p->GetMainFrame();
111  if (fNewBrowser)
112  fNewBrowser->SetActBrowser(this);
113  CreateBrowser();
114  Resize(w, h);
115  if (fBrowser) Show();
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Create the actual file browser.
120 
122 {
123  fCachedPic = 0;
124  SetCleanup(kDeepCleanup);
125 
126  fTopFrame = new TGHorizontalFrame(this, 100, 30);
127  fDrawOption = new TGComboBox(fTopFrame, "");
128  TGTextEntry *dropt_entry = fDrawOption->GetTextEntry();
129  dropt_entry->SetToolTipText("Object Draw Option", 300);
130  fDrawOption->Resize(80, 20);
131  TGListBox *lb = fDrawOption->GetListBox();
132  lb->Resize(lb->GetWidth(), 120);
133  Int_t dropt = 1;
134  fDrawOption->AddEntry("", dropt++);
135  fDrawOption->AddEntry("box", dropt++);
136  fDrawOption->AddEntry("colz", dropt++);
137  fDrawOption->AddEntry("lego", dropt++);
138  fDrawOption->AddEntry("lego1", dropt++);
139  fDrawOption->AddEntry("lego2", dropt++);
140  fDrawOption->AddEntry("same", dropt++);
141  fDrawOption->AddEntry("surf", dropt++);
142  fDrawOption->AddEntry("surf1", dropt++);
143  fDrawOption->AddEntry("surf2", dropt++);
144  fDrawOption->AddEntry("surf3", dropt++);
145  fDrawOption->AddEntry("surf4", dropt++);
146  fDrawOption->AddEntry("surf5", dropt++);
147  fDrawOption->AddEntry("text", dropt++);
148  fTopFrame->AddFrame(fDrawOption, new TGLayoutHints(kLHintsCenterY |
149  kLHintsRight, 2, 2, 2, 2));
150  fTopFrame->AddFrame(new TGLabel(fTopFrame, "Draw Option:"),
152  5, 2, 2, 2));
153 
154  fSortButton = new TGPictureButton(fTopFrame, "bld_sortup.png");
155  fSortButton->SetStyle(gClient->GetStyle());
156  fSortButton->SetToolTipText("Sort Alphabetically\n(Current folder only)");
157  fTopFrame->AddFrame(fSortButton, new TGLayoutHints(kLHintsCenterY |
158  kLHintsLeft, 2, 2, 2, 2));
159  fSortButton->Connect("Clicked()", "TGFileBrowser", this, "ToggleSort()");
160 
161  fFilterButton = new TGPictureButton(fTopFrame, "filter.png");
162  fFilterButton->SetStyle(gClient->GetStyle());
163  fFilterButton->SetToolTipText("Filter Content");
164  fTopFrame->AddFrame(fFilterButton, new TGLayoutHints(kLHintsCenterY |
165  kLHintsLeft, 2, 2, 2, 2));
166  fFilterButton->Connect("Clicked()", "TGFileBrowser", this, "RequestFilter()");
167 
168  fRefreshButton = new TGPictureButton(fTopFrame, "refresh.png");
169  fRefreshButton->SetStyle(gClient->GetStyle());
170  fRefreshButton->SetToolTipText("Refresh Current Folder");
171  fTopFrame->AddFrame(fRefreshButton, new TGLayoutHints(kLHintsCenterY |
172  kLHintsLeft, 2, 5, 2, 2));
173  fRefreshButton->Connect("Clicked()", "TGFileBrowser", this, "Refresh()");
174 
175  AddFrame(fTopFrame, new TGLayoutHints(kLHintsLeft | kLHintsTop |
176  kLHintsExpandX, 2, 2, 2, 2));
177  fCanvas = new TGCanvas(this, 100, 100);
178  fListTree = new TGListTree(fCanvas, kHorizontalFrame);
179  AddFrame(fCanvas, new TGLayoutHints(kLHintsLeft | kLHintsTop |
181  fListTree->Connect("DoubleClicked(TGListTreeItem *, Int_t)",
182  "TGFileBrowser", this, "DoubleClicked(TGListTreeItem *, Int_t)");
183  fListTree->Connect("Clicked(TGListTreeItem *, Int_t, Int_t, Int_t)",
184  "TGFileBrowser", this, "Clicked(TGListTreeItem *, Int_t, Int_t, Int_t)");
185  fListTree->Connect("Checked(TObject*, Bool_t)", "TGFileBrowser",
186  this, "Checked(TObject*, Bool_t)");
187 
188  fRootIcon = gClient->GetPicture("rootdb_t.xpm");
189  fFileIcon = gClient->GetPicture("doc_t.xpm");
190 
191  fBotFrame = new TGHorizontalFrame(this, 100, 30);
192  fBotFrame->AddFrame(new TGLabel(fBotFrame, "Filter: "),
194  2, 2, 2, 2));
195  fFileType = new TGComboBox(fBotFrame, " All Files (*.*)");
196  Int_t ftype = 1;
197  fFileType->AddEntry(" All Files (*.*)", ftype++);
198  fFileType->AddEntry(" C/C++ Files (*.c;*.cxx;*.h;...)", ftype++);
199  fFileType->AddEntry(" ROOT Files (*.root)", ftype++);
200  fFileType->AddEntry(" Text Files (*.txt)", ftype++);
201  fFileType->Resize(200, 20);
202  fBotFrame->AddFrame(fFileType, new TGLayoutHints(kLHintsLeft | kLHintsTop |
203  kLHintsExpandX, 2, 2, 2, 2));
204  fFileType->Connect("Selected(Int_t)", "TGFileBrowser", this,
205  "ApplyFilter(Int_t)");
206  fFileType->GetTextEntry()->Connect("ReturnPressed()", "TGFileBrowser",
207  this, "ApplyFilter(Int_t = -1)");
208  AddFrame(fBotFrame, new TGLayoutHints(kLHintsLeft | kLHintsTop |
209  kLHintsExpandX, 2, 2, 2, 2));
210 
211  fContextMenu = new TContextMenu("FileBrowserContextMenu");
212  fFilter = 0;
213  fGroupSize = 1000;
214  fListLevel = 0;
215  fCurrentDir = 0;
216  fRootDir = 0;
217  fDir = 0;
218  fFile = 0;
219  fNKeys = 0;
220  fCnt = 0;
221  fFilterStr = "*";
222 
223  TString gv = gEnv->GetValue("Browser.GroupView", "1000");
224  Int_t igv = atoi(gv.Data());
225  if (igv > 10)
226  fGroupSize = igv;
227 
228  if (gEnv->GetValue("Browser.ShowHidden", 0))
229  fShowHidden = kTRUE;
230  else
231  fShowHidden = kFALSE;
232 
233  fDblClick = kFALSE;
234 
235  TQObject::Connect("TGHtmlBrowser", "Clicked(char*)",
236  "TGFileBrowser", this, "Selected(char*)");
237 
238  TQObject::Connect("TPad", "Modified()",
239  "TGFileBrowser", this, "PadModified()");
240 
241  fListLevel = 0;
242  MapSubwindows();
243  Resize(GetDefaultSize());
244  MapWindow();
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Destructor.
249 
251 {
252  TQObject::Disconnect("TGHtmlBrowser", "Clicked(char*)");
253  TQObject::Disconnect("TPad", "Modified()");
254 
255  delete fContextMenu;
256  delete fListTree;
257  if (fRootIcon) fClient->FreePicture(fRootIcon);
258  if (fCachedPic && (fCachedPic != fFileIcon))
259  fClient->FreePicture(fCachedPic);
260  if (fFileIcon) fClient->FreePicture(fFileIcon);
261  Cleanup();
262 }
263 
264 ////////////////////////////////////////////////////////////////////////////////
265 /// Helper function checking if a class has a graphic properties editor.
266 
268 {
269  TBaseClass *base;
270  TList* bcl = cl->GetListOfBases();
271  TIter next(bcl);
272  while ((base = (TBaseClass*) next())) {
273  cl = base->GetClassPointer();
274  if (cl && TClass::GetClass(Form("%sEditor", cl->GetName())))
275  return kTRUE;
276  if (IsObjectEditable(cl))
277  return kTRUE;
278  }
279  return kFALSE;
280 }
281 
282 ////////////////////////////////////////////////////////////////////////////////
283 /// Format the tooltip information, based on the object passed in argument.
284 
285 static const char *FormatToolTip(TObject *obj, Int_t maxlen=0)
286 {
287  static TString infos;
288  if (!obj) {
289  infos.Clear();
290  return 0;
291  }
292  infos = obj->GetName();
293  if (obj->GetTitle()) {
294  infos += "\n";
295  infos += obj->GetTitle();
296  }
297  if (maxlen > 0 && infos.Length() > maxlen) {
298  infos.Remove(maxlen - 3);
299  infos += "...";
300  }
301  TString objinfo = obj->GetObjectInfo(1, 1);
302  if (!objinfo.IsNull() && !objinfo.BeginsWith("x=")) {
303  Long64_t bsize, fsize, objsize;
304  objsize = objinfo.Atoll();
305  if (objsize > 0) {
306  infos += "\n";
307  bsize = fsize = objsize;
308  if (fsize > 1024) {
309  fsize /= 1024;
310  if (fsize > 1024) {
311  // 3.7MB is more informative than just 3MB
312  infos += TString::Format("Size: %lld.%lldM", fsize/1024,
313  (fsize%1024)/103);
314  } else {
315  infos += TString::Format("Size: %lld.%lldK", bsize/1024,
316  (bsize%1024)/103);
317  }
318  } else {
319  infos += TString::Format("Size: %lld bytes", bsize);
320  }
321  }
322  }
323  return infos.Data();
324 }
325 
326 /**************************************************************************/
327 // TBrowserImp virtuals
328 /**************************************************************************/
329 
330 ////////////////////////////////////////////////////////////////////////////////
331 /// Add items to the browser. This function has to be called
332 /// by the Browse() member function of objects when they are
333 /// called by a browser. If check < 0 (default) no check box is drawn,
334 /// if 0 then unchecked checkbox is added, if 1 checked checkbox is added.
335 
336 void TGFileBrowser::Add(TObject *obj, const char *name, Int_t check)
337 {
338  if (fListLevel && !strcmp(fListLevel->GetText(), "Classes") &&
339  fListLevel->GetParent() &&
340  !strcmp(fListLevel->GetParent()->GetText(), "root")) {
341  // Browsing list of root classes...
342  }
343  else {
344  if (obj && obj->InheritsFrom("TApplication"))
345  fListLevel = 0;
346  if (obj && obj->InheritsFrom("TSystemDirectory"))
347  return;
348  }
349  if (fListLevel) {
350  TString oname = "";
351  if (name) oname = name;
352  else if (obj) oname = obj->GetName();
353  // check if the current item is filtered
354  mFiltered_i it = fFilteredItems.find(fListLevel);
355  if (it != fFilteredItems.end()) {
356  // check if the item (object) name match the filter
357  const char *filter = (const char *)(*it).second;
358  TRegexp re(filter, kTRUE);
359  // if not, simply return, so no item will be added
360  if (oname.Index(re) == kNPOS) return;
361  }
362  }
363  const TGPicture *pic=0;
364  if (obj && obj->InheritsFrom("TKey") && (obj->IsA() != TClass::Class()))
365  AddKey(fListLevel, obj, name);
366  else if (obj) {
367  GetObjPicture(&pic, obj);
368  if (!name) name = obj->GetName();
369  if (check > -1) {
370  if (!fListTree->FindChildByName(fListLevel, name)) {
371  TGListTreeItem *item = fListTree->AddItem(fListLevel, name, obj,
372  pic, pic, kTRUE);
373  if ((pic != fFileIcon) && (pic != fCachedPic))
374  fClient->FreePicture(pic);
375  if (item) fListTree->CheckItem(item, (Bool_t)check);
376  fListTree->SetToolTipItem(item, FormatToolTip(obj, 32));
377  }
378  }
379  else {
380  // special case for remote object
381  Bool_t isRemote = kFALSE;
382  if (obj->InheritsFrom("TRemoteObject"))
383  isRemote = kTRUE;
384  else if (fListLevel) {
385  // check also if one of its parents is a remote object
386  TGListTreeItem *top = fListLevel;
387  while (top->GetParent()) {
388  TObject *tobj = (TObject *) top->GetUserData();
389  if (tobj && (tobj->InheritsFrom("TRemoteObject") ||
390  tobj->InheritsFrom("TApplicationRemote"))) {
391  isRemote = kTRUE;
392  break;
393  }
394  top = top->GetParent();
395  }
396  }
397  if (isRemote) {
398  TRemoteObject *robj = (TRemoteObject *)obj;
399  if (!strcmp(robj->GetClassName(), "TKey")) {
400  AddKey(fListLevel, obj, name);
401  }
402  else {
403  TString fname = name;
404  // add the remote object only if not already in the list
405  if (!fShowHidden && fname.BeginsWith("."))
406  return;
407  AddRemoteFile(obj);
408  }
409  }
410  else {
411  if (!fListTree->FindChildByName(fListLevel, name)) {
412  TGListTreeItem *item = fListTree->AddItem(fListLevel, name, obj, pic, pic);
413  if ((pic != fFileIcon) && (pic != fCachedPic))
414  fClient->FreePicture(pic);
415  if (item && obj && obj->InheritsFrom("TObject"))
416  item->SetDNDSource(kTRUE);
417  fListTree->SetToolTipItem(item, FormatToolTip(obj, 32));
418  }
419  }
420  }
421  }
422 }
423 
424 ////////////////////////////////////////////////////////////////////////////////
425 /// Add remote file in list tree.
426 
428 {
429  Bool_t is_link;
430  Int_t type;
431  TString filename;
432  const TGPicture *spic;
433  TGPicture *pic;
434 
435  FileStat_t sbuf;
436 
437  type = 0;
438  is_link = kFALSE;
439 
440  TRemoteObject *robj = (TRemoteObject *)obj;
441 
442  robj->GetFileStat(&sbuf);
443  is_link = sbuf.fIsLink;
444  type = sbuf.fMode;
445  filename = robj->GetName();
446  if (R_ISDIR(type) || fFilter == 0 ||
447  (fFilter && filename.Index(*fFilter) != kNPOS)) {
448 
449  GetFilePictures(&spic, type, is_link, filename);
450 
451  pic = (TGPicture*)spic; pic->AddReference();
452 
453  if ((!fListTree->FindChildByName(fListLevel, filename)) &&
454  (!fListTree->FindChildByData(fListLevel, obj)))
455  fListTree->AddItem(fListLevel, filename, obj, pic, pic);
456  }
457 }
458 
459 ////////////////////////////////////////////////////////////////////////////////
460 /// Browse object. This, in turn, will trigger the calling of
461 /// TBrowser::Add() which will fill the IconBox and the tree.
462 /// Emits signal "BrowseObj(TObject*)".
463 
465 {
466  if (fNewBrowser)
467  fNewBrowser->SetActBrowser(this);
468  if (obj != gROOT) {
469  if (!fListTree->FindItemByObj(fListTree->GetFirstItem(), obj)) {
470  fListLevel = 0;
471  Add(obj);
472  fListLevel = fListTree->FindItemByObj(fListTree->GetFirstItem(), obj);
473  fListTree->HighlightItem(fListLevel);
474  if (obj->IsFolder())
475  fListTree->OpenItem(fListLevel);
476  fListTree->ClearViewPort();
477  fListTree->AdjustPosition(fListLevel);
478  }
479  }
480  if (fBrowser) obj->Browse(fBrowser);
481  if (obj == gROOT) {
482  TList *volumes = gSystem->GetVolumes("all");
483  TList *curvol = gSystem->GetVolumes("cur");
484  if (volumes && curvol) {
485  const char *curdrive;
486  TNamed *named = (TNamed *)curvol->At(0);
487  if (named)
488  curdrive = named->GetName();
489  else
490  curdrive = "C:";
491  TIter next(volumes);
492  TNamed *drive;
493  while ((drive = (TNamed *)next())) {
494  AddFSDirectory(TString::Format("%s\\", drive->GetName()), drive->GetTitle(),
495  (strcmp(drive->GetName(), curdrive) == 0) ?
496  "SetRootDir" : "Add");
497  }
498  delete volumes;
499  delete curvol;
500  }
501  else {
502  AddFSDirectory("/");
503  }
504  GotoDir(gSystem->WorkingDirectory());
505  if (gROOT->GetListOfFiles() && !gROOT->GetListOfFiles()->IsEmpty())
506  Selected(0);
507  }
508 }
509 
510 ////////////////////////////////////////////////////////////////////////////////
511 /// Emits signal when double clicking on icon.
512 
514 {
515  if (fNewBrowser)
516  fNewBrowser->Checked(obj, checked);
517 }
518 
519 ////////////////////////////////////////////////////////////////////////////////
520 /// returns drawing option
521 
523 {
524  return fDrawOption->GetTextEntry()->GetText();
525 }
526 
527 ////////////////////////////////////////////////////////////////////////////////
528 /// Determine the file picture for the given file type.
529 
530 void TGFileBrowser::GetFilePictures(const TGPicture **pic, Int_t file_type,
531  Bool_t is_link, const char *name)
532 {
533  static TString cached_ext;
534  static const TGPicture *cached_spic = 0;
535  const char *ext = name ? strrchr(name, '.') : 0;
536  TString sname = name ? name : " ";
537  *pic = 0;
538 
539  if (ext && cached_spic && (cached_ext == ext)) {
540  *pic = cached_spic;
541  return;
542  }
543 
544  if (R_ISREG(file_type)) {
545  *pic = gClient->GetMimeTypeList()->GetIcon(name, kTRUE);
546 
547  if (*pic) {
548  if (ext) {
549  cached_ext = ext;
550  cached_spic = *pic;
551  return;
552  }
553  }
554  } else {
555  *pic = 0;
556  }
557 
558  if (*pic == 0) {
559  *pic = gClient->GetPicture("doc_t.xpm");
560 
561  if (R_ISREG(file_type) && (file_type) & kS_IXUSR) {
562  *pic = gClient->GetPicture("app_t.xpm");
563  }
564  if (R_ISDIR(file_type)) {
565  *pic = gClient->GetPicture("folder_t.xpm");
566  }
567  if(sname.EndsWith(".root")) {
568  *pic = gClient->GetPicture("rootdb_t.xpm");
569  }
570 
571  }
572  if (is_link) {
573  *pic = gClient->GetPicture("slink_t.xpm");
574  }
575 
576  cached_spic = 0;
577  cached_ext = "";
578 }
579 
580 ////////////////////////////////////////////////////////////////////////////////
581 /// Recursively remove object.
582 
584 {
585  TGListTreeItem *itm = 0, *item = 0;
586  if (obj->InheritsFrom("TFile")) {
587  itm = fListTree->FindChildByData(0, gROOT->GetListOfFiles());
588  if (itm)
589  item = fListTree->FindChildByData(itm, obj);
590  if (item) {
591  // if the item to be deleted has a filter,
592  // delete its entry in the map
593  if (CheckFiltered(item))
594  fFilteredItems.erase(item);
595  fListTree->DeleteItem(item);
596  }
597  itm = fRootDir ? fRootDir->GetFirstChild() : 0;
598  while (itm) {
599  item = fListTree->FindItemByObj(itm, obj);
600  if (item) {
601  fListTree->DeleteChildren(item);
602  item->SetUserData(0);
603  }
604  itm = itm->GetNextSibling();
605  }
606  }
607  if (!obj->InheritsFrom("TFile") && fRootDir) {
608  item = fListTree->FindItemByObj(fRootDir, obj);
609  // if the item to be deleted has a filter, delete its entry in the map
610  if (item && CheckFiltered(item))
611  fFilteredItems.erase(item);
612  fListTree->RecursiveDeleteItem(fRootDir, obj);
613  }
614  //fListTree->ClearViewPort();
615 }
616 
617 ////////////////////////////////////////////////////////////////////////////////
618 /// Refresh content of the list tree.
619 
621 {
622  TTimer::SingleShot(200, "TGFileBrowser", this, "Update()");
623  return; // disable refresh for the time being...
624  // coverity[unreachable]
625  TCursorSwitcher cursorSwitcher(this, fListTree);
626  static UInt_t prev = 0;
627  UInt_t curr = gROOT->GetListOfBrowsables()->GetSize();
628  if (!prev) prev = curr;
629 
630  if (prev != curr) { // refresh gROOT
631  TGListTreeItem *sav = fListLevel;
632  fListLevel = 0;
633  BrowseObj(gROOT);
634  fListLevel = sav;
635  prev = curr;
636  }
637 }
638 
639 ////////////////////////////////////////////////////////////////////////////////
640 /// Update content of the list tree.
641 
643 {
644  Long64_t size = 0;
645  Long_t id = 0, flags = 0, modtime = 0;
646  char path[1024];
647  TGListTreeItem *item = fCurrentDir;
648  if (!item) item = fRootDir;
649  if (!item) return;
650  //fListTree->DeleteChildren(item);
651  TGListTreeItem *curr = fListTree->GetSelected(); // GetCurrent() ??
652  if (curr) {
653  TObject *obj = (TObject *) curr->GetUserData();
654  if (obj && !obj->TestBit(kNotDeleted)) {
655  // if the item to be deleted has a filter,
656  // delete its entry in the map
657  if (CheckFiltered(curr))
658  fFilteredItems.erase(curr);
659  fListTree->DeleteItem(curr);
660  curr = 0;
661  obj = 0;
662  }
663  else if (obj && obj->TestBit(kNotDeleted) &&
664  obj->InheritsFrom("TObjString") && curr->GetParent()) {
665  fListTree->GetPathnameFromItem(curr->GetParent(), path);
666  if (strlen(path) > 1) {
667  TString dirpath = FullPathName(curr->GetParent());
668  Int_t res = gSystem->GetPathInfo(dirpath.Data(), &id, &size,
669  &flags, &modtime);
670  if ((res == 0) && (flags & 2)) {
671  TString fullpath = FullPathName(curr);
672  if (gSystem->AccessPathName(fullpath.Data())) {
673  // if the item to be deleted has a filter,
674  // delete its entry in the map
675  if (CheckFiltered(curr))
676  fFilteredItems.erase(curr);
677  fListTree->DeleteItem(curr);
678  curr = 0;
679  obj = 0;
680  }
681  }
682  }
683  }
684  }
685  TString actpath = FullPathName(item);
686  flags = id = size = modtime = 0;
687  if (gSystem->GetPathInfo(actpath.Data(), &id, &size, &flags, &modtime) == 0) {
688  Int_t isdir = (Int_t)flags & 2;
689 
690  TString savdir = gSystem->WorkingDirectory();
691  if (isdir) {
692  TGListTreeItem *del = 0, *itm = item->GetFirstChild();
693  while (itm) {
694  fListTree->GetPathnameFromItem(itm, path);
695  if (strlen(path) > 1) {
696  TString recpath = FullPathName(itm);
697  if (gSystem->AccessPathName(recpath.Data())) {
698  del = itm;
699  itm = itm->GetNextSibling();
700  // if the item to be deleted has a filter,
701  // delete its entry in the map
702  if (CheckFiltered(del))
703  fFilteredItems.erase(del);
704  fListTree->DeleteItem(del);
705  }
706  }
707  if (del)
708  del = 0;
709  else
710  itm = itm->GetNextSibling();
711  }
712  }
713  }
714  TGListTreeItem *sav = fListLevel;
715  DoubleClicked(item, 1);
716  fListLevel = sav;
717  CheckFiltered(fListLevel, kTRUE);
718 }
719 
720 /**************************************************************************/
721 // Other
722 /**************************************************************************/
723 
724 ////////////////////////////////////////////////////////////////////////////////
725 /// Add file system directory in the list tree.
726 
727 void TGFileBrowser::AddFSDirectory(const char *entry, const char *path,
728  Option_t *opt)
729 {
730  TGListTreeItem *item = 0;
731  if ((opt == 0) || (!opt[0])) {
732  if (fRootDir == 0 && !fListTree->FindChildByName(0, rootdir))
733  item = fRootDir = fListTree->AddItem(0, rootdir);
734  return;
735  }
736  if (strstr(opt, "SetRootDir")) {
737  if (!fListTree->FindChildByName(0, entry))
738  item = fRootDir = fListTree->AddItem(0, entry);
739  }
740  else if (strstr(opt, "Add")) {
741  // MT: i give up! wanted to place entries for selected
742  // directories like home, pwd, alice-macros.
743  // TGListTreeItem *lti = fListTree->AddItem(0, entry);
744  //
745  if (!fListTree->FindChildByName(0, entry))
746  item = fListTree->AddItem(0, entry);
747  }
748  if (item && path) {
749  TString infos = path;
750  item->SetTipText(path);
751  TGPicture *pic = 0;
752  if (infos.Contains("Removable"))
753  pic = (TGPicture *)gClient->GetPicture("fdisk_t.xpm");
754  else if (infos.Contains("Local"))
755  pic = (TGPicture *)gClient->GetPicture("hdisk_t.xpm");
756  else if (infos.Contains("CD"))
757  pic = (TGPicture *)gClient->GetPicture("cdrom_t.xpm");
758  else if (infos.Contains("Network"))
759  pic = (TGPicture *)gClient->GetPicture("netdisk_t.xpm");
760  if (pic)
761  item->SetPictures(pic, pic);
762  }
763 }
764 
765 ////////////////////////////////////////////////////////////////////////////////
766 /// display content of ROOT file
767 
768 void TGFileBrowser::AddKey(TGListTreeItem *itm, TObject *obj, const char *name)
769 {
770  // Int_t from, to;
771  TGListTreeItem *where;
772  static TGListTreeItem *olditem = itm;
773  static TGListTreeItem *item = itm;
774  const TGPicture *pic;
775 
776  if (itm == 0) return;
777 
778  if ((fCnt == 0) || (olditem != itm)) {
779  olditem = item = itm;
780  }
781  if (!name) name = obj->GetName();
782  if (fNKeys > fGroupSize) {
783  where = itm->GetFirstChild();
784  while (where) {
785  if (fListTree->FindItemByObj(where, obj))
786  return;
787  where = where->GetNextSibling();
788  }
789  }
790  if ((fNKeys > fGroupSize) && (fCnt % fGroupSize == 0)) {
791  if (item != itm) {
792  TString newname = TString::Format("%s-%s", item->GetText(), name);
793  item->Rename(newname.Data());
794  }
795  item = fListTree->AddItem(itm, name);
796  item->SetDNDSource(kTRUE);
797  }
798  if ((fCnt > fGroupSize) && (fCnt >= fNKeys-1)) {
799  TString newname = TString::Format("%s-%s", item->GetText(), name);
800  item->Rename(newname.Data());
801  }
802  GetObjPicture(&pic, obj);
803  if (!fListTree->FindChildByName(item, name)) {
804  TGListTreeItem *it = fListTree->AddItem(item, name, obj, pic, pic);
805  if (pic && (pic != fFileIcon) && (pic != fCachedPic))
806  fClient->FreePicture(pic);
807  it->SetDNDSource(kTRUE);
808  it->SetTipText(FormatToolTip(obj, 32));
809  }
810  fCnt++;
811 }
812 
813 ////////////////////////////////////////////////////////////////////////////////
814 /// Apply filter selected in combo box to the file tree view.
815 
817 {
818  // Long64_t size;
819  // Long_t fid, flags, modtime;
820 
821  if (fFilter) delete fFilter;
822  fFilter = 0;
823  if ((id > 1) && (id < 5))
824  fFilter = new TRegexp(filters[id], kTRUE);
825  else if ((id < 0) || (id > 4)) {
826  TGTextLBEntry *lbe = (TGTextLBEntry *)fFileType->GetSelectedEntry();
827  if (lbe) {
828  const char *text = lbe->GetTitle();
829  fFilter = new TRegexp(text, kTRUE);
830  }
831  }
832  TGListTreeItem *item = fCurrentDir;
833  if (!item)
834  item = fRootDir;
835  if (!item) return;
836  fListTree->DeleteChildren(item);
837  DoubleClicked(item, 1);
838  //fListTree->AdjustPosition(item);
839  fListTree->ClearViewPort();
840 }
841 
842 ////////////////////////////////////////////////////////////////////////////////
843 /// Make object associated with item the current directory.
844 
846 {
847  if (item) {
848  TGListTreeItem *i = item;
849  while (i) {
850  TObject *obj = (TObject*) i->GetUserData();
851  if ((obj) && obj->InheritsFrom("TDirectory")) {
852  ((TDirectory *)obj)->cd();
853  break;
854  }
855  i = i->GetParent();
856  }
857  }
858 }
859 
860 ////////////////////////////////////////////////////////////////////////////////
861 /// Check if the current list tree item points to a remote object.
862 
864 {
865  if (!item) return;
866  TObject *obj = (TObject *) item->GetUserData();
867  if (obj) {
868  if (obj->InheritsFrom("TApplicationRemote")) {
869  if (!gApplication->GetAppRemote()) {
870  gROOT->ProcessLine(TString::Format(".R %s", item->GetText()));
871  if (gApplication->GetAppRemote()) {
872  Getlinem(kInit, TString::Format("\n%s:root [0]",
874  }
875  }
876  }
877  if (item->GetParent() && item->GetParent()->GetUserData() &&
878  ((TObject *)item->GetParent()->GetUserData())->InheritsFrom("TApplicationRemote")) {
879  // switch to remote session
880  if (!gApplication->GetAppRemote()) {
881  gROOT->ProcessLine(TString::Format(".R %s", item->GetParent()->GetText()));
882  if (gApplication->GetAppRemote()) {
883  Getlinem(kInit, TString::Format("\n%s:root [0]",
885  }
886  }
887  else if (!strcmp(item->GetText(), "ROOT Files")) {
888  // update list of files opened in the remote session
890  gApplication->ProcessLine("((TApplicationServer *)gApplication)->BrowseFile(0);");
891  }
892  }
893  else {
894  // check if the listtree item is from a local session or
895  // from a remote session, then switch to the session it belongs to
896  TGListTreeItem *top = item;
897  while (top->GetParent()) {
898  top = top->GetParent();
899  }
900  TObject *topobj = (TObject *) top->GetUserData();
901  if (topobj && topobj->InheritsFrom("TApplicationRemote")) {
902  // it belongs to a remote session
903  if (!gApplication->GetAppRemote()) {
904  // switch to remote session if not already in
905  gROOT->ProcessLine(TString::Format(".R %s", top->GetText()));
906  if (gApplication->GetAppRemote()) {
907  Getlinem(kInit, TString::Format("\n%s:root [0]",
909  }
910  }
911  }
912  else if (gApplication->GetAppRemote()) {
913  // switch back to local session if not already in
914  gApplication->ProcessLine(".R");
915  Getlinem(kInit, "\nroot [0]");
916  }
917  }
918  }
919  else if (gApplication->GetAppRemote()) {
920  // switch back to local session if not already in
921  gApplication->ProcessLine(".R");
922  Getlinem(kInit, "\nroot [0]");
923  }
924 }
925 
926 ////////////////////////////////////////////////////////////////////////////////
927 /// Check if there is a filter active on the children of the list tree item.
928 /// If the but argument is true, the "filter" button state is set accordingly,
929 /// and its tooltip will show the filter used.
930 
932 {
933  Bool_t found = kFALSE;
934  TString filter;
935  // if there is no filter (the map is empty) then just return
936  if (fFilteredItems.empty())
937  return kFALSE;
938  mFiltered_i it = fFilteredItems.find(item);
939  if (it != fFilteredItems.end()) {
940  // if the item is in the map, take the filter regexp string
941  filter = (const char *)(*it).second;
942  fFilterStr = filter;
943  found = kTRUE;
944  }
945  if (but) {
946  // if the but argument is true, change the button state
947  // to reflect the filtering state
948  fFilterButton->SetState(found ? kButtonEngaged : kButtonUp);
949  if (found) {
950  // format the tooltip to display the regexp used as filter
951  filter.Prepend("Showing only \'");
952  filter += "\'";
953  fFilterButton->SetToolTipText(filter.Data());
954  }
955  else {
956  // reset the tooltip text
957  fFilterButton->SetToolTipText("Filter Content...");
958  }
959  }
960  return found;
961 }
962 
963 ////////////////////////////////////////////////////////////////////////////////
964 /// Check if the list tree item children are alphabetically sorted.
965 /// If the but argument is true, the "sort" button state is set accordingly.
966 
968 {
969  Bool_t found = kFALSE;
970  TGListTreeItem *i, *itm;
971  if (item->GetFirstChild())
972  itm = item;
973  else
974  itm = item->GetParent();
975  for (sLTI_i p=fSortedItems.begin(); p!=fSortedItems.end(); ++p) {
976  i = (TGListTreeItem *)(*p);
977  if (itm == i) {
978  found = kTRUE;
979  break;
980  }
981  }
982  if (but) fSortButton->SetState(found ? kButtonEngaged : kButtonUp);
983  return found;
984 }
985 
986 ////////////////////////////////////////////////////////////////////////////////
987 /// Process mouse clicks in TGListTree.
988 
990 {
991  char path[1024];
992  Long64_t size = 0;
993  Long_t id = 0, flags = 0, modtime = 0;
994  fListLevel = item;
995  if (!item) return;
996  CheckSorted(item, kTRUE);
997  CheckFiltered(item, kTRUE);
998  CheckRemote(item);
999  TObject *selected = 0;
1000  TString fullpath = FullPathName(item);
1001  TObject *obj = (TObject *) item->GetUserData();
1002  if (obj && (!obj->InheritsFrom("TObjString") ||
1003  gSystem->AccessPathName(fullpath.Data()))) {
1004  if (obj->InheritsFrom("TKey") && (obj->IsA() != TClass::Class())) {
1005  Chdir(item);
1006  const char *clname = ((TKey *)obj)->GetClassName();
1007  if (clname && strcmp(clname, "TGeoManager")) {
1008  TClass *cl = TClass::GetClass(clname);
1009  TString name = ((TKey *)obj)->GetName();
1010  name += ";";
1011  name += ((TKey *)obj)->GetCycle();
1012  void *add = gDirectory->FindObjectAny((char *) name.Data());
1013  if (add && cl->IsTObject()) {
1014  obj = (TObject*)add;
1015  // don't change the user data, to avoid deletion of the
1016  // list tree item by RecursiveRemove()
1017  // it is better to read the object each time anyway,
1018  // as it may have changed in the file
1019  if (obj->InheritsFrom("TDirectory") || obj->InheritsFrom("TList"))
1020  item->SetUserData(obj);
1021  }
1022  }
1023  }
1024  if (obj->InheritsFrom("TLeaf") ||
1025  obj->InheritsFrom("TBranch")) {
1026  Chdir(item);
1027  }
1028  if (btn == kButton3)
1029  fContextMenu->Popup(x, y, obj, fBrowser);
1030  selected = obj;
1031  }
1032  else {
1033  fListTree->GetPathnameFromItem(item, path);
1034  if (strlen(path) > 3) {
1035  if (gSystem->GetPathInfo(fullpath.Data(), &id, &size, &flags, &modtime) == 0) {
1036  if (flags & 2) {
1037  fCurrentDir = item;
1038  if (btn == kButton3) {
1039  if (fDir) delete fDir;
1040  fDir = new TSystemDirectory(item->GetText(), fullpath.Data());
1041  fContextMenu->Popup(x, y, fDir, fBrowser);
1042  }
1043  }
1044  else {
1045  fCurrentDir = item->GetParent();
1046  if (btn == kButton3) {
1047  if (fFile) delete fFile;
1048  fFile = new TSystemFile(item->GetText(), fullpath.Data());
1049  fContextMenu->Popup(x, y, fFile, fBrowser);
1050  }
1051  }
1052  }
1053  }
1054  }
1055  fListTree->ClearViewPort();
1056  if (selected && (selected->IsA() != TClass::Class())) {
1057  if (selected->InheritsFrom("TLeaf"))
1058  selected = (TObject *)gROOT->ProcessLine(TString::Format("((TLeaf *)0x%lx)->GetBranch()->GetTree();", (ULong_t)selected));
1059  if (selected->InheritsFrom("TBranch"))
1060  selected = (TObject *)gROOT->ProcessLine(TString::Format("((TBranch *)0x%lx)->GetTree();", (ULong_t)selected));
1061  if (selected->InheritsFrom("TTree")) {
1062  // if a tree not attached to any directory (e.g. in a TFolder)
1063  // then attach it to the current directory (gDirectory)
1064  TDirectory *tdir = (TDirectory *)gROOT->ProcessLine(TString::Format("((TTree *)0x%lx)->GetDirectory();", (ULong_t)selected));
1065  if (!tdir) {
1066  gROOT->ProcessLine(TString::Format("((TTree *)0x%lx)->SetDirectory(gDirectory);", (ULong_t)selected));
1067  }
1068  }
1069  }
1070  if (selected && gPad && IsObjectEditable(selected->IsA())) {
1072  if (ved) {
1073  TGedEditor *ged = (TGedEditor *)ved;
1074  ged->SetModel(gPad, selected, kButton1Down);
1075  }
1076  }
1077 }
1078 
1079 ////////////////////////////////////////////////////////////////////////////////
1080 /// returns an absolute path
1081 
1083 {
1084  TGListTreeItem *parent, *itm = item;
1085  TString dirname = itm->GetText();
1086 
1087  while ((parent=itm->GetParent())) {
1088  char *s = gSystem->ConcatFileName(parent->GetText(), dirname);
1089  dirname = s;
1090  delete [] s;
1091  itm = parent;
1092  }
1093  dirname = gSystem->ExpandPathName(dirname.Data());
1094 #ifdef R__WIN32
1095  // only handle .lnk files on Windows
1096  while (dirname.Contains(".lnk")) {
1097  Ssiz_t idx = dirname.Index(".lnk") + 4;
1098  TString resolved = dirname;
1099  resolved.Remove(idx);
1100  resolved = gSystem->ExpandPathName(resolved.Data());
1101  dirname = resolved.Append(dirname.Remove(0, idx));
1102  }
1103 #endif
1104  return dirname;
1105 }
1106 
1107 ////////////////////////////////////////////////////////////////////////////////
1108 /// returns the directory path
1109 
1111 {
1112  TString dirname;
1113  TString fullpath = FullPathName(item);
1114 
1115 #ifdef WIN32
1116  char winDrive[256];
1117  char winDir[256];
1118  char winName[256];
1119  char winExt[256];
1120  _splitpath(fullpath.Data(), winDrive, winDir, winName, winExt);
1121  dirname = TString::Format("%s%s", winDrive, winDir);
1122 #else
1123  dirname = gSystem->DirName(fullpath);
1124 #endif
1125  return dirname;
1126 }
1127 
1128 ////////////////////////////////////////////////////////////////////////////////
1129 /// Returns true if given a text file
1130 /// Uses the specification given on p86 of the Camel book
1131 /// - Text files have no NULLs in the first block
1132 /// - and less than 30% of characters with high bit set
1133 
1134 static Bool_t IsTextFile(const char *candidate)
1135 {
1136  Int_t i;
1137  Int_t nchars;
1138  Int_t weirdcount = 0;
1139  char buffer[512];
1140  FILE *infile;
1141  FileStat_t buf;
1142 
1143  if (gSystem->GetPathInfo(candidate, buf) || !(buf.fMode & kS_IFREG))
1144  return kFALSE;
1145 
1146  infile = fopen(candidate, "r");
1147  if (infile) {
1148  // Read a block
1149  nchars = fread(buffer, 1, 512, infile);
1150  fclose (infile);
1151  // Examine the block
1152  for (i = 0; i < nchars; i++) {
1153  if (buffer[i] & 128)
1154  weirdcount++;
1155  if (buffer[i] == '\0')
1156  // No NULLs in text files
1157  return kFALSE;
1158  }
1159  if ((nchars > 0) && ((weirdcount * 100 / nchars) > 30))
1160  return kFALSE;
1161  } else {
1162  // Couldn't open it. Not a text file then
1163  return kFALSE;
1164  }
1165  return kTRUE;
1166 }
1167 
1168 ////////////////////////////////////////////////////////////////////////////////
1169 /// Create a symlink (shortcut on Windows) icon by merging the picture
1170 /// passed as argument and the slink_t.xpm icon (small arrow)
1171 
1172 static const TGPicture *MakeLinkPic(const TGPicture *pic)
1173 {
1174  const TGPicture *merged;
1175  TImage *img1, *img2;
1176  if (pic) {
1177  img1 = TImage::Create();
1178  if (img1 == 0) return pic;
1179  img1->SetImage(((const TGPicture *)pic)->GetPicture(),
1180  ((const TGPicture *)pic)->GetMask());
1181  img2 = TImage::Open("slink_t.xpm");
1182  if (img2) img1->Merge(img2);
1183  TString lnk_name = ((const TGPicture *)pic)->GetName();
1184  lnk_name.Prepend("lnk_");
1185  merged = gClient->GetPicturePool()->GetPicture(lnk_name.Data(),
1186  img1->GetPixmap(), img1->GetMask());
1187  if (img2) delete img2;
1188  delete img1;
1189  return merged;
1190  }
1191  return pic;
1192 }
1193 
1194 ////////////////////////////////////////////////////////////////////////////////
1195 /// Process double clicks in TGListTree.
1196 
1198 {
1199  const TGPicture *pic=0;
1200  TString dirname = DirName(item);
1201  TString fullpath = FullPathName(item);
1202  TGListTreeItem *itm;
1203  FileStat_t sbuf;
1204  Long64_t size;
1205  Long_t id, flags, modtime;
1206  char action[512];
1207  TString act;
1208  Bool_t is_link = kFALSE;
1209  if (!gSystem->GetPathInfo(item->GetText(), sbuf) && sbuf.fIsLink) {
1210  is_link = kTRUE;
1211  fullpath = gSystem->ExpandPathName(item->GetText());
1212  }
1213 
1214  if (fNewBrowser)
1215  fNewBrowser->SetActBrowser(this);
1216  TCursorSwitcher switcher(this, fListTree);
1217  fListLevel = item;
1218  CheckSorted(item, kTRUE);
1219  CheckFiltered(item, kTRUE);
1220  CheckRemote(item);
1221  TGListTreeItem *pitem = item->GetParent();
1222  TObject *obj = (TObject *) item->GetUserData();
1223  if (obj && !obj->InheritsFrom("TSystemFile")) {
1224  TString ext = obj->GetName();
1225  if (obj->InheritsFrom("TDirectory") && (obj->IsA() != TClass::Class())) {
1226  if (((TDirectory *)obj)->GetListOfKeys())
1227  fNKeys = ((TDirectory *)obj)->GetListOfKeys()->GetEntries();
1228  else
1229  fNKeys = 0;
1230  }
1231  else if (obj->InheritsFrom("TKey") && (obj->IsA() != TClass::Class())) {
1232  Chdir(item);
1233  const char *clname = ((TKey *)obj)->GetClassName();
1234  if (clname) {
1235  TClass *cl = TClass::GetClass(clname);
1236  TString name = ((TKey *)obj)->GetName();
1237  name += ";";
1238  name += ((TKey *)obj)->GetCycle();
1239  void *add = gDirectory->FindObjectAny((char *) name.Data());
1240  if (add && cl->IsTObject()) {
1241  obj = (TObject*)add;
1242  // don't change the user data, to avoid deletion of the
1243  // list tree item by RecursiveRemove()
1244  // it is better to read the object each time anyway,
1245  // as it may have changed in the file
1246  if (obj->InheritsFrom("TDirectory") || obj->InheritsFrom("TList"))
1247  item->SetUserData(obj);
1248  }
1249  }
1250  }
1251  else if (obj->InheritsFrom("TLeaf") || obj->InheritsFrom("TBranch")) {
1252  Chdir(item);
1253  }
1254  else if (obj->InheritsFrom("TRemoteObject")) {
1255  // the real object is a TKey
1256  TRemoteObject *robj = (TRemoteObject *)obj;
1257  if (!strcmp(robj->GetClassName(), "TKey")) {
1258  TGListTreeItem *parent = item;
1259  TRemoteObject *probj = (TRemoteObject *)parent->GetUserData();
1260  // find the TFile remote object containing the TKey
1261  while ( probj && strcmp(probj->GetClassName(), "TFile")) {
1262  parent = parent->GetParent();
1263  probj = (TRemoteObject *)parent->GetUserData();
1264  }
1265  if (probj && !strcmp(probj->GetClassName(), "TFile")) {
1266  // remotely browse file (remotely call TFile::cd())
1269  TString::Format("((TApplicationServer *)gApplication)->BrowseFile(\"%s\");",
1270  probj->GetName()));
1271  gSystem->Sleep(250);
1272  }
1273  }
1274  if (gClient->GetMimeTypeList()->GetAction(obj->GetName(), action)) {
1275  act = action;
1276  act.ReplaceAll("%s", obj->GetName());
1277  if ((act[0] != '!') && (strcmp(pitem->GetText(), "ROOT Files"))) {
1278  // special case for remote object: remote process
1280  gApplication->ProcessLine(act.Data());
1281  }
1282  }
1283  if ((ext.EndsWith(".root")) && (strcmp(pitem->GetText(), "ROOT Files"))) {
1285  gApplication->ProcessLine("((TApplicationServer *)gApplication)->BrowseFile(0);");
1286  }
1287  }
1288  if (!obj->InheritsFrom("TObjString") ||
1289  gSystem->AccessPathName(fullpath.Data())) {
1290  if (fBrowser) fBrowser->SetDrawOption(GetDrawOption());
1291  fDblClick = kTRUE;
1292  if (gClient->GetMimeTypeList()->GetAction(obj->IsA()->GetName(), action)) {
1293  act = action;
1294  if (fBrowser && act.Contains("->Browse()")) obj->Browse(fBrowser);
1295  else if (act.Contains("->Draw()")) obj->Draw(GetDrawOption());
1296  else {
1297  if (act.Contains("%s")) act.ReplaceAll("%s", obj->GetName());
1298  else act.Prepend(obj->GetName());
1299  gInterpreter->SaveGlobalsContext();
1300  if (act[0] == '!') {
1301  act.Remove(0, 1);
1302  gSystem->Exec(act.Data());
1303  } else {
1304  // special case for remote object: remote process
1305  if (obj->InheritsFrom("TRemoteObject"))
1307  gApplication->ProcessLine(act.Data());
1308  }
1309  }
1310  }
1311  else if (obj->InheritsFrom("TCanvas") && fNewBrowser &&
1312  fNewBrowser->GetTabRight() &&
1313  fNewBrowser->GetTabRight()->GetTabTab(obj->GetName())) {
1314  // avoid potential crash when drawing a canvas with the same name
1315  // than a canvas already embedded in one of the browser's tab
1316  obj->DrawClone();
1317  }
1318  else if (fBrowser && !obj->InheritsFrom("TFormula"))
1319  obj->Browse(fBrowser);
1320  fDblClick = kFALSE;
1321  fNKeys = 0;
1322  fCnt = 0;
1323  fListTree->ClearViewPort();
1324  if (gPad) gPad->Update();
1325  return;
1326  }
1327  }
1328  flags = id = size = modtime = 0;
1329  if (gSystem->GetPathInfo(fullpath.Data(), &id, &size, &flags, &modtime) != 0)
1330  return;
1331  Int_t isdir = (Int_t)flags & 2;
1332 
1333  TString savdir = gSystem->WorkingDirectory();
1334  if (isdir) {
1335  fCurrentDir = item;
1336  //fListTree->DeleteChildren(item);
1337  TSystemDirectory dir(item->GetText(),FullPathName(item));
1338  TList *files = dir.GetListOfFiles();
1339  if (files) {
1340  files->Sort();
1341  TIter next(files);
1342  TSystemFile *file;
1343  TString fname, pname;
1344  // directories first
1345  //fListTree->DeleteChildren(item);
1346  while ((file=(TSystemFile*)next())) {
1347  fname = file->GetName();
1348  if (file->IsDirectory()) {
1349  if (!fShowHidden && fname.BeginsWith("."))
1350  continue;
1351  if ((fname!="..") && (fname!=".")) { // skip it
1352  if (!fListTree->FindChildByName(item, fname)) {
1353  itm = fListTree->AddItem(item, fname);
1354  if (!gSystem->GetPathInfo(fname, sbuf) &&
1355  sbuf.fIsLink) {
1356  // change the pictures if it is a symlink
1357  // (shortcut on Windows)
1358  const TGPicture *opened = 0, *l_opened = 0;
1359  const TGPicture *closed = 0, *l_closed = 0;
1360  opened = fClient->GetPicture("ofolder_t.xpm");
1361  if (opened) l_opened = MakeLinkPic(opened);
1362  closed = fClient->GetPicture("folder_t.xpm");
1363  if (closed) l_closed = MakeLinkPic(closed);
1364  if (l_opened && l_closed)
1365  itm->SetPictures(l_opened, l_closed);
1366  if (opened) fClient->FreePicture(opened);
1367  if (closed) fClient->FreePicture(closed);
1368  if (l_opened) fClient->FreePicture(l_opened);
1369  if (l_closed) fClient->FreePicture(l_closed);
1370  }
1371  // uncomment line below to set directories as
1372  // DND targets
1373  //itm->SetDNDTarget(kTRUE);
1374  itm->SetUserData(0);
1375  }
1376  }
1377  }
1378  }
1379  // then files...
1380  TIter nextf(files);
1381  while ((file=(TSystemFile*)nextf())) {
1382  fname = pname = file->GetName();
1383  if (!file->IsDirectory() && (fFilter == 0 ||
1384  (fFilter && fname.Index(*fFilter) != kNPOS))) {
1385  if (!fShowHidden && fname.BeginsWith("."))
1386  continue;
1387  size = modtime = 0;
1388  if (gSystem->GetPathInfo(fname, sbuf) == 0) {
1389  size = sbuf.fSize;
1390  modtime = sbuf.fMtime;
1391  }
1392  if (sbuf.fIsLink && pname.EndsWith(".lnk"))
1393  pname.Remove(pname.Length()-4);
1394  pic = gClient->GetMimeTypeList()->GetIcon(pname, kTRUE);
1395  if (!pic)
1396  pic = fFileIcon;
1397  if (sbuf.fIsLink)
1398  pic = MakeLinkPic(pic);
1399  if (!fListTree->FindChildByName(item, fname)) {
1400  itm = fListTree->AddItem(item, fname, pic, pic);
1401  if (pic != fFileIcon)
1402  fClient->FreePicture(pic);
1403  if (sbuf.fIsLink)
1404  itm->SetUserData(new TObjString(TString::Format("file://%s\r\n",
1405  gSystem->ExpandPathName(file->GetName()))), kTRUE);
1406  else
1407  itm->SetUserData(new TObjString(TString::Format("file://%s/%s\r\n",
1408  gSystem->UnixPathName(file->GetTitle()),
1409  file->GetName())), kTRUE);
1410  itm->SetDNDSource(kTRUE);
1411  if (size && modtime) {
1412  char *tiptext = FormatFileInfo(fname.Data(), size, modtime);
1413  itm->SetTipText(tiptext);
1414  delete [] tiptext;
1415  }
1416  }
1417  }
1418  }
1419  files->Delete();
1420  delete files;
1421  }
1422  }
1423  else {
1424  TString lnkname = item->GetText();
1425  if (is_link && lnkname.EndsWith(".lnk"))
1426  lnkname.Remove(lnkname.Length()-4);
1427  fCurrentDir = item->GetParent();
1428  TSystemFile f(lnkname.Data(), fullpath.Data());
1429  TString fname = f.GetName();
1430  if (fname.EndsWith(".root")) {
1431  TDirectory *rfile = 0;
1432  gSystem->ChangeDirectory(dirname.Data());
1433  rfile = (TDirectory *)gROOT->GetListOfFiles()->FindObject(obj);
1434  if (!rfile) {
1435  rfile = (TDirectory *)gROOT->ProcessLine(TString::Format("new TFile(\"%s\")",fname.Data()));
1436  }
1437  if (rfile) {
1438  // replace actual user data (TObjString) by the TDirectory...
1439  if (item->GetUserData()) {
1440  // first delete the data to avoid memory leaks
1441  TObject *obj2 = static_cast<TObject *>(item->GetUserData());
1442  // only delete TObjString as they are the only objects
1443  // created who have to be deleted
1444  TObjString *ostr = dynamic_cast<TObjString *>(obj2);
1445  if (ostr) delete ostr;
1446  }
1447  item->SetUserData(rfile);
1448  fNKeys = rfile->GetListOfKeys()->GetEntries();
1449  fCnt = 0;
1450  if (fBrowser) rfile->Browse(fBrowser);
1451  fNKeys = 0;
1452  fCnt = 0;
1453  }
1454  }
1455  else if (fname.EndsWith(".png")) {
1456  gSystem->ChangeDirectory(dirname.Data());
1457  XXExecuteDefaultAction(&f);
1458  gSystem->ChangeDirectory(savdir.Data());
1459  }
1460  else if (IsTextFile(fullpath.Data())) {
1461  gSystem->ChangeDirectory(dirname.Data());
1462  if (fNewBrowser) {
1463  TGFrameElement *fe = 0;
1464  TGTab *tabRight = fNewBrowser->GetTabRight();
1465  TGCompositeFrame *frame = tabRight->GetCurrentContainer();
1466  if (frame)
1467  fe = (TGFrameElement *)frame->GetList()->First();
1468  if (fe) {
1469  TGCompositeFrame *embed = (TGCompositeFrame *)fe->fFrame;
1470  TString fullname = f.GetTitle();
1471  fullname.ReplaceAll("\\", "\\\\");
1472  if (embed->InheritsFrom("TGTextEditor")) {
1473  gROOT->ProcessLine(TString::Format("((TGTextEditor *)0x%lx)->LoadFile(\"%s\");",
1474  (ULong_t)embed, fullname.Data()));
1475  }
1476  else if (embed->InheritsFrom("TGTextEdit")) {
1477  gROOT->ProcessLine(TString::Format("((TGTextEdit *)0x%lx)->LoadFile(\"%s\");",
1478  (ULong_t)embed, fullname.Data()));
1479  }
1480  else {
1481  XXExecuteDefaultAction(&f);
1482  }
1483  }
1484  else {
1485  XXExecuteDefaultAction(&f);
1486  }
1487  }
1488  gSystem->ChangeDirectory(savdir.Data());
1489  }
1490  else {
1491  gSystem->ChangeDirectory(dirname.Data());
1492  XXExecuteDefaultAction(&f);
1493  gSystem->ChangeDirectory(savdir.Data());
1494  }
1495  }
1496  //gSystem->ChangeDirectory(savdir.Data());
1497  fListTree->ClearViewPort();
1498 }
1499 
1500 ////////////////////////////////////////////////////////////////////////////////
1501 /// Execute default action for selected object (action is specified
1502 /// in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.
1503 
1505 {
1506  char action[512];
1507  TString act;
1508  TString ext = obj->GetName();
1509  if (fBrowser) fBrowser->SetDrawOption(GetDrawOption());
1510 
1511  if (gClient->GetMimeTypeList()->GetAction(obj->GetName(), action)) {
1512  act = action;
1513  act.ReplaceAll("%s", obj->GetName());
1514  gInterpreter->SaveGlobalsContext();
1515 
1516  if (act[0] == '!') {
1517  act.Remove(0, 1);
1518  gSystem->Exec(act.Data());
1519  return 0;
1520  } else {
1521  // special case for remote object: remote process
1522  if (obj->InheritsFrom("TRemoteObject"))
1524 
1525  const Long_t res = gApplication->ProcessLine(act.Data());
1526 #ifdef R__HAS_COCOA
1527  if (act.Contains(".x") || act.Contains(".X")) {
1528  if (gPad) gPad->Update();
1529  }
1530 #endif
1531  return res;
1532  }
1533  }
1534  return 0;
1535 }
1536 
1537 ////////////////////////////////////////////////////////////////////////////////
1538 /// Format file information to be displayed in the tooltip.
1539 
1540 char *TGFileBrowser::FormatFileInfo(const char *fname, Long64_t size, Long_t modtime)
1541 {
1542  Long64_t fsize, bsize;
1543  TString infos = fname;
1544  infos += "\n";
1545 
1546  fsize = bsize = size;
1547  if (fsize > 1024) {
1548  fsize /= 1024;
1549  if (fsize > 1024) {
1550  // 3.7MB is more informative than just 3MB
1551  infos += TString::Format("Size: %lld.%lldM", fsize/1024, (fsize%1024)/103);
1552  } else {
1553  infos += TString::Format("Size: %lld.%lldK", bsize/1024, (bsize%1024)/103);
1554  }
1555  } else {
1556  infos += TString::Format("Size: %lld", bsize);
1557  }
1558  struct tm *newtime;
1559  time_t loctime = (time_t) modtime;
1560  newtime = localtime(&loctime);
1561  if (newtime) {
1562  infos += "\n";
1563  infos += TString::Format("%d-%02d-%02d %02d:%02d",
1564  newtime->tm_year + 1900,
1565  newtime->tm_mon+1, newtime->tm_mday,
1566  newtime->tm_hour, newtime->tm_min);
1567  }
1568  return StrDup(infos.Data());
1569 }
1570 
1571 ////////////////////////////////////////////////////////////////////////////////
1572 /// Retrieve icons associated with class "name". Association is made
1573 /// via the user's ~/.root.mimes file or via $ROOTSYS/etc/root.mimes.
1574 
1576 {
1577  const char *clname = 0;
1578  TClass *objClass = 0;
1579  static TImage *im = 0;
1580  if (!im) {
1581  im = TImage::Create();
1582  }
1583 
1584  if (obj->IsA() == TClass::Class()) {
1585  objClass = obj->IsA();
1586  if (objClass)
1587  clname = objClass->GetName();
1588  }
1589  else if (obj->InheritsFrom("TKey")) {
1590  clname = ((TKey *)obj)->GetClassName();
1591  }
1592  else if (obj->InheritsFrom("TKeyMapFile")) {
1593  clname = ((TKeyMapFile *)obj)->GetTitle();
1594  }
1595  else if (obj->InheritsFrom("TRemoteObject")) {
1596  // special case for remote object: get real object class
1597  TRemoteObject *robj = (TRemoteObject *)obj;
1598  if (!strcmp(robj->GetClassName(), "TKey"))
1599  clname = robj->GetKeyClassName();
1600  else
1601  clname = robj->GetClassName();
1602  }
1603  else {
1604  objClass = obj->IsA();
1605  if (objClass)
1606  clname = objClass->GetName();
1607  }
1608  if (!clname) {
1609  clname = "Unknown";
1610  }
1611  const char *name = obj->GetIconName() ? obj->GetIconName() : clname;
1612  TString xpm_magic(name, 3);
1613  Bool_t xpm = xpm_magic == "/* ";
1614  const char *iconname = xpm ? obj->GetName() : name;
1615 
1616  if (obj->IsA()->InheritsFrom("TGeoVolume")) {
1617  iconname = obj->GetIconName() ? obj->GetIconName() : obj->IsA()->GetName();
1618  }
1619 
1620  if (fCachedPicName == iconname) {
1621  *pic = fCachedPic;
1622  return;
1623  }
1624  *pic = gClient->GetMimeTypeList()->GetIcon(iconname, kTRUE);
1625  if (!(*pic) && xpm) {
1626  if (im && im->SetImageBuffer((char**)&name, TImage::kXpm)) {
1627  im->Scale(im->GetWidth()/4, im->GetHeight()/4);
1628  *pic = gClient->GetPicturePool()->GetPicture(iconname, im->GetPixmap(),
1629  im->GetMask());
1630  }
1631  gClient->GetMimeTypeList()->AddType("[thumbnail]", iconname, iconname, iconname, "->Browse()");
1632  return;
1633  }
1634  if (fCachedPic && (fCachedPic != fFileIcon))
1635  fClient->FreePicture(fCachedPic);
1636  if (*pic == 0) {
1637  if (!obj->IsFolder())
1638  *pic = fFileIcon;
1639  }
1640  fCachedPic = *pic;
1641  fCachedPicName = iconname;
1642 }
1643 
1644 ////////////////////////////////////////////////////////////////////////////////
1645 /// Go to the directory "path" and open all the parent list tree items.
1646 
1647 void TGFileBrowser::GotoDir(const char *path)
1648 {
1649  TGListTreeItem *item, *itm;
1650  Bool_t expand = kTRUE;
1651  TString sPath(gSystem->UnixPathName(path));
1652  item = fRootDir;
1653  if (item == 0) return;
1654  fListTree->OpenItem(item);
1655  TObjArray *tokens = sPath.Tokenize("/");
1656  if (tokens->IsEmpty()) {
1657  fListTree->HighlightItem(item);
1658  DoubleClicked(item, 1);
1659  delete tokens;
1660  fListTree->ClearViewPort();
1661  fListTree->AdjustPosition(item);
1662  return;
1663  }
1664  // if the Browser.ExpandDirectories option is set to "no", then don't
1665  // expand the parent directory tree (for example on nfs)
1666  TString str = gEnv->GetValue("Browser.ExpandDirectories", "yes");
1667  str.ToLower();
1668  expand = (str == "yes") ? kTRUE : kFALSE;
1669  TString first = ((TObjString*)tokens->At(0))->GetName();
1670  // always prevent expanding the parent directory tree on afs
1671  if (first == "afs")
1672  expand = kFALSE;
1673  if (first.Length() == 2 && first.EndsWith(":")) {
1674  TList *curvol = gSystem->GetVolumes("cur");
1675  if (curvol) {
1676  TNamed *drive = (TNamed *)curvol->At(0);
1677  if (first == drive->GetName()) {
1678  TString infos = drive->GetTitle();
1679  if (infos.Contains("Network"))
1680  expand = kFALSE;
1681  }
1682  delete curvol;
1683  }
1684  }
1685  for (Int_t i = 0; i < tokens->GetEntriesFast(); ++i) {
1686  TString token = ((TObjString*)tokens->At(i))->GetName();
1687  if (token.Length() == 2 && token.EndsWith(":")) {
1688  token.Append("\\");
1689  itm = fListTree->FindChildByName(0, token);
1690  if (itm) {
1691  item = itm;
1692  fListTree->OpenItem(item);
1693  if (expand)
1694  DoubleClicked(item, 1);
1695  }
1696  continue;
1697  }
1698  itm = fListTree->FindChildByName(item, token);
1699  if (itm) {
1700  item = itm;
1701  fListTree->OpenItem(item);
1702  if (expand)
1703  DoubleClicked(item, 1);
1704  }
1705  else {
1706  itm = fListTree->AddItem(item, token);
1707  item = itm;
1708  fListTree->OpenItem(item);
1709  if (expand)
1710  DoubleClicked(item, 1);
1711  }
1712  }
1713  fListTree->HighlightItem(item);
1714  DoubleClicked(item, 1);
1715  delete tokens;
1716  fListTree->ClearViewPort();
1717  fListTree->AdjustPosition(item);
1718 }
1719 
1720 ////////////////////////////////////////////////////////////////////////////////
1721 /// Slot used to switch to the tab containing the current pad/canvas (gPad)
1722 /// used e.g. when drawing a histogram by double-clicking on its list tree
1723 /// item in a root file.
1724 
1726 {
1727  if (fDblClick && fNewBrowser) {
1728  Int_t i;
1729  TGTab *tabRight = fNewBrowser->GetTabRight();
1730  for (i=0;i<tabRight->GetNumberOfTabs();++i) {
1731  TGFrameElement *fe = 0;
1732  TGCompositeFrame *embed = 0;
1733  TGCompositeFrame *frame = tabRight->GetTabContainer(i);
1734  if (frame)
1735  fe = (TGFrameElement *)frame->GetList()->First();
1736  if (fe)
1737  embed = (TGCompositeFrame *)fe->fFrame;
1738  if (embed && embed->InheritsFrom("TRootCanvas")) {
1739  ULong_t canvas = gROOT->ProcessLine(TString::Format("((TRootCanvas *)0x%lx)->Canvas();",
1740  (ULong_t)embed));
1741  if ((canvas) && (canvas == (ULong_t)gPad ||
1742  canvas == (ULong_t)gPad->GetCanvas())) {
1743  tabRight->SetTab(i, kTRUE);
1744  break;
1745  }
1746  }
1747  }
1748  }
1749 }
1750 
1751 ////////////////////////////////////////////////////////////////////////////////
1752 /// Open a dialog box asking for a string to be used as filter (regexp), and
1753 /// add an entry in the map of filtered entries. Entering "*" or empty string
1754 /// ("") will disable filtering on the current list tree item.
1755 
1757 {
1758  char filter[1024];
1759  if (!fListLevel)
1760  return;
1761  // initialize with previous (active) filter string
1762  snprintf(filter, sizeof(filter), "%s", fFilterStr.Data());
1763  new TGInputDialog(gClient->GetRoot(), this,
1764  "Enter filter expression:\n(empty string \"\" or \"*\" to remove filter)",
1765  filter, filter);
1766  // if user pressed cancel, update the status of the current list tree
1767  // item and return
1768  if ((filter[0] == 0) && (filter[1] == 0)) {
1769  CheckFiltered(fListLevel, kTRUE);
1770  return;
1771  }
1772  else if (((filter[0] == 0) && (filter[1] == 1)) || !strcmp(filter, "*")) {
1773  // if user entered "*" or "", just disable filtering for the current
1774  // list tree item
1775  fFilterButton->SetState(kButtonUp);
1776  fFilteredItems.erase(fListLevel);
1777  }
1778  else {
1779  // if user entered a string different from "*", use it to create an
1780  // entry in the filter map
1781  fFilterStr = filter;
1782  fFilterButton->SetState(kButtonEngaged);
1783  // if there is already a filter on this item, delete it
1784  if (CheckFiltered(fListLevel))
1785  fFilteredItems.erase(fListLevel);
1786  // insert a new entry for the current list tree item
1787  fFilteredItems.insert(std::make_pair(fListLevel, StrDup(filter)));
1788  }
1789  // finally update the list tree
1790  fListTree->DeleteChildren(fListLevel);
1791  DoubleClicked(fListLevel, 1);
1792  fListTree->ClearViewPort();
1793  fListTree->AdjustPosition(fListLevel);
1794 }
1795 
1796 ////////////////////////////////////////////////////////////////////////////////
1797 /// A ROOT File has been selected in TGHtmlBrowser.
1798 
1800 {
1801  TGListTreeItem *itm = fListTree->FindChildByData(0, gROOT->GetListOfFiles());
1802  if (itm) {
1803  fListTree->ClearHighlighted();
1804  fListLevel = itm;
1805  fListTree->HighlightItem(fListLevel);
1806  fListTree->OpenItem(fListLevel);
1807  BrowseObj(gROOT->GetListOfFiles());
1808  fListTree->ClearViewPort();
1809  fListTree->AdjustPosition(fListLevel);
1810  }
1811 }
1812 
1813 ////////////////////////////////////////////////////////////////////////////////
1814 /// Toggle the sort mode and set the "sort button" state accordingly.
1815 
1817 {
1818  if (!fListLevel) return;
1819  char *itemname = 0;
1820  TGListTreeItem *item = fListLevel;
1821  if (!fListLevel->GetFirstChild()) {
1822  item = fListLevel->GetParent();
1823  itemname = StrDup(fListLevel->GetText());
1824  }
1825  if (!item) {
1826  if (itemname)
1827  delete [] itemname;
1828  return;
1829  }
1830  Bool_t is_sorted = CheckSorted(item);
1831  if (!is_sorted) {
1832  //alphabetical sorting
1833  fListTree->SortChildren(item);
1834  fSortedItems.push_back(item);
1835  fSortButton->SetState(kButtonEngaged);
1836  }
1837  else {
1838  fListTree->DeleteChildren(item);
1839  DoubleClicked(item, 1);
1840  fSortedItems.remove(item);
1841  fSortButton->SetState(kButtonUp);
1842  gClient->NeedRedraw(fListTree, kTRUE);
1843  gClient->HandleInput();
1844  if (itemname) {
1845  TGListTreeItem *itm = fListTree->FindChildByName(item, itemname);
1846  if (itm) {
1847  fListTree->ClearHighlighted();
1848  Clicked(itm, 1, 0, 0);
1849  itm->SetActive(kTRUE);
1850  fListTree->SetSelected(itm);
1851  fListTree->HighlightItem(itm, kTRUE, kTRUE);
1852  }
1853  }
1854  }
1855  if (itemname)
1856  delete [] itemname;
1857  fListTree->ClearViewPort();
1858  fListTree->AdjustPosition(fListLevel);
1859 }
1860 
1861 
TGCompositeFrame * GetCurrentContainer() const
Definition: TGTab.h:110
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void RequestFilter()
Open a dialog box asking for a string to be used as filter (regexp), and add an entry in the map of f...
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1272
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:145
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
Process a single command line, either a C++ statement or an interpreter command starting with a "...
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition: TClass.cxx:3452
static const TGPicture * MakeLinkPic(const TGPicture *pic)
Create a symlink (shortcut on Windows) icon by merging the picture passed as argument and the slink_t...
An array of TObjects.
Definition: TObjArray.h:37
void AddKey(TGListTreeItem *itm, TObject *obj, const char *name=0)
display content of ROOT file
virtual void Resize(UInt_t w, UInt_t h)
Resize the listbox widget.
Definition: TGListBox.cxx:1419
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:148
const char * GetClassName() const
Definition: TRemoteObject.h:56
Bool_t CheckFiltered(TGListTreeItem *item, Bool_t but=kFALSE)
Check if there is a filter active on the children of the list tree item.
virtual void * GetUserData() const =0
long long Long64_t
Definition: RtypesCore.h:69
Utility class for browsing TMapFile objects.
Definition: TKeyMapFile.h:20
virtual UInt_t GetHeight() const
Definition: TImage.h:229
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:868
TGCompositeFrame * GetTabContainer(Int_t tabIndex) const
Return container of tab with index tabIndex.
Definition: TGTab.cxx:563
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad...
Definition: TObject.cxx:226
Definition: TGTab.h:62
Collectable string class.
Definition: TObjString.h:28
const char Option_t
Definition: RtypesCore.h:62
virtual UInt_t GetWidth() const
Definition: TImage.h:228
virtual const char * GetIconName() const
Returns mime type name of object.
Definition: TObject.cxx:374
const Ssiz_t kNPOS
Definition: RtypesCore.h:115
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:640
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
TClass * GetClassPointer(Bool_t load=kTRUE)
Get pointer to the base class TClass.
Definition: TBaseClass.cxx:63
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1370
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
TH1 * h
Definition: legend2.C:5
virtual Int_t GetEntries() const
Definition: TCollection.h:86
void ApplyFilter(Int_t id)
Apply filter selected in combo box to the file tree view.
Regular expression class.
Definition: TRegexp.h:31
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:859
sLTI_t::iterator sLTI_i
Definition: TGFileBrowser.h:39
#define gROOT
Definition: TROOT.h:375
virtual const char * GetTitle() const
Returns title of object.
Definition: TGListBox.h:117
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:587
UInt_t GetListOfKeys(TList &keys, TString inherits, TDirectory *dir=0)
Definition: tmvaglob.cxx:375
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition: TObject.cxx:126
Basic string class.
Definition: TString.h:129
#define gClient
Definition: TGClient.h:166
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
This static function calls a slot after a given time interval.
Definition: TTimer.cxx:256
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1099
Bool_t IsEmpty() const
Definition: TObjArray.h:70
int Int_t
Definition: RtypesCore.h:41
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1003
bool Bool_t
Definition: RtypesCore.h:59
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:202
#define gInterpreter
Definition: TInterpreter.h:499
Long_t fMtime
Definition: TSystem.h:132
An abstract interface to image processing library.
Definition: TImage.h:29
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:172
Bool_t CheckSorted(TGListTreeItem *item, Bool_t but=kFALSE)
Check if the list tree item children are alphabetically sorted.
TString & Prepend(const char *cs)
Definition: TString.h:609
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
TObject * At(Int_t idx) const
Definition: TObjArray.h:165
virtual Bool_t IsDirectory(const char *dir=0) const
Check if object is a directory.
Definition: TSystemFile.cxx:53
UInt_t GetWidth() const
Definition: TGFrame.h:271
Long64_t fSize
Definition: TSystem.h:131
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Returns string containing info about the object at position (px,py).
Definition: TObject.cxx:393
void AddFSDirectory(const char *entry, const char *path=0, Option_t *opt="")
Add file system directory in the list tree.
Handle_t GetId() const
Definition: TGObject.h:48
void DoubleClicked(TGListTreeItem *item, Int_t btn)
Process double clicks in TGListTree.
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:119
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:687
virtual Pixmap_t GetPixmap()
Definition: TImage.h:235
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1043
virtual void Scale(UInt_t, UInt_t)
Definition: TImage.h:141
Int_t fMode
Definition: TSystem.h:128
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:775
virtual void CheckItem(Bool_t=kTRUE)=0
Double_t x[n]
Definition: legend1.C:17
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
Definition: TRemoteObject.h:36
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2345
static TVirtualPadEditor * GetPadEditor(Bool_t load=kTRUE)
Returns the pad editor dialog. Static method.
void Class()
Definition: Class.C:29
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:444
void ToggleSort()
Toggle the sort mode and set the "sort button" state accordingly.
virtual void SetActive(Bool_t)
Definition: TGListTree.h:84
Int_t bsize[]
Definition: SparseFit4.cxx:31
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetUserData(void *, Bool_t=kFALSE)
Definition: TGListTree.h:94
void AddRemoteFile(TObject *obj)
Add remote file in list tree.
const char * GetKeyClassName() const
Definition: TRemoteObject.h:58
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1150
TString & Append(const char *cs)
Definition: TString.h:497
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
void PadModified()
Slot used to switch to the tab containing the current pad/canvas (gPad) used e.g. ...
virtual TList * GetList() const
Definition: TGFrame.h:369
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
Long64_t Atoll() const
Return long long value of string.
Definition: TString.cxx:2001
static Bool_t IsTextFile(const char *candidate)
Returns true if given a text file Uses the specification given on p86 of the Camel book...
TString FullPathName(TGListTreeItem *item)
returns an absolute path
char * FormatFileInfo(const char *fname, Long64_t size, Long_t modtime)
Format file information to be displayed in the tooltip.
TApplication * GetAppRemote() const
Definition: TApplication.h:145
void Chdir(TGListTreeItem *item)
Make object associated with item the current directory.
Describes an Operating System directory for the browser.
A doubly linked list.
Definition: TList.h:43
Pixmap_t GetPicture() const
Definition: TGPicture.h:65
virtual void SetTipText(const char *)
Definition: TGListTree.h:92
virtual void BrowseObj(TObject *obj)
Browse object.
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:867
const char * filters[]
virtual void Browse(TBrowser *b)
Browse the content of the directory.
Definition: TDirectory.cxx:178
virtual const char * ApplicationName() const
Definition: TApplication.h:123
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:561
virtual TGMainFrame * GetMainFrame() const
Definition: TBrowserImp.h:67
Bool_t fIsLink
Definition: TSystem.h:133
void CreateBrowser()
Create the actual file browser.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
TGListTreeItem * GetNextSibling() const
Definition: TGListTree.h:77
void GetFilePictures(const TGPicture **pic, Int_t file_type, Bool_t is_link, const char *name)
Determine the file picture for the given file type.
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:482
virtual void Refresh(Bool_t force=kFALSE)
Refresh content of the list tree.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:436
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:563
This class provides an interface to context sensitive popup menus.
Definition: TContextMenu.h:40
virtual Bool_t SetTab(Int_t tabIndex, Bool_t emit=kTRUE)
Brings the composite frame with the index tabIndex to the front and generate the following event if t...
Definition: TGTab.cxx:507
virtual const char * GetText() const =0
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t GetEntriesFast() const
Definition: TObjArray.h:64
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:388
virtual void RecursiveRemove(TObject *obj)
Recursively remove object.
void Clicked(TGListTreeItem *item, Int_t btn, Int_t x, Int_t y)
Process mouse clicks in TGListTree.
TGFrame * fFrame
Definition: TGLayout.h:119
TString DirName(TGListTreeItem *item)
returns the directory path
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:660
const std::string sname
Definition: testIO.cxx:45
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:315
Option_t * GetDrawOption() const
returns drawing option
mFiltered_t::iterator mFiltered_i
Definition: TGFileBrowser.h:42
void Rename(const char *new_name)
Definition: TGListTree.h:86
#define gVirtualX
Definition: TVirtualX.h:350
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:31
void Selected(char *)
A ROOT File has been selected in TGHtmlBrowser.
static const char * FormatToolTip(TObject *obj, Int_t maxlen=0)
Format the tooltip information, based on the object passed in argument.
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2524
const Bool_t kFALSE
Definition: RtypesCore.h:92
TString & Remove(Ssiz_t pos)
Definition: TString.h:621
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
TGListTreeItem * GetParent() const
Definition: TGListTree.h:73
Long_t XXExecuteDefaultAction(TObject *obj)
Execute default action for selected object (action is specified in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file.
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
Definition: THist.hxx:336
#define ClassImp(name)
Definition: Rtypes.h:336
double f(double x)
virtual Pixmap_t GetMask()
Definition: TImage.h:236
TText * text
Describe directory structure in memory.
Definition: TDirectory.h:34
TGListTreeItem * GetFirstChild() const
Definition: TGListTree.h:74
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
void GotoDir(const char *path)
Go to the directory "path" and open all the parent list tree items.
unsigned long ULong_t
Definition: RtypesCore.h:51
Double_t y[n]
Definition: legend1.C:17
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:572
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Definition: TQObject.cxx:1025
Abstract base class used by ROOT graphics editor.
virtual ~TGFileBrowser()
Destructor.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2885
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event, Bool_t force=kFALSE)
Activate object editors according to the selected object.
Definition: TGedEditor.cxx:349
virtual void SetPictures(const TGPicture *, const TGPicture *)
Definition: TGListTree.h:98
Bool_t IsNull() const
Definition: TString.h:385
Mother of all ROOT objects.
Definition: TObject.h:37
void CheckRemote(TGListTreeItem *item)
Check if the current list tree item points to a remote object.
virtual void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add items to the browser.
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:408
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition: TClass.cxx:5575
A TSystemFile describes an operating system file.
Definition: TSystemFile.h:29
Bool_t R_ISDIR(Int_t mode)
Definition: TSystem.h:116
void AddReference()
Definition: TRefCnt.h:40
Definition: file.py:1
static Bool_t IsObjectEditable(TClass *cl)
Helper function checking if a class has a graphic properties editor.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
void SetDNDSource(Bool_t onoff)
Definition: TGListTree.h:123
virtual TList * GetVolumes(Option_t *) const
Definition: TSystem.h:435
#define snprintf
Definition: civetweb.c:822
#define gPad
Definition: TVirtualPad.h:284
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects)...
Definition: TObject.cxx:466
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:110
#define gDirectory
Definition: TDirectory.h:211
void Checked(TObject *obj, Bool_t check)
Emits signal when double clicking on icon.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1250
Definition: first.py:1
static TImage * Create()
Create an image.
Definition: TImage.cxx:36
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:364
Int_t GetNumberOfTabs() const
Return number of tabs.
Definition: TGTab.cxx:658
const char rootdir[]
const Bool_t kTRUE
Definition: RtypesCore.h:91
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1051
virtual Bool_t SetImageBuffer(char **, EImageFileTypes=TImage::kPng)
Definition: TImage.h:242
void Update()
Update content of the list tree.
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
ABC describing GUI independent browser implementation protocol.
Definition: TBrowserImp.h:29
void GetObjPicture(const TGPicture **pic, TObject *obj)
Retrieve icons associated with class "name".
const char * Data() const
Definition: TString.h:347