📄 mainwindow.cpp
字号:
/* * 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: mainwindow.cpp,v 1.1.4.6 2007/09/17 15:34:50 wojci Exp $ */#include "mainwindow.h"#include <bcore/t_string.h>#include <bcore/logmacro.h>namespace btg{ namespace UI { namespace cli { statusEntry::statusEntry(btg::core::Status const& _s) : status(_s), marked(false), updated(true) { } statusEntry::statusEntry() : status(), marked(false), updated(false) { } /* */ /* */ /* */ statusList::statusList() : changed_(false), statusList_() { } void statusList::get(std::vector<statusEntry> & _list) const { std::map<t_int, statusEntry>::const_iterator iter; for (iter = statusList_.begin(); iter != statusList_.end(); iter++) { _list.push_back(iter->second); } } bool statusList::get(t_uint const _context_id, btg::core::Status & _status) const { bool status = false; std::map<t_int, statusEntry>::const_iterator iter = statusList_.find(_context_id); if (iter != statusList_.end()) { _status = iter->second.status; status = true; } return status; } bool statusList::getAtPosition(t_uint const _position, btg::core::Status & _status) const { bool status = false; if (statusList_.size() == 0) { return status; } std::map<t_int, statusEntry>::const_iterator iter; t_uint counter = 0; for (iter = statusList_.begin(); iter != statusList_.end(); iter++) { if (counter == _position) { status = true; break; } counter++; } if (status) { _status = iter->second.status; } return status; } void statusList::mark(t_uint const _position) { if (statusList_.size() == 0) { return; } std::map<t_int, statusEntry>::iterator iter; t_uint counter = 0; for (iter = statusList_.begin(); iter != statusList_.end(); iter++) { if (counter == _position) { if (iter->second.marked) { iter->second.marked = false; } else { iter->second.marked = true; } break; } counter++; } } void statusList::markAll() { std::map<t_int, statusEntry>::iterator iter; for (iter = statusList_.begin(); iter != statusList_.end(); iter++) { if (iter->second.marked) { iter->second.marked = false; } else { iter->second.marked = true; } } } void statusList::getMarked(std::vector<t_int> & _id_list) const { std::map<t_int, statusEntry>::const_iterator iter; for (iter = statusList_.begin(); iter != statusList_.end(); iter++) { if (iter->second.marked) { _id_list.push_back(iter->first); } } } void statusList::clearMark() { std::map<t_int, statusEntry>::iterator iter; for (iter = statusList_.begin(); iter != statusList_.end(); iter++) { iter->second.marked = false; } } void statusList::resetUpdated() { std::map<t_int, statusEntry>::iterator iter; for (iter = statusList_.begin(); iter != statusList_.end(); iter++) { iter->second.updated = false; } } void statusList::removeDead() { std::map<t_int, statusEntry>::iterator iter = statusList_.begin(); while (iter != statusList_.end()) { std::map<t_int, statusEntry>::iterator killIter = iter++; if (!killIter->second.updated) { statusList_.erase(killIter); } } } void statusList::update(std::vector<btg::core::Status> const& _list) { std::vector<btg::core::Status>::const_iterator iter; std::vector<btg::core::Status> new_entries; // Find out if any IDs were removed. resetUpdated(); for (iter = _list.begin(); iter != _list.end(); iter++) { t_int id = iter->contextID(); std::map<t_int, statusEntry>::iterator dst_iter = statusList_.find(id); if (dst_iter != statusList_.end()) { // Update context. dst_iter->second.status = *iter; dst_iter->second.updated = true; } else { // New context. // This also sets the updated flag. new_entries.push_back(*iter); BTG_NOTICE("Added new context"); } } if (new_entries.size() > 0) { BTG_NOTICE("Context number changed - add"); changed_ = true; } std::vector<btg::core::Status>::iterator iiter; for (iiter = new_entries.begin(); iiter != new_entries.end(); iiter++) { std::pair<t_int, statusEntry> p(iiter->contextID(), statusEntry(*iiter)); statusList_.insert(p); } // Remove dead entries. removeDead(); } void statusList::remove(std::vector<t_int> const& _id_list) { std::vector<t_int>::const_iterator iter; for (iter = _id_list.begin(); iter != _id_list.end(); iter++) { std::map<t_int, statusEntry>::iterator erase_iter = statusList_.find(*iter); if (erase_iter != statusList_.end()) { BTG_NOTICE("Removing " << erase_iter->second.status.contextID()); statusList_.erase(erase_iter); } } if (_id_list.size() > 0) { BTG_NOTICE("Context number changed - remove"); changed_ = true; } } void statusList::clear() { statusList_.clear(); } void statusList::resetChanged() { BTG_NOTICE("Reseting context change flag"); changed_ = false; } bool statusList::changed() const { return changed_; } t_uint statusList::size() const { return statusList_.size(); } statusList::~statusList() { statusList_.clear(); } /* */ /* */ /* */ mainWindow::mainWindow(keyMapping const& _kmap) : baseWindow(_kmap), numberOfLines_(0), list_(), positionWindowStart_(0), positionWindowEnd_(0), currentPosition_(0) { } bool mainWindow::init(windowSize const& _ws) { bool status = baseWindow::init(_ws); if (status) { numberOfLines_ = height_-1; } return status; } void mainWindow::resize(windowSize const& _ws) { destroy(); init(_ws); refresh(); } void mainWindow::refresh() { if (window_ == 0) { return; } drawList(); wrefresh(window_); } void mainWindow::drawList() { std::vector<statusEntry> lst; list_.get(lst); if (lst.size() == 0) { // No point in displaying an empty list. return; } setColor(Colors::C_NORMAL); std::vector<statusEntry>::const_iterator iterBeg = lst.begin(); std::vector<statusEntry>::const_iterator iterEnd = lst.begin(); if (positionWindowEnd_ == 0) { positionWindowEnd_ = numberOfLines_; } if (positionWindowEnd_ > static_cast<t_int>(lst.size())) { positionWindowEnd_ = lst.size(); } // Move the iterator the the start of the window to display. for (t_int counter = 0; counter < positionWindowStart_; counter++) { iterBeg++; } // Move the iterator the the end of the window to display. for (t_int counter = 0; counter < positionWindowEnd_; counter++) { iterEnd++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -