Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Open folder in new tab when dragging folder to "add tab" button #14144

Merged
merged 19 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Files.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@
Padding="8"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
AllowDrop="True"
AutomationProperties.Name="{x:Bind Commands.NewTab.AutomationName}"
Background="Transparent"
BorderThickness="0"
Command="{x:Bind Commands.NewTab}"
DragOver="HorizontalMultitaskingControlAddButton_DragOver"
Drop="HorizontalMultitaskingControlAddButton_Drop"
ToolTipService.ToolTip="{x:Bind Commands.NewTab.LabelWithHotKey, Mode=OneWay}">
<Button.Content>
<FontIcon
Expand Down
68 changes: 64 additions & 4 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using System.Data;
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation.Metadata;
using Windows.Services.Store;
using WinRT.Interop;
Expand Down Expand Up @@ -175,10 +177,10 @@ public void MultitaskingControl_CurrentInstanceChanged(object? sender, CurrentIn
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged -= PaneHolder_PropertyChanged;

var navArgs = e.CurrentInstance.TabItemParameter?.NavigationParameter;
if (e.CurrentInstance is IPaneHolder currentInstance)
{
SidebarAdaptiveViewModel.PaneHolder = currentInstance;
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged += PaneHolder_PropertyChanged;
if (e.CurrentInstance is IPaneHolder currentInstance)
{
SidebarAdaptiveViewModel.PaneHolder = currentInstance;
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged += PaneHolder_PropertyChanged;
}
SidebarAdaptiveViewModel.NotifyInstanceRelatedPropertiesChanged((navArgs as PaneNavigationArguments)?.LeftPaneNavPathParam);

Expand Down Expand Up @@ -474,6 +476,64 @@ private void RootGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
}
}

private bool lockFlag = false;
//private string[] dropableArchiveTypes = { "zip", "rar", "7z", "tar" };

private async void HorizontalMultitaskingControlAddButton_Drop(object sender, DragEventArgs e)
denisdekh marked this conversation as resolved.
Show resolved Hide resolved
{
if (lockFlag || !FilesystemHelpers.HasDraggedStorageItems(e.DataView))
return;

lockFlag = true;
denisdekh marked this conversation as resolved.
Show resolved Hide resolved

var items = (await FilesystemHelpers.GetDraggedStorageItems(e.DataView))
.Where(x => x.ItemType is FilesystemItemType.Directory
//|| dropableArchiveTypes.Contains(x.Name.Split('.').Last().ToLower())
);

var deferral = e.GetDeferral();
try
{
foreach (var item in items)
await NavigationHelpers.OpenPathInNewTab(item.Path);

deferral.Complete();
}
catch { }
lockFlag = false;
}

private async void HorizontalMultitaskingControlAddButton_DragOver(object sender, DragEventArgs e)
denisdekh marked this conversation as resolved.
Show resolved Hide resolved
{
if (!FilesystemHelpers.HasDraggedStorageItems(e.DataView))
{
e.AcceptedOperation = DataPackageOperation.None;
return;
}

bool hasValidDraggedItems =
(await FilesystemHelpers.GetDraggedStorageItems(e.DataView)).Any(x => x.ItemType is FilesystemItemType.Directory
//|| dropableArchiveTypes.Contains(x.Name.Split('.').Last().ToLower())
);

if (!hasValidDraggedItems)
{
e.AcceptedOperation = DataPackageOperation.None;
return;
}

try
{
e.Handled = true;
var deferral = e.GetDeferral();
e.DragUIOverride.IsCaptionVisible = true;
e.DragUIOverride.Caption = string.Format("OpenInNewTab".GetLocalizedResource());
e.AcceptedOperation = DataPackageOperation.Link;
deferral.Complete();
}
catch { }
}

private void NavToolbar_Loaded(object sender, RoutedEventArgs e) => UpdateNavToolbarProperties();

private void PaneSplitter_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
Expand Down