Skip to content

Commit 19feb24

Browse files
committed
window: Save splitter state to the cache
1 parent ad874c6 commit 19feb24

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

ReText/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def getBundledIcon(iconName):
9393
'lastFileList': [],
9494
'lastTabIndex': 0,
9595
'recentFileList': [],
96+
'splitterState': QByteArray(),
9697
'windowGeometry': QByteArray(),
9798
}
9899

ReText/window.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
except ImportError:
4141
enchant = None
4242

43-
from PyQt6.QtCore import QDir, QFile, QFileInfo, QFileSystemWatcher, \
44-
QIODevice, QLocale, QMarginsF, QStandardPaths, QTextStream, QTimer, \
45-
QUrl, Qt, pyqtSlot
43+
from PyQt6.QtCore import QByteArray, QDir, QFile, QFileInfo, \
44+
QFileSystemWatcher, QIODevice, QLocale, QMarginsF, QStandardPaths, \
45+
QTextStream, QTimer, QUrl, Qt, pyqtSlot
4646
from PyQt6.QtGui import QAction, QActionGroup, QColor, QDesktopServices, \
4747
QIcon, QKeySequence, QPageLayout, QPageSize, \
4848
QPalette, QTextDocument, QTextDocumentWriter
@@ -92,7 +92,10 @@ def __init__(self, parent=None):
9292
self.treeView.setVisible(globalSettings.showDirectoryTree)
9393
self.tabWidget = QTabWidget(self.splitter)
9494
self.initTabWidget()
95-
self.splitter.setSizes([self.width() // 5, self.width() * 4 // 5])
95+
if globalCache.splitterState:
96+
self.splitter.restoreState(globalCache.splitterState)
97+
else:
98+
self.splitter.setSizes([self.width() // 5, self.width() * 4 // 5])
9699
self.setCentralWidget(self.splitter)
97100
self.tabWidget.currentChanged.connect(self.changeIndex)
98101
self.tabWidget.tabCloseRequested.connect(self.closeTab)
@@ -1238,6 +1241,13 @@ def closeEvent(self, closeevent):
12381241
return closeevent.ignore()
12391242
if globalSettings.saveWindowGeometry:
12401243
globalCache.windowGeometry = self.saveGeometry()
1244+
if self.treeView.isVisible():
1245+
globalCache.splitterState = self.splitter.saveState()
1246+
else:
1247+
globalCache.splitterState = QByteArray()
1248+
else:
1249+
globalCache.windowGeometry = QByteArray()
1250+
globalCache.splitterState = QByteArray()
12411251
if globalSettings.openLastFilesOnStartup:
12421252
files = [tab.fileName for tab in self.iterateTabs()]
12431253
globalCache.lastFileList = files

configuration.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ option name | type | description
5555
If the type is 'file path', then the value should be an absolute path
5656
to a file.
5757

58-
These options can be set internally by ReText and should never be set
59-
manually: `recentFileList`, `lastFileList`, `lastTabIndex` and `windowGeometry`.
58+
There is also a separate file called `cache.conf` which contains options
59+
that are set internally by ReText and should never be set manually:
60+
61+
- `lastFileList`
62+
- `lastTabIndex`
63+
- `recentFileList`
64+
- `splitterState`
65+
- `windowGeometry`
6066

6167
Icon themes
6268
===========

0 commit comments

Comments
 (0)