mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-12 17:02:36 +12:00
Revert "Merge branch 'gtk' into gtk"
This reverts commit7ac53ed891
, reversing changes made to52c63a4763
.
This commit is contained in:
parent
7ac53ed891
commit
e04b148c57
|
@ -14,6 +14,5 @@ from manuskript.ui import MainWindow
|
|||
|
||||
path = os.path.join(os.getcwd(), "sample-projects/book-of-acts")
|
||||
|
||||
window = MainWindow()
|
||||
window.openProject(path + ".msk")
|
||||
window = MainWindow(path + ".msk")
|
||||
window.run()
|
||||
|
|
|
@ -20,11 +20,6 @@ class AbstractData:
|
|||
self.dataPath = path
|
||||
self.dataStatus = DataStatus.UNDEFINED
|
||||
|
||||
def changePath(self, path: str):
|
||||
print("{} -> {}".format(self.dataPath, path))
|
||||
|
||||
self.dataPath = path
|
||||
|
||||
def complete(self, statusCompletion: bool = True):
|
||||
if self.dataStatus == DataStatus.LOADING:
|
||||
self.dataStatus = DataStatus.LOADED if statusCompletion else DataStatus.UNDEFINED
|
||||
|
|
|
@ -37,10 +37,6 @@ class Character(AbstractData):
|
|||
self.color = None
|
||||
self.details = dict()
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, path)
|
||||
self.file = MmdFile(self.dataPath, 21)
|
||||
|
||||
def allowPOV(self) -> bool:
|
||||
return True if self.POV is None else self.POV
|
||||
|
||||
|
@ -123,15 +119,6 @@ class Characters(AbstractData):
|
|||
self.host = UniqueIDHost()
|
||||
self.data = dict()
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "characters"))
|
||||
|
||||
for character in self.data.values():
|
||||
filename = safeFilename("%s-%s" % (str(character.UID), character.name), "txt")
|
||||
path_ = os.path.join(self.dataPath, filename)
|
||||
|
||||
character.changePath(path_)
|
||||
|
||||
def __iter__(self):
|
||||
return self.data.values().__iter__()
|
||||
|
||||
|
|
|
@ -22,10 +22,6 @@ class Info(AbstractData):
|
|||
self.author = None
|
||||
self.email = None
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "infos.txt"))
|
||||
self.file = MmdFile(self.dataPath, 16)
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
|
|
|
@ -35,10 +35,6 @@ class LabelHost(AbstractData):
|
|||
self.file = MmdFile(self.dataPath, 21)
|
||||
self.labels = collections.OrderedDict()
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "labels.txt"))
|
||||
self.file = MmdFile(self.dataPath, 21)
|
||||
|
||||
def addLabel(self, name: str = None, color: Color = None) -> Label:
|
||||
if name is None:
|
||||
name = "New Label"
|
||||
|
|
|
@ -13,7 +13,7 @@ from manuskript.data.plots import Plots
|
|||
from manuskript.data.status import StatusHost
|
||||
from manuskript.data.unique_id import UniqueIDHost
|
||||
from manuskript.io.mmdFile import MmdFile
|
||||
from manuskript.util import CounterKind, countText, safeInt, safeFilename
|
||||
from manuskript.util import CounterKind, countText, safeInt
|
||||
|
||||
|
||||
@unique
|
||||
|
@ -43,10 +43,6 @@ class OutlineItem(AbstractData):
|
|||
self.compile = True
|
||||
self.goal = None
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, path)
|
||||
self.file = MmdFile(self.dataPath)
|
||||
|
||||
def parentItem(self):
|
||||
for item in self.outline.all():
|
||||
if item.contains(self):
|
||||
|
@ -98,8 +94,8 @@ class OutlineItem(AbstractData):
|
|||
metadata["summaryFull"] = item.summaryFull
|
||||
metadata["POV"] = item.POV
|
||||
metadata["notes"] = item.notes
|
||||
metadata["label"] = None if item.label is None else item.label.ID
|
||||
metadata["status"] = None if item.status is None else item.status.ID
|
||||
metadata["label"] = None if item is None else item.label.ID
|
||||
metadata["status"] = None if item is None else item.status.ID
|
||||
metadata["compile"] = item.compile
|
||||
metadata["setGoal"] = item.goal
|
||||
|
||||
|
@ -181,19 +177,6 @@ class OutlineFolder(OutlineItem):
|
|||
self.folderPath = path
|
||||
self.items = list()
|
||||
|
||||
def changePath(self, path: str):
|
||||
OutlineItem.changePath(self, os.path.join(path, "folder.txt"))
|
||||
|
||||
self.folderPath = path
|
||||
|
||||
index = 0
|
||||
for item in self.items:
|
||||
filename = safeFilename("%s-%s" % (str(index), item.title), None if type(item) is OutlineFolder else "md")
|
||||
path_ = os.path.join(self.folderPath, filename)
|
||||
|
||||
item.changePath(path_)
|
||||
index += 1
|
||||
|
||||
def __iter__(self):
|
||||
return self.items.__iter__()
|
||||
|
||||
|
@ -267,7 +250,6 @@ class OutlineFolder(OutlineItem):
|
|||
self.type = "folder"
|
||||
|
||||
OutlineItem.save(self)
|
||||
os.makedirs(self.folderPath, exist_ok=True)
|
||||
|
||||
metadata = OutlineItem.saveMetadata(self)
|
||||
self.file.save((metadata, "\n"))
|
||||
|
@ -285,17 +267,6 @@ class Outline(AbstractData):
|
|||
self.items = list()
|
||||
self.cache = dict()
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "outline"))
|
||||
|
||||
index = 0
|
||||
for item in self.items:
|
||||
filename = safeFilename("%s-%s" % (str(index), item.title), None if type(item) is OutlineFolder else "md")
|
||||
path_ = os.path.join(self.dataPath, filename)
|
||||
|
||||
item.changePath(path_)
|
||||
index += 1
|
||||
|
||||
def __iter__(self):
|
||||
return self.items.__iter__()
|
||||
|
||||
|
@ -346,10 +317,6 @@ class Outline(AbstractData):
|
|||
|
||||
AbstractData.load(self)
|
||||
|
||||
if not os.path.isdir(self.dataPath):
|
||||
self.complete(False)
|
||||
return
|
||||
|
||||
names = os.listdir(self.dataPath)
|
||||
names.sort()
|
||||
|
||||
|
|
|
@ -113,10 +113,6 @@ class Plots(AbstractData):
|
|||
self.characters = characters
|
||||
self.lines = dict()
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "plots.xml"))
|
||||
self.file = XmlFile(self.dataPath)
|
||||
|
||||
def addLine(self, name: str = None, importance: Importance = Importance.MINOR):
|
||||
line = PlotLine(self, self.host.newID(), name, importance)
|
||||
self.lines[line.UID.value] = line
|
||||
|
|
|
@ -29,8 +29,7 @@ from manuskript.util import profileTime
|
|||
|
||||
|
||||
class Project(AbstractData):
|
||||
|
||||
def __init__(self, path: str):
|
||||
def __init__(self, path):
|
||||
AbstractData.__init__(self, path)
|
||||
self.file = MskFile(self.dataPath)
|
||||
|
||||
|
@ -69,25 +68,6 @@ class Project(AbstractData):
|
|||
def upgradeVersion(self):
|
||||
self.version.value = CURRENT_MSK_VERSION
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, path)
|
||||
saveToZip = self.settings.isEnabled("saveToZip")
|
||||
|
||||
self.file = MskFile(self.dataPath, ignorePath=True, forceZip=saveToZip)
|
||||
os.makedirs(self.file.directoryPath, exist_ok=True)
|
||||
|
||||
self.version.changePath(self.file.directoryPath)
|
||||
self.info.changePath(self.file.directoryPath)
|
||||
self.summary.changePath(self.file.directoryPath)
|
||||
self.labels.changePath(self.file.directoryPath)
|
||||
self.statuses.changePath(self.file.directoryPath)
|
||||
self.settings.changePath(self.file.directoryPath)
|
||||
self.characters.changePath(self.file.directoryPath)
|
||||
self.plots.changePath(self.file.directoryPath)
|
||||
self.world.changePath(self.file.directoryPath)
|
||||
self.outline.changePath(self.file.directoryPath)
|
||||
self.revisions.changePath(self.file.directoryPath)
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
|
|
|
@ -43,10 +43,6 @@ class Revisions(AbstractData):
|
|||
self.file = XmlFile(self.dataPath)
|
||||
self.outline = dict()
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "revisions.xml"))
|
||||
self.file = XmlFile(self.dataPath)
|
||||
|
||||
def __iter__(self):
|
||||
return self.outline.values().__iter__()
|
||||
|
||||
|
|
|
@ -17,10 +17,6 @@ class Settings(AbstractData):
|
|||
if initDefault:
|
||||
Settings.loadDefaultSettings(self)
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "settings.txt"))
|
||||
self.file = JsonFile(self.dataPath)
|
||||
|
||||
def get(self, key: str):
|
||||
props = self.properties
|
||||
path = key.split(".")
|
||||
|
|
|
@ -33,10 +33,6 @@ class StatusHost(AbstractData):
|
|||
self.file = TextFile(self.dataPath)
|
||||
self.statuses = collections.OrderedDict()
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "status.txt"))
|
||||
self.file = TextFile(self.dataPath)
|
||||
|
||||
def addStatus(self, name: str = None) -> Status:
|
||||
if name is None:
|
||||
name = "New Status"
|
||||
|
|
|
@ -19,10 +19,6 @@ class Summary(AbstractData):
|
|||
self.page = None
|
||||
self.full = None
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "summary.txt"))
|
||||
self.file = MmdFile(self.dataPath, 13)
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
|
|
|
@ -19,11 +19,6 @@ class Version(AbstractData):
|
|||
|
||||
self.value = LEGACY_MSK_VERSION
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "MANUSKRIPT"))
|
||||
self.file = TextFile(self.dataPath)
|
||||
self.legacy_file = TextFile(os.path.join(path, "VERSION"))
|
||||
|
||||
def loadLegacy(self):
|
||||
try:
|
||||
return int(self.legacy_file.load())
|
||||
|
|
|
@ -45,10 +45,6 @@ class World(AbstractData):
|
|||
self.items = dict()
|
||||
self.top = list()
|
||||
|
||||
def changePath(self, path: str):
|
||||
AbstractData.changePath(self, os.path.join(path, "world.opml"))
|
||||
self.file = OpmlFile(self.dataPath)
|
||||
|
||||
def addItem(self, name: str = None, parent: WorldItem = None) -> WorldItem:
|
||||
item = WorldItem(self, self.host.newID(), name)
|
||||
|
||||
|
|
|
@ -13,16 +13,14 @@ from manuskript.data.version import LEGACY_MSK_VERSION
|
|||
|
||||
class MskFile(TextFile, ZipFile):
|
||||
|
||||
def __init__(self, path, ignorePath: bool = False, forceZip: bool = False):
|
||||
def __init__(self, path):
|
||||
try:
|
||||
if not forceZip:
|
||||
_ZipFile(path)
|
||||
|
||||
_ZipFile(path)
|
||||
directoryPath = None
|
||||
except (BadZipFile, FileNotFoundError):
|
||||
except BadZipFile:
|
||||
directoryPath = os.path.splitext(path)[0]
|
||||
|
||||
if (not ignorePath) and (not os.path.isdir(directoryPath)):
|
||||
if not os.path.isdir(directoryPath):
|
||||
directoryPath = None
|
||||
|
||||
self.zipFile = directoryPath is None
|
||||
|
@ -49,8 +47,7 @@ class MskFile(TextFile, ZipFile):
|
|||
if not os.path.isdir(self.directoryPath):
|
||||
os.mkdir(self.directoryPath)
|
||||
|
||||
if os.path.exists(self.path):
|
||||
ZipFile.load(self)
|
||||
ZipFile.load(self)
|
||||
|
||||
self.zipFile = zipFile
|
||||
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version('Gdk', '3.0')
|
||||
|
||||
from gi.repository import GObject, Gtk
|
||||
|
||||
from manuskript.ui.chooser.fileFilter import FileFilter
|
||||
|
||||
|
||||
def openFileDialog(window, fileFilter_: FileFilter = None, appendAllFilter: bool = True) -> str | None:
|
||||
dialog = Gtk.FileChooserDialog(
|
||||
"Please choose a file",
|
||||
window,
|
||||
Gtk.FileChooserAction.OPEN,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
|
||||
)
|
||||
|
||||
dialog.set_default_response(Gtk.ResponseType.OK)
|
||||
|
||||
if fileFilter_ is not None:
|
||||
fileFilter_.addToChooser(dialog)
|
||||
|
||||
if appendAllFilter:
|
||||
FileFilter("All files").addToChooser(dialog)
|
||||
|
||||
response = dialog.run()
|
||||
result = None
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
result = dialog.get_filename()
|
||||
|
||||
dialog.destroy()
|
||||
return result
|
||||
|
||||
|
||||
def saveFileDialog(window, fileFilter_: FileFilter = None, appendAllFilter: bool = True) -> str | None:
|
||||
dialog = Gtk.FileChooserDialog(
|
||||
"Please choose a file",
|
||||
window,
|
||||
Gtk.FileChooserAction.SAVE,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
|
||||
)
|
||||
|
||||
dialog.set_default_response(Gtk.ResponseType.OK)
|
||||
|
||||
if fileFilter_ is not None:
|
||||
fileFilter_.addToChooser(dialog)
|
||||
|
||||
if appendAllFilter:
|
||||
FileFilter("All files").addToChooser(dialog)
|
||||
|
||||
response = dialog.run()
|
||||
result = None
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
result = dialog.get_filename()
|
||||
|
||||
if ((fileFilter_ is not None) and (fileFilter_.name == dialog.get_filter().get_name()) and
|
||||
(not result.endswith("." + fileFilter_.extension))):
|
||||
result += "." + fileFilter_.extension
|
||||
|
||||
dialog.destroy()
|
||||
return result
|
|
@ -1,22 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version('Gdk', '3.0')
|
||||
|
||||
from gi.repository import GObject, Gtk
|
||||
|
||||
|
||||
class FileFilter:
|
||||
|
||||
def __init__(self, name: str, extension: str = ""):
|
||||
self.name = name
|
||||
self.extension = extension
|
||||
|
||||
def addToChooser(self, chooser: Gtk.FileChooser):
|
||||
fileFilter = Gtk.FileFilter()
|
||||
fileFilter.set_name(self.name)
|
||||
fileFilter.add_pattern("*.{}".format(self.extension) if len(self.extension) > 0 else "*")
|
||||
|
||||
chooser.add_filter(fileFilter)
|
|
@ -13,19 +13,40 @@ Handy.init()
|
|||
from manuskript.data import Project
|
||||
from manuskript.ui.views import *
|
||||
|
||||
from manuskript.ui.chooser import openFileDialog, saveFileDialog, FileFilter
|
||||
from manuskript.ui.tools import *
|
||||
from manuskript.ui.aboutDialog import AboutDialog
|
||||
from manuskript.ui.settingsWindow import SettingsWindow
|
||||
from manuskript.ui.startupWindow import StartupWindow
|
||||
from manuskript.ui.util import bindMenuItem, packViewIntoSlot, unpackFromSlot
|
||||
from manuskript.util import parseFilenameFromURL
|
||||
from manuskript.ui.util import bindMenuItem
|
||||
from manuskript.util import profileTime
|
||||
|
||||
|
||||
class MainWindow:
|
||||
|
||||
def __init__(self):
|
||||
self.project = None
|
||||
@classmethod
|
||||
def packViewIntoSlot(cls, builder, id, view_cls, data=None):
|
||||
slot = builder.get_object(id)
|
||||
|
||||
if slot is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
if data is None:
|
||||
view = profileTime(view_cls)
|
||||
else:
|
||||
view = profileTime(view_cls, data)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
if view.widget is None:
|
||||
return None
|
||||
|
||||
slot.pack_start(view.widget, True, True, 0)
|
||||
return view
|
||||
|
||||
def __init__(self, path):
|
||||
self.project = Project(path)
|
||||
self.project.load()
|
||||
|
||||
builder = Gtk.Builder()
|
||||
builder.add_from_file("ui/main.glade")
|
||||
|
@ -37,25 +58,19 @@ class MainWindow:
|
|||
self.leaflet = builder.get_object("leaflet")
|
||||
self.viewSwitcherBar = builder.get_object("view_switcher_bar")
|
||||
|
||||
self.headerBar.set_subtitle(self.project.info.title)
|
||||
|
||||
self.leaflet.bind_property("folded", self.viewSwitcherBar, "reveal", GObject.BindingFlags.SYNC_CREATE)
|
||||
self.leaflet.bind_property("folded", self.headerBar, "show-close-button", GObject.BindingFlags.SYNC_CREATE |
|
||||
GObject.BindingFlags.INVERT_BOOLEAN)
|
||||
|
||||
self.generalSlot = builder.get_object("general_slot")
|
||||
self.summarySlot = builder.get_object("summary_slot")
|
||||
self.charactersSlot = builder.get_object("characters_slot")
|
||||
self.plotSlot = builder.get_object("plot_slot")
|
||||
self.worldSlot = builder.get_object("world_slot")
|
||||
self.outlineSlot = builder.get_object("outline_slot")
|
||||
self.editorSlot = builder.get_object("editor_slot")
|
||||
|
||||
self.generalView = None
|
||||
self.summaryView = None
|
||||
self.charactersView = None
|
||||
self.plotView = None
|
||||
self.worldView = None
|
||||
self.outlineView = None
|
||||
self.editorView = None
|
||||
self.generalView = MainWindow.packViewIntoSlot(builder, "general_slot", GeneralView, self.project.info)
|
||||
self.summaryView = MainWindow.packViewIntoSlot(builder, "summary_slot", SummaryView, self.project.summary)
|
||||
self.charactersView = MainWindow.packViewIntoSlot(builder, "characters_slot", CharactersView, self.project)
|
||||
self.plotView = MainWindow.packViewIntoSlot(builder, "plot_slot", PlotView, self.project.plots)
|
||||
self.worldView = MainWindow.packViewIntoSlot(builder, "world_slot", WorldView, self.project.world)
|
||||
self.outlineView = MainWindow.packViewIntoSlot(builder, "outline_slot", OutlineView, self.project.outline)
|
||||
self.editorView = MainWindow.packViewIntoSlot(builder, "editor_slot", EditorView, self.project)
|
||||
|
||||
self.startupWindow = StartupWindow(self)
|
||||
self.aboutDialog = AboutDialog(self)
|
||||
|
@ -69,12 +84,8 @@ class MainWindow:
|
|||
self.settingsWindow
|
||||
]
|
||||
|
||||
self.recentChooserMenu = builder.get_object("recent_chooser_menu")
|
||||
self.recentChooserMenu.connect("item-activated", self._recentAction)
|
||||
|
||||
bindMenuItem(builder, "open_menu_item", self._openAction)
|
||||
bindMenuItem(builder, "save_menu_item", self._saveAction)
|
||||
bindMenuItem(builder, "saveas_menu_item", self._saveAsAction)
|
||||
bindMenuItem(builder, "close_menu_item", self._closeAction)
|
||||
bindMenuItem(builder, "quit_menu_item", self._quitAction)
|
||||
|
||||
|
@ -83,78 +94,21 @@ class MainWindow:
|
|||
bindMenuItem(builder, "character_details_template_editor", self._characterDetailsTemplateEditorAction)
|
||||
bindMenuItem(builder, "about_menu_item", self._aboutAction)
|
||||
|
||||
self.hide()
|
||||
|
||||
def getProject(self):
|
||||
return self.project
|
||||
|
||||
def openProject(self, path=None):
|
||||
if self.project is not None:
|
||||
self.closeProject()
|
||||
|
||||
if path is None:
|
||||
return
|
||||
|
||||
self.project = Project(path)
|
||||
self.project.load()
|
||||
|
||||
self.headerBar.set_subtitle(self.project.info.title)
|
||||
|
||||
self.generalView = packViewIntoSlot(self.generalSlot, GeneralView, self.project.info)
|
||||
self.summaryView = packViewIntoSlot(self.summarySlot, SummaryView, self.project.summary)
|
||||
self.charactersView = packViewIntoSlot(self.charactersSlot, CharactersView, self.project.characters)
|
||||
self.plotView = packViewIntoSlot(self.plotSlot, PlotView, self.project.plots)
|
||||
self.worldView = packViewIntoSlot(self.worldSlot, WorldView, self.project.world)
|
||||
self.outlineView = packViewIntoSlot(self.outlineSlot, OutlineView, self.project.outline)
|
||||
self.editorView = packViewIntoSlot(self.editorSlot, EditorView, self.project)
|
||||
|
||||
self.startupWindow.hide()
|
||||
self.show()
|
||||
def openProject(self):
|
||||
pass
|
||||
|
||||
def closeProject(self):
|
||||
if self.project is not None:
|
||||
self.generalView = unpackFromSlot(self.generalSlot, self.generalView)
|
||||
self.summaryView = unpackFromSlot(self.summarySlot, self.summaryView)
|
||||
self.charactersView = unpackFromSlot(self.charactersSlot, self.charactersView)
|
||||
self.plotView = unpackFromSlot(self.plotSlot, self.plotView)
|
||||
self.worldView = unpackFromSlot(self.worldSlot, self.worldView)
|
||||
self.outlineView = unpackFromSlot(self.outlineSlot, self.outlineView)
|
||||
self.editorView = unpackFromSlot(self.editorSlot, self.editorView)
|
||||
|
||||
del self.project
|
||||
self.project = None
|
||||
|
||||
self.hide()
|
||||
self.startupWindow.show()
|
||||
|
||||
def _openAction(self, menuItem: Gtk.MenuItem):
|
||||
path = openFileDialog(self.window, FileFilter("Manuskript project", "msk"))
|
||||
if path is None:
|
||||
return
|
||||
|
||||
self.openProject(path)
|
||||
|
||||
def _recentAction(self, recentChooser: Gtk.RecentChooser):
|
||||
uri = recentChooser.get_current_uri()
|
||||
if uri is None:
|
||||
return
|
||||
|
||||
path = parseFilenameFromURL(uri)
|
||||
if path is None:
|
||||
return
|
||||
|
||||
self.openProject(path)
|
||||
self.openProject()
|
||||
|
||||
def _saveAction(self, menuItem: Gtk.MenuItem):
|
||||
self.project.save()
|
||||
|
||||
def _saveAsAction(self, menuItem: Gtk.MenuItem):
|
||||
path = saveFileDialog(self.window, FileFilter("Manuskript project", "msk"))
|
||||
if path is None:
|
||||
return
|
||||
|
||||
self.project.changePath(path)
|
||||
self.project.save()
|
||||
self.getProject().save()
|
||||
|
||||
def _closeAction(self, menuItem: Gtk.MenuItem):
|
||||
self.closeProject()
|
||||
|
@ -163,7 +117,7 @@ class MainWindow:
|
|||
self.exit(True)
|
||||
|
||||
def getSettings(self):
|
||||
return self.project.settings
|
||||
return self.getProject().settings
|
||||
|
||||
def _settingsAction(self, menuItem: Gtk.MenuItem):
|
||||
self.settingsWindow.show()
|
||||
|
|
|
@ -6,11 +6,10 @@ import gi
|
|||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import GObject, Gtk, Handy
|
||||
|
||||
from manuskript.data import Project, Template, TemplateKind
|
||||
from manuskript.util import validInt, validString, parseFilenameFromURL
|
||||
from manuskript.data import Template, TemplateLevel, TemplateKind
|
||||
from manuskript.util import validInt, validString
|
||||
|
||||
from manuskript.ui.abstractDialog import AbstractDialog
|
||||
from manuskript.ui.chooser import openFileDialog, saveFileDialog, FileFilter
|
||||
from manuskript.ui.startup import TemplateEntry
|
||||
from manuskript.ui.util import bindMenuItem
|
||||
|
||||
|
@ -26,9 +25,6 @@ class StartupWindow(AbstractDialog):
|
|||
self.headerBar = None
|
||||
self.templatesLeaflet = None
|
||||
|
||||
self.recentChooserMenu = None
|
||||
self.recentChooserMenuBtn = None
|
||||
|
||||
self.templatesStore = None
|
||||
self.fictionTemplatesStore = None
|
||||
self.nonfictionTemplatesStore = None
|
||||
|
@ -41,10 +37,6 @@ class StartupWindow(AbstractDialog):
|
|||
self.addLevelButton = None
|
||||
self.addGoalButton = None
|
||||
|
||||
self.openButton = None
|
||||
self.recentButton = None
|
||||
self.createButton = None
|
||||
|
||||
def initWindow(self, builder, window):
|
||||
self.headerBar = builder.get_object("header_bar")
|
||||
self.templatesLeaflet = builder.get_object("templates_leaflet")
|
||||
|
@ -53,11 +45,6 @@ class StartupWindow(AbstractDialog):
|
|||
GObject.BindingFlags.SYNC_CREATE |
|
||||
GObject.BindingFlags.INVERT_BOOLEAN)
|
||||
|
||||
self.recentChooserMenu = builder.get_object("recent_chooser_menu")
|
||||
self.recentChooserMenuBtn = builder.get_object("recent_chooser_menu_btn")
|
||||
|
||||
self.recentChooserMenu.connect("item-activated", self._recentAction)
|
||||
self.recentChooserMenuBtn.connect("item-activated", self._recentAction)
|
||||
|
||||
bindMenuItem(builder, "open_menu_item", self._openAction)
|
||||
bindMenuItem(builder, "quit_menu_item", self._quitAction)
|
||||
|
@ -111,13 +98,6 @@ class StartupWindow(AbstractDialog):
|
|||
self.addLevelButton.connect("clicked", self._addLevelClicked)
|
||||
self.addGoalButton.connect("clicked", self._addGoalClicked)
|
||||
|
||||
self.openButton = builder.get_object("open_button")
|
||||
self.recentButton = builder.get_object("recent_button")
|
||||
self.createButton = builder.get_object("create_button")
|
||||
|
||||
self.openButton.connect("clicked", self._openClicked)
|
||||
self.createButton.connect("clicked", self._createClicked)
|
||||
|
||||
def loadTemplate(self, template: Template):
|
||||
self.template = template
|
||||
self.templateLevelsListbox.foreach(lambda child: self.templateLevelsListbox.remove(child))
|
||||
|
@ -172,40 +152,8 @@ class StartupWindow(AbstractDialog):
|
|||
self.template.addGoal()
|
||||
self.loadTemplate(self.template)
|
||||
|
||||
def openProject(self):
|
||||
path = openFileDialog(self.window, FileFilter("Manuskript project", "msk"))
|
||||
if path is None:
|
||||
return
|
||||
|
||||
self.mainWindow.openProject(path)
|
||||
|
||||
def _openClicked(self, button: Gtk.Button):
|
||||
self.openProject()
|
||||
|
||||
def _createClicked(self, button: Gtk.Button):
|
||||
path = saveFileDialog(self.window, FileFilter("Manuskript project", "msk"), appendAllFilter=False)
|
||||
if path is None:
|
||||
return
|
||||
|
||||
project = Project(path)
|
||||
# TODO: apply project template!
|
||||
project.save()
|
||||
|
||||
self.mainWindow.openProject(path)
|
||||
|
||||
def _openAction(self, menuItem: Gtk.MenuItem):
|
||||
self.openProject()
|
||||
|
||||
def _recentAction(self, recentChooser: Gtk.RecentChooser):
|
||||
uri = recentChooser.get_current_uri()
|
||||
if uri is None:
|
||||
return
|
||||
|
||||
path = parseFilenameFromURL(uri)
|
||||
if path is None:
|
||||
return
|
||||
|
||||
self.mainWindow.openProject(path)
|
||||
self.mainWindow.openProject()
|
||||
|
||||
def _quitAction(self, menuItem: Gtk.MenuItem):
|
||||
self.mainWindow.exit(True)
|
||||
|
|
|
@ -8,7 +8,6 @@ gi.require_version('GdkPixbuf', '2.0')
|
|||
from gi.repository import GdkPixbuf, Gdk
|
||||
|
||||
from manuskript.data import Color, OutlineItem, OutlineText, OutlineFolder
|
||||
from manuskript.util import profileTime
|
||||
|
||||
|
||||
def rgbaFromColor(color: Color) -> Gdk.RGBA:
|
||||
|
@ -35,36 +34,6 @@ def bindMenuItem(builder, id, action):
|
|||
menuItem.connect("activate", action)
|
||||
|
||||
|
||||
def packViewIntoSlot(slot, view_cls, data=None):
|
||||
if slot is None:
|
||||
return None
|
||||
|
||||
for child in slot.get_children():
|
||||
slot.remove(child)
|
||||
|
||||
try:
|
||||
if data is None:
|
||||
view = profileTime(view_cls)
|
||||
else:
|
||||
view = profileTime(view_cls, data)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
if view.widget is None:
|
||||
return None
|
||||
|
||||
slot.pack_start(view.widget, True, True, 0)
|
||||
return view
|
||||
|
||||
|
||||
def unpackFromSlot(slot, view):
|
||||
if (slot is not None) and (view.widget is not None):
|
||||
slot.remove(view.widget)
|
||||
|
||||
del view
|
||||
return None
|
||||
|
||||
|
||||
def iconByOutlineItemType(outlineItem: OutlineItem) -> str:
|
||||
if type(outlineItem) is OutlineFolder:
|
||||
return "folder-symbolic"
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
import re
|
||||
import time
|
||||
import traceback
|
||||
import urllib.parse
|
||||
|
||||
from manuskript.util.counter import CounterKind, CharCounter, WordCounter, PageCounter
|
||||
|
||||
|
@ -52,18 +51,6 @@ def safeFilename(filename: str, extension: str = None) -> str:
|
|||
return re.sub(r"[^a-zA-Z0-9._\-+()]", "_", name)
|
||||
|
||||
|
||||
def parseFilenameFromURL(url: str) -> str | None:
|
||||
result = urllib.parse.urlparse(url)
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
if result.scheme != "file":
|
||||
return None
|
||||
|
||||
return result.path
|
||||
|
||||
|
||||
def countText(text: str, kind: CounterKind = CounterKind.WORDS):
|
||||
if text is None:
|
||||
return 0
|
||||
|
|
|
@ -1175,7 +1175,6 @@ summary</property>
|
|||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Next</property>
|
||||
|
@ -1211,7 +1210,6 @@ summary</property>
|
|||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<pattern>*.msk</pattern>
|
||||
</patterns>
|
||||
</object>
|
||||
<object class="GtkRecentChooserMenu" id="recent_chooser_menu_btn">
|
||||
<object class="GtkRecentChooserMenu" id="recent_chooser_menu">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="filter">recent_filter</property>
|
||||
|
@ -91,10 +91,9 @@
|
|||
<property name="label" translatable="yes">_Recent</property>
|
||||
<property name="use-underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkRecentChooserMenu" id="recent_chooser_menu">
|
||||
<object class="GtkRecentChooserMenu" id="recent_chooser_menu1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="filter">recent_filter</property>
|
||||
<property name="limit">10</property>
|
||||
<property name="sort-type">mru</property>
|
||||
</object>
|
||||
|
@ -458,7 +457,7 @@
|
|||
<property name="halign">end</property>
|
||||
<property name="spacing">9</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="open_button">
|
||||
<object class="GtkButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
|
@ -501,12 +500,12 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="recent_button">
|
||||
<object class="GtkMenuButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="focus-on-click">False</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="popup">recent_chooser_menu_btn</property>
|
||||
<property name="popup">recent_chooser_menu</property>
|
||||
<property name="use-popover">False</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
|
@ -547,7 +546,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="create_button">
|
||||
<object class="GtkButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
|
|
Loading…
Reference in a new issue