Skip to content

Commit 44c8c28

Browse files
authored
Switch to inactive tab when files are dragged over for a certain duration (#2030)
1 parent 012ce28 commit 44c8c28

File tree

4 files changed

+85
-13
lines changed

4 files changed

+85
-13
lines changed

Files/UserControls/MultitaskingControl/HorizontalMultitaskingControl.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@
758758
AddTabButtonClick="TabView_AddTabButtonClick"
759759
AllowDropTabs="True"
760760
CanDragTabs="True"
761+
DragLeave="TabStrip_DragLeave"
761762
IsAddTabButtonVisible="True"
762763
SelectedIndex="{x:Bind local1:App.InteractionViewModel.TabStripSelectedIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
763764
SelectionChanged="TabStrip_SelectionChanged"
@@ -776,7 +777,8 @@
776777
<muxc:TabViewItem
777778
Margin="2,0,2,0"
778779
AllowDrop="True"
779-
DragOver="TabViewItem_DragOver"
780+
DragEnter="TabViewItem_DragEnter"
781+
DragLeave="TabViewItem_DragLeave"
780782
Drop="TabViewItem_Drop"
781783
FontFamily="{StaticResource FluentUIGlyphs}"
782784
Header="{x:Bind Header, Mode=OneWay}"

Files/UserControls/MultitaskingControl/HorizontalMultitaskingControl.xaml.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,22 @@ public sealed partial class HorizontalMultitaskingControl : UserControl, IMultit
2828

2929
public const string TabPathIdentifier = "FilesTabViewItemPath";
3030

31-
public HorizontalMultitaskingControl()
32-
{
33-
this.InitializeComponent();
34-
}
35-
3631
public SettingsViewModel AppSettings => App.AppSettings;
3732

3833
public void SelectionChanged() => TabStrip_SelectionChanged(null, null);
3934

4035
public ObservableCollection<TabItem> Items => MainPage.AppInstances;
4136

37+
private readonly DispatcherTimer tabHoverTimer = new DispatcherTimer();
38+
private TabViewItem hoveredTabViewItem = null;
39+
40+
public HorizontalMultitaskingControl()
41+
{
42+
this.InitializeComponent();
43+
tabHoverTimer.Interval = TimeSpan.FromMilliseconds(500);
44+
tabHoverTimer.Tick += TabHoverSelected;
45+
}
46+
4247
public async Task SetSelectedTabInfo(string text, string currentPathForTabIcon)
4348
{
4449
var selectedTabItem = MainPage.AppInstances[App.InteractionViewModel.TabStripSelectedIndex];
@@ -244,20 +249,39 @@ private void TabViewItem_Drop(object sender, DragEventArgs e)
244249
{
245250
e.AcceptedOperation = DataPackageOperation.None;
246251
}
252+
HorizontalTabView.CanReorderTabs = true;
253+
tabHoverTimer.Stop();
247254
}
248255

249-
private void TabViewItem_DragOver(object sender, DragEventArgs e)
256+
private void TabViewItem_DragEnter(object sender, DragEventArgs e)
250257
{
251258
if (e.DataView.AvailableFormats.Contains(StandardDataFormats.StorageItems))
252259
{
260+
HorizontalTabView.CanReorderTabs = false;
253261
e.AcceptedOperation = DataPackageOperation.Move;
262+
tabHoverTimer.Start();
263+
hoveredTabViewItem = sender as TabViewItem;
254264
}
255265
else
256266
{
257267
e.AcceptedOperation = DataPackageOperation.None;
258268
}
259269
}
260270

271+
private void TabViewItem_DragLeave(object sender, DragEventArgs e)
272+
{
273+
tabHoverTimer.Stop();
274+
hoveredTabViewItem = null;
275+
}
276+
277+
// Select tab that is hovered over for a certain duration
278+
private void TabHoverSelected(object sender, object e)
279+
{
280+
tabHoverTimer.Stop();
281+
if (hoveredTabViewItem != null)
282+
HorizontalTabView.SelectedItem = hoveredTabViewItem;
283+
}
284+
261285
private void TabStrip_TabDragStarting(TabView sender, TabViewTabDragStartingEventArgs args)
262286
{
263287
var tabViewItemPath = ((((args.Item as TabItem).Content as Grid).Children[0] as Frame).Tag as TabItemContent).NavigationArg;
@@ -269,15 +293,25 @@ private void TabStrip_TabStripDragOver(object sender, DragEventArgs e)
269293
{
270294
if (e.DataView.Properties.ContainsKey(TabPathIdentifier))
271295
{
296+
HorizontalTabView.CanReorderTabs = true;
272297
e.AcceptedOperation = DataPackageOperation.Move;
273298
e.DragUIOverride.Caption = ResourceController.GetTranslation("TabStripDragAndDropUIOverrideCaption");
274299
e.DragUIOverride.IsCaptionVisible = true;
275300
e.DragUIOverride.IsGlyphVisible = false;
301+
} else
302+
{
303+
HorizontalTabView.CanReorderTabs = false;
276304
}
277305
}
278306

307+
private void TabStrip_DragLeave(object sender, DragEventArgs e)
308+
{
309+
HorizontalTabView.CanReorderTabs = true;
310+
}
311+
279312
private async void TabStrip_TabStripDrop(object sender, DragEventArgs e)
280313
{
314+
HorizontalTabView.CanReorderTabs = true;
281315
if (!(sender is TabView tabStrip))
282316
{
283317
return;

Files/UserControls/MultitaskingControl/VerticalTabViewControl.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@
628628
Background="Transparent"
629629
CanDragTabs="True"
630630
CanReorderTabs="True"
631+
DragLeave="TabStrip_DragLeave"
631632
IsAddTabButtonVisible="True"
632633
SelectedIndex="{x:Bind local1:App.InteractionViewModel.TabStripSelectedIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
633634
SelectionChanged="TabStrip_SelectionChanged"
@@ -649,7 +650,8 @@
649650
<DataTemplate x:DataType="local:TabItem">
650651
<muxc:TabViewItem
651652
AllowDrop="True"
652-
DragOver="TabViewItem_DragOver"
653+
DragEnter="TabViewItem_DragEnter"
654+
DragLeave="TabViewItem_DragLeave"
653655
Drop="TabViewItem_Drop"
654656
FontFamily="{StaticResource FluentUIGlyphs}"
655657
Header="{x:Bind Header, Mode=OneWay}"

Files/UserControls/MultitaskingControl/VerticalTabViewControl.xaml.cs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ public sealed partial class VerticalTabViewControl : UserControl, IMultitaskingC
2525

2626
public const string TabPathIdentifier = "FilesTabViewItemPath";
2727

28+
public void SelectionChanged() => TabStrip_SelectionChanged(null, null);
29+
30+
public ObservableCollection<TabItem> Items => MainPage.AppInstances;
31+
32+
private readonly DispatcherTimer tabHoverTimer = new DispatcherTimer();
33+
private TabViewItem hoveredTabViewItem = null;
34+
2835
public VerticalTabViewControl()
2936
{
3037
this.InitializeComponent();
38+
tabHoverTimer.Interval = TimeSpan.FromMilliseconds(500);
39+
tabHoverTimer.Tick += TabHoverSelected;
3140
}
3241

33-
public void SelectionChanged() => TabStrip_SelectionChanged(null, null);
34-
35-
public ObservableCollection<TabItem> Items => MainPage.AppInstances;
36-
3742
public async Task SetSelectedTabInfo(string text, string currentPathForTabIcon = null)
3843
{
3944
var selectedTabItem = MainPage.AppInstances[App.InteractionViewModel.TabStripSelectedIndex];
@@ -234,20 +239,39 @@ private void TabViewItem_Drop(object sender, DragEventArgs e)
234239
{
235240
e.AcceptedOperation = DataPackageOperation.None;
236241
}
242+
VerticalTabView.CanReorderTabs = true;
243+
tabHoverTimer.Stop();
237244
}
238245

239-
private void TabViewItem_DragOver(object sender, DragEventArgs e)
246+
private void TabViewItem_DragEnter(object sender, DragEventArgs e)
240247
{
241248
if (e.DataView.AvailableFormats.Contains(StandardDataFormats.StorageItems))
242249
{
250+
VerticalTabView.CanReorderTabs = false;
243251
e.AcceptedOperation = DataPackageOperation.Move;
252+
tabHoverTimer.Start();
253+
hoveredTabViewItem = sender as TabViewItem;
244254
}
245255
else
246256
{
247257
e.AcceptedOperation = DataPackageOperation.None;
248258
}
249259
}
250260

261+
private void TabViewItem_DragLeave(object sender, DragEventArgs e)
262+
{
263+
tabHoverTimer.Stop();
264+
hoveredTabViewItem = null;
265+
}
266+
267+
// Select tab that is hovered over for a certain duration
268+
private void TabHoverSelected(object sender, object e)
269+
{
270+
tabHoverTimer.Stop();
271+
if (hoveredTabViewItem != null)
272+
VerticalTabView.SelectedItem = hoveredTabViewItem;
273+
}
274+
251275
private void TabStrip_TabDragStarting(TabView sender, TabViewTabDragStartingEventArgs args)
252276
{
253277
var tabViewItemPath = ((((args.Item as TabItem).Content as Grid).Children[0] as Frame).Tag as TabItemContent).NavigationArg;
@@ -259,15 +283,25 @@ private void TabStrip_TabStripDragOver(object sender, DragEventArgs e)
259283
{
260284
if (e.DataView.Properties.ContainsKey(TabPathIdentifier))
261285
{
286+
VerticalTabView.CanReorderTabs = true;
262287
e.AcceptedOperation = DataPackageOperation.Move;
263288
e.DragUIOverride.Caption = ResourceController.GetTranslation("TabStripDragAndDropUIOverrideCaption");
264289
e.DragUIOverride.IsCaptionVisible = true;
265290
e.DragUIOverride.IsGlyphVisible = false;
291+
} else
292+
{
293+
VerticalTabView.CanReorderTabs = false;
266294
}
267295
}
268296

297+
private void TabStrip_DragLeave(object sender, DragEventArgs e)
298+
{
299+
VerticalTabView.CanReorderTabs = true;
300+
}
301+
269302
private async void TabStrip_TabStripDrop(object sender, DragEventArgs e)
270303
{
304+
VerticalTabView.CanReorderTabs = true;
271305
if (!(sender is TabView tabStrip))
272306
{
273307
return;

0 commit comments

Comments
 (0)