forked from qt-creator/qt-creator
QmlDesigner: Disable Asset Library context menu when not needed
Assets Library context menus options are now enabled only when needed and disabled otherwise. Also some renaming etc. Task-number: QDS-4628 Change-Id: I5b2c4209f8389e51cf3f5e470bc14e5f9ffc1f29 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -33,6 +33,7 @@ import StudioTheme 1.0 as StudioTheme
|
|||||||
|
|
||||||
Item {
|
Item {
|
||||||
property var selectedAssets: ({})
|
property var selectedAssets: ({})
|
||||||
|
property int allExpandedState: 0
|
||||||
|
|
||||||
DropArea {
|
DropArea {
|
||||||
id: dropArea
|
id: dropArea
|
||||||
@@ -81,11 +82,13 @@ Item {
|
|||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Expand All")
|
text: qsTr("Expand All")
|
||||||
|
enabled: allExpandedState !== 1
|
||||||
onTriggered: assetsModel.toggleExpandAll(true)
|
onTriggered: assetsModel.toggleExpandAll(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Collapse All")
|
text: qsTr("Collapse All")
|
||||||
|
enabled: allExpandedState !== 2
|
||||||
onTriggered: assetsModel.toggleExpandAll(false)
|
onTriggered: assetsModel.toggleExpandAll(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,6 +121,7 @@ Item {
|
|||||||
dirExpanded = !dirExpanded
|
dirExpanded = !dirExpanded
|
||||||
}
|
}
|
||||||
onShowContextMenu: {
|
onShowContextMenu: {
|
||||||
|
allExpandedState = assetsModel.getAllExpandedState()
|
||||||
contextMenu.popup()
|
contextMenu.popup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,14 +44,35 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
void ItemLibraryAssetsModel::saveExpandedState(bool expanded, const QString §ionName)
|
void ItemLibraryAssetsModel::saveExpandedState(bool expanded, const QString &assetPath)
|
||||||
{
|
{
|
||||||
m_expandedStateHash.insert(sectionName, expanded);
|
m_expandedStateHash.insert(assetPath, expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemLibraryAssetsModel::loadExpandedState(const QString §ionName)
|
bool ItemLibraryAssetsModel::loadExpandedState(const QString &assetPath)
|
||||||
{
|
{
|
||||||
return m_expandedStateHash.value(sectionName, true);
|
return m_expandedStateHash.value(assetPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemLibraryAssetsModel::DirExpandState ItemLibraryAssetsModel::getAllExpandedState() const
|
||||||
|
{
|
||||||
|
const auto keys = m_expandedStateHash.keys();
|
||||||
|
bool allExpanded = true;
|
||||||
|
bool allCollapsed = true;
|
||||||
|
for (const QString &assetPath : keys) {
|
||||||
|
bool expanded = m_expandedStateHash.value(assetPath);
|
||||||
|
|
||||||
|
if (expanded)
|
||||||
|
allCollapsed = false;
|
||||||
|
if (!expanded)
|
||||||
|
allExpanded = false;
|
||||||
|
|
||||||
|
if (!allCollapsed && !allExpanded)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return allExpanded ? DirExpandState::AllExpanded : allCollapsed ? DirExpandState::AllCollapsed
|
||||||
|
: DirExpandState::SomeExpanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibraryAssetsModel::toggleExpandAll(bool expand)
|
void ItemLibraryAssetsModel::toggleExpandAll(bool expand)
|
||||||
@@ -200,6 +221,7 @@ void ItemLibraryAssetsModel::setRootPath(const QString &path)
|
|||||||
|
|
||||||
ItemLibraryAssetsDir *assetsDir = new ItemLibraryAssetsDir(subDir.path(), currDepth, loadExpandedState(subDir.path()), currAssetsDir);
|
ItemLibraryAssetsDir *assetsDir = new ItemLibraryAssetsDir(subDir.path(), currDepth, loadExpandedState(subDir.path()), currAssetsDir);
|
||||||
currAssetsDir->addDir(assetsDir);
|
currAssetsDir->addDir(assetsDir);
|
||||||
|
saveExpandedState(loadExpandedState(assetsDir->dirPath()), assetsDir->dirPath());
|
||||||
isEmpty &= parseDirRecursive(assetsDir, currDepth + 1);
|
isEmpty &= parseDirRecursive(assetsDir, currDepth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -69,10 +69,18 @@ public:
|
|||||||
const QSet<QString> &supportedSuffixes() const;
|
const QSet<QString> &supportedSuffixes() const;
|
||||||
const QSet<QString> &previewableSuffixes() const;
|
const QSet<QString> &previewableSuffixes() const;
|
||||||
|
|
||||||
static void saveExpandedState(bool expanded, const QString §ionName);
|
static void saveExpandedState(bool expanded, const QString &assetPath);
|
||||||
static bool loadExpandedState(const QString §ionName);
|
static bool loadExpandedState(const QString &assetPath);
|
||||||
|
|
||||||
|
enum class DirExpandState {
|
||||||
|
SomeExpanded,
|
||||||
|
AllExpanded,
|
||||||
|
AllCollapsed
|
||||||
|
};
|
||||||
|
Q_ENUM(DirExpandState)
|
||||||
|
|
||||||
Q_INVOKABLE void toggleExpandAll(bool expand);
|
Q_INVOKABLE void toggleExpandAll(bool expand);
|
||||||
|
Q_INVOKABLE DirExpandState getAllExpandedState() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SynchronousImageCache &m_fontImageCache;
|
SynchronousImageCache &m_fontImageCache;
|
||||||
@@ -83,7 +91,7 @@ private:
|
|||||||
ItemLibraryAssetsDir *m_assetsDir = nullptr;
|
ItemLibraryAssetsDir *m_assetsDir = nullptr;
|
||||||
|
|
||||||
QHash<int, QByteArray> m_roleNames;
|
QHash<int, QByteArray> m_roleNames;
|
||||||
inline static QHash<QString, bool> m_expandedStateHash;
|
inline static QHash<QString, bool> m_expandedStateHash; // <assetPath, isExpanded>
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user