Add clickable bread crumbs.
Clicking a parent path changes the root project directory.
This commit is contained in:
109
qml/Components/ClideBreadCrumbs.qml
Normal file
109
qml/Components/ClideBreadCrumbs.qml
Normal file
@@ -0,0 +1,109 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import clide.module 1.0
|
||||
import Logger 1.0
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property var fullPaths: []
|
||||
required property string path
|
||||
property var segments: []
|
||||
|
||||
signal crumbClicked(string path)
|
||||
|
||||
function rebuildSegments() {
|
||||
var cleaned = path;
|
||||
if (cleaned.endsWith("/"))
|
||||
cleaned = cleaned.slice(0, -1);
|
||||
var parts = cleaned.split("/");
|
||||
root.segments = [];
|
||||
root.fullPaths = [];
|
||||
var current = "";
|
||||
Logger.trace("Building segments for path: " + cleaned);
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
if (parts[i] === "") {
|
||||
current = "/";
|
||||
root.segments.push("/");
|
||||
root.fullPaths.push("/");
|
||||
} else {
|
||||
if (current === "/")
|
||||
current += parts[i];
|
||||
else
|
||||
current += "/" + parts[i];
|
||||
Logger.trace("Pushing path: " + parts[i] + " Current: " + current);
|
||||
root.segments.push(parts[i]);
|
||||
root.fullPaths.push(current);
|
||||
}
|
||||
}
|
||||
rep.model = root.segments;
|
||||
}
|
||||
|
||||
anchors.leftMargin: 20
|
||||
height: breadcrumbRow.implicitHeight
|
||||
width: parent.width
|
||||
|
||||
Component.onCompleted: rebuildSegments()
|
||||
onPathChanged: rebuildSegments()
|
||||
|
||||
Flow {
|
||||
id: breadcrumbRow
|
||||
|
||||
Repeater {
|
||||
id: rep
|
||||
|
||||
model: root.segments
|
||||
|
||||
delegate: Text {
|
||||
id: linkText
|
||||
|
||||
required property string modelData
|
||||
|
||||
function getText() {
|
||||
if (modelData === "/") {
|
||||
return modelData;
|
||||
}
|
||||
Logger.trace("Getting valid text:" + modelData);
|
||||
return modelData + "/";
|
||||
}
|
||||
|
||||
color: mouseArea.containsMouse ? "#2a7fff" : RustColors.explorer_text
|
||||
font.underline: mouseArea.containsMouse
|
||||
text: getText()
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
|
||||
onClicked: {
|
||||
console.log("Breadcrumb clicked:", root.fullPaths[root.segments.indexOf(modelData)]);
|
||||
root.crumbClicked(root.fullPaths[root.segments.indexOf(modelData)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.RightButton
|
||||
|
||||
onSingleTapped: (eventPoint, button) => contextMenu.popup()
|
||||
}
|
||||
ClideMenu {
|
||||
id: contextMenu
|
||||
|
||||
ClideMenuItem {
|
||||
action: Action {
|
||||
text: qsTr("Reset root")
|
||||
|
||||
onTriggered: {
|
||||
Logger.log("Resetting root directory: " + clideTreeView.originalRootDirectory);
|
||||
clideTreeView.rootDirectory = clideTreeView.originalRootDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,10 @@ import clide.module 1.0
|
||||
|
||||
Menu {
|
||||
background: Rectangle {
|
||||
border.color: Qt.darker(RustColors.menubar, 2)
|
||||
border.color: RustColors.hovered
|
||||
border.width: 10
|
||||
color: RustColors.menubar
|
||||
implicitWidth: 100
|
||||
radius: 2
|
||||
radius: 5
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@ ClideScrollBar ClideScrollBar.qml
|
||||
ClideHandle ClideHandle.qml
|
||||
ClideMenu ClideMenu.qml
|
||||
ClideMenuItem ClideMenuItem.qml
|
||||
ClideBreadCrumbs ClideBreadCrumbs.qml
|
||||
|
||||
Reference in New Issue
Block a user