Added Open/Close/Save options and toast notifications

This commit is contained in:
Adrien Bourmault 2022-07-29 17:59:05 +02:00
parent ccaf200dbe
commit 4acc10e72d
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
3 changed files with 118 additions and 75 deletions

View File

@ -47,6 +47,7 @@ class GemGraphApplication(Adw.Application):
We raise the application's main window, creating it if We raise the application's main window, creating it if
necessary. necessary.
""" """
print("app.do_activate called")
win = self.props.active_window win = self.props.active_window
if not win: if not win:
win = GemGraphWindow(application=self) win = GemGraphWindow(application=self)
@ -55,6 +56,24 @@ class GemGraphApplication(Adw.Application):
win.stack_switch_mode("run") win.stack_switch_mode("run")
win.present() win.present()
def do_open(self):
"""Called when the application is activated with a file to open.
We raise the application's main window, creating it if
necessary.
"""
print("app.do_open called")
win = self.props.active_window
if not win:
win = GemGraphWindow(application=self)
# Open file
pass
# Display run mode by default
win.stack_switch_mode("run")
win.present()
def on_about_action(self, widget, _): def on_about_action(self, widget, _):
"""Callback for the app.about action.""" """Callback for the app.about action."""
about = AboutDialog(self.props.active_window) about = AboutDialog(self.props.active_window)
@ -63,6 +82,8 @@ class GemGraphApplication(Adw.Application):
def on_preferences_action(self, widget, _): def on_preferences_action(self, widget, _):
"""Callback for the app.preferences action.""" """Callback for the app.preferences action."""
print('app.preferences action activated') print('app.preferences action activated')
win = self.props.active_window
win.send_toast("Not implemented at this time (sorry!)")
def on_editmode_action(self, widget, _): def on_editmode_action(self, widget, _):
"""Callback for the app.editmode action.""" """Callback for the app.editmode action."""

View File

@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk from gi.repository import Gtk, Adw
@Gtk.Template(filename='ui/gemgraph.ui') @Gtk.Template(filename='ui/gemgraph.ui')
@ -31,6 +31,7 @@ class GemGraphWindow(Gtk.ApplicationWindow):
side_stack = Gtk.Template.Child() side_stack = Gtk.Template.Child()
main_paned = Gtk.Template.Child() main_paned = Gtk.Template.Child()
main_button_mode = Gtk.Template.Child() main_button_mode = Gtk.Template.Child()
toast_overlay = Gtk.Template.Child()
__mode_icon = { __mode_icon = {
"mode_edit":"document-edit-symbolic" , "mode_edit":"document-edit-symbolic" ,
@ -50,7 +51,7 @@ class GemGraphWindow(Gtk.ApplicationWindow):
if position != 0: if position != 0:
self.main_paned.set_position(0) self.main_paned.set_position(0)
else: else:
self.main_paned.set_position(250) self.main_paned.set_position(300)
def stack_switch_mode(self, mode): def stack_switch_mode(self, mode):
""" """
@ -60,6 +61,9 @@ class GemGraphWindow(Gtk.ApplicationWindow):
self.side_stack.set_visible_child_full("side_"+mode, Gtk.StackTransitionType.CROSSFADE) self.side_stack.set_visible_child_full("side_"+mode, Gtk.StackTransitionType.CROSSFADE)
self.main_button_mode.props.icon_name = self.__mode_icon["mode_"+mode] self.main_button_mode.props.icon_name = self.__mode_icon["mode_"+mode]
def send_toast(self, message):
self.toast_overlay.add_toast(Adw.Toast(title=message))
class AboutDialog(Gtk.AboutDialog): class AboutDialog(Gtk.AboutDialog):
def __init__(self, parent): def __init__(self, parent):

View File

@ -43,93 +43,111 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkPaned" id="main_paned"> <object class="AdwToastOverlay" id="toast_overlay">
<property name="position">250</property> <property name="child">
<child> <object class="GtkPaned" id="main_paned">
<object class="GtkStack" id="side_stack"> <property name="position">300</property>
<child> <child>
<object class="GtkStackPage"> <object class="GtkStack" id="side_stack">
<property name="name">side_run</property> <child>
<property name="child"> <object class="GtkStackPage">
<object class="GtkLabel" id="labelsiderun"> <property name="name">side_run</property>
<property name="justify">center</property> <property name="child">
<property name="label" translatable="yes">&lt;b&gt;Sidebar: run mode&lt;/b&gt;</property> <object class="GtkLabel" id="labelsiderun">
<property name="use-markup">True</property> <property name="justify">center</property>
<property name="label" translatable="yes">&lt;b&gt;Sidebar: run mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object> </object>
</property> </child>
<child>
<object class="GtkStackPage">
<property name="name">side_presentation</property>
<property name="child">
<object class="GtkLabel" id="labelsidepresentation">
<property name="justify">center</property>
<property name="label" translatable="yes">&lt;b&gt;Sidebar: presentation mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">side_edit</property>
<property name="child">
<object class="GtkLabel" id="labelsideedit">
<property name="justify">center</property>
<property name="label" translatable="yes">&lt;b&gt;Sidebar: edit mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object>
</child>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkStackPage"> <object class="GtkStack" id="main_stack">
<property name="name">side_presentation</property> <child>
<property name="child"> <object class="GtkStackPage">
<object class="GtkLabel" id="labelsidepresentation"> <property name="name">main_run</property>
<property name="justify">center</property> <property name="child">
<property name="label" translatable="yes">&lt;b&gt;Sidebar: presentation mode&lt;/b&gt;</property> <object class="GtkLabel">
<property name="use-markup">True</property> <property name="halign">center</property>
<property name="label" translatable="yes">&lt;b&gt;Main zone: run mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object> </object>
</property> </child>
</object> <child>
</child> <object class="GtkStackPage">
<child> <property name="name">main_presentation</property>
<object class="GtkStackPage"> <property name="child">
<property name="name">side_edit</property> <object class="GtkLabel">
<property name="child"> <property name="halign">center</property>
<object class="GtkLabel" id="labelsideedit"> <property name="label" translatable="yes">&lt;b&gt;Main zone: presentation mode&lt;/b&gt;</property>
<property name="justify">center</property> <property name="use-markup">True</property>
<property name="label" translatable="yes">&lt;b&gt;Sidebar: edit mode&lt;/b&gt;</property> </object>
<property name="use-markup">True</property> </property>
</object> </object>
</property> </child>
<child>
<object class="GtkStackPage">
<property name="name">main_edit</property>
<property name="child">
<object class="GtkLabel">
<property name="halign">center</property>
<property name="label" translatable="yes">&lt;b&gt;Main zone: edit mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>
</child> </property>
<child> </object>
<object class="GtkStack" id="main_stack">
<child>
<object class="GtkStackPage">
<property name="name">main_run</property>
<property name="child">
<object class="GtkLabel">
<property name="halign">center</property>
<property name="label" translatable="yes">&lt;b&gt;Main zone: run mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">main_presentation</property>
<property name="child">
<object class="GtkLabel">
<property name="halign">center</property>
<property name="label" translatable="yes">&lt;b&gt;Main zone: presentation mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">main_edit</property>
<property name="child">
<object class="GtkLabel">
<property name="halign">center</property>
<property name="label" translatable="yes">&lt;b&gt;Main zone: edit mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child> </child>
</template> </template>
<menu id="main_menu"> <menu id="main_menu">
<section>
<item>
<attribute name="label" translatable="yes">_Open...</attribute>
<attribute name="action">app.open_file</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Close</attribute>
<attribute name="action">app.close_file</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Save</attribute>
<attribute name="action">app.save_file</attribute>
</item>
</section>
<section> <section>
<item> <item>
<attribute name="label" translatable="yes">_Preferences</attribute> <attribute name="label" translatable="yes">_Preferences</attribute>