Exemplo n.º 1
0
        /// <summary>
        /// Switch to a custom shortcut set.
        /// </summary>
        private void SelectCustomShortcut(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                Filter           = TextHelper.GetString("Info.ArgumentFilter") + "|*.fda",
                InitialDirectory = PathHelper.ShortcutsDir,
                Title            = " " + TextHelper.GetString("Title.OpenFileDialog")
            };

            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                this.listView.BeginUpdate();
                ShortcutManager.LoadCustomShortcuts(dialog.FileName, this.shortcutListItems);
                bool conflicts = this.UpdateAllShortcutsConflicts();
                this.listView.EndUpdate();
                if (conflicts)
                {
                    this.ShowConflictsPresent();            // Make sure the warning message shows up after the listview is rendered
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a list of all conflicting entries.
        /// </summary>
        void GetConflictItems(ShortcutListItem target)
        {
            var keys = target.Custom;

            if (keys == 0)
            {
                return;
            }

            List <ShortcutListItem> conflicts = null;

            for (int i = 0; i < this.shortcutListItems.Length; i++)
            {
                var item = this.shortcutListItems[i];

                if (item.Custom != keys || item == target)
                {
                    continue;
                }
                if (conflicts == null)
                {
                    conflicts = new List <ShortcutListItem> {
                        target
                    }
                }
                ;
                conflicts.Add(item);
                item.Conflicts = conflicts;
            }

            target.Conflicts = conflicts;
        }

        /// <summary>
        /// Reverts the shortcut to default value.
        /// </summary>
        void RevertToDefaultClick(object sender, EventArgs e)
        {
            if (this.listView.SelectedItems.Count > 0)
            {
                this.RevertToDefault((ShortcutListItem)this.listView.SelectedItems[0]);
            }
        }

        /// <summary>
        /// Reverts all visible shortcuts to their default value.
        /// </summary>
        void RevertAllToDefaultClick(object sender, EventArgs e)
        {
            foreach (ShortcutListItem item in this.listView.Items)
            {
                RevertToDefault(item);
            }
        }

        /// <summary>
        /// Revert the selected items shortcut to default.
        /// </summary>
        void RevertToDefault(ShortcutListItem item)
        {
            this.AssignNewShortcut(item, item.Default);
        }

        /// <summary>
        /// Removes the shortcut by setting it to <see cref="Keys.None"/>.
        /// </summary>
        void RemoveShortcutClick(object sender, EventArgs e)
        {
            if (this.listView.SelectedItems.Count > 0)
            {
                this.AssignNewShortcut((ShortcutListItem)this.listView.SelectedItems[0], 0);
            }
        }

        /// <summary>
        /// Clears the filter text field.
        /// </summary>
        void ClearFilterClick(object sender, EventArgs e)
        {
            this.filterTextBox.Text = string.Empty;
            this.filterTextBox.Select();
        }

        /// <summary>
        /// Set up the timer for delayed list update with filters.
        /// </summary>
        void SetupUpdateTimer()
        {
            this.updateTimer          = new Timer();
            this.updateTimer.Enabled  = false;
            this.updateTimer.Interval = 100;
            this.updateTimer.Tick    += this.UpdateTimer_Tick;
        }

        /// <summary>
        /// Update the list with filter.
        /// </summary>
        void UpdateTimer_Tick(object sender, EventArgs e)
        {
            this.updateTimer.Enabled = false;
            this.PopulateListView(this.filterTextBox.Text);
        }

        /// <summary>
        /// Restart the timer for updating the list.
        /// </summary>
        void FilterTextChanged(object sender, EventArgs e)
        {
            this.updateTimer.Stop();
            this.updateTimer.Start();
        }

        /// <summary>
        /// Switch to a custom shortcut set.
        /// </summary>
        void SelectCustomShortcut(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                Filter           = TextHelper.GetString("Info.ArgumentFilter") + "|*.fda",
                InitialDirectory = PathHelper.ShortcutsDir,
                Title            = " " + TextHelper.GetString("Title.OpenFileDialog")
            };

            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                this.listView.BeginUpdate();
                ShortcutManager.LoadCustomShortcuts(dialog.FileName, this.shortcutListItems);
                bool conflicts = this.UpdateAllShortcutsConflicts();
                this.listView.EndUpdate();
                if (conflicts)
                {
                    this.ShowConflictsPresent();            // Make sure the warning message shows up after the listview is rendered
                }
            }
        }

        /// <summary>
        /// Save the current shortcut set to a file.
        /// </summary>
        void SaveCustomShortcut(object sender, EventArgs e)
        {
            var dialog = new SaveFileDialog
            {
                AddExtension     = true,
                DefaultExt       = ".fda",
                Filter           = TextHelper.GetString("Info.ArgumentFilter") + "|*.fda",
                InitialDirectory = PathHelper.ShortcutsDir,
                OverwritePrompt  = true,
                Title            = " " + TextHelper.GetString("Title.SaveFileDialog")
            };

            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                ShortcutManager.SaveCustomShortcuts(dialog.FileName, this.shortcutListItems);
            }
        }

        /// <summary>
        /// Closes the shortcut dialog.
        /// </summary>
        void CloseButtonClick(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// When the form is about to close, checks for any conflicts.
        /// </summary>
        void DialogClosing(object sender, FormClosingEventArgs e)
        {
            for (int i = 0; i < this.shortcutListItems.Length; i++)
            {
                if (this.shortcutListItems[i].HasConflicts)
                {
                    e.Cancel = this.ShowConflictsPresent();
                    break;
                }
            }
        }

        /// <summary>
        /// When the form is closed, applies shortcuts.
        /// </summary>
        void DialogClosed(object sender, FormClosedEventArgs e)
        {
            for (int i = 0; i < this.shortcutListItems.Length; i++)
            {
                this.shortcutListItems[i].ApplyChanges();
            }
            Globals.MainForm.ApplyAllSettings();
        }