Logo ROOT  
Reference Guide
filedialog.cxx File Reference

Detailed Description

/*************************************************************************
* Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
// Show how RFileDialog can be used in sync and async modes
// Normally file dialogs will be used inside other widgets as ui5 dialogs
// By default, dialog starts in async mode - means macro immediately returns to command line
// To start OpenFile dialog in sync mode, call `root "filedialog.cxx(1)" -q`.
// Once file is selected, root execution will be stopped
// macro must be here to let macro work on Windows
R__LOAD_LIBRARY(libROOTBrowserv7)
#include <ROOT/RFileDialog.hxx>
using namespace ROOT::Experimental;
void filedialog(int kind = 0)
{
std::string fileName;
// example of sync methods, blocks until name is selected
switch (kind) {
case 1: fileName = RFileDialog::OpenFile("OpenFile title"); break;
case 2: fileName = RFileDialog::SaveAs("SaveAs title", "newfile.xml"); break;
case 3: fileName = RFileDialog::NewFile("NewFile title", "test.txt"); break;
}
if (kind > 0) {
printf("Selected file: %s\n", fileName.c_str());
return;
}
auto dialog = std::make_shared<RFileDialog>(RFileDialog::kOpenFile, "OpenFile dialog in async mode");
dialog->SetNameFilters({ "C++ files (*.cxx *.cpp *.c *.C)", "Image files (*.png *.jpg *.jpeg)", "Text files (*.txt)", "Any files (*)" });
dialog->SetSelectedFilter("C++ files");
// use dialog capture to keep reference until file name is selected
dialog->SetCallback([dialog](const std::string &res) mutable {
printf("Selected file: %s\n", res.c_str());
// cleanup dialog - actually not needed, lambda is cleaned up after that call anyway
// dialog.reset();
});
dialog->Show();
}
Date
2019-11-01
Warning
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Author
Sergey Linev S.Lin.nosp@m.ev@g.nosp@m.si.de

Definition in file filedialog.cxx.

ROOT::Experimental::RFileDialog::kOpenFile
@ kOpenFile
Definition: RFileDialog.hxx:42
ROOT::Experimental::RFileDialog::OpenFile
static std::string OpenFile(const std::string &title="", const std::string &fname="")
Start OpenFile dialog.
Definition: RFileDialog.cxx:365
ROOT::Experimental::RFileDialog::NewFile
static std::string NewFile(const std::string &title="", const std::string &fname="")
Start NewFile dialog.
Definition: RFileDialog.cxx:385
ROOT::Experimental::RFileDialog::SaveAs
static std::string SaveAs(const std::string &title="", const std::string &fname="")
Start SaveAs dialog.
Definition: RFileDialog.cxx:375
ROOT::Experimental
Definition: RDirectory.hxx:30
R__LOAD_LIBRARY
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:472