Skip to content

Commit c3cc094

Browse files
committed
clear current build report grid if fail to load new one, fix open build report row on double click, open build report row on Enter press, F5 to refresh build report, ctrl+c to copy buildreport selected row path (ref#49)
1 parent 6a33b3b commit c3cc094

File tree

2 files changed

+67
-16
lines changed

2 files changed

+67
-16
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@
852852

853853
<!-- Tab: Tools -->
854854
<TabItem Header="Tools" Style="{DynamicResource TabItemStyle1}" Padding="0,0,0,0" Margin="-1,1,1,-1" BorderBrush="{x:Null}" Background="Black">
855-
<Grid>
855+
<Grid PreviewKeyDown="Grid_PreviewKeyDown">
856856
<Grid.RowDefinitions>
857857
<RowDefinition Height="124" />
858858
<RowDefinition Height="50*" />
@@ -942,6 +942,10 @@
942942
</StackPanel>
943943

944944
<DataGrid x:Name="gridBuildReport" SelectionMode="Single" CanUserAddRows="False" Margin="4,30,2,0" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick">
945+
<DataGrid.CommandBindings>
946+
<CommandBinding Command="ApplicationCommands.Copy" Executed="CopyRowFolderToClipBoard" CanExecute="CanExecute_Copy"/>
947+
</DataGrid.CommandBindings>
948+
945949
<DataGrid.Columns>
946950
<DataGridTextColumn Binding="{Binding Size}" ClipboardContentBinding="{x:Null}" Header="Size" IsReadOnly="True" Width="75"/>
947951
<DataGridTextColumn Binding="{Binding Percentage}" ClipboardContentBinding="{x:Null}" Header="%" IsReadOnly="True" Width="55" />
@@ -953,6 +957,7 @@
953957
<DataGrid.ContextMenu>
954958
<ContextMenu>
955959
<MenuItem x:Name="menuItemExploreBuildItem" Header="Open Explorer here" Click="MenuItemExploreBuildItem_Click" />
960+
<MenuItem x:Name="menuItemCopyPathToClipboard" Header="Copy Path to clipboard" Click="menuItemCopyPathToClipboard_Click" />
956961
</ContextMenu>
957962
</DataGrid.ContextMenu>
958963

@@ -1064,7 +1069,7 @@
10641069
<Label Content="Reset" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
10651070
</Button>
10661071
</StackPanel>
1067-
1072+
10681073
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4" HorizontalAlignment="Left">
10691074
<TextBox x:Name="txtShortcutBatchFileFolder" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="150" ToolTip="Save generated .bat files here (they are run from Desktop Shortcut)" Padding="0,3,0,0" HorizontalAlignment="Left" MaxWidth="200" LostFocus="TxtShortcutBatchFileFolder_LostFocus" TextChanged="TxtShortcutBatchFileFolder_TextChanged" />
10701075
<Button Style="{StaticResource CustomButton}" x:Name="btnBrowseBatchFileFolder" Content="..." Margin="6,0,0,0" MinWidth="22" Click="BtnBrowseBatchFileFolder_Click" MinHeight="22" FontSize="16" ToolTip="Browse for .bat folder (default location is inside AppData/UnityLauncherPro/ and works fine, so this is optional)" HorizontalAlignment="Left" />

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public partial class MainWindow : Window
5353

5454
Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
5555

56-
string latestBuildReportProjectPath = null;
56+
string currentBuildReportProjectPath = null;
5757
List<List<string>> buildReports = new List<List<string>>();
5858
int currentBuildReport = 0;
5959

@@ -791,12 +791,11 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
791791
switch (e.Key)
792792
{
793793
case Key.F5: // refresh unitys
794-
UpdateUnityInstallationsList(); break;
794+
UpdateUnityInstallationsList();
795+
break;
795796
case Key.Escape: // clear project search
796797
txtSearchBoxUnity.Text = "";
797798
break;
798-
default: // any key
799-
break;
800799
}
801800
break;
802801

@@ -810,8 +809,6 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
810809
case Key.Escape: // clear project search
811810
txtSearchBoxUpdates.Text = "";
812811
break;
813-
default: // any key
814-
break;
815812
}
816813
break;
817814

