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 {
24
25namespace Details {
26 class RWebWindowPlugin;
27}
28
29/** \class ROOT::RFileDialog
30\ingroup rbrowser
31Initial message send to client to configure layout
32*/
33
34/// function signature for file dialog call-backs
35/// argument is selected file name
36using RFileDialogCallback_t = std::function<void(const std::string &)>;
37
38
39/** Web-based FileDialog */
40
43public:
44
49 };
50
51protected:
52
53 EDialogTypes fKind{kOpenFile}; ///<! dialog kind OpenFile, SaveAs, NewFile
54 std::string fTitle; ///<! title, when not specified default will be used
55 RBrowserData fBrowsable; ///<! central browsing element
56 bool fCanChangePath{true}; ///<! if working path can be changed via gui elements
57
58 std::shared_ptr<RWebWindow> fWebWindow; ///<! web window for file dialog
59
60 bool fDidSelect{false}; ///<! true when dialog is selected or closed
61 std::string fSelectedFilter; ///<! name of selected filter
62 std::vector<std::string> fNameFilters; ///<! name filters
63 std::string fSelect; ///<! result of file selection
64 RFileDialogCallback_t fCallback; ///<! function receiving result, called once
65
66 static std::string TypeAsString(EDialogTypes kind);
67
68 void SendInitMsg(unsigned connid);
69 void SendChPathMsg(unsigned connid);
70
71 void ProcessMsg(unsigned connid, const std::string &arg);
72
73 void InvokeCallBack();
74
75 std::string GetRegexp(const std::string &name) const;
76
77 static std::string Dialog(EDialogTypes kind, const std::string &title, const std::string &fname);
78
79 static void SetStartFunc(bool on);
80
81public:
82
83 RFileDialog(EDialogTypes kind = kOpenFile, const std::string &title = "", const std::string &fname = "");
84 virtual ~RFileDialog();
85
86 const EDialogTypes &GetType() const { return fKind; }
87
89
90 /** Set array of name filters like "Text files (*.txt)", "Any files (*)", "Image files (*png *.jpg)"
91 * Should be specified before starting dialog */
92 void SetNameFilters(const std::vector<std::string> &arr) { fNameFilters = arr; }
93 /** Returns array of name filters*/
94 const auto &GetNameFilters() const { return fNameFilters; }
95
96 /** Configure if working path in dialog can be changed via gui elements */
97 void SetCanChangePath(bool on = true) { fCanChangePath = on; }
98
99 /** Returns true if working path can be change with gui elements */
100 bool GetCanChangePath() const { return fCanChangePath; }
101
102 void SetWorkingPath(const std::string &);
103 std::string GetWorkingPath() const;
104
105 void SetSelectedFilter(const std::string &name);
106 std::string GetSelectedFilter() const;
107
108 void Show(const RWebDisplayArgs &args = "");
109 void Hide();
110
111 bool IsCompleted() const { return fDidSelect; }
112 const std::string &GetFileName() const { return fSelect; }
113
114 static std::string OpenFile(const std::string &title = "", const std::string &fname = "");
115 static std::string SaveAs(const std::string &title = "", const std::string &fname = "");
116 static std::string NewFile(const std::string &title = "", const std::string &fname = "");
117
118 static std::shared_ptr<RFileDialog> Embed(const std::shared_ptr<RWebWindow> &window, unsigned connid, const std::string &args);
119
120 static bool IsMessageToStartDialog(const std::string &msg);
121
122};
123
124} // namespace ROOT
125
126#endif
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.
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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
std::function< void(const std::string &)> RFileDialogCallback_t
function signature for file dialog call-backs argument is selected file name