Commit 678815ad authored by jan.koester's avatar jan.koester
Browse files

test

parent 890caffd
Loading
Loading
Loading
Loading
+24 −0
Changes for editor/localapi.cpp: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@

#include <QFileDialog>
#include <QFile>
#include <QDirIterator>
#include <QGuiApplication>
#include <QJsonDocument>
#include <QJsonArray>
@@ -209,6 +210,29 @@ bool LocalApi::renameBrowserFile(const QString &oldPath, const QString &newName)
    return dir.rename(fi.fileName(), newName);
}

bool LocalApi::moveBrowserFile(const QString &sourcePath, const QString &destFolder) {
    QFileInfo fi(sourcePath);
    if (!fi.exists()) return false;
    QDir dest(destFolder);
    if (!dest.exists()) return false;
    QString newPath = dest.filePath(fi.fileName());
    if (QFileInfo::exists(newPath)) return false;
    return QFile::rename(sourcePath, newPath);
}

QStringList LocalApi::listBrowserFolders() {
    QStringList folders;
    QString root = getLastBrowserFolder();
    if (root.isEmpty()) return folders;
    QDirIterator it(root, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
    while (it.hasNext()) {
        it.next();
        folders.append(it.filePath());
    }
    folders.sort();
    return folders;
}

bool LocalApi::deleteBrowserFile(const QString &path) {
    QFile file(path);
    return file.remove();
+2 −0
Changes for editor/localapi.h: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -100,6 +100,8 @@ public:
    Q_INVOKABLE bool createBrowserFolder(const QString &parentPath, const QString &name);
    Q_INVOKABLE bool createBrowserFile(const QString &parentPath, const QString &name);
    Q_INVOKABLE bool renameBrowserFile(const QString &oldPath, const QString &newName);
    Q_INVOKABLE bool moveBrowserFile(const QString &sourcePath, const QString &destFolder);
    Q_INVOKABLE QStringList listBrowserFolders();
    Q_INVOKABLE bool deleteBrowserFile(const QString &path);
    Q_INVOKABLE bool deleteBrowserFolder(const QString &path);
    Q_INVOKABLE QString openFolderDialog();
+131 −0
Changes for editor/qml/FileBrowserTab.qml: 131 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -122,6 +122,17 @@ Item {
                    }
                }
            }
            Action {
                text: qsTr("Move to...")
                onTriggered: {
                    moveDialog.sourcePath = ctxMenu.targetPath
                    moveDialog.sourceName = ctxMenu.targetName
                    var folders = localApi.listBrowserFolders()
                    var rootPath = localApi.getLastBrowserFolder()
                    moveDialog.folderList = [rootPath].concat(folders)
                    moveDialog.open()
                }
            }
            MenuSeparator {}
            Action {
                text: qsTr("Edit .gitignore")
@@ -229,4 +240,124 @@ Item {
            localApi.fileSystemModel().refreshGitStatus()
        }
    }

    Dialog {
        id: moveDialog
        property string sourcePath: ""
        property string sourceName: ""
        property var folderList: []
        property string moveStatus: ""

        title: qsTr("Move \"%1\" to...").arg(sourceName)
        standardButtons: Dialog.Ok | Dialog.Cancel
        width: 450
        height: 400
        x: (root.width - width) / 2
        y: (root.height - height) / 2
        modal: true

        onAccepted: {
            if (folderListView.currentIndex >= 0 && folderListView.currentIndex < folderList.length) {
                var dest = folderList[folderListView.currentIndex]
                if (!localApi.moveBrowserFile(sourcePath, dest)) {
                    moveDialog.moveStatus = qsTr("Move failed — file may already exist in target.")
                } else {
                    moveDialog.moveStatus = ""
                }
            }
        }
        onOpened: {
            moveDialog.moveStatus = ""
            folderSearchField.text = ""
            folderListView.currentIndex = -1
        }

        ColumnLayout {
            anchors.fill: parent
            spacing: 8

            Label {
                text: qsTr("Select destination folder:")
                font.pixelSize: 12
            }

            TextField {
                id: folderSearchField
                Layout.fillWidth: true
                placeholderText: qsTr("Filter folders...")
                font.pixelSize: 12
            }

            Rectangle {
                Layout.fillWidth: true
                Layout.fillHeight: true
                color: "transparent"
                border.color: Theme.border
                border.width: 1
                radius: 3

                ListView {
                    id: folderListView
                    anchors.fill: parent
                    anchors.margins: 2
                    clip: true
                    model: {
                        var filter = folderSearchField.text.toLowerCase()
                        if (filter === "") return moveDialog.folderList
                        var filtered = []
                        for (var i = 0; i < moveDialog.folderList.length; i++) {
                            if (moveDialog.folderList[i].toLowerCase().indexOf(filter) >= 0)
                                filtered.push(moveDialog.folderList[i])
                        }
                        return filtered
                    }

                    delegate: Rectangle {
                        width: folderListView.width
                        height: 30
                        color: folderListView.currentIndex === index ? Qt.rgba(Theme.accent.r, Theme.accent.g, Theme.accent.b, 0.2) : "transparent"
                        radius: 2

                        RowLayout {
                            anchors.fill: parent
                            anchors.leftMargin: 8
                            anchors.rightMargin: 8
                            spacing: 4

                            Label {
                                text: "\uD83D\uDCC1"
                                font.pixelSize: 13
                            }
                            Label {
                                property string rootPath: localApi.getLastBrowserFolder()
                                text: modelData.startsWith(rootPath) ? modelData.substring(rootPath.length) || "/" : modelData
                                font.pixelSize: 12
                                color: folderListView.currentIndex === index ? Theme.accent : Theme.textPrimary
                                Layout.fillWidth: true
                                elide: Text.ElideMiddle
                            }
                        }

                        MouseArea {
                            anchors.fill: parent
                            onClicked: folderListView.currentIndex = index
                            onDoubleClicked: {
                                folderListView.currentIndex = index
                                moveDialog.accept()
                            }
                        }
                    }
                }
            }

            Label {
                text: moveDialog.moveStatus
                font.pixelSize: 11
                color: "red"
                visible: moveDialog.moveStatus !== ""
                Layout.fillWidth: true
                wrapMode: Text.Wrap
            }
        }
    }
}