Skip to content

Commit 28ebdb1

Browse files
Bunch of code improvements
1 parent db59b79 commit 28ebdb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+590
-982
lines changed

ChromeTabs/AddTabButtonBehavior.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
6-
namespace ChromeTabs
1+
namespace ChromeTabs
72
{
8-
public enum AddTabButtonBehavior
3+
public enum AddTabButtonBehavior
94
{
105
OpenNewTab,
116
OpenNewTabInBackground

ChromeTabs/ChromeTabControl.cs

Lines changed: 136 additions & 174 deletions
Large diffs are not rendered by default.

ChromeTabs/ChromeTabItem.cs

Lines changed: 28 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
2+
using System.ComponentModel;
53
using System.Windows;
64
using System.Windows.Controls;
7-
using System.Windows.Data;
8-
using System.Windows.Documents;
5+
using System.Windows.Controls.Primitives;
96
using System.Windows.Input;
107
using System.Windows.Media;
11-
using System.Windows.Media.Imaging;
12-
using System.Windows.Navigation;
13-
using System.Windows.Shapes;
14-
using System.Windows.Controls.Primitives;
158
using System.Windows.Threading;
16-
using System.Diagnostics;
17-
using System.ComponentModel;
189

1910
namespace ChromeTabs
2011
{
@@ -53,16 +44,16 @@ public class ChromeTabItem : HeaderedContentControl
5344

5445
public bool IsSelected
5546
{
56-
get { return (bool)GetValue(IsSelectedProperty); }
57-
set { SetValue(IsSelectedProperty, value); }
47+
get => (bool)GetValue(IsSelectedProperty);
48+
set => SetValue(IsSelectedProperty, value);
5849
}
59-
public static readonly DependencyProperty IsSelectedProperty = Selector.IsSelectedProperty.AddOwner(typeof(ChromeTabItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsParentMeasure | FrameworkPropertyMetadataOptions.AffectsParentArrange, new PropertyChangedCallback(OnIsSelectedChanged)));
50+
public static readonly DependencyProperty IsSelectedProperty = Selector.IsSelectedProperty.AddOwner(typeof(ChromeTabItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsParentMeasure | FrameworkPropertyMetadataOptions.AffectsParentArrange, OnIsSelectedChanged));
6051

6152

6253
public bool IsPinned
6354
{
64-
get { return (bool)GetValue(IsPinnedProperty); }
65-
set { SetValue(IsPinnedProperty, value); }
55+
get => (bool)GetValue(IsPinnedProperty);
56+
set => SetValue(IsPinnedProperty, value);
6657
}
6758

6859
// Using a DependencyProperty as the backing store for IsPinned. This enables animation, styling, binding, etc...
@@ -73,8 +64,8 @@ public bool IsPinned
7364

7465
public Brush SelectedTabBrush
7566
{
76-
get { return (Brush)GetValue(SelectedTabBrushProperty); }
77-
set { SetValue(SelectedTabBrushProperty, value); }
67+
get => (Brush)GetValue(SelectedTabBrushProperty);
68+
set => SetValue(SelectedTabBrushProperty, value);
7869
}
7970

8071
// Using a DependencyProperty as the backing store for SelectedTabBrush. This enables animation, styling, binding, etc...
@@ -85,40 +76,28 @@ public Brush SelectedTabBrush
8576

8677
private static readonly RoutedUICommand closeTabCommand = new RoutedUICommand("Close tab", "CloseTab", typeof(ChromeTabItem));
8778

88-
public static RoutedUICommand CloseTabCommand
89-
{
90-
get { return closeTabCommand; }
91-
}
79+
public static RoutedUICommand CloseTabCommand => closeTabCommand;
9280

9381
private static readonly RoutedUICommand closeAllTabsCommand = new RoutedUICommand("Close all tabs", "CloseAllTabs", typeof(ChromeTabItem));
9482

95-
public static RoutedUICommand CloseAllTabsCommand
96-
{
97-
get { return closeAllTabsCommand; }
98-
}
83+
public static RoutedUICommand CloseAllTabsCommand => closeAllTabsCommand;
9984

10085
private static readonly RoutedUICommand closeOtherTabsCommand = new RoutedUICommand("Close other tabs", "CloseOtherTabs", typeof(ChromeTabItem));
10186

102-
public static RoutedUICommand CloseOtherTabsCommand
103-
{
104-
get { return closeOtherTabsCommand; }
105-
}
87+
public static RoutedUICommand CloseOtherTabsCommand => closeOtherTabsCommand;
10688

10789
private static readonly RoutedUICommand pinTabCommand = new RoutedUICommand("Pin Tab", "PinTab", typeof(ChromeTabItem));
10890

109-
public static RoutedUICommand PinTabCommand
110-
{
111-
get { return pinTabCommand; }
112-
}
91+
public static RoutedUICommand PinTabCommand => pinTabCommand;
11392

11493
public static void SetIsSelected(DependencyObject item, bool value)
11594
{
116-
item.SetValue(ChromeTabItem.IsSelectedProperty, value);
95+
item.SetValue(IsSelectedProperty, value);
11796
}
11897

11998
public static bool GetIsSelected(DependencyObject item)
12099
{
121-
return (bool)item.GetValue(ChromeTabItem.IsSelectedProperty);
100+
return (bool)item.GetValue(IsSelectedProperty);
122101
}
123102

124103

@@ -135,18 +114,18 @@ public ChromeTabItem()
135114
{
136115
if (DesignerProperties.GetIsInDesignMode(this))
137116
return;
138-
this.Loaded += ChromeTabItem_Loaded;
117+
Loaded += ChromeTabItem_Loaded;
139118
}
140119

141120
private void ChromeTabItem_Loaded(object sender, RoutedEventArgs e)
142121
{
143-
this.Loaded -= ChromeTabItem_Loaded;
144-
this.Unloaded += ChromeTabItem_Unloaded;
122+
Loaded -= ChromeTabItem_Loaded;
123+
Unloaded += ChromeTabItem_Unloaded;
145124
}
146125

147126
private void ChromeTabItem_Unloaded(object sender, RoutedEventArgs e)
148127
{
149-
this.Unloaded -= ChromeTabItem_Unloaded;
128+
Unloaded -= ChromeTabItem_Unloaded;
150129
StoptPersistTimer();
151130
}
152131

@@ -156,7 +135,7 @@ private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyCh
156135

157136
if (tabItem.ParentTabControl != null && tabItem.ParentTabControl.TabPersistBehavior == TabPersistBehavior.Timed)
158137
{
159-
if ((bool)args.NewValue == true)
138+
if ((bool)args.NewValue)
160139
{
161140
tabItem.StoptPersistTimer();
162141
}
@@ -172,8 +151,7 @@ private void StartPersistTimer()
172151
{
173152
StoptPersistTimer();
174153

175-
persistentTimer = new DispatcherTimer();
176-
persistentTimer.Interval = ParentTabControl.TabPersistDuration;
154+
persistentTimer = new DispatcherTimer {Interval = ParentTabControl.TabPersistDuration};
177155
persistentTimer.Tick += PersistentTimer_Tick;
178156
persistentTimer.Start();
179157
}
@@ -192,46 +170,35 @@ private void StoptPersistTimer()
192170
private void PersistentTimer_Tick(object sender, EventArgs e)
193171
{
194172
StoptPersistTimer();
195-
if (ParentTabControl != null)
196-
ParentTabControl.RemoveFromItemHolder(this);
173+
ParentTabControl?.RemoveFromItemHolder(this);
197174
}
198175

199176
private static void HandlePinTabCommand(object sender, ExecutedRoutedEventArgs e)
200177
{
201-
ChromeTabItem item = sender as ChromeTabItem;
202-
if (item == null) { return; }
178+
if (!(sender is ChromeTabItem item)) { return; }
203179
item.ParentTabControl.PinTab(item.DataContext);
204180
}
205181

206182

207183
private static void HandleCloseOtherTabsCommand(object sender, ExecutedRoutedEventArgs e)
208184
{
209-
ChromeTabItem item = sender as ChromeTabItem;
210-
if (item == null) { return; }
185+
if (!(sender is ChromeTabItem item)) { return; }
211186
item.ParentTabControl.RemoveAllTabs(item.DataContext);
212187
}
213188

214189
private static void HandleCloseAllTabsCommand(object sender, ExecutedRoutedEventArgs e)
215190
{
216-
ChromeTabItem item = sender as ChromeTabItem;
217-
if (item == null) { return; }
191+
if (!(sender is ChromeTabItem item)) { return; }
218192
item.ParentTabControl.RemoveAllTabs();
219193
}
220194

221195
private static void HandleCloseTabCommand(object sender, ExecutedRoutedEventArgs e)
222196
{
223-
ChromeTabItem item = sender as ChromeTabItem;
224-
if (item == null) { return; }
197+
if (!(sender is ChromeTabItem item)) { return; }
225198
item.ParentTabControl.RemoveFromItemHolder(item);
226199
item.ParentTabControl.RemoveTab(item);
227200
}
228-
public int Index
229-
{
230-
get
231-
{
232-
return ParentTabControl == null ? -1 : ParentTabControl.GetTabIndex(this);
233-
}
234-
}
201+
public int Index => ParentTabControl?.GetTabIndex(this) ?? -1;
235202

236203
protected override void OnKeyDown(KeyEventArgs e)
237204
{
@@ -242,9 +209,6 @@ protected override void OnKeyDown(KeyEventArgs e)
242209
}
243210
}
244211

245-
private ChromeTabControl ParentTabControl
246-
{
247-
get { return ItemsControl.ItemsControlFromItemContainer(this) as ChromeTabControl; }
248-
}
212+
private ChromeTabControl ParentTabControl => ItemsControl.ItemsControlFromItemContainer(this) as ChromeTabControl;
249213
}
250214
}

0 commit comments

Comments
 (0)