1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

feat: Add line numbers toggle to Notepad settings

This commit is contained in:
purian23
2025-09-20 19:06:58 -04:00
parent d4816bd174
commit ffc13f71b7
4 changed files with 104 additions and 4 deletions

View File

@@ -87,9 +87,11 @@ Singleton {
property bool notepadUseMonospace: true property bool notepadUseMonospace: true
property string notepadFontFamily: "" property string notepadFontFamily: ""
property real notepadFontSize: 14 property real notepadFontSize: 14
property bool notepadShowLineNumbers: false
onNotepadUseMonospaceChanged: saveSettings() onNotepadUseMonospaceChanged: saveSettings()
onNotepadFontFamilyChanged: saveSettings() onNotepadFontFamilyChanged: saveSettings()
onNotepadFontSizeChanged: saveSettings() onNotepadFontSizeChanged: saveSettings()
onNotepadShowLineNumbersChanged: saveSettings()
property bool gtkThemingEnabled: false property bool gtkThemingEnabled: false
property bool qtThemingEnabled: false property bool qtThemingEnabled: false
property bool showDock: false property bool showDock: false
@@ -264,6 +266,7 @@ Singleton {
notepadUseMonospace = settings.notepadUseMonospace !== undefined ? settings.notepadUseMonospace : true notepadUseMonospace = settings.notepadUseMonospace !== undefined ? settings.notepadUseMonospace : true
notepadFontFamily = settings.notepadFontFamily !== undefined ? settings.notepadFontFamily : "" notepadFontFamily = settings.notepadFontFamily !== undefined ? settings.notepadFontFamily : ""
notepadFontSize = settings.notepadFontSize !== undefined ? settings.notepadFontSize : 14 notepadFontSize = settings.notepadFontSize !== undefined ? settings.notepadFontSize : 14
notepadShowLineNumbers = settings.notepadShowLineNumbers !== undefined ? settings.notepadShowLineNumbers : false
gtkThemingEnabled = settings.gtkThemingEnabled !== undefined ? settings.gtkThemingEnabled : false gtkThemingEnabled = settings.gtkThemingEnabled !== undefined ? settings.gtkThemingEnabled : false
qtThemingEnabled = settings.qtThemingEnabled !== undefined ? settings.qtThemingEnabled : false qtThemingEnabled = settings.qtThemingEnabled !== undefined ? settings.qtThemingEnabled : false
showDock = settings.showDock !== undefined ? settings.showDock : false showDock = settings.showDock !== undefined ? settings.showDock : false
@@ -370,6 +373,7 @@ Singleton {
"notepadUseMonospace": notepadUseMonospace, "notepadUseMonospace": notepadUseMonospace,
"notepadFontFamily": notepadFontFamily, "notepadFontFamily": notepadFontFamily,
"notepadFontSize": notepadFontSize, "notepadFontSize": notepadFontSize,
"notepadShowLineNumbers": notepadShowLineNumbers,
"gtkThemingEnabled": gtkThemingEnabled, "gtkThemingEnabled": gtkThemingEnabled,
"qtThemingEnabled": qtThemingEnabled, "qtThemingEnabled": qtThemingEnabled,
"showDock": showDock, "showDock": showDock,

View File

@@ -143,6 +143,18 @@ Item {
} }
} }
DankToggle {
anchors.left: parent.left
anchors.leftMargin: -Theme.spacingM
width: parent.width + Theme.spacingM
text: "Show Line Numbers"
description: "Display line numbers in editor"
checked: SettingsData.notepadShowLineNumbers
onToggled: checked => {
SettingsData.notepadShowLineNumbers = checked
}
}
Rectangle { Rectangle {
width: parent.width width: parent.width
height: visible ? (fontDropdown.height + Theme.spacingS) : 0 height: visible ? (fontDropdown.height + Theme.spacingS) : 0

View File

@@ -63,6 +63,26 @@ Column {
saveCurrentTabContent() saveCurrentTabContent()
} }
function setTextDocumentLineHeight() {
return
}
property string lastTextForLineModel: ""
property var lineModel: []
function updateLineModel() {
if (!SettingsData.notepadShowLineNumbers) {
lineModel = []
lastTextForLineModel = ""
return
}
if (textArea.text !== lastTextForLineModel || lineModel.length === 0) {
lastTextForLineModel = textArea.text
lineModel = textArea.text.split('\n')
}
}
spacing: Theme.spacingM spacing: Theme.spacingM
StyledRect { StyledRect {
@@ -73,16 +93,70 @@ Column {
border.width: 1 border.width: 1
radius: Theme.cornerRadius radius: Theme.cornerRadius
ScrollView { DankFlickable {
id: flickable
anchors.fill: parent anchors.fill: parent
anchors.margins: 1 anchors.margins: 1
clip: true clip: true
contentWidth: width - 11
TextArea { Rectangle {
id: lineNumberArea
anchors.left: parent.left
anchors.top: parent.top
width: SettingsData.notepadShowLineNumbers ? Math.max(30, 32 + Theme.spacingXS) : 0
height: textArea.contentHeight + textArea.topPadding + textArea.bottomPadding
color: "transparent"
visible: SettingsData.notepadShowLineNumbers
ListView {
id: lineNumberList
anchors.top: parent.top
anchors.topMargin: textArea.topPadding
anchors.right: parent.right
anchors.rightMargin: 2
width: 32
height: textArea.contentHeight
model: SettingsData.notepadShowLineNumbers ? root.lineModel : []
interactive: false
spacing: 0
delegate: Item {
id: lineDelegate
required property int index
required property string modelData
width: 32
height: measuringText.contentHeight
Text {
id: measuringText
width: textArea.width - textArea.leftPadding - textArea.rightPadding
text: modelData || " "
font: textArea.font
wrapMode: Text.Wrap
visible: false
}
StyledText {
anchors.right: parent.right
anchors.rightMargin: 4
anchors.top: parent.top
text: index + 1
font.family: textArea.font.family
font.pixelSize: textArea.font.pixelSize
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.4)
horizontalAlignment: Text.AlignRight
}
}
}
}
TextArea.flickable: TextArea {
id: textArea id: textArea
placeholderText: qsTr("Start typing your notes here...") placeholderText: qsTr("Start typing your notes here...")
font.family: SettingsData.notepadUseMonospace ? SettingsData.monoFontFamily : (SettingsData.notepadFontFamily || SettingsData.fontFamily) font.family: SettingsData.notepadUseMonospace ? SettingsData.monoFontFamily : (SettingsData.notepadFontFamily || SettingsData.fontFamily)
font.pixelSize: SettingsData.notepadFontSize * SettingsData.fontScale font.pixelSize: SettingsData.notepadFontSize * SettingsData.fontScale
font.letterSpacing: 0
color: Theme.surfaceText color: Theme.surfaceText
selectByMouse: true selectByMouse: true
selectByKeyboard: true selectByKeyboard: true
@@ -93,13 +167,15 @@ Column {
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
persistentSelection: true persistentSelection: true
tabStopDistance: 40 tabStopDistance: 40
leftPadding: Theme.spacingM leftPadding: (SettingsData.notepadShowLineNumbers ? lineNumberArea.width + Theme.spacingXS : Theme.spacingM)
topPadding: Theme.spacingM topPadding: Theme.spacingM
rightPadding: Theme.spacingM rightPadding: Theme.spacingM
bottomPadding: Theme.spacingM bottomPadding: Theme.spacingM
Component.onCompleted: { Component.onCompleted: {
loadCurrentTabContent() loadCurrentTabContent()
setTextDocumentLineHeight()
root.updateLineModel()
} }
Connections { Connections {
@@ -114,11 +190,19 @@ Column {
} }
} }
Connections {
target: SettingsData
function onNotepadShowLineNumbersChanged() {
root.updateLineModel()
}
}
onTextChanged: { onTextChanged: {
if (contentLoaded && text !== lastSavedContent) { if (contentLoaded && text !== lastSavedContent) {
autoSaveTimer.restart() autoSaveTimer.restart()
} }
root.contentChanged() root.contentChanged()
root.updateLineModel()
} }
Keys.onEscapePressed: (event) => { Keys.onEscapePressed: (event) => {

View File

@@ -12,7 +12,7 @@ ScrollBar {
policy: (parent && parent.contentHeight > parent.height) ? ScrollBar.AsNeeded : ScrollBar.AlwaysOff policy: (parent && parent.contentHeight > parent.height) ? ScrollBar.AsNeeded : ScrollBar.AlwaysOff
minimumSize: 0.08 minimumSize: 0.08
implicitWidth: 10 implicitWidth: 8
interactive: true interactive: true
hoverEnabled: true hoverEnabled: true
z: 1000 z: 1000