Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  refresh projects after adding Unity editors, started adding project properties window (not used yet),
  new project: add warning if projectname starts or ends with Space character
  change/optimize GetElapsedTime #54
  simplified Project.ToString() override (its not needed anywhere, but WPF keeps calling it) #54
  remove unnecessary FindDir/DirectoryInfo scan #54
  avoid calling checkbox checked setting save code at startup (#54)
  after sorting columns: scroll view to selected row
  • Loading branch information
unitycoder committed Feb 13, 2024
2 parents 4a1226e + 45d981a commit ee58811
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 76 deletions.
9 changes: 8 additions & 1 deletion UnityLauncherPro/Data/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ public class Project : IValueConverter
public string[] TargetPlatforms { set; get; }
public bool folderExists { set; get; }

// WPF keeps calling this method from AppendFormatHelper, GetNameCore..? not sure if need to return something else or default would be faster?
public override string ToString()
{
return $"{Title} {Version} {Path} {Modified} {Arguments} {GITBranch} {TargetPlatform}";
return Path;
}

// for debugging
//public override string ToString()
//{
// return $"{Title} {Version} {Path} {Modified} {Arguments} {GITBranch} {TargetPlatform}";
//}

// change datagrid colors based on value using converter https://stackoverflow.com/a/5551986/5452781
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Expand Down
1 change: 1 addition & 0 deletions UnityLauncherPro/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
</MenuItem>
<Separator/>
<MenuItem x:Name="menuRemoveProject" Header="Remove from recent list" Click="MenuRemoveProject_Click" />
<!--<MenuItem x:Name="menuProjectProperties" Header="Properties..." Click="menuProjectProperties_Click" />-->
</ContextMenu>
</DataGrid.ContextMenu>

Expand Down
71 changes: 57 additions & 14 deletions UnityLauncherPro/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,13 @@ private void SaveSettingsOnExit()

void UpdateUnityInstallationsList()
{
// reset preferred string, if user changed it
// Reset preferred string, if user changed it
//preferredVersion = "none";

unityInstallationsSource = GetUnityInstallations.Scan();
dataGridUnitys.ItemsSource = unityInstallationsSource;

// also make dictionary of installed unitys, to search faster
// Also make dictionary of installed unitys, to search faster
unityInstalledVersions.Clear();

for (int i = 0, len = unityInstallationsSource.Count; i < len; i++)
Expand Down Expand Up @@ -725,6 +725,7 @@ void AddUnityInstallationRootFolder()
lstRootFolders.Items.Refresh();
Properties.Settings.Default.Save();
UpdateUnityInstallationsList();
RefreshRecentProjects();
}
}

Expand Down Expand Up @@ -1526,12 +1527,16 @@ private void BtnOpenWebsite_Click(object sender, RoutedEventArgs e)

private void ChkMinimizeToTaskbar_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.minimizeToTaskbar = (bool)chkMinimizeToTaskbar.IsChecked;
Settings.Default.Save();
}

private void ChkRegisterExplorerMenu_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

if ((bool)chkRegisterExplorerMenu.IsChecked)
{
Tools.AddContextMenuRegistry(contextRegRoot);
Expand All @@ -1548,6 +1553,7 @@ private void ChkRegisterExplorerMenu_CheckedChanged(object sender, RoutedEventAr
private void ChkShowLauncherArgumentsColumn_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.showArgumentsColumn = (bool)chkShowLauncherArgumentsColumn.IsChecked;
Settings.Default.Save();
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
Expand All @@ -1557,6 +1563,7 @@ private void ChkShowLauncherArgumentsColumn_CheckedChanged(object sender, Routed
private void ChkShowGitBranchColumn_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.showGitBranchColumn = (bool)chkShowGitBranchColumn.IsChecked;
Settings.Default.Save();
gridRecent.Columns[5].Visibility = (bool)chkShowGitBranchColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
Expand All @@ -1565,12 +1572,16 @@ private void ChkShowGitBranchColumn_CheckedChanged(object sender, RoutedEventArg

private void ChkQuitAfterOpen_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.closeAfterProject = (bool)chkQuitAfterOpen.IsChecked;
Settings.Default.Save();
}

private void ChkQuitAfterCommandline_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.closeAfterExplorer = (bool)chkQuitAfterCommandline.IsChecked;
Settings.Default.Save();
}
Expand Down Expand Up @@ -1793,12 +1804,16 @@ private void DataGridUpdates_PreviewMouseDoubleClick(object sender, MouseButtonE

private void ChkShowMissingFolderProjects_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.showProjectsMissingFolder = (bool)chkShowMissingFolderProjects.IsChecked;
Settings.Default.Save();
}

private void ChkAllowSingleInstanceOnly_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.AllowSingleInstanceOnly = (bool)chkAllowSingleInstanceOnly.IsChecked;
Settings.Default.Save();
}
Expand Down Expand Up @@ -1966,17 +1981,21 @@ void CreateNewEmptyProject(string targetFolder = null)

private void ChkAskNameForQuickProject_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.askNameForQuickProject = (bool)chkAskNameForQuickProject.IsChecked;
Properties.Settings.Default.Save();
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.askNameForQuickProject = (bool)chkAskNameForQuickProject.IsChecked;
Settings.Default.Save();
}

