コード例 #1
0
        public ConfigForm(HotkeyManager hotkeyManager, KneeboardManager kneeboardManager, AltCodeData altCodeData)
        {
            InitializeComponent();

            _HotkeyManager      = hotkeyManager;
            _KneeboardManager   = kneeboardManager;
            _AltCodeData        = altCodeData;
            _PlacementViewModel = new PlacementViewModel();

            // Tab pages
            tabPageEntryBindingSource.DataSource = new List <TabPageEntry>()
            {
                new TabPageEntry(R.keyboard, R.Hotkeys),
                new TabPageEntry(R.star, R.Favorites),
                new TabPageEntry(R.palette, R.Appearance),
                new TabPageEntry(R.placement, R.Dimensions)
            };

            // Hotkeys
            hotkeyListPanel.Controls.Clear();
            foreach (var kvp in _HotkeyManager.GetHooks())
            {
                var item = new HotkeyListItem(kvp.Key, kvp.Value);
                item.KeyComboEditingChanged += (sender, args) => _HotkeyManager.Enabled = !item.KeyComboEditing && Settings.Default.HotkeysEnabled;
                hotkeyListPanel.Controls.Add(item);
            }

            // Favorites
            _Favorites = new List <Favorite>();
            foreach (var code in _AltCodeData.AltCodes.AltCodes)
            {
                var f = new Favorite(code);
                f.PropertyChanged += Favorite_PropertyChanged;
                _Favorites.Add(f);
            }
            gridFavorites.RowCount = _Favorites.Count;

            // Favorites: Visible Groups
            var groups       = new List <GroupVisible>();
            var hiddenGroups = Settings.Default.HiddenGroups ?? new int[0];

            foreach (var group in _AltCodeData.Groups.Groups)
            {
                var gv = new GroupVisible(group, !hiddenGroups.Contains(group.ID));
                gv.PropertyChanged += GroupVisible_PropertyChanged;
                groups.Add(gv);
            }
            groupVisibleBindingSource.DataSource = groups;

            cmbStyleSort.DataSource = FormUtils.GetEnumList(typeof(SortMode));
            cmbStyleSort.DataBindings.Add(nameof(ComboBox.SelectedValue), Settings.Default, nameof(Settings.SortMode), false, DataSourceUpdateMode.OnPropertyChanged);

            // Appearance
            // TODO Allow theme selection from XML/other serialization
            _AppearanceViewModel             = new AppearanceViewModel();
            propertyGridTheme.SelectedObject = _KneeboardManager.Theme;
            propertyGridTheme.DataBindings.Add(nameof(PropertyGrid.PropertySort), _AppearanceViewModel, nameof(AppearanceViewModel.SortMode), false, DataSourceUpdateMode.OnPropertyChanged);
            toolStripButtonAppearanceThemeSortAlpha.DataBindings.Add(nameof(ToolStripButton.Checked), _AppearanceViewModel, nameof(AppearanceViewModel.SortAlpha), false, DataSourceUpdateMode.OnPropertyChanged);
            toolStripButtonAppearanceThemeSortByCategory.DataBindings.Add(nameof(ToolStripButton.Checked), _AppearanceViewModel, nameof(AppearanceViewModel.SortCategory), false, DataSourceUpdateMode.OnPropertyChanged);
            appearancePreview = new AppearancePreviewControl(new KneeboardLayout(_AltCodeData, Settings.Default.Favorites, Settings.Default.HiddenGroups), _KneeboardManager.Theme);
            appearancePreview.BackgroundImage       = R.TransparencyBackground;
            appearancePreview.BackgroundImageLayout = ImageLayout.Tile;
            appearancePreview.Dock = DockStyle.Fill;
            tableLayoutPanelAppearance.Controls.Add(appearancePreview, 1, 0);
            tableLayoutPanelAppearance.SetRowSpan(appearancePreview, 2);

            // Placement
            numPlacementX.DataBindings.Add(nameof(NumericUpDown.Value), _PlacementViewModel, nameof(PlacementViewModel.X), false, DataSourceUpdateMode.OnPropertyChanged);
            numPlacementY.DataBindings.Add(nameof(NumericUpDown.Value), _PlacementViewModel, nameof(PlacementViewModel.Y), false, DataSourceUpdateMode.OnPropertyChanged);
            numPlacementWidth.DataBindings.Add(nameof(NumericUpDown.Value), _PlacementViewModel, nameof(PlacementViewModel.Width), false, DataSourceUpdateMode.OnPropertyChanged);
            numPlacementHeight.DataBindings.Add(nameof(NumericUpDown.Value), _PlacementViewModel, nameof(PlacementViewModel.Height), false, DataSourceUpdateMode.OnPropertyChanged);
        }