Skip to content

Commit 6706117

Browse files
authored
Feature: Open folder in new tab when dragging folder to "add tab" button (#14144)
1 parent 1e9476e commit 6706117

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

src/Files.App/Views/MainPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,13 @@
155155
Padding="8"
156156
HorizontalAlignment="Left"
157157
VerticalAlignment="Bottom"
158+
AllowDrop="True"
158159
AutomationProperties.Name="{x:Bind Commands.NewTab.AutomationName}"
159160
Background="Transparent"
160161
BorderThickness="0"
161162
Command="{x:Bind Commands.NewTab}"
163+
DragOver="HorizontalMultitaskingControlAddButton_DragOver"
164+
Drop="HorizontalMultitaskingControlAddButton_Drop"
162165
ToolTipService.ToolTip="{x:Bind Commands.NewTab.LabelWithHotKey, Mode=OneWay}">
163166
<Button.Content>
164167
<FontIcon

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

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
using Microsoft.UI.Xaml.Controls;
1313
using Microsoft.UI.Xaml.Input;
1414
using Microsoft.UI.Xaml.Navigation;
15+
using System.Data;
1516
using Windows.ApplicationModel;
17+
using Windows.ApplicationModel.DataTransfer;
1618
using Windows.Foundation.Metadata;
1719
using Windows.Services.Store;
1820
using WinRT.Interop;
@@ -175,10 +177,10 @@ public void MultitaskingControl_CurrentInstanceChanged(object? sender, CurrentIn
175177
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged -= PaneHolder_PropertyChanged;
176178

177179
var navArgs = e.CurrentInstance.TabItemParameter?.NavigationParameter;
178-
if (e.CurrentInstance is IPaneHolder currentInstance)
179-
{
180-
SidebarAdaptiveViewModel.PaneHolder = currentInstance;
181-
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged += PaneHolder_PropertyChanged;
180+
if (e.CurrentInstance is IPaneHolder currentInstance)
181+
{
182+
SidebarAdaptiveViewModel.PaneHolder = currentInstance;
183+
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged += PaneHolder_PropertyChanged;
182184
}
183185
SidebarAdaptiveViewModel.NotifyInstanceRelatedPropertiesChanged((navArgs as PaneNavigationArguments)?.LeftPaneNavPathParam);
184186

@@ -474,6 +476,64 @@ private void RootGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
474476
}
475477
}
476478

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

479539
private void PaneSplitter_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)

0 commit comments

Comments
 (0)