123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.SystemLayer;
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.DbOpreate.DbBll;
- namespace PaintDotNet.Preview2
- {
- internal class ToolkitControl : UserControl
- {
- private ToolStripEx toolStripEx;
- private ImageList imageList;
- private const int tbWidth = 2;
- private Control onePxSpacingLeft;
- private ShortcutbarModel _shortcutbarModel;
- private System.ComponentModel.Container components = null;
- private DocumentView _docv;
- private AppWorkspace _app;
- public ToolkitControl(AppWorkspace app, DocumentView dv)
- {
- _docv = dv;
- _app = app;
- InitializeComponent();
- this.imageList = new ImageList();
- this.imageList.ColorDepth = ColorDepth.Depth32Bit;
- this.imageList.TransparentColor = Utility.TransparentKey;
- this.toolStripEx.ImageList = this.imageList;
- }
- public void UpdateTools(ShortcutbarModel model)
- {
- _shortcutbarModel = model;
- this.toolStripEx.Items.Clear();
- if (_shortcutbarModel != null && _shortcutbarModel.Menus.Count > 0)
- {
- List<ToolStripItem> buttons = new List<ToolStripItem>();
- // for (int i = 0; i < shortcutbarModel.Menus.Count; i++)
- foreach (var item1 in _shortcutbarModel.Menus)
- {
- ToolStripButton button = new ToolStripButton();
- if (item1.Id == 1211)//脚本 script
- {
- button = new ToolStripButton();
- var img = PdnResources.GetImageResource("Icons.Script.png").Reference;
- button.ToolTipText = item1.Name;
- button.TextImageRelation = TextImageRelation.ImageAboveText;
- button.ImageIndex = imageList.Images.Add(img, imageList.TransparentColor); ;
- button.Tag = item1;
- buttons.Add(button);
- continue;
- }
- int imageIndex = -1;
- ToolStripItem[] items = _app.ToolBar.MainMenu.Items.Find(item1.Description, true);
- if (items != null && items.Length > 0)
- {
- var item = (PdnMenuItem)(items[0]);
- if (item.Image != null)
- {
- imageIndex = this.imageList.Images.Add(item.Image, imageList.TransparentColor);
- button.ToolTipText = item.Text;
- }
- else
- {
- imageIndex = this.imageList.Images.Add(PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference, imageList.TransparentColor);
- //imageIndex = this.imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
- button.ToolTipText = item1.Name;// getShowName(Startup.instance.configModel.Language);
- }
- }
- else
- {
- imageIndex = this.imageList.Images.Add(PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference, imageList.TransparentColor);
- //imageIndex = this.imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
- button.ToolTipText = item1.Name;// getShowName(Startup.instance.configModel.Language);
- }
- button.Enabled = Startup.getMenuIdVisible(item1.Id);
- button.ImageIndex = imageIndex;
- button.Tag = item1;
- buttons.Add(button);
- if (item1.Id == 704)
- {
- _buttonContinue = button;
- }
- }
- this.toolStripEx.Items.AddRange(buttons.ToArray());
- }
- }
- protected override void OnLayout(LayoutEventArgs e)
- {
- int buttonWidth;
- if (this.toolStripEx.Items.Count > 0)
- {
- buttonWidth = this.toolStripEx.Items[0].Width;
- }
- else
- {
- buttonWidth = 0;
- }
- this.toolStripEx.Width =
- this.toolStripEx.Padding.Left +
- (buttonWidth * tbWidth) +
- (this.toolStripEx.Margin.Horizontal * tbWidth) +
- this.toolStripEx.Padding.Right;
- this.toolStripEx.Height = this.toolStripEx.GetPreferredSize(this.toolStripEx.Size).Height;
- this.Width = this.toolStripEx.Width + this.onePxSpacingLeft.Width;
- this.Height = this.toolStripEx.Height;
- base.OnLayout(e);
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (components != null)
- {
- components.Dispose();
- components = null;
- }
- }
- base.Dispose(disposing);
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.toolStripEx = new PaintDotNet.SystemLayer.ToolStripEx();
- this.onePxSpacingLeft = new System.Windows.Forms.Control();
- this.SuspendLayout();
- //
- // toolStripEx
- //
- this.toolStripEx.ClickThrough = false;
- this.toolStripEx.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
- this.toolStripEx.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
- this.toolStripEx.Location = new System.Drawing.Point(1, 0);
- this.toolStripEx.ManagedFocus = true;
- this.toolStripEx.Name = "toolStripEx";
- this.toolStripEx.Size = new System.Drawing.Size(47, 0);
- this.toolStripEx.TabIndex = 0;
- this.toolStripEx.RelinquishFocus += new System.EventHandler(this.ToolStripEx_RelinquishFocus);
- this.toolStripEx.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ToolStripEx_ItemClicked);
- //
- // onePxSpacingLeft
- //
- this.onePxSpacingLeft.Dock = System.Windows.Forms.DockStyle.Left;
- this.onePxSpacingLeft.Location = new System.Drawing.Point(0, 0);
- this.onePxSpacingLeft.Name = "onePxSpacingLeft";
- this.onePxSpacingLeft.Size = new System.Drawing.Size(1, 328);
- this.onePxSpacingLeft.TabIndex = 1;
- //
- // ToolkitControl
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
- this.Controls.Add(this.toolStripEx);
- this.Controls.Add(this.onePxSpacingLeft);
- this.Margin = new System.Windows.Forms.Padding(0);
- this.Name = "ToolkitControl";
- this.Size = new System.Drawing.Size(48, 328);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- private void ToolStripEx_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Delete)
- { _docv.MouseEvent_Del(null, null); }
- }
- public event EventHandler RelinquishFocus;
- private void OnRelinquishFocus()
- {
- if (RelinquishFocus != null)
- {
- RelinquishFocus(this, EventArgs.Empty);
- }
- }
- private void ToolStripEx_RelinquishFocus(object sender, EventArgs e)
- {
- OnRelinquishFocus();
- }
- private void ToolStripEx_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- if (_btnActionMap == null) InitActionMap();
- _buttonNow = e.ClickedItem as ToolStripButton;
- var tag = e.ClickedItem.Tag as ShortcutbarModel.Item;
- var id = tag.Id;
- if (_btnActionMap.Keys.Contains(id))
- {
- _btnActionMap[id]();
- }
- else
- {
- if (_docv.Document != null)
- _docv.ActiveTool = (DrawToolType)id;
- }
- }
- ToolStripButton _buttonNow;
- ToolStripButton _buttonContinue;
- Dictionary<int, Action> _btnActionMap;
- void InitActionMap()
- {
- _btnActionMap = new Dictionary<int, Action>();
- _btnActionMap.Add(701, SelectClicked);
- _btnActionMap.Add(702, SelectAllClicked);
- _btnActionMap.Add(704, ContinueDrawClicked);
- _btnActionMap.Add(705, DeleteAllClicked);
- _btnActionMap.Add(1211, ScriptClicked);
- }
- private void ScriptClicked()
- {
- List<mic_script> list = mic_script_BLL.FindAll();
- var scp = list.Find((e) => e.name == _buttonNow.ToolTipText);
- //获取当前选中的脚本步骤
- List<mic_script_step> steps = mic_script_step_BLL.FindAllByScripId(scp.id);
- var paramss = mic_script_step_param_BLL.FindAllByScriptId(scp.id);
- //循环脚本步骤
- foreach (mic_script_step step in steps)
- {
- //递归的方式
- this.RecursiveData(_app.ToolBar.MainMenu.Items/*this.collection*/, step);
- }
- }
- /// <summary>
- /// 递归查找菜单,暂时不用,改成直接用name查找
- /// </summary>
- /// <param name="collection"></param>
- /// <param name="step"></param>
- private void RecursiveData(ToolStripItemCollection collection, mic_script_step step)
- {
- for (int i = 0; i < collection.Count; i++)
- {
- if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection"))
- {
- if (collection[i] is PdnMenuItem)
- {
- if (step.menu_id == ((PdnMenuItem)collection[i]).MenuId)
- {
- ((PdnMenuItem)collection[i]).PerformClick();
- }
- RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, step);
- }
- }
- }
- }
- private void DeleteAllClicked()
- {
- _docv.GraphicsList.Clear();
- }
- private void ContinueDrawClicked()
- {
- _docv.ContinuousDrawingMeasure = !_docv.ContinuousDrawingMeasure;
- _buttonNow.Checked = _docv.ContinuousDrawingMeasure;
- }
- public void UpdateDisplay()
- {
- if (_buttonContinue != null)
- _buttonContinue.Checked = _docv.ContinuousDrawingMeasure;
- }
- private void SelectClicked()
- {
- _docv.ActiveTool = DrawToolType.Pointer;
- }
- private void SelectAllClicked()
- {
- _docv.GraphicsList.SelectAll();
- }
- }
- }
|