-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,45 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using CommunityToolkit.Mvvm.DependencyInjection; | ||
using Files.Backend.Services; | ||
using Files.Backend.ViewModels.Dialogs; | ||
using Files.Backend.ViewModels.Dialogs.AddItemDialog; | ||
using Files.Shared.Enums; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace Files.App.Dialogs | ||
{ | ||
public sealed partial class AddItemDialog : ContentDialog, IDialog<AddItemDialogViewModel> | ||
{ | ||
private readonly IAddItemService addItemService = Ioc.Default.GetRequiredService<IAddItemService>(); | ||
private readonly IAddItemService _addItemService; | ||
|
||
public AddItemDialogViewModel ViewModel | ||
{ | ||
get => (AddItemDialogViewModel)DataContext; | ||
set => DataContext = value; | ||
} | ||
public AddItemDialogViewModel ViewModel { get; set; } | ||
|
||
public AddItemDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
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; | ||
Hide(); | ||
// Dependency Injection | ||
_addItemService = Ioc.Default.GetRequiredService<IAddItemService>(); | ||
} | ||
|
||
public new async Task<DialogResult> ShowAsync() | ||
=> (DialogResult)await base.ShowAsync(); | ||
|
||
private async void AddItemDialog_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
var itemTypes = await addItemService.GetNewEntriesAsync(); | ||
var itemTypes = await _addItemService.GetNewEntriesAsync(); | ||
await ViewModel.AddItemsToList(itemTypes); | ||
|
||
// Focus on the list view so users can use keyboard navigation | ||
AddItemsListView.Focus(FocusState.Programmatic); | ||
} | ||
|
||
private void ListView_ItemClick(object sender, ItemClickEventArgs e) | ||
{ | ||
ViewModel.ResultType = ((AddItemDialogListItemViewModel)e.ClickedItem)?.ItemResult ?? throw new ArgumentNullException(); | ||
|
||
Hide(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters