Commit 22ad9e2f authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

share code for icon with filetree

there we had an emblem adding, that didn't work since
long as we missed to use an existing icon

just removed that part, now filetree and tabbar
use exactly the same icons

if the loading shall be slow, we can cache this
inside the helper function
parent dff451a7
Pipeline #199136 passed with stage
in 13 minutes and 27 seconds
......@@ -12,6 +12,7 @@ target_compile_definitions(katefiletreeplugin PRIVATE TRANSLATION_DOMAIN="katefi
target_link_libraries(
katefiletreeplugin
PUBLIC
kateprivate
KF5::I18n
KF5::TextEditor
KF5::GuiAddons
......
......@@ -5,8 +5,9 @@ target_include_directories(filetree_model_test PRIVATE ${CMAKE_CURRENT_SOURCE_DI
find_package(Qt${QT_MAJOR_VERSION}Test ${QT_MIN_VERSION} QUIET REQUIRED)
target_link_libraries(
filetree_model_test
filetree_model_test
PRIVATE
kateprivate
KF5::GuiAddons
KF5::I18n
KF5::TextEditor
......@@ -14,10 +15,10 @@ target_link_libraries(
)
target_sources(
filetree_model_test
filetree_model_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../katefiletreemodel.cpp
filetree_model_test.cpp
filetree_model_test.cpp
document_dummy.cpp
)
......
......@@ -25,6 +25,7 @@
#include <ktexteditor/editor.h>
#include "katefiletreedebug.h"
#include "ktexteditor_utils.h"
static constexpr int MaxHistoryItems = 10;
......@@ -1307,23 +1308,10 @@ void KateFileTreeModel::updateItemPathAndHost(ProxyItem *item)
void KateFileTreeModel::setupIcon(ProxyItem *item)
{
Q_ASSERT(item != nullptr);
Q_ASSERT(item->doc() != nullptr);
QString icon_name;
if (item->flag(ProxyItem::Modified)) {
icon_name = QStringLiteral("document-save");
} else {
const QUrl url(item->path());
icon_name = QMimeDatabase().mimeTypeForFile(url.path(), QMimeDatabase::MatchExtension).iconName();
}
QIcon icon = QIcon::fromTheme(icon_name);
if (item->flag(ProxyItem::ModifiedExternally) || item->flag(ProxyItem::DeletedExternally)) {
icon = KIconUtils::addOverlay(icon, QIcon(QLatin1String("emblem-important")), Qt::TopLeftCorner);
}
item->setIcon(icon);
// use common method as e.g. in tabbar, too
item->setIcon(Utils::iconForDocument(item->doc()));
}
void KateFileTreeModel::resetHistory()
......
......@@ -102,6 +102,7 @@ target_sources(
signal_watcher.cpp
gitprocess.cpp
quickdialog.cpp
ktexteditor_utils.cpp
data/kateprivate.qrc
)
......
......@@ -7,6 +7,7 @@
#include "katetabbar.h"
#include "kateapp.h"
#include "ktexteditor_utils.h"
#include "tabmimedata.h"
#include <QApplication>
......@@ -295,22 +296,8 @@ void KateTabBar::setTabDocument(int idx, KTextEditor::Document *doc)
void KateTabBar::setModifiedStateIcon(int idx, KTextEditor::Document *doc)
{
// simple modified indicator if modified
QIcon tabIcon;
if (doc->isModified()) {
tabIcon = QIcon::fromTheme(QStringLiteral("modified"));
}
// else mime-type icon
else {
tabIcon = QIcon::fromTheme(QMimeDatabase().mimeTypeForName(doc->mimeType()).iconName());
}
// ensure we always have a valid icon
if (tabIcon.isNull()) {
tabIcon = QIcon::fromTheme(QStringLiteral("text-plain"));
}
setTabIcon(idx, tabIcon);
// use common method, as e.g. in filetree plugin, too
setTabIcon(idx, Utils::iconForDocument(doc));
}
void KateTabBar::setCurrentDocument(KTextEditor::Document *doc)
......
/*
SPDX-FileCopyrightText: 2022 Christoph Cullmann <cullmann@kde.org>
SPDX-FileCopyrightText: 2022 Waqar Ahmed <waqar.17a@gmail.com>
SPDX-License-Identifier: MIT
*/
#include "ktexteditor_utils.h"
#include <QMimeDatabase>
namespace Utils
{
QIcon iconForDocument(KTextEditor::Document *doc)
{
// simple modified indicator if modified
QIcon icon;
if (doc->isModified()) {
icon = QIcon::fromTheme(QStringLiteral("modified"));
}
// else mime-type icon
else {
icon = QIcon::fromTheme(QMimeDatabase().mimeTypeForName(doc->mimeType()).iconName());
}
// ensure we always have a valid icon
if (icon.isNull()) {
icon = QIcon::fromTheme(QStringLiteral("text-plain"));
}
return icon;
}
}
......@@ -3,12 +3,15 @@
SPDX-License-Identifier: MIT
*/
#include "kateprivate_export.h"
#include <KTextEditor/ConfigInterface>
#include <KTextEditor/Editor>
#include <KTextEditor/MainWindow>
#include <KTextEditor/View>
#include <QFontDatabase>
#include <QIcon>
#include <QPointer>
#include <QScrollBar>
......@@ -79,4 +82,11 @@ inline QFont viewFont(KTextEditor::View *view)
return editorFont();
}
/**
* Return a matching icon for the given document.
* We use the mime type icon for unmodified stuff and the modified one for modified docs.
* @param doc document to get icon for
* @return icon, always valid
*/
KATE_PRIVATE_EXPORT QIcon iconForDocument(KTextEditor::Document *doc);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment