Skip to content

Commit

Permalink
A ton of minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lainsce committed Oct 1, 2023
1 parent 1ce807d commit 4c3eeb1
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 29 deletions.
1 change: 0 additions & 1 deletion data/com.fyralabs.Enigma.gresources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<file alias="style-dark.css">style-dark.css</file>

<file alias="main_window.ui">ui/main_window.ui</file>
<file alias="menu.ui">ui/menu.ui</file>
<file alias="prefs.ui">ui/prefs.ui</file>
<file alias="sidebar.ui">ui/sidebar.ui</file>
<file alias="docrow.ui">ui/docrow.ui</file>
Expand Down
13 changes: 13 additions & 0 deletions data/ui/contentview.ui
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<menu id="menu">
<section>
<item>
<attribute name="label" translatable="true">Settings…</attribute>
<attribute name="action">win.action_prefs</attribute>
</item>
<item>
<attribute name="label" translatable="true">About Enigma</attribute>
<attribute name="action">win.action_about</attribute>
</item>
</section>
</menu>
<template class="EnigmaContentView" parent="HeBin">
<property name="hexpand">true</property>
<child>
Expand All @@ -13,6 +25,7 @@
<child>
<object class="GtkMenuButton" id="menu_button">
<property name="icon-name">open-menu-symbolic</property>
<property name="menu-model">menu</property>
</object>
</child>
<child>
Expand Down
3 changes: 3 additions & 0 deletions data/ui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
<binding name="vm">
<lookup name="view-model">EnigmaMainWindow</lookup>
</binding>
<binding name="app">
<lookup name="app">EnigmaMainWindow</lookup>
</binding>
</object>
</child>
</object>
Expand Down
16 changes: 0 additions & 16 deletions data/ui/menu.ui

This file was deleted.

10 changes: 9 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ namespace Enigma {

[GtkChild]
public unowned Sidebar sidebar;
[GtkChild]
public unowned ContentView doccontent;

public SimpleActionGroup actions { get; construct; }
public const string ACTION_PREFIX = "win.";
public const string ACTION_ABOUT = "action_about";
public const string ACTION_PREFS = "action_prefs";
public const string ACTION_SAVE = "action_save";
public static Gee.MultiMap<string, string> action_accelerators = new Gee.HashMultiMap<string, string> ();

private const GLib.ActionEntry[] ACTION_ENTRIES = {
{ ACTION_ABOUT, action_about },
{ ACTION_PREFS, action_prefs },
{ ACTION_SAVE, action_save },
};

// Custom
Expand Down Expand Up @@ -66,7 +70,8 @@ namespace Enigma {

app.set_accels_for_action (ACTION_PREFIX + action, accels_array);
}
app.set_accels_for_action("app.quit", {"<Ctrl>q"});
app.set_accels_for_action ("app.quit", {"<Ctrl>q"});
app.set_accels_for_action ("win.action_save", {"<Ctrl>s"});

var theme = Gtk.IconTheme.get_for_display (Gdk.Display.get_default ());
theme.add_resource_path ("/com/fyralabs/Enigma/");
Expand Down Expand Up @@ -111,6 +116,9 @@ namespace Enigma {
settings.parent = this;
settings.present ();
}
public void action_save () {
doccontent.save.begin ();
}

public void load (GLib.File file) {
uint8[] t;
Expand Down
6 changes: 4 additions & 2 deletions src/Utils/MiscUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/
namespace Enigma.Utils {
public unowned MainWindow win;
public async File? display_open_dialog () {
public async File? display_open_dialog (Gtk.Window? win) {
var dialog = new Gtk.FileChooserNative (null, win, Gtk.FileChooserAction.OPEN, null, null);
dialog.set_transient_for(win);
dialog.modal = true;
var filter1 = new Gtk.FileFilter ();
filter1.set_filter_name (_("Text files"));
filter1.add_pattern ("*.txt");
Expand All @@ -39,9 +40,10 @@ namespace Enigma.Utils {
return null;
}

public async File? display_save_dialog () {
public async File? display_save_dialog (Gtk.Window? win) {
var dialog = new Gtk.FileChooserNative (null, win, Gtk.FileChooserAction.SAVE, null, null);
dialog.set_transient_for(win);
dialog.modal = true;
var filter1 = new Gtk.FileFilter ();
filter1.set_filter_name (_("Text files"));
filter1.add_pattern ("*.txt");
Expand Down
15 changes: 6 additions & 9 deletions src/Views/ContentView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class Enigma.ContentView : He.Bin {
[GtkChild]
public unowned Gtk.SearchEntry search_entry;
[GtkChild]
unowned Gtk.MenuButton menu_button;
[GtkChild]
unowned Gtk.Button open_button;
[GtkChild]
unowned Gtk.Button save_as_button;
Expand All @@ -44,6 +42,7 @@ public class Enigma.ContentView : He.Bin {

private GtkSource.VimIMContext? vim_im_context;
private Gtk.EventControllerKey? vim_event_controller;
public He.Application app { get; construct set; }

Doc? _doc;
public Doc? doc {
Expand Down Expand Up @@ -106,16 +105,14 @@ public class Enigma.ContentView : He.Bin {
}
}

public ContentView (DocViewModel? vm) {
public ContentView (DocViewModel? vm, He.Application app) {
Object (
vm: vm
vm: vm,
app: app
);
}

construct {
var builder = new Gtk.Builder.from_resource ("/com/fyralabs/Enigma/menu.ui");
menu_button.menu_model = (MenuModel)builder.get_object ("menu");

open_button.clicked.connect (() => { open.begin (); });
save_as_button.clicked.connect (() => { save.begin (); });

Expand Down Expand Up @@ -143,7 +140,7 @@ public class Enigma.ContentView : He.Bin {
}

public async void open () {
var file = yield Utils.display_open_dialog ();
var file = yield Utils.display_open_dialog (app.active_window);
uint8[] t;
try {
file.load_contents (null, out t, null);
Expand All @@ -170,7 +167,7 @@ public class Enigma.ContentView : He.Bin {
}

public async void save () {
var file = yield Utils.display_save_dialog ();
var file = yield Utils.display_save_dialog (app.active_window);
Gtk.TextIter start, end;
textbox.get_buffer ().get_bounds (out start, out end);
try {
Expand Down

0 comments on commit 4c3eeb1

Please sign in to comment.