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") {
426 return msg.compare(0, 11,
"FILEDIALOG:") == 0;
437std::shared_ptr<RFileDialog>
RFileDialog::Embed(
const std::shared_ptr<RWebWindow> &window,
unsigned connid,
const std::string &args)
442 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(args.substr(11));
444 if (!arr || (arr->size() < 3)) {
445 R__LOG_ERROR(
BrowserLog()) <<
"Embedded FileDialog failure - argument should have at least three strings" << args.substr(11);
456 auto dialog = std::make_shared<RFileDialog>(kind,
"", arr->at(1));
458 auto chid = std::stoi(arr->at(2));
460 if ((arr->size() > 3) && (arr->at(3) ==
"__cannotChangePath__"s)) {
461 dialog->SetCanChangePath(
false);
462 arr->erase(arr->begin() + 3, arr->begin() + 4);
463 }
else if ((arr->size() > 3) && (arr->at(3) ==
"__canChangePath__"s)) {
464 dialog->SetCanChangePath(
true);
465 arr->erase(arr->begin() + 3, arr->begin() + 4);
468 if ((arr->size() > 4) && (arr->at(3) ==
"__workingPath__"s)) {
469 dialog->SetWorkingPath(arr->at(4));
470 arr->erase(arr->begin() + 3, arr->begin() + 5);
473 if (arr->size() > 4) {
474 dialog->SetSelectedFilter(arr->at(3));
475 arr->erase(arr->begin(), arr->begin() + 4);
476 dialog->SetNameFilters(*arr);
479 dialog->Show({window, connid, chid});
482 dialog->SetCallback([dialog](
const std::string &)
mutable { dialog.reset(); });
495 return res ? true :
false;
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
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 "File s...
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.
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
const Browsable::RElementPath_t & GetWorkingPath() const
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 void SetStartFunc(bool on)
Set start dialog function for RWebWindow.
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
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...
void ProcessMsg(unsigned connid, const std::string &arg)
Process received data from client.
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 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
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.
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 void SetStartDialogFunc(std::function< bool(const std::shared_ptr< RWebWindow > &, unsigned, const std::string &)>)
Configure func which has to be used for starting dialog.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
class ROOT::Details::RWebWindowPlugin sRWebWindowPlugin
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
ROOT::Experimental::RLogChannel & BrowserLog()
Log channel for Browser diagnostics.