Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Read Only #292

Merged
merged 2 commits into from Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 12 additions & 21 deletions nw/core/document.py
Expand Up @@ -39,14 +39,13 @@ class NWDoc():

def __init__(self, theProject, theParent):

self.mainConf = nw.CONFIG
self.theProject = theProject
self.theParent = theParent
self.theItem = None
self.docHandle = None
self.docEditable = False
self.fileLoc = None
self.docMeta = ""
self.mainConf = nw.CONFIG
self.theProject = theProject
self.theParent = theParent
self.theItem = None
self.docHandle = None
self.fileLoc = None
self.docMeta = ""

# Internal Mapping
self.makeAlert = self.theParent.makeAlert
Expand All @@ -60,11 +59,10 @@ def __init__(self, theProject, theParent):
def clearDocument(self):
"""Clear the document contents.
"""
self.theItem = None
self.docHandle = None
self.docEditable = False
self.fileLoc = None
self.docMeta = ""
self.theItem = None
self.docHandle = None
self.fileLoc = None
self.docMeta = ""
return

def openDocument(self, tHandle, showStatus=True, isOrphan=False):
Expand All @@ -87,13 +85,6 @@ def openDocument(self, tHandle, showStatus=True, isOrphan=False):
self.clearDocument()
return None

# By default, the document is editable.
# Except for files in the trash folder.
self.docEditable = True
if self.theItem is not None:
if self.theItem.parHandle == self.theProject.projTree.trashRoot():
self.docEditable = False

docFile = self.docHandle+".nwd"
logger.debug("Opening document %s" % docFile)

Expand Down Expand Up @@ -137,7 +128,7 @@ def saveDocument(self, docText):
"""Save the document via temp file in case of save failure, and
in any case keep a backup of the file.
"""
if self.docHandle is None or not self.docEditable:
if self.docHandle is None:
return False

self.theProject.ensureFolderStructure()
Expand Down
3 changes: 1 addition & 2 deletions nw/gui/__init__.py
Expand Up @@ -2,7 +2,7 @@

from nw.gui.about import GuiAbout
from nw.gui.build import GuiBuildNovel
from nw.gui.docbars import GuiDocTitleBar, GuiNoticeBar, GuiSearchBar
from nw.gui.docbars import GuiDocTitleBar, GuiSearchBar
from nw.gui.docdetails import GuiDocViewDetails
from nw.gui.doceditor import GuiDocEditor
from nw.gui.docmerge import GuiDocMerge
Expand All @@ -25,7 +25,6 @@
"GuiAbout",
"GuiBuildNovel",
"GuiDocTitleBar",
"GuiNoticeBar",
"GuiSearchBar",
"GuiDocViewDetails",
"GuiDocEditor",
Expand Down
54 changes: 0 additions & 54 deletions nw/gui/docbars.py
Expand Up @@ -7,7 +7,6 @@

File History:
Created: 2019-09-29 [0.2.1] GuiSearchBar
Created: 2019-10-31 [0.3.2] GuiNoticeBar
Created: 2020-04-25 [0.4.5] GuiDocTitleBar

This file is a part of novelWriter
Expand Down Expand Up @@ -169,59 +168,6 @@ def _replaceVisible(self, isVisible):

# END Class GuiSearchBar

class GuiNoticeBar(QFrame):

def __init__(self, theParent):
QFrame.__init__(self, theParent)

logger.debug("Initialising GuiNoticeBar ...")

self.mainConf = nw.CONFIG
self.theParent = theParent
self.theTheme = theParent.theTheme

self.setContentsMargins(0, 0, 0, 0)
self.setFrameShape(QFrame.Box)

m8 = self.mainConf.pxInt(8)
m2 = self.mainConf.pxInt(2)

self.mainBox = QHBoxLayout(self)
self.mainBox.setContentsMargins(m8, m2, m2, m2)

self.noteLabel = QLabel("")

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("GuiNoticeBar initialisation complete")

return

def showNote(self, theNote):
"""Show the note on the noticebar.
"""
self.noteLabel.setText("<b>Note:</b> %s" % theNote)
self.setVisible(True)
return

def hideNote(self):
"""Clear the noticebar and hide it.
"""
self.noteLabel.setText("")
self.setVisible(False)
return

# END Class GuiNoticeBar

class GuiDocTitleBar(QLabel):

def __init__(self, theParent, theProject):
Expand Down
7 changes: 1 addition & 6 deletions nw/gui/doceditor.py
Expand Up @@ -158,7 +158,6 @@ def clearEditor(self):
self.hasSelection = False

self.setDocumentChanged(False)
self.theParent.noticeBar.hideNote()
self.docTitle.setTitleFromHandle(self.theHandle)

return True
Expand Down Expand Up @@ -270,11 +269,7 @@ def loadText(self, tHandle, tLine=None, showStatus=True):
self.setDocumentChanged(False)
self.theHandle = tHandle

if self.nwDocument.docEditable:
self.setReadOnly(False)
else:
self.theParent.noticeBar.showNote("This document is read only.")

self.setReadOnly(False)
self.docTitle.setTitleFromHandle(self.theHandle)
self.updateDocMargins()
self.hLight.spellCheck = spTemp
Expand Down
4 changes: 1 addition & 3 deletions nw/guimain.py
Expand Up @@ -42,7 +42,7 @@
from nw.gui import (
GuiBuildNovel, GuiDocEditor, GuiDocMerge, GuiDocSplit, GuiDocViewDetails,
GuiDocViewer, GuiItemDetails, GuiItemEditor, GuiMainMenu, GuiMainStatus,
GuiNoticeBar, GuiOutline, GuiOutlineDetails, GuiPreferences, GuiProjectLoad,
GuiOutline, GuiOutlineDetails, GuiPreferences, GuiProjectLoad,
GuiProjectSettings, GuiProjectTree, GuiSearchBar, GuiSessionLogView, GuiTheme
)
from nw.core import NWProject, NWDoc, NWIndex
Expand Down Expand Up @@ -90,7 +90,6 @@ def __init__(self):

# Main GUI Elements
self.statusBar = GuiMainStatus(self)
self.noticeBar = GuiNoticeBar(self)
self.treeView = GuiProjectTree(self)
self.docEditor = GuiDocEditor(self)
self.docViewer = GuiDocViewer(self)
Expand Down Expand Up @@ -118,7 +117,6 @@ def __init__(self):
self.docEdit.setContentsMargins(0, 0, 0, 0)
self.docEdit.setSpacing(self.mainConf.pxInt(2))
self.docEdit.addWidget(self.searchBar)
self.docEdit.addWidget(self.noticeBar)
self.docEdit.addWidget(self.docEditor)
self.editPane.setLayout(self.docEdit)

Expand Down