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