Changeset 330 in Sophya for trunk/SophyaPI/PIext/piacmd.cc


Ignore:
Timestamp:
Jun 24, 1999, 4:26:47 PM (26 years ago)
Author:
ercodmgr
Message:

Amelioration du Help pour piapp (Groupe de Help) Reza 24/6/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/piacmd.cc

    r324 r330  
    2424                PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd);
    2525  virtual       ~PIAHelpWind();
     26  virtual void  Show();
    2627  virtual void  Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
     28  inline  void  AddHelpGroup(const char * hgrp, int gid)
     29                    { hgrpom->AppendItem(hgrp, 20000+gid); }
     30  inline  void  ClearHelpList()
     31                    { mNitem=0; hitemlist->DeleteAllItems(); }
    2732  inline  void  AddHelpItem(const char * hitem)
    28                         { mNitem++;  hitemlist->AppendItem(hitem, 1000+mNitem); }
     33                    { mNitem++;  hitemlist->AppendItem(hitem, 100+mNitem); }
    2934protected :
    3035  PIStdImgApp* dap;
     
    3237  int mNitem;
    3338  PIList* hitemlist;
     39  PIOptMenu* hgrpom;
    3440  PIButton * mBut;
    3541  PILabel * mLab;
     
    4450piac = piacmd;
    4551mNitem = 0;
    46 SetMsg(777);
     52SetMsg(77);
    4753
    4854int bsx, bsy;
     
    5359tsx = 10*bsx+2*spx;  tsy = 7*bsy+3*spy;
    5460SetSize(tsx,tsy);
    55 hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-2*spy, spx/2, spy);
     61hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy);
     62hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
     63hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy);
    5664hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
    5765// hitemlist->SetBorderWidth(2);
     
    6573mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
    6674mLab->SetLabel("");
    67 mBut = new PIButton(this, "Close", 700, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
     75mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
    6876mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
    6977}
     
    7280PIAHelpWind::~PIAHelpWind()
    7381{
     82delete hgrpom;
    7483delete hitemlist;
    7584delete mTxt;
     
    8291{
    8392PIMessage um = UserMsg(msg);
    84 if (((um == 777) && (ModMsg(msg) == PIMsg_Close)) || (um == 700) ) {
     93if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
    8594  Hide();
    8695  return;
    8796  }
    88 else if ( (um > 1000) && (sender == hitemlist)) {
     97else if ( (um >= 20000) && (sender == hgrpom)) {  // Selection de groupe de Help
     98  mTxt->SetText("");
     99  mLab->SetLabel("");
     100  piac->UpdateHelpList(this, um-20000);
     101}
     102else if ( (um > 100) && (sender == hitemlist) && (ModMsg(msg) == PIMsg_Select) ) {
    89103  string s = hitemlist->GetSelectionStr();
    90104  mTxt->SetText(piac->GetUsage(s));
     
    93107}
    94108
     109/* --Methode-- */
     110void PIAHelpWind::Show()
     111{
     112hgrpom->SetValue(20000);   // Groupe All
     113mTxt->SetText("");
     114mLab->SetLabel("");
     115piac->UpdateHelpList(this, 0);
     116PIWindow::Show();
     117}
    95118
    96119static PIACmd* curpiacmd = NULL;
     
    105128gltimer = NULL;
    106129
     130cmdhgrp["All"] = 0;
     131cmdgrpid = 1;
     132cmdhgrp["Commands"] = 1;
    107133helpwin = new PIAHelpWind(app, this);
     134helpwin->AddHelpGroup("All", 0);
     135helpwin->AddHelpGroup("Commands", 1);
    108136
    109137string kw = "piacmd";
     
    120148usage += "  > help <command_name>  # <command_name> usage info \n";
    121149usage += "  > helpwindow           # Displays help window \n";
    122 RegisterCommand(kw, usage, NULL);
     150string grp = "Commands";
     151RegisterHelp(kw, usage, grp);
    123152
    124153basexec = new PIABaseExecutor(this, omg, app);
     
    156185
    157186/* --Methode-- */
    158 void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce)
    159 {
    160   // if (!ce) return;
     187void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string grp)
     188{
     189if (!ce) {
     190  RegisterHelp(keyw, usage, grp);
     191  return;
     192  }
     193int gid = CheckHelpGrp(grp);
    161194cmdex cme;
     195cme.group = gid;
    162196cme.us = usage;
    163197cme.cex = ce;
    164198cmdexmap[keyw] = cme;
    165 if (helpwin) helpwin->AddHelpItem(keyw.c_str());
     199}
     200
     201/* --Methode-- */
     202void PIACmd::RegisterHelp(string& keyw, string& usage, string& grp)
     203{
     204int gid = CheckHelpGrp(grp);
     205cmdex cme;
     206cme.group = gid;
     207cme.us = usage;
     208cme.cex = NULL;
     209helpexmap[keyw] = cme;
     210}
     211
     212/* --Methode-- */
     213int PIACmd::CheckHelpGrp(string& grp)
     214{
     215int gid=0;
     216CmdHGroup::iterator it = cmdhgrp.find(grp);
     217if (it == cmdhgrp.end()) {
     218  cmdgrpid++;   gid = cmdgrpid;
     219  cmdhgrp[grp] = gid;
     220  helpwin->AddHelpGroup(grp.c_str(), gid);
     221  }
     222else gid = (*it).second;
     223return(gid);
     224}
     225
     226/* --Methode-- */
     227void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
     228{
     229helpwin->ClearHelpList();
     230CmdExmap::iterator it;
     231for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
     232  if ( (gid != 0) && ((*it).second.group != gid) ) continue;
     233  helpwin->AddHelpItem((*it).first.c_str());
     234  }
     235for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
     236  if ( (gid != 0) && ((*it).second.group != gid) ) continue;
     237  helpwin->AddHelpItem((*it).first.c_str());
     238  }
    166239}
    167240
     
    252325if (kw == "helpwindow") ShowHelpWindow();
    253326else if (kw == "help") {
    254   if (tokens.size() > 0) {
    255     CmdExmap::iterator it = cmdexmap.find(tokens[0]);
    256     if (it == cmdexmap.end())  cout << "Nothing known about " << tokens[0] << " ?? " << endl;
    257     else cout << (*it).second.us << endl;
     327  if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl;
     328  else { 
     329    string kwh = "piacmd";
     330    cout << GetUsage(kwh) << endl;
    258331    }
    259   else { 
    260     cout << "\n -------- PIACmd::Interpret() ::::: Help ------------ \n";
    261     cout << ">>> Interpreter's keywords : \n";
    262     cout << "  timingon  timingoff traceon  traceoff \n";
    263     cout << "  set unset listvar listcommands exec shell \n";
    264     cout << "  > set varname 'string'   # To set a variable, $varname \n";
    265     cout << "  > unset varname          # clear variable definition \n";
    266     cout << "  > listvars   # List of variable names and values \n";
    267     cout << "  > listcommands # List of all known commands \n";
    268     cout << "  > exec filename  # Execute commands from file \n";
    269     cout << "  > shell comand_string  # Execute shell command \n";
    270     cout << "  > help <command_name>  # <command_name> usage info \n";
    271     cout << "  > helpwindow           # Displays help window \n" << endl;
    272     }
    273   }
    274 
     332  }
    275333
    276334else if (kw == "set") {
     
    292350  }
    293351else if (kw == "listvars") {
    294   cout << "---- PIACmd::Interpret()  Command keyword List ----- \n";
     352  cout << "---- PIACmd::Interpret()  Command Variable List ----- \n";
    295353  CmdExmap::iterator it;
    296354  int kc = 0;
     
    376434string& PIACmd::GetUsage(const string& kw)
    377435{
     436bool fndok = false;
    378437CmdExmap::iterator it = cmdexmap.find(kw);
    379 if (it == cmdexmap.end()) { 
    380   if (videstr == NULL) videstr = new string("");
    381   return(*videstr);
    382   }
    383 else return( (*it).second.us );
     438if (it == cmdexmap.end()) {
     439  it = helpexmap.find(kw);
     440  if (it != helpexmap.end())  fndok = true;
     441  }
     442  else  fndok = true;
     443if (fndok)   return( (*it).second.us );
     444// Keyword pas trouve
     445if (videstr == NULL) videstr = new string("");
     446*videstr =  "Nothing known about " + kw + " ?? ";
     447return(*videstr);
     448 
    384449}
    385450
Note: See TracChangeset for help on using the changeset viewer.