31using namespace std::string_literals;
57 auto separ =
fSelect.rfind(
"/");
58 if (separ == std::string::npos)
63 if (separ != std::string::npos) {
64 workdir =
fSelect.substr(0, separ);
68 auto comp = std::make_shared<Browsable::RGroup>(
"top",
"Top file dialog element");
76 fWebWindow->SetPanelName(
"rootui5.browser.view.FileDialog");
80 [
this](
unsigned connid,
const std::string &arg) {
ProcessMsg(connid, arg); },
140 case kSaveAs:
return "SaveAs"s;
165 std::string lastname, allname;
168 auto pp = entry.find(
" (");
169 if (pp == std::string::npos)
continue;
170 auto name = entry.substr(0, pp);
181 if (!allname.empty())
return allname;
182 if (!lastname.empty())
return lastname;
195 if (entry.compare(0, fname.length(), fname) == 0) {
196 auto pp = entry.find(
"(", fname.length());
200 while (pp != std::string::npos) {
201 pp = entry.find(
"*.", pp);
202 if (pp == std::string::npos)
break;
204 auto pp2 = entry.find_first_of(
" )", pp+2);
205 if (pp2 == std::string::npos)
break;
207 if (res.empty()) res =
"^(.*\\.(";
208 else res.append(
"|");
210 res.append(entry.substr(pp+2, pp2 - pp - 2));
215 if (!res.empty()) res.append(
")$)");
233 req.
sort =
"alphabetical";
243 "\"title\" : "s + jtitle.Data() +
","s +
244 "\"path\" : "s + jpath.Data() +
","s +
245 "\"can_change_path\" : "s + (
GetCanChangePath() ?
"true"s :
"false"s) +
","s +
246 "\"filter\" : "s + jfilter.Data() +
","s +
247 "\"filters\" : "s + jfilters.Data() +
","s +
248 "\"fname\" : "s + jfname.Data() +
","s +
258 req.
sort =
"alphabetical";
263 fWebWindow->Send(connid,
"CHMSG:{\"path\" : "s + jpath.Data() +
272 if (arg.compare(0, 7,
"CHPATH:") == 0) {
274 auto path = TBufferJSON::FromJSON<Browsable::RElementPath_t>(arg.substr(7));
280 }
else if (arg.compare(0, 6,
"CHEXT:") == 0) {
286 }
else if (arg.compare(0, 10,
"DLGSELECT:") == 0) {
289 auto path = TBufferJSON::FromJSON<Browsable::RElementPath_t>(arg.substr(10));
299 fSelect = elem->GetContent(
"filename");
303 bool need_confirm =
false;
309 std::string fname = path->back();
313 fSelect = direlem->GetContent(
"filename") +
"/"s + fname;
323 }
else if (arg ==
"DLGNOSELECT") {
326 fWebWindow->Send(connid,
"NOSELECT_CONFIRMED"s);
327 }
else if (arg ==
"DLG_CONFIRM_SELECT") {
427std::shared_ptr<RFileDialog>
RFileDialog::Embedded(
const std::shared_ptr<RWebWindow> &window,
const std::string &args)
429 if (args.compare(0, 11,
"FILEDIALOG:") != 0)
432 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(args.substr(11));
434 if (!arr || (arr->size() < 3)) {
435 R__LOG_ERROR(
BrowserLog()) <<
"Embedded FileDialog failure - argument should have at least three strings" << args.substr(11);
446 auto dialog = std::make_shared<RFileDialog>(kind,
"", arr->at(1));
448 auto chid = std::stoi(arr->at(2));
450 if ((arr->size() > 3) && (arr->at(3) ==
"__cannotChangePath__"s)) {
451 dialog->SetCanChangePath(
false);
452 arr->erase(arr->begin() + 3, arr->begin() + 4);
453 }
else if ((arr->size() > 3) && (arr->at(3) ==
"__canChangePath__"s)) {
454 dialog->SetCanChangePath(
true);
455 arr->erase(arr->begin() + 3, arr->begin() + 4);
458 if ((arr->size() > 4) && (arr->at(3) ==
"__workingPath__"s)) {
459 dialog->SetWorkingPath(arr->at(4));
460 arr->erase(arr->begin() + 3, arr->begin() + 5);
463 if (arr->size() > 4) {
464 dialog->SetSelectedFilter(arr->at(3));
465 arr->erase(arr->begin(), arr->begin() + 4);
466 dialog->SetNameFilters(*arr);
469 dialog->Show({window, chid});
472 dialog->SetCallback([dialog](
const std::string &)
mutable { dialog.reset(); });
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
static std::string GetPathAsString(const RElementPath_t &path)
Converts element path back to string.
static RElementPath_t ParsePath(const std::string &str)
Parse string path to produce RElementPath_t One should avoid to use string pathes as much as possible...
static RElementPath_t ProvideTopEntries(std::shared_ptr< RGroup > &comp, const std::string &workdir="")
Provide top entries for file system On windows it is list of existing drivers, on Linux it is "Files ...
void SetTopElement(std::shared_ptr< Browsable::RElement > elem)
set top element for browsing
std::shared_ptr< Browsable::RElement > GetSubElement(const Browsable::RElementPath_t &path)
Returns sub-element starting from top, using cached data.
const Browsable::RElementPath_t & GetWorkingPath() const
std::shared_ptr< Browsable::RElement > GetElementFromTop(const Browsable::RElementPath_t &path)
Returns element with path, specified as Browsable::RElementPath_t.
std::string ProcessRequest(const RBrowserRequest &request)
Process browser request, returns string with JSON of RBrowserReply data.
void SetWorkingPath(const Browsable::RElementPath_t &path)
set working directory relative to top element
Request send from client to get content of path element.
std::string sort
kind of sorting
std::string regex
applied regex
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
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
void ProcessMsg(unsigned connid, const std::string &arg)
Process received data from client.
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
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.
RFileDialog(EDialogTypes kind=kOpenFile, const std::string &title="", const std::string &fname="")
constructor When title not specified, default will be used
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.
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static unsigned ShowWindow(std::shared_ptr< RWebWindow > window, const RWebDisplayArgs &args="")
Static method to show web window Has to be used instead of RWebWindow::Show() when window potentially...
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
RLogChannel & BrowserLog()
Log channel for Browser diagnostics.
std::function< void(const std::string &)> RFileDialogCallback_t
function signature for file dialog call-backs argument is selected file name