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
bc60a534
Commit
bc60a534
authored
Jan 31, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Feb 20, 2021
Browse files
project-plugin: Allow renaming files
parent
de7bbd68
Changes
5
Hide whitespace changes
Inline
Side-by-side
addons/project/kateprojectitem.cpp
View file @
bc60a534
...
...
@@ -12,10 +12,12 @@
#include <QFile>
#include <QFileInfo>
#include <QIcon>
#include <QMessageBox>
#include <QMimeDatabase>
#include <QThread>
#include <KIconUtils>
#include <KLocalizedString>
#include <KTextEditor/Document>
...
...
@@ -131,3 +133,28 @@ QIcon *KateProjectItem::icon() const
return
m_icon
;
}
void
KateProjectItem
::
setData
(
const
QVariant
&
value
,
int
role
)
{
if
(
role
==
Qt
::
EditRole
)
{
auto
newFileName
=
value
.
toString
();
if
(
newFileName
.
isEmpty
())
return
;
auto
oldFileName
=
data
(
Qt
::
DisplayRole
).
toString
();
auto
oldName
=
data
(
Qt
::
UserRole
).
toString
();
QString
newName
=
oldName
;
newName
.
replace
(
oldFileName
,
newFileName
);
if
(
!
QFile
::
rename
(
oldName
,
newName
))
{
QMessageBox
::
critical
(
nullptr
,
i18n
(
"Error"
),
i18n
(
"File name already exists"
));
return
;
}
// change internal path
setData
(
oldName
,
Qt
::
UserRole
);
setData
(
oldName
,
Qt
::
ToolTipRole
);
}
QStandardItem
::
setData
(
value
,
role
);
}
addons/project/kateprojectitem.h
View file @
bc60a534
...
...
@@ -53,6 +53,7 @@ public:
* @return data for role
*/
QVariant
data
(
int
role
=
Qt
::
UserRole
+
1
)
const
override
;
void
setData
(
const
QVariant
&
value
,
int
role
)
override
;
/**
* We want case-insensitive sorting and directories first!
...
...
addons/project/kateprojecttreeviewcontextmenu.cpp
View file @
bc60a534
...
...
@@ -28,6 +28,8 @@
#include <QProcess>
#include <QStandardPaths>
#include "kateprojectviewtree.h"
KateProjectTreeViewContextMenu
::
KateProjectTreeViewContextMenu
()
{
}
...
...
@@ -61,7 +63,7 @@ static bool isGit(const QString &filename)
return
isGit
;
}
void
KateProjectTreeViewContextMenu
::
exec
(
const
QString
&
filename
,
const
QPoint
&
pos
,
QWidget
*
parent
)
void
KateProjectTreeViewContextMenu
::
exec
(
const
QString
&
filename
,
const
QModelIndex
&
index
,
const
QPoint
&
pos
,
QWidget
*
parent
)
{
/**
* Create context menu
...
...
@@ -124,6 +126,8 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint
job
->
start
();
};
auto
rename
=
menu
.
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"edit-rename"
)),
i18n
(
"&Rename"
));
/**
* run menu and handle the triggered action
*/
...
...
@@ -141,6 +145,8 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint
QDialog
*
dlg
=
new
KPropertiesDialog
(
fileItem
);
dlg
->
setAttribute
(
Qt
::
WA_DeleteOnClose
);
dlg
->
show
();
}
else
if
(
action
==
rename
)
{
static_cast
<
KateProjectViewTree
*>
(
parent
)
->
edit
(
index
);
}
else
{
// One of the git actions was triggered
}
...
...
addons/project/kateprojecttreeviewcontextmenu.h
View file @
bc60a534
...
...
@@ -12,6 +12,7 @@
#include <QString>
class
QWidget
;
class
QModelIndex
;
class
KateProjectTreeViewContextMenu
{
...
...
@@ -32,7 +33,7 @@ public:
* our project.
* @return project
*/
void
exec
(
const
QString
&
filename
,
const
QPoint
&
pos
,
QWidget
*
parent
);
void
exec
(
const
QString
&
filename
,
const
QModelIndex
&
index
,
const
QPoint
&
pos
,
QWidget
*
parent
);
protected:
};
...
...
addons/project/kateprojectviewtree.cpp
View file @
bc60a534
...
...
@@ -159,7 +159,7 @@ void KateProjectViewTree::contextMenuEvent(QContextMenuEvent *event)
}
KateProjectTreeViewContextMenu
menu
;
menu
.
exec
(
filePath
,
viewport
()
->
mapToGlobal
(
event
->
pos
()),
this
);
menu
.
exec
(
filePath
,
index
,
viewport
()
->
mapToGlobal
(
event
->
pos
()),
this
);
event
->
accept
();
}
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