Ignore:
Timestamp:
Oct 25, 2013, 3:51:05 PM (11 years ago)
Author:
touze
Message:

preparation pour ajouter une maille FODO

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_console.cc

    r417 r427  
    1313
    1414
    15 GWt_console::GWt_console()
    16 :WContainerWidget()
     15GWt_console::GWt_console() : WContainerWidget()
    1716{
    18     setObjectName("console");
     17  setObjectName("console");
    1918
    20 
    21     // la ligne de search
    22     Wt::WContainerWidget *searchContainer = new Wt::WContainerWidget();
     19  // la ligne de search
     20  Wt::WContainerWidget *searchContainer = new Wt::WContainerWidget();
    2321   
    24     Wt::WLabel *label = new Wt::WLabel("Search ", searchContainer);
    25     searchLineEdit_ = new Wt::WLineEdit("", searchContainer);
    26     searchLineEdit_->setToolTip("clic here to search a string in the output");
     22  Wt::WLabel *label = new Wt::WLabel("Search ", searchContainer);
     23  searchLineEdit_ = new Wt::WLineEdit("", searchContainer);
     24  searchLineEdit_->setToolTip("clic here to search a string in the output");
    2725   
    28     // le panel
    29     WPanel *panelConsole = new WPanel(this);
    30     panelConsole->setTitle(" output");
    31 
    32     WScrollArea* scrollContainer = new  WScrollArea();
    33    
    34 
    35     outputCurrent_ = new WText(this);
    36     outputCurrent_->setTextFormat(Wt::XHTMLText);
    37     outputCurrent_->setInline(false);
    38     outputCurrent_->setMaximumSize(750,400);
    39 
    40     scrollContainer->setWidget(outputCurrent_);
    41     scrollContainer->setStyleClass("scrollConsole");
    42 
    43     Wt::WContainerWidget *panelContainer = new Wt::WContainerWidget();
    44     Wt::WVBoxLayout* vContainerLayout = new Wt::WVBoxLayout();
    45 
    46     vContainerLayout->addWidget(searchContainer);
    47     vContainerLayout->addWidget(scrollContainer);
    48 
    49 
    50     panelContainer->setLayout(vContainerLayout);
    51     panelConsole->setCentralWidget(panelContainer);
    52 
    53     // signals
    54     searchLineEdit_->keyWentUp ().connect(this, &GWt_console::searchFilter);
     26  // le panel
     27  WPanel *panelConsole = new WPanel(this);
     28  panelConsole->setTitle(" output");
     29 
     30  WScrollArea* scrollContainer = new WScrollArea();
     31 
     32  outputCurrent_ = new WText(this);
     33  outputCurrent_->setTextFormat(Wt::XHTMLText);
     34  outputCurrent_->setInline(false);
     35  outputCurrent_->setMaximumSize(750,400);
     36  scrollContainer->setWidget(outputCurrent_);
     37  scrollContainer->setStyleClass("scrollConsole");
     38 
     39  Wt::WContainerWidget *panelContainer = new Wt::WContainerWidget();
     40  Wt::WVBoxLayout* vContainerLayout = new Wt::WVBoxLayout();
     41  vContainerLayout->addWidget(searchContainer);
     42  vContainerLayout->addWidget(scrollContainer);
     43  panelContainer->setLayout(vContainerLayout);
     44  panelConsole->setCentralWidget(panelContainer);
     45 
     46  // signals
     47  searchLineEdit_->keyWentUp ().connect(this,&GWt_console::searchFilter);
    5548}
    56 
    5749
    5850GWt_console::~GWt_console()
     
    6052}
    6153
    62 
    6354void GWt_console::searchFilter() {
    64 
    65     std::string br = "<br />";
     55 
     56  std::string br = "<br />";
     57 
     58  std::string txt = searchLineEdit_->text().toUTF8 ();
     59  if (searchLineEdit_->text() == "") {
     60    outputCurrent_->setText(outputOriginal_);
     61    outputCurrent_->setTextFormat(Wt::XHTMLText);
     62    return;
     63  }
     64 
     65  std::string outputStr = outputOriginal_.toUTF8();
     66  std::string outputFinal = "";
     67 
     68  // look for lines that contains the seacrh string
     69  bool end = false;
     70  int nextPos = 0;
     71  int nextPosTxt = 0;
     72  int lineNumber = 0;
     73  std::string beginStr;
     74  std::string endStr;
     75 
     76  // loop on all lines
     77  while (end == false) {
     78    lineNumber++;
    6679   
    67     std::string txt = searchLineEdit_->text().toUTF8 ();
    68     if (searchLineEdit_->text() == "") {
    69         outputCurrent_->setText(outputOriginal_);
    70         outputCurrent_->setTextFormat(Wt::XHTMLText);
    71         return;
    72     }
     80    nextPos = outputStr.find(br);
    7381   
    74     std::string outputStr = outputOriginal_.toUTF8();
    75     std::string outputFinal = "";
    76    
    77     // look for lines that contains the seacrh string
    78     bool end = false;
    79     int nextPos = 0;
    80     int nextPosTxt = 0;
    81     int lineNumber = 0;
    82     std::string beginStr;
    83     std::string endStr;
    84    
    85     // loop on all lines
    86     while (end == false) {
    87         lineNumber++;
     82    // if this line contains the token
     83    if (nextPos != std::string::npos) {
     84      beginStr = outputStr.substr(0,nextPos);
     85      endStr = outputStr.substr(nextPos+br.size());
     86      outputStr = endStr;
     87     
     88     
     89      // colorize for all token
     90      bool lineEnd = false;
     91      std::string colorizeTxt = "";
     92      while (lineEnd == false) {
     93        nextPosTxt = beginStr.find(txt);
    8894       
    89         nextPos = outputStr.find(br);
    90        
    91         // if this line contains the token
    92         if (nextPos != std::string::npos) {
    93             beginStr = outputStr.substr(0,nextPos);
    94             endStr = outputStr.substr(nextPos+br.size());
    95             outputStr = endStr;
    96 
    97 
    98             // colorize for all token
    99             bool lineEnd = false;
    100             std::string colorizeTxt = "";
    101             while (lineEnd == false) {
    102                 nextPosTxt = beginStr.find(txt);
    103                
    104                 if (nextPosTxt != std::string::npos) {
    105                     colorizeTxt += beginStr.substr(0,nextPosTxt)+
    106                     std::string("<b><font style='background-color:yellow;'>")+
    107                     txt+
    108                     std::string("</font></b>");
    109                     beginStr = beginStr.substr(nextPosTxt+txt.size());
    110                    
    111                 } else if (colorizeTxt != "") {
    112                     colorizeTxt += beginStr;
    113                     lineEnd = true;
    114                 } else {
    115                     lineEnd = true;
    116                 }
    117             }
    118             if (colorizeTxt != "") {
    119                 std::stringstream ss;
    120                 ss << lineNumber;
    121                 outputFinal += std::string("<font color='gray'>line ")+ss.str()+" : </font>"+colorizeTxt+br;
     95        if (nextPosTxt != std::string::npos) {
     96          colorizeTxt += beginStr.substr(0,nextPosTxt)+
     97            std::string("<b><font style='background-color:yellow;'>")+
     98            txt+
     99            std::string("</font></b>");
     100          beginStr = beginStr.substr(nextPosTxt+txt.size());
     101         
     102        } else if (colorizeTxt != "") {
     103          colorizeTxt += beginStr;
     104          lineEnd = true;
     105        } else {
     106          lineEnd = true;
     107        }
     108      }
     109      if (colorizeTxt != "") {
     110        std::stringstream ss;
     111        ss << lineNumber;
     112        outputFinal += std::string("<font color='gray'>line ")+ss.str()+" : </font>"+colorizeTxt+br;
    122113            }
    123114        } else {
     
    133124
    134125void GWt_console::addConsoleMessage(WString msg) {
    135    
    136     // changes specials caracters
    137     outputOriginal_ += Wt::Utils::htmlEncode (msg.toUTF8(),  Wt::Utils::EncodeNewLines);
    138 
    139     // apply filter, will modify outputCurrent
    140     searchFilter();
    141     /*
    142      * Little javascript trick to make sure we scroll along with new content
    143      */
    144     wApp->doJavaScript(outputCurrent_->jsRef() + ".scrollTop += "
    145                        + outputCurrent_->jsRef() + ".scrollHeight;");
    146    
     126 
     127  // changes specials caracters
     128  outputOriginal_ += Wt::Utils::htmlEncode (msg.toUTF8(),  Wt::Utils::EncodeNewLines);
     129 
     130  // apply filter, will modify outputCurrent
     131  searchFilter();
     132  /*
     133   * Little javascript trick to make sure we scroll along with new content
     134   */
     135  wApp->doJavaScript(outputCurrent_->jsRef() + ".scrollTop += "
     136                     + outputCurrent_->jsRef() + ".scrollHeight;");
     137 
    147138}
    148139
Note: See TracChangeset for help on using the changeset viewer.