Skip to content

Commit

Permalink
Partly implemented #8: Copy Dockerfile, Export Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryGolubenkov committed Jan 15, 2023
1 parent be0be66 commit b35e2a0
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 28 deletions.
10 changes: 9 additions & 1 deletion src/SharpDockerizer.AvaloniaUI/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
xmlns:themes="clr-namespace:Material.Styles.Themes;assembly=Material.Styles"
>
<Application.Styles>
<StyleInclude Source="avares://DialogHost.Avalonia/Styles.xaml"/>
<StyleInclude Source="avares://Material.Icons.Avalonia/App.xaml" />
<themes:MaterialTheme BaseTheme="Dark" PrimaryColor="Purple" SecondaryColor="Lime" />
<StyleInclude Source="avares://Material.DataGrid/DataGrid.xaml" />


<Style Selector="Button.Topbar">
<Setter Property="Foreground" Value="White" />
<Setter Property="Height" Value="35" />
<Setter Property="Width" Value="35" />
<Setter Property="CornerRadius" Value="35" />
</Style>

</Application.Styles>
</Application>
2 changes: 1 addition & 1 deletion src/SharpDockerizer.AvaloniaUI/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using System;

namespace SharpDockerizer.AvaloniaUI;
public partial class App : Application
{
Expand All @@ -36,6 +35,7 @@ public override void OnFrameworkInitializationCompleted()
desktop.MainWindow = new MainWindow();
}
Log.Information("Application started");

base.OnFrameworkInitializationCompleted();
}

Expand Down
5 changes: 2 additions & 3 deletions src/SharpDockerizer.AvaloniaUI/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
x:Class="SharpDockerizer.AvaloniaUI.MainWindow"
Title="SharpDockerizer"
>
<DockPanel>
<DockPanel>
<views:TopBar DockPanel.Dock="Top" />
<SplitView IsPaneOpen="true"
DisplayMode="Inline"
Expand All @@ -17,9 +17,8 @@
<SplitView.Pane>
<views:SolutionViewer/>
</SplitView.Pane>

<views:DockerfileGenerator />
</SplitView>

</DockPanel>
</Window>
6 changes: 5 additions & 1 deletion src/SharpDockerizer.AvaloniaUI/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using Avalonia;
using Avalonia.Controls;

namespace SharpDockerizer.AvaloniaUI;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

#if DEBUG
this.AttachDevTools();
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview4" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-preview4" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0-preview2" />
<PackageReference Include="DialogHost.Avalonia" Version="0.7.0-preview2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0-preview3" />
<PackageReference Include="Material.Avalonia" Version="3.0.0-avalonia11-preview2.137-nightly" />
<PackageReference Include="Material.Icons.Avalonia" Version="1.2.0" />
<PackageReference Include="Material.Icons.Avalonia" Version="1.2.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Serilog" Version="2.12.1-dev-01635" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.1-dev-10301" />
Expand All @@ -33,5 +32,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />
<Folder Include="Interfaces\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using Avalonia;
using System.IO;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform.Storage;

namespace SharpDockerizer.AvaloniaUI.ViewModels;
[INotifyPropertyChanged]
Expand All @@ -23,6 +27,8 @@ internal partial class DockerfileGeneratorViewModel
private string? _selectedProjectName;
[ObservableProperty]
private string? _generatedDockerfile;
[ObservableProperty]
private bool _dockerfileWasGenerated;

public ObservableCollection<ExposedPort> ExposedPorts { get; set; } = new ObservableCollection<ExposedPort>()
{
Expand All @@ -45,15 +51,16 @@ internal partial class DockerfileGeneratorViewModel

#region Constructor

public DockerfileGeneratorViewModel(IDockerfileGenerator dockerfileGenerator,
IMessenger messenger,
ISolutionUpdater solutionUpdater,
public DockerfileGeneratorViewModel(IDockerfileGenerator dockerfileGenerator,
IMessenger messenger,
ISolutionUpdater solutionUpdater,
ICurrentSolutionInfo currentSolutionInfo)
{
_dockerfileGenerator = dockerfileGenerator;
_messenger = messenger;
_solutionUpdater = solutionUpdater;
_currentSolutionInfo = currentSolutionInfo;

_messenger.Register<ProjectSelectedEvent>(this, OnProjectSelectedHandler);
}

Expand Down Expand Up @@ -92,7 +99,7 @@ public async Task GenerateDockerfile()

Log.Information($"Solution was changed: {solutionChanged}");
// If selected project data changed - refresh data
if(solutionChanged)
if (solutionChanged)
{
var newData = _currentSolutionInfo.Projects.FirstOrDefault(project => project.ProjectName == _selectedProjectData.ProjectName);

Expand Down Expand Up @@ -121,6 +128,7 @@ public async Task GenerateDockerfile()

// Display result
GeneratedDockerfile = result;
DockerfileWasGenerated = true;
}

[RelayCommand]
Expand Down Expand Up @@ -156,5 +164,56 @@ public void RemoveNuGetSource(object source)
OnPropertyChanged(nameof(NuGetSources));
}

[RelayCommand]
public async Task CopyToClipboard()
{
if (GeneratedDockerfile is null)
return;

await Application.Current.Clipboard.SetTextAsync(GeneratedDockerfile);

// TODO: Notification
}

[RelayCommand]
public async Task SaveToProjectFolder()
{
if (GeneratedDockerfile is null)
return;

await File.WriteAllTextAsync(
Path.Combine(Path.GetDirectoryName(_selectedProjectData.AbsolutePathToProjFile), "Dockerfile"),
GeneratedDockerfile);

// TODO: Dialog "Overwrite existing file?"
// TODO: Notification
}

[RelayCommand]
public async Task SaveToChosenFolder()
{
// TODO: Fix some bug with Downloads folder
if (Application.Current.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
return;
}

var result = await desktopLifetime.MainWindow.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions()
{
Title = "Choose folder, where Dockerfile will be saved",
AllowMultiple = false,
});

if (result[0].TryGetUri(out var pathUri))
{
await File.WriteAllTextAsync(
Path.Combine(pathUri.AbsolutePath, "Dockerfile"),
GeneratedDockerfile);
}

// TODO: Dialog "Overwrite existing file?"
// TODO: Notification
}

