Add basic debug logger.
This commit is contained in:
@@ -7,6 +7,7 @@ import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
import clide.module 1.0
|
||||
import Logger 1.0
|
||||
|
||||
SplitView {
|
||||
id: root
|
||||
@@ -78,6 +79,9 @@ SplitView {
|
||||
text: parent.index + 1
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
width: parent.width - indicator.width
|
||||
background: Rectangle {
|
||||
color: RustColors.terminal_background
|
||||
}
|
||||
}
|
||||
// Draw edge along the right side of the line number.
|
||||
Rectangle {
|
||||
@@ -149,20 +153,8 @@ SplitView {
|
||||
}
|
||||
}
|
||||
}
|
||||
TextArea {
|
||||
ClideLogger {
|
||||
id: areaConsole
|
||||
|
||||
height: 100
|
||||
width: parent.width
|
||||
placeholderText: qsTr("shaun@pc:~/Code/clide$ ")
|
||||
placeholderTextColor: "white"
|
||||
readOnly: true
|
||||
wrapMode: TextArea.Wrap
|
||||
background: Rectangle {
|
||||
color: RustColors.terminal_background
|
||||
implicitHeight: 100
|
||||
// border.color: control.enabled ? RustColors.active : RustColors.inactive
|
||||
}
|
||||
}
|
||||
|
||||
// We use an inline component to customize the horizontal and vertical
|
||||
@@ -208,4 +200,11 @@ SplitView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
// Show logging is working.
|
||||
Logger.debug("Debug console ready")
|
||||
Logger.warn("Warnings show up too")
|
||||
}
|
||||
}
|
||||
|
||||
58
qml/ClideLogger.qml
Normal file
58
qml/ClideLogger.qml
Normal file
@@ -0,0 +1,58 @@
|
||||
// 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 clide.module 1.0
|
||||
import Logger 1.0
|
||||
|
||||
Item {
|
||||
ListModel { id: model }
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: "#111"
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
anchors.fill: parent
|
||||
model: model
|
||||
clip: true
|
||||
|
||||
function getLogColor(level) {
|
||||
switch (level) {
|
||||
case "INFO":
|
||||
return RustColors.info_log
|
||||
break;
|
||||
case "DEBUG":
|
||||
return RustColors.debug_log
|
||||
break;
|
||||
case "WARN":
|
||||
return RustColors.warn_log
|
||||
break;
|
||||
case "ERROR":
|
||||
return RustColors.error_log
|
||||
break;
|
||||
default:
|
||||
return RustColors.info_log
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Text {
|
||||
text: `[${level}] ${message}`
|
||||
font.family: "monospace"
|
||||
color: listView.getLogColor(level)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Logger
|
||||
function onLogged(level, message) {
|
||||
model.append({ level, message })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
import clide.module 1.0
|
||||
import Logger 1.0
|
||||
|
||||
SplitView {
|
||||
id: root
|
||||
@@ -62,9 +63,7 @@ SplitView {
|
||||
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.RightButton
|
||||
onSingleTapped: (eventPoint, button) => {
|
||||
contextMenu.popup()
|
||||
}
|
||||
onSingleTapped: (eventPoint, button) => contextMenu.popup()
|
||||
}
|
||||
|
||||
Menu {
|
||||
@@ -72,7 +71,7 @@ SplitView {
|
||||
Action {
|
||||
text: qsTr("Reset root index")
|
||||
onTriggered: {
|
||||
console.log("Resetting root directory: " + clideTreeView.originalRootDirectory)
|
||||
Logger.log("Resetting root directory: " + clideTreeView.originalRootDirectory)
|
||||
clideTreeView.rootDirectory = clideTreeView.originalRootDirectory
|
||||
}
|
||||
}
|
||||
@@ -89,7 +88,7 @@ SplitView {
|
||||
originalRootDirectory: root.projectDir
|
||||
rootDirectory: root.projectDir
|
||||
onRootDirectoryChanged: {
|
||||
console.log(clideTreeView.rootDirectory)
|
||||
Logger.log(clideTreeView.rootDirectory)
|
||||
breadCrumb.text = clideTreeView.rootDirectory
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import QtQuick.Effects
|
||||
import QtQuick.Controls
|
||||
|
||||
import clide.module 1.0
|
||||
import Logger 1.0
|
||||
|
||||
TreeView {
|
||||
id: fileSystemTreeView
|
||||
@@ -133,14 +134,14 @@ TreeView {
|
||||
text: qsTr("Set as root index")
|
||||
enabled: treeDelegate.hasChildren
|
||||
onTriggered: {
|
||||
console.log("Setting new root directory: " + treeDelegate.filePath)
|
||||
Logger.debug("Setting new root directory: " + treeDelegate.filePath)
|
||||
fileSystemTreeView.rootDirectory = treeDelegate.filePath
|
||||
}
|
||||
}
|
||||
Action {
|
||||
text: qsTr("Reset root index")
|
||||
onTriggered: {
|
||||
console.log("Resetting root directory: " + fileSystemTreeView.originalRootDirectory)
|
||||
Logger.log("Resetting root directory: " + fileSystemTreeView.originalRootDirectory)
|
||||
fileSystemTreeView.rootDirectory = fileSystemTreeView.originalRootDirectory
|
||||
}
|
||||
}
|
||||
|
||||
26
qml/Logger/Logger.qml
Normal file
26
qml/Logger/Logger.qml
Normal file
@@ -0,0 +1,26 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
|
||||
QtObject {
|
||||
signal logged(string level, string message)
|
||||
|
||||
function log(msg) {
|
||||
console.log(msg)
|
||||
logged("INFO", msg)
|
||||
}
|
||||
|
||||
function debug(msg) {
|
||||
console.log(msg)
|
||||
logged("DEBUG", msg)
|
||||
}
|
||||
|
||||
function warn(msg) {
|
||||
console.warn(msg)
|
||||
logged("WARN", msg)
|
||||
}
|
||||
|
||||
function error(msg) {
|
||||
console.error(msg)
|
||||
logged("ERROR", msg)
|
||||
}
|
||||
}
|
||||
1
qml/Logger/qmldir
Normal file
1
qml/Logger/qmldir
Normal file
@@ -0,0 +1 @@
|
||||
singleton Logger 1.0 Logger.qml
|
||||
@@ -27,6 +27,7 @@ ApplicationWindow {
|
||||
title: qsTr("Error")
|
||||
}
|
||||
ClideProjectView {
|
||||
id: clideProjectView
|
||||
projectDir: appWindow.appContextPath
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user