Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
d8107866
Commit
d8107866
authored
Feb 27, 2021
by
Waqar Ahmed
Browse files
Use gitutils in contextmenu and show history action if git
parent
3a4950bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/project/kateprojecttreeviewcontextmenu.cpp
View file @
d8107866
...
...
@@ -6,6 +6,7 @@
*/
#include "kateprojecttreeviewcontextmenu.h"
#include "git/gitutils.h"
#include <KApplicationTrader>
#include <KIO/ApplicationLauncherJob>
...
...
@@ -18,14 +19,11 @@
#include <QApplication>
#include <QClipboard>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QIcon>
#include <QMenu>
#include <QMimeDatabase>
#include <QMimeType>
#include <QProcess>
#include <QStandardPaths>
#include "kateprojectviewtree.h"
...
...
@@ -38,31 +36,6 @@ KateProjectTreeViewContextMenu::~KateProjectTreeViewContextMenu()
{
}
static
bool
isGit
(
const
QString
&
filename
)
{
QFileInfo
fi
(
filename
);
QDir
dir
(
fi
.
absoluteDir
());
QProcess
git
;
git
.
setWorkingDirectory
(
dir
.
absolutePath
());
QStringList
args
;
// git ls-files -z results a bytearray where each entry is \0-terminated.
// NOTE: Without -z, Umlauts such as "Der Bäcker/Das Brötchen.txt" do not work (#389415, #402213)
args
<<
QStringLiteral
(
"ls-files"
)
<<
QStringLiteral
(
"-z"
)
<<
fi
.
fileName
();
git
.
start
(
QStringLiteral
(
"git"
),
args
,
QProcess
::
ReadOnly
);
bool
isGit
=
false
;
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
const
QList
<
QByteArray
>
byteArrayList
=
git
.
readAllStandardOutput
().
split
(
'\0'
);
const
QString
fn
=
fi
.
fileName
();
for
(
const
QByteArray
&
byteArray
:
byteArrayList
)
{
if
(
fn
==
QString
::
fromUtf8
(
byteArray
))
{
isGit
=
true
;
break
;
}
}
}
return
isGit
;
}
void
KateProjectTreeViewContextMenu
::
exec
(
const
QString
&
filename
,
const
QModelIndex
&
index
,
const
QPoint
&
pos
,
QWidget
*
parent
)
{
/**
...
...
@@ -103,14 +76,15 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
*/
auto
filePropertiesAction
=
menu
.
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"dialog-object-properties"
)),
i18n
(
"Properties"
));
auto
history
=
menu
.
addAction
(
i18n
(
"Show File History"
));
QAction
*
fileHistory
=
nullptr
;
/**
* Git menu
*/
KMoreToolsMenuFactory
menuFactory
(
QStringLiteral
(
"kate/addons/project/git-tools"
));
QMenu
gitMenu
;
// must live as long as the maybe filled menu items should live
if
(
isGit
(
filename
))
{
if
(
GitUtils
::
isGitRepo
(
QFileInfo
(
filename
).
absolutePath
()))
{
fileHistory
=
menu
.
addAction
(
i18n
(
"Show File History"
));
menuFactory
.
fillMenuFromGroupingNames
(
&
gitMenu
,
{
QLatin1String
(
"git-clients-and-actions"
)},
QUrl
::
fromLocalFile
(
filename
));
menu
.
addSection
(
i18n
(
"Git:"
));
const
auto
gitActions
=
gitMenu
.
actions
();
...
...
@@ -149,7 +123,7 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
dlg
->
show
();
}
else
if
(
action
==
rename
)
{
static_cast
<
KateProjectViewTree
*>
(
parent
)
->
edit
(
index
);
}
else
if
(
action
==
h
istory
)
{
}
else
if
(
action
==
fileH
istory
)
{
showFileHistory
(
index
.
data
(
Qt
::
UserRole
).
toString
());
}
else
{
// One of the git actions was triggered
...
...
addons/project/kateprojecttreeviewcontextmenu.h
View file @
d8107866
...
...
@@ -41,8 +41,6 @@ public:
* emits on clicking Menu->Show File History
*/
Q_SIGNAL
void
showFileHistory
(
const
QString
&
file
);
protected:
};
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment