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
2323// THE SOFTWARE.
2424
2525using System ;
26+ using System . Diagnostics . CodeAnalysis ;
2627using Pinta . Core ;
2728using 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 ) ;
0 commit comments