Skip to content

Commit 444c168

Browse files
authored
Update closing project procedure, and editor scrolling (#1247)
2 parents 9f4b9a4 + 61ab597 commit 444c168

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

novelwriter/enum.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,6 @@ class nwAlert(Enum):
130130
# END Enum nwAlert
131131

132132

133-
class nwState(Enum):
134-
135-
NONE = 0
136-
BAD = 1
137-
GOOD = 2
138-
139-
# END Enum nwState
140-
141-
142133
class nwView(Enum):
143134

144135
EDITOR = 0

novelwriter/gui/doceditor.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,17 @@ def setCursorPosition(self, position):
666666
theCursor.setPosition(minmax(position, 0, nChars-1))
667667
self.setTextCursor(theCursor)
668668

669-
# The editor scrolls so the cursor is on the last line, so we must correct
670-
vPos = self.verticalScrollBar().value() # Current scrollbar position
671-
cPos = self.cursorRect().topLeft().y() # Cursor position to scroll to
672-
dMrg = int(self.document().documentMargin()) # Document margin to subtract
673-
mPos = int(self.viewport().height()*0.1) # Distance from top to adjust for (10%)
674-
self.verticalScrollBar().setValue(max(0, vPos + cPos - dMrg - mPos))
669+
# By default, the editor scrolls so the cursor is on the
670+
# last line, so we must correct it. The user setting for
671+
# auto-scroll is used to determine the scroll distance. This
672+
# makes it compatible with the typewriter scrolling feature
673+
# when it is enabled. By default, it's 30% of viewport.
674+
vPos = self.verticalScrollBar().value()
675+
cPos = self.cursorRect().topLeft().y()
676+
mPos = int(self.mainConf.autoScrollPos*0.01 * self.viewport().height())
677+
if cPos > mPos:
678+
# Only scroll if the cursor is past the auto-scroll limit
679+
self.verticalScrollBar().setValue(max(0, vPos + cPos - mPos))
675680

676681
self.docFooter.updateLineCount()
677682

novelwriter/gui/statusbar.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton
3535

3636
from novelwriter.common import formatTime
37-
from novelwriter.enum import nwState
3837

3938
logger = logging.getLogger(__name__)
4039

@@ -53,8 +52,8 @@ def __init__(self, mainGui):
5352
self.userIdle = False
5453

5554
colNone = QColor(*self.mainTheme.statNone)
56-
colTrue = QColor(*self.mainTheme.statUnsaved)
57-
colFalse = QColor(*self.mainTheme.statSaved)
55+
colSaved = QColor(*self.mainTheme.statSaved)
56+
colUnsaved = QColor(*self.mainTheme.statUnsaved)
5857

5958
iPx = self.mainTheme.baseIconSize
6059

@@ -72,15 +71,15 @@ def __init__(self, mainGui):
7271
self.addPermanentWidget(self.langText)
7372

7473
# The Editor Status
75-
self.docIcon = StatusLED(colNone, colTrue, colFalse, iPx, iPx, self)
74+
self.docIcon = StatusLED(colNone, colSaved, colUnsaved, iPx, iPx, self)
7675
self.docText = QLabel(self.tr("Editor"))
7776
self.docIcon.setContentsMargins(0, 0, 0, 0)
7877
self.docText.setContentsMargins(0, 0, xM, 0)
7978
self.addPermanentWidget(self.docIcon)
8079
self.addPermanentWidget(self.docText)
8180

8281
# The Project Status
83-
self.projIcon = StatusLED(colNone, colTrue, colFalse, iPx, iPx, self)
82+
self.projIcon = StatusLED(colNone, colSaved, colUnsaved, iPx, iPx, self)
8483
self.projText = QLabel(self.tr("Project"))
8584
self.projIcon.setContentsMargins(0, 0, 0, 0)
8685
self.projText.setContentsMargins(0, 0, xM, 0)
@@ -122,8 +121,8 @@ def clearStatus(self):
122121
self.setRefTime(None)
123122
self.setLanguage(None, "")
124123
self.setProjectStats(0, 0)
125-
self.setProjectStatus(nwState.NONE)
126-
self.setDocumentStatus(nwState.NONE)
124+
self.setProjectStatus(StatusLED.S_NONE)
125+
self.setDocumentStatus(StatusLED.S_NONE)
127126
self.updateTime()
128127
return True
129128

@@ -236,21 +235,25 @@ def setLanguage(self, theLanguage, theProvider):
236235
def doUpdateProjectStatus(self, isChanged):
237236
"""Slot for updating the project status.
238237
"""
239-
self.setProjectStatus(nwState.GOOD if isChanged else nwState.BAD)
238+
self.setProjectStatus(StatusLED.S_BAD if isChanged else StatusLED.S_GOOD)
240239
return
241240

242241
@pyqtSlot(bool)
243242
def doUpdateDocumentStatus(self, isChanged):
244243
"""Slot for updating the document status.
245244
"""
246-
self.setDocumentStatus(nwState.GOOD if isChanged else nwState.BAD)
245+
self.setDocumentStatus(StatusLED.S_BAD if isChanged else StatusLED.S_GOOD)
247246
return
248247

249248
# END Class GuiMainStatus
250249

251250

252251
class StatusLED(QAbstractButton):
253252

253+
S_NONE = 0
254+
S_BAD = 1
255+
S_GOOD = 2
256+
254257
def __init__(self, colNone, colGood, colBad, sW, sH, parent=None):
255258
super().__init__(parent=parent)
256259

@@ -271,9 +274,9 @@ def __init__(self, colNone, colGood, colBad, sW, sH, parent=None):
271274
def setState(self, theState):
272275
"""Set the colour state.
273276
"""
274-
if theState == nwState.GOOD:
277+
if theState == self.S_GOOD:
275278
self._theCol = self._colGood
276-
elif theState == nwState.BAD:
279+
elif theState == self.S_BAD:
277280
self._theCol = self._colBad
278281
else:
279282
self._theCol = self._colNone

novelwriter/guimain.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def clearGUI(self):
312312
# Work Area
313313
self.docEditor.clearEditor()
314314
self.docEditor.setDictionaries()
315-
self.closeDocViewer()
315+
self.closeDocViewer(byUser=False)
316316
self.outlineView.clearProject()
317317

318318
# General
@@ -1220,14 +1220,19 @@ def closeDocEditor(self):
12201220
self.theProject.data.setLastHandle(None, "editor")
12211221
return
12221222

1223-
def closeDocViewer(self):
1223+
def closeDocViewer(self, byUser=True):
12241224
"""Close the document view panel.
12251225
"""
12261226
self.docViewer.clearViewer()
1227-
self.theProject.data.setLastHandle(None, "viewer")
1227+
if byUser:
1228+
# Only reset the last handle if the user called this
1229+
self.theProject.data.setLastHandle(None, "viewer")
1230+
1231+
# Hide the panel
12281232
bPos = self.splitMain.sizes()
12291233
self.splitView.setVisible(False)
12301234
self.splitDocs.setSizes([bPos[1], 0])
1235+
12311236
return not self.splitView.isVisible()
12321237

12331238
def toggleFocusMode(self):

tests/test_gui/test_gui_statusbar.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from tools import C, buildTestProject
2626

27-
from novelwriter.enum import nwState
27+
from novelwriter.gui.statusbar import StatusLED
2828

2929

3030
@pytest.mark.gui
@@ -44,19 +44,19 @@ def testGuiStatusBar_Main(qtbot, nwGUI, projPath, mockRnd):
4444
assert nwGUI.mainStatus.refTime == refTime
4545

4646
# Project Status
47-
nwGUI.mainStatus.setProjectStatus(nwState.NONE)
47+
nwGUI.mainStatus.setProjectStatus(StatusLED.S_NONE)
4848
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colNone
49-
nwGUI.mainStatus.setProjectStatus(nwState.BAD)
49+
nwGUI.mainStatus.setProjectStatus(StatusLED.S_BAD)
5050
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colBad
51-
nwGUI.mainStatus.setProjectStatus(nwState.GOOD)
51+
nwGUI.mainStatus.setProjectStatus(StatusLED.S_GOOD)
5252
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colGood
5353

5454
# Document Status
55-
nwGUI.mainStatus.setDocumentStatus(nwState.NONE)
55+
nwGUI.mainStatus.setDocumentStatus(StatusLED.S_NONE)
5656
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colNone
57-
nwGUI.mainStatus.setDocumentStatus(nwState.BAD)
57+
nwGUI.mainStatus.setDocumentStatus(StatusLED.S_BAD)
5858
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colBad
59-
nwGUI.mainStatus.setDocumentStatus(nwState.GOOD)
59+
nwGUI.mainStatus.setDocumentStatus(StatusLED.S_GOOD)
6060
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colGood
6161

6262
# Idle Status

0 commit comments

Comments
 (0)