Commit f2f91b13 authored by Krzysztof Stokop's avatar Krzysztof Stokop
Browse files

cleaning

parent 78586aca
......@@ -74,14 +74,14 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
/**
* Open terminal here
*/
QAction* terminal = menu.addAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), i18n("Open Terminal here"));
QAction* terminal = menu.addAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), i18n("Open Terminal Here"));
/**
* Handle "open with",
* find correct mimetype to query for possible applications
*/
QMenu *openWithMenu = menu.addMenu(i18n("Open With"));
QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename);
QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename);
const KService::List offers = KApplicationTrader::queryByMimeType(mimeType.name());
// For each one, insert a menu item...
for (const auto &service : offers) {
......@@ -135,15 +135,6 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
job->start();
};
auto handleOpenTerminalHere = [](const QString &filename)
{
QFileInfo checkFile(filename);
if (QUrl::fromLocalFile(filename).isLocalFile() && checkFile.isFile())
KToolInvocation::invokeTerminal(QString(), {}, QUrl::fromLocalFile(filename).toString(QUrl::RemoveFilename | QUrl::RemoveScheme));
if (QUrl::fromLocalFile(filename).isLocalFile() && checkFile.isDir())
KToolInvocation::invokeTerminal(QString(), {}, filename);
};
auto handleDeleteFile = [parent, index](const QString &path)
{
......@@ -154,10 +145,11 @@ 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 : KTextEditor::Editor::instance()->application()->documents())
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);
......@@ -167,7 +159,7 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
{
//if is open, close
for(auto doc : KTextEditor::Editor::instance()->application()->documents())
for(auto doc : openDocuments)
{
if(doc->url().adjusted(QUrl::RemoveScheme) == QUrl(path).adjusted(QUrl::RemoveScheme))
{
......@@ -190,77 +182,57 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QModelI
/**
* run menu and handle the triggered action
*/
if (QAction *const action = menu.exec(pos))
{
if (action == copyAction)
{
if (QAction *const action = menu.exec(pos)) {
if (action == copyAction) {
QApplication::clipboard()->setText(filename);
}
else if (action == terminal)
{
} else if (action == terminal) {
// handle "open terminal here"
handleOpenTerminalHere(filename);
}
else if (action->parentWidget() == openWithMenu)
{
QFileInfo checkFile(filename);
if (QUrl::fromLocalFile(filename).isLocalFile() && checkFile.isFile()) {
KToolInvocation::invokeTerminal(QString(), {}, QUrl::fromLocalFile(filename).toString(QUrl::RemoveFilename | QUrl::RemoveScheme));
} if (QUrl::fromLocalFile(filename).isLocalFile() && checkFile.isDir()) {
KToolInvocation::invokeTerminal(QString(), {}, filename);
}
} else if (action->parentWidget() == openWithMenu) {
// handle "open with"
handleOpenWith(action, filename);
}
else if (action == openContaingFolderAction)
{
} else if (action == openContaingFolderAction) {
KIO::highlightInFileManager({QUrl::fromLocalFile(filename)});
}
else if (action == fileDelete)
{
} else if (action == fileDelete) {
handleDeleteFile(filename);
}
else if (action == filePropertiesAction)
{
} else if (action == filePropertiesAction) {
// code copied and adapted from frameworks/kio/src/filewidgets/knewfilemenu.cpp
KFileItem fileItem(QUrl::fromLocalFile(filename));
QDialog *dlg = new KPropertiesDialog(fileItem);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show();
}
else if (rename && action == rename)
{
} else if (rename && action == rename) {
/**
* hack:
* We store a reference to project in the item so that
* after rename we can update file2Item map properly.
*/
KateProjectItem *item = parent->project()->itemForFile(index.data(Qt::UserRole).toString());
if (!item)
{
if (!item) {
return;
}
item->setData(QVariant::fromValue(parent->project()), KateProjectItem::ProjectRole);
/** start the edit */
parent->edit(index);
}
else if (action == fileHistory)
{
} else if (action == fileHistory) {
showFileHistory(index.data(Qt::UserRole).toString());
}
else if (addFile && action == addFile)
{
} else if (addFile && action == addFile) {
QString name = getName();
if (!name.isEmpty())
{
if (!name.isEmpty()) {
parent->addFile(index, name);
}
}
else if (addFolder && action == addFolder)
{
} else if (addFolder && action == addFolder) {
QString name = getName();
if (!name.isEmpty())
{
if (!name.isEmpty()) {
parent->addDirectory(index, name);
}
}
else
{
} else {
// One of the git actions was triggered
}
}
......
......@@ -174,19 +174,20 @@ void KateProjectViewTree::removeFile(const QModelIndex& idx, const QString& full
* Delete file
*/
QFile file(fullFilePath);
file.remove(); //.moveToTrash()
if(parent != nullptr)
{
parent->removeRow(item->row());
parent->sortChildren(0);
}
else
if(file.remove())//.moveToTrash()
{
m_project->model()->removeRow(item->row());
m_project->model()->sort(0);
if(parent != nullptr)
{
parent->removeRow(item->row());
parent->sortChildren(0);
}
else
{
m_project->model()->removeRow(item->row());
m_project->model()->sort(0);
}
m_project->removeFile(fullFilePath);
}
m_project->removeFile(fullFilePath);
}
void KateProjectViewTree::removeDirectory(const QModelIndex& idx, const QString& fullDirPath)
......@@ -197,17 +198,18 @@ void KateProjectViewTree::removeDirectory(const QModelIndex& idx, const QString&
QStandardItem* parent = item->parent();
QDir dir(fullDirPath);
dir.removeRecursively(); //.moveToTrash()
if(parent != nullptr)
{
parent->removeRow(item->row());
parent->sortChildren(0);
}
else
if(dir.removeRecursively()) //.moveToTrash()
{
m_project->model()->removeRow(item->row());
m_project->model()->sort(0);
if(parent != nullptr)
{
parent->removeRow(item->row());
parent->sortChildren(0);
}
else
{
m_project->model()->removeRow(item->row());
m_project->model()->sort(0);
}
}
}
......
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