QmlDesigner: Confirm deletion when removing custom folder files

Fixes: QDS-15321
Change-Id: Iaf6531d5432a05d6210159ef3957ce9c2d2eca12
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Shrief Gabr
2025-05-29 16:27:44 +03:00
parent 30ac4ce711
commit b7aa9f5598
4 changed files with 35 additions and 0 deletions

View File

@@ -16,13 +16,17 @@
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#include <qmldesignerbase/settings/designersettings.h>
#include <utils/algorithm.h>
#include <utils/filesystemwatcher.h>
#include <utils/qtcassert.h>
#include <QCheckBox>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QMessageBox>
#include <QUrl>
namespace QmlDesigner {
@@ -230,6 +234,26 @@ void ContentLibraryUserModel::removeTextures(const QStringList &fileNames, const
void ContentLibraryUserModel::removeTexture(ContentLibraryTexture *tex, bool refresh)
{
bool askBeforeDelete = QmlDesignerPlugin::settings()
.value(DesignerSettingsKey::ASK_BEFORE_DELETING_CONTENTLIB_FILE)
.toBool();
if (askBeforeDelete) {
QMessageBox msgBox(QMessageBox::Question,
tr("Confirm texture deletion"),
tr("The selected texture might be in use. Delete anyway?"),
QMessageBox::Yes | QMessageBox::No,
m_widget);
QCheckBox *dontAskAgain = new QCheckBox(tr("Don't ask again"), &msgBox);
msgBox.setCheckBox(dontAskAgain);
if (msgBox.exec() == QMessageBox::No)
return;
if (dontAskAgain->isChecked())
QmlDesignerPlugin::settings().insert(DesignerSettingsKey::ASK_BEFORE_DELETING_CONTENTLIB_FILE, false);
}
// remove resources
Utils::FilePath::fromString(tex->texturePath()).removeFile();
Utils::FilePath::fromString(tex->iconPath()).removeFile();

View File

@@ -82,6 +82,7 @@ private:
QRadioButton *m_useQsTranslateFunctionRadioButton;
QCheckBox *m_designerAlwaysDesignModeCheckBox;
QCheckBox *m_askBeforeDeletingAssetCheckBox;
QCheckBox *m_askBeforeDeletingContentLibFileCheckBox;
QCheckBox *m_alwaysAutoFormatUICheckBox;
QCheckBox *m_featureTimelineEditorCheckBox;
QCheckBox *m_featureDockWidgetContentMinSize;
@@ -186,6 +187,8 @@ SettingsPageWidget::SettingsPageWidget(ExternalDependencies &externalDependencie
Tr::tr("Always open ui.qml files in Design mode"));
m_askBeforeDeletingAssetCheckBox = new QCheckBox(
Tr::tr("Ask for confirmation before deleting asset"));
m_askBeforeDeletingContentLibFileCheckBox = new QCheckBox(
Tr::tr("Ask for confirmation before deleting content library files"));
m_alwaysAutoFormatUICheckBox = new QCheckBox(
Tr::tr("Always auto-format ui.qml files in Design mode"));
m_featureTimelineEditorCheckBox = new QCheckBox(Tr::tr("Enable Timeline editor"));
@@ -267,6 +270,8 @@ SettingsPageWidget::SettingsPageWidget(ExternalDependencies &externalDependencie
m_alwaysAutoFormatUICheckBox,
br,
m_askBeforeDeletingAssetCheckBox,
m_askBeforeDeletingContentLibFileCheckBox,
br,
m_featureTimelineEditorCheckBox,
br,
m_featureDockWidgetContentMinSize}},
@@ -383,6 +388,8 @@ QHash<QByteArray, QVariant> SettingsPageWidget::newSettings() const
m_designerAlwaysDesignModeCheckBox->isChecked());
settings.insert(DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET,
m_askBeforeDeletingAssetCheckBox->isChecked());
settings.insert(DesignerSettingsKey::ASK_BEFORE_DELETING_CONTENTLIB_FILE,
m_askBeforeDeletingContentLibFileCheckBox->isChecked());
settings.insert(DesignerSettingsKey::SMOOTH_RENDERING, m_smoothRendering->isChecked());
settings.insert(DesignerSettingsKey::REFORMAT_UI_QML_FILES,
@@ -463,6 +470,8 @@ void SettingsPageWidget::setSettings(const DesignerSettings &settings)
m_askBeforeDeletingAssetCheckBox->setChecked(
settings.value(DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET).toBool());
m_askBeforeDeletingContentLibFileCheckBox->setChecked(
settings.value(DesignerSettingsKey::ASK_BEFORE_DELETING_CONTENTLIB_FILE).toBool());
const auto showDebugSettings = settings.value(DesignerSettingsKey::SHOW_DEBUG_SETTINGS).toBool()
|| Utils::qtcEnvironmentVariableIsSet(

View File

@@ -85,6 +85,7 @@ void DesignerSettings::fromSettings(QtcSettings *settings)
restoreValue(settings, DesignerSettingsKey::ALWAYS_DESIGN_MODE, true);
restoreValue(settings, DesignerSettingsKey::DISABLE_ITEM_LIBRARY_UPDATE_TIMER, false);
restoreValue(settings, DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET, true);
restoreValue(settings, DesignerSettingsKey::ASK_BEFORE_DELETING_CONTENTLIB_FILE, true);
restoreValue(settings, DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR,
QStringList{"#222222", "#999999"});
restoreValue(settings, DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, "#cccccc");

View File

@@ -65,6 +65,7 @@ inline constexpr char COLOR_PALETTE_FAVORITE[] = "ColorPaletteFavorite";
inline constexpr char ALWAYS_DESIGN_MODE[] = "AlwaysDesignMode";
inline constexpr char DISABLE_ITEM_LIBRARY_UPDATE_TIMER[] = "DisableItemLibraryUpdateTimer";
inline constexpr char ASK_BEFORE_DELETING_ASSET[] = "AskBeforeDeletingAsset";
inline constexpr char ASK_BEFORE_DELETING_CONTENTLIB_FILE[] = "AskBeforeDeletingContentLibFile";
inline constexpr char SMOOTH_RENDERING[] = "SmoothRendering";
inline constexpr char EDITOR_ZOOM_FACTOR[] = "EditorZoomFactor";
inline constexpr char ACTIONS_MERGE_TEMPLATE_ENABLED[] = "ActionsMergeTemplateEnabled";