Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:58

0001 // Author: Sergey Linev <S.Linev@gsi.de>
0002 // Date: 2019-10-31
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT7_RFileDialog
0013 #define ROOT7_RFileDialog
0014 
0015 #include <ROOT/RWebWindow.hxx>
0016 #include <ROOT/RBrowserData.hxx>
0017 
0018 #include <vector>
0019 #include <memory>
0020 #include <cstdint>
0021 
0022 namespace ROOT {
0023 
0024 namespace Details {
0025    class RWebWindowPlugin;
0026 }
0027 
0028 /** \class ROOT::RFileDialog
0029 \ingroup rbrowser
0030 Initial message send to client to configure layout
0031 */
0032 
0033 /// function signature for file dialog call-backs
0034 /// argument is selected file name
0035 using RFileDialogCallback_t = std::function<void(const std::string &)>;
0036 
0037 
0038 /** Web-based FileDialog */
0039 
0040 class RFileDialog {
0041    friend class Details::RWebWindowPlugin;
0042 public:
0043 
0044    enum EDialogTypes {
0045       kOpenFile,
0046       kSaveAs,
0047       kNewFile
0048    };
0049 
0050 protected:
0051 
0052    EDialogTypes fKind{kOpenFile};      ///<! dialog kind OpenFile, SaveAs, NewFile
0053    std::string fTitle;                 ///<! title, when not specified default will be used
0054    RBrowserData fBrowsable;            ///<! central browsing element
0055    bool fCanChangePath{true};          ///<! if working path can be changed via gui elements
0056 
0057    std::shared_ptr<RWebWindow> fWebWindow;   ///<! web window for file dialog
0058 
0059    bool fDidSelect{false};                ///<! true when dialog is selected or closed
0060    std::string fSelectedFilter;           ///<! name of selected filter
0061    std::vector<std::string> fNameFilters; ///<! name filters
0062    std::string fSelect;                   ///<! result of file selection
0063    RFileDialogCallback_t fCallback;       ///<! function receiving result, called once
0064 
0065    static std::string TypeAsString(EDialogTypes kind);
0066 
0067    void SendInitMsg(unsigned connid);
0068    void SendChPathMsg(unsigned connid);
0069 
0070    void ProcessMsg(unsigned connid, const std::string &arg);
0071 
0072    void InvokeCallBack();
0073 
0074    std::string GetRegexp(const std::string &name) const;
0075 
0076    static std::string Dialog(EDialogTypes kind, const std::string &title, const std::string &fname);
0077 
0078    static void SetStartFunc(bool on);
0079 
0080 public:
0081 
0082    RFileDialog(EDialogTypes kind = kOpenFile, const std::string &title = "", const std::string &fname = "");
0083    virtual ~RFileDialog();
0084 
0085    const EDialogTypes &GetType() const { return fKind; }
0086 
0087    void SetCallback(RFileDialogCallback_t callback);
0088 
0089    /** Set array of name filters like "Text files (*.txt)", "Any files (*)", "Image files (*png *.jpg)"
0090     * Should be specified before starting dialog */
0091    void SetNameFilters(const std::vector<std::string> &arr) { fNameFilters = arr; }
0092    /** Returns array of name filters*/
0093    const auto &GetNameFilters() const { return fNameFilters; }
0094 
0095    /** Configure if working path in dialog can be changed via gui elements */
0096    void SetCanChangePath(bool on = true) { fCanChangePath = on; }
0097 
0098    /** Returns true if working path can be change with gui elements */
0099    bool GetCanChangePath() const { return fCanChangePath; }
0100 
0101    void SetWorkingPath(const std::string &);
0102    std::string GetWorkingPath() const;
0103 
0104    void SetSelectedFilter(const std::string &name);
0105    std::string GetSelectedFilter() const;
0106 
0107    void Show(const RWebDisplayArgs &args = "");
0108    void Hide();
0109 
0110    bool IsCompleted() const { return fDidSelect; }
0111    const std::string &GetFileName() const { return fSelect; }
0112 
0113    static std::string OpenFile(const std::string &title = "", const std::string &fname = "");
0114    static std::string SaveAs(const std::string &title = "", const std::string &fname = "");
0115    static std::string NewFile(const std::string &title = "", const std::string &fname = "");
0116 
0117    static std::shared_ptr<RFileDialog> Embed(const std::shared_ptr<RWebWindow> &window, unsigned connid, const std::string &args);
0118 
0119    static bool IsMessageToStartDialog(const std::string &msg);
0120 
0121 };
0122 
0123 } // namespace ROOT
0124 
0125 #endif