bool isInitializing = true; // used to avoid doing things while still starting up
private void ChkStreamerMode_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

Properties.Settings.Default.streamerMode = isChecked;
Properties.Settings.Default.Save();
Settings.Default.streamerMode = isChecked;
Settings.Default.Save();

// Create cellstyle and assign if streamermode is enabled
Style cellStyle = new Style(typeof(DataGridCell));
Expand All @@ -1999,6 +2018,8 @@ private void ChkStreamerMode_Checked(object sender, RoutedEventArgs e)

private void ChkShowPlatform_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

Settings.Default.showTargetPlatform = isChecked;
Expand Down Expand Up @@ -2072,6 +2093,8 @@ public void MoveRecentGridItem(int to)

private void ChkEnableProjectRename_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Properties.Settings.Default.enableProjectRename = (bool)chkEnableProjectRename.IsChecked;
Properties.Settings.Default.Save();
}
Expand Down Expand Up @@ -2565,8 +2588,8 @@ private void ChkUseCustomTheme_Checked(object sender, RoutedEventArgs e)
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;
Properties.Settings.Default.useCustomTheme = isChecked;
Properties.Settings.Default.Save();
Settings.Default.useCustomTheme = isChecked;
Settings.Default.Save();

btnReloadTheme.IsEnabled = isChecked;

Expand Down Expand Up @@ -2616,9 +2639,11 @@ private void BtnExploreFolder_Click(object sender, RoutedEventArgs e)

private void ChkEnablePlatformSelection_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;
Properties.Settings.Default.enablePlatformSelection = isChecked;
Properties.Settings.Default.Save();
Settings.Default.enablePlatformSelection = isChecked;
Settings.Default.Save();
chkEnablePlatformSelection.IsChecked = isChecked;
}

Expand All @@ -2642,9 +2667,10 @@ private void CmbPlatformSelection_DropDownClosed(object sender, EventArgs e)
private void ChkRunAutomatically_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;
Properties.Settings.Default.runAutomatically = isChecked;
Properties.Settings.Default.Save();
Settings.Default.runAutomatically = isChecked;
Settings.Default.Save();
chkRunAutomatically.IsChecked = isChecked;
// set or unset registry, NOTE should not do this on debug build.. (otherwise 2 builds try to run?)
Tools.SetStartupRegistry(isChecked);
Expand Down Expand Up @@ -2741,6 +2767,7 @@ bool ValidateIntRange(TextBox textBox, int min, int max)
private void ChkHumanFriendlyDateTime_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

// cannot have both date formats
Expand Down Expand Up @@ -2796,6 +2823,7 @@ void OpenSelectedBuildReportFile()
private void ChkRunAutomaticallyMinimized_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

Settings.Default.runAutomaticallyMinimized = isChecked;
Expand Down Expand Up @@ -2974,6 +3002,7 @@ private void Window_SourceInitialized(object sender, EventArgs e)
private void ChkSearchProjectPath_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

searchProjectPathAlso = isChecked;
Expand Down Expand Up @@ -3011,6 +3040,7 @@ private void MenuBatchBuildIOS_Click(object sender, RoutedEventArgs e)
private void ChkCheckPlasticBranch_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.checkPlasticBranch = (bool)chkCheckPlasticBranch.IsChecked;
Settings.Default.Save();
RefreshRecentProjects();
Expand Down Expand Up @@ -3087,7 +3117,6 @@ void SortHandlerUpdates(object sender, DataGridSortingEventArgs e)
{
DataGridColumn column = e.Column;


IComparer comparer = null;

// prevent the built-in sort from sorting
Expand Down Expand Up @@ -3179,6 +3208,14 @@ void SortHandlerRecentProjects(object sender, DataGridSortingEventArgs e)

//apply the sort
lcv.CustomSort = comparer;

if (gridRecent.SelectedItem != null)
{
// scroll view to selected, after sort
gridRecent.ScrollIntoView(gridRecent.SelectedItem);
// needed for keyboard to work in grid
gridRecent.Focus();
}
}

public class CustomProjectSort : IComparer
Expand Down Expand Up @@ -3308,7 +3345,7 @@ private void btnPatchHubConfig_Click(object sender, RoutedEventArgs e)
// replace the manual:true with manual:false using regex
json = json.Replace("\"manual\":true", "\"manual\":false");

Console.WriteLine(json);
//Console.WriteLine(json);

// write the config file
File.WriteAllText(configFile, json);
Expand Down Expand Up @@ -3556,6 +3593,12 @@ private void btnHubLogs_Click(object sender, RoutedEventArgs e)
Tools.OpenAppdataSpecialFolder("../Roaming/UnityHub/logs/");
}

//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
//{
// var proj = GetSelectedProject();
// if (proj == null) return;
// Tools.DisplayProjectProperties(proj, this);
//}
} // class
} //namespace

