Skip to content

Commit 5afea98

Browse files
authored
Code Quality: Move new tab button to TabBar itself (#15585)
1 parent df99a0a commit 5afea98

File tree

4 files changed

+80
-87
lines changed

4 files changed

+80
-87
lines changed

src/Files.App/UserControls/TabBar/TabBar.xaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,27 @@
111111
<ColumnDefinition x:Name="RightPaddingColumn" Width="0" />
112112
</Grid.ColumnDefinitions>
113113

114-
<!-- Footer Element e.g. Add New Tab Button -->
115-
<ContentPresenter Grid.Column="0" Content="{x:Bind FooterElement, Mode=OneWay}" />
114+
<!-- Height is not divisble by four in order to properly align the button -->
115+
<Button
116+
x:Name="TabBarAddNewTabButton"
117+
Grid.Column="0"
118+
Width="30"
119+
Height="30"
120+
Padding="8"
121+
HorizontalAlignment="Left"
122+
VerticalAlignment="Center"
123+
AllowDrop="True"
124+
AutomationProperties.Name="{x:Bind Commands.NewTab.AutomationName}"
125+
Background="Transparent"
126+
BorderThickness="0"
127+
Command="{x:Bind Commands.NewTab}"
128+
DragOver="TabBarAddNewTabButton_DragOver"
129+
Drop="TabBarAddNewTabButton_Drop"
130+
ToolTipService.ToolTip="{x:Bind Commands.NewTab.LabelWithHotKey, Mode=OneWay}">
131+
<Button.Content>
132+
<FontIcon FontSize="12" Glyph="&#xE710;" />
133+
</Button.Content>
134+
</Button>
116135

117136
<!-- Left Side Drag Area -->
118137
<Rectangle

src/Files.App/UserControls/TabBar/TabBar.xaml.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public sealed partial class TabBar : BaseTabBar
2222

2323
private TabViewItem? hoveredTabViewItem;
2424

25+
private bool _lockDropOperation = false;
26+
27+
//private string[] _droppableArchiveTypes = { "zip", "rar", "7z", "tar" };
28+
2529
public static readonly DependencyProperty FooterElementProperty =
2630
DependencyProperty.Register(
2731
nameof(FooterElement),
@@ -285,6 +289,60 @@ private void TabItemContextMenu_Closing(object sender, object e)
285289
SelectedTabItemChanged?.Invoke(null, null);
286290
}
287291

292+
private async void TabBarAddNewTabButton_Drop(object sender, DragEventArgs e)
293+
{
294+
if (_lockDropOperation || !FilesystemHelpers.HasDraggedStorageItems(e.DataView))
295+
return;
296+
297+
_lockDropOperation = true;
298+
299+
//|| _droppableArchiveTypes.Contains(x.Name.Split('.').Last().ToLower())
300+
var items = (await FilesystemHelpers.GetDraggedStorageItems(e.DataView))
301+
.Where(x => x.ItemType is FilesystemItemType.Directory);
302+
303+
var deferral = e.GetDeferral();
304+
try
305+
{
306+
foreach (var item in items)
307+
await NavigationHelpers.OpenPathInNewTab(item.Path, true);
308+
309+
deferral.Complete();
310+
}
311+
catch { }
312+
313+
_lockDropOperation = false;
314+
}
315+
316+
private async void TabBarAddNewTabButton_DragOver(object sender, DragEventArgs e)
317+
{
318+
if (!FilesystemHelpers.HasDraggedStorageItems(e.DataView))
319+
{
320+
e.AcceptedOperation = DataPackageOperation.None;
321+
return;
322+
}
323+
324+
//|| _droppableArchiveTypes.Contains(x.Name.Split('.').Last().ToLower())
325+
bool hasValidDraggedItems =
326+
(await FilesystemHelpers.GetDraggedStorageItems(e.DataView)).Any(x => x.ItemType is FilesystemItemType.Directory);
327+
328+
if (!hasValidDraggedItems)
329+
{
330+
e.AcceptedOperation = DataPackageOperation.None;
331+
return;
332+
}
333+
334+
try
335+
{
336+
e.Handled = true;
337+
var deferral = e.GetDeferral();
338+
e.DragUIOverride.IsCaptionVisible = true;
339+
e.DragUIOverride.Caption = string.Format("OpenInNewTab".GetLocalizedResource());
340+
e.AcceptedOperation = DataPackageOperation.Link;
341+
deferral.Complete();
342+
}
343+
catch { }
344+
}
345+
288346
public override DependencyObject ContainerFromItem(ITabBarItem item)
289347
{
290348
return HorizontalTabView.ContainerFromItem(item);

src/Files.App/Views/MainPage.xaml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -145,33 +145,7 @@
145145
HorizontalContentAlignment="Stretch"
146146
x:Load="False"
147147
Loaded="HorizontalMultitaskingControl_Loaded"
148-
TabIndex="0">
149-
<tabbar:TabBar.FooterElement>
150-
<!-- Height is not divisble by four in order to properly align the button -->
151-
<Button
152-
x:Name="HorizontalMultitaskingControlAddButton"
153-
Width="30"
154-
Height="30"
155-
Padding="8"
156-
HorizontalAlignment="Left"
157-
VerticalAlignment="Center"
158-
AllowDrop="True"
159-
AutomationProperties.Name="{x:Bind Commands.NewTab.AutomationName}"
160-
Background="Transparent"
161-
BorderThickness="0"
162-
Command="{x:Bind Commands.NewTab}"
163-
DragOver="HorizontalMultitaskingControlAddButton_DragOver"
164-
Drop="HorizontalMultitaskingControlAddButton_Drop"
165-
ToolTipService.ToolTip="{x:Bind Commands.NewTab.LabelWithHotKey, Mode=OneWay}">
166-
<Button.Content>
167-
<FontIcon
168-
x:Name="HorizontalMultitaskingControlAddButtonIcon"
169-
FontSize="12"
170-
Glyph="&#xE710;" />
171-
</Button.Content>
172-
</Button>
173-
</tabbar:TabBar.FooterElement>
174-
</tabbar:TabBar>
148+
TabIndex="0" />
175149

176150
<!-- Address Bar -->
177151
<uc:AddressToolbar

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -481,64 +481,6 @@ private void RootGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
481481
}
482482
}
483483

