Core: Inline filepropertiesdialog.ui

Change-Id: I256da32d9023886aecd2389a70c57b8572c46819
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Eike Ziller
2022-07-26 13:48:24 +02:00
parent b97c495d2b
commit 568f83d964
5 changed files with 115 additions and 365 deletions

View File

@@ -27,7 +27,7 @@ add_qtc_plugin(Core
dialogs/addtovcsdialog.cpp dialogs/addtovcsdialog.h dialogs/addtovcsdialog.ui
dialogs/codecselector.cpp dialogs/codecselector.h
dialogs/externaltoolconfig.cpp dialogs/externaltoolconfig.h dialogs/externaltoolconfig.ui
dialogs/filepropertiesdialog.cpp dialogs/filepropertiesdialog.h dialogs/filepropertiesdialog.ui
dialogs/filepropertiesdialog.cpp dialogs/filepropertiesdialog.h
dialogs/ioptionspage.cpp dialogs/ioptionspage.h
dialogs/newdialog.cpp dialogs/newdialog.h
dialogs/newdialogwidget.cpp dialogs/newdialogwidget.h

View File

@@ -204,7 +204,7 @@ Project {
"addtovcsdialog.cpp", "addtovcsdialog.h", "addtovcsdialog.ui",
"codecselector.cpp", "codecselector.h",
"externaltoolconfig.cpp", "externaltoolconfig.h", "externaltoolconfig.ui",
"filepropertiesdialog.cpp", "filepropertiesdialog.h", "filepropertiesdialog.ui",
"filepropertiesdialog.cpp", "filepropertiesdialog.h",
"ioptionspage.cpp", "ioptionspage.h",
"newdialog.cpp", "newdialog.h",
"newdialogwidget.cpp", "newdialogwidget.h",

View File

@@ -24,54 +24,111 @@
****************************************************************************/
#include "filepropertiesdialog.h"
#include "ui_filepropertiesdialog.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <utils/fileutils.h>
#include <utils/layoutbuilder.h>
#include <utils/mimeutils.h>
#include <QCheckBox>
#include <QDateTime>
#include <QDebug>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileInfo>
#include <QLabel>
#include <QLocale>
using namespace Utils;
namespace Core {
FilePropertiesDialog::FilePropertiesDialog(const FilePath &filePath, QWidget *parent) :
QDialog(parent),
m_ui(new Ui::FilePropertiesDialog),
m_filePath(filePath)
FilePropertiesDialog::FilePropertiesDialog(const FilePath &filePath, QWidget *parent)
: QDialog(parent)
, m_name(new QLabel)
, m_path(new QLabel)
, m_mimeType(new QLabel)
, m_defaultEditor(new QLabel)
, m_lineEndings(new QLabel)
, m_indentation(new QLabel)
, m_owner(new QLabel)
, m_group(new QLabel)
, m_size(new QLabel)
, m_lastRead(new QLabel)
, m_lastModified(new QLabel)
, m_readable(new QCheckBox)
, m_writable(new QCheckBox)
, m_executable(new QCheckBox)
, m_symLink(new QCheckBox)
, m_filePath(filePath)
{
m_ui->setupUi(this);
resize(400, 395);
connect(m_ui->readable, &QCheckBox::clicked, [this](bool checked) {
m_name->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_path->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_mimeType->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_defaultEditor->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_lineEndings->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_indentation->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_owner->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_group->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_size->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_lastRead->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_lastModified->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_symLink->setEnabled(false);
auto buttonBox = new QDialogButtonBox;
buttonBox->setStandardButtons(QDialogButtonBox::Close);
using namespace Layouting;
// clang-format off
Column {
Form {
tr("Name:"), m_name, br,
tr("Path:"), m_path, br,
tr("MIME type:"), m_mimeType, br,
tr("Default editor:"), m_defaultEditor, br,
tr("Line endings:"), m_lineEndings, br,
tr("Indentation:"), m_indentation, br,
tr("Owner:"), m_owner, br,
tr("Group:"), m_group, br,
tr("Size:"), m_size, br,
tr("Last read:"), m_lastRead, br,
tr("Last modified:"), m_lastModified, br,
tr("Readable:"), m_readable, br,
tr("Writable:"), m_writable, br,
tr("Executable:"), m_executable, br,
tr("Symbolic link:"), m_symLink, br
},
buttonBox
}.attachTo(this);
// clang-format on
connect(m_readable, &QCheckBox::clicked, [this](bool checked) {
setPermission(QFile::ReadUser | QFile::ReadOwner, checked);
});
connect(m_ui->writable, &QCheckBox::clicked, [this](bool checked) {
connect(m_writable, &QCheckBox::clicked, [this](bool checked) {
setPermission(QFile::WriteUser | QFile::WriteOwner, checked);
});
connect(m_ui->executable, &QCheckBox::clicked, [this](bool checked) {
connect(m_executable, &QCheckBox::clicked, [this](bool checked) {
setPermission(QFile::ExeUser | QFile::ExeOwner, checked);
});
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
refresh();
}
FilePropertiesDialog::~FilePropertiesDialog()
{
delete m_ui;
}
FilePropertiesDialog::~FilePropertiesDialog() = default;
void FilePropertiesDialog::detectTextFileSettings()
{
QFile file(m_filePath.toString());
if (!file.open(QIODevice::ReadOnly)) {
m_ui->lineEndings->setText(tr("Unknown"));
m_ui->indentation->setText(tr("Unknown"));
m_lineEndings->setText(tr("Unknown"));
m_indentation->setText(tr("Unknown"));
return;
}
@@ -81,15 +138,15 @@ void FilePropertiesDialog::detectTextFileSettings()
// Try to guess the files line endings
if (data.contains("\r\n")) {
m_ui->lineEndings->setText(tr("Windows (CRLF)"));
m_lineEndings->setText(tr("Windows (CRLF)"));
} else if (data.contains("\n")) {
m_ui->lineEndings->setText(tr("Unix (LF)"));
m_lineEndings->setText(tr("Unix (LF)"));
} else if (data.contains("\r")) {
m_ui->lineEndings->setText(tr("Mac (CR)"));
m_lineEndings->setText(tr("Mac (CR)"));
lineSeparator = '\r';
} else {
// That does not look like a text file at all
m_ui->lineEndings->setText(tr("Unknown"));
m_lineEndings->setText(tr("Unknown"));
return;
}
@@ -132,14 +189,14 @@ void FilePropertiesDialog::detectTextFileSettings()
if (!indents.empty()) {
if (tabIndented) {
m_ui->indentation->setText(tr("Mixed"));
m_indentation->setText(tr("Mixed"));
} else {
m_ui->indentation->setText(tr("%1 Spaces").arg(max->first));
m_indentation->setText(tr("%1 Spaces").arg(max->first));
}
} else if (tabIndented) {
m_ui->indentation->setText(tr("Tabs"));
m_indentation->setText(tr("Tabs"));
} else {
m_ui->indentation->setText(tr("Unknown"));
m_indentation->setText(tr("Unknown"));
}
}
@@ -149,29 +206,30 @@ void FilePropertiesDialog::refresh()
const QFileInfo fileInfo = m_filePath.toFileInfo();
QLocale locale;
m_ui->name->setText(fileInfo.fileName());
m_ui->path->setText(QDir::toNativeSeparators(fileInfo.canonicalPath()));
m_name->setText(fileInfo.fileName());
m_path->setText(QDir::toNativeSeparators(fileInfo.canonicalPath()));
const Utils::MimeType mimeType = Utils::mimeTypeForFile(m_filePath);
m_ui->mimeType->setText(mimeType.name());
m_mimeType->setText(mimeType.name());
const EditorTypeList factories = IEditorFactory::preferredEditorTypes(m_filePath);
m_ui->defaultEditor->setText(!factories.isEmpty() ? factories.at(0)->displayName() : tr("Undefined"));
m_defaultEditor->setText(!factories.isEmpty() ? factories.at(0)->displayName()
: tr("Undefined"));
m_ui->owner->setText(fileInfo.owner());
m_ui->group->setText(fileInfo.group());
m_ui->size->setText(locale.formattedDataSize(fileInfo.size()));
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()));
m_owner->setText(fileInfo.owner());
m_group->setText(fileInfo.group());
m_size->setText(locale.formattedDataSize(fileInfo.size()));
m_readable->setChecked(fileInfo.isReadable());
m_writable->setChecked(fileInfo.isWritable());
m_executable->setChecked(fileInfo.isExecutable());
m_symLink->setChecked(fileInfo.isSymLink());
m_lastRead->setText(fileInfo.lastRead().toString(locale.dateTimeFormat()));
m_lastModified->setText(fileInfo.lastModified().toString(locale.dateTimeFormat()));
if (mimeType.inherits("text/plain")) {
detectTextFileSettings();
} else {
m_ui->lineEndings->setText(tr("Unknown"));
m_ui->indentation->setText(tr("Unknown"));
m_lineEndings->setText(tr("Unknown"));
m_indentation->setText(tr("Unknown"));
}
});
}

View File

@@ -30,7 +30,8 @@
#include <QDialog>
QT_BEGIN_NAMESPACE
namespace Ui { class FilePropertiesDialog; }
class QLabel;
class QCheckBox;
QT_END_NAMESPACE
namespace Core {
@@ -49,7 +50,21 @@ private:
void detectTextFileSettings();
private:
Ui::FilePropertiesDialog *m_ui = nullptr;
QLabel *m_name;
QLabel *m_path;
QLabel *m_mimeType;
QLabel *m_defaultEditor;
QLabel *m_lineEndings;
QLabel *m_indentation;
QLabel *m_owner;
QLabel *m_group;
QLabel *m_size;
QLabel *m_lastRead;
QLabel *m_lastModified;
QCheckBox *m_readable;
QCheckBox *m_writable;
QCheckBox *m_executable;
QCheckBox *m_symLink;
const Utils::FilePath m_filePath;
};

View File

@@ -1,323 +0,0 @@
<?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="6" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Owner:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="owner">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Group:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="group">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLabel" name="size">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="11" 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="12" 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="13" 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="14" 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="9" column="1">
<widget class="QLabel" name="lastRead">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="10" 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="9" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Last read:</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Last modified:</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Readable:</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Writable:</string>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Executable:</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Symbolic link:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>MIME type:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Default editor:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="mimeType">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="defaultEditor">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Line endings:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Indentation:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="indentation">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="lineEndings">
<property name="text">
<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>