Minor refactoring and cleaning

Removed unnecessary comments. Added string interpolation from C# 6.0.
Removed unneeded library references.
This commit is contained in:
Robin 2015-11-30 19:19:23 +00:00
parent a29c055545
commit baaab81736
17 changed files with 30 additions and 47 deletions

View File

@ -40,20 +40,12 @@ namespace DarkUI
{ {
if (!_disposed) if (!_disposed)
{ {
if (disposing)
{
// Release managed resources
}
// Release unmanaged resources.
// Set large fields to null.
if (ItemsAdded != null) if (ItemsAdded != null)
ItemsAdded = null; ItemsAdded = null;
if (ItemsRemoved != null) if (ItemsRemoved != null)
ItemsRemoved = null; ItemsRemoved = null;
// Set disposed flag
_disposed = true; _disposed = true;
} }
} }

View File

@ -33,6 +33,7 @@ namespace DarkUI
Invalidate(); Invalidate();
} }
} }
public new bool Enabled public new bool Enabled
{ {
get { return base.Enabled; } get { return base.Enabled; }

View File

@ -208,7 +208,7 @@ namespace DarkUI
public void SelectItem(int index) public void SelectItem(int index)
{ {
if (index < 0 || index > Items.Count - 1) if (index < 0 || index > Items.Count - 1)
throw new IndexOutOfRangeException(string.Format("Value '{0}' is outside of valid range.", index)); throw new IndexOutOfRangeException($"Value '{index}' is outside of valid range.");
_selectedIndices.Clear(); _selectedIndices.Clear();
_selectedIndices.Add(index); _selectedIndices.Add(index);
@ -228,7 +228,7 @@ namespace DarkUI
foreach (var index in list) foreach (var index in list)
{ {
if (index < 0 || index > Items.Count - 1) if (index < 0 || index > Items.Count - 1)
throw new IndexOutOfRangeException(string.Format("Value '{0}' is outside of valid range.", index)); throw new IndexOutOfRangeException($"Value '{index}' is outside of valid range.");
_selectedIndices.Add(index); _selectedIndices.Add(index);
} }
@ -428,7 +428,6 @@ namespace DarkUI
var top = range.Min(); var top = range.Min();
var bottom = range.Max(); var bottom = range.Max();
// Draw items
for (var i = top; i <= bottom; i++) for (var i = top; i <= bottom; i++)
{ {
var width = Math.Max(ContentSize.Width, Viewport.Width); var width = Math.Max(ContentSize.Width, Viewport.Width);
@ -446,7 +445,7 @@ namespace DarkUI
g.FillRectangle(b, rect); g.FillRectangle(b, rect);
} }
// Border // DEBUG: Border
/*using (var p = new Pen(Colors.DarkBorder)) /*using (var p = new Pen(Colors.DarkBorder))
{ {
g.DrawLine(p, new Point(rect.Left, rect.Bottom - 1), new Point(rect.Right, rect.Bottom - 1)); g.DrawLine(p, new Point(rect.Left, rect.Bottom - 1), new Point(rect.Right, rect.Bottom - 1));

View File

@ -205,7 +205,7 @@ namespace DarkUI
if (_trackArea.Contains(e.Location) && e.Button == MouseButtons.Left) if (_trackArea.Contains(e.Location) && e.Button == MouseButtons.Left)
{ {
// Check if our input is at least aligned with the thumb // Step 1. Check if our input is at least aligned with the thumb
if (_scrollOrientation == DarkOrientation.Vertical) if (_scrollOrientation == DarkOrientation.Vertical)
{ {
var modRect = new Rectangle(_thumbArea.Left, _trackArea.Top, _thumbArea.Width, _trackArea.Height); var modRect = new Rectangle(_thumbArea.Left, _trackArea.Top, _thumbArea.Width, _trackArea.Height);
@ -219,7 +219,7 @@ namespace DarkUI
return; return;
} }
// Step 1. Scroll to the area initially clicked. // Step 2. Scroll to the area initially clicked.
if (_scrollOrientation == DarkOrientation.Vertical) if (_scrollOrientation == DarkOrientation.Vertical)
{ {
var loc = e.Location.Y; var loc = e.Location.Y;
@ -235,7 +235,7 @@ namespace DarkUI
ScrollToPhysical(loc); ScrollToPhysical(loc);
} }
// Step 2. Initiate a thumb drag. // Step 3. Initiate a thumb drag.
_isScrolling = true; _isScrolling = true;
_initialContact = e.Location; _initialContact = e.Location;
_thumbHot = true; _thumbHot = true;
@ -246,7 +246,6 @@ namespace DarkUI
_initialValue = _thumbArea.Left; _initialValue = _thumbArea.Left;
Invalidate(); Invalidate();
return; return;
} }
} }

View File

@ -163,13 +163,6 @@ namespace DarkUI
{ {
if (!_disposed) if (!_disposed)
{ {
if (disposing)
{
// Release managed resources
}
// Release unmanaged resources.
// Set large fields to null.
DisposeIcons(); DisposeIcons();
if (SelectedNodesChanged != null) if (SelectedNodesChanged != null)
@ -187,11 +180,9 @@ namespace DarkUI
if (_selectedNodes != null) if (_selectedNodes != null)
_selectedNodes.CollectionChanged -= SelectedNodes_CollectionChanged; _selectedNodes.CollectionChanged -= SelectedNodes_CollectionChanged;
// Set disposed flag
_disposed = true; _disposed = true;
} }
// Call Dispose on your base class.
base.Dispose(disposing); base.Dispose(disposing);
} }
@ -1159,7 +1150,7 @@ namespace DarkUI
if (node == dropNode) if (node == dropNode)
{ {
if (isMoving) if (isMoving)
DarkMessageBox.ShowError(String.Format(@"Cannot move {0}. The destination folder is the same as the source folder.", node.Text), Application.ProductName); DarkMessageBox.ShowError($"Cannot move {node.Text}. The destination folder is the same as the source folder.", Application.ProductName);
return false; return false;
} }
@ -1167,7 +1158,7 @@ namespace DarkUI
if (node.ParentNode != null && node.ParentNode == dropNode) if (node.ParentNode != null && node.ParentNode == dropNode)
{ {
if (isMoving) if (isMoving)
DarkMessageBox.ShowError(String.Format(@"Cannot move {0}. The destination folder is the same as the source folder.", node.Text), Application.ProductName); DarkMessageBox.ShowError($"Cannot move {node.Text}. The destination folder is the same as the source folder.", Application.ProductName);
return false; return false;
} }
@ -1178,7 +1169,7 @@ namespace DarkUI
if (node == parentNode) if (node == parentNode)
{ {
if (isMoving) if (isMoving)
DarkMessageBox.ShowError(String.Format(@"Cannot move {0}. The destination folder is a subfolder of the source folder.", node.Text), Application.ProductName); DarkMessageBox.ShowError($"Cannot move {node.Text}. The destination folder is a subfolder of the source folder.", Application.ProductName);
return false; return false;
} }

View File

@ -7,8 +7,11 @@ namespace DarkUI
#region Property Region #region Property Region
public string Text { get; set; } public string Text { get; set; }
public Rectangle Area { get; set; } public Rectangle Area { get; set; }
public Color TextColor { get; set; } public Color TextColor { get; set; }
public FontStyle FontStyle { get; set; } public FontStyle FontStyle { get; set; }
#endregion #endregion

View File

@ -46,13 +46,17 @@ namespace DarkUI
} }
public Rectangle ExpandArea { get; set; } public Rectangle ExpandArea { get; set; }
public Rectangle IconArea { get; set; } public Rectangle IconArea { get; set; }
public Rectangle TextArea { get; set; } public Rectangle TextArea { get; set; }
public Rectangle FullArea { get; set; } public Rectangle FullArea { get; set; }
public bool ExpandAreaHot { get; set; } public bool ExpandAreaHot { get; set; }
public Bitmap Icon { get; set; } public Bitmap Icon { get; set; }
public Bitmap ExpandedIcon { get; set; } public Bitmap ExpandedIcon { get; set; }
public bool Expanded public bool Expanded

View File

@ -1,7 +1,5 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
namespace DarkUI namespace DarkUI
{ {
@ -12,7 +10,7 @@ namespace DarkUI
var last = items.LastOrDefault(); var last = items.LastOrDefault();
if (last == null) if (last == null)
return false; return false;
return item.Equals(last); // OR Object.ReferenceEquals(last, item) return item.Equals(last);
} }
internal static bool IsFirst<T>(this IEnumerable<T> items, T item) internal static bool IsFirst<T>(this IEnumerable<T> items, T item)

View File

@ -14,9 +14,8 @@ namespace DarkUI
var hControlUnderMouse = Native.WindowFromPoint(new Point((int)m.LParam)); var hControlUnderMouse = Native.WindowFromPoint(new Point((int)m.LParam));
if (hControlUnderMouse == m.HWnd) if (hControlUnderMouse == m.HWnd)
return false; // Already headed for the right control. return false;
// Redirect the message to the control under the mouse.
Native.SendMessage(hControlUnderMouse, (uint)m.Msg, m.WParam, m.LParam); Native.SendMessage(hControlUnderMouse, (uint)m.Msg, m.WParam, m.LParam);
return true; return true;
} }

View File

@ -11,7 +11,7 @@ namespace Example
{ {
InitializeComponent(); InitializeComponent();
lblVersion.Text = string.Format("Version: {0}", Application.ProductVersion.ToString()); lblVersion.Text = $"Version: {Application.ProductVersion.ToString()}";
btnOk.Text = "Close"; btnOk.Text = "Close";
} }

View File

@ -11,7 +11,7 @@ namespace Example
// Build dummy list data // Build dummy list data
for (var i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
var item = new DarkListItem(string.Format("List item #{0}", i)); var item = new DarkListItem($"List item #{i}");
lstTest.Items.Add(item); lstTest.Items.Add(item);
} }
@ -19,13 +19,13 @@ namespace Example
var childCount = 0; var childCount = 0;
for (var i = 0; i < 20; i++) for (var i = 0; i < 20; i++)
{ {
var node = new DarkTreeNode(string.Format("Root node #{0}", i)); var node = new DarkTreeNode($"Root node #{i}");
node.ExpandedIcon = Icons.folder_open; node.ExpandedIcon = Icons.folder_open;
node.Icon = Icons.folder_closed; node.Icon = Icons.folder_closed;
for (var x = 0; x < 10; x++) for (var x = 0; x < 10; x++)
{ {
var childNode = new DarkTreeNode(string.Format("Child node #{0}", childCount)); var childNode = new DarkTreeNode($"Child node #{childCount}");
childNode.Icon = Icons.files; childNode.Icon = Icons.files;
childCount++; childCount++;
node.Nodes.Add(childNode); node.Nodes.Add(childNode);

View File

@ -13,7 +13,7 @@ namespace Example
// Build dummy list data // Build dummy list data
for (var i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
var item = new DarkListItem(string.Format("List item #{0}", i)); var item = new DarkListItem($"List item #{i}");
lstConsole.Items.Add(item); lstConsole.Items.Add(item);
} }
} }

View File

@ -13,7 +13,7 @@ namespace Example
// Build dummy list data // Build dummy list data
for (var i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
var item = new DarkListItem(string.Format("List item #{0}", i)); var item = new DarkListItem($"List item #{i}");
lstHistory.Items.Add(item); lstHistory.Items.Add(item);
} }
} }

View File

@ -13,7 +13,7 @@ namespace Example
// Build dummy list data // Build dummy list data
for (var i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
var item = new DarkListItem(string.Format("List item #{0}", i)); var item = new DarkListItem($"List item #{i}");
lstLayers.Items.Add(item); lstLayers.Items.Add(item);
} }
} }

View File

@ -14,13 +14,13 @@ namespace Example
var childCount = 0; var childCount = 0;
for (var i = 0; i < 20; i++) for (var i = 0; i < 20; i++)
{ {
var node = new DarkTreeNode(string.Format("Root node #{0}", i)); var node = new DarkTreeNode($"Root node #{i}");
node.ExpandedIcon = Icons.folder_open; node.ExpandedIcon = Icons.folder_open;
node.Icon = Icons.folder_closed; node.Icon = Icons.folder_closed;
for (var x = 0; x < 10; x++) for (var x = 0; x < 10; x++)
{ {
var childNode = new DarkTreeNode(string.Format("Child node #{0}", childCount)); var childNode = new DarkTreeNode($"Child node #{childCount}");
childNode.Icon = Icons.files; childNode.Icon = Icons.files;
childCount++; childCount++;
node.Nodes.Add(childNode); node.Nodes.Add(childNode);

View File

@ -43,7 +43,7 @@ namespace Example
DockPanel.AddContent(_dockLayers); DockPanel.AddContent(_dockLayers);
DockPanel.AddContent(_dockHistory); DockPanel.AddContent(_dockHistory);
// Add 3 dummy documents to the main document area of the dock panel // Add dummy documents to the main document area of the dock panel
DockPanel.AddContent(new DockDocument { DockText = "Document 1" }); DockPanel.AddContent(new DockDocument { DockText = "Document 1" });
DockPanel.AddContent(new DockDocument { DockText = "Document 2" }); DockPanel.AddContent(new DockDocument { DockText = "Document 2" });
DockPanel.AddContent(new DockDocument { DockText = "Document 3" }); DockPanel.AddContent(new DockDocument { DockText = "Document 3" });

View File

@ -5,9 +5,6 @@ namespace Example
{ {
static class Program static class Program
{ {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {