Add a file properties dialog

Task-number: QTCREATORBUG-19588
Change-Id: I75599459beb7e23812ba48670ae968585faefda9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Andre Hartmann
2018-01-13 23:26:26 +01:00
committed by André Hartmann
parent 8e83f6f0e7
commit 9467ed42c3
12 changed files with 454 additions and 1 deletions

View File

@@ -88,6 +88,7 @@ SOURCES += corejsextensions.cpp \
sidebarwidget.cpp \ sidebarwidget.cpp \
externaltool.cpp \ externaltool.cpp \
dialogs/externaltoolconfig.cpp \ dialogs/externaltoolconfig.cpp \
dialogs/filepropertiesdialog.cpp \
toolsettings.cpp \ toolsettings.cpp \
variablechooser.cpp \ variablechooser.cpp \
mimetypemagicdialog.cpp \ mimetypemagicdialog.cpp \
@@ -199,6 +200,7 @@ HEADERS += corejsextensions.h \
sidebarwidget.h \ sidebarwidget.h \
externaltool.h \ externaltool.h \
dialogs/externaltoolconfig.h \ dialogs/externaltoolconfig.h \
dialogs/filepropertiesdialog.h \
toolsettings.h \ toolsettings.h \
variablechooser.h \ variablechooser.h \
mimetypemagicdialog.h \ mimetypemagicdialog.h \
@@ -230,6 +232,7 @@ FORMS += dialogs/newdialog.ui \
dialogs/openwithdialog.ui \ dialogs/openwithdialog.ui \
generalsettings.ui \ generalsettings.ui \
dialogs/externaltoolconfig.ui \ dialogs/externaltoolconfig.ui \
dialogs/filepropertiesdialog.ui \
mimetypesettingspage.ui \ mimetypesettingspage.ui \
mimetypemagicdialog.ui \ mimetypemagicdialog.ui \
dialogs/addtovcsdialog.ui \ dialogs/addtovcsdialog.ui \

View File

