more work on gtk & code cleanup
This commit is contained in:
34
Pilz.UI.Gtk/Dialogs/GtkContent.cs
Normal file
34
Pilz.UI.Gtk/Dialogs/GtkContent.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
33
Pilz.UI.Gtk/Dialogs/GtkDialogBase.Statics.cs
Normal file
33
Pilz.UI.Gtk/Dialogs/GtkDialogBase.Statics.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
20
Pilz.UI.Gtk/Dialogs/GtkDialogBase.cs
Normal file
20
Pilz.UI.Gtk/Dialogs/GtkDialogBase.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
65
Pilz.UI.Gtk/Dialogs/GtkDialogBase.glade
Normal file
65
Pilz.UI.Gtk/Dialogs/GtkDialogBase.glade
Normal 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>
|
||||
@@ -11,6 +11,14 @@
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="**\*.glade" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="**\*.glade" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GtkSharp" Version="3.24.24.95" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class GtkSymbolFactory<TSymbols> : BaseSymbolFactory<TSymbols>,
|
||||
pixbuf = new(stream);
|
||||
else
|
||||
pixbuf = new(stream, size.Width, size.Height);
|
||||
|
||||
|
||||
return GetImageFromPixbuf(pixbuf);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user