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

📄 filelist.cpp

📁 LINUX下
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                                   spacecounter++)                                 {                                    spacestr += " ";                                 }                           }                        if (isDirectory)                           {                              setColor(Colors::C_DIRECTORY);                              mvwprintw(window_, counter, 0, " %s%s", filename.c_str(), spacestr.c_str());                              unSetColor(Colors::C_DIRECTORY);                           }                        else                           {                              setColor(Colors::C_FILE);                              mvwprintw(window_, counter, 0, " %s%s", filename.c_str(), spacestr.c_str());                              unSetColor(Colors::C_FILE);                           }                        ::wattroff(window_, A_REVERSE);                     }                  else                     {                        if (isDirectory)                           {                              setColor(Colors::C_DIRECTORY);                              mvwprintw(window_, counter, 0, " %s\n", filename.c_str());                              unSetColor(Colors::C_DIRECTORY);                           }                        else                           {                              setColor(Colors::C_FILE);                              mvwprintw(window_, counter, 0, " %s\n", filename.c_str());                              unSetColor(Colors::C_FILE);                           }                     }                  counter++;               }         }         void fileList::getDirectory()         {            entries_.clear();            fs::directory_iterator end_iter;            // Fill the list, not caring if something cannot be            // accessed.            fs::path currentpath(currentDirectory_);            std::vector<boost::filesystem::path> directories;            std::vector<boost::filesystem::path> files;            for (fs::directory_iterator iter(currentpath);                 iter != end_iter;                 iter++ )               {                  try                     {                        fs::path p = *iter;                        std::string filename = p.leaf();                        if (filename.size() > 0)                           {                              bool isdir = fs::is_directory(p);                              // Do not show entries that start with a dot,                              // as they are hidden.                              if (filename[0] == '.')                                 {                                    continue;                                 }                              // Do not show files that are not                              // torrent files.                              if ((!isdir) && (filename.find(".torrent") == std::string::npos))                                 {                                    continue;                                 }                              if (isdir)                                 {                                    directories.push_back(p);                                 }                              else                                 {                                    files.push_back(p);                                 }                           }                     }                  catch (const std::exception & ex)                     {                     }               }            // Sort the result by name.            std::sort(files.begin(), files.end(), filename_compare);            std::sort(directories.begin(), directories.end(), filename_compare);            entries_.push_back(fs::path(".."));            std::copy(directories.begin(), directories.end(), back_inserter(entries_));            std::copy(files.begin(),       files.end(),       back_inserter(entries_));         }         void fileList::moveDown()         {            const t_int list_max = entries_.size();            if (currentPosition_ < (numberOfLines_-1))               {                  currentPosition_++;                  if (entries_.size() > 0)                     {                        if (currentPosition_ > (list_max-1))                           {                              currentPosition_--;                           }                     }               }            else               {                  if (positionWindowEnd_ < list_max)                     {                        positionWindowStart_++;                        positionWindowEnd_++;                     }               }         }         void fileList::moveUp()         {            if (currentPosition_ > 0)               {                  currentPosition_--;               }            else               {                  if ((positionWindowStart_-1) >= 0)                     {                        positionWindowStart_--;                        positionWindowEnd_--;                     }               }         }         void fileList::toStart()         {            currentPosition_     = 0;         }         void fileList::toEnd()         {            currentPosition_ = (numberOfLines_-1);            t_int max_position = entries_.size();            if (max_position > 0)               {                  max_position--;               }            if (currentPosition_ > max_position)               {                  currentPosition_ = max_position;               }         }         bool fileList::getSelection(fs::path & _p) const         {            bool status = false;            if (entries_.size() == 0)               {                  return status;               }            t_uint current = positionWindowStart_ + currentPosition_;            if (current == 0)               {                  // Handle ".."                  fs::path current(currentDirectory_);                  try                     {                        _p = current.branch_path();                        status = true;                     }                  catch (...)                     {                        _p     = fs::path(currentDirectory_);                        status = false;                     }               }            else               {                  std::vector<fs::path>::const_iterator iter = entries_.begin();                  if ((iter + current) != entries_.end())                     {                        iter  += current;                        _p     = *iter;                        status = true;                     }               }            return status;         }         windowSize fileList::calculateDimenstions(windowSize const& _ws) const         {            // Use the parents dimensions.            windowSize ws = _ws;            return ws;         }         dialog::RESULT fileList::showHelp()         {            // Show a help window on the middle of the screen.            std::vector<std::string> helpText;            helpText.push_back("Help");            helpText.push_back("----");            helpText.push_back("    ");            std::string keyDescr;            if (helpWindow::generateHelpForKey(kmap_,                                               keyMapping::K_DOWN,                                               "",                                               keyDescr,                                               false))               {                  helpText.push_back(keyDescr);                  helpText.push_back("  to move down");               }            if (helpWindow::generateHelpForKey(kmap_,                                               keyMapping::K_UP,                                               "",                                               keyDescr,                                               false))               {                  helpText.push_back(keyDescr);                  helpText.push_back("  to move up");               }            if (helpWindow::generateHelpForKey(kmap_,                                               keyMapping::K_SELECT,                                               "",                                               keyDescr,                                               false))               {                  helpText.push_back(keyDescr);                  helpText.push_back("  to select a torrent file to load or enter dir");               }            if (helpWindow::generateHelpForKey(kmap_,                                               keyMapping::K_QUIT,                                               "",                                               keyDescr,                                               false))               {                  helpText.push_back(keyDescr);                  helpText.push_back("  to abort loading");               }            helpText.push_back(" ");            helpText.push_back("Press shift + character to jump to the filename");            helpText.push_back("or directory beginning with this chracter.");            helpText.push_back(" ");            helpWindow hw(kmap_, helpText);            return hw.run();         }         void fileList::moveTo(t_int const _key)         {            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();                  if (filename.size() >= 1)                     {                        t_int c = std::toupper(filename[0]);                        if (c == _key)                           {                              currentPosition_ = counter;                              refresh();                              break;                           }                     }                  counter++;               }         }         fileList::~fileList()         {            destroy();         }                  bool filename_compare(boost::filesystem::path const& _p1,                               boost::filesystem::path const& _p2)         {            return (_p1.string() < _p2.string());         }               } // namespace cli   } // namespace UI} // namespace btg

⌨️ 快捷键说明

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