Exemplo n.º 1
0
        public void SelectTool(ITool tool)
        {
            ITool oldTool = null;
            ITool newTool = null;

            if (tool.IsActivatable)
            {
                if (ActivatedTools.Contains(tool))
                {
                    ActivatedTools.Remove(tool);
                }
                else
                {
                    ActivatedTools.Add(tool);
                }

                tool.IsActivated = ActivatedTools.Contains(tool);
            }
            else
            {
                oldTool = SelectedTool;

                SelectedTool?.Unselect();
                SelectedTool = tool;
                SelectedTool.Select();

                newTool = SelectedTool;
            }

            ToolSelected?.Invoke(this, new ToolSelectedEventArgs(oldTool, newTool));
        }
Exemplo n.º 2
0
        public void LoadData(IMotherboard motherboard)
        {
            Motherboard = new MotherboardRowData(motherboard ?? throw new ArgumentNullException(nameof(motherboard)));

            picMotherboard.ImageLocation = Motherboard.Images.FirstOrDefault()?.Url;
            txtId.Text          = Motherboard.Id;
            txtName.Text        = Motherboard.Name;
            txtBrand.Text       = Motherboard.Brand;
            txtModel.Text       = Motherboard.Model;
            txtVersion.Text     = Motherboard.Version;
            txtTags.Text        = Motherboard.TagsString;
            txtDescription.Text = Motherboard.Description;

            {
                List <ITool> tools = _model.Tools.Where(x => motherboard.ToolIds.Contains(x.Id)).ToList();

                flpTools.Controls.Clear();

                foreach (ITool item in tools)
                {
                    ITool     tool = item;
                    LinkLabel lbl  = new LinkLabel()
                    {
                        Text     = tool.Name,
                        AutoSize = true,
                        Anchor   = AnchorStyles.Left | AnchorStyles.Right
                    };

                    flpTools.Controls.Add(lbl);

                    lbl.Click += (s, a) =>
                    {
                        ToolSelected?.Invoke(this, tool);
                    };
                }
            }

            grdImages.DataSource = motherboard.Images.Select(x => new
            {
                x.Name,
                x.Url,
                Image = new Bitmap(x.Url)
            }).ToList();
            grdImages.AutoResizeColumns();

            grdBioses.DataSource = new GenericBindingList <BiosRowData>
                                   (
                _model
                .Bioses
                .Where(x => x.MotherboardIds.Contains(motherboard.Id))
                .Select(x => new BiosRowData(x))
                                   );
            grdBioses.AutoResizeColumns();

            grdLinks.DataSource = motherboard.Links;
            grdLinks.AutoResizeColumns();
        }
Exemplo n.º 3
0
        private void toggleButton_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is ToolStripButton)
            {
                ToolStripButton button = (ToolStripButton)sender;

                if (button.Checked)
                {
                    if (button is ITool)
                    {
                        this.activeTool = (ITool)button;
                        Debug.WriteLine(this.activeTool.Name + " is activated.");

                        ToolSelected?.Invoke(this.activeTool);

                        UncheckInactiveToggleButtons();
                    }
                    else
                    {
                        throw new InvalidCastException("The tool is not an instance of ITool.");
                    }
                }
            }
        }
Exemplo n.º 4
0
 private void OnToolSelected(string ToolName)
 {
     ToolSelected?.Invoke(this, new PropertyChangedEventArgs(ToolName));
 }