/* * GNU AFFERO GENERAL PUBLIC LICENSE * Version 3, 19 November 2007 * Copyright (C) 2007 Free Software Foundation, Inc. * Everyone is permitted to copy and distribute verbatim copies * of this license document, but changing it is not allowed. */ using System.ComponentModel; using System.Drawing.Design; using System.Runtime.CompilerServices; using System.Windows.Forms; using UVtools.Core.Extensions; using UVtools.GUI.Annotations; namespace UVtools.GUI.Controls { public partial class CtrlToolWindowContent : UserControl, INotifyPropertyChanged { #region BindableBase /// /// Multicast event for property change notifications. /// public event PropertyChangedEventHandler PropertyChanged; /// /// Checks if a property already matches a desired value. Sets the property and /// notifies listeners only when necessary. /// /// Type of the property. /// Reference to a property with both getter and setter. /// Desired value for the property. /// /// Name of the property used to notify listeners. This /// value is optional and can be provided automatically when invoked from compilers that /// support CallerMemberName. /// /// /// True if the value was changed, false if the existing value matched the /// desired value. /// [NotifyPropertyChangedInvocator] protected bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null) { if (Equals(storage, value)) { return false; } storage = value; OnPropertyChanged(propertyName); return true; } /// /// Notifies listeners that a property value has changed. /// /// /// Name of the property used to notify listeners. This /// value is optional and can be provided automatically when invoked from compilers /// that support . /// [NotifyPropertyChangedInvocator] protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { var eventHandler = PropertyChanged; if (!ReferenceEquals(eventHandler, null)) { eventHandler(this, new PropertyChangedEventArgs(propertyName)); } } #endregion #region Properties [Editor("System.ComponentModel.Design.MultilineStringEditor", typeof(UITypeEditor))] [SettingsBindable(true)] public string Description { get; set; } private bool _buttonOkEnabled; [SettingsBindable(true)] public bool ButtonOkEnabled { get => _buttonOkEnabled; set => SetProperty(ref _buttonOkEnabled, value); } [Editor("System.ComponentModel.Design.MultilineStringEditor", typeof(UITypeEditor))] [SettingsBindable(true)] public string ButtonOkText { get; set; } = "Ok"; [Editor("System.ComponentModel.Design.MultilineStringEditor", typeof(UITypeEditor))] [SettingsBindable(true)] public string ButtonCancelText { get; set; } = "Cancel"; [SettingsBindable(true)] public bool LayerRangeVisible { get; set; } = true; [SettingsBindable(true)] public bool LayerRangeEndVisible { get; set; } = true; /*[SettingsBindable(true)] public uint LayerRangeStart { get; set; } [SettingsBindable(true)] public uint LayerRangeEnd { get; set; }*/ [ReadOnly(true)] [Browsable(false)] public virtual string ConfirmationText { get; } = "do this action?"; #endregion #region Constructor public CtrlToolWindowContent() { InitializeComponent(); } #endregion #region Methods public virtual bool ValidateForm() => true; public DialogResult MessageErrorBox(string message, MessageBoxButtons buttons = MessageBoxButtons.OK) => GUIExtensions.MessageErrorBox($"{Text} Error", message, buttons); public DialogResult MessageQuestionBox(string message, string title = null, MessageBoxButtons buttons = MessageBoxButtons.YesNo) => GUIExtensions.MessageQuestionBox($"{title ?? Text}", message, buttons); #endregion } }