Core: Inline readonlyfilesdialog.ui

Change-Id: Ifefa5116b4af6ad85c964b55c306fa2d921f8759
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2022-07-27 13:10:48 +02:00
parent ea550ee831
commit 22c583b31d
4 changed files with 84 additions and 189 deletions

View File

@@ -33,7 +33,7 @@ add_qtc_plugin(Core
dialogs/newdialogwidget.cpp dialogs/newdialogwidget.h
dialogs/openwithdialog.cpp dialogs/openwithdialog.h
dialogs/promptoverwritedialog.cpp dialogs/promptoverwritedialog.h
dialogs/readonlyfilesdialog.cpp dialogs/readonlyfilesdialog.h dialogs/readonlyfilesdialog.ui
dialogs/readonlyfilesdialog.cpp dialogs/readonlyfilesdialog.h
dialogs/restartdialog.cpp dialogs/restartdialog.h
dialogs/saveitemsdialog.cpp dialogs/saveitemsdialog.h
dialogs/settingsdialog.cpp dialogs/settingsdialog.h

View File

@@ -210,7 +210,7 @@ Project {
"newdialogwidget.cpp", "newdialogwidget.h",
"openwithdialog.cpp", "openwithdialog.h",
"promptoverwritedialog.cpp", "promptoverwritedialog.h",
"readonlyfilesdialog.cpp", "readonlyfilesdialog.h", "readonlyfilesdialog.ui",
"readonlyfilesdialog.cpp", "readonlyfilesdialog.h",
"restartdialog.cpp", "restartdialog.h",
"saveitemsdialog.cpp", "saveitemsdialog.h",
"settingsdialog.cpp", "settingsdialog.h",

View File

@@ -24,7 +24,6 @@
****************************************************************************/
#include "readonlyfilesdialog.h"
#include "ui_readonlyfilesdialog.h"
#include <coreplugin/editormanager/editormanager_p.h>
#include <coreplugin/icore.h>
@@ -36,15 +35,20 @@
#include <utils/fileutils.h>
#include <utils/fsengine/fileiconprovider.h>
#include <utils/hostosinfo.h>
#include <utils/layoutbuilder.h>
#include <utils/stringutils.h>
#include <QButtonGroup>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileInfo>
#include <QLabel>
#include <QMap>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QTreeWidget>
using namespace Utils;
@@ -107,7 +111,9 @@ public:
QString versionControlOpenText;
const QString saveAsText;
Ui::ReadOnlyFilesDialog ui;
QLabel *m_msgLabel;
QTreeWidget *m_treeWidget;
QComboBox *m_setAll;
};
ReadOnlyFilesDialogPrivate::ReadOnlyFilesDialogPrivate(ReadOnlyFilesDialog *parent, IDocument *document, bool displaySaveAs)
@@ -202,7 +208,7 @@ ReadOnlyFilesDialog::~ReadOnlyFilesDialog()
*/
void ReadOnlyFilesDialog::setMessage(const QString &message)
{
d->ui.msgLabel->setText(message);
d->m_msgLabel->setText(message);
}
/*!
@@ -346,7 +352,7 @@ QRadioButton *ReadOnlyFilesDialogPrivate::createRadioButtonForItem(QTreeWidgetIt
auto radioButton = new QRadioButton(q);
group->addButton(radioButton, type);
item->setTextAlignment(type, Qt::AlignHCenter);
ui.treeWidget->setItemWidget(item, type, radioButton);
m_treeWidget->setItemWidget(item, type, radioButton);
return radioButton;
}
@@ -392,11 +398,11 @@ void ReadOnlyFilesDialogPrivate::updateSelectAll()
if (selectedOperation == -1) {
selectedOperation = groupForFile.group->checkedId();
} else if (selectedOperation != groupForFile.group->checkedId()) {
ui.setAll->setCurrentIndex(0);
m_setAll->setCurrentIndex(0);
return;
}
}
ui.setAll->setCurrentIndex(setAllIndexForOperation[selectedOperation]);
m_setAll->setCurrentIndex(setAllIndexForOperation[selectedOperation]);
}
/*!
@@ -408,9 +414,48 @@ void ReadOnlyFilesDialogPrivate::updateSelectAll()
*/
void ReadOnlyFilesDialogPrivate::initDialog(const FilePaths &filePaths)
{
ui.setupUi(q);
ui.buttonBox->addButton(tr("Change &Permission"), QDialogButtonBox::AcceptRole);
ui.buttonBox->addButton(QDialogButtonBox::Cancel);
q->resize(639, 217);
q->setWindowTitle(tr("Files Without Write Permissions"));
m_msgLabel = new QLabel(tr(
"The following files have no write permissions. Do you want to change the permissions?"));
m_treeWidget = new QTreeWidget;
auto headerItem = new QTreeWidgetItem;
headerItem->setText(0, tr("Make Writable"));
headerItem->setText(1, tr("Open with VCS"));
headerItem->setText(2, tr("Save As"));
headerItem->setText(3, tr("Filename"));
headerItem->setText(4, tr("Path"));
m_treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
m_treeWidget->setTextElideMode(Qt::ElideLeft);
m_treeWidget->setIndentation(0);
m_treeWidget->setUniformRowHeights(true);
m_treeWidget->setItemsExpandable(false);
m_treeWidget->setColumnCount(5);
m_treeWidget->setHeaderItem(headerItem);
m_setAll = new QComboBox;
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::NoButton);
buttonBox->addButton(tr("Change &Permission"), QDialogButtonBox::AcceptRole);
buttonBox->addButton(QDialogButtonBox::Cancel);
QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &QDialog::accept);
QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject);
using namespace Layouting;
QWidget *setAllWidget = Row{tr("Select all, if possible: "), m_setAll, st}.emerge(
WithoutMargins);
// clang-format off
Column {
m_msgLabel,
m_treeWidget,
setAllWidget,
buttonBox
}.attachTo(q);
// clang-format on
QString vcsOpenTextForAll;
QString vcsMakeWritableTextForAll;
@@ -420,7 +465,7 @@ void ReadOnlyFilesDialogPrivate::initDialog(const FilePaths &filePaths)
const FilePath directory = filePath.absolutePath();
// Setup a default entry with filename folder and make writable radio button.
auto item = new QTreeWidgetItem(ui.treeWidget);
auto item = new QTreeWidgetItem(m_treeWidget);
item->setText(FileName, visibleName);
item->setIcon(FileName, FileIconProvider::icon(filePath));
item->setText(Folder, directory.shortNativePath());
@@ -472,69 +517,64 @@ void ReadOnlyFilesDialogPrivate::initDialog(const FilePaths &filePaths)
// Apply the Mac file dialog style.
if (Utils::HostOsInfo::isMacHost())
ui.treeWidget->setAlternatingRowColors(true);
m_treeWidget->setAlternatingRowColors(true);
// Do not show any options to the user if he has no choice.
if (!useSaveAs && (!useVCS || !useMakeWritable)) {
ui.treeWidget->setColumnHidden(MakeWritable, true);
ui.treeWidget->setColumnHidden(OpenWithVCS, true);
ui.treeWidget->setColumnHidden(SaveAs, true);
ui.treeWidget->resizeColumnToContents(FileName);
ui.treeWidget->resizeColumnToContents(Folder);
ui.setAll->setVisible(false);
ui.setAllLabel->setVisible(false);
ui.verticalLayout->removeItem(ui.setAllLayout);
m_treeWidget->setColumnHidden(MakeWritable, true);
m_treeWidget->setColumnHidden(OpenWithVCS, true);
m_treeWidget->setColumnHidden(SaveAs, true);
m_treeWidget->resizeColumnToContents(FileName);
m_treeWidget->resizeColumnToContents(Folder);
setAllWidget->setVisible(false);
if (useVCS)
ui.msgLabel->setText(tr("The following files are not checked out yet.\n"
m_msgLabel->setText(tr("The following files are not checked out yet.\n"
"Do you want to check them out now?"));
return;
}
// If there is just one file entry, there is no need to show the select all combo box
if (filePaths.count() < 2) {
ui.setAll->setVisible(false);
ui.setAllLabel->setVisible(false);
ui.verticalLayout->removeItem(ui.setAllLayout);
}
if (filePaths.count() < 2)
setAllWidget->setVisible(false);
// Add items to the Set all combo box.
ui.setAll->addItem(mixedText);
setAllIndexForOperation[-1/*mixed*/] = ui.setAll->count() - 1;
m_setAll->addItem(mixedText);
setAllIndexForOperation[-1 /*mixed*/] = m_setAll->count() - 1;
if (useVCS) {
// If the files are managed by just one version control system, the Open and Make Writable
// text for the specific system is used.
if (!vcsOpenTextForAll.isEmpty() && vcsOpenTextForAll != versionControlOpenText) {
versionControlOpenText = vcsOpenTextForAll;
ui.treeWidget->headerItem()->setText(OpenWithVCS, versionControlOpenText);
m_treeWidget->headerItem()->setText(OpenWithVCS, versionControlOpenText);
}
if (!vcsMakeWritableTextForAll.isEmpty() && vcsMakeWritableTextForAll != makeWritableText) {
makeWritableText = vcsMakeWritableTextForAll;
ui.treeWidget->headerItem()->setText(MakeWritable, makeWritableText);
m_treeWidget->headerItem()->setText(MakeWritable, makeWritableText);
}
ui.setAll->addItem(versionControlOpenText);
ui.setAll->setCurrentIndex(ui.setAll->count() - 1);
setAllIndexForOperation[OpenWithVCS] = ui.setAll->count() - 1;
m_setAll->addItem(versionControlOpenText);
m_setAll->setCurrentIndex(m_setAll->count() - 1);
setAllIndexForOperation[OpenWithVCS] = m_setAll->count() - 1;
}
if (useMakeWritable) {
ui.setAll->addItem(makeWritableText);
setAllIndexForOperation[MakeWritable] = ui.setAll->count() - 1;
if (ui.setAll->currentIndex() == -1)
ui.setAll->setCurrentIndex(ui.setAll->count() - 1);
m_setAll->addItem(makeWritableText);
setAllIndexForOperation[MakeWritable] = m_setAll->count() - 1;
if (m_setAll->currentIndex() == -1)
m_setAll->setCurrentIndex(m_setAll->count() - 1);
}
if (useSaveAs) {
ui.setAll->addItem(saveAsText);
setAllIndexForOperation[SaveAs] = ui.setAll->count() - 1;
m_setAll->addItem(saveAsText);
setAllIndexForOperation[SaveAs] = m_setAll->count() - 1;
}
QObject::connect(ui.setAll, &QComboBox::activated, [this](int index) { setAll(index); });
QObject::connect(m_setAll, &QComboBox::activated, [this](int index) { setAll(index); });
// Filter which columns should be visible and resize them to content.
for (int i = 0; i < NumberOfColumns; ++i) {
if ((i == SaveAs && !useSaveAs) || (i == OpenWithVCS && !useVCS)
|| (i == MakeWritable && !useMakeWritable)) {
ui.treeWidget->setColumnHidden(i, true);
m_treeWidget->setColumnHidden(i, true);
continue;
}
ui.treeWidget->resizeColumnToContents(i);
m_treeWidget->resizeColumnToContents(i);
}
}

View File

@@ -1,145 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Core::Internal::ReadOnlyFilesDialog</class>
<widget class="QDialog" name="Core::Internal::ReadOnlyFilesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>639</width>
<height>217</height>
</rect>
</property>
<property name="windowTitle">
<string>Files Without Write Permissions</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="msgLabel">
<property name="text">
<string>The following files have no write permissions. Do you want to change the permissions?</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="treeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideLeft</enum>
</property>
<property name="indentation">
<number>0</number>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="columnCount">
<number>5</number>
</property>
<column>
<property name="text">
<string>Make Writable</string>
</property>
</column>
<column>
<property name="text">
<string>Open with VCS</string>
</property>
</column>
<column>
<property name="text">
<string>Save As</string>
</property>
</column>
<column>
<property name="text">
<string notr="true">Filename</string>
</property>
</column>
<column>
<property name="text">
<string>Path</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="setAllLayout">
<item>
<widget class="QLabel" name="setAllLabel">
<property name="text">
<string>Select all, if possible: </string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="setAll"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::NoButton</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Core::Internal::ReadOnlyFilesDialog</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>Core::Internal::ReadOnlyFilesDialog</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>