Commit eb99ab6a authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Show only file name in status tree

parent 4653a602
......@@ -6,6 +6,7 @@
#include "gitstatusmodel.h"
#include <QDebug>
#include <QFileInfo>
#include <QFont>
#include <QIcon>
#include <QMimeDatabase>
......@@ -115,9 +116,20 @@ QVariant GitStatusModel::data(const QModelIndex &index, int role) const
}
if (role == Qt::DisplayRole) {
if (index.column() == 0) {
const auto filename = QFileInfo(m_nodes[rootIndex].at(row).file).fileName();
if (filename.isEmpty()) {
return m_nodes[rootIndex].at(row).file;
}
return filename;
} else {
return QString(QLatin1Char(m_nodes[rootIndex].at(row).statusChar));
}
} else if (role == FileNameRole) {
return m_nodes[rootIndex].at(row).file;
} else if (role == Qt::DecorationRole) {
return QIcon::fromTheme(QMimeDatabase().mimeTypeForFile(m_nodes[rootIndex].at(row).file, QMimeDatabase::MatchExtension).iconName());
if (index.column() == 0)
return QIcon::fromTheme(QMimeDatabase().mimeTypeForFile(m_nodes[rootIndex].at(row).file, QMimeDatabase::MatchExtension).iconName());
} else if (role == Role::TreeItemType) {
return ItemType::NodeFile;
} else if (role == Qt::TextAlignmentRole) {
......
......@@ -16,7 +16,7 @@ public:
explicit GitStatusModel(QObject *parent);
enum ItemType { NodeStage = 0, NodeChanges, NodeConflict, NodeUntrack, NodeFile };
enum Role { TreeItemType = Qt::UserRole };
enum Role { TreeItemType = Qt::UserRole + 1, FileNameRole };
public:
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
......
......@@ -16,6 +16,7 @@
#include <QDialog>
#include <QEvent>
#include <QFileInfo>
#include <QHeaderView>
#include <QInputMethodEvent>
#include <QLineEdit>
#include <QMenu>
......@@ -36,6 +37,7 @@
#include <KTextEditor/Message>
#include <KTextEditor/View>
GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow, KateProjectPluginView *pluginView)
: m_project(project)
, m_mainWin(mainWindow)
......@@ -83,6 +85,9 @@ GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow,
m_treeView->setModel(m_model);
m_treeView->installEventFilter(this);
m_treeView->header()->setStretchLastSection(false);
m_treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
setLayout(layout);
connect(&m_gitStatusWatcher, &QFutureWatcher<GitUtils::GitParsedStatus>::finished, this, &GitWidget::parseStatusReady);
......@@ -534,7 +539,7 @@ QMenu *GitWidget::stashMenu()
void GitWidget::treeViewContextMenuEvent(QContextMenuEvent *e)
{
if (auto selModel = m_treeView->selectionModel()) {
if (selModel->selectedIndexes().count() > 1) {
if (selModel->selectedRows().count() > 1) {
return selectedContextMenu(e);
}
}
......@@ -589,7 +594,7 @@ void GitWidget::treeViewContextMenuEvent(QContextMenuEvent *e)
auto discardAct = untracked ? menu.addAction(i18n("Remove")) : menu.addAction(i18n("Discard"));
auto act = menu.exec(m_treeView->viewport()->mapToGlobal(e->pos()));
const QString file = m_gitPath + idx.data().toString();
const QString file = m_gitPath + idx.data(GitStatusModel::FileNameRole).toString();
if (act == stageAct) {
if (staged) {
return unstage({file});
......@@ -598,13 +603,13 @@ void GitWidget::treeViewContextMenuEvent(QContextMenuEvent *e)
} else if (act == discardAct && !untracked) {
discard({file});
} else if (act == openAtHead && !untracked) {
openAtHEAD(idx.data().toString());
openAtHEAD(idx.data(GitStatusModel::FileNameRole).toString());
} else if (act == showDiffAct && !untracked) {
showDiff(file, staged);
} else if (act == discardAct && untracked) {
clean({file});
} else if (act == launchDifftoolAct) {
launchExternalDiffTool(idx.data().toString(), staged);
launchExternalDiffTool(idx.data(GitStatusModel::FileNameRole).toString(), staged);
}
} else if (type == GitStatusModel::NodeStage) {
QMenu menu;
......@@ -642,7 +647,7 @@ void GitWidget::selectedContextMenu(QContextMenuEvent *e)
} else {
selectionHasChangedItems = true;
}
files.append(idx.data().toString());
files.append(idx.data(GitStatusModel::FileNameRole).toString());
}
}
......
Markdown is supported
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