484-
private bool lockFlag = false;
485-
//private string[] dropableArchiveTypes = { "zip", "rar", "7z", "tar" };
486-
487-
private async void HorizontalMultitaskingControlAddButton_Drop(object sender, DragEventArgs e)
488-
{
489-
if (lockFlag || !FilesystemHelpers.HasDraggedStorageItems(e.DataView))
490-
return;
491-
492-
lockFlag = true;
493-
494-
var items = (await FilesystemHelpers.GetDraggedStorageItems(e.DataView))
495-
.Where(x => x.ItemType is FilesystemItemType.Directory
496-
//|| dropableArchiveTypes.Contains(x.Name.Split('.').Last().ToLower())
497-
);
498-
499-
var deferral = e.GetDeferral();
500-
try
501-
{
502-
foreach (var item in items)
503-
await NavigationHelpers.OpenPathInNewTab(item.Path, true);
504-
505-
deferral.Complete();
506-
}
507-
catch { }
508-
lockFlag = false;
509-
}
510-
511-
private async void HorizontalMultitaskingControlAddButton_DragOver(object sender, DragEventArgs e)
512-
{
513-
if (!FilesystemHelpers.HasDraggedStorageItems(e.DataView))
514-
{
515-
e.AcceptedOperation = DataPackageOperation.None;
516-
return;
517-
}
518-
519-
bool hasValidDraggedItems =
520-
(await FilesystemHelpers.GetDraggedStorageItems(e.DataView)).Any(x => x.ItemType is FilesystemItemType.Directory
521-
//|| dropableArchiveTypes.Contains(x.Name.Split('.').Last().ToLower())
522-
);
523-
524-
if (!hasValidDraggedItems)
525-
{
526-
e.AcceptedOperation = DataPackageOperation.None;
527-
return;
528-
}
529-
530-
try
531-
{
532-
e.Handled = true;
533-
var deferral = e.GetDeferral();
534-
e.DragUIOverride.IsCaptionVisible = true;
535-
e.DragUIOverride.Caption = string.Format("OpenInNewTab".GetLocalizedResource());
536-
e.AcceptedOperation = DataPackageOperation.Link;
537-
deferral.Complete();
538-
}
539-
catch { }
540-
}
541-
542484
private void NavToolbar_Loaded(object sender, RoutedEventArgs e) => UpdateNavToolbarProperties();
543485

544486
private void PaneSplitter_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)

0 commit comments

Comments
 (0)