Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:43

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