Skip to content

Commit 1afbd31

Browse files
committed
Port the dock and canvas to the new subclass init style.
1 parent 4d1ad3c commit 1afbd31

11 files changed

Lines changed: 154 additions & 132 deletions

File tree

Pinta.Docking/Dock.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//
1+
//
22
// Author:
33
// Cameron White <cameronwhite91@gmail.com>
4-
//
4+
//
55
// Copyright (c) 2020 Cameron White
6-
//
6+
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
99
// in the Software without restriction, including without limitation the rights
1010
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
// copies of the Software, and to permit persons to whom the Software is
1212
// furnished to do so, subject to the following conditions:
13-
//
13+
//
1414
// The above copyright notice and this permission notice shall be included in
1515
// all copies or substantial portions of the Software.
16-
//
16+
//
1717
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -22,22 +22,25 @@
2222
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
// THE SOFTWARE.
2424

25+
using System.Diagnostics.CodeAnalysis;
2526
using Pinta.Core;
2627

2728
namespace Pinta.Docking;
2829

2930
/// <summary>
3031
/// The root widget, containing all dock items underneath it.
3132
/// </summary>
32-
public sealed class Dock : Gtk.Box
33+
[GObject.Subclass<Gtk.Box>]
34+
public sealed partial class Dock
3335
{
34-
private readonly Gtk.Paned pane;
36+
private Gtk.Paned pane;
3537

36-
public DockPanel RightPanel { get; } = new ();
38+
public DockPanel RightPanel { get; } = DockPanel.New ();
3739

38-
public Dock ()
40+
[MemberNotNull (nameof (pane))]
41+
partial void Initialize ()
3942
{
40-
Gtk.Paned pane = Gtk.Paned.New (Gtk.Orientation.Horizontal);
43+
pane = Gtk.Paned.New (Gtk.Orientation.Horizontal);
4144
pane.EndChild = RightPanel;
4245
pane.ResizeEndChild = false;
4346
pane.ShrinkEndChild = false;
@@ -46,12 +49,10 @@ public Dock ()
4649

4750
SetOrientation (Gtk.Orientation.Horizontal);
4851
Append (pane);
49-
50-
// --- References to keep
51-
52-
this.pane = pane;
5352
}
5453

54+
public static Dock New () => NewWithProperties ([]);
55+
5556
public void AddItem (DockItem item, DockPlacement placement)
5657
{
5758
switch (placement) {

Pinta.Docking/DockItem.cs

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//
1+
//
22
// Author:
33
// Cameron White <cameronwhite91@gmail.com>
4-
//
4+
//
55
// Copyright (c) 2020 Cameron White
6-
//
6+
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
99
// in the Software without restriction, including without limitation the rights
1010
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
// copies of the Software, and to permit persons to whom the Software is
1212
// furnished to do so, subject to the following conditions:
13-
//
13+
//
1414
// The above copyright notice and this permission notice shall be included in
1515
// all copies or substantial portions of the Software.
16-
//
16+
//
1717
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -23,6 +23,7 @@
2323
// THE SOFTWARE.
2424

2525
using System;
26+
using System.Diagnostics.CodeAnalysis;
2627
using Pinta.Core;
2728
using Pinta.Resources;
2829

@@ -32,22 +33,23 @@ namespace Pinta.Docking;
3233
/// A dock item contains a single child widget, and can be docked at
3334
/// various locations.
3435
/// </summary>
35-
public sealed class DockItem : Gtk.Box
36+
[GObject.Subclass<Gtk.Box>]
37+
public sealed partial class DockItem
3638
{
37-
private readonly Gtk.Label label_widget;
38-
private readonly Gtk.Stack button_stack;
39-
private readonly Gtk.Button minimize_button;
40-
private readonly Gtk.Button maximize_button;
39+
private Gtk.Label label_widget;
40+
private Gtk.Stack button_stack;
41+
private Gtk.Button minimize_button;
42+
private Gtk.Button maximize_button;
4143

4244
/// <summary>
4345
/// Unique identifier for the dock item. Used e.g. when saving the dock layout to disk.
4446
/// </summary>
45-
public string UniqueName { get; }
47+
public string UniqueName { get; private set; } = string.Empty;
4648

4749
/// <summary>
4850
/// Icon name for the dock item, used when minimized.
4951
/// </summary>
50-
public string IconName { get; }
52+
public string IconName { get; private set; } = string.Empty;
5153

5254
/// <summary>
5355
/// Visible label for the dock item.
@@ -67,82 +69,87 @@ public string Label {
6769
/// </summary>
6870
public event EventHandler? MaximizeClicked;
6971

70-
public DockItem (
71-
Gtk.Widget child,
72-
string uniqueName,
73-
string iconName,
74-
bool locked = false)
72+
[MemberNotNull (nameof (label_widget))]
73+
[MemberNotNull (nameof (button_stack))]
74+
[MemberNotNull (nameof (minimize_button))]
75+
[MemberNotNull (nameof (maximize_button))]
76+
partial void Initialize ()
7577
{
76-
Gtk.Button minimizeButton = CreateMinimizeButton (locked);
77-
Gtk.Button maximizeButton = CreateMaximizeButton (locked);
78+
Gtk.Button minimizeButton = CreateMinimizeButton ();
79+
Gtk.Button maximizeButton = CreateMaximizeButton ();
7880

7981
Gtk.Stack buttonStack = Gtk.Stack.New ();
8082
buttonStack.AddChild (minimizeButton);
8183
buttonStack.AddChild (maximizeButton);
8284

83-
Gtk.Label labelWidget = CreateLabelWidget (locked);
85+
Gtk.Label labelWidget = CreateLabelWidget ();
8486

8587
// --- Initialization (Gtk.Box)
8688

8789
SetOrientation (Gtk.Orientation.Vertical);
8890

89-
// --- Initialization
91+
// TODO - support dragging into floating panel?
9092

91-
UniqueName = uniqueName;
92-
IconName = iconName;
93+
// --- References to keep
9394

94-
child.Valign = Gtk.Align.Fill;
95-
child.Vexpand = true;
95+
minimize_button = minimizeButton;
96+
maximize_button = maximizeButton;
9697

97-
if (!locked) {
98+
button_stack = buttonStack;
9899

99-
Gtk.Box titleLayout = GtkExtensions.BoxHorizontal ([
100-
labelWidget,
101-
buttonStack]);
100+
label_widget = labelWidget;
101+
}
102102

103-
Append (titleLayout);
104-
}
103+
public static DockItem New (
104+
Gtk.Widget child,
105+
string uniqueName,
106+
string iconName,
107+
bool locked = false)
108+
{
109+
DockItem item = NewWithProperties ([]);
105110

106-
Append (child);
111+
item.UniqueName = uniqueName;
112+
item.IconName = iconName;
107113

108-
// TODO - support dragging into floating panel?
114+
if (!locked) {
115+
item.minimize_button.OnClicked += (o, args) => item.Minimize ();
116+
item.maximize_button.OnClicked += (o, args) => item.Maximize ();
109117

110-
// --- References to keep
118+
const int padding = 8;
119+
item.label_widget.MarginStart = item.label_widget.MarginEnd = padding;
120+
item.label_widget.Hexpand = true;
121+
item.label_widget.Halign = Gtk.Align.Start;
111122

112-
minimize_button = minimizeButton;
113-
maximize_button = maximizeButton;
123+
Gtk.Box titleLayout = GtkExtensions.BoxHorizontal ([
124+
item.label_widget,
125+
item.button_stack]);
114126

115-
button_stack = buttonStack;
127+
item.Append (titleLayout);
128+
}
116129

117-
label_widget = labelWidget;
130+
child.Valign = Gtk.Align.Fill;
131+
child.Vexpand = true;
132+
item.Append (child);
133+
134+
return item;
118135
}
119136

120-
private Gtk.Button CreateMinimizeButton (bool locked)
137+
private Gtk.Button CreateMinimizeButton ()
121138
{
122139
Gtk.Button result = Gtk.Button.NewFromIconName (StandardIcons.WindowMinimize);
123140
result.AddCssClass (AdwaitaStyles.Flat);
124-
125-
if (!locked)
126-
result.OnClicked += (o, args) => Minimize ();
127-
128141
return result;
129142
}
130143

131-
private Gtk.Button CreateMaximizeButton (bool locked)
144+
private Gtk.Button CreateMaximizeButton ()
132145
{
133146
Gtk.Button result = Gtk.Button.NewFromIconName (StandardIcons.WindowMaximize);
134147
result.AddCssClass (AdwaitaStyles.Flat);
135-
if (!locked)
136-
result.OnClicked += (o, args) => Maximize ();
137-
138148
return result;
139149
}
140150

141-
private static Gtk.Label CreateLabelWidget (bool locked)
151+
private static Gtk.Label CreateLabelWidget ()
142152
{
143-
if (locked)
144-
return Gtk.Label.New (null);
145-
146153
const int padding = 8;
147154

148155
Gtk.Label result = Gtk.Label.New (null);

Pinta.Docking/DockNotebook.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//
1+
//
22
// Author:
33
// Cameron White <cameronwhite91@gmail.com>
4-
//
4+
//
55
// Copyright (c) 2020 Cameron White
6-
//
6+
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
99
// in the Software without restriction, including without limitation the rights
1010
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
// copies of the Software, and to permit persons to whom the Software is
1212
// furnished to do so, subject to the following conditions:
13-
//
13+
//
1414
// The above copyright notice and this permission notice shall be included in
1515
// all copies or substantial portions of the Software.
16-
//
16+
//
1717
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -25,6 +25,7 @@
2525
using System;
2626
using System.Collections.Generic;
2727
using System.ComponentModel;
28+
using System.Diagnostics.CodeAnalysis;
2829
using System.Linq;
2930
using Pinta.Core;
3031

@@ -40,13 +41,16 @@ public sealed class TabEventArgs (IDockNotebookItem? item) : EventArgs
4041
public IDockNotebookItem? Item { get; } = item;
4142
}
4243

43-
public sealed class DockNotebook : Gtk.Box
44+
[GObject.Subclass<Gtk.Box>]
45+
public sealed partial class DockNotebook
4446
{
45-
private readonly Adw.TabView tab_view;
46-
private readonly Adw.TabBar tab_bar;
47+
private Adw.TabView tab_view;
48+
private Adw.TabBar tab_bar;
4749
private readonly HashSet<IDockNotebookItem> items = [];
4850

49-
public DockNotebook ()
51+
[MemberNotNull (nameof (tab_view))]
52+
[MemberNotNull (nameof (tab_bar))]
53+
partial void Initialize ()
5054
{
5155
Adw.TabView tabView = Adw.TabView.New ();
5256
tabView.Vexpand = true;
@@ -77,6 +81,8 @@ public DockNotebook ()
7781
Adw.TabView.SelectedPagePropertyDefinition.Notify (tabView, TabView_TabChanged);
7882
}
7983

84+
public static DockNotebook New () => NewWithProperties ([]);
85+
8086
private void TabView_TabChanged (GObject.Object _, NotifySignalArgs __)
8187
{
8288
Adw.TabPage? page = tab_view.SelectedPage;

Pinta.Docking/DockPanel.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//
1+
//
22
// Author:
33
// Cameron White <cameronwhite91@gmail.com>
4-
//
4+
//
55
// Copyright (c) 2020 Cameron White
6-
//
6+
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
99
// in the Software without restriction, including without limitation the rights
1010
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
// copies of the Software, and to permit persons to whom the Software is
1212
// furnished to do so, subject to the following conditions:
13-
//
13+
//
1414
// The above copyright notice and this permission notice shall be included in
1515
// all copies or substantial portions of the Software.
16-
//
16+
//
1717
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -29,7 +29,8 @@
2929

3030
namespace Pinta.Docking;
3131

32-
public sealed class DockPanel : Gtk.Box
32+
[GObject.Subclass<Gtk.Box>]
33+
public sealed partial class DockPanel
3334
{
3435
internal sealed class DockPanelItem
3536
{
@@ -108,12 +109,14 @@ public void UpdateOnMinimize (Gtk.Box dock_bar)
108109
/// </summary>
109110
private readonly List<DockPanelItem> items = [];
110111

111-
public DockPanel ()
112+
partial void Initialize ()
112113
{
113114
SetOrientation (Gtk.Orientation.Horizontal);
114115
Append (dock_bar);
115116
}
116117

118+
public static DockPanel New () => NewWithProperties ([]);
119+
117120
public void AddItem (DockItem item)
118121
{
119122
DockPanelItem panelItem = new (item);

Pinta.Docking/Pinta.Docking.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4+
</PropertyGroup>
5+
26
<Import Project="../properties/ReferenceGirCoreAdw1.props" />
37

48
<ItemGroup>

0 commit comments

Comments
 (0)