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