13 changes: 11 additions & 2 deletions UnityLauncherPro/NewProject.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UnityLauncherPro"
mc:Ignorable="d"
Title="Create New Project" Height="460" Width="450" Background="{DynamicResource ThemeDarkestBackground}" PreviewKeyDown="Window_PreviewKeyDown" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" ShowInTaskbar="True">
Title="Create New Project" Height="480" Width="450" Background="{DynamicResource ThemeDarkestBackground}" PreviewKeyDown="Window_PreviewKeyDown" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" ShowInTaskbar="True">

<Grid>
<StackPanel Margin="10,3">
Expand All @@ -24,7 +24,7 @@
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="40*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Project Name:" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0" Padding="0,5,5,0" />
<Label x:Name="lblNewProjectNameLabel" Grid.Column="0" Content="Project Name:" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0" Padding="0,5,5,0" />
<Label Grid.Column="1" Content="Platform:" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0" Padding="0,5,0,0" />
<Label x:Name="lblTemplateTitleAndCount" Grid.Column="2" Content="Templates:" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0" Padding="5,5,5,0" />
</Grid>
Expand Down Expand Up @@ -53,6 +53,15 @@
<Label Content="_Create" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"/>
</Button>
</Grid>

<Grid Grid.Row="2" UseLayoutRounding="False">
<StatusBar VerticalAlignment="Center" Background="{x:Null}" Foreground="{DynamicResource ThemeStatusText}">
<StatusBarItem>
<TextBlock x:Name="txtNewProjectStatus" VerticalAlignment="Center" Text=""/>
</StatusBarItem>
</StatusBar>
</Grid>

</StackPanel>
</Grid>
</Window>
19 changes: 18 additions & 1 deletion UnityLauncherPro/NewProject.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -217,6 +218,22 @@ private void TxtNewProjectName_TextChanged(object sender, TextChangedEventArgs e
{
if (isInitializing == true) return;

// warning yellow if contains space at start or end
if (txtNewProjectName.Text.StartsWith(" ") || txtNewProjectName.Text.EndsWith(" "))
{
// NOTE txtbox outline didnt work
txtNewProjectName.Background = Brushes.Yellow;
txtNewProjectStatus.Text = "Warning: Project name starts or ends with SPACE character";
txtNewProjectStatus.Foreground = Brushes.Orange;
}
else
{
// NOTE this element is not using themes yet, so can set white
txtNewProjectName.Background = Brushes.White;
txtNewProjectStatus.Foreground = Brushes.White;
txtNewProjectStatus.Text = "";
}

// validate new projectname that it doesnt exists already
var targetPath = Path.Combine(targetFolder, txtNewProjectName.Text);
if (Directory.Exists(targetPath) == true)
Expand Down
38 changes: 38 additions & 0 deletions UnityLauncherPro/ProjectProperties.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Window x:Class="UnityLauncherPro.ProjectProperties"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UnityLauncherPro"
mc:Ignorable="d"
Title="Project Properties" Height="480" Width="450" Background="{DynamicResource ThemeDarkestBackground}" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" ShowInTaskbar="True" PreviewKeyDown="Window_PreviewKeyDown">

<Grid>
<StackPanel Margin="10,3">
<Label Content="Custom environment variables:" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,3" Padding="5,5,5,3" />
<TextBox x:Name="txtCustomEnvVariables" IsUndoEnabled="True" TextChanged="txtCustomEnvVariables_TextChanged" PreviewKeyDown="txtCustomEnvVariables_PreviewKeyDown" TabIndex="0" Width="320" Text="JAVA_HOME=C:\Program Files\Java\jdk1.8.0_202" />

<Grid HorizontalAlignment="Stretch" Margin="0,8,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnCloseProperties" Margin="0,0,3,3" BorderBrush="{x:Null}" VerticalAlignment="Top" Height="35" TabIndex="4" Click="btnCloseProperties_Click" >
<Label Content="Cancel" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"/>
</Button>
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnApplyProperties" Margin="0,0,3,3" BorderBrush="{x:Null}" VerticalAlignment="Top" Height="35" TabIndex="4" Click="btnApplyProperties_Click" >
<Label Content="Apply" Foreground="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"/>
</Button>
</Grid>

<!--<DataGrid x:Name="gridEnvVariables" SelectionMode="Single" Height="88" Margin="10,121,10,0" VerticalAlignment="Top" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" PreviewKeyDown="GridAvailableVersions_PreviewKeyDown" Loaded="GridAvailableVersions_Loaded" PreviewMouseDoubleClick="GridAvailableVersions_PreviewMouseDoubleClick" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Variable" Binding="{Binding Version}" IsReadOnly="True" CanUserResize="False" MinWidth="80" />
<DataGridTextColumn Header="Value" Binding="{Binding PlatformsCombined}" IsReadOnly="True" CanUserResize="False" MinWidth="270" />
</DataGrid.Columns>
</DataGrid>-->


</StackPanel>
</Grid>
</Window>
Loading

0 comments on commit ee58811

Please sign in to comment.