Implemented home state and open action activating modes
This commit is contained in:
parent
a866f117b1
commit
392242dff0
|
@ -27,14 +27,14 @@ from gi.repository import Gtk, Gio, Adw
|
||||||
from .window import GemGraphWindow, AboutDialog
|
from .window import GemGraphWindow, AboutDialog
|
||||||
|
|
||||||
|
|
||||||
|
ENABLE = True
|
||||||
|
DISABLE = False
|
||||||
|
|
||||||
|
|
||||||
class GemGraphApplication(Adw.Application):
|
class GemGraphApplication(Adw.Application):
|
||||||
"""The main application singleton class."""
|
"""The main application singleton class."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
ENABLE = True
|
|
||||||
DISABLE = False
|
|
||||||
|
|
||||||
super().__init__(application_id='org.example.App',
|
super().__init__(application_id='org.example.App',
|
||||||
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||||
|
|
||||||
|
@ -45,14 +45,42 @@ class GemGraphApplication(Adw.Application):
|
||||||
self.create_action('togglesidebar', self.on_togglesidebar_action, ENABLE)
|
self.create_action('togglesidebar', self.on_togglesidebar_action, ENABLE)
|
||||||
|
|
||||||
# Create later actions (mode)
|
# Create later actions (mode)
|
||||||
self.create_action('editmode', self.on_editmode_action, DISABLE, ['<primary>e'])
|
self.editmode_action = \
|
||||||
self.create_action('runmode', self.on_runmode_action, DISABLE, ['<primary>r'])
|
self.create_action(
|
||||||
self.create_action('presentmode', self.on_presentmode_action, DISABLE, ['<primary>p'])
|
'editmode',
|
||||||
|
self.on_editmode_action,
|
||||||
|
DISABLE,
|
||||||
|
['<primary>e'])
|
||||||
|
|
||||||
|
self.runmode_action = \
|
||||||
|
self.create_action(
|
||||||
|
'runmode',
|
||||||
|
self.on_runmode_action,
|
||||||
|
DISABLE,
|
||||||
|
['<primary>r'])
|
||||||
|
|
||||||
|
self.presentmode_action = \
|
||||||
|
self.create_action(
|
||||||
|
'presentmode',
|
||||||
|
self.on_presentmode_action,
|
||||||
|
DISABLE,
|
||||||
|
['<primary>p'])
|
||||||
|
|
||||||
# Create file actions
|
# Create file actions
|
||||||
self.create_action('openfile', self.do_open, DISABLE)
|
self.create_action('openfile', self.do_open, ENABLE)
|
||||||
self.create_action('closefile', self.on_close_action, DISABLE)
|
|
||||||
self.create_action('savefile', self.on_save_action, DISABLE, ['<primary>s'])
|
self.close_action = \
|
||||||
|
self.create_action(
|
||||||
|
'closefile',
|
||||||
|
self.on_close_action,
|
||||||
|
DISABLE)
|
||||||
|
|
||||||
|
self.save_action = \
|
||||||
|
self.create_action(
|
||||||
|
'savefile',
|
||||||
|
self.on_save_action,
|
||||||
|
DISABLE,
|
||||||
|
['<primary>s'])
|
||||||
|
|
||||||
def do_activate(self):
|
def do_activate(self):
|
||||||
"""Called when the application is activated.
|
"""Called when the application is activated.
|
||||||
|
@ -69,7 +97,7 @@ class GemGraphApplication(Adw.Application):
|
||||||
win.stack_switch_mode("home")
|
win.stack_switch_mode("home")
|
||||||
win.present()
|
win.present()
|
||||||
|
|
||||||
def do_open(self):
|
def do_open(self, widget, _):
|
||||||
"""Called when the application is activated with a file to open.
|
"""Called when the application is activated with a file to open.
|
||||||
|
|
||||||
We raise the application's main window, creating it if
|
We raise the application's main window, creating it if
|
||||||
|
@ -85,14 +113,34 @@ class GemGraphApplication(Adw.Application):
|
||||||
# Open file
|
# Open file
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Display run mode by default
|
# Activate file actions
|
||||||
win.stack_switch_mode("run")
|
self.close_action.set_enabled(True)
|
||||||
|
self.save_action.set_enabled(True)
|
||||||
|
|
||||||
|
# Activate mode actions
|
||||||
|
self.runmode_action.set_enabled(True)
|
||||||
|
self.editmode_action.set_enabled(True)
|
||||||
|
self.presentmode_action.set_enabled(True)
|
||||||
|
|
||||||
|
# Display edit mode
|
||||||
|
win.stack_switch_mode("edit")
|
||||||
win.present()
|
win.present()
|
||||||
|
|
||||||
def on_close_action(self, widget, _):
|
def on_close_action(self, widget, _):
|
||||||
"""Callback for the app.closefile action."""
|
"""Callback for the app.closefile action."""
|
||||||
print('app.closefile action activated')
|
print('app.closefile action activated')
|
||||||
win = self.props.active_window
|
win = self.props.active_window
|
||||||
|
|
||||||
|
# Disable file actions
|
||||||
|
self.close_action.set_enabled(False)
|
||||||
|
self.save_action.set_enabled(False)
|
||||||
|
|
||||||
|
# Disable mode actions
|
||||||
|
self.runmode_action.set_enabled(False)
|
||||||
|
self.editmode_action.set_enabled(False)
|
||||||
|
self.presentmode_action.set_enabled(False)
|
||||||
|
|
||||||
|
# Get home
|
||||||
win.stack_switch_mode("home")
|
win.stack_switch_mode("home")
|
||||||
|
|
||||||
def on_save_action(self, widget, _):
|
def on_save_action(self, widget, _):
|
||||||
|
@ -150,6 +198,7 @@ class GemGraphApplication(Adw.Application):
|
||||||
self.add_action(action)
|
self.add_action(action)
|
||||||
if shortcuts:
|
if shortcuts:
|
||||||
self.set_accels_for_action(f"app.{name}", shortcuts)
|
self.set_accels_for_action(f"app.{name}", shortcuts)
|
||||||
|
return action
|
||||||
|
|
||||||
|
|
||||||
def main(version):
|
def main(version):
|
||||||
|
|
Loading…
Reference in New Issue