示例#1
0
        private void OnSelectionChanged(object sender, EventArgs e)
        {
            ISelectionService selectionService   = (ISelectionService)this.GetService(typeof(ISelectionService));
            ICollection       selectedComponents = selectionService?.GetSelectedComponents();

            isSelected = false;

            if (selectedComponents != null)
            {
                foreach (object component in selectedComponents)
                {
                    if (component == this.Component)
                    {
                        isSelected = true;
                    }
                }
            }
        }
 private void AddSelectionGlyphs(SelectionManager selMgr, ISelectionService selectionService)
 {
     ICollection selectedComponents = selectionService.GetSelectedComponents();
     GlyphCollection glyphs = new GlyphCollection();
     foreach (object obj2 in selectedComponents)
     {
         ToolStripItem component = obj2 as ToolStripItem;
         if (component != null)
         {
             ToolStripItemDesigner designer = (ToolStripItemDesigner) this.host.GetDesigner(component);
             if (designer != null)
             {
                 designer.GetGlyphs(ref glyphs, new ResizeBehavior(component.Site));
             }
         }
     }
     if (glyphs.Count > 0)
     {
         selMgr.SelectionGlyphAdorner.Glyphs.AddRange(glyphs);
     }
 }
        private void Delete(object sender, EventArgs args)
        {
            IDesignerHost     host      = GetService(typeof(IDesignerHost)) as IDesignerHost;
            ISelectionService selection = GetService(typeof(ISelectionService)) as ISelectionService;

            if (host == null || selection == null)
            {
                return;
            }

            ICollection selectedComponents = selection.GetSelectedComponents();
            string      description        = "Delete " +
                                             (selectedComponents.Count > 1 ? (selectedComponents.Count.ToString() + " controls") :
                                              ((IComponent)selection.PrimarySelection).Site.Name);
            DesignerTransaction transaction = host.CreateTransaction(description);

            foreach (object component in selectedComponents)
            {
                if (component != host.RootComponent)
                {
                    ComponentDesigner designer = host.GetDesigner((IComponent)component) as ComponentDesigner;
                    if (designer != null && designer.AssociatedComponents != null)
                    {
                        foreach (object associatedComponent in designer.AssociatedComponents)
                        {
                            host.DestroyComponent((IComponent)associatedComponent);
                        }
                    }
                    host.DestroyComponent((IComponent)component);
                }
            }
#if NET_2_0
            selection.SetSelectedComponents(selectedComponents, SelectionTypes.Remove);
#else
            selection.SetSelectedComponents(selectedComponents);
#endif
            transaction.Commit();
        }
示例#4
0
        public void DestroyComponent(IComponent component)
        {
            //deselect it if selected
            ISelectionService sel = this.GetService(typeof(ISelectionService)) as ISelectionService;
            bool found            = false;

            if (sel != null)
            {
                foreach (IComponent c in sel.GetSelectedComponents())
                {
                    if (c == component)
                    {
                        found = true;
                        break;
                    }
                }
            }
            //can't modify selection in loop
            if (found)
            {
                sel.SetSelectedComponents(null);
            }

            if (component != RootComponent)
            {
                //remove from component and document
                ((Control)RootComponent).Controls.Remove((Control)component);
                RootDocument.RemoveControl((Control)component);
            }

            //remove from container if still sited
            if (component.Site != null)
            {
                container.Remove(component);
            }

            component.Dispose();
        }
        private void UndoUnits(object owningObject)
        {
            UndoEngineImpl undoEngineImpl = designerhost.GetService(typeof(UndoEngine)) as UndoEngineImpl;

            if (undoEngineImpl.UndoInProgress == true && undoEngineImpl.UndoUnitName != null && undoEngineImpl.UndoUnitName.IndexOf("删除") == -1 && undoEngineImpl.UndoUnitName.IndexOf("创建") == -1 && undoEngineImpl.UndoUnitName.ToLower().IndexOf("remove") == -1 && undoEngineImpl.UndoUnitName.ToLower().IndexOf("create") == -1)
            {
                for (int i = undoStockImpl.Count - 1; i >= 0; i--)
                {
                    UndoUnitImpl undoUnitImpl = undoStockImpl[i];
                    undoUnitImpl.Undo();
                    undoStockImpl.Remove(undoUnitImpl);
                    redoStockImpl.Add(undoUnitImpl);

                    if (owningObject == undoUnitImpl.OwningObject)
                    {
                        break;
                    }
                }

                ISelectionService selection = designerhost.GetService(typeof(ISelectionService)) as ISelectionService;
                selection.SetSelectedComponents(selection.GetSelectedComponents());
            }
        }
示例#6
0
        private void SelSvc_SelectionChanged(object sender, EventArgs e)
        {
            if (program == null)
            {
                return;
            }
            var ar = selSvc.GetSelectedComponents()
                     .Cast <AddressRange>()
                     .FirstOrDefault();

            if (ar == null)
            {
                return;
            }
            if (!program.SegmentMap.TryFindSegment(ar.Begin, out var seg))
            {
                return;
            }
            //$TODO: what about non-byte-granularity.
            this.bmem = seg.MemoryArea as ByteMemoryArea;
            UpdateScrollbar();
            Invalidate();
        }
示例#7
0
        protected override void OnPaintAdornments(PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);

            using (Pen p = new Pen(Color.Black))
            {
                p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

                ISelectionService host = GetService(typeof(ISelectionService)) as ISelectionService;

                if (host != null)
                {
                    foreach (IComponent comp in host.GetSelectedComponents())
                    {
                        RibbonItem item = comp as RibbonItem;
                        if (item != null && !Ribbon.OrbDropDown.AllItems.Contains(item))
                        {
                            pe.Graphics.DrawRectangle(p, item.Bounds);
                        }
                    }
                }
            }
        }
示例#8
0
        void ExecuteCut(object sender, EventArgs e)
        {
            IDesignerHost host = (IDesignerHost)(this.GetService(typeof(IDesignerHost)));

            if (host != null)
            {
                ISelectionService ss = (ISelectionService)host.GetService(typeof(ISelectionService));
                if (ss != null)
                {
                    ICollection cc = ss.GetSelectedComponents();
                    if (cc != null)
                    {
                        using (DesignerTransaction trans = host.CreateTransaction("Cut " + cc.Count + " component(s)"))
                        {
                            ExecuteCopy(sender, e);
                            ExecuteDel(sender, e);
                            trans.Commit();
                            enableUndoMenu();
                        }
                    }
                }
            }
        }
示例#9
0
        protected override void OnPaintAdornments(PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);


            using (Pen p = new Pen(Color.Black))
            {
                p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

                ISelectionService host = GetService(typeof(ISelectionService)) as ISelectionService;

                if (host != null)
                {
                    foreach (IComponent comp in host.GetSelectedComponents())
                    {
                        if (comp is IRibbonElement)
                        {
                            pe.Graphics.DrawRectangle(p, (comp as IRibbonElement).Bounds);
                        }
                    }
                }
            }
        }
