Skip to content

Commit

Permalink
Merge pull request #26 from cinnamon-msft/hack/cazamor/file-picker
Browse files Browse the repository at this point in the history
Add a file picker
  • Loading branch information
cinnamon-msft authored Jul 30, 2020
2 parents bdd6195 + 6debfe8 commit 4b27b65
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
60 changes: 57 additions & 3 deletions src/TerminalSettings/TerminalSettings/Profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#include "Profiles.g.cpp"

using namespace winrt;
using namespace Windows::UI::Xaml;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Storage;
using namespace winrt::Windows::Storage::AccessCache;
using namespace winrt::Windows::Storage::Pickers;

namespace winrt::SettingsControl::implementation
{
Expand All @@ -24,10 +28,8 @@ namespace winrt::SettingsControl::implementation
return m_profileModel;
}


void Profiles::ClickHandler(IInspectable const&, RoutedEventArgs const&)
{

}

void Profiles::cursorColorPickerConfirmColor_Click(IInspectable const&, RoutedEventArgs const&)
Expand Down Expand Up @@ -69,4 +71,56 @@ namespace winrt::SettingsControl::implementation
{
//selectionBackgroundColorPickerButton.Flyout.Hide();
}

fire_and_forget Profiles::BackgroundImage_Click(IInspectable const&, RoutedEventArgs const&)
{
auto lifetime = get_strong();

FileOpenPicker picker;

picker.ViewMode(PickerViewMode::Thumbnail);
picker.SuggestedStartLocation(PickerLocationId::PicturesLibrary);
picker.FileTypeFilter().ReplaceAll({ L".jpg", L".jpeg", L".png", L".gif" });

StorageFile file = co_await picker.PickSingleFileAsync();
if (file != nullptr)
{
BackgroundImage().Text(file.Path());
}
}

fire_and_forget Profiles::Commandline_Click(IInspectable const&, RoutedEventArgs const&)
{
auto lifetime = get_strong();

FileOpenPicker picker;

picker.ViewMode(PickerViewMode::Thumbnail);
picker.SuggestedStartLocation(PickerLocationId::ComputerFolder);
picker.FileTypeFilter().ReplaceAll({ L".bat", L".exe" });

StorageFile file = co_await picker.PickSingleFileAsync();
if (file != nullptr)
{
Commandline().Text(file.Path());
}
}

/*
fire_and_forget Profiles::StartingDirectory_Click(IInspectable const&, RoutedEventArgs const&)
{
// This crashes on click, for some reason
auto lifetime = get_strong();
FolderPicker picker;
picker.SuggestedStartLocation(PickerLocationId::DocumentsLibrary);
StorageFolder folder = co_await picker.PickSingleFolderAsync();
if (folder != nullptr)
{
StorageApplicationPermissions::FutureAccessList().AddOrReplace(L"PickedFolderToken", folder);
StartingDirectory().Text(folder.Path());
}
}
*/
}
5 changes: 5 additions & 0 deletions src/TerminalSettings/TerminalSettings/Profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ namespace winrt::SettingsControl::implementation

private:
ObjectModel::ProfileModel m_profileModel{ nullptr };

public:
fire_and_forget BackgroundImage_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
fire_and_forget Commandline_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
//fire_and_forget StartingDirectory_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
};
}

Expand Down
11 changes: 7 additions & 4 deletions src/TerminalSettings/TerminalSettings/Profiles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="1" Grid.Column="0" Margin="0,0,100,0">
<TextBox Header="Command line" Margin="0,0,0,10" Text="{x:Bind ProfileModel.Profile.Commandline, Mode=TwoWay}"/>
<TextBox Header="Starting directory" Margin="0,0,0,10" Text="{x:Bind ProfileModel.Profile.StartingDirectory, Mode=TwoWay}"/>
<TextBox x:Name="Commandline" Header="Command line" Margin="0,0,0,10" Text="{x:Bind ProfileModel.Profile.Commandline, Mode=TwoWay}"/>
<Button Content="Browse" Click="Commandline_Click"/>
<TextBox x:Name="StartingDirectory" Header="Starting directory" Margin="0,0,0,10" Text="{x:Bind ProfileModel.Profile.StartingDirectory, Mode=TwoWay}"/>
<!--<Button Content="Browse" Click="StartingDirectory_Click"/>-->
<TextBox Header="Icon" Margin="0,0,0,10" Text="{x:Bind ProfileModel.Profile.Icon, Mode=TwoWay}"/>
<TextBox Header="Tab title" Margin="0,0,0,10" Text="{x:Bind ProfileModel.Profile.TabTitle, Mode=TwoWay}"/>
<Controls:RadioButtons Header="Scrollbar visibility" Margin="0,0,0,10">
Expand Down Expand Up @@ -163,8 +165,9 @@
<StackPanel Grid.Row="2" Grid.Column="0" Margin="0,0,100,0">
<CheckBox Content="Enable acrylic" IsChecked="{x:Bind ProfileModel.Profile.UseAcrylic, Mode=TwoWay}"/>
<Controls:NumberBox Header="Acrylic opacity" Margin="0,0,0,10" Value="{x:Bind ProfileModel.Profile.AcrylicOpacity, Mode=TwoWay}" SpinButtonPlacementMode="Compact" SmallChange="0.1" LargeChange="0.25" />
<TextBox Header="Background image" Margin="0,0,0,10" Text="{x:Bind ProfileModel.Profile.BackgroundImage, Mode=TwoWay}"/>
<Controls:RadioButtons Header="Background image stretch mode" Margin="0,0,0,10">
<TextBox x:Name="BackgroundImage" Header="Background image" Margin="0,0,0,10" Text="{x:Bind ProfileModel.Profile.BackgroundImage, Mode=TwoWay}"/>
<Button Content="Browse" Click="BackgroundImage_Click"/>
<Controls:RadioButtons Header="Background image stretch mode" Margin="0,0,0,10">
<RadioButton x:Name="backgroundImageStretchModeNone" Content="none"/>
<RadioButton x:Name="backgroundImageStretchModeFill" Content="fill"/>
<RadioButton x:Name="backgroundImageStretchModeUniform" Content="uniform"/>
Expand Down
14 changes: 9 additions & 5 deletions src/TerminalSettings/TerminalSettings/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
#include <unknwn.h>
#include <restrictederrorinfo.h>
#include <hstring.h>

#include <winrt/Microsoft.UI.Xaml.Controls.h>
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>

#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.AccessCache.h>
#include <winrt/Windows.Storage.Pickers.h>

#include <winrt/Windows.UI.h>
#include <winrt/Windows.UI.Xaml.h>
#include <winrt/Windows.UI.h>
#include <winrt/Windows.UI.Xaml.Media.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Controls.Primitives.h>
#include <winrt/Windows.UI.Xaml.Data.h>
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <winrt/Windows.UI.Xaml.Markup.h>
#include <winrt/Windows.UI.Xaml.Media.h>
#include <winrt/Windows.UI.Xaml.Navigation.h>
#include "winrt/Microsoft.UI.Xaml.Controls.h"
#include "winrt/Microsoft.UI.Xaml.XamlTypeInfo.h"

0 comments on commit 4b27b65

Please sign in to comment.