]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/TGCommandPlugin.cxx
Dummy methods DefineParticle required by the interface added.
[u/mrichter/AliRoot.git] / EVE / Reve / TGCommandPlugin.cxx
1
2 #include "TROOT.h"
3 #include "TSystem.h"
4 #include "TRint.h"
5 #include "TApplication.h"
6 #include "TGClient.h"
7 #include "TGLabel.h"
8 #include "TGFrame.h"
9 #include "TGLayout.h"
10 #include "TGComboBox.h"
11 #include "TGTextView.h"
12 #include "TGTextEntry.h"
13 #include "TGTextEdit.h"
14 #include "TInterpreter.h"
15 #include "Getline.h"
16
17 #include "TGCommandPlugin.h"
18
19 ClassImp(TGCommandPlugin)
20
21 //______________________________________________________________________________
22 TGCommandPlugin::TGCommandPlugin(const TGWindow *p, UInt_t w, UInt_t h) :
23       TGMainFrame(p, w, h)
24 {
25
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, 
37                  5, 5, 1, 1));
38    AddFrame(fHf, new TGLayoutHints(kLHintsLeft | kLHintsTop | 
39             kLHintsExpandX, 3, 3, 3, 3));
40    fCommand->Connect("ReturnPressed()", "TGCommandPlugin", this,
41                      "HandleCommand()");
42
43    Pixel_t pxl;
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");
54    if (lunin) {
55       char histline[256];
56       while (fgets(histline, 256, lunin)) {
57          histline[strlen(histline)-1] = 0; // remove trailing "\n"
58          fComboCmd->InsertEntry(histline, 0, -1);
59       }
60       fclose(lunin);
61    }
62    MapSubwindows();
63    Resize(GetDefaultSize());
64    MapWindow();
65 }
66
67 //______________________________________________________________________________
68 TGCommandPlugin::~TGCommandPlugin()
69 {
70    // Destructor.
71
72    Cleanup();
73 }
74
75 //______________________________________________________________________________
76 void TGCommandPlugin::CheckRemote(const char * /*str*/)
77 {
78    // Check if actual ROOT session is a remote one or a local one.
79
80    Pixel_t pxl;
81    TString sPrompt = ((TRint*)gROOT->GetApplication())->GetPrompt();
82    Int_t end = sPrompt.Index(":root [", 0);
83    if (end > 0 && end != kNPOS) {
84       // remote session
85       sPrompt.Remove(end);
86       gClient->GetColorByName("#ff0000", pxl);
87       fLabel->SetTextColor(pxl);
88       fLabel->SetText(Form("Command (%s):", sPrompt.Data()));
89    }
90    else {
91       // local session
92       gClient->GetColorByName("#000000", pxl);
93       fLabel->SetTextColor(pxl);
94       fLabel->SetText("Command (local):");
95    }
96    fHf->Layout();
97 }
98
99 //______________________________________________________________________________
100 void TGCommandPlugin::HandleCommand()
101 {
102    // Handle command line from the "command" combo box.
103
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");
110       if (lunout) {
111          fputs(Form("%s%s\n",sPrompt.Data(), string), lunout);
112          fclose(lunout);
113       }
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();
122       CheckRemote(string);
123       fCommand->Clear();
124    }
125
126 }
127