Skip to content
Snippets Groups Projects
Select Git revision
  • 254686085c806b66372e0afddc9913564c266fae
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

shell_history.cc

Blame
  • user avatar
    Marco Biasini authored
    4dd85f94
    History
    shell_history.cc 2.87 KiB
    //------------------------------------------------------------------------------
    // This file is part of the OpenStructure project <www.openstructure.org>
    //
    // Copyright (C) 2008-2011 by the OpenStructure authors
    //
    // This library is free software; you can redistribute it and/or modify it under
    // the terms of the GNU Lesser General Public License as published by the Free
    // Software Foundation; either version 3.0 of the License, or (at your option)
    // any later version.
    // This library is distributed in the hope that it will be useful, but WITHOUT
    // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    // FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    // details.
    //
    // You should have received a copy of the GNU Lesser General Public License
    // along with this library; if not, write to the Free Software Foundation, Inc.,
    // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    //------------------------------------------------------------------------------
    /*
      Author: Andreas Schenk
     */
    #include "shell_history.hh"
    
    namespace ost { namespace gui {
    
    
    ShellHistory::ShellHistory() :
      history_list_(),
      current_(""),
      current_mode_(EDITMODE_SINGLELINE),
      index_(0)
    {
    }
    void ShellHistory::SetCurrentCommand(const QString& command, BlockEditMode block_edit_mode)
    {
      current_=command;
      if(block_edit_mode==EDITMODE_MULTILINE_ACTIVE){
        current_mode_=EDITMODE_MULTILINE_INACTIVE;
      }else{
        current_mode_=block_edit_mode;
      }
    }
    
    void ShellHistory::AppendCommand(const QString& command, BlockEditMode block_edit_mode)
    {
      if(block_edit_mode==EDITMODE_MULTILINE_ACTIVE){
      history_list_.push_back(std::pair<QString,BlockEditMode>(command,EDITMODE_MULTILINE_INACTIVE));
      }else{
      history_list_.push_back(std::pair<QString,BlockEditMode>(command,block_edit_mode));
      }
      index_=history_list_.size();
      current_="";
      current_mode_=EDITMODE_SINGLELINE;
    }
    
    QString ShellHistory::GetCommand()
    {
      if(index_>=history_list_.size()){
        return current_;
      }else{
        return history_list_[index_].first;
      }
    }
    
    BlockEditMode ShellHistory::GetCommandMode()
    {
      if(index_>=history_list_.size()){
        return current_mode_;
      }else{
        return history_list_[index_].second;
      }
    }
    
    bool ShellHistory::AtEnd()
    {
      return index_>=history_list_.size();
    }
    
    void ShellHistory::MoveToPreviousMatch()
    {
      int newindex=index_-1;
      while(newindex>=0){
        if(history_list_[newindex].first.indexOf(current_)==0 || current_.size()==0){
          index_=newindex;
          break;
        }
        --newindex;
      }
    }
    
    void ShellHistory::MoveToNextMatch()
    {
      int newindex=index_+1;
      while(static_cast<unsigned int>(newindex)<history_list_.size()){
        if(history_list_[newindex].first.indexOf(current_)==0 || current_.size()==0){
          index_=newindex;
          break;
        }
        ++newindex;
      }
      if(static_cast<unsigned int>(newindex)!=index_){
        index_=history_list_.size();
      }
    }
    
    
    }}//ns