Add button interactions

This commit is contained in:
2021-12-04 13:31:20 +01:00
parent 0d2f2a6653
commit 5d761a5920
4 changed files with 61 additions and 15 deletions

View File

@@ -29,7 +29,6 @@
<!--Working Directory--> <!--Working Directory-->
<TextBlock Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" Text="Working Directory:" /> <TextBlock Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" Text="Working Directory:" />
<TextBox Grid.Column="1" Grid.Row="2" Margin="5" VerticalContentAlignment="Center" Text="{Binding ApplicationWorkingDirectory}" /> <TextBox Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Margin="5" VerticalContentAlignment="Center" Text="{Binding ApplicationWorkingDirectory}" />
<Button Grid.Column="2" Grid.Row="2" Margin="5" Padding="5,2" Content="Browse" Click="Button_WorkingDirectory" />
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -11,7 +12,7 @@ using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using Microsoft.Win32;
namespace ExeLauncher.GUI namespace ExeLauncher.GUI
{ {
@@ -59,12 +60,20 @@ namespace ExeLauncher.GUI
private void Button_Path(object sender, RoutedEventArgs e) private void Button_Path(object sender, RoutedEventArgs e)
{ {
var dialog = new OpenFileDialog()
}
private void Button_WorkingDirectory(object sender, RoutedEventArgs e)
{ {
AddExtension = true,
DefaultExt = ".exe",
FileName = "Run.exe",
Filter = "Executable|*.exe"
};
if (dialog.ShowDialog() == true)
{
ApplicationPath = dialog.FileName;
ApplicationWorkingDirectory = Path.GetDirectoryName(ApplicationPath) ?? "";
}
} }
} }
} }

View File

@@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
@@ -19,10 +21,41 @@ namespace ExeLauncher.GUI
/// <summary> /// <summary>
/// Interaction logic for MainWindow.xaml /// Interaction logic for MainWindow.xaml
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window, INotifyPropertyChanged
{ {
public string ApplicationName { get; set; } = ""; public event PropertyChangedEventHandler? PropertyChanged;
public string ApplicationIconPath { get; set; } = "";
private string _appName = "";
public string ApplicationName
{
get => _appName;
set
{
if (_appName != value)
{
_appName = value;
NotifyPropertyChanged();
}
}
}
private string _applicationIconPath = "";
public string ApplicationIconPath
{
get => _applicationIconPath;
set
{
if (_applicationIconPath != value)
{
_applicationIconPath = value;
NotifyPropertyChanged();
}
}
}
public ObservableCollection<ApplicationModel> Applications { get; set; } public ObservableCollection<ApplicationModel> Applications { get; set; }
@@ -38,7 +71,7 @@ namespace ExeLauncher.GUI
private void Button_Icon(object sender, RoutedEventArgs e) private void Button_Icon(object sender, RoutedEventArgs e)
{ {
ApplicationIconPath = Program.GetIcon();
} }
private void Button_Add(object sender, RoutedEventArgs e) private void Button_Add(object sender, RoutedEventArgs e)
@@ -53,5 +86,10 @@ namespace ExeLauncher.GUI
Applications.RemoveAt(Applications.Count - 1); Applications.RemoveAt(Applications.Count - 1);
} }
} }
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
} }
} }

View File

@@ -8,7 +8,7 @@ using System.Windows.Forms;
namespace ExeLauncher namespace ExeLauncher
{ {
class Program public class Program
{ {
const string Paths = "%Paths%"; const string Paths = "%Paths%";
const string Arguments = "%Arguments%"; const string Arguments = "%Arguments%";
@@ -62,7 +62,7 @@ namespace ExeLauncher
Console.ReadKey(true); Console.ReadKey(true);
} }
private static void CreateExecutable(string location, string paths, string arguments, string workingDirectories, string icon) public static void CreateExecutable(string location, string paths, string arguments, string workingDirectories, string icon)
{ {
code = code.Replace(Paths, paths); code = code.Replace(Paths, paths);
code = code.Replace(Arguments, arguments); code = code.Replace(Arguments, arguments);
@@ -92,7 +92,7 @@ namespace ExeLauncher
} }
} }
private static string GetIcon() public static string GetIcon()
{ {
var dialog = new OpenFileDialog() var dialog = new OpenFileDialog()
{ {
@@ -108,7 +108,7 @@ namespace ExeLauncher
return ""; return "";
} }
private static string GetLocation() public static string GetLocation()
{ {
var dialog = new SaveFileDialog() var dialog = new SaveFileDialog()
{ {