5 #include "TApplication.h"
10 #include "TGComboBox.h"
11 #include "TGTextView.h"
12 #include "TGTextEntry.h"
13 #include "TGTextEdit.h"
14 #include "TInterpreter.h"
17 #include "TGCommandPlugin.h"
19 ClassImp(TGCommandPlugin)
21 //______________________________________________________________________________
22 TGCommandPlugin::TGCommandPlugin(const TGWindow *p, UInt_t w, UInt_t h) :
26 SetCleanup(kDeepCleanup);
27 fHf = new TGHorizontalFrame(this, 100, 20);
28 fCommandBuf = new TGTextBuffer(256);
29 fComboCmd = new TGComboBox(fHf, "", 1);
30 fCommand = fComboCmd->GetTextEntry();
31 fCommandBuf = fCommand->GetBuffer();
32 fComboCmd->Resize(200, fCommand->GetDefaultHeight());
33 fHf->AddFrame(fComboCmd, new TGLayoutHints(kLHintsCenterY |
34 kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
35 fHf->AddFrame(fLabel = new TGLabel(fHf, "Command (local):"),
36 new TGLayoutHints(kLHintsCenterY | kLHintsRight,
38 AddFrame(fHf, new TGLayoutHints(kLHintsLeft | kLHintsTop |
39 kLHintsExpandX, 3, 3, 3, 3));
40 fCommand->Connect("ReturnPressed()", "TGCommandPlugin", this,
44 gClient->GetColorByName("#ccccff", pxl);
45 fStatus = new TGTextView(this, 10, 100, 1);
46 fStatus->SetSelectBack(pxl);
47 fStatus->SetSelectFore(TGFrame::GetBlackPixel());
48 AddFrame(fStatus, new TGLayoutHints(kLHintsLeft | kLHintsTop |
49 kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3));
50 fPid = gSystem->GetPid();
51 TString defhist(Form("%s/.root_hist", gSystem->UnixPathName(
52 gSystem->HomeDirectory())));
53 FILE *lunin = fopen(defhist.Data(), "rt");
56 while (fgets(histline, 256, lunin)) {
57 histline[strlen(histline)-1] = 0; // remove trailing "\n"
58 fComboCmd->InsertEntry(histline, 0, -1);
63 Resize(GetDefaultSize());
67 //______________________________________________________________________________
68 TGCommandPlugin::~TGCommandPlugin()
75 //______________________________________________________________________________
76 void TGCommandPlugin::CheckRemote(const char * /*str*/)
78 // Check if actual ROOT session is a remote one or a local one.
81 TString sPrompt = ((TRint*)gROOT->GetApplication())->GetPrompt();
82 Int_t end = sPrompt.Index(":root [", 0);
83 if (end > 0 && end != kNPOS) {
86 gClient->GetColorByName("#ff0000", pxl);
87 fLabel->SetTextColor(pxl);
88 fLabel->SetText(Form("Command (%s):", sPrompt.Data()));
92 gClient->GetColorByName("#000000", pxl);
93 fLabel->SetTextColor(pxl);
94 fLabel->SetText("Command (local):");
99 //______________________________________________________________________________
100 void TGCommandPlugin::HandleCommand()
102 // Handle command line from the "command" combo box.
104 const char *string = fCommandBuf->GetString();
105 if (strlen(string) > 1) {
106 // form temporary file path
107 TString pathtmp = Form("%s/ride.%d.log", gSystem->TempDirectory(), fPid);
108 TString sPrompt = ((TRint*)gROOT->GetApplication())->GetPrompt();
109 FILE *lunout = fopen(pathtmp.Data(), "a+t");
111 fputs(Form("%s%s\n",sPrompt.Data(), string), lunout);
114 gSystem->RedirectOutput(pathtmp.Data(), "a");
115 gApplication->SetBit(TApplication::kProcessRemotely);
116 gROOT->ProcessLine(string);
117 fComboCmd->InsertEntry(string, 0, -1);
118 Gl_histadd((char *)string);
119 gSystem->RedirectOutput(0);
120 fStatus->LoadFile(pathtmp.Data());
121 fStatus->ShowBottom();