more work on gtk & code cleanup

This commit is contained in:
2025-06-16 15:30:56 +02:00
parent 6f7bb5d92c
commit a49a3b2beb
69 changed files with 374 additions and 268 deletions

View File

@@ -0,0 +1,34 @@
using Gtk;
namespace Pilz.UI.Gtk.Dialogs;
public class GtkContent : Box
{
public GtkDialogBase Dialog { get; internal set; } = null!;
public ResponseType Result { get; set; } = ResponseType.Cancel;
public bool RegisterDialogAccept { get; set; } = true;
public bool RegisterDialogCancel { get; set; } = true;
protected void Close(ResponseType result)
{
Result = result;
Dialog.Destroy();
}
protected virtual bool ValidateOK()
{
return true;
}
protected virtual void Button_Confirm_Clicked(object? sender, EventArgs e)
{
if (ValidateOK())
Close(ResponseType.Ok);
}
protected virtual void Button_Cancel_Clicked(object? sender, EventArgs e)
{
Close(ResponseType.Cancel);
}
}

View File

@@ -0,0 +1,33 @@
using Gtk;
namespace Pilz.UI.Gtk.Dialogs;
public partial class GtkDialogBase
{
private static GtkDialogBase CreateDialog<TContent>(TContent content, string title) where TContent : Widget
{
var dialog = new GtkDialogBase
{
Title = title,
};
dialog.ContentArea.Add(content);
content.Show();
return dialog;
}
public static TContent Show<TContent>(TContent content, string title) where TContent : Widget
{
var dialog = CreateDialog(content, title);
dialog.Show();
dialog.Destroy();
return content;
}
public static TContent ShowDialog<TContent>(TContent content, string title) where TContent : Widget
{
var dialog = CreateDialog(content, title);
dialog.Run();
dialog.Destroy();
return content;
}
}

View File

@@ -0,0 +1,20 @@
using Gtk;
namespace Pilz.UI.Gtk.Dialogs;
public partial class GtkDialogBase : Dialog
{
public GtkDialogBase() : this(new Builder("GtkDialogBase.glade")) { }
private GtkDialogBase(Builder builder) : base(builder.GetRawOwnedObject("GtkDialogBase"))
{
builder.Autoconnect(this);
DefaultResponse = ResponseType.Cancel;
Response += Dialog_Response;
}
protected virtual void Dialog_Response(object o, ResponseArgs args)
{
Hide();
}
}

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.18"/>
<object class="GtkDialog" id="GtkDialogBase">
<property name="can-focus">False</property>
<property name="window-position">center-on-parent</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="buttonOkay">
<property name="label">gtk-apply</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="buttonCancel">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-5">buttonOkay</action-widget>
<action-widget response="-6">buttonCancel</action-widget>
</action-widgets>
</object>
</interface>