This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
using System;
using System.Collections;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Drawing;
namespace DTS.Common.Utilities
{
public class PersistWindowState : System.ComponentModel.Component
{
// event info that allows form to persist extra window state data
public delegate void WindowStateDelegate(object sender, RegistryKey key);
public event WindowStateDelegate LoadStateEvent;
public event WindowStateDelegate SaveStateEvent;
private Form m_parent;
private string m_regPath;
private int m_normalLeft;
private int m_normalTop;
private int m_normalWidth;
private int m_normalHeight;
private FormWindowState m_windowState;
private bool m_allowSaveMinimized = false;
private bool m_startMaximized = false;
public PersistWindowState()
{
}
public Form Parent
{
set
{
m_parent = value;
// subscribe to parent form's events
m_parent.Closing += new System.ComponentModel.CancelEventHandler(OnClosing);
m_parent.Resize += new System.EventHandler(OnResize);
m_parent.Move += new System.EventHandler(OnMove);
m_parent.Load += new System.EventHandler(OnLoad);
// get initial width and height in case form is never resized
m_normalWidth = m_parent.Width;
m_normalHeight = m_parent.Height;
}
get => m_parent;
}
// registry key should be set in parent form's constructor
public string RegistryPath
{
set => m_regPath = value;
get => m_regPath;
}
public bool AllowSaveMinimized
{
set => m_allowSaveMinimized = value;
}
public bool StartMaximized
{
set => m_startMaximized = value;
}
private void OnResize(object sender, System.EventArgs e)
{
// save width and height
if (m_parent.WindowState == FormWindowState.Normal)
{
m_normalWidth = m_parent.Width;
m_normalHeight = m_parent.Height;
}
}
private void OnMove(object sender, System.EventArgs e)
{
// save position
if (m_parent.WindowState == FormWindowState.Normal)
{
m_normalLeft = m_parent.Left;
m_normalTop = m_parent.Top;
}
// save state
m_windowState = m_parent.WindowState;
}
private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
// save position, size and state
var key = Registry.CurrentUser.CreateSubKey(m_regPath);
key.SetValue("Left", m_normalLeft);
key.SetValue("Top", m_normalTop);
key.SetValue("Width", m_normalWidth);
key.SetValue("Height", m_normalHeight);
// check if we are allowed to save the state as minimized (not normally)
if (!m_allowSaveMinimized)
{
if (m_windowState == FormWindowState.Minimized)
m_windowState = FormWindowState.Normal;
}
key.SetValue("WindowState", (int)m_windowState);
// fire SaveState event
if (SaveStateEvent != null)
SaveStateEvent(this, key);
}
private void OnLoad(object sender, System.EventArgs e)
{
// attempt to read state from registry
var key = Registry.CurrentUser.OpenSubKey(m_regPath);
if (key != null)
{
var left = (int)key.GetValue("Left", m_parent.Left);
var top = (int)key.GetValue("Top", m_parent.Top);
var width = (int)key.GetValue("Width", m_parent.Width);
var height = (int)key.GetValue("Height", m_parent.Height);
var windowState = new FormWindowState();
if (m_startMaximized == true)
{
windowState = FormWindowState.Maximized;
}
else
{
windowState = (FormWindowState)key.GetValue("WindowState", (int)m_parent.WindowState);
}
if (Screen.AllScreens.Length == 1)
{
//There is only 1 monitor, so disregard what was in the registry
//to ensure that the window is not displayed on a non-existent monitor
m_parent.Location = new Point(100, 100);
}
else
{
m_parent.Location = new Point(left, top);
}
m_parent.Size = new Size(width, height);
m_parent.WindowState = windowState;
// fire LoadState event
if (LoadStateEvent != null)
LoadStateEvent(this, key);
}
}
}
}

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace DTS.Common.Utilities
{
public class SortableBindingList<T> : BindingList<T>
{
private readonly Dictionary<Type, PropertyComparer<T>> _comparers;
private bool _isSorted;
private ListSortDirection _listSortDirection;
private PropertyDescriptor _propertyDescriptor;
public SortableBindingList()
: base(new List<T>())
{
_comparers = new Dictionary<Type, PropertyComparer<T>>();
}
public SortableBindingList(IEnumerable<T> enumeration)
: base(new List<T>(enumeration))
{
_comparers = new Dictionary<Type, PropertyComparer<T>>();
}
protected override bool SupportsSortingCore => true;
protected override bool IsSortedCore => _isSorted;
protected override PropertyDescriptor SortPropertyCore => _propertyDescriptor;
protected override ListSortDirection SortDirectionCore => _listSortDirection;
protected override bool SupportsSearchingCore => true;
protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
{
var itemsList = (List<T>)Items;
var propertyType = property.PropertyType;
PropertyComparer<T> comparer;
if (!_comparers.TryGetValue(propertyType, out comparer))
{
comparer = new PropertyComparer<T>(property, direction);
_comparers.Add(propertyType, comparer);
}
comparer.SetPropertyAndDirection(property, direction);
itemsList.Sort(comparer);
_propertyDescriptor = property;
_listSortDirection = direction;
_isSorted = true;
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
protected override void RemoveSortCore()
{
_isSorted = false;
_propertyDescriptor = base.SortPropertyCore;
_listSortDirection = base.SortDirectionCore;
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
protected override int FindCore(PropertyDescriptor property, object key)
{
var count = Count;
for (var i = 0; i < count; ++i)
{
var element = this[i];
var value = property.GetValue(element);
if (value != null && value.Equals(key))
return i;
}
return -1;
}
}
}