diff --git a/gemgraph/main.py b/gemgraph/main.py index fb8228d..1773047 100644 --- a/gemgraph/main.py +++ b/gemgraph/main.py @@ -31,15 +31,28 @@ class GemGraphApplication(Adw.Application): """The main application singleton class.""" def __init__(self): + + ENABLE = True + DISABLE = False + super().__init__(application_id='org.example.App', flags=Gio.ApplicationFlags.FLAGS_NONE) - self.create_action('quit', self.quit, ['q']) - self.create_action('about', self.on_about_action) - self.create_action('preferences', self.on_preferences_action) - self.create_action('editmode', self.on_editmode_action, ['e']) - self.create_action('runmode', self.on_runmode_action, ['r']) - self.create_action('presentmode', self.on_presentmode_action, ['p']) - self.create_action('togglesidebar', self.on_togglesidebar_action) + + # Create base actions + self.create_action('quit', self.quit, ENABLE, ['q']) + self.create_action('about', self.on_about_action, ENABLE) + self.create_action('preferences', self.on_preferences_action, ENABLE) + self.create_action('togglesidebar', self.on_togglesidebar_action, ENABLE) + + # Create later actions (mode) + self.create_action('editmode', self.on_editmode_action, DISABLE, ['e']) + self.create_action('runmode', self.on_runmode_action, DISABLE, ['r']) + self.create_action('presentmode', self.on_presentmode_action, DISABLE, ['p']) + + # Create file actions + self.create_action('openfile', self.do_open, DISABLE) + self.create_action('closefile', self.on_close_action, DISABLE) + self.create_action('savefile', self.on_save_action, DISABLE, ['s']) def do_activate(self): """Called when the application is activated. @@ -53,7 +66,7 @@ class GemGraphApplication(Adw.Application): win = GemGraphWindow(application=self) # Display run mode by default - win.stack_switch_mode("run") + win.stack_switch_mode("home") win.present() def do_open(self): @@ -61,6 +74,8 @@ class GemGraphApplication(Adw.Application): We raise the application's main window, creating it if necessary. + + Also a callback for the app.openfile action """ print("app.do_open called") win = self.props.active_window @@ -74,6 +89,17 @@ class GemGraphApplication(Adw.Application): win.stack_switch_mode("run") win.present() + def on_close_action(self, widget, _): + """Callback for the app.closefile action.""" + print('app.closefile action activated') + win = self.props.active_window + win.stack_switch_mode("home") + + def on_save_action(self, widget, _): + """Callback for the app.savefile action.""" + print('app.savefile action activated') + win = self.props.active_window + def on_about_action(self, widget, _): """Callback for the app.about action.""" about = AboutDialog(self.props.active_window) @@ -109,7 +135,7 @@ class GemGraphApplication(Adw.Application): win = self.props.active_window win.toggle_sidebar() - def create_action(self, name, callback, shortcuts=None): + def create_action(self, name, callback, is_enabled, shortcuts=None): """Add an application action. Args: @@ -120,6 +146,7 @@ class GemGraphApplication(Adw.Application): """ action = Gio.SimpleAction.new(name, None) action.connect("activate", callback) + action.set_enabled(is_enabled) self.add_action(action) if shortcuts: self.set_accels_for_action(f"app.{name}", shortcuts) diff --git a/gemgraph/window.py b/gemgraph/window.py index dc76339..6736a24 100644 --- a/gemgraph/window.py +++ b/gemgraph/window.py @@ -32,11 +32,13 @@ class GemGraphWindow(Gtk.ApplicationWindow): main_paned = Gtk.Template.Child() main_button_mode = Gtk.Template.Child() toast_overlay = Gtk.Template.Child() + main_button_sidebar = Gtk.Template.Child() __mode_icon = { + "mode_home":"user-home-symbolic" , "mode_edit":"document-edit-symbolic" , "mode_run":"system-run-symbolic" , - "mode_presentation":"video-display-symbolic" + "mode_presentation":"x-office-presentation-symbolic" } def __init__(self, **kwargs): @@ -53,6 +55,8 @@ class GemGraphWindow(Gtk.ApplicationWindow): else: self.main_paned.set_position(300) + self.main_button_sidebar.toggled() + def stack_switch_mode(self, mode): """ Sets the active mode from stack. Mode is the name of the mode (string) diff --git a/ui/gemgraph.ui b/ui/gemgraph.ui index 423527f..f3189e3 100644 --- a/ui/gemgraph.ui +++ b/ui/gemgraph.ui @@ -61,6 +61,18 @@ + + + side_home + + + center + <b>Sidebar: home</b> + True + + + + side_presentation @@ -101,6 +113,18 @@ + + + main_home + + + center + <b>Main zone: home</b> + True + + + + main_presentation @@ -137,15 +161,15 @@
_Open... - app.open_file + app.openfile _Close - app.close_file + app.closefile _Save - app.save_file + app.savefile