Exemplo n.º 1
0
        public SettingsModel(Sidebar sidebar)
        {
            DockEdgeItems = new DockItem[2]
            {
                new DockItem()
                {
                    Text = Resources.SettingsDockLeft, Value = DockEdge.Left
                },
                new DockItem()
                {
                    Text = Resources.SettingsDockRight, Value = DockEdge.Right
                }
            };

            DockEdge = Framework.Settings.Instance.DockEdge;

            Monitor[] _monitors = Monitor.GetMonitors();

            ScreenItems = _monitors.Select((s, i) => new ScreenItem()
            {
                Index = i, Text = string.Format("#{0}", i + 1)
            }).ToArray();

            if (Framework.Settings.Instance.ScreenIndex < _monitors.Length)
            {
                ScreenIndex = Framework.Settings.Instance.ScreenIndex;
            }
            else
            {
                ScreenIndex = _monitors.Where(s => s.IsPrimary).Select((s, i) => i).Single();
            }

            CultureItems = Utilities.Culture.GetAll();
            Culture      = Framework.Settings.Instance.Culture;

            UIScale         = Framework.Settings.Instance.UIScale;
            XOffset         = Framework.Settings.Instance.XOffset;
            YOffset         = Framework.Settings.Instance.YOffset;
            PollingInterval = Framework.Settings.Instance.PollingInterval;
            UseAppBar       = Framework.Settings.Instance.UseAppBar;
            AlwaysTop       = Framework.Settings.Instance.AlwaysTop;
            ToolbarMode     = Framework.Settings.Instance.ToolbarMode;
            ClickThrough    = Framework.Settings.Instance.ClickThrough;
            ShowTrayIcon    = Framework.Settings.Instance.ShowTrayIcon;
            AutoUpdate      = Framework.Settings.Instance.AutoUpdate;
            RunAtStartup    = Framework.Settings.Instance.RunAtStartup;
            SidebarWidth    = Framework.Settings.Instance.SidebarWidth;
            AutoBGColor     = Framework.Settings.Instance.AutoBGColor;
            BGColor         = Framework.Settings.Instance.BGColor;
            BGOpacity       = Framework.Settings.Instance.BGOpacity;

            TextAlignItems = new TextAlignItem[2]
            {
                new TextAlignItem()
                {
                    Text = Resources.SettingsTextAlignLeft, Value = TextAlign.Left
                },
                new TextAlignItem()
                {
                    Text = Resources.SettingsTextAlignRight, Value = TextAlign.Right
                }
            };

            TextAlign = Framework.Settings.Instance.TextAlign;

            FontSettingItems = new FontSetting[5]
            {
                FontSetting.x10,
                FontSetting.x12,
                FontSetting.x14,
                FontSetting.x16,
                FontSetting.x18
            };

            FontSetting    = Framework.Settings.Instance.FontSetting;
            FontColor      = Framework.Settings.Instance.FontColor;
            AlertFontColor = Framework.Settings.Instance.AlertFontColor;
            AlertBlink     = Framework.Settings.Instance.AlertBlink;

            DateSettingItems = new DateSetting[4]
            {
                DateSetting.Disabled,
                DateSetting.Short,
                DateSetting.Normal,
                DateSetting.Long
            };

            DateSetting     = Framework.Settings.Instance.DateSetting;
            CollapseMenuBar = Framework.Settings.Instance.CollapseMenuBar;
            InitiallyHidden = Framework.Settings.Instance.InitiallyHidden;
            ShowMachineName = Framework.Settings.Instance.ShowMachineName;
            ShowClock       = Framework.Settings.Instance.ShowClock;
            Clock24HR       = Framework.Settings.Instance.Clock24HR;

            ObservableCollection <MonitorConfig> _config = new ObservableCollection <MonitorConfig>(Framework.Settings.Instance.MonitorConfig.Select(c => c.Clone()).OrderByDescending(c => c.Order));

            if (sidebar.Ready)
            {
                foreach (MonitorConfig _record in _config)
                {
                    _record.HardwareOC = new ObservableCollection <HardwareConfig>(
                        from hw in sidebar.Model.MonitorManager.GetHardware(_record.Type)
                        join config in _record.Hardware on hw.ID equals config.ID into merged
                        from newhw in merged.DefaultIfEmpty(hw).Select(newhw => { newhw.ActualName = hw.ActualName; if (string.IsNullOrEmpty(newhw.Name))
                                                                                  {
                                                                                      newhw.Name = hw.ActualName;
                                                                                  }
                                                                                  return(newhw); })
                        orderby newhw.Order descending, newhw.Name ascending
                        select newhw
                        );
                }
            }

            MonitorConfig = _config;

            if (Framework.Settings.Instance.Hotkeys != null)
            {
                ToggleKey       = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Toggle);
                ShowKey         = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Show);
                HideKey         = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Hide);
                ReloadKey       = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Reload);
                CloseKey        = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Close);
                CycleEdgeKey    = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.CycleEdge);
                CycleScreenKey  = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.CycleScreen);
                ReserveSpaceKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.ReserveSpace);
            }

            IsChanged = false;
        }
        public SettingsModel(Sidebar sidebar)
        {
            DockEdgeItems = new DockItem[2]
            {
                new DockItem() { Text = Resources.SettingsDockLeft, Value = DockEdge.Left },
                new DockItem() { Text = Resources.SettingsDockRight, Value = DockEdge.Right }
            };

            DockEdge = Framework.Settings.Instance.DockEdge;

            Monitor[] _monitors = Monitor.GetMonitors();

            ScreenItems = _monitors.Select((s, i) => new ScreenItem() { Index = i, Text = string.Format("#{0}", i + 1) }).ToArray();

            if (Framework.Settings.Instance.ScreenIndex < _monitors.Length)
            {
                ScreenIndex = Framework.Settings.Instance.ScreenIndex;
            }
            else
            {
                ScreenIndex = _monitors.Where(s => s.IsPrimary).Select((s, i) => i).Single();
            }

            CultureItems = Utilities.Culture.GetAll();
            Culture = Framework.Settings.Instance.Culture;

            UIScale = Framework.Settings.Instance.UIScale;
            XOffset = Framework.Settings.Instance.XOffset;
            YOffset = Framework.Settings.Instance.YOffset;
            PollingInterval = Framework.Settings.Instance.PollingInterval;
            UseAppBar = Framework.Settings.Instance.UseAppBar;
            AlwaysTop = Framework.Settings.Instance.AlwaysTop;
            ToolbarMode = Framework.Settings.Instance.ToolbarMode;
            ClickThrough = Framework.Settings.Instance.ClickThrough;
            ShowTrayIcon = Framework.Settings.Instance.ShowTrayIcon;
            AutoUpdate = Framework.Settings.Instance.AutoUpdate;
            RunAtStartup = Framework.Settings.Instance.RunAtStartup;
            SidebarWidth = Framework.Settings.Instance.SidebarWidth;
            AutoBGColor = Framework.Settings.Instance.AutoBGColor;
            BGColor = Framework.Settings.Instance.BGColor;
            BGOpacity = Framework.Settings.Instance.BGOpacity;

            TextAlignItems = new TextAlignItem[2]
            {
                new TextAlignItem() { Text = Resources.SettingsTextAlignLeft, Value = TextAlign.Left },
                new TextAlignItem() { Text = Resources.SettingsTextAlignRight, Value = TextAlign.Right }
            };

            TextAlign = Framework.Settings.Instance.TextAlign;

            FontSettingItems = new FontSetting[5]
            {
                FontSetting.x10,
                FontSetting.x12,
                FontSetting.x14,
                FontSetting.x16,
                FontSetting.x18
            };

            FontSetting = Framework.Settings.Instance.FontSetting;
            FontColor = Framework.Settings.Instance.FontColor;
            AlertFontColor = Framework.Settings.Instance.AlertFontColor;
            AlertBlink = Framework.Settings.Instance.AlertBlink;

            DateSettingItems = new DateSetting[4]
            {
                DateSetting.Disabled,
                DateSetting.Short,
                DateSetting.Normal,
                DateSetting.Long
            };

            DateSetting = Framework.Settings.Instance.DateSetting;
            CollapseMenuBar = Framework.Settings.Instance.CollapseMenuBar;
            InitiallyHidden = Framework.Settings.Instance.InitiallyHidden;
            ShowClock = Framework.Settings.Instance.ShowClock;
            Clock24HR = Framework.Settings.Instance.Clock24HR;

            ObservableCollection<MonitorConfig> _config = new ObservableCollection<MonitorConfig>(Framework.Settings.Instance.MonitorConfig.Select(c => c.Clone()).OrderByDescending(c => c.Order));

            if (sidebar.Ready)
            {
                foreach (MonitorConfig _record in _config)
                {
                    _record.HardwareOC = new ObservableCollection<HardwareConfig>(
                        from hw in sidebar.Model.MonitorManager.GetHardware(_record.Type)
                        join config in _record.Hardware on hw.ID equals config.ID into merged
                        from newhw in merged.DefaultIfEmpty(hw).Select(newhw => { newhw.ActualName = hw.ActualName; if (string.IsNullOrEmpty(newhw.Name)) { newhw.Name = hw.ActualName; } return newhw; })
                        orderby newhw.Order descending, newhw.Name ascending
                        select newhw
                        );
                }
            }

            MonitorConfig = _config;

            if (Framework.Settings.Instance.Hotkeys != null)
            {
                ToggleKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Toggle);
                ShowKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Show);
                HideKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Hide);
                ReloadKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Reload);
                CloseKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.Close);
                CycleEdgeKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.CycleEdge);
                CycleScreenKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.CycleScreen);
                ReserveSpaceKey = Framework.Settings.Instance.Hotkeys.FirstOrDefault(k => k.Action == Hotkey.KeyAction.ReserveSpace);
            }

            IsChanged = false;
        }