⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filelist.cpp

📁 LINUX下
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * btg Copyright (C) 2005 Michael Wojciechowski. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *//* * $Id: filelist.cpp,v 1.1.4.6 2007/09/17 15:34:50 wojci Exp $ */#include "filelist.h"#include <boost/filesystem/operations.hpp>#include <boost/filesystem/exception.hpp>#include <algorithm>#include <cctype>#include "helpwindow.h"namespace btg{   namespace UI   {      namespace cli      {         bool filename_compare(boost::filesystem::path const& _p1,                               boost::filesystem::path const& _p2);         namespace fs = boost::filesystem;         fileList::fileList(keyMapping const& _kmap,                             windowSize const& _ws,                            std::string const& _directory)            : baseWindow(_kmap),              size_(_ws),              currentDirectory_(_directory),              currentFile_(),              numberOfLines_(0),              positionWindowStart_(0),              positionWindowEnd_(0),              currentPosition_(0)         {            if (currentDirectory_.size() == 0)               {                  currentDirectory_ = fs::initial_path().string();               }         }         dialog::RESULT fileList::run()         {            init(size_);            getDirectory();            refresh();            // Handle keyboard.            keyMapping::KEYLABEL label = keyMapping::K_UNDEF;            t_uint               key   = 0;            bool                 cont  = true;            while (cont)               {                  key = readAnyKey();                  if (!handleKeyboard(key, label))                     {                        // Got something that is not recognized as one of                        // the keys that are used.                        //                         // Use this information to move to the position                        // in the list of files which begins with this                        // character.                        moveTo(key);                        continue;                     }                  switch (label)                     {                     case keyMapping::K_HELP:                        {                           if (showHelp() == dialog::R_RESIZE)                              {                                 // Resized window.                                 return dialog::R_RESIZE;                              }                           break;                        }                     case keyMapping::K_QUIT:                        {                           cont = false;                           break;                        }                     case keyMapping::K_DOWN:                        {                           moveDown();                           refresh();                           break;                        }                     case keyMapping::K_UP:                        {                           moveUp();                           refresh();                           break;                        }                     case keyMapping::K_LIST_START:                        {                           toStart();                           refresh();                           break;                        }                     case keyMapping::K_LIST_END:                        {                           toEnd();                           refresh();                           break;                        }                     case keyMapping::K_SELECT:                        {                           fs::path p;                           if (getSelection(p))                              {                                 if (p.string() == "")                                    {                                       break;                                    }                                 if (fs::is_directory(p))                                    {                                       // check here, that the                                       // selected directory is valid.                                       //                                       // It seems that when using                                       // directories with + in them,                                       // an exception is thrown.                                       try                                          {                                             fs::path fpath(p.string());                                          }                                       catch (...)                                          {                                             break;                                          }                                       currentDirectory_ = p.string();                                       getDirectory();                                       currentPosition_     = 0;                                       positionWindowEnd_   = 0;                                       positionWindowStart_ = 0;                                       refresh();                                    }                                 else                                    {                                       // A file was selected.                                       currentFile_ = p.string();                                       cont         = false;                                    }                              }                           // A file or directory was selected.                           // Find out which one.                           break;                        }                     case keyMapping::K_RESIZE:                        {                           // Close this window, and make the parent                           // resize its window.                           return dialog::R_RESIZE;                           break;                        }                     default:                        {                           refresh();                           break;                        }                     }               }            return dialog::R_QUIT;         }         std::string fileList::getLastDirectory() const         {            return currentDirectory_;         }         bool fileList::getFile(std::string & _file) const         {            bool status = false;            if (currentFile_.size() > 0)               {                  _file  = currentFile_;                  status = true;               }            return status;         }         bool fileList::init(windowSize const& _ws)         {            bool status = baseWindow::init(_ws);            if (status)               {                  numberOfLines_  = _ws.height-1;               }            return status;         }         void fileList::resize(windowSize const& _ws)         {         }         bool fileList::destroy()         {            if (window_ != 0)               {                  delwin(window_);                  window_ = 0;               }            return true;         }         void fileList::refresh()         {            if (window_ == 0)               {                  return;               }            clear();            drawList();            wrefresh(window_);         }         void fileList::fillIterator(std::vector<fs::path>::const_iterator & _startIter,                                     std::vector<fs::path>::const_iterator & _endIter)         {            if (positionWindowEnd_ == 0)               {                  positionWindowEnd_ = numberOfLines_;               }	              if (positionWindowEnd_ > static_cast<t_int>(entries_.size()))               {                  positionWindowEnd_ = entries_.size();               }	              // Move the iterator the the start of the window to display.            for (t_int counter = 0;                 counter < positionWindowStart_;                 counter++)               {                  _startIter++;               }	              // Move the iterator the the end of the window to display.            for (t_int counter = 0;                 counter < positionWindowEnd_;                 counter++)               {                  _endIter++;               }         }         void fileList::drawList()         {            std::vector<fs::path>::const_iterator iterBeg = entries_.begin();            std::vector<fs::path>::const_iterator iterEnd = entries_.begin();            fillIterator(iterBeg, iterEnd);            // Display the window.            t_int counter = 0;            std::vector<fs::path>::const_iterator iter;            for (iter = iterBeg;                 iter != iterEnd;                 iter++)               {                  fs::path p = *iter;                  std::string filename = p.leaf();                  bool isDirectory = false;                  try                     {                        if (fs::is_directory(p))                           {                              isDirectory = true;                           }                     }                  catch(...)                     {                        isDirectory = false;                     }                  if (counter == currentPosition_)                     {                        ::wattron(window_, A_REVERSE);                        std::string spacestr;                        t_int spaces = width_ - filename.size() - 1 /* extra space is inserted at                                                                     * the beginning of the line.                                                                     */;                        if (spaces > 0)                           {                              for (t_int spacecounter = 0;                                   spacecounter < spaces;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -