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
necessary.
"""
print("app.do_activate called")
win = self.props.active_window
if not win:
win = GemGraphWindow(application=self)
@ -55,6 +56,24 @@ class GemGraphApplication(Adw.Application):
win.stack_switch_mode("run")
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, _):
"""Callback for the app.about action."""
about = AboutDialog(self.props.active_window)
@ -63,6 +82,8 @@ class GemGraphApplication(Adw.Application):
def on_preferences_action(self, widget, _):
"""Callback for the app.preferences action."""
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, _):
"""Callback for the app.editmode action."""

View File

@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# 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')
@ -31,6 +31,7 @@ class GemGraphWindow(Gtk.ApplicationWindow):
side_stack = Gtk.Template.Child()
main_paned = Gtk.Template.Child()
main_button_mode = Gtk.Template.Child()
toast_overlay = Gtk.Template.Child()
__mode_icon = {
"mode_edit":"document-edit-symbolic" ,
@ -50,7 +51,7 @@ class GemGraphWindow(Gtk.ApplicationWindow):
if position != 0:
self.main_paned.set_position(0)
else:
self.main_paned.set_position(250)
self.main_paned.set_position(300)
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.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):
def __init__(self, parent):

View File

@ -43,93 +43,111 @@
</object>
</child>
<child>
<object class="GtkPaned" id="main_paned">
<property name="position">250</property>
<child>
<object class="GtkStack" id="side_stack">
<object class="AdwToastOverlay" id="toast_overlay">
<property name="child">
<object class="GtkPaned" id="main_paned">
<property name="position">300</property>
<child>
<object class="GtkStackPage">
<property name="name">side_run</property>
<property name="child">
<object class="GtkLabel" id="labelsiderun">
<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 class="GtkStack" id="side_stack">
<child>
<object class="GtkStackPage">
<property name="name">side_run</property>
<property name="child">
<object class="GtkLabel" id="labelsiderun">
<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>
</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>
</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 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>
</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>
</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>
</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>
</child>
</object>
</child>
<child>
<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>
</property>
</object>
</child>
</template>
<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>
<item>
<attribute name="label" translatable="yes">_Preferences</attribute>