Пример #1
0
        public KneeboardApplication(bool showConfig, AltCodeData altCodes)
        {
            _AltCodes = altCodes;

            _HotkeyManager         = new HotkeyManager();
            _HotkeyManager.Enabled = Settings.Default.HotkeysEnabled;

            _KneeboardManager = new KneeboardManager(_AltCodes);

            var momentaryKC = KeyCombo.FromStorage(Settings.Default.MomentaryShowKeyCombo);
            var toggleKC    = KeyCombo.FromStorage(Settings.Default.ToggleShowKeyCombo);

            _HotkeyManager.AddHook(HK_MOMENTARY, R.Hotkey_Momentary_Name, R.Hotkey_Momentary_Desc, Settings.Default.MomentaryShowEnabled, momentaryKC, _KneeboardManager.ShowKneeboard, _KneeboardManager.HideKneeboard, MomentaryShowHook_PropertyChanged);
            _HotkeyManager.AddHook(HK_TOGGLE, R.Hotkey_Toggle_Name, R.Hotkey_Toggle_Desc, Settings.Default.ToggleShowEnabled, toggleKC, _KneeboardManager.ToggleKneeboard, null, ToggleShowHook_PropertyChanged);

            _TrayIcon                  = new NotifyIcon();
            _TrayIcon.Icon             = R.appicon;
            _TrayIcon.Text             = R.AppTitle;
            _TrayIcon.DoubleClick     += OnShowConfig;
            _TrayIcon.ContextMenuStrip = new ContextMenuStrip();
            _TrayIcon.ContextMenuStrip.Items.Add(new ToolStripMenuItem(R.Configure, FormUtils.RenderSvg(R.keyboard, SystemColors.ControlText, new Size(16, 16)), OnShowConfig));
            _TrayIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
            _TrayIcon.ContextMenuStrip.Items.Add(new ToolStripMenuItem(R.ToggleKneeboard, null, (sender, args) => _KneeboardManager.ToggleKneeboard()));
            _TrayIcon.ContextMenuStrip.Items.Add(new ToolStripMenuItem(R.ShowCharMap, null, OnShowCharMap));
            _TrayIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
            _TrayIcon.ContextMenuStrip.Items.Add(new ToolStripMenuItem(R.Exit, FormUtils.RenderSvg(R.close, SystemColors.ControlText, new Size(16, 16)), (sender, e) => ExitThread()));
            _TrayIcon.ContextMenuStrip.Items[0].Font = new Font(_TrayIcon.ContextMenuStrip.Items[0].Font, FontStyle.Bold);
            _TrayIcon.Visible = true;

            Settings.Default.PropertyChanged += Settings_PropertyChanged;

            if (showConfig)
            {
                OnShowConfig(this, EventArgs.Empty);
            }
        }
Пример #2
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);
        }