GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
refactor(bar): remove unused bar view model; separate refreshing item source state into its own method
Larsbf2ea762a6f0
diff --git a/LarsWM.Bar/BarViewModel.cs b/LarsWM.Bar/BarViewModel.csdeleted file mode 100644index f879a27f..00000000--- a/LarsWM.Bar/BarViewModel.cs+++ /dev/null@@ -1,49 +0,0 @@-using System.Collections.Generic;-using System.Collections.ObjectModel;-using System.ComponentModel;-using LarsWM.Domain.Workspaces;--namespace LarsWM.Bar-{- public class BarViewModel : INotifyPropertyChanged- {- public event PropertyChangedEventHandler PropertyChanged;- private ObservableCollection<Workspace> _workspaces = new ObservableCollection<Workspace>();- public ObservableCollection<Workspace> Workspaces- {- get { return _workspaces; }- set- {- _workspaces = value;- OnPropertyChanged("Workspaces");- }- }-- public void AddWorkspace(Workspace workspace)- {- this.Workspaces.Add(workspace);- OnPropertyChanged("Workspaces");- }-- public void ClearWorkspaces()- {- this.Workspaces.Clear();- OnPropertyChanged("Workspaces");- }-- public void SetWorkspaces(List<Workspace> workspaces)- {- workspaces.Clear();-- foreach (var workspace in workspaces)- workspaces.Add(workspace);-- OnPropertyChanged("Workspaces");- }-- private void OnPropertyChanged(string propertyName)- {- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));- }- }-}diff --git a/LarsWM.Bar/MainWindow.xaml.cs b/LarsWM.Bar/MainWindow.xaml.csindex 96a9c8fd..db19c481 100644--- a/LarsWM.Bar/MainWindow.xaml.cs+++ b/LarsWM.Bar/MainWindow.xaml.cs@@ -9,9 +9,6 @@ using System;using System.Windows;using System.Windows.Controls;using System.Windows.Data;-using System.ComponentModel;-using System.Collections.Generic;-using System.Diagnostics;namespace LarsWM.Bar{@@ -32,30 +29,33 @@ namespace LarsWM.BarInitializeComponent();// TODO: Bind padding, bg color, button bg color and font from user config.- this.Top = monitor.Y;- this.Left = monitor.X;- this.Width = monitor.Width;+ Top = monitor.Y;+ Left = monitor.X;+ Width = monitor.Width;// TODO: Change height to be set in XAML.- this.Height = 50;+ Height = 50;var workspaces = new ObservableCollection<Workspace>();BindingOperations.EnableCollectionSynchronization(workspaces, _lock);- foreach (var workspace in monitor.Children)- workspaces.Add(workspace as Workspace);-- this.WorkspaceItems.ItemsSource = workspaces;+ WorkspaceItems.ItemsSource = workspaces;+ RefreshState(monitor);_bus.Events.Where(@event => @event is WorkspaceAttachedEvent).Subscribe(observer =>{- // Refresh contents of `workspaces` collection.- (this.WorkspaceItems.ItemsSource as ObservableCollection<Workspace>).Clear();-- foreach (var workspace in monitor.Children)- (this.WorkspaceItems.ItemsSource as ObservableCollection<Workspace>).Add(workspace as Workspace);+ // Refresh contents of items source.+ RefreshState(monitor);});}+ private void RefreshState(Monitor monitor)+ {+ (WorkspaceItems.ItemsSource as ObservableCollection<Workspace>).Clear();++ foreach (var workspace in monitor.Children)+ (WorkspaceItems.ItemsSource as ObservableCollection<Workspace>).Add(workspace as Workspace);+ }+private void OnWorkspaceButtonClick(object sender, RoutedEventArgs e){var button = sender as Button;