mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-11 15:34:33 +12:00
Implement to open projects
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
9287e85b7e
commit
960691e387
33
manuskript/ui/chooser/__init__.py
Normal file
33
manuskript/ui/chooser/__init__.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/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) -> 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)
|
||||||
|
)
|
||||||
|
|
||||||
|
if fileFilter is not None:
|
||||||
|
fileFilter.addToChooser(dialog)
|
||||||
|
FileFilter("All files", "*").addToChooser(dialog)
|
||||||
|
|
||||||
|
response = dialog.run()
|
||||||
|
result = None
|
||||||
|
|
||||||
|
if response == Gtk.ResponseType.OK:
|
||||||
|
result = dialog.get_filename()
|
||||||
|
|
||||||
|
dialog.destroy()
|
||||||
|
return result
|
22
manuskript/ui/chooser/fileFilter.py
Normal file
22
manuskript/ui/chooser/fileFilter.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/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, pattern: str):
|
||||||
|
self.name = name
|
||||||
|
self.pattern = pattern
|
||||||
|
|
||||||
|
def addToChooser(self, chooser: Gtk.FileChooser):
|
||||||
|
fileFilter = Gtk.FileFilter()
|
||||||
|
fileFilter.set_name(self.name)
|
||||||
|
fileFilter.add_pattern(self.pattern)
|
||||||
|
|
||||||
|
chooser.add_filter(fileFilter)
|
|
@ -13,6 +13,7 @@ Handy.init()
|
||||||
from manuskript.data import Project
|
from manuskript.data import Project
|
||||||
from manuskript.ui.views import *
|
from manuskript.ui.views import *
|
||||||
|
|
||||||
|
from manuskript.ui.chooser import openFileDialog, FileFilter
|
||||||
from manuskript.ui.tools import *
|
from manuskript.ui.tools import *
|
||||||
from manuskript.ui.aboutDialog import AboutDialog
|
from manuskript.ui.aboutDialog import AboutDialog
|
||||||
from manuskript.ui.settingsWindow import SettingsWindow
|
from manuskript.ui.settingsWindow import SettingsWindow
|
||||||
|
@ -85,13 +86,10 @@ class MainWindow:
|
||||||
def getProject(self):
|
def getProject(self):
|
||||||
return self.project
|
return self.project
|
||||||
|
|
||||||
def openProject(self, path=None, dialog=False):
|
def openProject(self, path=None):
|
||||||
if self.project is not None:
|
if self.project is not None:
|
||||||
self.closeProject()
|
self.closeProject()
|
||||||
|
|
||||||
if dialog:
|
|
||||||
return
|
|
||||||
|
|
||||||
if path is None:
|
if path is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -128,7 +126,11 @@ class MainWindow:
|
||||||
self.startupWindow.show()
|
self.startupWindow.show()
|
||||||
|
|
||||||
def _openAction(self, menuItem: Gtk.MenuItem):
|
def _openAction(self, menuItem: Gtk.MenuItem):
|
||||||
self.openProject(dialog=True)
|
path = openFileDialog(self.window, FileFilter("Manuskript project", "*.msk"))
|
||||||
|
if path is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.openProject(path)
|
||||||
|
|
||||||
def _recentAction(self, recentChooser: Gtk.RecentChooser):
|
def _recentAction(self, recentChooser: Gtk.RecentChooser):
|
||||||
uri = recentChooser.get_current_uri()
|
uri = recentChooser.get_current_uri()
|
||||||
|
|
|
@ -10,6 +10,7 @@ from manuskript.data import Template, TemplateKind
|
||||||
from manuskript.util import validInt, validString, parseFilenameFromURL
|
from manuskript.util import validInt, validString, parseFilenameFromURL
|
||||||
|
|
||||||
from manuskript.ui.abstractDialog import AbstractDialog
|
from manuskript.ui.abstractDialog import AbstractDialog
|
||||||
|
from manuskript.ui.chooser import openFileDialog, FileFilter
|
||||||
from manuskript.ui.startup import TemplateEntry
|
from manuskript.ui.startup import TemplateEntry
|
||||||
from manuskript.ui.util import bindMenuItem
|
from manuskript.ui.util import bindMenuItem
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ class StartupWindow(AbstractDialog):
|
||||||
self.templatesLeaflet = None
|
self.templatesLeaflet = None
|
||||||
|
|
||||||
self.recentChooserMenu = None
|
self.recentChooserMenu = None
|
||||||
|
self.recentChooserMenuBtn = None
|
||||||
|
|
||||||
self.templatesStore = None
|
self.templatesStore = None
|
||||||
self.fictionTemplatesStore = None
|
self.fictionTemplatesStore = None
|
||||||
|
@ -39,6 +41,10 @@ class StartupWindow(AbstractDialog):
|
||||||
self.addLevelButton = None
|
self.addLevelButton = None
|
||||||
self.addGoalButton = None
|
self.addGoalButton = None
|
||||||
|
|
||||||
|
self.openButton = None
|
||||||
|
self.recentButton = None
|
||||||
|
self.createButton = None
|
||||||
|
|
||||||
def initWindow(self, builder, window):
|
def initWindow(self, builder, window):
|
||||||
self.headerBar = builder.get_object("header_bar")
|
self.headerBar = builder.get_object("header_bar")
|
||||||
self.templatesLeaflet = builder.get_object("templates_leaflet")
|
self.templatesLeaflet = builder.get_object("templates_leaflet")
|
||||||
|
@ -48,7 +54,10 @@ class StartupWindow(AbstractDialog):
|
||||||
GObject.BindingFlags.INVERT_BOOLEAN)
|
GObject.BindingFlags.INVERT_BOOLEAN)
|
||||||
|
|
||||||
self.recentChooserMenu = builder.get_object("recent_chooser_menu")
|
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.recentChooserMenu.connect("item-activated", self._recentAction)
|
||||||
|
self.recentChooserMenuBtn.connect("item-activated", self._recentAction)
|
||||||
|
|
||||||
bindMenuItem(builder, "open_menu_item", self._openAction)
|
bindMenuItem(builder, "open_menu_item", self._openAction)
|
||||||
bindMenuItem(builder, "quit_menu_item", self._quitAction)
|
bindMenuItem(builder, "quit_menu_item", self._quitAction)
|
||||||
|
@ -102,6 +111,12 @@ class StartupWindow(AbstractDialog):
|
||||||
self.addLevelButton.connect("clicked", self._addLevelClicked)
|
self.addLevelButton.connect("clicked", self._addLevelClicked)
|
||||||
self.addGoalButton.connect("clicked", self._addGoalClicked)
|
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)
|
||||||
|
|
||||||
def loadTemplate(self, template: Template):
|
def loadTemplate(self, template: Template):
|
||||||
self.template = template
|
self.template = template
|
||||||
self.templateLevelsListbox.foreach(lambda child: self.templateLevelsListbox.remove(child))
|
self.templateLevelsListbox.foreach(lambda child: self.templateLevelsListbox.remove(child))
|
||||||
|
@ -156,8 +171,18 @@ class StartupWindow(AbstractDialog):
|
||||||
self.template.addGoal()
|
self.template.addGoal()
|
||||||
self.loadTemplate(self.template)
|
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 _openAction(self, menuItem: Gtk.MenuItem):
|
def _openAction(self, menuItem: Gtk.MenuItem):
|
||||||
self.mainWindow.openProject()
|
self.openProject()
|
||||||
|
|
||||||
def _recentAction(self, recentChooser: Gtk.RecentChooser):
|
def _recentAction(self, recentChooser: Gtk.RecentChooser):
|
||||||
uri = recentChooser.get_current_uri()
|
uri = recentChooser.get_current_uri()
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<pattern>*.msk</pattern>
|
<pattern>*.msk</pattern>
|
||||||
</patterns>
|
</patterns>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkRecentChooserMenu" id="recent_chooser_menu">
|
<object class="GtkRecentChooserMenu" id="recent_chooser_menu_btn">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
<property name="filter">recent_filter</property>
|
<property name="filter">recent_filter</property>
|
||||||
|
@ -91,9 +91,10 @@
|
||||||
<property name="label" translatable="yes">_Recent</property>
|
<property name="label" translatable="yes">_Recent</property>
|
||||||
<property name="use-underline">True</property>
|
<property name="use-underline">True</property>
|
||||||
<child type="submenu">
|
<child type="submenu">
|
||||||
<object class="GtkRecentChooserMenu" id="recent_chooser_menu1">
|
<object class="GtkRecentChooserMenu" id="recent_chooser_menu">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
|
<property name="filter">recent_filter</property>
|
||||||
<property name="limit">10</property>
|
<property name="limit">10</property>
|
||||||
<property name="sort-type">mru</property>
|
<property name="sort-type">mru</property>
|
||||||
</object>
|
</object>
|
||||||
|
@ -457,7 +458,7 @@
|
||||||
<property name="halign">end</property>
|
<property name="halign">end</property>
|
||||||
<property name="spacing">9</property>
|
<property name="spacing">9</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton">
|
<object class="GtkButton" id="open_button">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">True</property>
|
<property name="can-focus">True</property>
|
||||||
<property name="receives-default">True</property>
|
<property name="receives-default">True</property>
|
||||||
|
@ -500,12 +501,12 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkMenuButton">
|
<object class="GtkMenuButton" id="recent_button">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">True</property>
|
<property name="can-focus">True</property>
|
||||||
<property name="focus-on-click">False</property>
|
<property name="focus-on-click">False</property>
|
||||||
<property name="receives-default">True</property>
|
<property name="receives-default">True</property>
|
||||||
<property name="popup">recent_chooser_menu</property>
|
<property name="popup">recent_chooser_menu_btn</property>
|
||||||
<property name="use-popover">False</property>
|
<property name="use-popover">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
|
@ -546,7 +547,7 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton">
|
<object class="GtkButton" id="create_button">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">True</property>
|
<property name="can-focus">True</property>
|
||||||
<property name="receives-default">True</property>
|
<property name="receives-default">True</property>
|
||||||
|
|
Loading…
Reference in a new issue