示例#10
0
        private ActivityDesigner GetDesignerToResize(Point point, out DesignerEdges sizingEdge)
        {
            ActivityDesigner designer = null;

            sizingEdge = DesignerEdges.None;
            ISelectionService service = base.GetService(typeof(ISelectionService)) as ISelectionService;

            if (service != null)
            {
                ArrayList list = new ArrayList(service.GetSelectedComponents());
                for (int i = 0; (i < list.Count) && (designer == null); i++)
                {
                    Activity activity = list[i] as Activity;
                    if (activity != null)
                    {
                        ActivityDesigner designer2 = ActivityDesigner.GetDesigner(activity);
                        if (designer2 != null)
                        {
                            SelectionGlyph glyph = designer2.Glyphs[typeof(SelectionGlyph)] as SelectionGlyph;
                            if (glyph != null)
                            {
                                foreach (Rectangle rectangle in glyph.GetGrabHandles(designer2))
                                {
                                    if (rectangle.Contains(point))
                                    {
                                        designer   = designer2;
                                        sizingEdge = this.GetSizingEdge(designer, point);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(designer);
        }
示例#11
0
        public void UpdatePropertyGridHost(DesignSurfaceExt2 surface)
        {
            IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));

            if (null == host)
            {
                return;
            }
            if (null == host.RootComponent)
            {
                return;
            }
            //- sync the PropertyGridHost
            if (host.TransactionDescription == null)
            {
                return;
            }

            string[]          transactionArr   = host.TransactionDescription.Split(' ');
            ISelectionService selectionService = (ISelectionService)(ActiveDesignSurface.GetService(typeof(ISelectionService)));
            ICollection       i = selectionService.GetSelectedComponents();

            //if (transactionArr[0] == "Move" || transactionArr[0] == "Resize")
            if (transactionArr[0] != "Move" && transactionArr[0] != "Resize")
            {
                //if (transactionArr[0] == "Delete")
                //{
                //    this.PropertyGridHost.DeleteReportControlPropertyItem();
                //}
                this.PropertyGridHost.SelectedObject = host.RootComponent;
            }
            else
            {
                this.PropertyGridHost.SelectedObject = this.PropertyGridHost.SelectedObject;
                updateStatusBar(this.PropertyGridHost.reportCtrlProp.reportControlProperty);
            }
        }
示例#12
0
        /// <summary>
        /// 使控件宽度相等
        /// </summary>
        public void HorizSpaceMakeEqual()
        {
            ISelectionService       selection = GetService(typeof(ISelectionService)) as ISelectionService;
            IDesignerHost           idh       = GetService(typeof(IDesignerHost)) as IDesignerHost;
            IComponentChangeService cs        = GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (selection.SelectionCount > 1 && selection.PrimarySelection != idh.RootComponent)
            {
                Control pControl = selection.PrimarySelection as Control;

                foreach (Control ctrl in selection.GetSelectedComponents())
                {
                    if (ctrl != pControl)
                    {
                        PropertyDescriptor prop = TypeDescriptor.GetProperties(ctrl.GetType())["Width"];

                        cs.OnComponentChanging(ctrl, prop);
                        int oldWidth = ctrl.Width;
                        ctrl.Width = pControl.Width;
                        cs.OnComponentChanged(ctrl, prop, oldWidth, ctrl.Width);
                    }
                }
            }
        }
示例#13
0
        protected override bool OnMouseDoubleClick(MouseEventArgs eventArgs)
        {
            ISelectionService service = base.GetService(typeof(ISelectionService)) as ISelectionService;

            if (service != null)
            {
                ArrayList list = new ArrayList(service.GetSelectedComponents());
                for (int i = 0; i < list.Count; i++)
                {
                    Activity activity = list[i] as Activity;
                    if (activity != null)
                    {
                        IDesigner designer = ActivityDesigner.GetDesigner(activity);
                        if (designer != null)
                        {
                            designer.DoDefaultAction();
                            ((IWorkflowDesignerMessageSink)designer).OnMouseDoubleClick(eventArgs);
                            break;
                        }
                    }
                }
            }
            return(false);
        }
示例#14
0
		private void OnSelectionChanged(object sender, EventArgs e)
		{
			ISelectionService service=(ISelectionService)this.GetService(typeof(ISelectionService));
			this.collapsibleContainerSelected=false;
			if(service!=null)
			{
				foreach(object obj2 in service.GetSelectedComponents())
				{
					CollapsibleContainerPanel panel=obj2 as CollapsibleContainerPanel;
					if((panel!=null)&&(panel.Parent==this.collapsibleContainer))
					{
						this.collapsibleContainerSelected=false;
						this.Selected=panel;
						break;
					}
					this.Selected=null;
					if(obj2==this.collapsibleContainer)
					{
						this.collapsibleContainerSelected=true;
						break;
					}
				}
			}
		}
示例#15
0
        private void UpdatePropertyGrid(IServiceProvider serviceProvider)
        {
            _propertyGrid.SelectedObject = null;
            if (serviceProvider == null)
            {
                return;
            }
            ISelectionService selectionService = serviceProvider.GetService(typeof(ISelectionService)) as ISelectionService;

            if (selectionService == null)
            {
                return;
            }

            ICollection selectionCollection = selectionService.GetSelectedComponents();

            if (selectionCollection != null)
            {
                object[] selection = new object[selectionCollection.Count];
                selectionCollection.CopyTo(selection, 0);
                _propertyGrid.SelectedObjects = selection;
                ShowEventsTab();
            }
        }
        private void OnTabSelectedIndexChanged(object sender, EventArgs e)
        {
            ISelectionService service = (ISelectionService)this.GetService(typeof(ISelectionService));

            if (service != null)
            {
                ICollection selectedComponents = service.GetSelectedComponents();
                TabControl  component          = (TabControl)base.Component;
                bool        flag = false;
                foreach (object obj2 in selectedComponents)
                {
                    TabPage tabPageOfComponent = GetTabPageOfComponent(obj2);
                    if (((tabPageOfComponent != null) && (tabPageOfComponent.Parent == component)) && (tabPageOfComponent == component.SelectedTab))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    service.SetSelectedComponents(new object[] { base.Component });
                }
            }
        }
示例#17
0
        private void OnTabSelectedIndexChanged(object sender, EventArgs e)
        {
            ISelectionService service1 = (ISelectionService)this.GetService(typeof(ISelectionService));

            if (service1 != null)
            {
                ICollection collection1 = service1.GetSelectedComponents();
                TabControl  control1    = (TabControl)base.Component;
                bool        flag1       = false;
                foreach (object obj1 in collection1)
                {
                    TabPage page1 = TabControlDesigner.GetTabPageOfComponent(obj1);
                    if (((page1 != null) && (page1.Parent == control1)) && (page1 == control1.SelectedTab))
                    {
                        flag1 = true;
                        break;
                    }
                }
                if (!flag1)
                {
                    service1.SetSelectedComponents(new object[] { base.Component });
                }
            }
        }
示例#18
0
		void UpdatePropertyPadSelection(ISelectionService selectionService)
		{
			ICollection selection = selectionService.GetSelectedComponents();
			var selArray = new object[selection.Count];
			selection.CopyTo(selArray, 0);
			propertyContainer.SelectedObjects = selArray;
		}
示例#19
0
        /// <summary>
        /// Creates a method signature in the source code file for the default event on the component and navigates the user's cursor to that location in preparation to assign the default action.
        /// </summary>
        public virtual void DoDefaultAction()
        {
            IEventBindingService eps = (IEventBindingService)GetService(typeof(IEventBindingService));

            //If the event binding service is not available, there is nothing much we can do, so just return.
            if (eps == null)
            {
                return;
            }

            ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));

            if (selectionService == null)
            {
                return;
            }

            ICollection         components       = selectionService.GetSelectedComponents();
            EventDescriptor     thisDefaultEvent = null;
            string              thisHandler      = null;
            IDesignerHost       host             = (IDesignerHost)GetService(typeof(IDesignerHost));
            DesignerTransaction t = null;

            try
            {
                foreach (object comp in components)
                {
                    if (!(comp is IComponent))
                    {
                        continue;
                    }

                    EventDescriptor    defaultEvent     = TypeDescriptor.GetDefaultEvent(comp);
                    PropertyDescriptor defaultPropEvent = null;
                    string             handler          = null;
                    bool eventChanged = false;

                    if (defaultEvent != null)
                    {
                        defaultPropEvent = eps.GetEventProperty(defaultEvent);
                    }

                    // If we couldn't find a property for this event, or of the property is read only, then abort.
                    if (defaultPropEvent == null || defaultPropEvent.IsReadOnly)
                    {
                        continue;
                    }

                    try
                    {
                        if (host != null && t == null)
                        {
                            t = host.CreateTransaction(string.Format(SR.ComponentDesignerAddEvent, defaultEvent.Name));
                        }
                    }
                    catch (CheckoutException cxe)
                    {
                        if (cxe == CheckoutException.Canceled)
                        {
                            return;
                        }

                        throw cxe;
                    }

                    // handler will be null if there is no explicit event hookup in the parsed init method
                    handler = (string)defaultPropEvent.GetValue(comp);

                    if (handler == null)
                    {
                        eventChanged = true;

                        handler = eps.CreateUniqueMethodName((IComponent)comp, defaultEvent);
                    }
                    else
                    {
                        // ensure the handler is still there
                        eventChanged = true;
                        foreach (string compatibleMethod in eps.GetCompatibleMethods(defaultEvent))
                        {
                            if (handler == compatibleMethod)
                            {
                                eventChanged = false;
                                break;
                            }
                        }
                    }

                    // Save the new value... BEFORE navigating to it!
                    //s_codemarkers.CodeMarker(CodeMarkerEvent.perfFXBindEventDesignToCode);
                    if (eventChanged && defaultPropEvent != null)
                    {
                        defaultPropEvent.SetValue(comp, handler);
                    }

                    if (_component == comp)
                    {
                        thisDefaultEvent = defaultEvent;
                        thisHandler      = handler;
                    }
                }
            }
            catch (InvalidOperationException)
            {
                if (t != null)
                {
                    t.Cancel();
                    t = null;
                }
            }
            finally
            {
                if (t != null)
                {
                    t.Commit();
                }
            }

            // Now show the event code.
            if (thisHandler != null && thisDefaultEvent != null)
            {
                eps.ShowCode(_component, thisDefaultEvent);
            }
        }
        /// <summary>
        ///  When any MouseMove message enters the BehaviorService's AdornerWindow (mousemove, ncmousemove) it is first passed here, to the top-most Behavior in the BehaviorStack.  Returning 'true' from this function signifies that  the Message was 'handled' by the Behavior and should not continue to be processed.
        /// </summary>
        public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
        {
            bool retVal = false;
            ToolStripItemGlyph glyph     = g as ToolStripItemGlyph;
            ToolStripItem      glyphItem = glyph.Item;
            ISelectionService  selSvc    = GetSelectionService(glyphItem);

            if (selSvc == null || glyphItem.Site == null || MouseHandlerPresent(glyphItem))
            {
                return(false);
            }
            if (!selSvc.GetComponentSelected(glyphItem))
            {
                PaintInsertionMark(glyphItem);
                retVal = false;
            }

            if (button == MouseButtons.Left && glyph != null && glyph.ItemDesigner != null && !glyph.ItemDesigner.IsEditorActive)
            {
                Rectangle     dragBox      = Rectangle.Empty;
                IDesignerHost designerHost = (IDesignerHost)glyphItem.Site.GetService(typeof(IDesignerHost));
                Debug.Assert(designerHost != null, "Invalid DesignerHost");
                if (glyphItem.Placement == ToolStripItemPlacement.Overflow || (glyphItem.Placement == ToolStripItemPlacement.Main && !(glyphItem.IsOnDropDown)))
                {
                    ToolStripItemDesigner itemDesigner    = glyph.ItemDesigner;
                    ToolStrip             parentToolStrip = itemDesigner.GetMainToolStrip();
                    if (designerHost.GetDesigner(parentToolStrip) is ToolStripDesigner parentDesigner)
                    {
                        dragBox = parentDesigner.DragBoxFromMouseDown;
                    }
                }
                else if (glyphItem.IsOnDropDown)
                {
                    //Get the OwnerItem's Designer and set the value...
                    if (glyphItem.Owner is ToolStripDropDown parentDropDown)
                    {
                        ToolStripItem ownerItem = parentDropDown.OwnerItem;
                        if (designerHost.GetDesigner(ownerItem) is ToolStripItemDesigner ownerItemDesigner)
                        {
                            dragBox = ownerItemDesigner.dragBoxFromMouseDown;
                        }
                    }
                }
                // If the mouse moves outside the rectangle, start the drag.
                if (dragBox != Rectangle.Empty && !dragBox.Contains(mouseLoc.X, mouseLoc.Y))
                {
                    if (_timer != null)
                    {
                        _timer.Enabled = false;
                        _timer.Tick   -= new System.EventHandler(OnDoubleClickTimerTick);
                        _timer.Dispose();
                        _timer = null;
                    }

                    // Proceed with the drag and drop, passing in the list item.
                    try
                    {
                        ArrayList   dragItems = new ArrayList();
                        ICollection selComps  = selSvc.GetSelectedComponents();
                        //create our list of controls-to-drag
                        foreach (IComponent comp in selComps)
                        {
                            if (comp is ToolStripItem item)
                            {
                                dragItems.Add(item);
                            }
                        }

                        //Start Drag-Drop only if ToolStripItem is the primary Selection
                        if (selSvc.PrimarySelection is ToolStripItem selectedItem)
                        {
                            ToolStrip owner = selectedItem.Owner;
                            ToolStripItemDataObject data = new ToolStripItemDataObject(dragItems, selectedItem, owner);
                            DropSource.QueryContinueDrag += new QueryContinueDragEventHandler(QueryContinueDrag);
                            if (glyphItem is ToolStripDropDownItem ddItem)
                            {
                                if (designerHost.GetDesigner(ddItem) is ToolStripMenuItemDesigner itemDesigner)
                                {
                                    itemDesigner.InitializeBodyGlyphsForItems(false, ddItem);
                                    ddItem.HideDropDown();
                                }
                            }
                            else if (glyphItem.IsOnDropDown && !glyphItem.IsOnOverflow)
                            {
                                ToolStripDropDown     dropDown  = glyphItem.GetCurrentParent() as ToolStripDropDown;
                                ToolStripDropDownItem ownerItem = dropDown.OwnerItem as ToolStripDropDownItem;
                                selSvc.SetSelectedComponents(new IComponent[] { ownerItem }, SelectionTypes.Replace);
                            }
                            DropSource.DoDragDrop(data, DragDropEffects.All);
                        }
                    }
                    finally
                    {
                        DropSource.QueryContinueDrag -= new QueryContinueDragEventHandler(QueryContinueDrag);
                        //Reset all Drag-Variables
                        SetParentDesignerValuesForDragDrop(glyphItem, false, Point.Empty);
                        ToolStripDesigner.s_dragItem = null;
                        _dropSource = null;
                    }
                    retVal = false;
                }
            }
            return(retVal);
        }
        // Occurs when MouseDown on the TooLStripItem glyph
        public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
        {
            ToolStripItemGlyph glyph     = g as ToolStripItemGlyph;
            ToolStripItem      glyphItem = glyph.Item;
            ISelectionService  selSvc    = GetSelectionService(glyphItem);
            BehaviorService    bSvc      = GetBehaviorService(glyphItem);
            ToolStripKeyboardHandlingService keyService = GetKeyBoardHandlingService(glyphItem);

            if ((button == MouseButtons.Left) && (keyService != null) && (keyService.TemplateNodeActive))
            {
                if (keyService.ActiveTemplateNode.IsSystemContextMenuDisplayed)
                {
                    // skip behaviors when the context menu is displayed
                    return(false);
                }
            }

            IDesignerHost designerHost = (IDesignerHost)glyphItem.Site.GetService(typeof(IDesignerHost));

            Debug.Assert(designerHost != null, "Invalid DesignerHost");

            //Cache original selection
            ICollection originalSelComps = null;

            if (selSvc != null)
            {
                originalSelComps = selSvc.GetSelectedComponents();
            }

            // Add the TemplateNode to the Selection if it is currently Selected as the GetSelectedComponents wont do it for us.
            ArrayList origSel = new ArrayList(originalSelComps);

            if (origSel.Count == 0)
            {
                if (keyService != null && keyService.SelectedDesignerControl != null)
                {
                    origSel.Add(keyService.SelectedDesignerControl);
                }
            }

            if (keyService != null)
            {
                keyService.SelectedDesignerControl = null;
                if (keyService.TemplateNodeActive)
                {
                    // If templateNode Active .. commit and Select it
                    keyService.ActiveTemplateNode.CommitAndSelect();
                    // if the selected item is clicked .. then commit the node and reset the selection (refer 488002)
                    if (selSvc.PrimarySelection is ToolStripItem currentSel && currentSel == glyphItem)
                    {
                        selSvc.SetSelectedComponents(null, SelectionTypes.Replace);
                    }
                }
            }

            if (selSvc == null || MouseHandlerPresent(glyphItem))
            {
                return(false);
            }

            if (glyph != null && button == MouseButtons.Left)
            {
                ToolStripItem selectedItem = selSvc.PrimarySelection as ToolStripItem;
                // Always set the Drag-Rect for Drag-Drop...
                SetParentDesignerValuesForDragDrop(glyphItem, true, mouseLoc);
                // Check if this item is already selected ...
                if (selectedItem != null && selectedItem == glyphItem)
                {
                    // If the Selecteditem is already in editmode ... bail out
                    if (selectedItem != null)
                    {
                        ToolStripItemDesigner selectedItemDesigner = glyph.ItemDesigner;
                        if (selectedItemDesigner != null && selectedItemDesigner.IsEditorActive)
                        {
                            return(false);
                        }
                    }

                    // Check if this is CTRL + Click or SHIFT + Click, if so then just remove the selection
                    bool removeSel = (Control.ModifierKeys & (Keys.Control | Keys.Shift)) > 0;
                    if (removeSel)
                    {
                        selSvc.SetSelectedComponents(new IComponent[] { selectedItem }, SelectionTypes.Remove);
                        return(false);
                    }

                    //start Double Click Timer
                    // This is required for the second down in selection which can be the first down of a Double click on the glyph confusing... hence this comment ...
                    // Heres the scenario ....
                    // DOWN 1 - selects the ITEM
                    // DOWN 2 - ITEM goes into INSITU....
                    // DOUBLE CLICK - dont show code..
                    // Open INSITU after the double click time
                    if (selectedItem is ToolStripMenuItem)
                    {
                        _timer = new Timer
                        {
                            Interval = SystemInformation.DoubleClickTime
                        };
                        _timer.Tick   += new EventHandler(OnDoubleClickTimerTick);
                        _timer.Enabled = true;
                        _selectedGlyph = glyph;
                    }
                }
                else
                {
                    bool shiftPressed = (Control.ModifierKeys & Keys.Shift) > 0;
                    // We should process MouseDown only if we are not yet selected....
                    if (!selSvc.GetComponentSelected(glyphItem))
                    {
                        //Reset the State... On the Glpyhs .. we get MouseDown - Mouse UP (for single Click) And we get MouseDown - MouseUp - DoubleClick - Up (for double Click) Hence reset the state at start....
                        _mouseUpFired     = false;
                        _doubleClickFired = false;
                        //Implementing Shift + Click....
                        // we have 2 items, namely, selectedItem (current PrimarySelection) and glyphItem (item which has received mouseDown) FIRST check if they have common parent...  IF YES then get the indices of the two and SELECT all items from LOWER index to the HIGHER index.
                        if (shiftPressed && (selectedItem != null && CommonParent(selectedItem, glyphItem)))
                        {
                            ToolStrip parent = null;
                            if (glyphItem.IsOnOverflow)
                            {
                                parent = glyphItem.Owner;
                            }
                            else
                            {
                                parent = glyphItem.GetCurrentParent();
                            }
                            int startIndexOfSelection = Math.Min(parent.Items.IndexOf(selectedItem), parent.Items.IndexOf(glyphItem));
                            int endIndexOfSelection   = Math.Max(parent.Items.IndexOf(selectedItem), parent.Items.IndexOf(glyphItem));
                            int countofItemsSelected  = (endIndexOfSelection - startIndexOfSelection) + 1;

                            // if two adjacent items are selected ...
                            if (countofItemsSelected == 2)
                            {
                                selSvc.SetSelectedComponents(new IComponent[] { glyphItem });
                            }
                            else
                            {
                                object[] totalObjects = new object[countofItemsSelected];
                                int      j            = 0;
                                for (int i = startIndexOfSelection; i <= endIndexOfSelection; i++)
                                {
                                    totalObjects[j++] = parent.Items[i];
                                }
                                selSvc.SetSelectedComponents(new IComponent[] { parent }, SelectionTypes.Replace);
                                ToolStripDesigner.s_shiftState = true;
                                selSvc.SetSelectedComponents(totalObjects, SelectionTypes.Replace);
                            }
                        }
                        //End Implmentation
                        else
                        {
                            if (glyphItem.IsOnDropDown && ToolStripDesigner.s_shiftState)
                            {
                                //Invalidate glyh only if we are in ShiftState...
                                ToolStripDesigner.s_shiftState = false;
                                if (bSvc != null)
                                {
                                    bSvc.Invalidate(glyphItem.Owner.Bounds);
                                }
                            }
                            selSvc.SetSelectedComponents(new IComponent[] { glyphItem }, SelectionTypes.Auto);
                        }
                        // Set the appropriate object.
                        if (keyService != null)
                        {
                            keyService.ShiftPrimaryItem = glyphItem;
                        }
                    }
                    // we are already selected and if shiftpressed...
                    else if (shiftPressed || (Control.ModifierKeys & Keys.Control) > 0)
                    {
                        selSvc.SetSelectedComponents(new IComponent[] { glyphItem }, SelectionTypes.Remove);
                    }
                }
            }

            if (glyph != null && button == MouseButtons.Right)
            {
                if (!selSvc.GetComponentSelected(glyphItem))
                {
                    selSvc.SetSelectedComponents(new IComponent[] { glyphItem });
                }
            }

            // finally Invalidate all selections
            ToolStripDesignerUtils.InvalidateSelection(origSel, glyphItem, glyphItem.Site, false);
            return(false);
        }
示例#22
0
        private void RotateTabSelection(bool backwards)
        {
            ComponentTray.TrayControl control2         = null;
            ISelectionService         selectionService = base.SelectionService;

            if (selectionService != null)
            {
                IComponent component;
                Control    control;
                IComponent primarySelection = selectionService.PrimarySelection as IComponent;
                if (primarySelection != null)
                {
                    component = primarySelection;
                }
                else
                {
                    component = null;
                    foreach (object obj2 in selectionService.GetSelectedComponents())
                    {
                        IComponent component3 = obj2 as IComponent;
                        if (component3 != null)
                        {
                            component = component3;
                            break;
                        }
                    }
                }
                if (component != null)
                {
                    control = ComponentTray.TrayControl.FromComponent(component);
                }
                else
                {
                    control = null;
                }
                if (control != null)
                {
                    for (int i = 1; i < this.compositionUI.Controls.Count; i++)
                    {
                        if (this.compositionUI.Controls[i] == control)
                        {
                            int num2 = i + 1;
                            if (num2 >= this.compositionUI.Controls.Count)
                            {
                                num2 = 1;
                            }
                            ComponentTray.TrayControl control3 = this.compositionUI.Controls[num2] as ComponentTray.TrayControl;
                            if (control3 != null)
                            {
                                control2 = control3;
                                break;
                            }
                        }
                    }
                }
                else if (this.compositionUI.Controls.Count > 1)
                {
                    ComponentTray.TrayControl control4 = this.compositionUI.Controls[1] as ComponentTray.TrayControl;
                    if (control4 != null)
                    {
                        control2 = control4;
                    }
                }
                if (control2 != null)
                {
                    selectionService.SetSelectedComponents(new object[] { control2.Component }, SelectionTypes.Replace);
                }
            }
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (bMouseDown)
            {
                if (e.Button == MouseButtons.Left)
                {
                }
            }
            bMouseDown = false;
            if ((e.Button & MouseButtons.Right) == MouseButtons.Right)
            {
                int nSelectionCount = 0;
                ISelectionService selectionService = (ISelectionService)this.GetService(typeof(ISelectionService));
                if (selectionService != null)
                {
                    bool        selected = false;
                    ICollection ic       = selectionService.GetSelectedComponents();
                    if (ic != null)
                    {
                        nSelectionCount = ic.Count;
                        foreach (object v in ic)
                        {
                            if (v == this)
                            {
                                selected = true;
                                break;
                            }
                        }
                    }
                    if (!selected)
                    {
                        selectionService.SetSelectedComponents(new IComponent[] { this });
                        nSelectionCount = 1;
                    }
                }
                ContextMenu cm = new ContextMenu();
                MenuItem    mi;
                if (!ReadOnly)
                {
                    if (nSelectionCount == 1)
                    {
                        if (CanEditAction)
                        {
                            mi = new MenuItemWithBitmap("Edit", miEdit_Click, Resources._method.ToBitmap());
                            cm.MenuItems.Add(mi);
                        }
                        ////
                        if (this.CanReplaceAction)
                        {
                            mi = new MenuItemWithBitmap("Replace", miReplace_Click, Resources._replace.ToBitmap());
                            cm.MenuItems.Add(mi);
                        }
                        OnCreateContextMenu(cm);
                    }

                    if (nSelectionCount > 1 && CanDeleteAction)
                    {
                        mi = new MenuItemWithBitmap("Make action list", miMakeList_Click, Resources._actLst.ToBitmap());
                        cm.MenuItems.Add(mi);
                        mi = new MenuItemWithBitmap("Make action group", miMakeGroup_Click, Resources._method.ToBitmap());
                        cm.MenuItems.Add(mi);
                    }
                }
                if (nSelectionCount == 1)
                {
                    if (_act != null)
                    {
                        if (_act.BreakBeforeExecute)
                        {
                            cm.MenuItems.Add(new MenuItemWithBitmap("Remove break point before action", mnu_removeBefore, Resources._del_breakPoint.ToBitmap()));
                        }
                        else
                        {
                            cm.MenuItems.Add(new MenuItemWithBitmap("Add break point before action", mnu_addBefore, Resources._breakpoint.ToBitmap()));
                        }
                        if (_act.BreakAfterExecute)
                        {
                            cm.MenuItems.Add(new MenuItemWithBitmap("Remove break point after action", mnu_removeAfter, Resources._del_breakPoint.ToBitmap()));
                        }
                        else
                        {
                            cm.MenuItems.Add(new MenuItemWithBitmap("Add break point after action", mnu_addAfter, Resources._breakpoint.ToBitmap()));
                        }
                    }
                }
                if (!ReadOnly)
                {
                    if (nSelectionCount > 0 && CanDeleteAction)
                    {
                        cm.MenuItems.Add("-");
                        //
                        mi = new MenuItemWithBitmap("Delete", miDelete_Click, Resources._cancel.ToBitmap());
                        cm.MenuItems.Add(mi);
                        ////
                    }
                }
                if (cm.MenuItems.Count > 0)
                {
                    cm.Show(this, new Point(e.X, e.Y));
                }
            }
        }
示例#24
0
        private bool IsRecursiveDropOperation(ActivityDesigner dropTargetDesigner)
        {
            if (dropTargetDesigner == null)
            {
                return(false);
            }

            ISelectionService selectionService    = (ISelectionService)GetService(typeof(ISelectionService));
            CompositeActivity dropTargetComponent = dropTargetDesigner.Activity as CompositeActivity;

            if (dropTargetComponent == null || selectionService == null)
            {
                return(false);
            }

            // First check for activity designer specific recursion - possible recursion when drag-n-drop from outside the current
            // designer such toolbox or other activity designers.
            WorkflowView           workflowView = GetService(typeof(WorkflowView)) as WorkflowView;
            IDesignerHost          host         = GetService(typeof(IDesignerHost)) as IDesignerHost;
            WorkflowDesignerLoader loader       = GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

            // When drag-n-drop within the same designer, if the drag drop is not within designer or no valid droptarget, we do not do anything
            if (this.draggedActivities.Count == 0 || this.existingDraggedActivities.Count == 0)
            {
                return(false);
            }

            //Go thru all the components in dragged components and check for recursive dragdrop
            //Get all the top level activities being dragged dropped
            ArrayList         topLevelActivities = new ArrayList(Helpers.GetTopLevelActivities(selectionService.GetSelectedComponents()));
            CompositeActivity parentActivity     = dropTargetComponent;

            while (parentActivity != null)
            {
                if (topLevelActivities.Contains(parentActivity))
                {
                    return(true);
                }

                parentActivity = parentActivity.Parent;
            }


            return(false);
        }
示例#25
0
        public bool PreFilterMessage(ref Message m)
        {
            if (m.Msg != keyPressedMessage /*&& m.Msg != leftMouseButtonDownMessage*/)
            {
                return(false);
            }

            FormsDesignerViewContent formDesigner = WorkbenchSingleton.Workbench.ActiveContent as FormsDesignerViewContent;

            if (formDesigner == null || formDesigner.Host == null)
            {
                return(false);
            }
            if (formDesigner.UserContent != null && !((Control)formDesigner.UserContent).ContainsFocus)
            {
                return(false);
            }

            Control originControl = Control.FromChildHandle(m.HWnd);

            if (originControl != null && formDesigner.UserContent != null && !(formDesigner.UserContent == originControl || formDesigner.UserContent.Contains(originControl)))
            {
                // Ignore if message origin not in forms designer
                // (e.g. navigating the main menu)
                return(false);
            }

            Keys keyPressed = (Keys)m.WParam.ToInt32() | Control.ModifierKeys;

            if (keyPressed == Keys.Escape)
            {
                if (formDesigner.IsTabOrderMode)
                {
                    formDesigner.HideTabOrder();
                    return(true);
                }
            }

            CommandWrapper commandWrapper;

            if (keyTable.TryGetValue(keyPressed, out commandWrapper))
            {
                if (commandWrapper.CommandID == MenuCommands.Delete)
                {
                    // Check Delete menu is enabled.
                    if (!formDesigner.EnableDelete)
                    {
                        return(false);
                    }
                }
                LoggingService.Debug("Run menu command: " + commandWrapper.CommandID);

                IMenuCommandService menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService));
                ISelectionService   selectionService   = (ISelectionService)formDesigner.Host.GetService(typeof(ISelectionService));
                ICollection         components         = selectionService.GetSelectedComponents();
                if (components.Count == 1)
                {
                    foreach (IComponent component in components)
                    {
                        if (HandleMenuCommand(formDesigner, component, keyPressed))
                        {
                            return(false);
                        }
                    }
                }

                menuCommandService.GlobalInvoke(commandWrapper.CommandID);

                if (commandWrapper.RestoreSelection)
                {
                    selectionService.SetSelectedComponents(components);
                }
                return(true);
            }

            return(false);
        }
示例#26
0
        void HostSurface_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                ServiceSelection.SetSelectedComponents(new IComponent[] { DesignerHost.RootComponent });
            }
            else if (e.KeyCode == Keys.Delete)
            {
                this.PerformAction(System.ComponentModel.Design.StandardCommands.Delete);
            }
            else if (e.KeyCode == Keys.X && e.Control)
            {
                this.PerformAction(System.ComponentModel.Design.StandardCommands.Cut);
            }
            else if (e.KeyCode == Keys.C && e.Control)
            {
                this.PerformAction(System.ComponentModel.Design.StandardCommands.Copy);
            }
            else if (e.KeyCode == Keys.V && e.Control)
            {
                this.PerformAction(System.ComponentModel.Design.StandardCommands.Paste);
            }
            else if (e.KeyCode == Keys.Z && e.Control)
            {
                this.DoUndo();
            }
            else if (e.KeyCode == Keys.Y && e.Control)
            {
                this.DoRedo();
            }
            else if (e.KeyCode == Keys.A && e.Control)
            {
                this.PerformAction(System.ComponentModel.Design.StandardCommands.SelectAll);
            }


            #region Location
            else if (e.KeyCode == Keys.Left)
            {
                foreach (Component comp in ServiceSelection.GetSelectedComponents())
                {
                    if (comp is Control && comp != DesignerHost.RootComponent)
                    {
                        ((Control)comp).Left -= 2;
                    }
                }
            }
            else if (e.KeyCode == Keys.Right)
            {
                foreach (Component comp in ServiceSelection.GetSelectedComponents())
                {
                    if (comp is Control && comp != DesignerHost.RootComponent)
                    {
                        ((Control)comp).Left += 2;
                    }
                }
            }
            else if (e.KeyCode == Keys.Up)
            {
                foreach (Component comp in ServiceSelection.GetSelectedComponents())
                {
                    if (comp is Control && comp != DesignerHost.RootComponent)
                    {
                        ((Control)comp).Top -= 2;
                    }
                }
            }
            else if (e.KeyCode == Keys.Down)
            {
                foreach (Component comp in ServiceSelection.GetSelectedComponents())
                {
                    if (comp is Control && comp != DesignerHost.RootComponent)
                    {
                        ((Control)comp).Top += 2;
                    }
                }
            }
            #endregion
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            ISelectionService service = base.GetService(typeof(ISelectionService)) as ISelectionService;

            if (((service != null) ? service.PrimarySelection : null) != null)
            {
                List <Activity> list = new List <Activity>(Helpers.GetTopLevelActivities(service.GetSelectedComponents()));
                if (((e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Right)) || ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down)))
                {
                    Size empty = Size.Empty;
                    if (e.KeyCode == Keys.Left)
                    {
                        empty = new Size(-5, 0);
                    }
                    else if (e.KeyCode == Keys.Right)
                    {
                        empty = new Size(5, 0);
                    }
                    else if (e.KeyCode == Keys.Up)
                    {
                        empty = new Size(0, -5);
                    }
                    else if (e.KeyCode == Keys.Down)
                    {
                        empty = new Size(0, 5);
                    }
                    foreach (Activity activity in list)
                    {
                        ActivityDesigner designer = ActivityDesigner.GetDesigner(activity);
                        if (designer != null)
                        {
                            base.ParentView.InvalidateClientRectangle(new Rectangle(designer.Location, designer.Size));
                            designer.Location += empty;
                            base.ParentView.InvalidateClientRectangle(new Rectangle(designer.Location, designer.Size));
                        }
                    }
                    base.PerformLayout();
                    e.Handled = true;
                }
                else if (e.KeyCode == Keys.Delete)
                {
                    foreach (object obj3 in service.GetSelectedComponents())
                    {
                        ConnectorHitTestInfo info = obj3 as ConnectorHitTestInfo;
                        if (info != null)
                        {
                            FreeformActivityDesigner associatedDesigner = info.AssociatedDesigner as FreeformActivityDesigner;
                            if (associatedDesigner != null)
                            {
                                ReadOnlyCollection <Connector> connectors = associatedDesigner.Connectors;
                                int num = info.MapToIndex();
                                if (num < connectors.Count)
                                {
                                    service.SetSelectedComponents(new object[] { info }, SelectionTypes.Remove);
                                    associatedDesigner.RemoveConnector(connectors[num]);
                                    object obj4 = associatedDesigner;
                                    if (connectors.Count > 0)
                                    {
                                        obj4 = new ConnectorHitTestInfo(associatedDesigner, HitTestLocations.Connector | HitTestLocations.Designer, (num > 0) ? (num - 1) : num);
                                    }
                                    service.SetSelectedComponents(new object[] { obj4 }, SelectionTypes.Replace);
                                }
                            }
                        }
                    }
                    e.Handled = true;
                }
                if (!e.Handled)
                {
                    base.OnKeyDown(e);
                }
            }
        }
