-
Notifications
You must be signed in to change notification settings - Fork 1
/
S3_RemoveFolder.xaml.cpp
104 lines (92 loc) · 3.62 KB
/
S3_RemoveFolder.xaml.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
//
// Scenario3.xaml.cpp
// Implementation of the Scenario3 class
//
#include "pch.h"
#include "S3_RemoveFolder.xaml.h"
using namespace SDKTemplate;
using namespace concurrency;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
Scenario3::Scenario3()
{
InitializeComponent();
GetPicturesLibrary();
}
/// <summary>
/// Requests the user's permission to remove the selected location from the Pictures library.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Scenario3::RemoveFolderButton_Click(Platform::Object^ /*sender*/, Windows::UI::Xaml::RoutedEventArgs^ /*e*/)
{
auto folderToRemove = safe_cast<StorageFolder^>(FoldersComboBox->SelectedItem);
create_task(picturesLibrary->RequestRemoveFolderAsync(folderToRemove)).then([this, folderToRemove](bool folderRemoved)
{
if (folderRemoved)
{
OutputTextBlock->Text = folderToRemove->DisplayName + " was removed from the Pictures library.";
}
else
{
OutputTextBlock->Text = "Operation canceled.";
}
});
}
/// <summary>
/// Gets the Pictures library and sets up the FoldersComboBox to list its folders.
/// </summary>
void Scenario3::GetPicturesLibrary()
{
create_task(StorageLibrary::GetLibraryAsync(KnownLibraryId::Pictures)).then([this](StorageLibrary^ library)
{
picturesLibrary = library;
// Bind the ComboBox to the list of folders currently in the library
FoldersComboBox->ItemsSource = picturesLibrary->Folders;
// Update the states of our controls when the list of folders changes
picturesLibrary->DefinitionChanged += ref new TypedEventHandler<StorageLibrary^, Platform::Object^>(
[this](StorageLibrary^ /*sender*/, Platform::Object^ /*e*/)
{
Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]()
{
UpdateControls();
}));
});
UpdateControls();
});
}
/// <summary>
// Fills the ComboBox control with the folders that make up the Pictures library.
/// </summary>
void Scenario3::FillComboBox()
{
FoldersComboBox->ItemsSource = nullptr;
FoldersComboBox->ItemsSource = picturesLibrary->Folders;
}
/// <summary>
/// Updates the Visibility and IsEnabled properties of UI controls that depend upon the Pictures library
/// having at least one folder in its Folders list.
/// </summary>
void Scenario3::UpdateControls()
{
FillComboBox();
bool libraryHasFolders = (picturesLibrary->Folders->Size > 0);
FoldersComboBox->SelectedIndex = libraryHasFolders ? 0 : -1;
FoldersComboBox->Visibility = libraryHasFolders ? Windows::UI::Xaml::Visibility::Visible : Windows::UI::Xaml::Visibility::Collapsed;
LibraryEmptyTextBlock->Visibility = libraryHasFolders ? Windows::UI::Xaml::Visibility::Collapsed : Windows::UI::Xaml::Visibility::Visible;
RemoveFolderButton->IsEnabled = libraryHasFolders;
}