45using namespace std::string_literals;
80 bool DrawElement(std::shared_ptr<Browsable::RElement> &
elem,
const std::string & =
"")
override
83 auto code =
elem->GetContent(
"text");
90 auto json =
elem->GetContent(
"json");
105 auto img =
elem->GetContent(
"image64");
154 std::string
GetKind()
const override {
return "info"s; }
157 bool DrawElement(std::shared_ptr<Browsable::RElement> &,
const std::string & =
"")
override {
return false; }
167 std::ofstream
ofs(
pathtmp.str(), std::ofstream::out | std::ofstream::app);
172 gROOT->ProcessLine(
".g");
237 std::string
GetKind()
const override {
return "catched"s; }
288 if (
gROOT->IsWebDisplayBatch()) {
289 ::Warning(
"RBrowser::RBrowser",
"The RBrowser cannot run in web batch mode");
301 fTimer = std::make_unique<RBrowserTimer>(10,
kTRUE, *
this);
304 fWebWindow->SetDefaultPage(
"file:rootui5sys/browser/browser.html");
307 reverse =
gEnv->
GetValue(
"WebGui.Browser.Reverse",
"no"),
308 hidden =
gEnv->
GetValue(
"WebGui.Browser.ShowHidden",
"no"),
314 reverse = (reverse ==
"on" || reverse ==
"yes" || reverse ==
"1") ?
"true" :
"false";
315 hidden = (hidden ==
"on" || hidden ==
"yes" || hidden ==
"1") ?
"true" :
"false";
325 [
this](
unsigned connid,
const std::string &arg) {
ProcessMsg(connid, arg); });
384 fWebWindow->GetManager()->SetShowCallback(
nullptr);
385 fWebWindow->GetManager()->SetDeleteCallback(
nullptr);
395 std::unique_ptr<RBrowserRequest> request;
398 request = std::make_unique<RBrowserRequest>();
400 request->number = 100;
402 request = TBufferJSON::FromJSON<RBrowserRequest>(
msg);
419 if (
fname.empty())
return;
432 exec.
Form(
"TPython::ExecScript(\"%s\");",
file_path.c_str());
446 std::string opt = args.back();
450 path.insert(path.end(), args.begin(), args.end());
455 if (!
elem)
return ""s;
485 elem->GetChildsIter();
490 SendProgress(connid, progress);
496 return widget->SendWidgetContent();
501 [path](
const std::shared_ptr<RBrowserWidget> &
wg) { return path == wg->GetPath(); });
504 return "SELECT_WIDGET:"s + (*iter)->GetName();
549 path.insert(path.end(), args.begin(), args.end());
554 if (!
elem)
return ""s;
558 SendProgress(connid, progress);
564 return widget->SendWidgetContent();
613 std::shared_ptr<RBrowserWidget>
widget;
615 if (kind ==
"editor"s)
616 widget = std::make_shared<RBrowserEditorWidget>(
name,
true);
617 else if (kind ==
"image"s)
618 widget = std::make_shared<RBrowserEditorWidget>(
name,
false);
619 else if (kind ==
"info"s)
620 widget = std::make_shared<RBrowserInfoWidget>(
name);
641 if (!
win || kind.empty())
646 auto widget = std::make_shared<RBrowserCatchedWidget>(
name,
win, kind);
672 [
name, kind](
const std::shared_ptr<RBrowserWidget> &
widget) {
673 return kind.empty() ? name == widget->GetName() : kind == widget->GetKind();
687 auto iter = std::find_if(
fWidgets.begin(),
fWidgets.end(), [
name](std::shared_ptr<RBrowserWidget> &
widget) { return name == widget->GetName(); });
700 std::vector<std::string>
arr;
703 path +=
"/.root_hist" ;
704 std::ifstream
infile(path);
723 std::vector<std::string>
arr;
741 std::vector<std::vector<std::string>>
reply;
751 reply.emplace_back(std::vector<std::string>({
"active"s, fActiveWidgetName }));
760 if (
logs.size() > 0) {
765 reply.emplace_back(std::vector<std::string>({
772 reply.emplace_back(std::vector<std::string>({
778 std::string
msg =
"INMSG:";
858 unsigned connid = std::stoul(
arr.back());
arr.pop_back();
859 std::string kind =
arr.back();
arr.pop_back();
861 if (kind ==
"DBLCLK") {
864 }
else if (kind ==
"DROP") {
881 std::string kind,
msg;
882 auto pos =
arg0.find(
":");
883 if (pos == std::string::npos) {
886 kind =
arg0.substr(0, pos);
890 if (kind ==
"QUIT_ROOT") {
894 }
else if (kind ==
"BRREQ") {
899 }
else if (kind ==
"LASTCYCLE") {
903 }
else if (kind ==
"DBLCLK") {
905 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(
msg);
906 if (
arr && (
arr->size() > 2)) {
907 arr->push_back(kind);
908 arr->push_back(std::to_string(connid));
916 }
else if (kind ==
"DROP") {
918 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(
msg);
920 arr->push_back(kind);
921 arr->push_back(std::to_string(connid));
929 }
else if (kind ==
"WIDGET_SELECTED") {
936 }
else if (kind ==
"CLOSE_TAB") {
938 }
else if (kind ==
"GETWORKPATH") {
940 }
else if (kind ==
"CHPATH") {
941 auto path = TBufferJSON::FromJSON<Browsable::RElementPath_t>(
msg);
944 }
else if (kind ==
"CMD") {
945 std::string
sPrompt =
"root []";
947 if (
app->InheritsFrom(
"TRint")) {
961 auto widget = std::dynamic_pointer_cast<RBrowserInfoWidget>(
FindWidget(
""s,
"info"s));
976 }
else if (kind ==
"GETHISTORY") {
981 }
else if (kind ==
"GETLOGS") {
990 }
else if (kind ==
"SYNCEDITOR") {
991 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(
msg);
992 if (
arr && (
arr->size() > 4)) {
995 editor->fFirstSend =
true;
999 if ((
arr->size() == 6) && (
arr->at(5) ==
"SAVE"))
1001 if ((
arr->size() == 6) && (
arr->at(5) ==
"RUN")) {
1008 }
else if (kind ==
"GETINFO") {
1014 }
else if (kind ==
"NEWWIDGET") {
1018 }
else if (kind ==
"NEWCHANNEL") {
1019 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(
msg);
1020 if (
arr && (
arr->size() == 2)) {
1025 }
else if (kind ==
"CDWORKDIR") {
1033 }
else if (kind ==
"OPTIONS") {
1034 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(
msg);
1035 if (
arr && (
arr->size() == 3)) {
1068 if (
widget->GetTitle() != title)
1071 if (!kind.empty() && (
widget->GetKind() != kind))
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t win
Option_t Option_t TPoint TPoint const char mode
R__EXTERN TSystem * gSystem
static bool IsLastKeyCycle()
Is only last cycle from the list of keys is shown.
static void SetLastKeyCycle(bool on=true)
Set flag to show only last cycle from the list of keys.
static int ExtractItemIndex(std::string &name)
Extract index from name Index coded by client with ###<indx>$$$ suffix Such coding used by browser to...
@ kActImage
can be shown in image viewer, can provide image
@ kActDraw6
can be drawn inside ROOT6 canvas
@ kActCanvas
indicate that it is canvas and should be drawn directly
@ kActTree
can be shown in tree viewer
@ kActGeom
can be shown in geometry viewer
@ kActBrowse
just browse (expand) item
@ kActEdit
can provide data for text editor
@ kActDraw7
can be drawn inside ROOT7 canvas
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 bool SetClassDrawOption(const ClassArg &, const std::string &)
Set draw option for the class Return true if entry for the class exists.
static std::string GetClassDrawOption(const ClassArg &)
Return configured draw option for the class.
static RElementPath_t GetWorkingPath(const std::string &workdir="")
Return working path in browser hierarchy.
std::shared_ptr< Browsable::RElement > GetSubElement(const Browsable::RElementPath_t &path)
Returns sub-element starting from top, using cached data.
void ClearCache()
Clear internal objects cache.
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
void CreateDefaultElements()
Create default elements shown in the RBrowser.
RBrowserTimer(Long_t milliSec, Bool_t mode, RBrowser &br)
!< browser processing postponed requests
void Timeout() override
timeout handler used to process postponed requests in main ROOT thread
Web-based ROOT files and objects browser.
std::unique_ptr< RBrowserTimer > fTimer
! timer to handle postponed requests
RBrowserData fBrowsable
! central browsing element
std::shared_ptr< RBrowserWidget > AddWidget(const std::string &kind)
Creates new widget.
std::vector< std::string > GetRootHistory()
Get content of history file.
void AddInitWidget(const std::string &kind)
Create new widget and send init message to the client.
std::vector< std::vector< std::string > > fPostponed
! postponed messages, handled in timer
std::shared_ptr< RWebWindow > fWebWindow
! web window to browser
std::string ProcessDrop(unsigned connid, std::vector< std::string > &args)
Process drop of item in the current tab.
int fWidgetCnt
! counter for created widgets
std::shared_ptr< RBrowserWidget > GetActiveWidget() const
std::string ProcessDblClick(unsigned connid, std::vector< std::string > &args)
Process dbl click on browser item.
void ClearOnClose(const std::shared_ptr< void > &handle)
Set handle which will be cleared when connection is closed.
std::string fActiveWidgetName
! name of active widget
RBrowser(bool use_rcanvas=false)
constructor
void SetWorkingPath(const std::string &path)
Set working path in the browser.
std::string NewWidgetMsg(std::shared_ptr< RBrowserWidget > &widget)
Create message which send to client to create new widget.
bool fCatchWindowShow
! if arbitrary RWebWindow::Show calls should be catched by browser
std::string fPromptFileOutput
! file name for prompt output
void Show(const RWebDisplayArgs &args="", bool always_start_new_browser=false)
show Browser in specified place
std::string GetCurrentWorkingDirectory()
Return the current directory of ROOT.
void SetUseRCanvas(bool on=true)
std::shared_ptr< RBrowserWidget > FindWidget(const std::string &name, const std::string &kind="") const
Find widget by name or kind.
std::shared_ptr< RBrowserWidget > AddCatchedWidget(RWebWindow *win, const std::string &kind)
Add widget catched from external scripts.
bool GetUseRCanvas() const
std::vector< std::shared_ptr< RBrowserWidget > > fWidgets
! all browser widgets
virtual ~RBrowser()
destructor
void ProcessSaveFile(const std::string &fname, const std::string &content)
Process file save command in the editor.
float fLastProgressSend
! last value of send progress
std::string GetWindowUrl(bool remote)
Return URL parameter for the window showing ROOT Browser See ROOT::RWebWindow::GetUrl docu for more d...
std::string ProcessBrowserRequest(const std::string &msg)
Process browser request.
std::vector< std::string > GetRootLogs()
Get content of log file.
void ProcessMsg(unsigned connid, const std::string &arg)
Process received message from the client.
void CheckWidgtesModified(unsigned connid)
Check if any widget was modified and update if necessary.
void CloseTab(const std::string &name)
Close and delete specified widget.
void ProcessPostponedRequests()
Process postponed requests - decouple from websocket handling Only requests which can take longer tim...
unsigned fConnId
! default connection id
bool ActivateWidget(const std::string &title, const std::string &kind="")
Activate widget in RBrowser One should specify title and (optionally) kind of widget like "tcanvas" o...
void SendInitMsg(unsigned connid)
Process client connect.
void SendProgress(unsigned connid, float progr)
Send generic progress message to the web window Should show progress bar on client side.
long long fLastProgressSendTm
! time when last progress message was send
void ProcessRunMacro(const std::string &file_path)
Process run macro command in the editor.
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,...
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...
const_iterator begin() const
const_iterator end() const
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
const std::string & GetWidgetKind() const
returns widget kind
Represents web window, which can be shown in web browser or any other supported environment.
std::string GetUrl(bool remote=true)
Return URL string to connect web window URL typically includes extra parameters required for connecti...
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...
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
@ kNoSpaces
no new lines plus remove all spaces around "," and ":" symbols
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
const char * Data() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=nullptr)
Redirect standard output (stdout, stderr) to the specified file.
virtual int GetPid()
Get process id.
virtual TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
virtual int Unlink(const char *name)
Unlink, i.e.
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Handles synchronous and a-synchronous timer events.
Namespace for new ROOT classes and functions.
ROOT::RLogChannel & BrowserLog()
Log channel for Browser diagnostics.