mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-21 05:12:27 +12:00
Needs to do the Markdown syntax highlighter now...
This commit is contained in:
parent
6e43756669
commit
a27e5db6f5
|
@ -23,6 +23,10 @@ def saveProject(version=None):
|
||||||
# FIXME: add settings to chose between saving as zip or not.
|
# FIXME: add settings to chose between saving as zip or not.
|
||||||
|
|
||||||
|
|
||||||
|
def clearSaveCache():
|
||||||
|
v1.cache = {}
|
||||||
|
|
||||||
|
|
||||||
def loadProject(project):
|
def loadProject(project):
|
||||||
|
|
||||||
# Detect version
|
# Detect version
|
||||||
|
|
|
@ -530,7 +530,7 @@ def exportOutlineItem(root):
|
||||||
content = outlineToMMD(child)
|
content = outlineToMMD(child)
|
||||||
files.append((fpath, content))
|
files.append((fpath, content))
|
||||||
|
|
||||||
elif child.type() in ["txt", "t2t"]:
|
elif child.type() in ["txt", "t2t", "md"]:
|
||||||
content = outlineToMMD(child)
|
content = outlineToMMD(child)
|
||||||
files.append((spath, content))
|
files.append((spath, content))
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from PyQt5.QtWidgets import QMainWindow, QHeaderView, qApp, QMenu, QActionGroup,
|
||||||
from manuskript import settings
|
from manuskript import settings
|
||||||
from manuskript.enums import Character, PlotStep, Plot, World
|
from manuskript.enums import Character, PlotStep, Plot, World
|
||||||
from manuskript.functions import AUC, wordCount, appPath
|
from manuskript.functions import AUC, wordCount, appPath
|
||||||
from manuskript.loadSave import saveProject, loadProject
|
from manuskript import loadSave
|
||||||
from manuskript.models.characterModel import characterModel
|
from manuskript.models.characterModel import characterModel
|
||||||
from manuskript.models.outlineModel import outlineModel
|
from manuskript.models.outlineModel import outlineModel
|
||||||
from manuskript.models.plotModel import plotModel
|
from manuskript.models.plotModel import plotModel
|
||||||
|
@ -375,8 +375,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
|
|
||||||
# Clear datas
|
# Clear datas
|
||||||
self.loadEmptyDatas()
|
self.loadEmptyDatas()
|
||||||
|
|
||||||
self.saveTimer.stop()
|
self.saveTimer.stop()
|
||||||
|
loadSave.clearSaveCache()
|
||||||
|
|
||||||
# UI
|
# UI
|
||||||
for i in [self.actSave, self.actSaveAs, self.actCloseProject,
|
for i in [self.actSave, self.actSaveAs, self.actCloseProject,
|
||||||
|
@ -460,7 +460,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
self.currentProject = projectName
|
self.currentProject = projectName
|
||||||
QSettings().setValue("lastProject", projectName)
|
QSettings().setValue("lastProject", projectName)
|
||||||
|
|
||||||
saveProject() # version=0
|
loadSave.saveProject() # version=0
|
||||||
self.saveTimerNoChanges.stop()
|
self.saveTimerNoChanges.stop()
|
||||||
|
|
||||||
# Giving some feedback
|
# Giving some feedback
|
||||||
|
@ -481,7 +481,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
|
|
||||||
def loadDatas(self, project):
|
def loadDatas(self, project):
|
||||||
|
|
||||||
errors = loadProject(project)
|
errors = loadSave.loadProject(project)
|
||||||
|
|
||||||
# Giving some feedback
|
# Giving some feedback
|
||||||
if not errors:
|
if not errors:
|
||||||
|
|
|
@ -481,9 +481,9 @@ class outlineItem():
|
||||||
elif role == Qt.DecorationRole and column == Outline.title.value:
|
elif role == Qt.DecorationRole and column == Outline.title.value:
|
||||||
if self.isFolder():
|
if self.isFolder():
|
||||||
return QIcon.fromTheme("folder")
|
return QIcon.fromTheme("folder")
|
||||||
elif self.isText():
|
elif self.isText:
|
||||||
return QIcon.fromTheme("text-x-generic")
|
return QIcon.fromTheme("text-x-generic")
|
||||||
elif self.isT2T():
|
elif self.isT2T() or self.isMD():
|
||||||
return QIcon.fromTheme("text-x-script")
|
return QIcon.fromTheme("text-x-script")
|
||||||
elif self.isHTML():
|
elif self.isHTML():
|
||||||
return QIcon.fromTheme("text-html")
|
return QIcon.fromTheme("text-html")
|
||||||
|
@ -529,12 +529,12 @@ class outlineItem():
|
||||||
# Stuff to do before
|
# Stuff to do before
|
||||||
if column == Outline.type.value:
|
if column == Outline.type.value:
|
||||||
oldType = self._data[Outline.type]
|
oldType = self._data[Outline.type]
|
||||||
if oldType == "html" and data in ["txt", "t2t"]:
|
if oldType == "html" and data in ["txt", "t2t", "md"]:
|
||||||
# Resource inneficient way to convert HTML to plain text
|
# Resource inneficient way to convert HTML to plain text
|
||||||
e = QTextEdit()
|
e = QTextEdit()
|
||||||
e.setHtml(self._data[Outline.text])
|
e.setHtml(self._data[Outline.text])
|
||||||
self._data[Outline.text] = e.toPlainText()
|
self._data[Outline.text] = e.toPlainText()
|
||||||
elif oldType in ["txt", "t2t"] and data == "html" and Outline.text in self._data:
|
elif oldType in ["txt", "t2t", "md"] and data == "html" and Outline.text in self._data:
|
||||||
self._data[Outline.text] = self._data[Outline.text].replace("\n", "<br>")
|
self._data[Outline.text] = self._data[Outline.text].replace("\n", "<br>")
|
||||||
|
|
||||||
elif column == Outline.text.value:
|
elif column == Outline.text.value:
|
||||||
|
@ -663,6 +663,12 @@ class outlineItem():
|
||||||
def isT2T(self):
|
def isT2T(self):
|
||||||
return self._data[Outline.type] == "t2t"
|
return self._data[Outline.type] == "t2t"
|
||||||
|
|
||||||
|
def isMD(self):
|
||||||
|
return self._data[Outline.type] == "md"
|
||||||
|
|
||||||
|
def isMMD(self):
|
||||||
|
return self._data[Outline.type] == "md"
|
||||||
|
|
||||||
def isHTML(self):
|
def isHTML(self):
|
||||||
return self._data[Outline.type] == "html"
|
return self._data[Outline.type] == "html"
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ corkBackground = {
|
||||||
"color": "#926239",
|
"color": "#926239",
|
||||||
"image": ""
|
"image": ""
|
||||||
}
|
}
|
||||||
defaultTextType = "t2t"
|
defaultTextType = "md"
|
||||||
fullScreenTheme = "spacedreams"
|
fullScreenTheme = "spacedreams"
|
||||||
|
|
||||||
textEditor = {
|
textEditor = {
|
||||||
|
|
|
@ -18,6 +18,7 @@ from manuskript.ui.editors.themes import getThemeName
|
||||||
from manuskript.ui.editors.themes import loadThemeDatas
|
from manuskript.ui.editors.themes import loadThemeDatas
|
||||||
from manuskript.ui.settings_ui import Ui_Settings
|
from manuskript.ui.settings_ui import Ui_Settings
|
||||||
from manuskript.ui.views.textEditView import textEditView
|
from manuskript.ui.views.textEditView import textEditView
|
||||||
|
from manuskript.ui.welcome import welcome
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import enchant
|
import enchant
|
||||||
|
@ -59,11 +60,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
||||||
self.chkAutoLoad.setChecked(autoLoad)
|
self.chkAutoLoad.setChecked(autoLoad)
|
||||||
self.chkAutoLoad.stateChanged.connect(self.saveSettingsChanged)
|
self.chkAutoLoad.stateChanged.connect(self.saveSettingsChanged)
|
||||||
|
|
||||||
dtt = [
|
dtt = welcome.defaultTextType()
|
||||||
("t2t", self.tr("Txt2Tags"), "text-x-script"),
|
|
||||||
("html", self.tr("Rich Text (html)"), "text-html"),
|
|
||||||
("txt", self.tr("Plain Text"), "text-x-generic"),
|
|
||||||
]
|
|
||||||
self.cmbDefaultTextType.clear()
|
self.cmbDefaultTextType.clear()
|
||||||
for t in dtt:
|
for t in dtt:
|
||||||
self.cmbDefaultTextType.addItem(QIcon.fromTheme(t[2]), t[1], t[0])
|
self.cmbDefaultTextType.addItem(QIcon.fromTheme(t[2]), t[1], t[0])
|
||||||
|
|
16
manuskript/ui/editors/MMDHighlighter.py
Normal file
16
manuskript/ui/editors/MMDHighlighter.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf8 -*-
|
||||||
|
from manuskript.ui.editors.basicHighlighter import basicHighlighter
|
||||||
|
|
||||||
|
|
||||||
|
class MMDHighlighter(basicHighlighter):
|
||||||
|
|
||||||
|
def __init__(self, editor, style="Default"):
|
||||||
|
basicHighlighter.__init__(self, editor)
|
||||||
|
|
||||||
|
def highlightBlock(self, text):
|
||||||
|
basicHighlighter.highlightBlockBefore(self, text)
|
||||||
|
|
||||||
|
# FIXME
|
||||||
|
|
||||||
|
basicHighlighter.highlightBlockAfter(self, text)
|
|
@ -62,7 +62,8 @@ class textFormat(QWidget, Ui_textFormat):
|
||||||
elif item.isText():
|
elif item.isText():
|
||||||
self.align.setVisible(False)
|
self.align.setVisible(False)
|
||||||
self.format.setVisible(False)
|
self.format.setVisible(False)
|
||||||
elif item.isT2T():
|
|
||||||
|
elif item.isT2T() or item.isMD():
|
||||||
self.align.setVisible(False)
|
self.align.setVisible(False)
|
||||||
|
|
||||||
def setFormat(self):
|
def setFormat(self):
|
||||||
|
|
|
@ -5,6 +5,7 @@ from PyQt5.QtGui import QIcon, QBrush
|
||||||
from PyQt5.QtWidgets import QComboBox
|
from PyQt5.QtWidgets import QComboBox
|
||||||
|
|
||||||
from manuskript.enums import Outline
|
from manuskript.enums import Outline
|
||||||
|
from manuskript.ui.welcome import welcome
|
||||||
|
|
||||||
|
|
||||||
class cmbOutlineTypeChoser(QComboBox):
|
class cmbOutlineTypeChoser(QComboBox):
|
||||||
|
@ -24,11 +25,8 @@ class cmbOutlineTypeChoser(QComboBox):
|
||||||
|
|
||||||
def updateItems(self):
|
def updateItems(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
types = [
|
types = welcome.defaultTextType()
|
||||||
("t2t", self.tr("Txt2Tags"), "text-x-generic"),
|
|
||||||
("html", self.tr("Rich Text (html)"), "text-html"),
|
|
||||||
("txt", self.tr("Plain Text"), "text-x-generic"),
|
|
||||||
]
|
|
||||||
for t in types:
|
for t in types:
|
||||||
self.addItem(QIcon.fromTheme(t[2]), t[1], t[0])
|
self.addItem(QIcon.fromTheme(t[2]), t[1], t[0])
|
||||||
|
|
||||||
|
@ -43,7 +41,7 @@ class cmbOutlineTypeChoser(QComboBox):
|
||||||
index = index.sibling(index.row(), self._column)
|
index = index.sibling(index.row(), self._column)
|
||||||
self._index = index
|
self._index = index
|
||||||
# Disabled if item type is not text
|
# Disabled if item type is not text
|
||||||
self.setEnabled(index.internalPointer().type() in ["t2t", "html", "txt"])
|
self.setEnabled(index.internalPointer().type() in ["t2t", "html", "txt", "md"])
|
||||||
self.updateItems()
|
self.updateItems()
|
||||||
self.updateSelectedItem()
|
self.updateSelectedItem()
|
||||||
|
|
||||||
|
@ -57,7 +55,7 @@ class cmbOutlineTypeChoser(QComboBox):
|
||||||
if i.column() != self._column:
|
if i.column() != self._column:
|
||||||
i = i.sibling(i.row(), self._column)
|
i = i.sibling(i.row(), self._column)
|
||||||
self._indexes.append(i)
|
self._indexes.append(i)
|
||||||
if i.internalPointer().type() in ["t2t", "html", "txt"]:
|
if i.internalPointer().type() in ["t2t", "html", "txt", "md"]:
|
||||||
hasText = True
|
hasText = True
|
||||||
|
|
||||||
self.setEnabled(hasText)
|
self.setEnabled(hasText)
|
||||||
|
|
|
@ -11,6 +11,7 @@ from manuskript.enums import Outline
|
||||||
from manuskript.functions import AUC
|
from manuskript.functions import AUC
|
||||||
from manuskript.functions import toString
|
from manuskript.functions import toString
|
||||||
from manuskript.models.outlineModel import outlineModel
|
from manuskript.models.outlineModel import outlineModel
|
||||||
|
from manuskript.ui.editors.MMDHighlighter import MMDHighlighter
|
||||||
from manuskript.ui.editors.basicHighlighter import basicHighlighter
|
from manuskript.ui.editors.basicHighlighter import basicHighlighter
|
||||||
from manuskript.ui.editors.t2tFunctions import t2tClearFormat
|
from manuskript.ui.editors.t2tFunctions import t2tClearFormat
|
||||||
from manuskript.ui.editors.t2tFunctions import t2tFormatSelection
|
from manuskript.ui.editors.t2tFunctions import t2tFormatSelection
|
||||||
|
@ -160,6 +161,8 @@ class textEditView(QTextEdit):
|
||||||
self._textFormat = "html"
|
self._textFormat = "html"
|
||||||
elif item.isT2T():
|
elif item.isT2T():
|
||||||
self._textFormat = "t2t"
|
self._textFormat = "t2t"
|
||||||
|
elif item.isMD():
|
||||||
|
self._textFormat = "md"
|
||||||
else:
|
else:
|
||||||
self._textFormat = "text"
|
self._textFormat = "text"
|
||||||
|
|
||||||
|
@ -174,8 +177,10 @@ class textEditView(QTextEdit):
|
||||||
item = index.internalPointer()
|
item = index.internalPointer()
|
||||||
if self._column == Outline.text.value and not item.isT2T():
|
if self._column == Outline.text.value and not item.isT2T():
|
||||||
self.highlighter = basicHighlighter(self)
|
self.highlighter = basicHighlighter(self)
|
||||||
else:
|
elif item.isT2T():
|
||||||
self.highlighter = t2tHighlighter(self)
|
self.highlighter = t2tHighlighter(self)
|
||||||
|
elif item.isMD():
|
||||||
|
self.highlighter = MMDHighlighter(self)
|
||||||
|
|
||||||
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
||||||
|
|
||||||
|
@ -551,3 +556,7 @@ class textEditView(QTextEdit):
|
||||||
t2tFormatSelection(self, 2)
|
t2tFormatSelection(self, 2)
|
||||||
elif _format == "Clear":
|
elif _format == "Clear":
|
||||||
t2tClearFormat(self)
|
t2tClearFormat(self)
|
||||||
|
|
||||||
|
elif self._textFormat == "md":
|
||||||
|
# FIXME
|
||||||
|
print("Not implemented yet.")
|
||||||
|
|
|
@ -7,7 +7,8 @@ import os
|
||||||
|
|
||||||
from PyQt5.QtCore import QSettings, QRegExp, Qt, QDir
|
from PyQt5.QtCore import QSettings, QRegExp, Qt, QDir
|
||||||
from PyQt5.QtGui import QIcon, QBrush, QColor, QStandardItemModel, QStandardItem
|
from PyQt5.QtGui import QIcon, QBrush, QColor, QStandardItemModel, QStandardItem
|
||||||
from PyQt5.QtWidgets import QWidget, QAction, QFileDialog, QSpinBox, QLineEdit, QLabel, QPushButton, QTreeWidgetItem
|
from PyQt5.QtWidgets import QWidget, QAction, QFileDialog, QSpinBox, QLineEdit, QLabel, QPushButton, QTreeWidgetItem, \
|
||||||
|
qApp
|
||||||
|
|
||||||
from manuskript import settings
|
from manuskript import settings
|
||||||
from manuskript.enums import Outline
|
from manuskript.enums import Outline
|
||||||
|
@ -191,11 +192,13 @@ class welcome(QWidget, Ui_welcome):
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
|
|
||||||
def defaultTextType(self):
|
@classmethod
|
||||||
|
def defaultTextType(cls):
|
||||||
return [
|
return [
|
||||||
("t2t", self.tr("Txt2Tags"), "text-x-generic"),
|
("t2t", qApp.translate("Welcome", "Txt2Tags"), "text-x-generic"),
|
||||||
("html", self.tr("Rich Text (html)"), "text-html"),
|
("html", qApp.translate("Welcome", "Rich Text (html)"), "text-html"),
|
||||||
("txt", self.tr("Plain Text"), "text-x-generic"),
|
("txt", qApp.translate("Welcome", "Plain Text"), "text-x-generic"),
|
||||||
|
("md", qApp.translate("Welcome", "Multi-Markdown"), "text-x-generic"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def changeTemplate(self, item, column):
|
def changeTemplate(self, item, column):
|
||||||
|
|
Loading…
Reference in a new issue