Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFileDialog.hxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2019-10-31
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT7_RFileDialog
14#define ROOT7_RFileDialog
15
16#include <ROOT/RWebWindow.hxx>
17#include <ROOT/RBrowserData.hxx>
18
19#include <vector>
20#include <memory>
21#include <stdint.h>
22
23namespace ROOT {
24namespace Experimental {
25
26/** \class ROOT::Experimental::RFileDialog
27\ingroup rbrowser
28Initial message send to client to configure layout
29*/
30
31/// function signature for file dialog call-backs
32/// argument is selected file name
33using RFileDialogCallback_t = std::function<void(const std::string &)>;
34
35
36/** Web-based FileDialog */
37
39public:
40
45 };
46
47protected:
48
49 EDialogTypes fKind{kOpenFile}; ///<! dialog kind OpenFile, SaveAs, NewFile
50 std::string fTitle; ///<! title, when not specified default will be used
51 RBrowserData fBrowsable; ///<! central browsing element
52 bool fCanChangePath{true}; ///<! if working path can be changed via gui elements
53
54 std::shared_ptr<RWebWindow> fWebWindow; ///<! web window for file dialog
55
56 bool fDidSelect{false}; ///<! true when dialog is selected or closed
57 std::string fSelectedFilter; ///<! name of selected filter
58 std::vector<std::string> fNameFilters; ///<! name filters
59 std::string fSelect; ///<! result of file selection
60 RFileDialogCallback_t fCallback; ///<! function receiving result, called once
61
62 static std::string TypeAsString(EDialogTypes kind);
63
64 void SendInitMsg(unsigned connid);
65 void SendChPathMsg(unsigned connid);
66
67 void ProcessMsg(unsigned connid, const std::string &arg);
68
69 void InvokeCallBack();
70
71 std::string GetRegexp(const std::string &name) const;
72
73 static std::string Dialog(EDialogTypes kind, const std::string &title, const std::string &fname);
74
75public:
76
77 RFileDialog(EDialogTypes kind = kOpenFile, const std::string &title = "", const std::string &fname = "");
78 virtual ~RFileDialog();
79
80 const EDialogTypes &GetType() const { return fKind; }
81
83
84 /** Set array of name filters like "Text files (*.txt)", "Any files (*)", "Image files (*png *.jpg)"
85 * Should be specified before starting dialog */
86 void SetNameFilters(const std::vector<std::string> &arr) { fNameFilters = arr; }
87 /** Returns array of name filters*/
88 const auto &GetNameFilters() const { return fNameFilters; }
89
90 /** Configure if working path in dialog can be changed via gui elements */
91 void SetCanChangePath(bool on = true) { fCanChangePath = on; }
92
93 /** Returns true if working path can be change with gui elements */
94 bool GetCanChangePath() const { return fCanChangePath; }
95
96 void SetWorkingPath(const std::string &);
97 std::string GetWorkingPath() const;
98
99 void SetSelectedFilter(const std::string &name);
100 std::string GetSelectedFilter() const;
101
102 void Show(const RWebDisplayArgs &args = "");
103 void Hide();
104
105 bool IsCompleted() const { return fDidSelect; }
106 const std::string &GetFileName() const { return fSelect; }
107
108 static std::string OpenFile(const std::string &title = "", const std::string &fname = "");
109 static std::string SaveAs(const std::string &title = "", const std::string &fname = "");
110 static std::string NewFile(const std::string &title = "", const std::string &fname = "");
111
112 static std::shared_ptr<RFileDialog> Embedded(const std::shared_ptr<RWebWindow> &window, const std::string &args);
113
114};
115
116} // namespace Experimental
117} // namespace ROOT
118
119#endif
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
char name[80]
Definition TGX11.cxx:110
Way to browse (hopefully) everything in ROOT.
const auto & GetNameFilters() const
Returns array of name filters.
std::vector< std::string > fNameFilters
! name filters
static std::string Dialog(EDialogTypes kind, const std::string &title, const std::string &fname)
Start specified dialog type.
EDialogTypes fKind
! dialog kind OpenFile, SaveAs, NewFile
void SetNameFilters(const std::vector< std::string > &arr)
Set array of name filters like "Text files (*.txt)", "Any files (*)", "Image files (*png *....
bool GetCanChangePath() const
Returns true if working path can be change with gui elements.
bool fDidSelect
! true when dialog is selected or closed
void Show(const RWebDisplayArgs &args="")
Show or update RFileDialog in web window If web window already started - just refresh it like "reload...
void InvokeCallBack()
Invoke specified callback.
std::shared_ptr< RWebWindow > fWebWindow
! web window for file dialog
static std::string SaveAs(const std::string &title="", const std::string &fname="")
Start SaveAs dialog.
std::string GetSelectedFilter() const
Returns selected filter Can differ from specified value - if it does not match to existing entry in N...
const EDialogTypes & GetType() const
RBrowserData fBrowsable
! central browsing element
bool fCanChangePath
! if working path can be changed via gui elements
void ProcessMsg(unsigned connid, const std::string &arg)
Process received data from client.
void SetCanChangePath(bool on=true)
Configure if working path in dialog can be changed via gui elements.
static std::shared_ptr< RFileDialog > Embedded(const std::shared_ptr< RWebWindow > &window, const std::string &args)
Create dialog instance to use as embedded dialog inside other widget Embedded dialog started on the c...
static std::string OpenFile(const std::string &title="", const std::string &fname="")
Start OpenFile dialog.
std::string fSelectedFilter
! name of selected filter
const std::string & GetFileName() const
void Hide()
Hide ROOT Browser.
std::string fSelect
! result of file selection
std::string GetRegexp(const std::string &name) const
Returns regexp for selected filter String should have form "Filter name (*.ext1 *....
void SendChPathMsg(unsigned connid)
Sends new data after change current directory.
std::string fTitle
! title, when not specified default will be used
RFileDialogCallback_t fCallback
! function receiving result, called once
std::string GetWorkingPath() const
Returns current working path.
static std::string TypeAsString(EDialogTypes kind)
Returns dialog type as string String value used for configuring JS-side.
static std::string NewFile(const std::string &title="", const std::string &fname="")
Start NewFile dialog.
void SetSelectedFilter(const std::string &name)
Configure selected filter Has to be one of the string from NameFilters entry.
void SetCallback(RFileDialogCallback_t callback)
Assign callback.
void SendInitMsg(unsigned connid)
Sends initial message to the client.
void SetWorkingPath(const std::string &)
Change current working path of file dialog If dialog already shown, change will be immediately applie...
virtual ~RFileDialog()
destructor
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
std::function< void(const std::string &)> RFileDialogCallback_t
function signature for file dialog call-backs argument is selected file name
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...