public AutoSwitchConfigsViewModel(List <AutoSwitchConfig> autoSwitchConfigs, IKvmSwitchEnvironment environment)
        {
            this.environment = environment;

            this.AddConfigCommand = new RelayCommand(args =>
            {
                var newConfig = this.CreateAutoSwitchConfigViewModel(new AutoSwitchConfig {
                    Name = "New"
                });
                this.AutoSwitchConfigs.Add(newConfig);

                this.SelectedAutoSwitchConfigViewModel = newConfig;
            });

            this.DeleteConfigCommand = new RelayCommand(
                args => { this.AutoSwitchConfigs.Remove(this.SelectedAutoSwitchConfigViewModel); },
                x => this.SelectedAutoSwitchConfigViewModel != null);

            this.AutoSwitchConfigs = new ObservableCollection <AutoSwitchConfigViewModel>();
            foreach (var config in autoSwitchConfigs)
            {
                this.AutoSwitchConfigs.Add(this.CreateAutoSwitchConfigViewModel(config));
            }

            this.SelectedAutoSwitchConfigViewModel = this.AutoSwitchConfigs.FirstOrDefault();
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="AutomaticMonitorSwitcher" /> class.
 /// </summary>
 /// <param name="environment">The environment.</param>
 public AutomaticMonitorSwitcher(IKvmSwitchEnvironment environment)
 {
     this.environment = environment;
     this.environment.ConfigChanged += this.EnvironmentOnConfigChanged;
     environment.UsbDeviceMonitor.UsbDeviceConnected += this.UsbDeviceMonitorOnUsbDeviceConnected;
     environment.UsbDeviceMonitor.UsbDeviceRemoved   += this.UsbDeviceMonitorOnUsbDeviceRemoved;
     this.AssignAutoSwitchConfig();
 }
Пример #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ConfigWindowModel" /> class.
        /// </summary>
        public ConfigWindowModel(IKvmSwitchEnvironment environment)
        {
            this.environment                = environment;
            this.GeneralConfigViewModel     = new GeneralConfigViewModel(environment.Config);
            this.AutoSwitchConfigsViewModel = new AutoSwitchConfigsViewModel(environment.Config.AutoSwitchConfigs, environment);

            this.SaveCommand   = new RelayCommand(window => this.SaveConfiguration((Window)window));
            this.CancelCommand = new RelayCommand(window => Cancel((Window)window));
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="AutoSwitchConfigViewModel" /> class.
        /// </summary>
        /// <param name="autoSwitchConfig">The automatic switch configuration.</param>
        /// <param name="environment"></param>
        public AutoSwitchConfigViewModel(AutoSwitchConfig autoSwitchConfig, IKvmSwitchEnvironment environment)
        {
            this.environment = environment;
            this.Name        = autoSwitchConfig.Name;
            this.Active      = autoSwitchConfig.Active;
            this.ExecuteOnUsbDeviceConnected    = autoSwitchConfig.ExecuteOnUsbDeviceConnected;
            this.ExecuteOnUsbDeviceDisconnected = autoSwitchConfig.ExecuteOnUsbDeviceDisconnected;

            this.InitUsbDevices(autoSwitchConfig);

            // Displays
            var supportedMonitorSources = environment.DisplayDataChannel.GetSupportedSourcesOfMonitors();

            this.MonitorInfos = new List <MonitorInfo>();

            for (var monitorIndex = 0; monitorIndex < supportedMonitorSources.Count; ++monitorIndex)
            {
                var monitorInfo = new MonitorInfo
                {
                    MonitorIndex   = monitorIndex,
                    MonitorSources = supportedMonitorSources[monitorIndex]
                };

                var existingMonitorConfig =
                    autoSwitchConfig.MonitorConfigs?.FirstOrDefault(x => x.Name == monitorInfo.Name);


                MonitorSource monitorSource = null;

                if (existingMonitorConfig != null)
                {
                    monitorSource =
                        monitorInfo.MonitorSources.FirstOrDefault(x => x.Name == existingMonitorConfig.Input);
                    monitorInfo.UseInProfile = true;
                }


                if (monitorSource == null)
                {
                    monitorSource = monitorInfo.MonitorSources.FirstOrDefault();
                }

                monitorInfo.SelectedMonitorSource = monitorSource;
                this.MonitorInfos.Add(monitorInfo);
            }
        }
Пример #5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Current.DispatcherUnhandledException += this.Current_DispatcherUnhandledException;

            this.environment = new KvmSwitchEnvironment();
            this.environment.Initialize();

            this.notifyIcon = new NotifyIcon
            {
                Icon             = KvmSwitch.Properties.Resources.TraySymbol,
                Visible          = true,
                ContextMenuStrip = new ContextMenuStrip()
            };

            this.InitializeNotifyIconContextMenu();
            this.environment.ConfigChanged += (sender, args) =>
            {
                this.UpdateTextOfContextMenuItems();
            };

            this.environment.ConfigChanged += (sender, args) => this.UpdateProfileMenuItems();
        }