31using namespace std::string_literals;
58 auto separ =
fSelect.rfind(
"/");
59 if (separ == std::string::npos)
64 if (separ != std::string::npos) {
65 workdir =
fSelect.substr(0, separ);
69 auto comp = std::make_shared<Browsable::RGroup>(
"top",
"Top file dialog element");
77 fWebWindow->SetPanelName(
"rootui5.browser.view.FileDialog");
81 [
this](
unsigned connid,
const std::string &arg) {
ProcessMsg(connid, arg); },
141 case kSaveAs:
return "SaveAs"s;
166 std::string lastname, allname;
169 auto pp = entry.find(
" (");
170 if (pp == std::string::npos)
continue;
171 auto name = entry.substr(0, pp);
182 if (!allname.empty())
return allname;
183 if (!lastname.empty())
return lastname;
196 if (entry.compare(0, fname.length(), fname) == 0) {
197 auto pp = entry.find(
"(", fname.length());
201 while (pp != std::string::npos) {
202 pp = entry.find(
"*.", pp);
203 if (pp == std::string::npos)
break;
205 auto pp2 = entry.find_first_of(
" )", pp+2);
206 if (pp2 == std::string::npos)
break;
208 if (res.empty()) res =
"^(.*\\.(";
209 else res.append(
"|");
211 res.append(entry.substr(pp+2, pp2 - pp - 2));
216 if (!res.empty()) res.append(
")$)");
234 req.
sort =
"alphabetical";
244 "\"title\" : "s + jtitle.Data() +
","s +
245 "\"path\" : "s + jpath.Data() +
","s +
246 "\"can_change_path\" : "s + (
GetCanChangePath() ?
"true"s :
"false"s) +
","s +
247 "\"filter\" : "s + jfilter.Data() +
","s +
248 "\"filters\" : "s + jfilters.Data() +
","s +
249 "\"fname\" : "s + jfname.Data() +
","s +
259 req.
sort =
"alphabetical";
264 fWebWindow->Send(connid,
"CHMSG:{\"path\" : "s + jpath.Data() +
273 if (arg.compare(0, 7,
"CHPATH:") == 0) {
275 auto path = TBufferJSON::FromJSON<Browsable::RElementPath_t>(arg.substr(7));
281 }
else if (arg.compare(0, 6,
"CHEXT:") == 0) {
287 }
else if (arg.compare(0, 10,
"DLGSELECT:") == 0) {
290 auto path = TBufferJSON::FromJSON<Browsable::RElementPath_t>(arg.substr(10));
300 fSelect = elem->GetContent(
"filename");
304 bool need_confirm =
false;
310 std::string fname = path->back();
314 fSelect = direlem->GetContent(
"filename") +
"/"s + fname;
324 }
else if (arg ==
"DLGNOSELECT") {
327 fWebWindow->Send(connid,
"NOSELECT_CONFIRMED"s);
328 }
else if (arg ==
"DLG_CONFIRM_SELECT") {
427 return msg.compare(0, 11,
"FILEDIALOG:") == 0;
438std::shared_ptr<RFileDialog>
RFileDialog::Embed(
const std::shared_ptr<RWebWindow> &window,
unsigned connid,
const std::string &args)
443 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(args.substr(11));
445 if (!arr || (arr->size() < 3)) {
446 R__LOG_ERROR(
BrowserLog()) <<
"Embedded FileDialog failure - argument should have at least three strings" << args.substr(11);
457 auto dialog = std::make_shared<RFileDialog>(kind,
"", arr->at(1));
459 auto chid = std::stoi(arr->at(2));
461 if ((arr->size() > 3) && (arr->at(3) ==
"__cannotChangePath__"s)) {
462 dialog->SetCanChangePath(
false);
463 arr->erase(arr->begin() + 3, arr->begin() + 4);
464 }
else if ((arr->size() > 3) && (arr->at(3) ==
"__canChangePath__"s)) {
465 dialog->SetCanChangePath(
true);
466 arr->erase(arr->begin() + 3, arr->begin() + 4);
469 if ((arr->size() > 4) && (arr->at(3) ==
"__workingPath__"s)) {
470 dialog->SetWorkingPath(arr->at(4));
471 arr->erase(arr->begin() + 3, arr->begin() + 5);
474 if (arr->size() > 4) {
475 dialog->SetSelectedFilter(arr->at(3));
476 arr->erase(arr->begin(), arr->begin() + 4);
477 dialog->SetNameFilters(*arr);
480 dialog->Show({window, connid, chid});
483 dialog->SetCallback([dialog](
const std::string &)
mutable { dialog.reset(); });
496 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.