Add settings func
This commit is contained in:
@@ -1,17 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using VisionAsist.Models;
|
using VisionAsist.Models;
|
||||||
|
using VisionAsist.Views;
|
||||||
|
|
||||||
namespace VisionAsist.ViewModels;
|
namespace VisionAsist.ViewModels;
|
||||||
|
|
||||||
public partial class MainWindowViewModel : ViewModelBase
|
public partial class MainWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
[RelayCommand]
|
||||||
|
private void Settingse()
|
||||||
|
{
|
||||||
|
new Settings
|
||||||
|
{
|
||||||
|
DataContext = new SettingsViewModel()
|
||||||
|
}.Show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isListening;
|
private bool isListening;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string recognizedtext;
|
private string recognizedtext;
|
||||||
private Action<string>? _coreHandler;
|
private Action<string>? _coreHandler;
|
||||||
|
|
||||||
partial void OnIsListeningChanged(bool value)
|
partial void OnIsListeningChanged(bool value)
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
|
|||||||
@@ -1,6 +1,44 @@
|
|||||||
namespace VisionAsist.ViewModels;
|
using System;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
namespace VisionAsist.ViewModels;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
public class ModuleItem
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public IRelayCommand SettingsCommand { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class SettingsViewModel : ViewModelBase
|
public class SettingsViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
string Plugin = Path.Combine(AppContext.BaseDirectory, "Modules");
|
||||||
|
public ObservableCollection<ModuleItem> Modules { get; } = new();
|
||||||
|
|
||||||
|
public SettingsViewModel()
|
||||||
|
{
|
||||||
|
string[] folderNames = new DirectoryInfo(Plugin)
|
||||||
|
.GetDirectories()
|
||||||
|
.Select(d => d.Name)
|
||||||
|
.ToArray();
|
||||||
|
foreach (string folderName in folderNames)
|
||||||
|
{
|
||||||
|
AddModule(folderName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddModule(string name)
|
||||||
|
{
|
||||||
|
Modules.Add(new ModuleItem
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
SettingsCommand = new RelayCommand(() => OpenSettings(name))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenSettings(string moduleName)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Нажата кнопка модуля: {moduleName}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<StackPanel Orientation="Horizontal" Margin="10">
|
<StackPanel Orientation="Horizontal" Margin="10">
|
||||||
<Button Content="Настройки"/>
|
<Button Content="Настройки" Command="{Binding SettingseCommand}"/>
|
||||||
<ToggleButton IsChecked="{Binding IsListening, Mode=TwoWay}"
|
<ToggleButton IsChecked="{Binding IsListening, Mode=TwoWay}"
|
||||||
Content="Запуск асистента"
|
Content="Запуск асистента"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
|
|||||||
@@ -11,7 +11,23 @@
|
|||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||||
<vm:MainWindowViewModel/>
|
<vm:SettingsViewModel/>
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
|
<ListBox ItemsSource="{Binding Modules}"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Stretch">
|
||||||
|
|
||||||
|
<ListBox.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="vm:ModuleItem">
|
||||||
|
<Border Background="DarkBlue" CornerRadius="5" Padding="10" Margin="5">
|
||||||
|
<Grid ColumnDefinitions="*,Auto">
|
||||||
|
<TextBlock Text="{Binding Name}" />
|
||||||
|
<Button Content="Settings"
|
||||||
|
Grid.Column="1"
|
||||||
|
Command="{Binding SettingsCommand}"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListBox.ItemTemplate>
|
||||||
|
</ListBox>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
Reference in New Issue
Block a user