TGFileDialog.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGFileDialog.cxx 35518 2010-09-21 09:54:10Z bellenot $
00002 // Author: Fons Rademakers   20/01/98
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TGFileDialog                                                         //
00015 //                                                                      //
00016 // This class creates a file selection dialog. It contains a combo box  //
00017 // to select the desired directory. A listview with the different       //
00018 // files in the current directory and a combo box with which you can    //
00019 // select a filter (on file extensions).                                //
00020 // When creating a file dialog one passes a pointer to a TGFileInfo     //
00021 // object. In this object you can set the fFileTypes and fIniDir to     //
00022 // specify the list of file types for the filter combo box and the      //
00023 // initial directory. When the TGFileDialog ctor returns the selected   //
00024 // file name can be found in the TGFileInfo::fFilename field and the    //
00025 // selected directory in TGFileInfo::fIniDir. The fFilename and         //
00026 // fIniDir are deleted by the TGFileInfo dtor.                          //
00027 //                                                                      //
00028 //////////////////////////////////////////////////////////////////////////
00029 
00030 #include "TGFileDialog.h"
00031 #include "TGLabel.h"
00032 #include "TGButton.h"
00033 #include "TGTextEntry.h"
00034 #include "TGComboBox.h"
00035 #include "TGListView.h"
00036 #include "TGFSContainer.h"
00037 #include "TGFSComboBox.h"
00038 #include "TGMsgBox.h"
00039 #include "TSystem.h"
00040 #include "TGInputDialog.h"
00041 #include "TObjString.h"
00042 
00043 #include <sys/stat.h>
00044 
00045 enum EFileFialog {
00046    kIDF_CDUP,
00047    kIDF_NEW_FOLDER,
00048    kIDF_LIST,
00049    kIDF_DETAILS,
00050    kIDF_CHECKB,
00051    kIDF_FSLB,
00052    kIDF_FTYPESLB,
00053    kIDF_OK,
00054    kIDF_CANCEL
00055 };
00056 
00057 static const char *gDefTypes[] = { "All files",     "*",
00058                                    "ROOT files",    "*.root",
00059                                    "ROOT macros",   "*.C",
00060                                     0,               0 };
00061 
00062 static TGFileInfo gInfo;
00063 
00064 
00065 ClassImp(TGFileDialog)
00066 
00067 //______________________________________________________________________________
00068 TGFileInfo::~TGFileInfo()
00069 {
00070    // TGFileInfo Destructor.
00071 
00072    delete [] fFilename;
00073    delete [] fIniDir;
00074    if ( fFileNamesList != 0 ) {
00075       fFileNamesList->Delete();
00076       delete fFileNamesList;
00077    }
00078 }
00079 
00080 //______________________________________________________________________________
00081 void TGFileInfo::SetMultipleSelection(Bool_t option)
00082 {
00083    // Turn on/off multiple selection.
00084 
00085    if ( fMultipleSelection != option ) {
00086       fMultipleSelection = option;
00087       if ( fMultipleSelection == kTRUE )
00088          fFileNamesList = new TList();
00089       else {
00090          fFileNamesList->Delete();
00091          delete fFileNamesList;
00092          fFileNamesList = 0;
00093       }
00094    }
00095 }
00096 
00097 //______________________________________________________________________________
00098 TGFileDialog::TGFileDialog(const TGWindow *p, const TGWindow *main,
00099                            EFileDialogMode dlg_type, TGFileInfo *file_info) :
00100    TGTransientFrame(p, main, 10, 10, kVerticalFrame)
00101 {
00102    // Create a file selection dialog. Depending on the dlg_type it can be
00103    // used for opening or saving a file.
00104 
00105    SetCleanup(kDeepCleanup);
00106    Connect("CloseWindow()", "TGFileDialog", this, "CloseWindow()");
00107    DontCallClose();
00108 
00109    int i;
00110 
00111    if (!p && !main) {
00112       MakeZombie();
00113       return;
00114    }
00115    if (!file_info) {
00116       Error("TGFileDialog", "file_info argument not set");
00117       fFileInfo = &gInfo;
00118       if (fFileInfo->fIniDir) {
00119          delete [] fFileInfo->fIniDir;
00120          fFileInfo->fIniDir = 0;
00121       }
00122       if (fFileInfo->fFilename) {
00123          delete [] fFileInfo->fFilename;
00124          fFileInfo->fFilename = 0;
00125       }
00126       fFileInfo->fFileTypeIdx = 0;
00127    } else
00128       fFileInfo = file_info;
00129 
00130    if (!fFileInfo->fFileTypes)
00131       fFileInfo->fFileTypes = gDefTypes;
00132 
00133    if (!fFileInfo->fIniDir)
00134       fFileInfo->fIniDir = StrDup(".");
00135 
00136    TGHorizontalFrame *fHtop = new TGHorizontalFrame(this, 10, 10);
00137    
00138    //--- top toolbar elements
00139    TGLabel *fLookin = new TGLabel(fHtop, new TGHotString((dlg_type == kFDSave)
00140                                                   ? "S&ave in:" : "&Look in:"));
00141    fTreeLB = new TGFSComboBox(fHtop, kIDF_FSLB);
00142    fTreeLB->Associate(this);
00143 
00144    fPcdup = fClient->GetPicture("tb_uplevel.xpm");
00145    fPnewf = fClient->GetPicture("tb_newfolder.xpm");
00146    fPlist = fClient->GetPicture("tb_list.xpm");
00147    fPdetails = fClient->GetPicture("tb_details.xpm");
00148 
00149    if (!(fPcdup && fPnewf && fPlist && fPdetails))
00150       Error("TGFileDialog", "missing toolbar pixmap(s).\n");
00151 
00152    fCdup    = new TGPictureButton(fHtop, fPcdup, kIDF_CDUP);
00153    fNewf    = new TGPictureButton(fHtop, fPnewf, kIDF_NEW_FOLDER);
00154    fList    = new TGPictureButton(fHtop, fPlist, kIDF_LIST);
00155    fDetails = new TGPictureButton(fHtop, fPdetails, kIDF_DETAILS);
00156 
00157    fCdup->SetToolTipText("Up One Level");
00158    fNewf->SetToolTipText("Create New Folder");
00159    fList->SetToolTipText("List");
00160    fDetails->SetToolTipText("Details");
00161 
00162    fCdup->Associate(this);
00163    fNewf->Associate(this);
00164    fList->Associate(this);
00165    fDetails->Associate(this);
00166 
00167    fList->AllowStayDown(kTRUE);
00168    fDetails->AllowStayDown(kTRUE);
00169 
00170    fTreeLB->Resize(200, fTreeLB->GetDefaultHeight());
00171 
00172    fHtop->AddFrame(fLookin, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
00173    fHtop->AddFrame(fTreeLB, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 3, 0, 2, 2));
00174    fHtop->AddFrame(fCdup, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
00175    fHtop->AddFrame(fNewf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
00176    fHtop->AddFrame(fList, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
00177    fHtop->AddFrame(fDetails, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 8, 2, 2));
00178 
00179    if (dlg_type == kFDSave) {
00180       fCheckB = new TGCheckButton(fHtop, "&Overwrite", kIDF_CHECKB);
00181       fCheckB->SetToolTipText("Overwrite a file without displaying a message if selected");
00182    } else {
00183       fCheckB = new TGCheckButton(fHtop, "&Multiple files", kIDF_CHECKB);
00184       fCheckB->SetToolTipText("Allows multiple file selection when SHIFT is pressed");
00185       fCheckB->Connect("Toggled(Bool_t)","TGFileInfo",fFileInfo,"SetMultipleSelection(Bool_t)");
00186    }
00187    fHtop->AddFrame(fCheckB, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00188    fCheckB->SetOn(fFileInfo->fMultipleSelection);
00189    AddFrame(fHtop, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 4, 3, 1));
00190 
00191    //--- file view
00192 
00193    fFv = new TGListView(this, 400, 161);
00194 
00195    fFc = new TGFileContainer(fFv->GetViewPort(),
00196                              10, 10, kHorizontalFrame, fgWhitePixel);
00197    fFc->Associate(this);
00198 
00199    fFv->GetViewPort()->SetBackgroundColor(fgWhitePixel);
00200    fFv->SetContainer(fFc);
00201    fFv->SetViewMode(kLVList);
00202    fFv->SetIncrements(1, 19); // set vertical scroll one line height at a time
00203 
00204    TGTextButton** buttons = fFv->GetHeaderButtons();
00205    if (buttons) {
00206       buttons[0]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByName)");
00207       buttons[1]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByType)");
00208       buttons[2]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortBySize)");
00209       buttons[3]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByOwner)");
00210       buttons[4]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByGroup)");
00211       buttons[5]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByDate)");
00212    }
00213 
00214    fFc->SetFilter(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx+1]);
00215    fFc->Sort(kSortByName);
00216    fFc->ChangeDirectory(fFileInfo->fIniDir);
00217    fFc->SetMultipleSelection(fFileInfo->fMultipleSelection);
00218    fTreeLB->Update(fFc->GetDirectory());
00219 
00220    fList->SetState(kButtonEngaged);
00221 
00222    AddFrame(fFv, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 4, 4, 3, 1));
00223 
00224    if (dlg_type == kFDOpen) {
00225       fCheckB->Connect("Toggled(Bool_t)","TGFileContainer",fFc,"SetMultipleSelection(Bool_t)");
00226       fCheckB->Connect("Toggled(Bool_t)","TGFileContainer",fFc,"UnSelectAll()");
00227    }
00228    
00229    //--- file name and types
00230 
00231    TGHorizontalFrame *fHf = new TGHorizontalFrame(this, 10, 10);
00232 
00233    TGVerticalFrame *fVf = new TGVerticalFrame(fHf, 10, 10);
00234 
00235    TGHorizontalFrame *fHfname = new TGHorizontalFrame(fVf, 10, 10);
00236 
00237    TGLabel *fLfname = new TGLabel(fHfname, new TGHotString("File &name:"));
00238    fTbfname = new TGTextBuffer(1034);
00239    fName = new TGTextEntry(fHfname, fTbfname);
00240    fName->Resize(230, fName->GetDefaultHeight());
00241    fName->Associate(this);
00242 
00243    fHfname->AddFrame(fLfname, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
00244    fHfname->AddFrame(fName, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 20, 2, 2));
00245 
00246    fVf->AddFrame(fHfname, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));
00247 
00248    TGHorizontalFrame *fHftype = new TGHorizontalFrame(fVf, 10, 10);
00249 
00250    TGLabel *fLftypes = new TGLabel(fHftype, new TGHotString("Files of &type:"));
00251    fTypes = new TGComboBox(fHftype, kIDF_FTYPESLB);
00252    fTypes->Associate(this);
00253    fTypes->Resize(230, fName->GetDefaultHeight());
00254 
00255    TString s;
00256    for (i = 0; fFileInfo->fFileTypes[i] != 0; i += 2) {
00257       s.Form("%s (%s)", fFileInfo->fFileTypes[i], fFileInfo->fFileTypes[i+1]);
00258       fTypes->AddEntry(s.Data(), i);
00259    }
00260    fTypes->Select(fFileInfo->fFileTypeIdx);
00261 
00262    // Show all items in combobox without scrollbar
00263    //TGDimension fw = fTypes->GetListBox()->GetContainer()->GetDefaultSize();
00264    //fTypes->GetListBox()->Resize(fw.fWidth, fw.fHeight);
00265 
00266    if (fFileInfo->fFilename && fFileInfo->fFilename[0])
00267       fTbfname->AddText(0, fFileInfo->fFilename);
00268    else
00269       fTbfname->Clear();
00270 
00271    fHftype->AddFrame(fLftypes, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
00272    fHftype->AddFrame(fTypes, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 20, 2, 2));
00273 
00274    fVf->AddFrame(fHftype, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));
00275 
00276    fHf->AddFrame(fVf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));
00277 
00278    //--- Open/Save and Cancel buttons
00279 
00280    TGVerticalFrame *fVbf = new TGVerticalFrame(fHf, 10, 10, kFixedWidth);
00281 
00282    fOk = new TGTextButton(fVbf, new TGHotString((dlg_type == kFDSave)
00283                                                  ? "&Save" : "&Open"), kIDF_OK);
00284    fCancel = new TGTextButton(fVbf, new TGHotString("Cancel"), kIDF_CANCEL);
00285 
00286    fOk->Associate(this);
00287    fCancel->Associate(this);
00288 
00289    fVbf->AddFrame(fOk, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
00290    fVbf->AddFrame(fCancel, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
00291 
00292    UInt_t width = TMath::Max(fOk->GetDefaultWidth(), fCancel->GetDefaultWidth()) + 20;
00293    fVbf->Resize(width + 20, fVbf->GetDefaultHeight());
00294 
00295    fHf->AddFrame(fVbf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00296 
00297    AddFrame(fHf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 4, 3, 1));
00298    SetEditDisabled(kEditDisable);
00299 
00300    MapSubwindows();
00301 
00302    TGDimension size = GetDefaultSize();
00303 
00304    Resize(size);
00305 
00306    //---- position relative to the parent's window
00307 
00308    CenterOnParent();
00309 
00310    //---- make the message box non-resizable
00311 
00312    SetWMSize(size.fWidth, size.fHeight);
00313    SetWMSizeHints(size.fWidth, size.fHeight, 10000, 10000, 1, 1);
00314 
00315    const char *wname = (dlg_type == kFDSave) ? "Save As..." : "Open";
00316    SetWindowName(wname);
00317    SetIconName(wname);
00318    SetClassHints("FileDialog", "FileDialog");
00319 
00320    SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
00321                               kMWMDecorMinimize | kMWMDecorMenu,
00322                kMWMFuncAll |  kMWMFuncResize    | kMWMFuncMaximize |
00323                               kMWMFuncMinimize,
00324                kMWMInputModeless);
00325 
00326    MapWindow();
00327    fFc->DisplayDirectory();
00328    fClient->WaitFor(this);
00329 }
00330 
00331 //______________________________________________________________________________
00332 TGFileDialog::~TGFileDialog()
00333 {
00334    // Delete file dialog.
00335 
00336    if (IsZombie()) return;
00337    TString str = fCheckB->GetString();
00338    if (str.Contains("Multiple")) 
00339       fCheckB->Disconnect("Toggled(Bool_t)");
00340    fClient->FreePicture(fPcdup);
00341    fClient->FreePicture(fPnewf);
00342    fClient->FreePicture(fPlist);
00343    fClient->FreePicture(fPdetails);
00344    delete fFc; 
00345 }
00346 
00347 //______________________________________________________________________________
00348 void TGFileDialog::CloseWindow()
00349 {
00350    // Close file dialog.
00351 
00352    if (fFileInfo->fFilename)
00353       delete [] fFileInfo->fFilename;
00354    fFileInfo->fFilename = 0;
00355    if (fFileInfo->fFileNamesList != 0) {
00356       fFileInfo->fFileNamesList->Delete();
00357       fFileInfo->fFileNamesList = 0;
00358    }
00359    DeleteWindow();
00360 }
00361 
00362 //______________________________________________________________________________
00363 Bool_t TGFileDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00364 {
00365    // Process messages generated by the user input in the file dialog.
00366 
00367    if (!fFc->GetDisplayStat()) return kTRUE;  // Cancel button was pressed
00368    
00369    TGTreeLBEntry *e;
00370    TGTextLBEntry *te;
00371    TGFileItem *f;
00372    void *p = 0;
00373    TString txt;
00374    TString sdir = gSystem->WorkingDirectory();
00375 
00376    switch (GET_MSG(msg)) {
00377       case kC_COMMAND:
00378          switch (GET_SUBMSG(msg)) {
00379             case kCM_BUTTON:
00380                switch (parm1) {
00381                   case kIDF_OK:
00382                      // same code as under kTE_ENTER
00383                      if (fTbfname->GetTextLength() == 0) {
00384                         txt = "Please provide file name or use \"Cancel\"";
00385                         new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00386                                      "Missing File Name", txt, kMBIconExclamation,
00387                                      kMBOk);
00388                         return kTRUE;
00389                      } else if (!gSystem->AccessPathName(fTbfname->GetString(), kFileExists) &&
00390                                 !strcmp(fOk->GetTitle(), "Save") &&
00391                                 (!(fCheckB->GetState() == kButtonDown))) {
00392                         Int_t ret;
00393                         txt = TString::Format("File name %s already exists, OK to overwrite it?",
00394                                               fTbfname->GetString());
00395                         new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00396                                      "File Name Exist", txt.Data(), kMBIconExclamation,
00397                                      kMBYes | kMBNo, &ret);
00398                         if (ret == kMBNo)
00399                            return kTRUE;
00400                      }
00401                      if (fFileInfo->fMultipleSelection) {
00402                         if (fFileInfo->fFilename)
00403                            delete [] fFileInfo->fFilename;
00404                         fFileInfo->fFilename = 0;
00405                      }
00406                      else {
00407                         if (fFileInfo->fFilename)
00408                            delete [] fFileInfo->fFilename;
00409                         if (gSystem->IsAbsoluteFileName(fTbfname->GetString()))
00410                            fFileInfo->fFilename = StrDup(fTbfname->GetString());
00411                         else
00412                            fFileInfo->fFilename = gSystem->ConcatFileName(fFc->GetDirectory(),
00413                                                                           fTbfname->GetString());
00414                         fFileInfo->fFilename = StrDup(gSystem->UnixPathName(fFileInfo->fFilename));
00415                      }
00416                      if (fCheckB && (fCheckB->GetState() == kButtonDown))
00417                         fFileInfo->fOverwrite = kTRUE;
00418                      else
00419                         fFileInfo->fOverwrite = kFALSE;
00420                      DeleteWindow();
00421                      break;
00422 
00423                   case kIDF_CANCEL:
00424                      if (fFileInfo->fFilename)
00425                         delete [] fFileInfo->fFilename;
00426                      fFileInfo->fFilename = 0;
00427                      if (fFc->GetDisplayStat()) 
00428                         fFc->SetDisplayStat(kFALSE);
00429                      if (fFileInfo->fFileNamesList != 0) {
00430                         fFileInfo->fFileNamesList->Delete();
00431                         fFileInfo->fFileNamesList = 0;
00432                      }
00433                      DeleteWindow();
00434                      return kTRUE;   //no need to redraw fFc
00435                      break;
00436 
00437                   case kIDF_CDUP:
00438                      fFc->ChangeDirectory("..");
00439                      fTreeLB->Update(fFc->GetDirectory());
00440                      if (fFileInfo->fIniDir) delete [] fFileInfo->fIniDir;
00441                      fFileInfo->fIniDir = StrDup(fFc->GetDirectory());
00442                      if (strcmp(gSystem->WorkingDirectory(),fFc->GetDirectory())) {
00443                         gSystem->cd(fFc->GetDirectory());
00444                      }
00445                      break;
00446 
00447                   case kIDF_NEW_FOLDER: {
00448                      char answer[128];
00449                      strlcpy(answer, "(empty)", sizeof(answer));
00450                      new TGInputDialog(gClient->GetRoot(), GetMainFrame(),
00451                                        "Enter directory name:",
00452                                        answer/*"(empty)"*/, answer);
00453 
00454                      while ( strcmp(answer, "(empty)") == 0 ) {
00455                         new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
00456                                      "Please enter a valid directory name.",
00457                                      kMBIconStop, kMBOk);
00458                         new TGInputDialog(gClient->GetRoot(), GetMainFrame(),
00459                                           "Enter directory name:",
00460                                           answer, answer);
00461                      }
00462                      if ( strcmp(answer, "") == 0 )  // Cancel button was pressed
00463                         break;
00464                      
00465                      if (strcmp(gSystem->WorkingDirectory(),fFc->GetDirectory())) {
00466                         gSystem->cd(fFc->GetDirectory());
00467                      }
00468                      if ( gSystem->MakeDirectory(answer) != 0 )
00469                         new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
00470                                      TString::Format("Directory name \'%s\' already exists!", answer),
00471                                      kMBIconStop, kMBOk);
00472                      else {
00473                         fFc->DisplayDirectory();
00474                      }
00475                      gSystem->ChangeDirectory(sdir.Data());
00476                      break;
00477                   }
00478 
00479                   case kIDF_LIST:
00480                      fFv->SetViewMode(kLVList);
00481                      fDetails->SetState(kButtonUp);
00482                      break;
00483 
00484                   case kIDF_DETAILS:
00485                      fFv->SetViewMode(kLVDetails);
00486                      fList->SetState(kButtonUp);
00487                      break;
00488                }
00489                break;
00490 
00491             case kCM_COMBOBOX:
00492                switch (parm1) {
00493                   case kIDF_FSLB:
00494                      e = (TGTreeLBEntry *) fTreeLB->GetSelectedEntry();
00495                      if (e) {
00496                         fFc->ChangeDirectory(e->GetPath()->GetString());
00497                         fTreeLB->Update(fFc->GetDirectory());
00498                         if (fFileInfo->fIniDir) delete [] fFileInfo->fIniDir;
00499                         fFileInfo->fIniDir = StrDup(fFc->GetDirectory());
00500                         if (strcmp(gSystem->WorkingDirectory(),fFc->GetDirectory())) {
00501                            gSystem->cd(fFc->GetDirectory());
00502                         }
00503                      }
00504                      break;
00505 
00506                   case kIDF_FTYPESLB:
00507                      te = (TGTextLBEntry *) fTypes->GetSelectedEntry();
00508                      if (te) {
00509                         //fTbfname->Clear();
00510                         //fTbfname->AddText(0, fFileInfo->fFileTypes[te->EntryId()+1]);
00511                         fFileInfo->fFileTypeIdx = te->EntryId();
00512                         fFc->SetFilter(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx+1]);
00513                         fFc->DisplayDirectory();
00514                         fClient->NeedRedraw(fName);
00515                      }
00516                      break;
00517                }
00518                break;
00519 
00520             default:
00521                break;
00522          } // switch(GET_SUBMSG(msg))
00523          break;
00524 
00525       case kC_CONTAINER:
00526          switch (GET_SUBMSG(msg)) {
00527             case kCT_ITEMCLICK:
00528                if (parm1 == kButton1) {
00529                   if (fFc->NumSelected() > 0) {
00530                      if ( fFileInfo->fMultipleSelection == kFALSE ) {
00531                         TGLVEntry *e2 = (TGLVEntry *) fFc->GetNextSelected(&p);
00532                         fTbfname->Clear();
00533                         fTbfname->AddText(0, e2->GetItemName()->GetString());
00534                         fClient->NeedRedraw(fName);
00535                      }
00536                      else {
00537                         TString tmpString;
00538                         TList *tmp = fFc->GetSelectedItems();
00539                         TObjString *el;
00540                         TIter next(tmp);
00541                         if ( fFileInfo->fFileNamesList != 0 ) {
00542                            fFileInfo->fFileNamesList->Delete();
00543                         }
00544                         else {
00545                            fFileInfo->fFileNamesList = new TList();
00546                         }
00547                         while ((el = (TObjString *) next())) {
00548                            char *s = gSystem->ConcatFileName(fFc->GetDirectory(),
00549                                                              el->GetString());
00550                            tmpString += "\"" + el->GetString() + "\" ";
00551                            fFileInfo->fFileNamesList->Add(new TObjString(s));
00552                            delete [] s;
00553                         }
00554                         fTbfname->Clear();
00555                         fTbfname->AddText(0, tmpString);
00556                         fClient->NeedRedraw(fName);
00557                      }
00558                   }
00559                }
00560                break;
00561 
00562             case kCT_ITEMDBLCLICK:
00563 
00564                if (parm1 == kButton1) {
00565                   if (fFc->NumSelected() == 1) {
00566                      f = (TGFileItem *) fFc->GetNextSelected(&p);
00567                      if (R_ISDIR(f->GetType())) {
00568                         fFc->ChangeDirectory(f->GetItemName()->GetString());
00569                         fTreeLB->Update(fFc->GetDirectory());
00570                         if (fFileInfo->fIniDir) delete [] fFileInfo->fIniDir;
00571                         fFileInfo->fIniDir = StrDup(fFc->GetDirectory());
00572                         if (strcmp(gSystem->WorkingDirectory(),fFc->GetDirectory())) {
00573                            gSystem->cd(fFc->GetDirectory());
00574                         }
00575                      } else {
00576                         if (!strcmp(fOk->GetTitle(), "Save") &&
00577                             (!(fCheckB->GetState() == kButtonDown))) {
00578 
00579                            Int_t ret;
00580                            txt = TString::Format("File name %s already exists, OK to overwrite it?",
00581                                                  fTbfname->GetString());
00582                            new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00583                                         "File Name Exist", txt.Data(), kMBIconExclamation,
00584                                         kMBYes | kMBNo, &ret);
00585                            if (ret == kMBNo)
00586                               return kTRUE;
00587                         }
00588                         if (fFileInfo->fFilename)
00589                            delete [] fFileInfo->fFilename;
00590                         if (gSystem->IsAbsoluteFileName(fTbfname->GetString()))
00591                            fFileInfo->fFilename = StrDup(fTbfname->GetString());
00592                         else
00593                            fFileInfo->fFilename = gSystem->ConcatFileName(fFc->GetDirectory(),
00594                                                                           fTbfname->GetString());
00595                         fFileInfo->fFilename = StrDup(gSystem->UnixPathName(fFileInfo->fFilename));
00596                         if (fCheckB && (fCheckB->GetState() == kButtonDown))
00597                            fFileInfo->fOverwrite = kTRUE;
00598                         else
00599                            fFileInfo->fOverwrite = kFALSE;
00600 
00601                         DeleteWindow();
00602                      }
00603                   }
00604                }
00605 
00606                break;
00607 
00608             default:
00609                break;
00610 
00611          } // switch(GET_SUBMSG(msg))
00612          break;
00613 
00614       case kC_TEXTENTRY:
00615          switch (GET_SUBMSG(msg)) {
00616             case kTE_ENTER:
00617                // same code as under kIDF_OK
00618                if (fTbfname->GetTextLength() == 0) {
00619                   const char *txt2 = "Please provide file name or use \"Cancel\"";
00620                   new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00621                                "Missing File Name", txt2, kMBIconExclamation,
00622                                kMBOk);
00623                   return kTRUE;
00624                } else if (!gSystem->AccessPathName(fTbfname->GetString(), kFileExists)) {
00625                   FileStat_t buf;
00626                   gSystem->GetPathInfo(fTbfname->GetString(), buf);
00627                   if (R_ISDIR(buf.fMode)) {
00628                      fFc->ChangeDirectory(fTbfname->GetString());
00629                      fTreeLB->Update(fFc->GetDirectory());
00630                      if (strcmp(gSystem->WorkingDirectory(), fFc->GetDirectory())) {
00631                         gSystem->cd(fFc->GetDirectory());
00632                      }
00633                      fName->SetText("", kFALSE);
00634                      return kTRUE;
00635                   }
00636                   else if (!strcmp(fOk->GetTitle(), "Save") && 
00637                           (!(fCheckB->GetState() == kButtonDown))) {
00638                      Int_t ret;
00639                      txt = TString::Format("File name %s already exists, OK to overwrite it?",
00640                                            fTbfname->GetString());
00641                      new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00642                                   "File Name Exist", txt.Data(), kMBIconExclamation,
00643                                   kMBYes | kMBNo, &ret);
00644                      if (ret == kMBNo)
00645                         return kTRUE;
00646                   }
00647                }
00648                if (fFileInfo->fFilename)
00649                   delete [] fFileInfo->fFilename;
00650                fFileInfo->fFilename = gSystem->ConcatFileName(fFc->GetDirectory(),
00651                                                               fTbfname->GetString());
00652                fFileInfo->fFilename = StrDup(gSystem->UnixPathName(fFileInfo->fFilename));
00653                if (fCheckB && (fCheckB->GetState() == kButtonDown))
00654                   fFileInfo->fOverwrite = kTRUE;
00655                else
00656                   fFileInfo->fOverwrite = kFALSE;
00657                DeleteWindow();
00658                break;
00659 
00660             default:
00661                break;
00662          }
00663          break;
00664 
00665       default:
00666          break;
00667 
00668    } // switch(GET_MSG(msg))
00669 
00670    fClient->NeedRedraw(fFc);
00671    return kTRUE;
00672 }

Generated on Tue Jul 5 14:21:58 2011 for ROOT_528-00b_version by  doxygen 1.5.1