/// <summary> /// Raises the <see cref="E:System.Windows.Forms.DataGridView.RowEnter"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DataGridViewCellEventArgs"></see> that contains the event data.</param> protected override void OnRowEnter(DataGridViewCellEventArgs e) { base.OnRowEnter(e); if (_root.Store == null) { return; } IMonitorSelectionService monitorSelectionService = (IMonitorSelectionService)((ModelElement)_root).Store.GetService(typeof(IMonitorSelectionService)); if (monitorSelectionService != null && e.RowIndex > 0) { ISelectionService selectionService = monitorSelectionService.CurrentSelectionContainer as ISelectionService; VirtualTreeGridItem value = GetRowValue(e.RowIndex); if (value != null && value.DataItem != null) { if (selectionService != null) { selectionService.SetSelectedComponents(new object[] { value.DataItem }); } } } }
private void DocumentWindowChanged(Object sender, MonitorSelectionEventArgs e) { IMonitorSelectionService monitor = (IMonitorSelectionService)sender; IORMDesignerView testView = monitor.CurrentSelectionContainer as IORMDesignerView; this.CurrentDesignerView = (testView != null && testView.CurrentDesigner != null) ? testView : monitor.CurrentDocumentView as IORMDesignerView; }
/// <summary> /// Execute the command /// </summary> public void Exec() { using (Transaction transaction = _clazz.Store.TransactionManager.BeginTransaction("Property to Association")) { Entity targetModel = FindModelClassByName(_property); if (targetModel == null) { return; } // Suppression en tant que propriété _clazz.Properties.Remove(_property); // Propriétés de l'association Association assoc = _clazz.AddAssociationTo(targetModel); assoc.SourceRoleName = _property.Name; assoc.SourceMultiplicity = Multiplicity.ZeroOne; assoc.XmlName = _property.XmlName; // TIPS sélection d'un composant // On enlève la sélection sur la propriété car on vient de la supprimer IMonitorSelectionService monitorSelectionService = (IMonitorSelectionService)_serviceProvider.GetService(typeof(IMonitorSelectionService)); if (monitorSelectionService != null) { ISelectionService selectionService = monitorSelectionService.CurrentSelectionContainer as ISelectionService; if (selectionService != null) { selectionService.SetSelectedComponents(null); } } transaction.Commit(); } }
/// <summary> /// Initializes a new instance of the <see cref="T:Microsoft.VisualStudio.Modeling.Shell.ToolWindow"></see> class. /// </summary> protected override void Initialize() { base.Initialize(); monitorSelection = GetService(typeof(IMonitorSelectionService)) as IMonitorSelectionService; if (monitorSelection != null) { monitorSelection.SelectionChanged += MonitorSelection_SelectionChanged; } }
public void Dispose() { if (myCommands != null) { RemoveCommands(myCommands); } myMenuService = null; myMonitorSelection = null; myServiceProvider = null; myCommands = null; }
/// <summary> /// Handles the DocumentWindowChanged event on the IMonitorSelectionService /// </summary> private void DocumentWindowChanged(object sender, MonitorSelectionEventArgs e) { IMonitorSelectionService monitor = (IMonitorSelectionService)sender; DocDataType docData = monitor.CurrentDocument as DocDataType; DocViewType docView = monitor.CurrentDocumentView as DocViewType; if (!CurrentDocumentChanging(docData, docView)) { SetCurrentDocument(docData, docView); } }
private static object SafeGetCurrentDocument(IMonitorSelectionService monitor) { object retVal = null; try { retVal = monitor.CurrentDocument; } catch (System.Runtime.InteropServices.COMException) { // Swallow, this will occasionally be initialized when the document is shutting down } return(retVal); }
private static ModelChangeMonitor CreateModelChangeMonitor() { IMonitorSelectionService monitorSelectionService = RuntimeHelper.ServiceProvider.GetService(typeof(IMonitorSelectionService)) as IMonitorSelectionService; if (monitorSelectionService != null) // may be null on tests { DocData docData = monitorSelectionService.CurrentDocument as DocData; if (docData != null) { return(new ModelChangeMonitor(docData)); } } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="T:NewFactScanner"/> class. /// </summary> public FactEditorLineScanner(LanguageService service, IVsTextLines textLines) { m_LanguageService = service; m_TextLines = textLines; IMonitorSelectionService monitor = m_LanguageService.GetService(typeof(IMonitorSelectionService)) as IMonitorSelectionService; EventHandler <MonitorSelectionEventArgs> windowChange = new EventHandler <MonitorSelectionEventArgs>(DocumentWindowChanged); monitor.DocumentWindowChanged += windowChange; monitor.WindowChanged += windowChange; IORMDesignerView testView = monitor.CurrentSelectionContainer as IORMDesignerView; m_View = (testView != null && testView.CurrentDesigner != null) ? testView : monitor.CurrentDocumentView as IORMDesignerView; }
/// <summary> /// Execute the command /// </summary> public void Exec() { using (Transaction transaction = _association.Store.TransactionManager.BeginTransaction("Property to Association")) { Entity sourceModel = _association.Source; // Création de la propriété Property property = new Property(sourceModel.Store); property.Name = _association.SourceRoleName; if (_association.SourceMultiplicity == Multiplicity.OneMany || _association.SourceMultiplicity == Multiplicity.ZeroMany) { property.Type = "List<" + _association.Target.Type + ">"; } else { property.Type = _association.Target.Name; } property.XmlName = _association.XmlName; sourceModel.Properties.Add(property); if (!String.IsNullOrEmpty(_association.TargetRoleName)) { Entity targetModel = _association.Target; // Création de la propriété property = new Property(targetModel.Store); property.Name = _association.TargetRoleName; property.Type = _association.Target.Name; property.XmlName = _association.Target.Name; targetModel.Properties.Add(property); } // Suppression de l'association _association.Delete(); // TIPS sélection d'un composant // On enlève la sélection sur l'association car on vient de la supprimer IMonitorSelectionService monitorSelectionService = (IMonitorSelectionService)_serviceProvider.GetService(typeof(IMonitorSelectionService)); if (monitorSelectionService != null) { ISelectionService selectionService = monitorSelectionService.CurrentSelectionContainer as ISelectionService; if (selectionService != null) { selectionService.SetSelectedComponents(null); } } transaction.Commit(); } }
/// <summary> /// Handles the SelectionChanged event on the IMonitorSelectionService /// </summary> private void MonitorSelectionChanged(object sender, MonitorSelectionEventArgs e) { IMonitorSelectionService monitor = (IMonitorSelectionService)sender; SelectionContainerType newContainer = monitor.CurrentSelectionContainer as SelectionContainerType; if (newContainer == null) { IProvideFrameVisibility visibility = myCurrentSelectionContainer as IProvideFrameVisibility; if (visibility == null || visibility.CurrentFrameVisibility == FrameVisibility.Hidden) { newContainer = monitor.CurrentDocumentView as SelectionContainerType; } } CurrentSelectionContainer = newContainer; }
/// <summary> /// Clear the contents of the tool window associated with this <see cref="T:ToolWindowActivationHelper"/> /// </summary> protected virtual void ClearContents() { FrameVisibilityFlags flags = myFrameVisibility; switch (flags & FrameVisibilityFlags.FrameVisibilityMask) { case FrameVisibilityFlags.Covered: case FrameVisibilityFlags.Visible: IMonitorSelectionService monitor = myMonitorSelectionService; monitor.SelectionChanged -= new EventHandler <MonitorSelectionEventArgs>(MonitorSelectionChanged); monitor.DocumentWindowChanged -= new EventHandler <MonitorSelectionEventArgs>(DocumentWindowChanged); myFrameVisibility = FrameVisibilityFlags.Hidden | (flags & FrameVisibilityFlags.PersistentFlagsMask); SetCurrentDocument(null, null); break; } }
/// <summary> /// Releases the unmanaged resources used by the <see cref="T:Microsoft.VisualStudio.Modeling.Shell.ToolWindow"></see> and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (monitorSelection != null) { monitorSelection.SelectionChanged -= MonitorSelection_SelectionChanged; if (monitorSelection is IDisposable) { IDisposable disposable = monitorSelection as IDisposable; if (disposable != null) { disposable.Dispose(); } } monitorSelection = null; } base.Dispose(disposing); }
/// <summary> /// Create a new <see cref="T:ToolWindowActivationHelper"/> /// </summary> /// <param name="unfilteredServiceProvider">An <see cref="IServiceProvider"/> that is not filtered by /// the containing toolwindow implementation.</param> /// <param name="frame">The <see cref="IVsWindowFrame"/> to provide notifications for</param> /// <param name="coveredFrameActions">The default <see cref="CoveredFrameContentActions"/></param> /// <param name="notifyCallback">Thee <see cref="T:INotifyToolWindowActivation"/> callback used to communicate /// with the consuming class</param> public ToolWindowActivationHelper(IServiceProvider unfilteredServiceProvider, IVsWindowFrame frame, CoveredFrameContentActions coveredFrameActions, INotifyToolWindowActivation <DocDataType, DocViewType, SelectionContainerType> notifyCallback) { if (unfilteredServiceProvider == null) { throw new ArgumentNullException("unfilteredServiceProvider"); } if (frame == null) { throw new ArgumentNullException("frame"); } if (notifyCallback == null) { throw new ArgumentNullException("notifyCallback"); } myLastFrameMode = (VSFRAMEMODE)(-1); myMonitorSelectionService = (IMonitorSelectionService)unfilteredServiceProvider.GetService(typeof(IMonitorSelectionService)); myFrame = frame; myCoveredFrameActions = coveredFrameActions; myNotifyCallback = notifyCallback; frame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, this); }
private void ShowContents() { FrameVisibilityFlags flags = myFrameVisibility; switch (flags & FrameVisibilityFlags.FrameVisibilityMask) { case FrameVisibilityFlags.Covered: myFrameVisibility = FrameVisibilityFlags.Visible | (flags & FrameVisibilityFlags.PersistentFlagsMask) | FrameVisibilityFlags.HasBeenVisible; break; case FrameVisibilityFlags.Hidden: IMonitorSelectionService monitor = myMonitorSelectionService; monitor.SelectionChanged += new EventHandler <MonitorSelectionEventArgs>(MonitorSelectionChanged); monitor.DocumentWindowChanged += new EventHandler <MonitorSelectionEventArgs>(DocumentWindowChanged); myNotifyCallback.ActivatorVisibleWindowSessionBeginning(this); SetCurrentDocument(SafeGetCurrentDocument(monitor) as DocDataType, monitor.CurrentDocumentView as DocViewType); myFrameVisibility = FrameVisibilityFlags.Visible | (flags & FrameVisibilityFlags.PersistentFlagsMask) | FrameVisibilityFlags.HasBeenVisible; CurrentSelectionContainer = monitor.CurrentSelectionContainer as SelectionContainerType ?? monitor.CurrentDocumentView as SelectionContainerType; break; } }
/// <summary> /// Returns the model element currently selected in the diagram, or /// null if a model element could not be determined. /// </summary> /// <returns></returns> public ModelElement GetDiagramSelectedModelElement() { ModelingDocView view = null; _monitorSelection = (IMonitorSelectionService)_store.GetService(typeof(IMonitorSelectionService)); // We are only interested if the selection container is a ModelingDocView // (if it isn't, then the selected item isn't on a diagram). if (_monitorSelection != null) view = _monitorSelection.CurrentSelectionContainer as ModelingDocView; if (view == null) { return null; } // The primary selection could be a PresentationElement (e.g. if a geometry shape is selected) // or a ModelElement (e.g. if an item in a compartment is selected). // If a presentation element is selected, then get the selected model element ModelElement selectedElement; var newSelectedShape = view.PrimarySelection as ShapeElement; if (newSelectedShape != null) { selectedElement = newSelectedShape; } else { selectedElement = view.PrimarySelection as ModelElement; } return selectedElement; }