Esempio n. 1
0
        /// <summary>
        /// Gets a list of all conflicting entries.
        /// </summary>
        private 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;
        }
Esempio n. 2
0
 /// <summary>
 /// Updates the font highlight of the item.
 /// </summary>
 private static void UpdateItemHighlightFont(ShortcutListItem item)
 {
     if (item.HasConflicts)
     {
         item.ForeColor             = Color.DarkRed;
         item.SubItems[1].ForeColor = Color.DarkRed;
     }
     else
     {
         item.ForeColor             = SystemColors.ControlText;
         item.SubItems[1].ForeColor = item.Custom == 0 ? SystemColors.GrayText : SystemColors.ControlText;
     }
     item.Font = new Font(Globals.Settings.DefaultFont, item.IsModified ? FontStyle.Bold : 0);
     item.UseItemStyleForSubItems = item.IsModified;
 }
Esempio n. 3
0
        /// <summary>
        /// Resets the conflicts status of an item.
        /// </summary>
        private static void ResetConflicts(ShortcutListItem item)
        {
            if (!item.HasConflicts)
            {
                return;
            }
            var conflicts = item.Conflicts;

            conflicts.Remove(item);
            item.Conflicts = null;
            if (conflicts.Count == 1)
            {
                item = conflicts[0];
                conflicts.RemoveAt(0);
                item.Conflicts = null; // empty conflicts list will be garbage collected
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Assign the new shortcut.
        /// </summary>
        void AssignNewShortcut(ShortcutListItem item, Keys shortcut)
        {
            if (shortcut == 0 || shortcut == Keys.Delete)
            {
                shortcut = 0;
            }
            else if (!ToolStripManager.IsValidShortcut(shortcut))
            {
                return;
            }

            if (item.Custom == shortcut)
            {
                return;
            }
            this.listView.BeginUpdate();
            var oldShortcut = item.Custom;

            item.Custom   = shortcut;
            item.Selected = true;
            this.GetConflictItems(item);
            this.listView.EndUpdate();
            if (item.HasConflicts)
            {
                string text    = TextHelper.GetString("Info.ShortcutIsAlreadyUsed");
                string caption = TextHelper.GetString("Title.WarningDialog");
                switch (MessageBox.Show(Globals.MainForm, text, " " + caption, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning))
                {
                case DialogResult.Abort:
                    this.listView.BeginUpdate();
                    item.Custom = oldShortcut;
                    this.GetConflictItems(item);
                    this.listView.EndUpdate();
                    break;

                case DialogResult.Retry:
                    this.filterTextBox.Text = ViewConflictsKey + item.KeysString;
                    this.filterTextBox.SelectAll();
                    this.filterTextBox.Focus();     // Set focus to filter...
                    break;
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Revert the selected items shortcut to default.
 /// </summary>
 private void RevertToDefault(ShortcutListItem item)
 {
     this.AssignNewShortcut(item, item.Default);
 }
Esempio n. 6
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();
        }