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
a3da7eb9
Commit
a3da7eb9
authored
May 18, 2021
by
Krzysztof Stokop
Browse files
removing "directory removing"
parent
f2f91b13
Changes
3
Hide whitespace changes
Inline
Side-by-side
addons/project/kateprojecttreeviewcontextmenu.cpp
View file @
a3da7eb9
...
...
@@ -61,6 +61,7 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
QAction
*
addFile
=
nullptr
;
QAction
*
addFolder
=
nullptr
;
QAction
*
fileDelete
=
nullptr
;
if
(
index
.
data
(
KateProjectItem
::
TypeRole
).
toInt
()
==
KateProjectItem
::
Directory
)
{
addFile
=
menu
.
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"document-new"
)),
i18n
(
"Add File"
));
addFolder
=
menu
.
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"folder-new"
)),
i18n
(
"Add Folder"
));
...
...
@@ -99,10 +100,13 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
*/
auto
openContaingFolderAction
=
menu
.
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"document-open-folder"
)),
i18n
(
"&Open Containing Folder"
));
/**
* File delete dialog
*/
QAction
*
fileDelete
=
menu
.
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"delete"
)),
i18n
(
"Delete"
));
if
(
index
.
data
(
KateProjectItem
::
TypeRole
).
toInt
()
==
KateProjectItem
::
File
)
{
/**
* File delete dialog
*/
fileDelete
=
menu
.
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"delete"
)),
i18n
(
"Delete"
));
}
/**
* File Properties Dialog
...
...
@@ -137,8 +141,6 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
auto
handleDeleteFile
=
[
parent
,
index
](
const
QString
&
path
)
{
QFileInfo
fileInfo
(
path
);
//message box
const
QString
title
=
i18n
(
"Confirm deleting: %1"
,
path
);
const
QString
text
=
i18n
(
"Do you want to delete: %1 ?"
,
path
);
...
...
@@ -146,30 +148,17 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
if
(
QMessageBox
::
Yes
==
QMessageBox
::
question
(
parent
,
title
,
text
,
QMessageBox
::
No
|
QMessageBox
::
Yes
,
QMessageBox
::
Yes
))
{
const
QList
<
KTextEditor
::
Document
*
>
openDocuments
=
KTextEditor
::
Editor
::
instance
()
->
application
()
->
documents
();
if
(
fileInfo
.
isDir
())
//for dir
{
//has opend files ?
for
(
auto
doc
:
openDocuments
)
if
(
QUrl
(
path
).
isParentOf
(
doc
->
url
().
adjusted
(
QUrl
::
RemoveScheme
)))
KTextEditor
::
Editor
::
instance
()
->
application
()
->
closeDocument
(
doc
);
//KTextEditor::Editor::instance()->application()->documentWillBeDeleted(doc);
parent
->
removeDirectory
(
index
,
path
);
}
else
//for file
//if is open, close
for
(
auto
doc
:
openDocuments
)
{
//if is open, close
for
(
auto
doc
:
openDocuments
)
if
(
doc
->
url
().
adjusted
(
QUrl
::
RemoveScheme
)
==
QUrl
(
path
).
adjusted
(
QUrl
::
RemoveScheme
))
{
if
(
doc
->
url
().
adjusted
(
QUrl
::
RemoveScheme
)
==
QUrl
(
path
).
adjusted
(
QUrl
::
RemoveScheme
))
{
KTextEditor
::
Editor
::
instance
()
->
application
()
->
closeDocument
(
doc
);
// KTextEditor::Editor::instance()->application()->documentWillBeDeleted(doc);
break
;
}
KTextEditor
::
Editor
::
instance
()
->
application
()
->
closeDocument
(
doc
);
break
;
}
parent
->
removeFile
(
index
,
path
);
}
parent
->
removeFile
(
index
,
path
);
}
};
...
...
@@ -198,7 +187,7 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
handleOpenWith
(
action
,
filename
);
}
else
if
(
action
==
openContaingFolderAction
)
{
KIO
::
highlightInFileManager
({
QUrl
::
fromLocalFile
(
filename
)});
}
else
if
(
action
==
fileDelete
)
{
}
else
if
(
fileDelete
&&
action
==
fileDelete
)
{
handleDeleteFile
(
filename
);
}
else
if
(
action
==
filePropertiesAction
)
{
// code copied and adapted from frameworks/kio/src/filewidgets/knewfilemenu.cpp
...
...
addons/project/kateprojectviewtree.cpp
View file @
a3da7eb9
...
...
@@ -190,31 +190,6 @@ void KateProjectViewTree::removeFile(const QModelIndex& idx, const QString& full
}
}
void
KateProjectViewTree
::
removeDirectory
(
const
QModelIndex
&
idx
,
const
QString
&
fullDirPath
)
{
auto
proxyModel
=
static_cast
<
QSortFilterProxyModel
*>
(
model
());
auto
index
=
proxyModel
->
mapToSource
(
idx
);
auto
item
=
m_project
->
model
()
->
itemFromIndex
(
index
);
QStandardItem
*
parent
=
item
->
parent
();
QDir
dir
(
fullDirPath
);
if
(
dir
.
removeRecursively
())
//.moveToTrash()
{
if
(
parent
!=
nullptr
)
{
parent
->
removeRow
(
item
->
row
());
parent
->
sortChildren
(
0
);
}
else
{
m_project
->
model
()
->
removeRow
(
item
->
row
());
m_project
->
model
()
->
sort
(
0
);
}
}
}
void
KateProjectViewTree
::
slotClicked
(
const
QModelIndex
&
index
)
{
/**
...
...
addons/project/kateprojectviewtree.h
View file @
a3da7eb9
...
...
@@ -69,11 +69,6 @@ public:
*/
void
removeFile
(
const
QModelIndex
&
idx
,
const
QString
&
fullFilePath
);
/**
* remove a directory, the function isn't closing documents before removing
*/
void
removeDirectory
(
const
QModelIndex
&
idx
,
const
QString
&
fullDirPath
);
private
Q_SLOTS
:
/**
* item got clicked, do stuff, like open document
...
...
Write
Preview
Markdown
is supported
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