Skip to content

Commit

Permalink
Add do_open handler
Browse files Browse the repository at this point in the history
  • Loading branch information
amka committed Jun 28, 2020
1 parent f2e8c07 commit 8f70472
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions norka/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ class Application(Gtk.Application):

def __init__(self, version: str = None):
super().__init__(application_id=APP_ID,
flags=Gio.ApplicationFlags.FLAGS_NONE)
flags=Gio.ApplicationFlags.HANDLES_OPEN)

self.version = version

# Init GSettings
self.settings = Settings.new()

self.init_style()
self.window = None
self.window: NorkaWindow = None

# Init storage location and SQL structure
try:
Expand All @@ -81,7 +81,6 @@ def __init__(self, version: str = None):
shortcuts_action.connect("activate", self.on_shortcuts)
self.add_action(shortcuts_action)


def init_style(self):
css_provider = Gtk.CssProvider()
css_provider.load_from_resource('/com/github/tenderowl/norka/css/application.css')
Expand All @@ -96,11 +95,29 @@ def do_startup(self):
self.settings.connect("changed", self.on_settings_changed)

def do_activate(self):
"""Activates the application.
"""
self.window = self.props.active_window
if not self.window:
self.window = NorkaWindow(application=self, settings=self.settings)
self.window.present()

def do_open(self, files: [Gio.File], n_files: int, hint: str):
"""Opens the given files.
:param files: an array of Gio.Files to open
:param n_files: number of files in command line args
:param hint: a hint (or “”), but never None
"""
if n_files and not self.window:
self.do_activate()
for gfile in files:
path = gfile.get_path()
if not path:
continue
self.window.import_document(file_path=path)

def on_settings_changed(self, settings, key):
Logger.debug(f'SETTINGS: %s changed', key)
if key == "autosave":
Expand Down

0 comments on commit 8f70472

Please sign in to comment.