@@ -822,8 +819,6 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
822819
case Key.Escape: // clear search
823820
txtSearchBoxBuildReport.Text = "";
824821
break;
825-
default: // any key
826-
break;
827822
}
828823
break;
829824
default:
@@ -1739,6 +1734,7 @@ private void ChkShowPlatform_Checked(object sender, RoutedEventArgs e)
17391734
public void CopyRowFolderToClipBoard(object sender, ExecutedRoutedEventArgs e)
17401735
{
17411736
string path = null;
1737+
17421738
if (tabControl.SelectedIndex == 0) // projects
17431739
{
17441740
path = GetSelectedProject()?.Path;
@@ -1751,9 +1747,18 @@ public void CopyRowFolderToClipBoard(object sender, ExecutedRoutedEventArgs e)
17511747
{
17521748
path = GetSelectedUpdate()?.Version; // TODO copy url instead
17531749
}
1754-
Console.WriteLine("CopyRowFolderToClipBoard=" + path);
1750+
else if (tabControl.SelectedIndex == 3) // tools
1751+
{
1752+
path = GetSelectedBuildItem().Path;
1753+
if (path != null) path = Path.Combine(currentBuildReportProjectPath, path);
1754+
}
17551755

1756-
if (string.IsNullOrEmpty(path) == false) Clipboard.SetText(path);
1756+
if (string.IsNullOrEmpty(path) == false)
1757+
{
1758+
// fix backslashes
1759+
path = path.Replace('\\', '/');
1760+
Clipboard.SetText(path);
1761+
}
17571762
}
17581763

17591764
public void CanExecute_Copy(object sender, CanExecuteRoutedEventArgs e)
@@ -1832,6 +1837,11 @@ private void GridRecent_ContextMenuOpening(object sender, ContextMenuEventArgs e
18321837
}));
18331838

18341839
private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
1840+
{
1841+
RefreshBuildReports();
1842+
}
1843+
1844+
void RefreshBuildReports()
18351845
{
18361846
currentBuildReport = 0;
18371847
buildReports.Clear();
@@ -1852,10 +1862,21 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
18521862
using (StreamReader sr = new StreamReader(fs))
18531863
{
18541864
bool collect = false;
1855-
// now we collect all lines, but could collect only those needed below
1865+
bool gotProjectPath = false;
1866+
18561867
while (!sr.EndOfStream)
18571868
{
18581869
var line = sr.ReadLine();
1870+
1871+
// get current projectpath
1872+
if (gotProjectPath == true)
1873+
{
1874+
currentBuildReportProjectPath = line;
1875+
gotProjectPath = false;
1876+
}
1877+
if (line == "-projectPath") gotProjectPath = true;
1878+
1879+
18591880
// build report starts, TODO collect report header also
18601881
if (collect == false && line.IndexOf("Used Assets and files from the Resources folder, sorted by uncompressed size:") == 0)
18611882
{
@@ -1882,12 +1903,16 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
18821903
}
18831904
catch (Exception)
18841905
{
1906+
gridBuildReport.ItemsSource = null;
1907+
gridBuildReport.Items.Clear();
18851908
Console.WriteLine("Failed to open editor log: " + logFile);
18861909
return;
18871910
}
18881911

18891912
if (buildReports.Count < 1 || buildReports[0].Count < 1)
18901913
{
1914+
gridBuildReport.ItemsSource = null;
1915+
gridBuildReport.Items.Clear();
18911916
Console.WriteLine("Failed to parse Editor.Log (probably no build reports there)");
18921917
return;
18931918
}
@@ -2260,11 +2285,9 @@ void OpenSelectedBuildReportFile()
22602285
{
22612286
var item = GetSelectedBuildItem();
22622287

2263-
Console.WriteLine(item.Path);
2264-
22652288
if (item != null)
22662289
{
2267-
string filePath = Path.Combine(latestBuildReportProjectPath, item.Path);
2290+
string filePath = Path.Combine(currentBuildReportProjectPath, item.Path);
22682291
Tools.LaunchExplorerSelectFile(filePath);
22692292
}
22702293
}
@@ -2517,6 +2540,29 @@ private void BtnBrowseBatchFileFolder_Click(object sender, RoutedEventArgs e)
25172540
}
25182541
}
25192542

2543+
private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
2544+
{
2545+
switch (e.Key)
2546+
{
2547+
case Key.F5: // update build reports
2548+
e.Handled = true;
2549+
RefreshBuildReports();
2550+
break;
2551+
case Key.Return: // open build report
2552+
e.Handled = true;
2553+
OpenSelectedBuildReportFile();
2554+
break;
2555+
}
2556+
}
2557+
2558+
private void menuItemCopyPathToClipboard_Click(object sender, RoutedEventArgs e)
2559+
{
2560+
var path = GetSelectedBuildItem().Path;
2561+
if (path != null) path = Path.Combine(currentBuildReportProjectPath, path);
2562+
path = path.Replace('\\', '/');
2563+
Clipboard.SetText(path);
2564+
}
2565+
25202566
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
25212567
//{
25222568
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");

0 commit comments

Comments
 (0)