Skip to content

Feature: Auto select new folder on add item dialog #10042

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

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 2 additions & 4 deletions src/Files.App/Dialogs/AddItemDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
BorderThickness="0"
CornerRadius="{StaticResource OverlayCornerRadius}"
Loaded="AddItemDialog_Loaded"
PrimaryButtonStyle="{StaticResource AccentButtonStyle}"
PrimaryButtonText="{helpers:ResourceString Name=Cancel}"
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}"
SecondaryButtonText="{helpers:ResourceString Name=Cancel}"
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">

Expand All @@ -40,8 +39,7 @@
Width="400"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick"
ItemsSource="{x:Bind ViewModel.AddItemsList}"
SelectionMode="None">
ItemsSource="{x:Bind ViewModel.AddItemsList}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="vm:AddItemDialogListItemViewModel">
<Grid Height="50">
Expand Down
49 changes: 26 additions & 23 deletions src/Files.App/Dialogs/AddItemDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,34 @@

namespace Files.App.Dialogs
{
public sealed partial class AddItemDialog : ContentDialog, IDialog<AddItemDialogViewModel>
{
public AddItemDialogViewModel ViewModel
{
get => (AddItemDialogViewModel)DataContext;
set => DataContext = value;
}
public sealed partial class AddItemDialog : ContentDialog, IDialog<AddItemDialogViewModel>
{
public AddItemDialogViewModel ViewModel
{
get => (AddItemDialogViewModel)DataContext;
set => DataContext = value;
}

public AddItemDialog()
{
InitializeComponent();
}
public AddItemDialog()
{
InitializeComponent();
}

public new async Task<DialogResult> ShowAsync() => (DialogResult)await base.ShowAsync();
public new async Task<DialogResult> ShowAsync() => (DialogResult)await base.ShowAsync();

private void ListView_ItemClick(object sender, ItemClickEventArgs e)
{
ViewModel.ResultType = (e.ClickedItem as AddItemDialogListItemViewModel).ItemResult;
this.Hide();
}
private void ListView_ItemClick(object sender, ItemClickEventArgs e)
{
ViewModel.ResultType = (e.ClickedItem as AddItemDialogListItemViewModel).ItemResult;
this.Hide();
}

private async void AddItemDialog_Loaded(object sender, RoutedEventArgs e)
{
var itemTypes = await ShellNewEntryExtensions.GetNewContextMenuEntries();
await ViewModel.AddItemsToList(itemTypes); // TODO(i): This is a very cheap way of doing it, consider adding a service to retrieve the itemTypes list.
}
}
private async void AddItemDialog_Loaded(object sender, RoutedEventArgs e)
{
var itemTypes = await ShellNewEntryExtensions.GetNewContextMenuEntries();
await ViewModel.AddItemsToList(itemTypes); // TODO(i): This is a very cheap way of doing it, consider adding a service to retrieve the itemTypes list.

// Focus on the list view so users can use keyboard navigation
AddItemsListView.Focus(FocusState.Programmatic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,20 @@ public async Task AddItemsToList(IEnumerable<ShellNewEntry> itemTypes)
IsItemEnabled = true,
ItemResult = new AddItemDialogResultModel() { ItemType = AddItemDialogItemType.Folder }
});
AddItemsList.Add(new AddItemDialogListItemViewModel
{
Header = "File".ToLocalized(),
SubHeader = "AddDialogListFileSubHeader".ToLocalized(),
Glyph = "\xE8A5",
IsItemEnabled = true,
ItemResult = new AddItemDialogResultModel()
{
ItemType = AddItemDialogItemType.File,
ItemInfo = new ShellNewEntry() // TODO(i): Make ItemInfo nullable and pass null there?
}
});

foreach (var itemType in itemTypes)
foreach (var itemType in itemTypes)
{
ImageModel? imageModel = null;
if (!string.IsNullOrEmpty(itemType.IconBase64))
Expand All @@ -64,19 +76,6 @@ public async Task AddItemsToList(IEnumerable<ShellNewEntry> itemTypes)
}
});
}

AddItemsList.Add(new AddItemDialogListItemViewModel
{
Header = "File".ToLocalized(),
SubHeader = "AddDialogListFileSubHeader".ToLocalized(),
Glyph = "\xE8A5",
IsItemEnabled = true,
ItemResult = new AddItemDialogResultModel()
{
ItemType = AddItemDialogItemType.File,
ItemInfo = new ShellNewEntry() // TODO(i): Make ItemInfo nullable and pass null there?
}
});
}
}
}