Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TGFileDialog.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id: f3cd439bd51d763ffd53693e89c42b2eaa27c520 $
2// Author: Fons Rademakers 20/01/98
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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
13/** \class TGFileDialog
14 \ingroup guiwidgets
15
16This class creates a file selection dialog. It contains a combo box
17to select the desired directory. A listview with the different
18files in the current directory and a combo box with which you can
19select a filter (on file extensions).
20When creating a file dialog one passes a pointer to a TGFileInfo
21object. In this object you can set the fFileTypes and fIniDir to
22specify the list of file types for the filter combo box and the
23initial directory. When the TGFileDialog ctor returns the selected
24file name can be found in the TGFileInfo::fFilename field and the
25selected directory in TGFileInfo::fIniDir. The fFilename and
26fIniDir are deleted by the TGFileInfo dtor.
27
28*/
29
30
31#include "TGFileDialog.h"
32#include "TGLabel.h"
33#include "TGTextEntry.h"
34#include "TGComboBox.h"
35#include "TGListView.h"
36#include "TGFSContainer.h"
37#include "TGFSComboBox.h"
38#include "TGMsgBox.h"
39#include "TGInputDialog.h"
40#include "TSystem.h"
41#include "TObjString.h"
42#include "strlcpy.h"
43
44#include <sys/stat.h>
45
57
58static const char *gDefTypes[] = { "All files", "*",
59 "ROOT files", "*.root",
60 "ROOT macros", "*.C",
61 nullptr, nullptr };
62
64
65
66
67////////////////////////////////////////////////////////////////////////////////
68/// TGFileInfo Destructor.
69
71{
72 delete [] fFilename;
73 delete [] fIniDir;
75}
76
77
78////////////////////////////////////////////////////////////////////////////////
79/// Delete file names list
80
82{
83 if (fFileNamesList) {
84 fFileNamesList->Delete();
85 delete fFileNamesList;
86 fFileNamesList = nullptr;
87 }
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Turn on/off multiple selection.
92
94{
95 if ( fMultipleSelection != option ) {
96 fMultipleSelection = option;
99 fFileNamesList = new TList();
100 }
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Set file name
105
106void TGFileInfo::SetFilename(const char *fname)
107{
108 delete [] fFilename;
109 fFilename = fname ? StrDup(fname) : nullptr;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Set directory name
114
115void TGFileInfo::SetIniDir(const char *inidir)
116{
117 delete [] fIniDir;
118 fIniDir = inidir ? StrDup(inidir) : nullptr;
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Create a file selection dialog. Depending on the dlg_type it can be
123/// used for opening or saving a file.
124/// About the first two arguments, p is the parent Window, usually the
125/// desktop (root) window, and main is the main (TGMainFrame) application
126/// window (the one opening the dialog), onto which the dialog is
127/// usually centered, and which is waiting for it to close.
128
130 EFileDialogMode dlg_type, TGFileInfo *file_info) :
132 fTypes(0), fTreeLB(0), fCdup(0), fNewf(0), fList(0), fDetails(0), fCheckB(0),
133 fPcdup(0), fPnewf(0), fPlist(0), fPdetails(0), fOk(0), fCancel(0), fFv(0),
134 fFc(0), fFileInfo(0), fDlgType(dlg_type)
135{
137 Connect("CloseWindow()", "TGFileDialog", this, "CloseWindow()");
139
140 int i;
141
142 if (!p && !main) {
143 MakeZombie();
144 return;
145 }
146 if (!file_info) {
147 Error("TGFileDialog", "file_info argument not set");
148 fFileInfo = &gInfo;
149 fFileInfo->SetIniDir(nullptr);
150 fFileInfo->SetFilename(nullptr);
151 fFileInfo->fFileTypeIdx = 0;
152 } else
153 fFileInfo = file_info;
154
155 if (!fFileInfo->fFileTypes)
156 fFileInfo->fFileTypes = gDefTypes;
157
158 if (!fFileInfo->fIniDir)
159 fFileInfo->SetIniDir(".");
160
161 TGHorizontalFrame *fHtop = new TGHorizontalFrame(this, 10, 10);
162
163 //--- top toolbar elements
164 TGLabel *fLookin = new TGLabel(fHtop, new TGHotString((dlg_type == kFDSave || dlg_type == kDSave)
165 ? "S&ave in:" : "&Look in:"));
166 fTreeLB = new TGFSComboBox(fHtop, kIDF_FSLB);
167 fTreeLB->Associate(this);
168
169 fPcdup = fClient->GetPicture("tb_uplevel.xpm");
170 fPnewf = fClient->GetPicture("tb_newfolder.xpm");
171 fPlist = fClient->GetPicture("tb_list.xpm");
172 fPdetails = fClient->GetPicture("tb_details.xpm");
173
174 if (!(fPcdup && fPnewf && fPlist && fPdetails))
175 Error("TGFileDialog", "missing toolbar pixmap(s).\n");
176
177 fCdup = new TGPictureButton(fHtop, fPcdup, kIDF_CDUP);
179 fList = new TGPictureButton(fHtop, fPlist, kIDF_LIST);
181
182 fCdup->SetStyle(gClient->GetStyle());
183 fNewf->SetStyle(gClient->GetStyle());
184 fList->SetStyle(gClient->GetStyle());
185 fDetails->SetStyle(gClient->GetStyle());
186
187 fCdup->SetToolTipText("Up One Level");
188 fNewf->SetToolTipText("Create New Folder");
189 fList->SetToolTipText("List");
190 fDetails->SetToolTipText("Details");
191
192 fCdup->Associate(this);
193 fNewf->Associate(this);
194 fList->Associate(this);
195 fDetails->Associate(this);
196
197 fList->AllowStayDown(kTRUE);
198 fDetails->AllowStayDown(kTRUE);
199
200 fTreeLB->Resize(200, fTreeLB->GetDefaultHeight());
201
202 fHtop->AddFrame(fLookin, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
203 fHtop->AddFrame(fTreeLB, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 3, 0, 2, 2));
204 fHtop->AddFrame(fCdup, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
205 fHtop->AddFrame(fNewf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
206 fHtop->AddFrame(fList, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
207 fHtop->AddFrame(fDetails, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 8, 2, 2));
208
209 if (dlg_type == kFDSave) {
210 fCheckB = new TGCheckButton(fHtop, "&Overwrite", kIDF_CHECKB);
211 fCheckB->SetToolTipText("Overwrite a file without displaying a message if selected");
212 } else if (dlg_type == kFDOpen) {
213 fCheckB = new TGCheckButton(fHtop, "&Multiple files", kIDF_CHECKB);
214 fCheckB->SetToolTipText("Allows multiple file selection when SHIFT is pressed");
215 fCheckB->Connect("Toggled(Bool_t)","TGFileInfo",fFileInfo,"SetMultipleSelection(Bool_t)");
216 }
217 if (fCheckB) {
219 fCheckB->SetOn(fFileInfo->fMultipleSelection);
220 }
221 AddFrame(fHtop, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 4, 3, 1));
222
223 //--- file view
224
225 fFv = new TGListView(this, 400, 161);
226
227 fFc = new TGFileContainer(fFv->GetViewPort(),
229 fFc->Associate(this);
230
231 fFv->GetViewPort()->SetBackgroundColor(fgWhitePixel);
232 fFv->SetContainer(fFc);
233 fFv->SetViewMode(kLVList);
234 fFv->SetIncrements(1, 19); // set vertical scroll one line height at a time
235
236 TGTextButton** buttons = fFv->GetHeaderButtons();
237 if (buttons) {
238 buttons[0]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByName)");
239 buttons[1]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByType)");
240 buttons[2]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortBySize)");
241 buttons[3]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByOwner)");
242 buttons[4]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByGroup)");
243 buttons[5]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByDate)");
244 }
245
246 fFc->SetFilter(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx+1]);
247 fFc->Sort(kSortByName);
248 fFc->ChangeDirectory(fFileInfo->fIniDir);
249 fFc->SetMultipleSelection(fFileInfo->fMultipleSelection);
250 fTreeLB->Update(fFc->GetDirectory());
251
252 fList->SetState(kButtonEngaged);
253
255
256 if (dlg_type == kFDOpen) {
257 fCheckB->Connect("Toggled(Bool_t)","TGFileContainer",fFc,"SetMultipleSelection(Bool_t)");
258 fCheckB->Connect("Toggled(Bool_t)","TGFileContainer",fFc,"UnSelectAll()");
259 }
260
261 //--- file name and types
262
263 TGHorizontalFrame *fHf = new TGHorizontalFrame(this, 10, 10);
264
265 TGVerticalFrame *fVf = new TGVerticalFrame(fHf, 10, 10);
266
267 TGHorizontalFrame *fHfname = new TGHorizontalFrame(fVf, 10, 10);
268
269 TGLabel *fLfname = new TGLabel(fHfname, new TGHotString(
270 (dlg_type == kDOpen || dlg_type == kDSave ) ? "Folder &name:" : "File &name:"));
271 fTbfname = new TGTextBuffer(1034);
272 fName = new TGTextEntry(fHfname, fTbfname);
273 fName->Resize(230, fName->GetDefaultHeight());
274 fName->Associate(this);
275
276 fHfname->AddFrame(fLfname, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
277 fHfname->AddFrame(fName, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 20, 2, 2));
278
280
281 TGHorizontalFrame *fHftype = new TGHorizontalFrame(fVf, 10, 10);
282
283 TGLabel *fLftypes = new TGLabel(fHftype, new TGHotString("Files of &type:"));
284 fTypes = new TGComboBox(fHftype, kIDF_FTYPESLB);
285 fTypes->Associate(this);
286 fTypes->Resize(230, fName->GetDefaultHeight());
287
288 TString s;
289 for (i = 0; fFileInfo->fFileTypes[i] != 0; i += 2) {
290 s.Form("%s (%s)", fFileInfo->fFileTypes[i], fFileInfo->fFileTypes[i+1]);
291 fTypes->AddEntry(s.Data(), i);
292 }
293 fTypes->Select(fFileInfo->fFileTypeIdx);
294
295 // Show all items in combobox without scrollbar
296 //TGDimension fw = fTypes->GetListBox()->GetContainer()->GetDefaultSize();
297 //fTypes->GetListBox()->Resize(fw.fWidth, fw.fHeight);
298
299 if (fFileInfo->fFilename && fFileInfo->fFilename[0]) {
300 fTbfname->AddText(0, fFileInfo->fFilename);
301 } else {
302 fTbfname->Clear();
303 if (dlg_type == kFDSave) {
304 fTbfname->AddText(0, "unnamed");
305 fName->SelectAll();
306 if (fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx+1] &&
307 strstr(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx+1], "*.")) {
308 TString ext = fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx+1];
309 ext.ReplaceAll("*.", ".");
310 fTbfname->AddText(7, ext.Data());
311 }
312 fName->SetFocus();
313 }
314 }
315
316 fTypes->GetListBox()->Resize(230, 120);
317 if (dlg_type == kDOpen || dlg_type == kDSave) {
318 fTypes->SetEnabled(kFALSE);
319 }
320
321 fHftype->AddFrame(fLftypes, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
322 fHftype->AddFrame(fTypes, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 20, 2, 2));
323
325
327
328 //--- Open/Save and Cancel buttons
329
330 TGVerticalFrame *fVbf = new TGVerticalFrame(fHf, 10, 10, kFixedWidth);
331
332 fOk = new TGTextButton(fVbf, new TGHotString((dlg_type == kFDSave || dlg_type == kDSave)
333 ? "&Save" : "&Open"), kIDF_OK);
334 fCancel = new TGTextButton(fVbf, new TGHotString("Cancel"), kIDF_CANCEL);
335
336 fOk->Associate(this);
337 fCancel->Associate(this);
338
339 fVbf->AddFrame(fOk, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
340 fVbf->AddFrame(fCancel, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
341
342 UInt_t width = std::max(fOk->GetDefaultWidth(), fCancel->GetDefaultWidth()) + 20;
343 fVbf->Resize(width + 20, fVbf->GetDefaultHeight());
344
346
347 AddFrame(fHf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 4, 3, 1));
349
351
353
354 Resize(size);
355
356 //---- position relative to the parent's window
357
359
360 //---- make the message box non-resizable
361
362 SetWMSize(size.fWidth, size.fHeight);
363 SetWMSizeHints(size.fWidth, size.fHeight, 10000, 10000, 1, 1);
364
365 const char *wname = (dlg_type == kFDSave || dlg_type == kDSave) ? "Save As..." : "Open";
366 SetWindowName(wname);
367 SetIconName(wname);
368 SetClassHints("ROOT", "FileDialog");
369
375
376 MapWindow();
377 fFc->DisplayDirectory();
378 if (dlg_type == kFDSave || dlg_type == kDSave)
379 fName->SetFocus();
380 fClient->WaitFor(this);
381}
382
383////////////////////////////////////////////////////////////////////////////////
384/// Delete file dialog.
385
387{
388 if (IsZombie()) return;
389 TString str = fCheckB ? fCheckB->GetString() : TString();
390 if (str.Contains("Multiple") && fCheckB)
391 fCheckB->Disconnect("Toggled(Bool_t)");
392 fClient->FreePicture(fPcdup);
393 fClient->FreePicture(fPnewf);
394 fClient->FreePicture(fPlist);
395 fClient->FreePicture(fPdetails);
396 delete fFc;
397}
398
399////////////////////////////////////////////////////////////////////////////////
400/// Close file dialog.
401
403{
404 fFileInfo->SetFilename(nullptr);
405 fFileInfo->DeleteFileNamesList();
406 DeleteWindow();
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Small function used to prevent memory leaks with TSystem::ExpandPathName,
411/// which returns a string created by StrDup, that has to be deleted
412
413namespace {
414 static inline void pExpandUnixPathName(TGFileInfo &file_info) {
415 char *tmpPath = gSystem->ExpandPathName(file_info.fFilename);
416 file_info.SetFilename(gSystem->UnixPathName(tmpPath));
417 delete[] tmpPath;
418 }
419}
420
421////////////////////////////////////////////////////////////////////////////////
422/// Process messages generated by the user input in the file dialog.
423
425{
426 if (!fFc->GetDisplayStat()) return kTRUE; // Cancel button was pressed
427
429 TGTextLBEntry *te;
430 TGFileItem *f;
431 void *p = 0;
432 TString txt;
433 TString sdir = gSystem->WorkingDirectory();
434 TString temp_string = fTbfname->GetString();
435
436 switch (GET_MSG(msg)) {
437 case kC_COMMAND:
438 switch (GET_SUBMSG(msg)) {
439 case kCM_BUTTON:
440 switch (parm1) {
441 case kIDF_OK:
442 // same code as under kTE_ENTER
443 if (fTbfname->GetTextLength() == 0) {
444 txt = "Please provide file name or use \"Cancel\"";
445 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
446 "Missing File Name", txt, kMBIconExclamation,
447 kMBOk);
448 return kTRUE;
449 } else if (!gSystem->AccessPathName(fTbfname->GetString(), kFileExists) &&
450 !strcmp(fOk->GetTitle(), "Save") && fCheckB &&
451 (!(fCheckB->GetState() == kButtonDown))) {
452 Int_t ret;
453 txt = TString::Format("File name %s already exists, OK to overwrite it?",
454 fTbfname->GetString());
455 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
456 "File Name Exist", txt.Data(), kMBIconExclamation,
457 kMBYes | kMBNo, &ret);
458 if (ret == kMBNo)
459 return kTRUE;
460 }
461 if (fFileInfo->fMultipleSelection) {
462 fFileInfo->SetFilename(nullptr);
463 } else {
464 fFileInfo->SetFilename(nullptr);
465 // FIXME: once appropriate gSystem method exists, use SetFilename here
466 if (gSystem->IsAbsoluteFileName(fTbfname->GetString()))
467 fFileInfo->SetFilename(fTbfname->GetString());
468 else {
469 TString temp = fTbfname->GetString();
470 fFileInfo->fFilename = strdup(gSystem->PrependPathName(fFc->GetDirectory(), temp));
471 }
472 pExpandUnixPathName(*fFileInfo);
473 }
474 if (fCheckB && (fCheckB->GetState() == kButtonDown))
475 fFileInfo->fOverwrite = kTRUE;
476 else
477 fFileInfo->fOverwrite = kFALSE;
478 DeleteWindow();
479 break;
480
481 case kIDF_CANCEL:
482 fFileInfo->SetFilename(nullptr);
483 if (fDlgType == kDOpen || fDlgType == kDSave)
484 fFileInfo->SetIniDir(nullptr);
485 if (fFc->GetDisplayStat())
486 fFc->SetDisplayStat(kFALSE);
487 fFileInfo->DeleteFileNamesList();
488 DeleteWindow();
489 return kTRUE; //no need to redraw fFc
490 break;
491
492 case kIDF_CDUP:
493 fFc->ChangeDirectory("..");
494 fTreeLB->Update(fFc->GetDirectory());
495 fFileInfo->SetIniDir(fFc->GetDirectory());
496 if (strcmp(gSystem->WorkingDirectory(),fFc->GetDirectory())) {
497 gSystem->cd(fFc->GetDirectory());
498 }
499 break;
500
501 case kIDF_NEW_FOLDER: {
502 char answer[128];
503 strlcpy(answer, "(empty)", sizeof(answer));
504 new TGInputDialog(gClient->GetRoot(), GetMainFrame(),
505 "Enter directory name:",
506 answer/*"(empty)"*/, answer);
507
508 while ( strcmp(answer, "(empty)") == 0 ) {
509 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
510 "Please enter a valid directory name.",
512 new TGInputDialog(gClient->GetRoot(), GetMainFrame(),
513 "Enter directory name:",
514 answer, answer);
515 }
516 if ( strcmp(answer, "") == 0 ) // Cancel button was pressed
517 break;
518
519 if (strcmp(gSystem->WorkingDirectory(),fFc->GetDirectory())) {
520 gSystem->cd(fFc->GetDirectory());
521 }
522 if ( gSystem->MakeDirectory(answer) != 0 )
523 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
524 TString::Format("Directory name \'%s\' already exists!", answer),
526 else {
527 fFc->DisplayDirectory();
528 }
529 gSystem->ChangeDirectory(sdir.Data());
530 break;
531 }
532
533 case kIDF_LIST:
534 fFv->SetViewMode(kLVList);
535 fDetails->SetState(kButtonUp);
536 break;
537
538 case kIDF_DETAILS:
539 fFv->SetViewMode(kLVDetails);
540 fList->SetState(kButtonUp);
541 break;
542 }
543 break;
544
545 case kCM_COMBOBOX:
546 switch (parm1) {
547 case kIDF_FSLB:
548 e = (TGTreeLBEntry *) fTreeLB->GetSelectedEntry();
549 if (e) {
550 fFc->ChangeDirectory(e->GetPath()->GetString());
551 fTreeLB->Update(fFc->GetDirectory());
552 fFileInfo->SetIniDir(fFc->GetDirectory());
553 if (strcmp(gSystem->WorkingDirectory(),fFc->GetDirectory())) {
554 gSystem->cd(fFc->GetDirectory());
555 }
556 }
557 break;
558
559 case kIDF_FTYPESLB:
560 te = (TGTextLBEntry *) fTypes->GetSelectedEntry();
561 if (te) {
562 //fTbfname->Clear();
563 //fTbfname->AddText(0, fFileInfo->fFileTypes[te->EntryId()+1]);
564 fFileInfo->fFileTypeIdx = te->EntryId();
565 fFc->SetFilter(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx+1]);
566 fFc->DisplayDirectory();
567 fClient->NeedRedraw(fName);
568 }
569 break;
570 }
571 break;
572
573 default:
574 break;
575 } // switch(GET_SUBMSG(msg))
576 break;
577
578 case kC_CONTAINER:
579 switch (GET_SUBMSG(msg)) {
580 case kCT_ITEMCLICK:
581 if (parm1 == kButton1) {
582 if (fFc->NumSelected() > 0) {
583 if ( fFileInfo->fMultipleSelection == kFALSE ) {
584 TGLVEntry *e2 = (TGLVEntry *) fFc->GetNextSelected(&p);
585 if (fDlgType == kFDOpen || fDlgType == kFDSave) {
586 if ((e2) && !R_ISDIR(((TGFileItem *)e2)->GetType())) {
587 fTbfname->Clear();
588 if (e2->GetItemName())
589 fTbfname->AddText(0, e2->GetItemName()->GetString());
590 fClient->NeedRedraw(fName);
591 }
592 } else {
593 if ((e2) && R_ISDIR(((TGFileItem *)e2)->GetType())) {
594 fTbfname->Clear();
595 if (e2->GetItemName())
596 fTbfname->AddText(0, e2->GetItemName()->GetString());
597 fClient->NeedRedraw(fName);
598 fOk->SetEnabled(kTRUE);
599 } else if ((e2)) {
600 fOk->SetEnabled(kFALSE);
601 }
602 }
603 }
604 else {
605 TString tmpString;
606 TList *tmp = fFc->GetSelectedItems();
607 TObjString *el;
608 TIter next(tmp);
609 if (fFileInfo->fFileNamesList) {
610 fFileInfo->fFileNamesList->Delete();
611 } else {
612 fFileInfo->fFileNamesList = new TList();
613 }
614 while ((el = (TObjString *) next())) {
615 TString temp = el->GetString();
616 const char *s = gSystem->PrependPathName(fFc->GetDirectory(), temp);
617 tmpString += "\"" + el->GetString() + "\" ";
618 fFileInfo->fFileNamesList->Add(new TObjString(s));
619 }
620 tmp->Delete();
621 delete tmp;
622 fTbfname->Clear();
623 fTbfname->AddText(0, tmpString);
624 fClient->NeedRedraw(fName);
625 }
626 }
627 }
628 break;
629
630 case kCT_ITEMDBLCLICK:
631
632 if (parm1 == kButton1) {
633 if (fFc->NumSelected() == 1) {
634 f = (TGFileItem *) fFc->GetNextSelected(&p);
635 if (f && R_ISDIR(f->GetType())) {
636 fFc->ChangeDirectory(f->GetItemName()->GetString());
637 fTreeLB->Update(fFc->GetDirectory());
638 fFileInfo->SetIniDir(fFc->GetDirectory());
639 if (strcmp(gSystem->WorkingDirectory(),fFc->GetDirectory())) {
640 gSystem->cd(fFc->GetDirectory());
641 }
642 if (fDlgType == kDOpen || fDlgType == kDSave) {
643 fTbfname->Clear();
644 fTbfname->AddText(0, fFc->GetDirectory());
645 fClient->NeedRedraw(fName);
646 }
647 } else if (fDlgType == kFDOpen || fDlgType == kFDSave) {
648 if (!strcmp(fOk->GetTitle(), "Save") && fCheckB &&
649 (!(fCheckB->GetState() == kButtonDown))) {
650
651 Int_t ret;
652 txt = TString::Format("File name %s already exists, OK to overwrite it?",
653 fTbfname->GetString());
654 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
655 "File Name Exist", txt.Data(), kMBIconExclamation,
656 kMBYes | kMBNo, &ret);
657 if (ret == kMBNo)
658 return kTRUE;
659 }
660 fFileInfo->SetFilename(nullptr);
661 // FIXME: once appropriate gSystem method exists, use SetFilename here
662 if (gSystem->IsAbsoluteFileName(fTbfname->GetString()))
663 fFileInfo->SetFilename(fTbfname->GetString());
664 else {
665 TString temp = fTbfname->GetString();
666 fFileInfo->fFilename = strdup(gSystem->PrependPathName(fFc->GetDirectory(), temp));
667 }
668 pExpandUnixPathName(*fFileInfo);
669 if (fCheckB && (fCheckB->GetState() == kButtonDown))
670 fFileInfo->fOverwrite = kTRUE;
671 else
672 fFileInfo->fOverwrite = kFALSE;
673
674 DeleteWindow();
675 }
676 }
677 }
678
679 break;
680
681 default:
682 break;
683
684 } // switch(GET_SUBMSG(msg))
685 break;
686
687 case kC_TEXTENTRY:
688 // when typing, re-enable previously disabled button after having clicked on file instead of folder
689 if ((fDlgType==kDOpen || fDlgType==kDSave) && fOk->GetState()==kButtonDisabled)
690 fOk->SetEnabled(kTRUE);
691
692 switch (GET_SUBMSG(msg)) {
693 case kTE_ENTER:
694 // same code as under kIDF_OK
695 if (fTbfname->GetTextLength() == 0) {
696 const char *txt2 = "Please provide file name or use \"Cancel\"";
697 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
698 "Missing File Name", txt2, kMBIconExclamation,
699 kMBOk);
700 return kTRUE;
701 } else if (!gSystem->AccessPathName(fTbfname->GetString(), kFileExists)) {
702 FileStat_t buf;
703 if (!gSystem->GetPathInfo(fTbfname->GetString(), buf) &&
704 R_ISDIR(buf.fMode)) {
705 fFc->ChangeDirectory(fTbfname->GetString());
706 fTreeLB->Update(fFc->GetDirectory());
707 if (strcmp(gSystem->WorkingDirectory(), fFc->GetDirectory())) {
708 gSystem->cd(fFc->GetDirectory());
709 }
710 fName->SetText("", kFALSE);
711 return kTRUE;
712 }
713 else if (!strcmp(fOk->GetTitle(), "Save") && fCheckB &&
714 (!(fCheckB->GetState() == kButtonDown))) {
715 Int_t ret;
716 txt = TString::Format("File name %s already exists, OK to overwrite it?",
717 fTbfname->GetString());
718 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
719 "File Name Exist", txt.Data(), kMBIconExclamation,
720 kMBYes | kMBNo, &ret);
721 if (ret == kMBNo)
722 return kTRUE;
723 }
724 }
725 fFileInfo->SetFilename(nullptr);
726 // FIXME: once appropriate gSystem method exists, use SetFilename here
727 temp_string = fTbfname->GetString();
728 fFileInfo->fFilename = strdup(gSystem->PrependPathName(fFc->GetDirectory(), temp_string));
729 pExpandUnixPathName(*fFileInfo);
730 if (fCheckB && (fCheckB->GetState() == kButtonDown))
731 fFileInfo->fOverwrite = kTRUE;
732 else
733 fFileInfo->fOverwrite = kFALSE;
734 DeleteWindow();
735 break;
736
737 default:
738 break;
739 }
740 break;
741
742 default:
743 break;
744
745 } // switch(GET_MSG(msg))
746
747 fClient->NeedRedraw(fFc);
748 return kTRUE;
749}
@ kVerticalFrame
Definition GuiTypes.h:382
@ kFixedWidth
Definition GuiTypes.h:388
@ kHorizontalFrame
Definition GuiTypes.h:383
@ kButton1
Definition GuiTypes.h:215
#define f(i)
Definition RSha256.hxx:104
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char * ret
Definition Rotated.cxx:221
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:89
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
@ kButtonEngaged
Definition TGButton.h:55
#define gClient
Definition TGClient.h:157
@ kSortByName
EFileFialog
@ kIDF_OK
@ kIDF_FTYPESLB
@ kIDF_FSLB
@ kIDF_CDUP
@ kIDF_DETAILS
@ kIDF_NEW_FOLDER
@ kIDF_CHECKB
@ kIDF_LIST
@ kIDF_CANCEL
static TGFileInfo gInfo
static const char * gDefTypes[]
EFileDialogMode
@ kFDOpen
@ kDOpen
@ kDSave
@ kFDSave
@ kMWMDecorResizeH
Definition TGFrame.h:65
@ kMWMFuncAll
Definition TGFrame.h:49
@ kMWMFuncResize
Definition TGFrame.h:50
@ kMWMDecorMaximize
Definition TGFrame.h:69
@ kMWMDecorMinimize
Definition TGFrame.h:68
@ kMWMDecorMenu
Definition TGFrame.h:67
@ kMWMDecorAll
Definition TGFrame.h:63
@ kMWMFuncMaximize
Definition TGFrame.h:53
@ kMWMInputModeless
Definition TGFrame.h:57
@ kMWMFuncMinimize
Definition TGFrame.h:52
@ 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
@ kLVDetails
Definition TGListView.h:25
@ kLVList
Definition TGListView.h:24
@ kMBNo
Definition TGMsgBox.h:32
@ kMBYes
Definition TGMsgBox.h:31
@ kMBOk
Definition TGMsgBox.h:33
@ kMBIconExclamation
Definition TGMsgBox.h:24
@ kMBIconStop
Definition TGMsgBox.h:22
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2564
@ kFileExists
Definition TSystem.h:52
Bool_t R_ISDIR(Int_t mode)
Definition TSystem.h:123
externTSystem * gSystem
Definition TSystem.h:582
Int_t GET_MSG(Long_t val)
@ kCM_COMBOBOX
@ kTE_ENTER
@ kCT_ITEMCLICK
@ kC_COMMAND
@ kCM_BUTTON
@ kC_TEXTENTRY
@ kCT_ITEMDBLCLICK
@ kC_CONTAINER
Int_t GET_SUBMSG(Long_t val)
Selects different options.
Definition TGButton.h:264
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
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:1109
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:316
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1064
void SetEditDisabled(UInt_t on=1) override
Set edit disable flag for this frame and subframes.
Definition TGFrame.cxx:1014
This is a combo box that is used in the File Selection dialog box.
const TGPicture * fPcdup
picture for fCdup
const TGPicture * fPdetails
picture for fDetails
TGFileContainer * fFc
file list view container (containing the files)
TGPictureButton * fDetails
top toolbar button
TGPictureButton * fNewf
top toolbar button
EFileDialogMode fDlgType
the dialog type passed
TGTextBuffer * fTbfname
text buffer of file name
TGTextButton * fCancel
cancel button
TGFSComboBox * fTreeLB
file system path combo box
TGFileInfo * fFileInfo
file info passed to this dialog
~TGFileDialog() override
Delete file dialog.
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process messages generated by the user input in the file dialog.
TGTextEntry * fName
file name text entry
const TGPicture * fPnewf
picture for fNewf
TGPictureButton * fList
top toolbar button
void CloseWindow() override
Close file dialog.
TGPictureButton * fCdup
top toolbar button
TGListView * fFv
file list view
const TGPicture * fPlist
picture for fList
TGTextButton * fOk
ok button
TGCheckButton * fCheckB
set on/off file overwriting for Open dialog OR set on/off multiple file selection for SaveAs dialog
TGFileDialog(const TGFileDialog &)=delete
TGComboBox * fTypes
file type combo box
TList * fFileNamesList
list of selected file names
char * fFilename
selected file name
void SetMultipleSelection(Bool_t option)
Turn on/off multiple selection.
char * fIniDir
on input: initial directory, on output: new directory
~TGFileInfo()
TGFileInfo Destructor.
void DeleteFileNamesList()
Delete file names list.
void SetFilename(const char *fname)
Set file name.
Bool_t fMultipleSelection
if true, allow multiple file selection
void SetIniDir(const char *inidir)
Set directory name.
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
void MapWindow() override
map window
Definition TGFrame.h:206
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:268
static Pixel_t fgWhitePixel
Definition TGFrame.h:103
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
TGHotString is a string with a "hot" character underlined.
Definition TGString.h:42
Input Dialog Widget.
Int_t EntryId() const
Definition TGListBox.h:40
TGString * GetItemName() const
Definition TGListView.h:88
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
A list view is a widget that can contain a number of items arranged in a grid or list.
Definition TGListView.h:115
void DontCallClose()
Typically call this method in the slot connected to the CloseWindow() signal to prevent the calling o...
Definition TGFrame.cxx:1772
void SetClassHints(const char *className, const char *resourceName)
Set the windows class and resource name.
Definition TGFrame.cxx:1850
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1793
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1885
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1780
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition TGFrame.cxx:1860
void SetWMSizeHints(UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
Give the window manager minimum and maximum size hints.
Definition TGFrame.cxx:1898
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Yield an action as soon as it is clicked.
Definition TGButton.h:228
const char * GetString() const
Definition TGString.h:30
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
Text string listbox entries.
Definition TGListBox.h:48
TGTransientFrame(const TGTransientFrame &)=delete
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1949
A composite frame that layout their children in vertical way.
Definition TGFrame.h:376
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition TGWindow.cxx:150
@ kEditDisable
disable edit of this window
Definition TGWindow.h:57
A doubly linked list.
Definition TList.h:38
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
Collectable string class.
Definition TObjString.h:28
const TString & GetString() const
Definition TObjString.h:46
void MakeZombie()
Definition TObject.h:55
Bool_t IsZombie() const
Definition TObject.h:161
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
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:713
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:2385
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2363
int main(int argc, char **argv)
Definition hadd.cxx:631
Int_t fMode
Definition TSystem.h:135