clide/qml/ClideProjectView.qml
Shaun Reed fdfc8d3fd8 Add context menu on breadcrumbs.
The only option is to reset the root directory.
2026-02-01 18:52:48 -05:00

107 lines
3.4 KiB
QML

// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import clide.module 1.0
SplitView {
id: root
// Path to the directory of the project opened in clide.
required property string projectDir
Layout.fillHeight: true
Layout.fillWidth: true
anchors.fill: parent
// Customized handle to drag between the Navigation and the Editor.
handle: Rectangle {
id: verticalSplitHandle
border.color: SplitHandle.pressed ? RustColors.pressed : SplitHandle.hovered ? RustColors.hovered : RustColors.gutter
color: SplitHandle.pressed ? RustColors.pressed : SplitHandle.hovered ? RustColors.hovered : RustColors.gutter
implicitWidth: 8
radius: 2.5
// Execute these behaviors when the color is changed.
Behavior on color {
ColorAnimation {
duration: 400
}
}
}
Rectangle {
id: navigationView
color: RustColors.explorer_background
SplitView.fillHeight: true
SplitView.minimumWidth: 0
SplitView.preferredWidth: 200
SplitView.maximumWidth: 250
ColumnLayout {
spacing: 2
// TODO: Make a ClideBreadCrumb element to support select parent paths as root
Rectangle {
width: navigationView.width
height: 25
color: RustColors.explorer_background
Text {
id: breadCrumb
anchors.fill: parent
text: clideTreeView.rootDirectory
color: RustColors.explorer_text
elide: Text.ElideLeft
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
TapHandler {
acceptedButtons: Qt.RightButton
onSingleTapped: (eventPoint, button) => {
contextMenu.popup()
}
}
Menu {
id: contextMenu
Action {
text: qsTr("Reset root index")
onTriggered: {
console.log("Resetting root directory: " + clideTreeView.originalRootDirectory)
clideTreeView.rootDirectory = clideTreeView.originalRootDirectory
}
}
}
}
ClideTreeView {
id: clideTreeView
onFileClicked: path => clideEditor.filePath = path
width: navigationView.width
height: navigationView.height
// Path to the directory opened in the file explorer.
originalRootDirectory: root.projectDir
rootDirectory: root.projectDir
onRootDirectoryChanged: {
console.log(clideTreeView.rootDirectory)
breadCrumb.text = clideTreeView.rootDirectory
}
}
}
}
ClideEditor {
id: clideEditor
SplitView.fillWidth: true
// Provide a path to the file currently open in the text editor.
// Initialized using the Default trait in Rust QML singleton FileSystem.
filePath: FileSystem.filePath
}
}