示例#28
0
        protected override bool OnKeyDown(KeyEventArgs eventArgs)
        {
            if (eventArgs != null && (eventArgs.KeyCode == Keys.PageUp || eventArgs.KeyCode == Keys.PageDown))
            {
                UpdateViewOnPageUpDown(eventArgs.KeyCode == Keys.PageUp);
            }
            ISelectionService selectionService = ((IServiceProvider)this.ParentView).GetService(typeof(ISelectionService)) as ISelectionService;

            //enter key (
            if (eventArgs.KeyCode == Keys.Enter)
            {
                // on enter key we want to do DoDefault of the designer
                IDesigner designer = ActivityDesigner.GetDesigner(selectionService.PrimarySelection as Activity) as IDesigner;
                if (designer != null)
                {
                    designer.DoDefaultAction();
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Escape)
            {
                if (!eventArgs.Handled)
                {
                    CompositeActivityDesigner parentDesigner = ActivityDesigner.GetParentDesigner(selectionService.PrimarySelection);
                    if (parentDesigner != null)
                    {
                        selectionService.SetSelectedComponents(new object[] { parentDesigner.Activity }, SelectionTypes.Replace);
                    }

                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Delete)
            {
                // check if we are cutting root component
                IDesignerHost designerHost = ((IServiceProvider)this.ParentView).GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (!(designerHost == null || selectionService.GetComponentSelected(designerHost.RootComponent)))
                {
                    //Check that we are cutting all activities
                    //Check if we are in writable context
                    ICollection components = selectionService.GetSelectedComponents();
                    if (DesignerHelpers.AreComponentsRemovable(components))
                    {
                        // check if we can delete these
                        List <Activity> topLevelActivities     = new List <Activity>(Helpers.GetTopLevelActivities(selectionService.GetSelectedComponents()));
                        bool            needToDelete           = (topLevelActivities.Count > 0);
                        IDictionary     commonParentActivities = Helpers.PairUpCommonParentActivities(topLevelActivities);
                        foreach (DictionaryEntry entry in commonParentActivities)
                        {
                            CompositeActivityDesigner compositeActivityDesigner = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                            if (compositeActivityDesigner != null && !compositeActivityDesigner.CanRemoveActivities(new List <Activity>((Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity))).AsReadOnly()))
                            {
                                needToDelete = false;
                            }
                        }

                        if (needToDelete)
                        {
                            List <ConnectorHitTestInfo> connectors = new List <ConnectorHitTestInfo>();
                            foreach (object component in components)
                            {
                                ConnectorHitTestInfo connector = component as ConnectorHitTestInfo;
                                if (connector != null)
                                {
                                    connectors.Add(connector);
                                }
                            }

                            //cache selcted connectors before calling this func
                            CompositeActivityDesigner.RemoveActivities((IServiceProvider)this.ParentView, topLevelActivities.AsReadOnly(), SR.GetString(SR.DeletingActivities));

                            //add connectors back to the selection service
                            if (selectionService != null && connectors.Count > 0)
                            {
                                selectionService.SetSelectedComponents(connectors, SelectionTypes.Add);
                            }

                            eventArgs.Handled = true;
                        }
                    }
                }
            }
            //navigation (left, right, up, down, tab, shift-tab)
            else if (eventArgs.KeyCode == Keys.Left || eventArgs.KeyCode == Keys.Right || eventArgs.KeyCode == Keys.Up || eventArgs.KeyCode == Keys.Down || eventArgs.KeyCode == Keys.Tab)
            {
                //we'll pass it to the parent designer of the primary selected designer
                //sequential designers just navigate between their children
                //free form designers may move their children on arrow keys and navigate on tab
                ActivityDesigner designer = ActivityDesigner.GetDesigner(selectionService.PrimarySelection as Activity) as ActivityDesigner;
                if (designer != null && designer.ParentDesigner != null)
                {
                    //we will let the parent see if it wants to handle the event,
                    //otherwise the selected designer itself will be called from a designer message filter below
                    ((IWorkflowDesignerMessageSink)designer.ParentDesigner).OnKeyDown(eventArgs);
                    eventArgs.Handled = true;
                }
            }

            if (!eventArgs.Handled)
            {
                ActivityDesigner designerWithFocus = GetDesignerWithFocus();
                if (designerWithFocus != null)
                {
                    ((IWorkflowDesignerMessageSink)designerWithFocus).OnKeyDown(eventArgs);
                }
            }

            return(eventArgs.Handled);
        }
示例#29
0
        protected override bool OnKeyDown(KeyEventArgs eventArgs)
        {
            if ((eventArgs != null) && ((eventArgs.KeyCode == Keys.PageUp) || (eventArgs.KeyCode == Keys.Next)))
            {
                this.UpdateViewOnPageUpDown(eventArgs.KeyCode == Keys.PageUp);
            }
            ISelectionService service = ((IServiceProvider)base.ParentView).GetService(typeof(ISelectionService)) as ISelectionService;

            if (eventArgs.KeyCode == Keys.Enter)
            {
                IDesigner designer = ActivityDesigner.GetDesigner(service.PrimarySelection as Activity);
                if (designer != null)
                {
                    designer.DoDefaultAction();
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Escape)
            {
                if (!eventArgs.Handled)
                {
                    CompositeActivityDesigner parentDesigner = ActivityDesigner.GetParentDesigner(service.PrimarySelection);
                    if (parentDesigner != null)
                    {
                        service.SetSelectedComponents(new object[] { parentDesigner.Activity }, SelectionTypes.Replace);
                    }
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Delete)
            {
                IDesignerHost host = ((IServiceProvider)base.ParentView).GetService(typeof(IDesignerHost)) as IDesignerHost;
                if ((host != null) && !service.GetComponentSelected(host.RootComponent))
                {
                    ICollection selectedComponents = service.GetSelectedComponents();
                    if (DesignerHelpers.AreComponentsRemovable(selectedComponents))
                    {
                        List <Activity> activities = new List <Activity>(Helpers.GetTopLevelActivities(service.GetSelectedComponents()));
                        bool            flag       = activities.Count > 0;
                        foreach (DictionaryEntry entry in Helpers.PairUpCommonParentActivities(activities))
                        {
                            CompositeActivityDesigner designer3 = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                            if ((designer3 != null) && !designer3.CanRemoveActivities(new List <Activity>((Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity))).AsReadOnly()))
                            {
                                flag = false;
                            }
                        }
                        if (flag)
                        {
                            List <ConnectorHitTestInfo> components = new List <ConnectorHitTestInfo>();
                            foreach (object obj2 in selectedComponents)
                            {
                                ConnectorHitTestInfo item = obj2 as ConnectorHitTestInfo;
                                if (item != null)
                                {
                                    components.Add(item);
                                }
                            }
                            CompositeActivityDesigner.RemoveActivities(base.ParentView, activities.AsReadOnly(), SR.GetString("DeletingActivities"));
                            if ((service != null) && (components.Count > 0))
                            {
                                service.SetSelectedComponents(components, SelectionTypes.Add);
                            }
                            eventArgs.Handled = true;
                        }
                    }
                }
            }
            else if (((eventArgs.KeyCode == Keys.Left) || (eventArgs.KeyCode == Keys.Right)) || (((eventArgs.KeyCode == Keys.Up) || (eventArgs.KeyCode == Keys.Down)) || (eventArgs.KeyCode == Keys.Tab)))
            {
                ActivityDesigner designer4 = ActivityDesigner.GetDesigner(service.PrimarySelection as Activity);
                if ((designer4 != null) && (designer4.ParentDesigner != null))
                {
                    ((IWorkflowDesignerMessageSink)designer4.ParentDesigner).OnKeyDown(eventArgs);
                    eventArgs.Handled = true;
                }
            }
            if (!eventArgs.Handled)
            {
                ActivityDesigner designerWithFocus = this.GetDesignerWithFocus();
                if (designerWithFocus != null)
                {
                    ((IWorkflowDesignerMessageSink)designerWithFocus).OnKeyDown(eventArgs);
                }
            }
            return(eventArgs.Handled);
        }
        //- Gets a new DesignSurfaceExt2
        //- and loads it with the appropriate type of root component.
        public DesignSurfaceExt2 CreateDesignSurfaceExt2()
        {
            //- with a DesignSurfaceManager class, is useless to add new services
            //- to every design surface we are about to create,
            //- because of the "IServiceProvider" parameter of CreateDesignSurface(IServiceProvider) Method.
            //- This param let every design surface created
            //- to use the services of the DesignSurfaceManager.
            //- A new merged service provider will be created that will first ask
            //- this provider for a service, and then delegate any failures
            //- to the design surface manager object.
            //- Note:
            //-     the following line of code create a brand new DesignSurface which is added
            //-     to the Designsurfeces collection,
            //-     i.e. the property "this.DesignSurfaces" ( the .Count in incremented by one)
            DesignSurfaceExt2 surface = (DesignSurfaceExt2)(this.CreateDesignSurface(this.ServiceContainer));


            //- each time a brand new DesignSurface is created,
            //- subscribe our handler to its SelectionService.SelectionChanged event
            //- to sync the PropertyGridHost
            ISelectionService selectionService = (ISelectionService)(surface.GetService(typeof(ISelectionService)));

            if (null != selectionService)
            {
                selectionService.SelectionChanged += (object sender, EventArgs e) =>
                {
                    ISelectionService selectService = sender as ISelectionService;
                    if (null == selectService)
                    {
                        return;
                    }

                    if (0 == selectService.SelectionCount)
                    {
                        return;
                    }

                    //- Sync the PropertyGridHost
                    PropertyGrid propertyGrid = (PropertyGrid)this.GetService(typeof(PropertyGrid));
                    if (null == propertyGrid)
                    {
                        return;
                    }

                    ArrayList comps = new ArrayList();
                    var       x     = selectService.GetSelectedComponents();
                    foreach (Control c in x)
                    {
                        if (c is IEbControlContainer)
                        {
                            comps.Add((c as IEbControlContainer).EbControlContainer);
                        }
                        else if (c is IEbControl)
                        {
                            comps.Add((c as IEbControl).EbControl);
                        }
                    }
                    //comps.AddRange( selectService.GetSelectedComponents() );
                    propertyGrid.SelectedObjects = comps.ToArray();
                };
            }
            DesignSurfaceExt2Collection.Add(surface);
            this.ActiveDesignSurface = surface;

            //- and return the DesignSurface (to let the its BeginLoad() method to be called)
            return(surface);
        }
示例#31
0
        /// <summary>
        /// In response to a MouseDown, the SelectionBehavior will push (initiate) a dragBehavior by alerting the SelectionMananger that a new control has been selected and the mouse is down. Note that this is only if we find the related control's Dock property == none.
        /// </summary>
        public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
        {
            //we only care about the right mouse button for resizing
            if (button != MouseButtons.Left)
            {
                //pass any other mouse click along - unless we've already started our resize in which case we'll ignore it
                return(_pushedBehavior);
            }
            //start with no selection rules and try to obtain this info from the glyph
            _targetResizeRules = SelectionRules.None;
            if (g is SelectionGlyphBase sgb)
            {
                _targetResizeRules = sgb.SelectionRules;
                _cursor            = sgb.HitTestCursor;
            }

            if (_targetResizeRules == SelectionRules.None)
            {
                return(false);
            }

            ISelectionService selSvc = (ISelectionService)_serviceProvider.GetService(typeof(ISelectionService));

            if (selSvc == null)
            {
                return(false);
            }

            _initialPoint = mouseLoc;
            _lastMouseLoc = mouseLoc;
            //build up a list of our selected controls
            _primaryControl = selSvc.PrimarySelection as Control;

            // Since we don't know exactly how many valid objects we are going to have we use this temp
            ArrayList components = new ArrayList();

            foreach (object o in selSvc.GetSelectedComponents())
            {
                if (o is Control)
                {
                    //don't drag locked controls
                    PropertyDescriptor prop = TypeDescriptor.GetProperties(o)["Locked"];
                    if (prop != null)
                    {
                        if ((bool)prop.GetValue(o))
                        {
                            continue;
                        }
                    }
                    components.Add(o);
                }
            }

            if (components.Count == 0)
            {
                return(false);
            }

            _resizeComponents = new ResizeComponent[components.Count];
            for (int i = 0; i < components.Count; i++)
            {
                _resizeComponents[i].resizeControl = components[i];
            }

            //push this resizebehavior
            _pushedBehavior = true;
            BehaviorService.PushCaptureBehavior(this);
            return(false);
        }
示例#32
0
        // This method is called when a user double-clicks (the representation of) a component.
        // Tries to bind the default event to a method or creates a new one.
        //
        public virtual void DoDefaultAction()
        {
            IDesignerHost       host        = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            DesignerTransaction transaction = null;

            if (host != null)
            {
                transaction = host.CreateTransaction("ComponentDesigner_AddEvent");
            }

            IEventBindingService eventBindingService    = GetService(typeof(IEventBindingService)) as IEventBindingService;
            EventDescriptor      defaultEventDescriptor = null;

            if (eventBindingService != null)
            {
                ISelectionService selectionService = this.GetService(typeof(ISelectionService)) as ISelectionService;
                try {
                    if (selectionService != null)
                    {
                        ICollection selectedComponents = selectionService.GetSelectedComponents();

                        foreach (IComponent component in selectedComponents)
                        {
                            EventDescriptor eventDescriptor = TypeDescriptor.GetDefaultEvent(component);
                            if (eventDescriptor != null)
                            {
                                PropertyDescriptor eventProperty = eventBindingService.GetEventProperty(eventDescriptor);
                                if (eventProperty != null && !eventProperty.IsReadOnly)
                                {
                                    string methodName = eventProperty.GetValue(component) as string;
                                    bool   newMethod  = true;

                                    if (methodName != null || methodName != String.Empty)
                                    {
                                        ICollection compatibleMethods = eventBindingService.GetCompatibleMethods(eventDescriptor);
                                        foreach (string signature in compatibleMethods)
                                        {
                                            if (signature == methodName)
                                            {
                                                newMethod = false;
                                                break;
                                            }
                                        }
                                    }
                                    if (newMethod)
                                    {
                                        if (methodName == null)
                                        {
                                            methodName = eventBindingService.CreateUniqueMethodName(component, eventDescriptor);
                                        }

                                        eventProperty.SetValue(component, methodName);
                                    }

                                    if (component == _component)
                                    {
                                        defaultEventDescriptor = eventDescriptor;
                                    }
                                }
                            }
                        }
                    }
                }
                catch {
                    if (transaction != null)
                    {
                        transaction.Cancel();
                        transaction = null;
                    }
                }
                finally {
                    if (transaction != null)
                    {
                        transaction.Commit();
                    }
                }

                if (defaultEventDescriptor != null)
                {
                    eventBindingService.ShowCode(_component, defaultEventDescriptor);
                }
            }
        }
		void UpdatePropertyPadSelection(ISelectionService selectionService)
		{
			ICollection selection = selectionService.GetSelectedComponents();
			object[] selArray = new object[selection.Count];
			selection.CopyTo(selArray, 0);
			propertyContainer.SelectedObjects = selArray;
			//System.Windows.Input.CommandManager.InvalidateRequerySuggested();
		}