Skip to content

Commit

Permalink
progress in adding export
Browse files Browse the repository at this point in the history
  • Loading branch information
duchuule committed Aug 6, 2015
1 parent 2a9db3d commit 58daff4
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 31 deletions.
1 change: 1 addition & 0 deletions DirectXPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,3 +831,4 @@ task<void> DirectXPage::UpdateDBEntry()

}


2 changes: 1 addition & 1 deletion DirectXPage.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ namespace VBA10
void TogglePaneButton_UnChecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void TogglePaneButton_Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void CloseMenu();
};
};
}

2 changes: 1 addition & 1 deletion ExportPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/>
<TextBlock TextWrapping="Wrap"
Text="If for any reason you cannot access the rom folder, e.g., the rom is stored in the app's private storage, use this option to export save files to OneDrive."
Margin=" 0, 4, 0, 4" />
Margin=" 0, 4, 0, 4" />

<StackPanel Orientation="Horizontal"
Margin="0,4,0,12">
Expand Down
70 changes: 69 additions & 1 deletion ExportPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "pch.h"
#include "ExportPage.xaml.h"
#include "App.xaml.h"
#include "SelectFilePane.xaml.h"
#include "SelectFilesPane.xaml.h"

using namespace VBA10;

Expand All @@ -20,6 +22,7 @@ using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;



// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

ExportPage::ExportPage()
Expand Down Expand Up @@ -76,5 +79,70 @@ void ExportPage::signin_Completed(bool isLoggedIn)

void ExportPage::exportOneDrivebtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
//get a list of rom
Vector<Platform::String ^> ^romNames = ref new Vector<Platform::String ^>();
for (int i = 0; i < App::ROMDB->AllROMDBEntries->Size; i++)
romNames->Append(App::ROMDB->AllROMDBEntries->GetAt(i)->DisplayName);

//open panel to let user select rom
Popup ^statePopup = ref new Popup();
statePopup->IsLightDismissEnabled = true;

SelectFilePane ^pane = ref new SelectFilePane(romNames, "Select ROM");
statePopup->Child = pane;
pane->Width = titleBar->ActualWidth;//statePopup->Width;
pane->MaxHeight = Window::Current->Bounds.Height - 48; //statePopup->MaxHeight;

pane->FileSelectedCallback = ref new FileSelectedDelegate([=](int selectedIndex)
{
ROMDBEntry^ entry = App::ROMDB->AllROMDBEntries->GetAt(selectedIndex);

//get list of save files
Search::QueryOptions ^options = ref new Search::QueryOptions();
options->FileTypeFilter->Append("*");
options->IndexerOption = Search::IndexerOption::DoNotUseIndexer;
options->UserSearchFilter = entry->DisplayName;
create_task(entry->Folder->CreateFileQueryWithOptions(options)->GetFilesAsync())
.then([this](IVectorView<StorageFile ^> ^files)
{
//open panel to let user select file
Popup ^statePopup = ref new Popup();
statePopup->IsLightDismissEnabled = true;

Vector<Platform::String ^> ^fileNames = ref new Vector<Platform::String ^>();
for (int i = 0; i < files->Size; i++)
fileNames->Append(files->GetAt(i)->Name);

SelectFilesPane ^pane = ref new SelectFilesPane(fileNames, "Select file(s) to export");
statePopup->Child = pane;
pane->Width = titleBar->ActualWidth;//statePopup->Width;
pane->MaxHeight = Window::Current->Bounds.Height - 48; //statePopup->MaxHeight;

pane->FilesSelectedCallback = ref new FilesSelectedDelegate([=](IVector<int>^ selectedIndices)
{

});

auto transform = ((UIElement^)titleBar)->TransformToVisual(nullptr);

Windows::Foundation::Point point = transform->TransformPoint(Windows::Foundation::Point());
statePopup->HorizontalOffset = point.X + 1; //+ selectStateBtn->ActualWidth / 2.0f - pane->Width / 2.0f;
statePopup->VerticalOffset = point.Y + titleBar->ActualHeight;

statePopup->IsOpen = true;

});



});

