添加文件夹重命名功能
This commit is contained in:
parent
b415eac4a4
commit
38343851e3
|
@ -1,13 +1,15 @@
|
||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
import QtQuick.Controls 2.5
|
import QtQuick.Controls 2.5
|
||||||
|
import AppControls2 1.0 as AppControls2
|
||||||
import org.ukui.menu.core 1.0
|
import org.ukui.menu.core 1.0
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: control
|
id: control
|
||||||
|
property bool editStatus: false
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
// ToolTip.visible: content.textTruncated && control.containsMouse
|
ToolTip.visible: textShow.truncated && textShow.visible && control.containsMouse
|
||||||
// ToolTip.text: name
|
ToolTip.text: name
|
||||||
|
|
||||||
StyleBackground {
|
StyleBackground {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
@ -19,6 +21,7 @@ MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.leftMargin: 12
|
anchors.leftMargin: 12
|
||||||
spacing: 12
|
spacing: 12
|
||||||
|
|
||||||
FolderIcon {
|
FolderIcon {
|
||||||
rows: 2; columns: 2
|
rows: 2; columns: 2
|
||||||
spacing: 2; padding: 2
|
spacing: 2; padding: 2
|
||||||
|
@ -28,14 +31,98 @@ MouseArea {
|
||||||
Layout.preferredHeight: 32
|
Layout.preferredHeight: 32
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Item {
|
||||||
|
id: renameArea
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
|
||||||
|
StyleText {
|
||||||
|
id: textShow
|
||||||
|
anchors.fill: parent
|
||||||
|
visible: !control.editStatus
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
horizontalAlignment: Text.AlignLeft
|
horizontalAlignment: Text.AlignLeft
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
text: name
|
text: name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppControls2.StyleBackground {
|
||||||
|
anchors.fill: parent
|
||||||
|
radius: 6
|
||||||
|
useStyleTransparent: false
|
||||||
|
alpha: textChange.activeFocus ? 0.04 : 0
|
||||||
|
paletteRole: Palette.Text
|
||||||
|
border.width: 2
|
||||||
|
borderAlpha: textChange.activeFocus ? 1 : 0
|
||||||
|
borderColor: Palette.Highlight
|
||||||
|
|
||||||
|
TextInput {
|
||||||
|
id: textChange
|
||||||
|
text: name
|
||||||
|
visible: control.editStatus
|
||||||
|
focus: false
|
||||||
|
clip: true
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 8
|
||||||
|
anchors.right: buttonMouseArea.left
|
||||||
|
anchors.rightMargin: 8
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
activeFocusOnPress: false
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
selectByMouse: true
|
||||||
|
maximumLength: 14
|
||||||
|
|
||||||
|
onEditingFinished: {
|
||||||
|
modelManager.getAppModel().renameFolder(id, text);
|
||||||
|
control.editStatus = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTextInputColor() {
|
||||||
|
color = themePalette.paletteColor(Palette.Text);
|
||||||
|
selectionColor = themePalette.paletteColor(Palette.Highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
updateTextInputColor();
|
||||||
|
themePalette.styleColorChanged.connect(updateTextInputColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: buttonMouseArea
|
||||||
|
hoverEnabled: true
|
||||||
|
width: 16; height: width
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 10
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
visible: textChange.activeFocus
|
||||||
|
|
||||||
|
ThemeIcon {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
width: 16; height: width
|
||||||
|
source: "image://appicon/edit-clear-symbolic"
|
||||||
|
}
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
textChange.text = name;
|
||||||
|
control.editStatus = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onEditStatusChanged: {
|
||||||
|
if (editStatus) {
|
||||||
|
textChange.forceActiveFocus();
|
||||||
|
textChange.focus = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
textChange.focus = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,18 @@ Item {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Component.onCompleted: {
|
||||||
|
appListView.model.renameText.connect(toEditText);
|
||||||
|
}
|
||||||
|
Component.onDestruction: {
|
||||||
|
appListView.model.renameText.disconnect(toEditText);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toEditText(idOfIndex){
|
||||||
|
if (id === idOfIndex) {
|
||||||
|
editStatus = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,22 +123,36 @@ SwipeView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AppControls2.StyleBackground {
|
Item {
|
||||||
|
id: contain
|
||||||
|
property bool editStatus: false
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
|
||||||
|
AppControls2.StyleText {
|
||||||
|
id: textShow
|
||||||
|
visible: !contain.editStatus
|
||||||
|
anchors.fill: parent
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
horizontalAlignment: Text.AlignLeft
|
||||||
|
elide: Text.ElideRight
|
||||||
|
text: title
|
||||||
|
}
|
||||||
|
|
||||||
|
AppControls2.StyleBackground {
|
||||||
|
anchors.fill: parent
|
||||||
radius: 6
|
radius: 6
|
||||||
alpha: folderText.activeFocus ? 0.04 : 0
|
|
||||||
useStyleTransparent: false
|
useStyleTransparent: false
|
||||||
|
alpha: textEdit.activeFocus ? 0.04 : 0
|
||||||
paletteRole: Palette.Text
|
paletteRole: Palette.Text
|
||||||
border.width: 2
|
border.width: 2
|
||||||
borderAlpha: folderText.activeFocus ? 1 : 0
|
borderAlpha: textEdit.activeFocus ? 1 : 0
|
||||||
borderColor: Palette.Highlight
|
borderColor: Palette.Highlight
|
||||||
|
|
||||||
TextInput {
|
TextInput {
|
||||||
id: folderText
|
id: textEdit
|
||||||
|
visible: contain.editStatus
|
||||||
clip: true
|
clip: true
|
||||||
font.pixelSize: 14
|
|
||||||
focus: false
|
focus: false
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: 8
|
anchors.leftMargin: 8
|
||||||
|
@ -153,8 +167,8 @@ SwipeView {
|
||||||
|
|
||||||
onEditingFinished: {
|
onEditingFinished: {
|
||||||
modelManager.getFolderModel().renameFolder(text);
|
modelManager.getFolderModel().renameFolder(text);
|
||||||
folderText.focus = false;
|
textShow.text = text;
|
||||||
folderText.z = 0;
|
contain.editStatus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTextInputColor() {
|
function updateTextInputColor() {
|
||||||
|
@ -173,11 +187,9 @@ SwipeView {
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: textArea
|
id: textArea
|
||||||
anchors.fill: folderText
|
anchors.fill: textEdit
|
||||||
onDoubleClicked: {
|
onDoubleClicked: {
|
||||||
forceActiveFocus();
|
contain.editStatus = true;
|
||||||
folderText.focus = true;
|
|
||||||
folderText.z = 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +200,7 @@ SwipeView {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: 10
|
anchors.rightMargin: 10
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
visible: folderText.activeFocus
|
visible: textEdit.activeFocus
|
||||||
|
|
||||||
ThemeIcon {
|
ThemeIcon {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
@ -197,9 +209,20 @@ SwipeView {
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
folderText.text = title;
|
textEdit.text = title;
|
||||||
folderText.focus = false;
|
contain.editStatus = false;
|
||||||
folderText.z = 0;
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onEditStatusChanged: {
|
||||||
|
if (editStatus) {
|
||||||
|
textEdit.z = 2;
|
||||||
|
textEdit.forceActiveFocus();
|
||||||
|
textEdit.focus = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
textEdit.z = 0;
|
||||||
|
textEdit.focus = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include "app-folder-helper.h"
|
#include "app-folder-helper.h"
|
||||||
#include "menu-manager.h"
|
#include "menu-manager.h"
|
||||||
#include "app-data-manager.h"
|
#include "app-data-manager.h"
|
||||||
|
#include "model-manager.h"
|
||||||
|
#include "app-model.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
@ -109,10 +111,10 @@ void FolderMenuProvider::folderMenuForNormal(QObject *parent, const QString &app
|
||||||
|
|
||||||
void FolderMenuProvider::folderMenuForFolder(QObject *parent, const QString &folderId, QList<QAction *> &list)
|
void FolderMenuProvider::folderMenuForFolder(QObject *parent, const QString &folderId, QList<QAction *> &list)
|
||||||
{
|
{
|
||||||
// list << new QAction(QObject::tr("Rename"), parent);
|
list << new QAction(QObject::tr("Rename"), parent);
|
||||||
// QObject::connect(list.last(), &QAction::triggered, parent, [folderId] {
|
QObject::connect(list.last(), &QAction::triggered, parent, [folderId] {
|
||||||
// AppFolderHelper::instance()->renameFolder(folderId.toInt(), "new name");
|
ModelManager::instance()->getAppModel()->toRenameFolder(folderId);
|
||||||
// });
|
});
|
||||||
|
|
||||||
list << new QAction(QObject::tr("Dissolve folder"), parent);
|
list << new QAction(QObject::tr("Dissolve folder"), parent);
|
||||||
QObject::connect(list.last(), &QAction::triggered, parent, [folderId] {
|
QObject::connect(list.last(), &QAction::triggered, parent, [folderId] {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "app-model.h"
|
#include "app-model.h"
|
||||||
#include "app-manager.h"
|
#include "app-manager.h"
|
||||||
#include "menu-manager.h"
|
#include "menu-manager.h"
|
||||||
|
#include "app-folder-helper.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
@ -110,6 +111,11 @@ void AppModel::reloadPluginData()
|
||||||
resetModel(data);
|
resetModel(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppModel::toRenameFolder(QString id)
|
||||||
|
{
|
||||||
|
Q_EMIT renameText(id);
|
||||||
|
}
|
||||||
|
|
||||||
void AppModel::onPluginDataChanged(QVector<DataEntity> data, DataUpdateMode::Mode mode, quint32 index)
|
void AppModel::onPluginDataChanged(QVector<DataEntity> data, DataUpdateMode::Mode mode, quint32 index)
|
||||||
{
|
{
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
@ -180,6 +186,11 @@ void AppModel::openMenu(const int &index)
|
||||||
MenuManager::instance()->showMenu(m_apps.at(index));
|
MenuManager::instance()->showMenu(m_apps.at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppModel::renameFolder(const QString &index, const QString &folderName)
|
||||||
|
{
|
||||||
|
AppFolderHelper::instance()->renameFolder(index.toInt(), folderName);
|
||||||
|
}
|
||||||
|
|
||||||
QVariantList AppModel::getApps(int start, int end)
|
QVariantList AppModel::getApps(int start, int end)
|
||||||
{
|
{
|
||||||
if (start < 0 || start >= m_apps.size() || end < 0 || end > m_apps.size()) {
|
if (start < 0 || start >= m_apps.size() || end < 0 || end > m_apps.size()) {
|
||||||
|
|
|
@ -42,6 +42,10 @@ public:
|
||||||
Q_INVOKABLE QVariantList folderApps(const QString &folderName);
|
Q_INVOKABLE QVariantList folderApps(const QString &folderName);
|
||||||
Q_INVOKABLE void appClicked(const int &index);
|
Q_INVOKABLE void appClicked(const int &index);
|
||||||
Q_INVOKABLE void openMenu(const int &index);
|
Q_INVOKABLE void openMenu(const int &index);
|
||||||
|
Q_INVOKABLE void renameFolder(const QString &index, const QString &folderName);
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void toRenameFolder(QString id);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onPluginDataChanged(QVector<DataEntity> data, DataUpdateMode::Mode mode, quint32 index);
|
void onPluginDataChanged(QVector<DataEntity> data, DataUpdateMode::Mode mode, quint32 index);
|
||||||
|
@ -55,6 +59,9 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<DataEntity> m_apps;
|
QVector<DataEntity> m_apps;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
Q_INVOKABLE void renameText(QString id);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // UkuiMenu
|
} // UkuiMenu
|
||||||
|
|
Loading…
Reference in New Issue