28 ClassImp(TGCommandPlugin);
33 TGCommandPlugin::TGCommandPlugin(
const TGWindow *p, UInt_t w, UInt_t h) :
36 SetCleanup(kDeepCleanup);
37 fHf =
new TGHorizontalFrame(
this, 100, 20);
38 fComboCmd =
new TGComboBox(fHf,
"", 1);
39 fCommand = fComboCmd->GetTextEntry();
40 fCommandBuf = fCommand->GetBuffer();
41 fComboCmd->Resize(200, fCommand->GetDefaultHeight());
42 fHf->AddFrame(fComboCmd,
new TGLayoutHints(kLHintsCenterY |
43 kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
44 fHf->AddFrame(fLabel =
new TGLabel(fHf,
"Command (local):"),
45 new TGLayoutHints(kLHintsCenterY | kLHintsRight,
47 AddFrame(fHf,
new TGLayoutHints(kLHintsLeft | kLHintsTop |
48 kLHintsExpandX, 3, 3, 3, 3));
49 fCommand->Connect(
"ReturnPressed()",
"TGCommandPlugin",
this,
51 fStatus =
new TGTextView(
this, 10, 100, 1);
52 if (gClient->GetStyle() < 2) {
54 gClient->GetColorByName(
"#a0a0a0", pxl);
55 fStatus->SetSelectBack(pxl);
56 fStatus->SetSelectFore(TGFrame::GetWhitePixel());
58 AddFrame(fStatus,
new TGLayoutHints(kLHintsLeft | kLHintsTop |
59 kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3));
60 fPid = gSystem->GetPid();
61 TString defhist(Form(
"%s/.root_hist", gSystem->UnixPathName(
62 gSystem->HomeDirectory())));
63 FILE *lunin = fopen(defhist.Data(),
"rt");
65 ULong_t linecount = 0;
68 while (fgets(histline, 256, lunin))
71 if (linecount > 500) {
73 while(--linecount > 0)
74 if (!fgets(histline, 256, lunin))
78 while (fgets(histline, 256, lunin)) {
79 histline[strlen(histline)-1] = 0;
80 fComboCmd->InsertEntry(histline, 0, -1);
82 if (++linecount > 500)
87 fTimer =
new TTimer(
this, 1000);
91 Resize(GetDefaultSize());
98 TGCommandPlugin::~TGCommandPlugin()
100 TString pathtmp = TString::Format(
"%s/command.%d.log",
101 gSystem->TempDirectory(), fPid);
102 gSystem->Unlink(pathtmp);
103 fCommand->Disconnect(
"ReturnPressed()");
112 void TGCommandPlugin::CheckRemote(
const char * )
115 TApplication *app = gROOT->GetApplication();
116 if (!app->InheritsFrom(
"TRint"))
118 TString sPrompt = ((TRint*)app)->GetPrompt();
119 Int_t end = sPrompt.Index(
":root [", 0);
120 if (end > 0 && end != kNPOS) {
123 gClient->GetColorByName(
"#ff0000", pxl);
124 fLabel->SetTextColor(pxl);
125 fLabel->SetText(Form(
"Command (%s):", sPrompt.Data()));
129 gClient->GetColorByName(
"#000000", pxl);
130 fLabel->SetTextColor(pxl);
131 fLabel->SetText(
"Command (local):");
139 void TGCommandPlugin::HandleCommand()
141 const char *
string = fCommandBuf->GetString();
142 if (strlen(
string) > 1) {
144 TString sPrompt =
"root []";
145 TString pathtmp = TString::Format(
"%s/command.%d.log",
146 gSystem->TempDirectory(), fPid);
147 TApplication *app = gROOT->GetApplication();
148 if (app->InheritsFrom(
"TRint"))
149 sPrompt = ((TRint*)gROOT->GetApplication())->GetPrompt();
150 FILE *lunout = fopen(pathtmp.Data(),
"a+t");
152 fputs(Form(
"%s%s\n",sPrompt.Data(), string), lunout);
155 gSystem->RedirectOutput(pathtmp.Data(),
"a");
156 gApplication->SetBit(TApplication::kProcessRemotely);
157 gROOT->ProcessLine(
string);
158 fComboCmd->InsertEntry(
string, 0, -1);
159 if (app->InheritsFrom(
"TRint"))
160 Gl_histadd((
char *)string);
161 gSystem->RedirectOutput(0);
162 fStatus->LoadFile(pathtmp.Data());
163 fStatus->ShowBottom();
172 Bool_t TGCommandPlugin::HandleTimer(TTimer *t)
174 if ((fTimer == 0) || (t != fTimer))
return kTRUE;