auto transform = ((UIElement^)titleBar)->TransformToVisual(nullptr);

Windows::Foundation::Point point = transform->TransformPoint(Windows::Foundation::Point());
statePopup->HorizontalOffset = point.X + 1; //+ selectStateBtn->ActualWidth / 2.0f - pane->Width / 2.0f;
statePopup->VerticalOffset = point.Y + titleBar->ActualHeight;

statePopup->IsOpen = true;
}

}
1 change: 1 addition & 0 deletions ExportPage.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ namespace VBA10
void Page_Loaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void SignInbtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void signin_Completed(bool isLoggedIn);

};
}
2 changes: 1 addition & 1 deletion ImportPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
Margin="0,8,0,0"
/>
<TextBlock TextWrapping="Wrap"
Text="Use this option to import roms and save files from OneDrive, which will be copied to the app's private storage. NOTE: If you are on Dekstop/Tablet, you should use the Local Storage option and browse to the OneDrive folder, which gives you automatic cloud sync."
Text="Use this option to import roms and save files from OneDrive, which will be copied to the app's private storage. NOTE: It is recommended that you store the roms on an user-accessible folder and use the Local Storage option to import them, which will prevents loss of progress if you the app every becomes corrupted."
Margin=" 0, 4, 0, 4" />


Expand Down
9 changes: 7 additions & 2 deletions ImportPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,18 @@ void ImportPage::chooseFolderbtn_Click(Platform::Object^ sender, Windows::UI::Xa
Popup ^statePopup = ref new Popup();
statePopup->IsLightDismissEnabled = true;

SelectFilePane ^pane = ref new SelectFilePane(files);
Vector<Platform::String ^> ^fileNames = ref new Vector<Platform::String ^>();
for (int i = 0; i < files->Size; i++)
fileNames->Append(files->GetAt(i)->Name);

SelectFilePane ^pane = ref new SelectFilePane(fileNames, "Select file to import");
statePopup->Child = pane;
pane->Width = titleBar->ActualWidth;//statePopup->Width;
pane->MaxHeight = Window::Current->Bounds.Height - 48; //statePopup->MaxHeight;

pane->FileSelectedCallback = ref new FileSelectedDelegate([=](StorageFile ^file)
pane->FileSelectedCallback = ref new FileSelectedDelegate([=](int selectedIndex)
{
StorageFile^ file = files->GetAt(selectedIndex);
//calculate snapshot name
Platform::String ^file_path = file->Path;
wstring wfilepath(file_path->Begin(), file_path->End());
Expand Down
19 changes: 13 additions & 6 deletions SelectFilePane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,40 @@

<StackPanel Background="{ThemeResource ListBoxBorderThemeBrush}"
VerticalAlignment="Stretch">
<TextBlock Text="Select file to import"
<TextBlock Text="Assigned at run time"
x:Name="txtTitle"
Style="{ThemeResource TitleTextBlockStyle}"
Margin="8,4,0,4"
Margin="10,4,0,4"
/>
</StackPanel>

<TextBlock x:Name="txtNoFile" Grid.Row="1"
Text="No supported file found!"
Foreground="Red"
Margin="8,8,0,8"/>
Margin="10,8,0,8"/>

<ListBox Name="fileList"
Background="Transparent"
SelectionChanged="fileList_SelectionChanged"
ItemsSource="{Binding Source={StaticResource FileListvs}}"
Grid.Row="1"
>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="10"/>
</Style>
</ListBox.ItemContainerStyle>

<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Name}"
FontSize="20"/>
<TextBlock Text="{Binding}"
FontSize="18"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>


</Grid>
</UserControl>
21 changes: 12 additions & 9 deletions SelectFilePane.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "pch.h"
#include "SelectFilePane.xaml.h"
#include "DirectXPage.xaml.h";
#include "DirectXPage.xaml.h"

using namespace VBA10;

Expand All @@ -19,20 +19,22 @@ using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Platform::Collections;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236


SelectFilePane::SelectFilePane(IVectorView<StorageFile^>^ list):initdone(false)
SelectFilePane::SelectFilePane(IVector<Platform::String^>^ list, Platform::String^ title):initdone(false)
{
InitializeComponent();
this->fileVector = ref new Vector<StorageFile^>();

//this->fileVector = ref new Vector<Platform::String^>();

for (int i = 0; i < list->Size; i++)
this->fileVector->Append(list->GetAt(i));
//for (int i = 0; i < list->Size; i++)
// this->fileVector->Append(list->GetAt(i));
this->txtTitle->Text = title;

this->FileListvs->Source = this->fileVector;
this->FileListvs->Source = list;
this->fileList->SelectedItem = nullptr;

if (list->Size > 0)
Expand All @@ -53,7 +55,8 @@ void SelectFilePane::fileList_SelectionChanged(Platform::Object^ sender, Windows
{
if (initdone)
{
StorageFile ^file = (StorageFile ^)(this->fileList->SelectedItem);
//StorageFile ^file = (StorageFile ^)(this->fileList->SelectedItem);
int selectedIndex = this->fileList->SelectedIndex;

//close the pane
auto dp = this->Parent;
Expand All @@ -62,7 +65,7 @@ void SelectFilePane::fileList_SelectionChanged(Platform::Object^ sender, Windows

//return the file to whatever windows that call it
if (this->FileSelectedCallback)
FileSelectedCallback(file);
FileSelectedCallback(selectedIndex);


}
Expand Down
12 changes: 4 additions & 8 deletions SelectFilePane.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@

#include "SelectFilePane.g.h"

using namespace Windows::Foundation::Collections;
using namespace Platform::Collections;
using namespace Windows::Storage;


namespace VBA10
{

public delegate void FileSelectedDelegate(StorageFile ^file);
public delegate void FileSelectedDelegate(int selectedIndex);

[Windows::Foundation::Metadata::WebHostHidden]
public ref class SelectFilePane sealed
{
public:
SelectFilePane(IVectorView<StorageFile^>^ list);
SelectFilePane(Windows::Foundation::Collections::IVector<Platform::String^>^ list, Platform::String^ Title);
property FileSelectedDelegate ^FileSelectedCallback;
private:
bool initdone;

Platform::Collections::Vector<StorageFile^>^ fileVector;

void Init(void);
//Platform::Collections::Vector<Platform::String^>^ fileVector;

void fileList_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
};
Expand Down
71 changes: 71 additions & 0 deletions SelectFilesPane.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<UserControl
x:Class="VBA10.SelectFilesPane"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VBA10"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="500"
d:DesignWidth="320">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
BorderThickness="2,0,2,2" BorderBrush="{ThemeResource ListBoxBorderThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.Resources>
<CollectionViewSource x:Name="FileListvs"/>
</Grid.Resources>


<StackPanel Background="{ThemeResource ListBoxBorderThemeBrush}"
VerticalAlignment="Stretch">
<TextBlock Text="Assigned at run time"
x:Name="txtTitle"
Style="{ThemeResource TitleTextBlockStyle}"
Margin="10,4,0,4"
/>
</StackPanel>

<TextBlock x:Name="txtNoFile" Grid.Row="1"
Text="No supported file found!"
Foreground="Red"
Margin="10,8,0,8"/>

<ListBox Name="fileList"
Background="Transparent"
ItemsSource="{Binding Source={StaticResource FileListvs}}"
Grid.Row="1"
SelectionMode="Multiple"
>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="10"/>
</Style>
</ListBox.ItemContainerStyle>

<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding}"
FontSize="18"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>


<Button Content="OK" Grid.Row="2"
Width="120"
HorizontalAlignment="Center"
Margin="0,4,0,4"
x:Name="OkBtn"
Click="OkBtn_Click"
/>

</Grid>
</UserControl>
Loading

0 comments on commit 58daff4

Please sign in to comment.