Ejemplo n.º 1
0
        public ActionsToolbarEditForm(List <HotkeyType> actions)
        {
            InitializeComponent();
            Icon = ShareXResources.Icon;

            Actions = actions;

            foreach (HotkeyType hotkeyType in Helpers.GetEnums <HotkeyType>())
            {
                Image img;

                if (hotkeyType == HotkeyType.None)
                {
                    img = Resources.ui_splitter;
                }
                else
                {
                    img = TaskHelpers.GetHotkeyTypeIcon(hotkeyType);
                }

                ilMain.Images.Add(hotkeyType.ToString(), img);
            }

            AddEnumItemsContextMenu(AddAction, cmsAction);

            foreach (HotkeyType action in Actions)
            {
                AddActionToList(action);
            }
        }
Ejemplo n.º 2
0
        private void AddEnumItemsContextMenu(Action <HotkeyType> selectedEnum, params ToolStripDropDown[] parents)
        {
            EnumInfo[] enums = Helpers.GetEnums <HotkeyType>().OfType <Enum>().Select(x => new EnumInfo(x)).ToArray();

            foreach (ToolStripDropDown parent in parents)
            {
                foreach (EnumInfo enumInfo in enums)
                {
                    HotkeyType hotkeyType = (HotkeyType)Enum.ToObject(typeof(HotkeyType), enumInfo.Value);

                    string text;
                    Image  img;

                    if (hotkeyType == HotkeyType.None)
                    {
                        text = Resources.ActionsToolbarEditForm_Separator;
                        img  = Resources.ui_splitter;
                    }
                    else
                    {
                        text = enumInfo.Description.Replace("&", "&&");
                        img  = TaskHelpers.GetHotkeyTypeIcon(hotkeyType);
                    }

                    ToolStripMenuItem tsmi = new ToolStripMenuItem(text);
                    tsmi.Image = img;
                    tsmi.Tag   = enumInfo;

                    tsmi.Click += (sender, e) =>
                    {
                        selectedEnum(hotkeyType);
                    };

                    if (!string.IsNullOrEmpty(enumInfo.Category))
                    {
                        ToolStripMenuItem tsmiParent = parent.Items.OfType <ToolStripMenuItem>().FirstOrDefault(x => x.Text == enumInfo.Category);

                        if (tsmiParent == null)
                        {
                            tsmiParent = new ToolStripMenuItem(enumInfo.Category);
                            parent.Items.Add(tsmiParent);
                        }

                        tsmiParent.DropDownItems.Add(tsmi);
                    }
                    else
                    {
                        parent.Items.Add(tsmi);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdateToolbar(List <HotkeyType> actions)
        {
            tsMain.SuspendLayout();

            tsMain.Items.Clear();

            ToolStripLabel tslTitle = new ToolStripLabel()
            {
                Margin      = new Padding(4, 0, 3, 0),
                Text        = "ShareX",
                ToolTipText = "Hold left down to drag\r\nRight click to open menu\r\nMiddle click to close"
            };

            tslTitle.MouseDown  += tslTitle_MouseDown;
            tslTitle.MouseEnter += tslTitle_MouseEnter;
            tslTitle.MouseLeave += tslTitle_MouseLeave;
            tslTitle.MouseUp    += tslTitle_MouseUp;

            tsMain.Items.Add(tslTitle);

            foreach (HotkeyType action in Program.Settings.SimpleActionsList)
            {
                if (action == HotkeyType.None)
                {
                    ToolStripSeparator tss = new ToolStripSeparator()
                    {
                        Margin = new Padding(0)
                    };

                    tsMain.Items.Add(tss);
                }
                else
                {
                    ToolStripButton tsb = new ToolStripButton()
                    {
                        Text         = action.GetLocalizedDescription(),
                        DisplayStyle = ToolStripItemDisplayStyle.Image,
                        Image        = TaskHelpers.GetHotkeyTypeIcon(action)
                    };

                    tsb.Click += (sender, e) =>
                    {
                        if (Program.Settings.SimpleActionsFormStayTopMost)
                        {
                            TopMost = false;
                        }

                        TaskHelpers.ExecuteJob(action);

                        if (Program.Settings.SimpleActionsFormStayTopMost)
                        {
                            TopMost = true;
                        }
                    };

                    tsMain.Items.Add(tsb);
                }
            }

            foreach (ToolStripItem tsi in tsMain.Items)
            {
                tsi.MouseEnter += (sender, e) =>
                {
                    string text;

                    if (!string.IsNullOrEmpty(tsi.ToolTipText))
                    {
                        text = tsi.ToolTipText;
                    }
                    else
                    {
                        text = tsi.Text;
                    }

                    ttMain.SetToolTip(tsMain, text);
                };

                tsi.MouseLeave += tsMain_MouseLeave;
            }

            tsMain.ResumeLayout(false);
            tsMain.PerformLayout();
        }