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
4/*************************************************************************
5 * Copyright (C) 1995-2019, 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#ifndef ROOT7_RFileDialog
13#define ROOT7_RFileDialog
14
15#include <ROOT/RWebWindow.hxx>
16#include <ROOT/RBrowserData.hxx>
17
18#include <vector>
19#include <memory>
20#include <stdint.h>
21
22namespace ROOT {
23
24namespace Details {
25 class RWebWindowPlugin;
26}
27
28/** \class ROOT::RFileDialog
29\ingroup rbrowser
30Initial message send to client to configure layout
31*/
32
33/// function signature for file dialog call-backs
34/// argument is selected file name
35using RFileDialogCallback_t = std::function<void(const std::string &)>;
36
37
38/** Web-based FileDialog */
39
42public:
43
49
50protected:
51
52 EDialogTypes fKind{kOpenFile}; ///<! dialog kind OpenFile, SaveAs, NewFile
53 std::string fTitle; ///<! title, when not specified default will be used
54 RBrowserData fBrowsable; ///<! central browsing element
55 bool fCanChangePath{true}; ///<! if working path can be changed via gui elements
56
57 std::shared_ptr<RWebWindow> fWebWindow; ///<! web window for file dialog
58
59 bool fDidSelect{false}; ///<! true when dialog is selected or closed
60 std::string fSelectedFilter; ///<! name of selected filter
61 std::vector<std::string> fNameFilters; ///<! name filters
62 std::string fSelect; ///<! result of file selection
63 RFileDialogCallback_t fCallback; ///<! function receiving result, called once
64
65 static std::string TypeAsString(EDialogTypes kind);
66
67 void SendInitMsg(unsigned connid);
68 void SendChPathMsg(unsigned connid);
69
70 void ProcessMsg(unsigned connid, const std::string &arg);
71
72 void InvokeCallBack();
73
74 std::string GetRegexp(const std::string &name) const;
75
76 static std::string Dialog(EDialogTypes kind, const std::string &title, const std::string &fname);
77
78 static void SetStartFunc(bool on);
79
80public:
81
82 RFileDialog(EDialogTypes kind = kOpenFile, const std::string &title = "", const std::string &fname = "");
83 virtual ~RFileDialog();
84
85 const EDialogTypes &GetType() const { return fKind; }
86
88
89 /** Set array of name filters like "Text files (*.txt)", "Any files (*)", "Image files (*png *.jpg)"
90 * Should be specified before starting dialog */
91 void SetNameFilters(const std::vector<std::string> &arr) { fNameFilters = arr; }
92 /** Returns array of name filters*/
93 const auto &GetNameFilters() const { return fNameFilters; }
94
95 /** Configure if working path in dialog can be changed via gui elements */
96 void SetCanChangePath(bool on = true) { fCanChangePath = on; }
97
98 /** Returns true if working path can be change with gui elements */
99 bool GetCanChangePath() const { return fCanChangePath; }
100
101 void SetWorkingPath(const std::string &);
102 std::string GetWorkingPath() const;
103
104 void SetSelectedFilter(const std::string &name);
105 std::string GetSelectedFilter() const;
106
107 void Show(const RWebDisplayArgs &args = "");
108 void Hide();
109
110 bool IsCompleted() const { return fDidSelect; }
111 const std::string &GetFileName() const { return fSelect; }
112
113 static std::string OpenFile(const std::string &title = "", const std::string &fname = "");
114 static std::string SaveAs(const std::string &title = "", const std::string &fname = "");
115 static std::string NewFile(const std::string &title = "", const std::string &fname = "");
116
117 static std::shared_ptr<RFileDialog> Embed(const std::shared_ptr<RWebWindow> &window, unsigned connid, const std::string &args);
118
119 static bool IsMessageToStartDialog(const std::string &msg);
120
121};
122
123} // namespace ROOT
124
125#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Definition TGX11.cxx:110
Way to browse (hopefully) everything in ROOT.
Web-based FileDialog.
std::vector< std::string > fNameFilters
! name filters
static void SetStartFunc(bool on)
Set start dialog function for RWebWindow.
const auto & GetNameFilters() const
Returns array of name filters.
static std::string Dialog(EDialogTypes kind, const std::string &title, const std::string &fname)
Start specified dialog type.
std::shared_ptr< RWebWindow > fWebWindow
! web window for file dialog
EDialogTypes fKind
! dialog kind OpenFile, SaveAs, NewFile
const std::string & GetFileName() const
bool GetCanChangePath() const
Returns true if working path can be change with gui elements.
RFileDialogCallback_t fCallback
! function receiving result, called once
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.
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...
friend class Details::RWebWindowPlugin
void SetNameFilters(const std::vector< std::string > &arr)
Set array of name filters like "Text files (*.txt)", "Any files (*)", "Image files (*png *....
void ProcessMsg(unsigned connid, const std::string &arg)
Process received data from client.
bool fCanChangePath
! if working path can be changed via gui elements
bool fDidSelect
! true when dialog is selected or closed
static std::string OpenFile(const std::string &title="", const std::string &fname="")
Start OpenFile dialog.
void Hide()
Hide ROOT Browser.
std::string GetRegexp(const std::string &name) const
Returns regexp for selected filter String should have form "Filter name (*.ext1 *....
std::string fSelectedFilter
! name of selected filter
void SetCanChangePath(bool on=true)
Configure if working path in dialog can be changed via gui elements.
void SendChPathMsg(unsigned connid)
Sends new data after change current directory.
static bool IsMessageToStartDialog(const std::string &msg)
Check if this could be the message send by client to start new file dialog If returns true,...
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.
RFileDialog(EDialogTypes kind=kOpenFile, const std::string &title="", const std::string &fname="")
constructor When title not specified, default will be used
static std::shared_ptr< RFileDialog > Embed(const std::shared_ptr< RWebWindow > &window, unsigned connid, const std::string &args)
Create dialog instance to use as embedded dialog inside other widget Embedded dialog started on the c...
void SetCallback(RFileDialogCallback_t callback)
Assign callback.
RBrowserData fBrowsable
! central browsing element
std::string fTitle
! title, when not specified default will be used
bool IsCompleted() const
void SendInitMsg(unsigned connid)
Sends initial message to the client.
const EDialogTypes & GetType() const
void SetWorkingPath(const std::string &)
Change current working path of file dialog If dialog already shown, change will be immediately applie...
virtual ~RFileDialog()
destructor
std::string fSelect
! result of file selection
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
std::function< void(const std::string &)> RFileDialogCallback_t
function signature for file dialog call-backs argument is selected file name