private void contextMenuStripLog_MouseClick(object sender, MouseEventArgs e)
        {
            ContextMenuStrip logMenuStrip = (ContextMenuStrip)sender;

            if (logMenuStrip.GetItemAt(e.Location).Text != "Clear")
            {
                OnLogMenuClickEvent(logMenuStrip.GetItemAt(e.Location).Text);

                LogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), logMenuStrip.GetItemAt(e.Location).Text);
            }
            else
            {
                Clear();
            }
        }
Esempio n. 2
0
        private void OnLogsFilesBoxClicked(object sender, EventArgs e)
        {
            if (e is MouseEventArgs mouse && mouse.Button == MouseButtons.Left && logs.SelectedItems.Count > 0)
            {
                ContextMenuStrip cms          = sender as ContextMenuStrip;
                object           selectedItem = logs.SelectedItem;

                var toolStripItem = cms?.GetItemAt(mouse.Location);
                if (toolStripItem != null)
                {
                    if (toolStripItem.Text == "Open in file explorer")
                    {
                        try {
                            string si = selectedItem.ToString();
                            System.Diagnostics.Process.Start("explorer.exe", File.Exists(si) ? new FileInfo(si).DirectoryName : si);
                        } catch (Exception ex) {
                            LogException(ex.Message + " " + ex.StackTrace);
                            MessageBox.Show("File not found", "The file to open does not exist: " + ex.Message, MessageBoxButtons.OK);
                        }
                    }
                    else if (toolStripItem.Text == "Remove")
                    {
                        logs.Items.Remove(selectedItem);

                        string si = selectedItem.ToString();
                        if (Directory.Exists(si))
                        {
                            Directory.Delete(si, true);
                        }
                        else if (File.Exists(si))
                        {
                            File.Delete(si);
                        }
                    }
                }

                if (cms != null)
                {
                    cms.Close();
                }

                logs.SelectedItems.Clear();
            }
        }
Esempio n. 3
0
        public void PerformClickOnContextMenu()
        {
            EmptyHandler del = delegate()
            {
                Point point = cMS_MatchedGestures.PointToClient(Cursor.Position);
                //Debug.WriteLine(string.Format("PerformClickOnContextMenu X: {0} Y: {1}", point.X, point.Y));
                ToolStripItem item = cMS_MatchedGestures.GetItemAt(point);

                if (item == null)
                {
                    point.Y -= 1;

                    foreach (ContextMenuStrip contextMenu in m_cmsList)
                    {
                        point = contextMenu.PointToClient(Cursor.Position);
                        item  = contextMenu.GetItemAt(point);
                        if (item != null)
                        {
                            break;
                        }
                    }
                }

                if (item != null)
                {
                    ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
                    if (menuItem.DropDownItems.Count == 0)
                    {
                        item.PerformClick();
                    }
                }
            };

            if (this.InvokeRequired)
            {
                this.Invoke(del);
            }
            else
            {
                del();
            }
        }
        private void OnFilterListClicked(object sender, EventArgs e)
        {
            if (e is MouseEventArgs mouse && mouse.Button == MouseButtons.Left && filterList.SelectedItems.Count > 0)
            {
                ContextMenuStrip cms          = sender as ContextMenuStrip;
                object           selectedItem = filterList.SelectedItem;

                filterList.Items.Remove(selectedItem);

                var toolStripItem = cms?.GetItemAt(mouse.Location);
                if (toolStripItem != null)
                {
                    if (toolStripItem.Text == "Open in file explorer")
                    {
                        try {
                            System.Diagnostics.Process.Start("explorer.exe", selectedItem.ToString());
                        } catch (Exception ex) {
                            RedundantFileRemover.LogException(ex.Message + " " + ex.StackTrace);
                            MessageBox.Show("File not found", "The file to open does not exist: " + ex.Message, MessageBoxButtons.OK);
                        }
                    }
                    else if (toolStripItem.Text == "Remove from list")
                    {
                        FileDataReader.ProgramSettings.SettingsWindow.IgnoredDirectories.Remove(selectedItem.ToString());
                    }
                }

                if (filterList.Items.Count == 0)
                {
                    removeFilters.Enabled = false;
                }

                if (cms != null)
                {
                    cms.Close();
                }

                filterList.SelectedItems.Clear();
            }
        }
    protected virtual void OnShowContextMenu(ShowContextMenuEventArgs e)
    {
        var handler = ShowContextMenu;

        if (handler != null)
        {
            handler(e);
            if (e.ContextMenuToShow != null)
            {
                ContextMenuStrip toolStrip = (ContextMenuStrip)Control.FromHandle(Handle);
                Point            client    = toolStrip.PointToClient(Control.MousePosition);
                SourceItem                  = toolStrip.GetItemAt(client);
                previousItemBackColor       = SourceItem.BackColor;
                SourceItem.BackColor        = SystemColors.MenuHighlight;
                e.ContextMenuToShow.Closed -= restoreItemState;
                e.ContextMenuToShow.Closed += restoreItemState;
                keepOpen = true;
                e.ContextMenuToShow.Show(Control.MousePosition);
                keepOpen = false;
            }
        }
    }