diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index fc17001c..6b78eee6 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -116,6 +116,7 @@ class GuiDocEditor(QTextEdit): self.hasSelection = False self.setDocumentChanged(False) + self.theParent.noticeBar.hideNote() return True @@ -201,6 +202,8 @@ class GuiDocEditor(QTextEdit): if self.nwDocument.docEditable: self.setReadOnly(False) + else: + self.theParent.noticeBar.showNote("This document is read only.") return True @@ -244,9 +247,10 @@ class GuiDocEditor(QTextEdit): return theText def setCursorPosition(self, thePosition): - theCursor = self.textCursor() - theCursor.setPosition(thePosition) - self.setTextCursor(theCursor) + if thePosition > 0: + theCursor = self.textCursor() + theCursor.setPosition(thePosition) + self.setTextCursor(theCursor) return True def getCursorPosition(self): diff --git a/nw/gui/elements/noticebar.py b/nw/gui/elements/noticebar.py new file mode 100644 index 00000000..17bd512e --- /dev/null +++ b/nw/gui/elements/noticebar.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +"""novelWriter GUI Main Window Notice Bar + + novelWriter – GUI Main Window Notice Bar +========================================== + Class holding the main window notice bar for the doc editor + + File History: + Created: 2019-10-31 [0.3.2] + +""" + +import logging +import nw + +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QPalette, QColor +from PyQt5.QtWidgets import QFrame, QHBoxLayout, QLabel, QPushButton + +logger = logging.getLogger(__name__) + +class GuiNoticeBar(QFrame): + + def __init__(self, theParent): + QFrame.__init__(self, theParent) + + logger.debug("Initialising NoticeBar ...") + + self.mainConf = nw.CONFIG + self.theParent = theParent + self.theTheme = theParent.theTheme + + self.setContentsMargins(0,0,0,0) + self.setFrameShape(QFrame.Box) + + self.mainBox = QHBoxLayout(self) + self.mainBox.setContentsMargins(8,2,2,2) + + self.noteLabel = QLabel("Hi there!") + self.closeButton = QPushButton(self.theTheme.getIcon("close"),"") + self.closeButton.clicked.connect(self.hideNote) + + self.mainBox.addWidget(self.noteLabel) + self.mainBox.addWidget(self.closeButton) + self.mainBox.setStretch(0, 1) + + self.setLayout(self.mainBox) + + self.hideNote() + + logger.debug("NoticeBar initialisation complete") + + return + + def showNote(self, theNote): + self.noteLabel.setText("Note: %s" % theNote) + self.setVisible(True) + return + + def hideNote(self): + self.noteLabel.setText("") + self.setVisible(False) + return + +# END Class GuiNoticeBar diff --git a/nw/gui/elements/searchbar.py b/nw/gui/elements/searchbar.py index 53a5883b..e5da35ee 100644 --- a/nw/gui/elements/searchbar.py +++ b/nw/gui/elements/searchbar.py @@ -26,7 +26,7 @@ class GuiSearchBar(QFrame): def __init__(self, theParent): QFrame.__init__(self, theParent) - logger.debug("Initialising GuiSearchBar ...") + logger.debug("Initialising SearchBar ...") self.mainConf = nw.CONFIG self.theParent = theParent @@ -73,7 +73,7 @@ class GuiSearchBar(QFrame): self._replaceVisible(False) - logger.debug("GuiSearchBar initialisation complete") + logger.debug("SearchBar initialisation complete") return diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index 1349e467..a45c9067 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -30,6 +30,7 @@ from nw.gui.elements.doceditor import GuiDocEditor from nw.gui.elements.docviewer import GuiDocViewer from nw.gui.elements.docdetails import GuiDocDetails from nw.gui.elements.searchbar import GuiSearchBar +from nw.gui.elements.noticebar import GuiNoticeBar from nw.gui.dialogs.configeditor import GuiConfigEditor from nw.gui.dialogs.projecteditor import GuiProjectEditor from nw.gui.dialogs.export import GuiExport @@ -72,6 +73,7 @@ class GuiMain(QMainWindow): # Main GUI Elements self.statusBar = GuiMainStatus(self) + self.noticeBar = GuiNoticeBar(self) self.docEditor = GuiDocEditor(self, self.theProject) self.docViewer = GuiDocViewer(self, self.theProject) self.docDetails = GuiDocDetails(self, self.theProject) @@ -86,6 +88,7 @@ class GuiMain(QMainWindow): # Assemble Main Window self.treePane = QFrame() self.treeBox = QVBoxLayout() + self.treeBox.setContentsMargins(0,0,0,0) self.treeBox.addWidget(self.treeView) self.treeBox.addWidget(self.docDetails) self.treePane.setLayout(self.treeBox) @@ -94,6 +97,7 @@ class GuiMain(QMainWindow): self.docView = QVBoxLayout() self.docView.setContentsMargins(0,0,0,0) self.docView.addWidget(self.searchBar) + self.docView.addWidget(self.noticeBar) self.docView.addWidget(self.docEditor) self.docPane.setLayout(self.docView) @@ -103,6 +107,7 @@ class GuiMain(QMainWindow): self.splitView.splitterMoved.connect(self._splitViewMove) self.splitMain = QSplitter(Qt.Horizontal) + self.splitMain.setContentsMargins(4,4,4,4) self.splitMain.addWidget(self.treePane) self.splitMain.addWidget(self.splitView) self.splitMain.setSizes(self.mainConf.mainPanePos) diff --git a/nw/project/document.py b/nw/project/document.py index 24e203ea..0a3fa126 100644 --- a/nw/project/document.py +++ b/nw/project/document.py @@ -86,7 +86,7 @@ class NWDoc(): def saveDocument(self, docText): - if self.docHandle is None: + if self.docHandle is None or not self.docEditable: return False docDir, docFile = self._assemblePath(self.FILE_MN)