/* * WhackerLink - WhackerLinkConsoleV2 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Copyright (C) 2024 Caleb, K4PHP * */ using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace WhackerLinkConsoleV2.Controls { public partial class ChannelBox : UserControl { public string ChannelName { get; set; } public string SystemName { get; set; } public string TGID { get; set; } public event EventHandler PTTButtonClicked; private readonly SelectedChannelsManager _selectedChannelsManager; public bool IsEditMode { get; set; } private bool _isSelected; public bool IsSelected { get => _isSelected; set { _isSelected = value; UpdateBackground(); } } public ChannelBox(SelectedChannelsManager selectedChannelsManager, string channelName, string systemName, string tgid) { InitializeComponent(); DataContext = this; _selectedChannelsManager = selectedChannelsManager; ChannelName = channelName; SystemName = $"System: {systemName}"; TGID = $"TGID: {tgid}"; UpdateBackground(); MouseLeftButtonDown += ChannelBox_MouseLeftButtonDown; } private void ChannelBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (IsEditMode) return; IsSelected = !IsSelected; Background = IsSelected ? Brushes.Blue : Brushes.Gray; if (IsSelected) { _selectedChannelsManager.AddSelectedChannel(this); } else { _selectedChannelsManager.RemoveSelectedChannel(this); } } private void UpdateBackground() { Background = IsSelected ? Brushes.DodgerBlue : Brushes.DarkGray; } private void PTTButton_Click(object sender, RoutedEventArgs e) { PTTButtonClicked.Invoke(sender, this); } } }