Skip to content

Commit 4d9a96d

Browse files
committed
Adding 'Close all' context menu item to result tabs
1 parent c06b012 commit 4d9a96d

File tree

8 files changed

+167
-339
lines changed

8 files changed

+167
-339
lines changed

DataCommander.Foundation/Collections/DynamicArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void Add(T item)
8888

8989
if (this.count == this.array.Length)
9090
{
91-
int newSize = this.count == 0 ? 1 : 2 * this.count;
91+
int newSize = this.count == 0 ? 1 : 2*this.count;
9292

9393
if (newSize > this.maxSize)
9494
{

DataCommander.Foundation/Linq/IEnumerableExtensions.cs

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static List<TResult> CreateList<TSource, TResult>(this IEnumerable<TSourc
143143
/// <returns></returns>
144144
public static IEnumerable<T> Clone<T>(this IEnumerable<T> source)
145145
{
146-
Contract.Requires(source != null);
146+
Contract.Requires<ArgumentNullException>(source != null);
147147
return source.Select<T, T>(Clone);
148148
}
149149

@@ -166,7 +166,7 @@ public static IEnumerable<TSource> EmptyIfNull<TSource>(this IEnumerable<TSource
166166
/// <param name="action"></param>
167167
public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource, int> action)
168168
{
169-
Contract.Requires(action != null);
169+
Contract.Requires<ArgumentNullException>(action != null);
170170

171171
if (source != null)
172172
{
@@ -184,29 +184,52 @@ public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSo
184184
/// </summary>
185185
/// <typeparam name="T"></typeparam>
186186
/// <param name="source"></param>
187-
/// <param name="partitionSize"></param>
187+
/// <param name="count"></param>
188+
/// <param name="partitionCount"></param>
188189
/// <returns></returns>
189-
public static IEnumerable<List<T>> GetPartitions<T>(this IEnumerable<T> source, int partitionSize)
190+
public static IEnumerable<List<T>> GetPartitions<T>(
191+
this IEnumerable<T> source,
192+
int count,
193+
int partitionCount)
190194
{
191-
Contract.Requires(source != null);
192-
Contract.Requires(partitionSize > 0);
195+
Contract.Requires<ArgumentNullException>(source != null);
196+
Contract.Requires<ArgumentOutOfRangeException>(count >= 0);
197+
Contract.Requires<ArgumentOutOfRangeException>(partitionCount > 0);
193198

194-
var partition = new List<T>(partitionSize);
199+
Contract.Ensures(Contract.Result<IEnumerable<List<T>>>().Count() <= partitionCount);
200+
Contract.Ensures(Contract.ForAll(Contract.Result<IEnumerable<List<T>>>().ToList(), partition => partition.Count > 0));
195201

196-
foreach (var item in source)
202+
int partitionSize = count/partitionCount;
203+
int remainder = count%partitionCount;
204+
205+
using (var enumerator = source.GetEnumerator())
197206
{
198-
if (partition.Count == partitionSize)
207+
for (int partitionIndex = 0; partitionIndex < partitionCount; partitionIndex++)
199208
{
200-
yield return partition;
201-
partition = new List<T>(partitionSize);
202-
}
203-
204-
partition.Add(item);
205-
}
209+
int currentPartitionSize = partitionSize;
210+
if (remainder > 0)
211+
{
212+
currentPartitionSize++;
213+
remainder--;
214+
}
206215

207-
if (partition.Count > 0)
208-
{
209-
yield return partition;
216+
if (currentPartitionSize > 0)
217+
{
218+
var partition = enumerator.Take(currentPartitionSize);
219+
if (partition.Count > 0)
220+
{
221+
yield return partition;
222+
}
223+
else
224+
{
225+
break;
226+
}
227+
}
228+
else
229+
{
230+
break;
231+
}
232+
}
210233
}
211234
}
212235

@@ -219,7 +242,7 @@ public static IEnumerable<List<T>> GetPartitions<T>(this IEnumerable<T> source,
219242
/// <returns></returns>
220243
public static IndexedItem<T> IndexOf<T>(this IEnumerable<T> source, Func<T, bool> predicate)
221244
{
222-
Contract.Requires(predicate != null);
245+
Contract.Requires<ArgumentNullException>(predicate != null);
223246

224247
IndexedItem<T> result = null;
225248
if (source != null)
@@ -445,7 +468,7 @@ public static TCollection ToCollection<TSource, TCollection>(
445468
this IEnumerable<TSource> source,
446469
Func<TCollection> createCollection) where TCollection : ICollection<TSource>
447470
{
448-
Contract.Requires(createCollection != null);
471+
Contract.Requires<ArgumentNullException>(createCollection != null);
449472

450473
TCollection collection = default(TCollection);
451474
if (source != null)
@@ -470,8 +493,8 @@ public static TCollection ToCollection<TSource, TCollection>(
470493
Func<TCollection> createCollection,
471494
Action<TCollection, TSource> add)
472495
{
473-
Contract.Requires(createCollection != null);
474-
Contract.Requires(add != null);
496+
Contract.Requires<ArgumentNullException>(createCollection != null);
497+
Contract.Requires<ArgumentNullException>(add != null);
475498

476499
TCollection collection = default(TCollection);
477500
if (source != null)
@@ -578,12 +601,12 @@ public static SortedDictionary<TKey, TValue> ToSortedDictionary<TKey, TValue>(th
578601
/// <returns></returns>
579602
public static string ToString<T>(this IEnumerable<T> source, string separator, Func<T, string> toString)
580603
{
581-
Contract.Requires(toString != null);
604+
Contract.Requires<ArgumentNullException>(toString != null);
582605

583606
string result;
584607
if (source != null)
585608
{
586-
StringBuilder sb = new StringBuilder();
609+
var sb = new StringBuilder();
587610
foreach (var item in source)
588611
{
589612
if (sb.Length > 0)
@@ -700,6 +723,8 @@ private static T Clone<T>(T source)
700723

701724
#endregion
702725

726+
#region Private Classes
727+
703728
private sealed class EmptyReadOnlyList<T> : IReadOnlyList<T>
704729
{
705730
private static readonly EmptyReadOnlyList<T> instance = new EmptyReadOnlyList<T>();
@@ -738,5 +763,7 @@ IEnumerator IEnumerable.GetEnumerator()
738763
return Enumerable.Empty<T>().GetEnumerator();
739764
}
740765
}
766+
767+
#endregion
741768
}
742769
}

DataCommander.Foundation/Linq/IEnumeratorExtensions.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
/// </summary>
1111
public static class IEnumeratorExtensions
1212
{
13+
#region Public Methods
14+
1315
/// <summary>
1416
///
1517
/// </summary>
@@ -23,6 +25,39 @@ public static IEnumerable<T> AsEnumerable<T>(this IEnumerator<T> enumerator)
2325
return new Enumerable<T>(enumerator);
2426
}
2527

28+
/// <summary>
29+
///
30+
/// </summary>
31+
/// <param name="enumerator"></param>
32+
/// <param name="count"></param>
33+
/// <returns></returns>
34+
public static List<T> Take<T>(this IEnumerator<T> enumerator, int count)
35+
{
36+
Contract.Requires<ArgumentNullException>(enumerator != null);
37+
Contract.Requires<ArgumentOutOfRangeException>(count >= 0);
38+
39+
var list = new List<T>(count);
40+
41+
for (int i = 0; i < count; i++)
42+
{
43+
if (enumerator.MoveNext())
44+
{
45+
var item = enumerator.Current;
46+
list.Add(item);
47+
}
48+
else
49+
{
50+
break;
51+
}
52+
}
53+
54+
return list;
55+
}
56+
57+
#endregion
58+
59+
#region Private Classes
60+
2661
private sealed class Enumerable<T> : IEnumerable<T>
2762
{
2863
private readonly IEnumerator<T> enumerator;
@@ -44,5 +79,7 @@ IEnumerator IEnumerable.GetEnumerator()
4479
return this.enumerator;
4580
}
4681
}
82+
83+
#endregion
4784
}
4885
}

DataCommander.Foundation/Linq/StringTableColumnInfo.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public sealed class StringTableColumnInfo<T>
2323
public StringTableColumnInfo(
2424
string columnName,
2525
StringTableColumnAlign align,
26-
Func<T, int, string> toString )
26+
Func<T, int, string> toString)
2727
{
28-
Contract.Requires<ArgumentNullException>( toString != null );
28+
Contract.Requires<ArgumentNullException>(toString != null);
2929

3030
this.columnName = columnName;
3131
this.align = align;
@@ -41,16 +41,16 @@ public StringTableColumnInfo(
4141
public StringTableColumnInfo(
4242
string columnName,
4343
StringTableColumnAlign align,
44-
Func<T, object> getValue )
44+
Func<T, object> getValue)
4545
{
46-
Contract.Requires<ArgumentNullException>( getValue != null );
46+
Contract.Requires<ArgumentNullException>(getValue != null);
4747

4848
this.columnName = columnName;
4949
this.align = align;
50-
this.toString = delegate( T item, int index )
50+
this.toString = delegate(T item, int index)
5151
{
52-
object value = getValue( item );
53-
return ToString( value );
52+
object value = getValue(item);
53+
return ToString(value);
5454
};
5555
}
5656

@@ -76,12 +76,12 @@ public StringTableColumnAlign Align
7676
}
7777
}
7878

79-
internal string ToString( T item, int index )
79+
internal string ToString(T item, int index)
8080
{
81-
return this.toString( item, index );
81+
return this.toString(item, index);
8282
}
8383

84-
private static string ToString( object source )
84+
private static string ToString(object source)
8585
{
8686
string result;
8787
if (source != null)

DataCommander.Foundation/SmallDate.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,33 @@ public static explicit operator SmallDate(DateTime dateTime)
114114
return new SmallDate(value);
115115
}
116116

117+
/// <summary>
118+
///
119+
/// </summary>
120+
/// <param name="smallDate"></param>
121+
/// <param name="value"></param>
122+
/// <returns></returns>
123+
public static SmallDate operator +(SmallDate smallDate, int value)
124+
{
125+
int result = smallDate.value + value;
126+
if (result < ushort.MinValue || ushort.MaxValue < result)
127+
{
128+
throw new OverflowException();
129+
}
130+
return new SmallDate((ushort) result);
131+
}
132+
133+
/// <summary>
134+
///
135+
/// </summary>
136+
/// <param name="smallDate1"></param>
137+
/// <param name="smallDate2"></param>
138+
/// <returns></returns>
139+
public static int operator -(SmallDate smallDate1, SmallDate smallDate2)
140+
{
141+
return smallDate1.value - smallDate2.value;
142+
}
143+
117144
/// <summary>
118145
///
119146
/// </summary>
@@ -124,6 +151,33 @@ public DateTime ToDateTime()
124151
return ToDateTime(this.value);
125152
}
126153

154+
/// <summary>
155+
///
156+
/// </summary>
157+
/// <param name="value"></param>
158+
/// <returns></returns>
159+
[Pure]
160+
public SmallDate AddDays(short value)
161+
{
162+
int valueInt32 = this.value + value;
163+
ushort valueUInt16;
164+
165+
if (valueInt32 < ushort.MinValue)
166+
{
167+
valueUInt16 = ushort.MinValue;
168+
}
169+
else if (ushort.MaxValue < valueInt32)
170+
{
171+
valueUInt16 = ushort.MaxValue;
172+
}
173+
else
174+
{
175+
valueUInt16 = (ushort)valueInt32;
176+
}
177+
178+
return new SmallDate(valueUInt16);
179+
}
180+
127181
/// <summary>
128182
///
129183
/// </summary>

DataCommander.Providers/AboutForm.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using DataCommander.Foundation;
2-
using DataCommander.Foundation.Linq;
3-
4-
namespace DataCommander.Providers
1+
namespace DataCommander.Providers
52
{
63
using System;
74
using System.Diagnostics;
@@ -10,6 +7,9 @@ namespace DataCommander.Providers
107
using System.Web;
118
using System.Windows.Forms;
129
using DataCommander.Foundation.Diagnostics;
10+
using System.Linq;
11+
using DataCommander.Foundation;
12+
using DataCommander.Foundation.Linq;
1313

1414
public partial class AboutForm : Form
1515
{
@@ -22,9 +22,15 @@ public AboutForm()
2222
DateTime lastWriteTime = File.GetLastWriteTime(path);
2323
string dotNetFrameworkVersion = AppDomainMonitor.DotNetFrameworkVersion;
2424

25-
string searchPattern = string.Format("DataCommander {0:yyyy.MM.dd}*.log", LocalTime.Default.Now.Date);
26-
string[] logFileNames = Directory.GetFiles(Path.GetTempPath(), searchPattern);
27-
string logFileName = logFileNames.Last();
25+
const string searchPattern = "DataCommander*.log";
26+
var directoryInfo = new DirectoryInfo(Path.GetTempPath());
27+
FileInfo[] fileInfos = directoryInfo.GetFiles(searchPattern, SearchOption.TopDirectoryOnly);
28+
var fileInfo = fileInfos.OrderByDescending(i => i.CreationTime).FirstOrDefault();
29+
string logFileName = null;
30+
if (fileInfo != null)
31+
{
32+
logFileName = fileInfo.FullName;
33+
}
2834

2935
string text = string.Format(@"<div style=""font-family:verdana;font-size:9pt"">
3036
<a href=""https://github.com/csbernath/DataCommander"">Data Commander</a>

DataCommander.Providers/Query/QueryForm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ private void resultSetsTabControl_MouseUp(object sender, MouseEventArgs e)
332332
{
333333
Tag = hotTab
334334
});
335+
contextMenu.Items.Add(new ToolStripMenuItem("Close all", null, this.mnuCloseAllTabPages_Click, Keys.Control | Keys.Shift | Keys.F4));
335336
contextMenu.Show(this.resultSetsTabControl, e.Location);
336337
}
337338
}

0 commit comments

Comments
 (0)