/// <summary> /// 各メニューを構築します /// </summary> public void InitializeMenus() { _menuAllItems = new List <OperationMenuItem>(); // 作成メニュー _createMenuItem = new ToolStripMenuItem("Create"); _createMenuItem.DropDownOpening += onMenuOpening; // 作成されるオブジェクトごとにメニューを分けるので,作成されるオブジェクトを列挙 HashSet <Type> motionObjectTypes = new HashSet <Type>(); bool otherTypeExists = false; foreach (IMotionOperationCreateObject ope in _dataSet.GetOperationCreateObject()) { Type t = ope.CreatedType; if (t != null && t.IsSubclassOf(typeof(MotionObject))) { motionObjectTypes.Add(t); } else { otherTypeExists = true; } } // 作成されるオブジェクトごとのメニューを作成 Dictionary <Type, ToolStripMenuItem> typeMenus = new Dictionary <Type, ToolStripMenuItem>(); foreach (Type type in motionObjectTypes) { MotionObjectInfo testInfo = new MotionObjectInfo(type); MotionObject testObj = testInfo.GetEmptyObject(); ToolStripMenuItem item = new ToolStripMenuItem(type.Name, testObj.GetIcon() ?? global::MotionDataHandler.Properties.Resources.question); typeMenus[type] = item; } ToolStripMenuItem otherTypeMenu = new ToolStripMenuItem("General"); // 処理ごとにメニューを作成 foreach (bool isEditWrapper in new bool[] { false, true }) { if (isEditWrapper) { foreach (Type t in motionObjectTypes) { typeMenus[t].DropDownItems.Add(new ToolStripSeparator()); } if (otherTypeExists) { otherTypeMenu.DropDownItems.Add(new ToolStripSeparator()); } } foreach (IMotionOperationCreateObject ope in _dataSet.GetOperationCreateObject()) { if ((ope is MotionOperationEditToCreateWrapper) != isEditWrapper) { continue; } Type t = ope.CreatedType; ToolStripMenuItem item = new ToolStripMenuItem(ope.GetTitle()); try { Bitmap icon = ope.IconBitmap; if (icon != null) { item.Image = icon; } } catch (NotImplementedException) { } IMotionOperationCreateObject opeForLabmda = ope; item.Click += new EventHandler((sender, e) => { DialogMotionOperation dialog = new DialogMotionOperation(ScriptConsole.Singleton, opeForLabmda); dialog.ShowDialog(); }); _menuAllItems.Add(new OperationMenuItem(ope, item)); if (motionObjectTypes.Contains(t)) { typeMenus[t].DropDownItems.Add(item); } else { otherTypeMenu.DropDownItems.Add(item); } } } foreach (Type t in motionObjectTypes.OrderBy(t => t.Name)) { _createMenuItem.DropDownItems.Add(typeMenus[t]); } if (otherTypeExists) { _createMenuItem.DropDownItems.Add(otherTypeMenu); } if (_createMenuItem.DropDownItems.Count == 0) { _createMenuItem = null; } // その他 _editMenuItem = new ToolStripMenuItem(); _outputMenuItem = new ToolStripMenuItem(); _generalMenuItem = new ToolStripMenuItem(); List <MenuAutoGenerator> genList = new List <MenuAutoGenerator>(); genList.Add(new MenuAutoGenerator("Edit", _editMenuItem, () => _dataSet.GetOperationEditObject().Select(ope => (IMotionOperationBase)ope).ToList())); genList.Add(new MenuAutoGenerator("Output", _outputMenuItem, () => _dataSet.GetOperationOutputSequence().Select(ope => (IMotionOperationBase)ope).ToList())); genList.Add(new MenuAutoGenerator("General", _generalMenuItem, () => _dataSet.GetOperationGeneral().Select(ope => (IMotionOperationBase)ope).ToList())); foreach (MenuAutoGenerator gen in genList) { gen.OutputMenu.Text = gen.DefaultName; gen.OutputMenu.DropDownOpening += onMenuOpening; foreach (IMotionOperationBase ope in gen.OperationGenerator()) { ToolStripMenuItem item = new ToolStripMenuItem(ope.GetTitle()); try { Bitmap icon = ope.IconBitmap; if (icon != null) { item.Image = icon; } } catch (NotImplementedException) { } IMotionOperationBase opeForLabmda = ope; item.Click += new EventHandler((sender, e) => { DialogMotionOperation dialog = new DialogMotionOperation(ScriptConsole.Singleton, opeForLabmda); dialog.ShowDialog(); }); _menuAllItems.Add(new OperationMenuItem(ope, item)); gen.OutputMenu.DropDownItems.Add(item); } } if (_editMenuItem.DropDownItems.Count == 0) { _editMenuItem = null; } if (_outputMenuItem.DropDownItems.Count == 0) { _outputMenuItem = null; } if (_generalMenuItem.DropDownItems.Count == 0) { _generalMenuItem = null; } }