@@ -207,6 +207,7 @@ Project {
files: [ files: [
"addtovcsdialog.cpp", "addtovcsdialog.h", "addtovcsdialog.ui", "addtovcsdialog.cpp", "addtovcsdialog.h", "addtovcsdialog.ui",
"externaltoolconfig.cpp", "externaltoolconfig.h", "externaltoolconfig.ui", "externaltoolconfig.cpp", "externaltoolconfig.h", "externaltoolconfig.ui",
"filepropertiesdialog.cpp", "filepropertiesdialog.h", "filepropertiesdialog.ui",
"ioptionspage.cpp", "ioptionspage.h", "ioptionspage.cpp", "ioptionspage.h",
"newdialog.cpp", "newdialog.h", "newdialog.ui", "newdialog.cpp", "newdialog.h", "newdialog.ui",
"openwithdialog.cpp", "openwithdialog.h", "openwithdialog.ui", "openwithdialog.cpp", "openwithdialog.h", "openwithdialog.ui",

View File

@@ -0,0 +1,99 @@
/****************************************************************************
**
** Copyright (C) 2018 Andre Hartmann <aha_1980@gmx.de>
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "filepropertiesdialog.h"
#include "ui_filepropertiesdialog.h"
#include <utils/fileutils.h>
#include <QDateTime>
#include <QDebug>
#include <QFileInfo>
#include <QLocale>
FilePropertiesDialog::FilePropertiesDialog(const Utils::FileName &fileName, QWidget *parent) :
QDialog(parent),
m_ui(new Ui::FilePropertiesDialog),
m_fileName(fileName.toString())
{
m_ui->setupUi(this);
connect(m_ui->readable, &QCheckBox::clicked, [this](bool checked) {
setPermission(QFile::ReadUser | QFile::ReadOwner, checked);
});
connect(m_ui->writable, &QCheckBox::clicked, [this](bool checked) {
setPermission(QFile::WriteUser | QFile::WriteOwner, checked);
});
connect(m_ui->executable, &QCheckBox::clicked, [this](bool checked) {
setPermission(QFile::ExeUser | QFile::ExeOwner, checked);
});
refresh();
}
FilePropertiesDialog::~FilePropertiesDialog()
{
delete m_ui;
}
void FilePropertiesDialog::refresh()
{
Utils::withNTFSPermissions<void>([this] {
const QFileInfo fileInfo(m_fileName);
QLocale locale;
m_ui->name->setText(fileInfo.fileName());
m_ui->path->setText(fileInfo.canonicalPath());
m_ui->owner->setText(fileInfo.owner());
m_ui->group->setText(fileInfo.group());
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
m_ui->size->setText(locale.formattedDataSize(fileInfo.size()));
#else
m_ui->size->setText(tr("%1 Bytes").arg(locale.toString(fileInfo.size())));
#endif
m_ui->readable->setChecked(fileInfo.isReadable());
m_ui->writable->setChecked(fileInfo.isWritable());
m_ui->executable->setChecked(fileInfo.isExecutable());
m_ui->symLink->setChecked(fileInfo.isSymLink());
m_ui->lastRead->setText(fileInfo.lastRead().toString(locale.dateTimeFormat()));
m_ui->lastModified->setText(fileInfo.lastModified().toString(locale.dateTimeFormat()));
});
}
void FilePropertiesDialog::setPermission(QFile::Permissions newPermissions, bool set)
{
Utils::withNTFSPermissions<void>([this, newPermissions, set] {
QFile::Permissions permissions = QFile::permissions(m_fileName);
if (set)
permissions |= newPermissions;
else
permissions &= ~newPermissions;
if (!QFile::setPermissions(m_fileName, permissions))
qWarning() << "Cannot change permissions for file" << m_fileName;
});
refresh();
}

View File

@@ -0,0 +1,52 @@
/****************************************************************************
**
** Copyright (C) 2018 Andre Hartmann <aha_1980@gmx.de>
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <utils/fileutils.h>
#include <QDialog>
#include <QFile>
namespace Ui {
class FilePropertiesDialog;
}
class FilePropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit FilePropertiesDialog(const Utils::FileName &fileName, QWidget *parent = nullptr);
~FilePropertiesDialog();
private:
void refresh();
void setPermission(QFile::Permissions newPermissions, bool set);
private:
Ui::FilePropertiesDialog *m_ui = nullptr;
const QString m_fileName;
};

View File

@@ -0,0 +1,267 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FilePropertiesDialog</class>
<widget class="QDialog" name="FilePropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>395</height>
</rect>
</property>
<property name="windowTitle">
<string>File Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Owner:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="owner">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Group:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="group">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="size">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="readable">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="writable">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="executable">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QCheckBox" name="symLink">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="lastRead">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="lastModified">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="name">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="path">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Path:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Last read:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Last modified:</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Readable:</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Writable:</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Executable:</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Symbolic link:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FilePropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FilePropertiesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -31,6 +31,7 @@
#include "coreconstants.h" #include "coreconstants.h"
#include <coreplugin/diffservice.h> #include <coreplugin/diffservice.h>
#include <coreplugin/dialogs/filepropertiesdialog.h>
#include <coreplugin/dialogs/readonlyfilesdialog.h> #include <coreplugin/dialogs/readonlyfilesdialog.h>
#include <coreplugin/dialogs/saveitemsdialog.h> #include <coreplugin/dialogs/saveitemsdialog.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
@@ -948,6 +949,12 @@ bool DocumentManager::saveModifiedDocument(IDocument *document, const QString &m
alwaysSaveMessage, alwaysSave, failedToClose); alwaysSaveMessage, alwaysSave, failedToClose);
} }
void DocumentManager::showFilePropertiesDialog(const FileName &filePath)
{
FilePropertiesDialog properties(filePath);
properties.exec();
}
/*! /*!
Asks the user for a set of file names to be opened. The \a filters Asks the user for a set of file names to be opened. The \a filters
and \a selectedFilter arguments are interpreted like in and \a selectedFilter arguments are interpreted like in

View File

@@ -123,6 +123,7 @@ public:
const QString &alwaysSaveMessage = QString(), const QString &alwaysSaveMessage = QString(),
bool *alwaysSave = nullptr, bool *alwaysSave = nullptr,
QList<IDocument *> *failedToClose = nullptr); QList<IDocument *> *failedToClose = nullptr);
static void showFilePropertiesDialog(const Utils::FileName &filePath);
static QString fileDialogLastVisitedDirectory(); static QString fileDialogLastVisitedDirectory();
static void setFileDialogLastVisitedDirectory(const QString &); static void setFileDialogLastVisitedDirectory(const QString &);

View File

@@ -211,7 +211,8 @@ EditorManagerPrivate::EditorManagerPrivate(QObject *parent) :
m_closeAllEditorsExceptVisibleContextAction(new QAction(EditorManager::tr("Close All Except Visible"), this)), m_closeAllEditorsExceptVisibleContextAction(new QAction(EditorManager::tr("Close All Except Visible"), this)),
m_openGraphicalShellAction(new QAction(FileUtils::msgGraphicalShellAction(), this)), m_openGraphicalShellAction(new QAction(FileUtils::msgGraphicalShellAction(), this)),
m_openTerminalAction(new QAction(FileUtils::msgTerminalAction(), this)), m_openTerminalAction(new QAction(FileUtils::msgTerminalAction(), this)),
m_findInDirectoryAction(new QAction(FileUtils::msgFindInDirectory(), this)) m_findInDirectoryAction(new QAction(FileUtils::msgFindInDirectory(), this)),
m_filePropertiesAction(new QAction(tr("Properties..."), this))
{ {
d = this; d = this;
} }
@@ -344,6 +345,11 @@ void EditorManagerPrivate::init()
connect(m_openTerminalAction, &QAction::triggered, this, &EditorManagerPrivate::openTerminal); connect(m_openTerminalAction, &QAction::triggered, this, &EditorManagerPrivate::openTerminal);
connect(m_findInDirectoryAction, &QAction::triggered, connect(m_findInDirectoryAction, &QAction::triggered,
this, &EditorManagerPrivate::findInDirectory); this, &EditorManagerPrivate::findInDirectory);
connect(m_filePropertiesAction, &QAction::triggered, []() {
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty())
return;
DocumentManager::showFilePropertiesDialog(d->m_contextMenuEntry->fileName());
});
// Goto Previous In History Action // Goto Previous In History Action
cmd = ActionManager::registerAction(m_gotoPreviousDocHistoryAction, Constants::GOTOPREVINHISTORY, editDesignContext); cmd = ActionManager::registerAction(m_gotoPreviousDocHistoryAction, Constants::GOTOPREVINHISTORY, editDesignContext);
@@ -2425,9 +2431,11 @@ void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentM
d->m_openGraphicalShellAction->setEnabled(enabled); d->m_openGraphicalShellAction->setEnabled(enabled);
d->m_openTerminalAction->setEnabled(enabled); d->m_openTerminalAction->setEnabled(enabled);
d->m_findInDirectoryAction->setEnabled(enabled); d->m_findInDirectoryAction->setEnabled(enabled);
d->m_filePropertiesAction->setEnabled(enabled);
contextMenu->addAction(d->m_openGraphicalShellAction); contextMenu->addAction(d->m_openGraphicalShellAction);
contextMenu->addAction(d->m_openTerminalAction); contextMenu->addAction(d->m_openTerminalAction);
contextMenu->addAction(d->m_findInDirectoryAction); contextMenu->addAction(d->m_findInDirectoryAction);
contextMenu->addAction(d->m_filePropertiesAction);
QMenu *openWith = contextMenu->addMenu(tr("Open With")); QMenu *openWith = contextMenu->addMenu(tr("Open With"));
openWith->setEnabled(enabled); openWith->setEnabled(enabled);
if (enabled) if (enabled)

View File

@@ -181,6 +181,7 @@ signals:
void editorAboutToClose(Core::IEditor *editor); void editorAboutToClose(Core::IEditor *editor);
void editorsClosed(QList<Core::IEditor *> editors); void editorsClosed(QList<Core::IEditor *> editors);
void findOnFileSystemRequest(const QString &path); void findOnFileSystemRequest(const QString &path);
void openFileProperties(const Utils::FileName &path);
void aboutToSave(IDocument *document); void aboutToSave(IDocument *document);
void autoSaved(); void autoSaved();
void currentEditorAboutToChange(Core::IEditor *editor); void currentEditorAboutToChange(Core::IEditor *editor);

View File

@@ -245,6 +245,7 @@ private:
QAction *m_openGraphicalShellAction; QAction *m_openGraphicalShellAction;
QAction *m_openTerminalAction; QAction *m_openTerminalAction;
QAction *m_findInDirectoryAction; QAction *m_findInDirectoryAction;
QAction *m_filePropertiesAction = nullptr;
DocumentModel::Entry *m_contextMenuEntry = nullptr; DocumentModel::Entry *m_contextMenuEntry = nullptr;
IEditor *m_contextMenuEditor = nullptr; IEditor *m_contextMenuEditor = nullptr;

View File

@@ -382,6 +382,7 @@ public:
QAction *m_removeProjectAction; QAction *m_removeProjectAction;
QAction *m_deleteFileAction; QAction *m_deleteFileAction;
QAction *m_renameFileAction; QAction *m_renameFileAction;
QAction *m_filePropertiesAction = nullptr;
QAction *m_diffFileAction; QAction *m_diffFileAction;
QAction *m_openFileAction; QAction *m_openFileAction;
QAction *m_projectTreeCollapseAllAction; QAction *m_projectTreeCollapseAllAction;
@@ -1073,6 +1074,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
cmd->setDescription(dd->m_unloadActionContextMenu->text()); cmd->setDescription(dd->m_unloadActionContextMenu->text());
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST); mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
// file properties action
dd->m_filePropertiesAction = new QAction(tr("Properties..."), this);
cmd = ActionManager::registerAction(dd->m_filePropertiesAction, Constants::FILEPROPERTIES,
projecTreeContext);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
// remove file action // remove file action
dd->m_removeFileAction = new QAction(tr("Remove File..."), this); dd->m_removeFileAction = new QAction(tr("Remove File..."), this);
cmd = ActionManager::registerAction(dd->m_removeFileAction, Constants::REMOVEFILE, cmd = ActionManager::registerAction(dd->m_removeFileAction, Constants::REMOVEFILE,
@@ -1343,6 +1350,11 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
dd, &ProjectExplorerPluginPrivate::showInGraphicalShell); dd, &ProjectExplorerPluginPrivate::showInGraphicalShell);
connect(dd->m_openTerminalHere, &QAction::triggered, connect(dd->m_openTerminalHere, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::openTerminalHere); dd, &ProjectExplorerPluginPrivate::openTerminalHere);
connect(dd->m_filePropertiesAction, &QAction::triggered, this, []() {
const Node *currentNode = ProjectTree::findCurrentNode();
QTC_ASSERT(currentNode && currentNode->nodeType() == NodeType::File, return);
DocumentManager::showFilePropertiesDialog(currentNode->filePath());
});
connect(dd->m_removeFileAction, &QAction::triggered, connect(dd->m_removeFileAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::removeFile); dd, &ProjectExplorerPluginPrivate::removeFile);
connect(dd->m_duplicateFileAction, &QAction::triggered, connect(dd->m_duplicateFileAction, &QAction::triggered,

View File

@@ -37,6 +37,7 @@ const char MODE_SESSION[] = "Project";
const char BUILD[] = "ProjectExplorer.Build"; const char BUILD[] = "ProjectExplorer.Build";
const char STOP[] = "ProjectExplorer.Stop"; const char STOP[] = "ProjectExplorer.Stop";
const char ADDNEWFILE[] = "ProjectExplorer.AddNewFile"; const char ADDNEWFILE[] = "ProjectExplorer.AddNewFile";
const char FILEPROPERTIES[] = "ProjectExplorer.FileProperties";
const char RENAMEFILE[] = "ProjectExplorer.RenameFile"; const char RENAMEFILE[] = "ProjectExplorer.RenameFile";
const char REMOVEFILE[] = "ProjectExplorer.RemoveFile"; const char REMOVEFILE[] = "ProjectExplorer.RemoveFile";