From c486fc514c9d70a58c5ea295cbefb05f97c2be40 Mon Sep 17 00:00:00 2001 From: Gustavo Carneiro Date: Wed, 15 Jul 2020 19:38:34 -0300 Subject: [PATCH] Move CompactHistoryType class to a new file. --- src/CMakeLists.txt | 1 + src/CompactHistoryType.cpp | 54 ++++++++++++++++++++++++++++++++++++++ src/CompactHistoryType.h | 46 ++++++++++++++++++++++++++++++++ src/History.cpp | 28 -------------------- src/History.h | 14 +--------- 5 files changed, 102 insertions(+), 41 deletions(-) create mode 100644 src/CompactHistoryType.cpp create mode 100644 src/CompactHistoryType.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8e121f26..d4d96a60 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -85,6 +85,7 @@ set(konsoleprivate_SRCS ${sessionadaptors_SRCS} HistoryType.cpp HistoryTypeNone.cpp HistoryTypeFile.cpp + CompactHistoryType.cpp HistorySizeDialog.cpp widgets/HistorySizeWidget.cpp widgets/IncrementalSearchBar.cpp diff --git a/src/CompactHistoryType.cpp b/src/CompactHistoryType.cpp new file mode 100644 index 00000000..29dedd21 --- /dev/null +++ b/src/CompactHistoryType.cpp @@ -0,0 +1,54 @@ +/* + This file is part of Konsole, an X terminal. + Copyright 1997,1998 by Lars Doelle + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + +// Own +#include "CompactHistoryType.h" + +#include "CompactHistoryScroll.h" + +using namespace Konsole; + +CompactHistoryType::CompactHistoryType(unsigned int nbLines) : + _maxLines(nbLines) +{ +} + +bool CompactHistoryType::isEnabled() const +{ + return true; +} + +int CompactHistoryType::maximumLineCount() const +{ + return _maxLines; +} + +HistoryScroll *CompactHistoryType::scroll(HistoryScroll *old) const +{ + if (old != nullptr) { + auto *oldBuffer = dynamic_cast(old); + if (oldBuffer != nullptr) { + oldBuffer->setMaxNbLines(_maxLines); + return oldBuffer; + } + delete old; + } + return new CompactHistoryScroll(_maxLines); +} diff --git a/src/CompactHistoryType.h b/src/CompactHistoryType.h new file mode 100644 index 00000000..077ad94d --- /dev/null +++ b/src/CompactHistoryType.h @@ -0,0 +1,46 @@ +/* + This file is part of Konsole, an X terminal. + Copyright 1997,1998 by Lars Doelle + + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + +#ifndef COMPACTHISTORYTYPE_H +#define COMPACTHISTORYTYPE_H + +#include "HistoryType.h" +#include "konsoleprivate_export.h" + +namespace Konsole +{ + +class KONSOLEPRIVATE_EXPORT CompactHistoryType : public HistoryType +{ +public: + explicit CompactHistoryType(unsigned int nbLines); + + bool isEnabled() const override; + int maximumLineCount() const override; + + HistoryScroll *scroll(HistoryScroll *) const override; + +protected: + unsigned int _maxLines; +}; + +} + +#endif diff --git a/src/History.cpp b/src/History.cpp index a17ba8da..39a06b57 100644 --- a/src/History.cpp +++ b/src/History.cpp @@ -56,31 +56,3 @@ using namespace Konsole; of cells and line/column indexed read access to the scroll at constant costs. */ - -CompactHistoryType::CompactHistoryType(unsigned int nbLines) : - _maxLines(nbLines) -{ -} - -bool CompactHistoryType::isEnabled() const -{ - return true; -} - -int CompactHistoryType::maximumLineCount() const -{ - return _maxLines; -} - -HistoryScroll *CompactHistoryType::scroll(HistoryScroll *old) const -{ - if (old != nullptr) { - auto *oldBuffer = dynamic_cast(old); - if (oldBuffer != nullptr) { - oldBuffer->setMaxNbLines(_maxLines); - return oldBuffer; - } - delete old; - } - return new CompactHistoryScroll(_maxLines); -} diff --git a/src/History.h b/src/History.h index 1820f0f4..49c5e4d6 100644 --- a/src/History.h +++ b/src/History.h @@ -45,6 +45,7 @@ #include "HistoryType.h" #include "HistoryTypeNone.h" #include "HistoryTypeFile.h" +#include "CompactHistoryType.h" // Konsole #include "Character.h" @@ -57,19 +58,6 @@ namespace Konsole { // where history lines are allocated in (avoids heap fragmentation) ////////////////////////////////////////////////////////////////////// -class KONSOLEPRIVATE_EXPORT CompactHistoryType : public HistoryType -{ -public: - explicit CompactHistoryType(unsigned int nbLines); - - bool isEnabled() const override; - int maximumLineCount() const override; - - HistoryScroll *scroll(HistoryScroll *) const override; - -protected: - unsigned int _maxLines; -}; } #endif // HISTORY_H