Skip to content

Commit 71b1901

Browse files
committed
notepad: add inline tab renaming and bump tab size
1 parent 32e2d96 commit 71b1901

6 files changed

Lines changed: 344 additions & 294 deletions

File tree

quickshell/Common/SessionData.qml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,18 @@ Singleton {
120120

121121
function setMonitorScrollPosition(screenName, scrollX, scrollY) {
122122
var newPositions = Object.assign({}, monitorScrollPositions);
123-
newPositions[screenName] = { scrollX: scrollX, scrollY: scrollY };
123+
newPositions[screenName] = {
124+
scrollX: scrollX,
125+
scrollY: scrollY
126+
};
124127
monitorScrollPositions = newPositions;
125128
}
126129

127130
function getMonitorScrollPosition(screenName) {
128-
return monitorScrollPositions[screenName] || { scrollX: 50, scrollY: 50 };
131+
return monitorScrollPositions[screenName] || {
132+
scrollX: 50,
133+
scrollY: 50
134+
};
129135
}
130136

131137
function clearMonitorScrollPosition(screenName) {
@@ -209,6 +215,8 @@ Singleton {
209215
property string locale: ""
210216
property string timeLocale: ""
211217

218+
property string notepadLastMode: ""
219+
212220
property string launcherLastMode: "all"
213221
property string launcherLastFileSearchType: "all"
214222
property string launcherLastQuery: ""
@@ -1216,6 +1224,13 @@ Singleton {
12161224
I18n.useLocale(locale, locale.startsWith("en") ? "" : I18n.folder + "/" + locale + ".json");
12171225
}
12181226

1227+
function setNotepadLastMode(mode) {
1228+
if (notepadLastMode === mode)
1229+
return;
1230+
notepadLastMode = mode;
1231+
saveSettings();
1232+
}
1233+
12191234
function setLauncherLastMode(mode) {
12201235
launcherLastMode = mode;
12211236
saveSettings();

quickshell/Common/settings/SessionSpec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ var SPEC = {
8888
locale: { def: "", onChange: "updateLocale" },
8989
timeLocale: { def: "" },
9090

91+
notepadLastMode: { def: "" },
92+
9193
launcherLastMode: { def: "all" },
9294
launcherLastFileSearchType: { def: "all" },
9395
launcherLastQuery: { def: "" },

quickshell/DMSShellIPC.qml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Item {
373373
}
374374

375375
function open(): string {
376-
if (SettingsData.notepadDefaultMode === "popout") {
376+
if (PopoutService.notepadResolvedMode === "popout") {
377377
PopoutService.openNotepadPopout();
378378
return "NOTEPAD_OPEN_SUCCESS";
379379
}
@@ -388,7 +388,7 @@ Item {
388388
function openFile(path: string): string {
389389
if (!path)
390390
return open();
391-
if (SettingsData.notepadDefaultMode === "popout") {
391+
if (PopoutService.notepadResolvedMode === "popout") {
392392
PopoutService.openNotepadPopoutWithFile(path);
393393
return "NOTEPAD_OPEN_FILE_SUCCESS";
394394
}
@@ -402,7 +402,7 @@ Item {
402402
}
403403

404404
function close(): string {
405-
if (SettingsData.notepadDefaultMode === "popout") {
405+
if (PopoutService.notepadResolvedMode === "popout") {
406406
PopoutService.notepadPopout?.hide();
407407
return "NOTEPAD_CLOSE_SUCCESS";
408408
}
@@ -415,7 +415,7 @@ Item {
415415
}
416416

417417
function toggle(): string {
418-
if (SettingsData.notepadDefaultMode === "popout") {
418+
if (PopoutService.notepadResolvedMode === "popout") {
419419
PopoutService.toggleNotepadPopout();
420420
return "NOTEPAD_TOGGLE_SUCCESS";
421421
}

quickshell/Modules/Notepad/NotepadTabs.qml

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ Column {
1313
property int draggedIndex: -1
1414
property int dropTargetIndex: -1
1515
property bool suppressShiftAnimation: false
16-
readonly property real tabItemSize: 128 + Theme.spacingXS
16+
property int editingIndex: -1
17+
readonly property real tabItemSize: tabRow.dynamicTabWidth + Theme.spacingXS
1718

1819
signal tabSwitched(int tabIndex)
1920
signal tabClosed(int tabIndex)
2021
signal newTabRequested
2122

23+
function commitRename(index, newTitle) {
24+
if (index >= 0)
25+
NotepadStorageService.renameTab(index, newTitle);
26+
editingIndex = -1;
27+
}
28+
2229
function hasUnsavedChangesForTab(tab) {
2330
if (!tab)
2431
return false;
@@ -32,11 +39,19 @@ Column {
3239
spacing: Theme.spacingXS
3340

3441
Row {
42+
id: tabRow
3543
width: parent.width
3644
height: 36
3745
spacing: Theme.spacingXS
3846

47+
readonly property real dynamicTabWidth: {
48+
var count = Math.max(1, NotepadStorageService.tabs.length);
49+
var raw = (tabScroll.width - (count - 1) * Theme.spacingXS) / count;
50+
return Math.max(128, Math.min(300, raw));
51+
}
52+
3953
ScrollView {
54+
id: tabScroll
4055
width: parent.width - newTabButton.width - Theme.spacingXS
4156
height: parent.height
4257
clip: true
@@ -57,7 +72,8 @@ Column {
5772

5873
readonly property bool isActive: NotepadStorageService.currentTabIndex === index
5974
readonly property bool isHovered: tabMouseArea.containsMouse && !closeMouseArea.containsMouse
60-
readonly property real tabWidth: 128
75+
readonly property bool editing: root.editingIndex === index
76+
readonly property real tabWidth: tabRow.dynamicTabWidth
6177
property bool longPressing: false
6278
property bool dragging: false
6379
property point dragStartPos: Qt.point(0, 0)
@@ -138,6 +154,7 @@ Column {
138154

139155
StyledText {
140156
id: tabText
157+
visible: !delegateItem.editing
141158
width: parent.width - (tabCloseButton.visible ? tabCloseButton.width + Theme.spacingXS : 0)
142159
text: {
143160
var prefix = "";
@@ -155,13 +172,54 @@ Column {
155172
anchors.verticalCenter: parent.verticalCenter
156173
}
157174

175+
TextInput {
176+
id: renameField
177+
visible: delegateItem.editing
178+
enabled: delegateItem.editing
179+
width: parent.width
180+
anchors.verticalCenter: parent.verticalCenter
181+
font.pixelSize: Theme.fontSizeSmall
182+
font.weight: Font.Medium
183+
color: Theme.primary
184+
selectionColor: Theme.primary
185+
selectedTextColor: Theme.background
186+
selectByMouse: true
187+
clip: true
188+
189+
onEditingFinished: root.commitRename(index, text)
190+
Keys.onEscapePressed: event => {
191+
text = modelData.title || "Untitled";
192+
root.editingIndex = -1;
193+
event.accepted = true;
194+
}
195+
196+
// A tab switch re-focuses the editor via Qt.callLater; the
197+
// timer fires afterwards so the field keeps focus + selection.
198+
Timer {
199+
id: renameFocusTimer
200+
interval: 20
201+
repeat: false
202+
onTriggered: {
203+
renameField.forceActiveFocus();
204+
renameField.selectAll();
205+
}
206+
}
207+
208+
onVisibleChanged: {
209+
if (!visible)
210+
return;
211+
text = modelData.title || "Untitled";
212+
renameFocusTimer.restart();
213+
}
214+
}
215+
158216
Rectangle {
159217
id: tabCloseButton
160218
width: 20
161219
height: 20
162220
radius: Theme.cornerRadius
163221
color: closeMouseArea.containsMouse ? Theme.surfaceTextHover : Theme.withAlpha(Theme.surfaceTextHover, 0)
164-
visible: NotepadStorageService.tabs.length > 1
222+
visible: NotepadStorageService.tabs.length > 1 && !delegateItem.editing
165223
anchors.verticalCenter: parent.verticalCenter
166224

167225
DankIcon {
@@ -195,11 +253,24 @@ Column {
195253
MouseArea {
196254
id: tabMouseArea
197255
anchors.fill: parent
256+
enabled: !delegateItem.editing
198257
hoverEnabled: true
199258
preventStealing: dragging || longPressing
200259
cursorShape: dragging || longPressing ? Qt.ClosedHandCursor : Qt.PointingHandCursor
201260
acceptedButtons: Qt.LeftButton
202261

262+
onDoubleClicked: {
263+
root.tabSwitched(index);
264+
root.editingIndex = index;
265+
}
266+
267+
onExited: tabTooltip.hide()
268+
269+
onContainsMouseChanged: {
270+
if (containsMouse && tabText.truncated)
271+
tabTooltip.show(modelData.title || "Untitled", delegateItem, 0, 0, "bottom");
272+
}
273+
203274
onPressed: mouse => {
204275
if (mouse.button === Qt.LeftButton && NotepadStorageService.tabs.length > 1) {
205276
delegateItem.dragStartPos = Qt.point(mouse.x, mouse.y);
@@ -279,4 +350,8 @@ Column {
279350
onClicked: root.newTabRequested()
280351
}
281352
}
353+
354+
DankTooltipV2 {
355+
id: tabTooltip
356+
}
282357
}

0 commit comments

Comments
 (0)