Logo ROOT  
Reference Guide
RMenuItem.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#include "ROOT/RMenuItem.hxx"
10
11#include "TROOT.h"
12#include "TString.h"
13#include "TClass.h"
14#include "TList.h"
15#include "TMethod.h"
16#include "TMethodArg.h"
17#include "TMethodCall.h"
18#include "TBufferJSON.h"
19
21{
22 fItems.clear();
23
24 TList lst;
25 cl->GetMenuItems(&lst);
26
27 TIter iter(&lst);
28 TMethod *m = nullptr;
29
30 while ((m = (TMethod *)iter()) != nullptr) {
31
32 if (m->IsMenuItem() == kMenuToggle) {
33 TString getter;
34 if (m->Getter() && strlen(m->Getter()) > 0) {
35 getter = m->Getter();
36 } else if (strncmp(m->GetName(), "Set", 3) == 0) {
37 getter = TString(m->GetName())(3, strlen(m->GetName()) - 3);
38 if (cl->GetMethodAllAny(TString("Has") + getter))
39 getter = TString("Has") + getter;
40 else if (cl->GetMethodAllAny(TString("Get") + getter))
41 getter = TString("Get") + getter;
42 else if (cl->GetMethodAllAny(TString("Is") + getter))
43 getter = TString("Is") + getter;
44 else
45 getter = "";
46 }
47
48 if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
49 // execute getter method to get current state of toggle item
50
51 auto call = std::make_unique<TMethodCall>(cl, getter, "");
52
53 if (call->ReturnType() == TMethodCall::kLong) {
54 Long_t l(0);
55 call->Execute(obj, l);
56
57 AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, Form("%s(%s)", m->GetName(), (l != 0) ? "0" : "1"));
58
59 } else {
60 // Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
61 }
62 }
63 } else {
64 TList *args = m->GetListOfMethodArgs();
65
66 if (!args || (args->GetSize() == 0)) {
67 AddMenuItem(m->GetName(), m->GetTitle(), Form("%s()", m->GetName()));
68 } else {
69 auto item = std::make_unique<Detail::RArgsMenuItem>(m->GetName(), m->GetTitle());
70 item->SetExec(Form("%s()", m->GetName()));
71
72 TIter args_iter(args);
73 TMethodArg *arg = nullptr;
74
75 while ((arg = dynamic_cast<TMethodArg *>(args_iter())) != nullptr) {
76 Detail::RMenuArgument menu_arg(arg->GetName(), arg->GetTitle(), arg->GetFullTypeName());
77 if (arg->GetDefault()) menu_arg.SetDefault(arg->GetDefault());
78 item->AddArg(menu_arg);
79 }
80
81 Add(std::move(item));
82 }
83 }
84 }
85}
long Long_t
Definition: RtypesCore.h:50
@ kMenuToggle
Definition: TMethod.h:34
char * Form(const char *fmt,...)
Argument description for menu item which should invoke class method.
Definition: RMenuItem.hxx:96
void SetDefault(const std::string &dflt)
Definition: RMenuItem.hxx:112
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
Definition: RMenuItem.hxx:162
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
Definition: RMenuItem.hxx:169
std::vector< std::unique_ptr< Detail::RMenuItem > > fItems
list of items in the menu
Definition: RMenuItem.hxx:154
void Add(std::unique_ptr< Detail::RMenuItem > &&item)
Definition: RMenuItem.hxx:160
void PopulateObjectMenu(void *obj, TClass *cl)
Definition: RMenuItem.cxx:20
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
void GetMenuItems(TList *listitems)
Returns list of methods accessible by context menu.
Definition: TClass.cxx:3717
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition: TClass.cxx:4225
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
A doubly linked list.
Definition: TList.h:44
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition: TMethodArg.h:31
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
Definition: TMethodArg.cxx:75
const char * GetDefault() const
Get default value of method argument.
Definition: TMethodArg.cxx:58
static const EReturnType kLong
Definition: TMethodCall.h:43
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
auto * m
Definition: textangle.C:8
auto * l
Definition: textangle.C:4