#endregion
}
34 changes: 25 additions & 9 deletions src/SharpDockerizer.AvaloniaUI/Views/DockerfileGenerator.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
>

<ScrollViewer Grid.Column="0">
<DockPanel Margin="8" LastChildFill="False">
<DockPanel Margin="10" LastChildFill="False">
<!-- Header -->
<Border DockPanel.Dock="Top"
BorderBrush="{DynamicResource MaterialDesignCardBackground}"
BorderThickness="0,0,0,1"
<Border DockPanel.Dock="Top"
BorderBrush="{DynamicResource MaterialDesignCardBackground}"
BorderThickness="0,0,0,1"
Margin="0,0,0,8"
HorizontalAlignment="Stretch">
<WrapPanel>
Expand All @@ -34,7 +34,7 @@
</Border>

<!-- Exposed ports part -->
<Expander Header="Exposed ports"
<Expander Header="Exposed ports"
Margin="0,0,0,8"
HorizontalAlignment="Stretch"
DockPanel.Dock="Top">
Expand Down Expand Up @@ -67,7 +67,7 @@
</Expander>

<!-- Nuget sources part -->
<Expander Header="NuGet sources"
<Expander Header="NuGet sources"
Margin="0,0,0,8"
HorizontalAlignment="Stretch"
DockPanel.Dock="Top">
Expand Down Expand Up @@ -123,13 +123,29 @@
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<Border DockPanel.Dock="Top" BorderBrush="{DynamicResource MaterialDesignCardBackground}" BorderThickness="0,0,0,1">
<WrapPanel>
<mati:MaterialIcon Kind="Docker" />
<DockPanel DockPanel.Dock="Top" LastChildFill="False">
<mati:MaterialIcon Kind="Docker" DockPanel.Dock="Left" />
<TextBlock
DockPanel.Dock="Left"
Margin="8"
FontSize="16">Generated Dockerfile</TextBlock>
</WrapPanel>


<Button IsEnabled="{Binding DockerfileWasGenerated}" Classes="Flat Light Topbar" DockPanel.Dock="Right" Command="{Binding CopyToClipboard}" ToolTip.Tip="Copy to clipboard">
<mati:MaterialIcon Kind="ContentCopy" />
</Button>
<Button IsEnabled="{Binding DockerfileWasGenerated}" Classes="Flat Light Topbar" DockPanel.Dock="Right" Command="{Binding SaveToChosenFolder}" ToolTip.Tip="Save to..">
<mati:MaterialIcon Kind="ContentSave" />
</Button>
<Button IsEnabled="{Binding DockerfileWasGenerated}" Classes="Flat Light Topbar" DockPanel.Dock="Right" Command="{Binding SaveToProjectFolder}" ToolTip.Tip="Save to project folder">
<mati:MaterialIcon Kind="FileExport" />
</Button>
</DockPanel>
</Border>




<TextBox
DockPanel.Dock="Top"
Text="{Binding GeneratedDockerfile}"
Expand Down
7 changes: 1 addition & 6 deletions src/SharpDockerizer.AvaloniaUI/Views/SolutionViewer.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
DockPanel.Dock="Left">Solution Viewer</TextBlock>
<Button Command="{Binding RefreshSolution}"
DockPanel.Dock="Right"
Background="Transparent"
IsVisible="{Binding IsSolutionLoaded}"
Classes="Flat Light"
Foreground="White"
Padding="4"
Height="25"
Width="25"
Classes="Flat Light Topbar"
>
<mati:MaterialIcon Kind="Refresh" ToolTip.Tip="Refresh Solution" />
</Button>
Expand Down

0 comments on commit b35e2a0

Please sign in to comment.