public void Drop(IEnumerable<IDragSource> nodes, DropPosition mode, DragDropEffect effect, DragDropKeyStates initialKeyStates) { foreach (var node in nodes) { this.Drop(node, mode, effect == DragDropEffect.Copy); } }
private static ModifierKeys GetModifiers(InputEventArgs inputEventArgs) { DragEventArgs dragEventArgs = (DragEventArgs)null; ToolActionEventArgs toolActionEventArgs = inputEventArgs as ToolActionEventArgs; if (toolActionEventArgs != null) { dragEventArgs = toolActionEventArgs.SourceEvent as DragEventArgs; } ModifierKeys modifierKeys = ModifierKeys.None; if (dragEventArgs != null) { DragDropKeyStates keyStates = dragEventArgs.KeyStates; if ((keyStates & DragDropKeyStates.AltKey) != DragDropKeyStates.None) { modifierKeys |= ModifierKeys.Alt; } if ((keyStates & DragDropKeyStates.ControlKey) != DragDropKeyStates.None) { modifierKeys |= ModifierKeys.Control; } if ((keyStates & DragDropKeyStates.ShiftKey) != DragDropKeyStates.None) { modifierKeys |= ModifierKeys.Shift; } } else { modifierKeys = KeyboardHelper.Modifiers; } return(modifierKeys); }
/// <summary> /// Initializes a new instance of the <see cref="DragLeaveArgs" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="keyStates">The key states.</param> /// <param name="dropTarget">The drop target.</param> /// <param name="allowedEffects">The allowed effects.</param> public DragLeaveArgs( IDataObject data, DragDropKeyStates keyStates, Object dropTarget, DragDropEffects allowedEffects ) : base( data, keyStates, dropTarget ) { Ensure.That( allowedEffects ).Named( "allowedEffects" ).IsTrue( v => v.IsDefined() ); this.AllowedEffects = allowedEffects; }
private static string TextFromProjectItems(this IDataObject dataObject, string projectFolder, DragDropKeyStates keystates) { var sb = new StringBuilder(); bool first = true; foreach (var item in dataObject.GetProjectItems()) { var relative = item.FileName.MakeRRelativePath(projectFolder); var ext = Path.GetExtension(item.FileName).ToLowerInvariant(); switch (ext) { case ".r": if ((keystates & DragDropKeyStates.ControlKey) != 0) { sb.Append(GetFileContent(item.FileName)); } else { var str = first ? Environment.NewLine : string.Empty; sb.AppendLine(Invariant($"{str}source('{relative}')")); first = false; } break; case ".sql": if ((keystates & DragDropKeyStates.ControlKey) != 0) { sb.Append(Invariant($"'{GetFileContent(item.FileName)}'")); } else { sb.Append(Invariant($@"iconv(paste(readLines('{relative}', encoding = 'UTF-8', warn = FALSE), collapse='\n'), from = 'UTF-8', to = 'ASCII', sub = '')")); } break; default: sb.Append(Invariant($"'{relative}'")); break; } } return sb.ToString(); }
public static string GetPlainText(this IDataObject dataObject, string projectFolder, DragDropKeyStates keystates) { var flags = dataObject.GetFlags(); if ((flags & DataObjectFlags.ProjectItems) != 0) { return dataObject.TextFromProjectItems(projectFolder, keystates); } return string.Empty; }
/// <summary> /// Initializes a new instance of the <see cref="DragOverArgs" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="keyStates">The key states.</param> /// <param name="dropTarget">The drop target.</param> /// <param name="allowedEffects">The allowed effects.</param> /// <param name="position">The position.</param> public DragOverArgs( IDataObject data, DragDropKeyStates keyStates, Object dropTarget, DragDropEffects allowedEffects, Point position ) : base( data, keyStates, dropTarget ) { Ensure.That( allowedEffects ).Named( "allowedEffects" ).IsTrue( v => v.IsDefined() ); this.AllowedEffects = allowedEffects; this.Position = position; }
/// <summary> /// Initializes a new instance of the <see cref="DragOverArgs" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="keyStates">The key states.</param> /// <param name="dropTarget">The drop target.</param> /// <param name="allowedEffects">The allowed effects.</param> /// <param name="position">The position.</param> public DragOverArgs(IDataObject data, DragDropKeyStates keyStates, Object dropTarget, DragDropEffects allowedEffects, Point position) : base(data, keyStates, dropTarget) { Ensure.That(allowedEffects).Named("allowedEffects").IsTrue(v => v.IsDefined()); this.AllowedEffects = allowedEffects; this.Position = position; }
public static DiagramLibraryNodeDragDropAction GetDropAction(DragDropKeyStates states) { if (states.HasFlag(DragDropKeyStates.ControlKey)) { return(DiagramLibraryNodeDragDropAction.Copy); } return(DiagramLibraryNodeDragDropAction.Move); }
/// <summary> /// Initializes a new instance of the <see cref="DragDropOperationArgs"/> class. /// </summary> /// <param name="data">The data.</param> /// <param name="keyStates">The key states.</param> /// <param name="dropTarget">The drop target.</param> protected DragDropOperationArgs(IDataObject data, DragDropKeyStates keyStates, Object dropTarget) { Ensure.That(data).Named("data").IsNotNull(); Ensure.That(keyStates).Named("keyStates").IsTrue(ks => ks.IsDefined()); this.Data = data; this.KeyStates = keyStates; this.DropTarget = dropTarget; }
/// <summary> /// Initializes a new instance of the <see cref="DragDropOperationArgs"/> class. /// </summary> /// <param name="data">The data.</param> /// <param name="keyStates">The key states.</param> /// <param name="dropTarget">The drop target.</param> protected DragDropOperationArgs( IDataObject data, DragDropKeyStates keyStates, Object dropTarget ) { Ensure.That( data ).Named( "data" ).IsNotNull(); Ensure.That( keyStates ).Named( "keyStates" ).IsTrue( ks => ks.IsDefined() ); this.Data = data; this.KeyStates = keyStates; this.DropTarget = dropTarget; }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors /// <summary> /// Initializes a new instance of the QueryContinueDragEventArgs class. /// </summary> /// <param name="escapePressed"> /// Escape key was pressed. /// </param> /// <param name="dragDropKeyStates"> /// Input states. /// </param> internal QueryContinueDragEventArgs(bool escapePressed, DragDropKeyStates dragDropKeyStates) { if (!DragDrop.IsValidDragDropKeyStates(dragDropKeyStates)) { Debug.Assert(false, "Invalid dragDropKeyStates"); } this._escapePressed = escapePressed; this._dragDropKeyStates = dragDropKeyStates; }
public TreeViewDragDropTarget() { _cSyncRoot = new object(); _bMouseDown = false; _eDragDropKeyStates = DragDropKeyStates.None; nDelay = 300; AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnMouseLeftButtonDown), true); AddHandler(MouseLeftButtonUpEvent, new MouseButtonEventHandler(OnMouseLeftButtonUp), true); AddHandler(KeyDownEvent, new KeyEventHandler(OnKeyDown), true); AddHandler(KeyUpEvent, new KeyEventHandler(OnKeyUp), true); }
void DispatchDragMergeHorizontal(Event eventSource, Event eventTarget, DragDropKeyStates keyStates) { if (keyStates == DragDropKeyStates.ControlKey || ((LinedEventsCanvas)(Parent)).MergeAllIntoBaseMode) { MergeAllHorizontally(eventTarget); } else { MergeHorizontally(eventSource, eventTarget, true); } }
private static bool ShouldCopyData(IDropInfo dropInfo, DragDropKeyStates dragDropCopyKeyState) { // default should always the move action/effect if (dropInfo == null) { return(false); } var copyData = ((dragDropCopyKeyState != default(DragDropKeyStates)) && dropInfo.KeyStates.HasFlag(dragDropCopyKeyState)) || dragDropCopyKeyState.HasFlag(DragDropKeyStates.LeftMouseButton); return(copyData); }
private void OnKeyUp(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Ctrl: _eDragDropKeyStates &= ~DragDropKeyStates.ControlKey; break; case Key.Shift: _eDragDropKeyStates &= ~DragDropKeyStates.ShiftKey; break; } }
public DragCopyPipeline WithParameters([NotNull] ItemTreeViewItem target, [NotNull] IEnumerable <IItem> items, ControlDragAdornerPosition position, DragDropKeyStates keyStates) { Assert.ArgumentNotNull(target, nameof(target)); Assert.ArgumentNotNull(items, nameof(items)); KeyStates = keyStates; Target = target; Items = items; Position = position; Start(); return(this); }
/// <summary> /// Handles the PreviewDragEnter event on the drop target. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event args.</param> private void DropTargetPreviewDragEnter(object sender, DragEventArgs e) { this.initialKeyStates = e.KeyStates; this.targetItemsControl = (TreeListBox)sender; object draggedItems = e.Data.GetData(this.format.Name); if (draggedItems != null) { this.DecideDropTarget(e); this.UpdateAdorner(); e.Handled = true; } }
/// <summary> /// Returns the drop effects allowed /// </summary> /// <param name="allowedEffects"></param> /// <param name="keyStates"></param> /// <returns></returns> static DragDropEffects GetDropEffectType(DragDropEffects allowedEffects, DragDropKeyStates keyStates) { // None? if (allowedEffects == DragDropEffects.None) { return(allowedEffects); } return((allowedEffects & (DragDropEffects.Move | DragDropEffects.Copy)) == (DragDropEffects.Move | DragDropEffects.Copy) ? (((keyStates & DragDropKeyStates.ControlKey) != 0) ? DragDropEffects.Copy : DragDropEffects.Move) : ((allowedEffects & DragDropEffects.Copy) != 0 ? DragDropEffects.Copy : DragDropEffects.Move)); }
static DragDropAction DetectDragAction(DragDropKeyStates keys) { if ((keys & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey) { if ((keys & DragDropKeyStates.ShiftKey) == DragDropKeyStates.ShiftKey) { return(DragDropAction.Link); } else { return(DragDropAction.Copy); } } return(DragDropAction.Move); }
public FileListDataGrid() { this.DragMouseButton = DragDropKeyStates.None; this.DragEnter += (o, e) => { this.DragMouseButton = e.KeyStates; }; this.DragOver += (o, e) => { this.DragMouseButton = e.KeyStates; }; this.DragLeave += (o, e) => { this.DragMouseButton = DragDropKeyStates.None; }; }
private DragDropEffects GetDropEffect(DragDropEffects allowedEffects, DragDropKeyStates keyStates, IDataObject data) { DragDropEffects AcceptedEffects = this.targetHandler.GetDropEffects(data); DragDropKeyStates KeyboardStates = keyStates & (DragDropKeyStates.AltKey | DragDropKeyStates.ShiftKey | DragDropKeyStates.ControlKey); DragDropKeyStates MouseStates = keyStates & (DragDropKeyStates.LeftMouseButton | DragDropKeyStates.RightMouseButton | DragDropKeyStates.MiddleMouseButton); if (AcceptedEffects == DragDropEffects.Scroll) { return(DragDropEffects.Scroll); } if (KeyboardStates == DragDropKeyStates.None) { DragDropEffect DefaultEffect = this.targetHandler.GetDefaultEffect(data); if ((allowedEffects & (DragDropEffects)DefaultEffect) != 0) { return((DragDropEffects)DefaultEffect); } } else if ((KeyboardStates & DragDropKeyStates.ControlKey) != 0) { if ((allowedEffects & DragDropEffects.Copy) != 0 && (AcceptedEffects & DragDropEffects.Copy) != 0) { return(DragDropEffects.Copy); } } else if ((KeyboardStates & DragDropKeyStates.ShiftKey) != 0) { if ((allowedEffects & DragDropEffects.Move) != 0 && (AcceptedEffects & DragDropEffects.Move) != 0) { return(DragDropEffects.Move); } } else if ((KeyboardStates & DragDropKeyStates.AltKey) != 0) { if ((allowedEffects & DragDropEffects.Link) != 0 && (AcceptedEffects & DragDropEffects.Link) != 0) { return(DragDropEffects.Link); } } return(DragDropEffects.None); }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors /// <summary> /// Constructs a DragEventArgs instance. /// </summary> /// <param name="data"> /// The data object used in this drag drop operation. /// </param> /// <param name="dragDropKeyStates"> /// The current state of the mouse button and modifier keys. /// </param> /// <param name="allowedEffects"> /// Allowed effects of a drag-and-drop operation. /// </param> /// <param name="target"> /// The target of the event. /// </param> /// <param name="point"> /// The current mouse position of the target. /// </param> internal DragEventArgs(IDataObject data, DragDropKeyStates dragDropKeyStates, DragDropEffects allowedEffects, DependencyObject target, Point point) { if (!DragDrop.IsValidDragDropKeyStates(dragDropKeyStates)) { Debug.Assert(false, "Invalid dragDropKeyStates"); } if (!DragDrop.IsValidDragDropEffects(allowedEffects)) { Debug.Assert(false, "Invalid allowedEffects"); } if (target == null) { Debug.Assert(false, "Invalid target"); } this._data = data; this._dragDropKeyStates = dragDropKeyStates; this._allowedEffects = allowedEffects; this._target = target; this._dropPoint = point; this._effects = allowedEffects; }
/// <summary> /// Gets the <see cref="OperationKind"/> related to a <see cref="DragDropKeyStates"/> when a drag-and-drop operation is performed /// </summary> /// <param name="keyStates"> /// The <see cref="DragDropKeyStates"/></param> for /// <returns> /// The <see cref="OperationKind"/> or null /// </returns> public static OperationKind?GetCopyOperationKind(this DragDropKeyStates keyStates) { if (keyStates == Constants.DryCopy) { return(OperationKind.CopyDefaultValuesChangeOwner); } if (keyStates == Constants.CtrlCopy) { return(OperationKind.CopyKeepValuesChangeOwner); } if (keyStates == Constants.ShiftCopy) { return(OperationKind.Copy); } if (keyStates == Constants.CtlrShiftCopy) { return(OperationKind.CopyKeepValues); } return(null); }
public static DragEventArgs CreateDragEventArgs(IDataObject data, DragDropEffects allowedEffects = DragDropEffects.All, DragDropKeyStates dragDropKeyStates = DragDropKeyStates.None, DependencyObject target = null, Point point = default) { var argType = typeof(DragEventArgs); var argConstructor = argType.GetConstructor( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new[] { typeof(IDataObject), typeof(DragDropKeyStates), typeof(DragDropEffects), typeof(DependencyObject), typeof(Point), }, null ); return((DragEventArgs)argConstructor.Invoke(new object[] { data, dragDropKeyStates, allowedEffects, target, point })); }
private bool IsCopyKeyState(DragDropKeyStates keyStates) { return((keyStates & (DragDropKeyStates.ControlKey | DragDropKeyStates.AltKey)) != DragDropKeyStates.None); }
/// <summary> /// Initializes a new instance of the DragInfo class. /// </summary> /// <param name="sender">The sender of the input event that initiated the drag operation.</param> /// <param name="originalSource">The original source of the input event.</param> /// <param name="mouseButton">The mouse button which was used for the drag operation.</param> /// <param name="getPosition">A function of the input event which is used to get drag position points.</param> public DragInfo(object sender, object originalSource, MouseButton mouseButton, Func <IInputElement, Point> getPosition) { this.MouseButton = mouseButton; this.Effects = DragDropEffects.None; this.VisualSource = sender as UIElement; this.DragStartPosition = getPosition(this.VisualSource); this.DragDropCopyKeyState = DragDrop.GetDragDropCopyKeyState(this.VisualSource); var dataFormat = DragDrop.GetDataFormat(this.VisualSource); if (dataFormat != null) { this.DataFormat = dataFormat; } var sourceElement = originalSource as UIElement; // If we can't cast object as a UIElement it might be a FrameworkContentElement, if so try and use its parent. if (sourceElement == null && originalSource is FrameworkContentElement frameworkContentElement) { sourceElement = frameworkContentElement.Parent as UIElement; } if (sender is ItemsControl itemsControl) { this.SourceGroup = itemsControl.FindGroup(this.DragStartPosition); this.VisualSourceFlowDirection = itemsControl.GetItemsPanelFlowDirection(); UIElement item = null; if (sourceElement != null) { item = itemsControl.GetItemContainer(sourceElement); } if (item == null) { var itemPosition = this.DragStartPosition; if (DragDrop.GetDragDirectlySelectedOnly(this.VisualSource)) { item = itemsControl.GetItemContainerAt(itemPosition); } else { item = itemsControl.GetItemContainerAt(itemPosition, itemsControl.GetItemsPanelOrientation()); if (item.IsDragSourceIgnored()) { item = null; } } } if (item != null) { // Remember the relative position of the item being dragged this.PositionInDraggedItem = getPosition(item); var itemParent = ItemsControl.ItemsControlFromItemContainer(item); if (itemParent != null) { this.SourceCollection = itemParent.ItemsSource ?? itemParent.Items; if (itemParent != itemsControl) { if (item is TreeViewItem tvItem) { var tv = tvItem.GetVisualAncestor <TreeView>(); if (tv != null && tv != itemsControl && !tv.IsDragSource()) { return; } } else if (itemsControl.ItemContainerGenerator.IndexFromContainer(itemParent) < 0 && !itemParent.IsDragSource()) { return; } } this.SourceIndex = itemParent.ItemContainerGenerator.IndexFromContainer(item); this.SourceItem = itemParent.ItemContainerGenerator.ItemFromContainer(item); } else { this.SourceIndex = -1; } var selectedItems = itemsControl.GetSelectedItems().OfType <object>().Where(i => i != CollectionView.NewItemPlaceholder).ToList(); this.SourceItems = selectedItems; // Some controls (I'm looking at you TreeView!) haven't updated their // SelectedItem by this point. Check to see if there 1 or less item in // the SourceItems collection, and if so, override the control's SelectedItems with the clicked item. // // The control has still the old selected items at the mouse down event, so we should check this and give only the real selected item to the user. if (selectedItems.Count <= 1 || this.SourceItem != null && !selectedItems.Contains(this.SourceItem)) { this.SourceItems = Enumerable.Repeat(this.SourceItem, 1); } this.VisualSourceItem = item; } else { this.SourceCollection = itemsControl.ItemsSource ?? itemsControl.Items; } } else { this.SourceItem = (sender as FrameworkElement)?.DataContext; if (this.SourceItem != null) { this.SourceItems = Enumerable.Repeat(this.SourceItem, 1); } this.VisualSourceItem = sourceElement; this.PositionInDraggedItem = sourceElement != null?getPosition(sourceElement) : this.DragStartPosition; } this.SourceItems ??= Enumerable.Empty <object>(); }
public static string GetPlainText(this IDataObject dataObject, string projectFolder, DragDropKeyStates keystates) { var flags = dataObject.GetFlags(); if ((flags & DataObjectFlags.ProjectItems) != 0) { return(dataObject.TextFromProjectItems(projectFolder, keystates)); } return(string.Empty); }
public void SetGate(int pressedColumn, RegisterRefModel pressedRow, DragDropKeyStates keyStates) { ActionName action = HomeVM.SelectedAction; Gate oldGate; // make selection if (keyStates.HasFlag(DragDropKeyStates.ShiftKey)) { // move selection if (keyStates.HasFlag(DragDropKeyStates.ControlKey)) { if (_model.IsSelected(pressedRow.OffsetToRoot, pressedColumn)) { _model.Cut(); _model.Select(_row.OffsetToRoot, _row.OffsetToRoot, _column, _column); _model.Paste(); } } else { _model.Select(pressedRow.OffsetToRoot, _row.OffsetToRoot, pressedColumn, _column); } } else { switch (action) { case ActionName.Empty: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name != GateName.Empty) { for (int i = oldGate.Begin; i <= oldGate.End; i++) { RegisterRefModel gateRef = _model.GetRefFromOffset(i); Gate newGate = new EmptyGate(gateRef); _model.Steps[_column].SetGate(newGate); } if (oldGate is MultiControlledGate) { MultiControlledGate mcg = oldGate as MultiControlledGate; if (mcg.Controls.Contains<RegisterRefModel>(_row)) { RegisterRefModel[] toRemove = new RegisterRefModel[] { _row }; RegisterRefModel[] newControls = mcg.Controls.Except<RegisterRefModel>(toRemove).ToArray(); Gate toAdd = null; if (oldGate.Name == GateName.PhaseKick) { PhaseKickGate pk = oldGate as PhaseKickGate; toAdd = new PhaseKickGate(pk.Gamma, pk.Target, newControls); } else if (oldGate.Name == GateName.CPhaseShift) { CPhaseShiftGate cps = oldGate as CPhaseShiftGate; toAdd = new CPhaseShiftGate(cps.Dist, cps.Target, newControls); } else if (oldGate.Name == GateName.InvCPhaseShift) { InvCPhaseShiftGate icps = oldGate as InvCPhaseShiftGate; toAdd = new InvCPhaseShiftGate(icps.Dist, icps.Target, newControls); } else // Toffoli { if (newControls.Length > 1) { toAdd = new ToffoliGate(oldGate.Target, newControls); } else { toAdd = new CNotGate(oldGate.Target, newControls[0]); } } _model.Steps[_column].SetGate(toAdd); } } else if (oldGate.Name == GateName.CNot) { if (oldGate.Control.Value.OffsetToRoot == _row.OffsetToRoot) { Gate toAdd = new SigmaXGate(oldGate.Target); _model.Steps[_column].SetGate(toAdd); } } else if (oldGate is SingleGate) { SingleGate sg = oldGate as SingleGate; if (sg.Control.HasValue) { if (sg.Control.Value.OffsetToRoot == _row.OffsetToRoot) { Gate toAdd = null; switch (sg.Name) { case GateName.Hadamard: toAdd = new HadamardGate(sg.Target); break; case GateName.PhaseScale: toAdd = new PhaseScaleGate((sg as PhaseScaleGate).Gamma, sg.Target); break; case GateName.RotateX: toAdd = new RotateXGate((sg as RotateXGate).Gamma, sg.Target); break; case GateName.RotateY: toAdd = new RotateYGate((sg as RotateYGate).Gamma, sg.Target); break; case GateName.RotateZ: toAdd = new RotateZGate((sg as RotateZGate).Gamma, sg.Target); break; case GateName.SigmaX: toAdd = new SigmaXGate(sg.Target); break; case GateName.SigmaY: toAdd = new SigmaYGate(sg.Target); break; case GateName.SigmaZ: toAdd = new SigmaZGate(sg.Target); break; case GateName.SqrtX: toAdd = new SqrtXGate(sg.Target); break; case GateName.Unitary: toAdd = new UnitaryGate((sg as UnitaryGate).Matrix, sg.Target); break; default: break; } _model.Steps[_column].SetGate(toAdd); } } } } break; case ActionName.Hadamard: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Empty) { _model.Steps[_column].SetGate(new HadamardGate(_row)); _model.AddStepAfter(_column); } break; case ActionName.SigmaX: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Empty) { _model.Steps[_column].SetGate(new SigmaXGate(_row)); _model.AddStepAfter(_column); } break; case ActionName.SigmaY: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Empty) { _model.Steps[_column].SetGate(new SigmaYGate(_row)); _model.AddStepAfter(_column); } break; case ActionName.SigmaZ: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Empty) { _model.Steps[_column].SetGate(new SigmaZGate(_row)); _model.AddStepAfter(_column); } break; case ActionName.SqrtX: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Empty) { _model.Steps[_column].SetGate(new SqrtXGate(_row)); _model.AddStepAfter(_column); } break; case ActionName.RotateX: case ActionName.RotateY: case ActionName.RotateZ: case ActionName.PhaseKick: case ActionName.PhaseScale: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Empty) { MainWindow window = App.Current.MainWindow as MainWindow; GammaInputVM gammmaVM = new GammaInputVM(); ICustomContentDialog dialog = window.DialogManager.CreateCustomContentDialog(new GammaInput(gammmaVM), DialogMode.OkCancel); dialog.Ok = () => { double gamma = gammmaVM.Gamma; if (action == ActionName.RotateX) { _model.Steps[_column].SetGate(new RotateXGate(gamma, _row)); _model.AddStepAfter(_column); } else if (action == ActionName.RotateY) { _model.Steps[_column].SetGate(new RotateYGate(gamma, _row)); _model.AddStepAfter(_column); } else if (action == ActionName.RotateZ) { _model.Steps[_column].SetGate(new RotateZGate(gamma, _row)); _model.AddStepAfter(_column); } else if (action == ActionName.PhaseKick) { _model.Steps[_column].SetGate(new PhaseKickGate(gamma, _row)); _model.AddStepAfter(_column); } else { _model.Steps[_column].SetGate(new PhaseScaleGate(gamma, _row)); _model.AddStepAfter(_column); } }; dialog.Show(); } break; case ActionName.Unitary: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Empty) { MainWindow window1 = App.Current.MainWindow as MainWindow; MatrixInputVM matrixVM = new MatrixInputVM(); ICustomContentDialog dialog1 = window1.DialogManager.CreateCustomContentDialog(new MatrixInput(matrixVM), DialogMode.OkCancel); dialog1.Ok = () => { Complex[,] matrix = matrixVM.Matrix; if (matrix != null) { _model.Steps[_column].SetGate(new UnitaryGate(matrix, _row)); _model.AddStepAfter(_column); } }; dialog1.Show(); } break; case ActionName.Control: if (pressedColumn == _column) { oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (!_row.Equals(pressedRow)) { if (oldGate.Name == GateName.CNot) { CNotGate oldCnot = oldGate as CNotGate; if (pressedRow.OffsetToRoot < oldGate.Begin) { if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, oldGate.Begin - 1)) { _model.Steps[_column].SetGate(new ToffoliGate(oldCnot.Target, oldCnot.Control.Value, pressedRow)); } } else if (pressedRow.OffsetToRoot > oldGate.End) { if (_model.Steps[_column].HasPlace(oldGate.End + 1, pressedRow.OffsetToRoot)) { _model.Steps[_column].SetGate(new ToffoliGate(oldCnot.Target, oldCnot.Control.Value, pressedRow)); } } else // new Control inside { //check if not doubled if (_row.OffsetToRoot != oldCnot.Target.OffsetToRoot && _row.OffsetToRoot != oldCnot.Control.Value.OffsetToRoot) { _model.Steps[_column].SetGate(new ToffoliGate(oldCnot.Target, oldCnot.Control.Value, _row)); } } } else if (oldGate.Name == GateName.Toffoli) { ToffoliGate oldT = oldGate as ToffoliGate; if (pressedRow.OffsetToRoot < oldGate.Begin) { if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, oldGate.Begin - 1)) { _model.Steps[_column].SetGate(new ToffoliGate(oldT.Target, pressedRow, oldT.Controls)); } } else if (pressedRow.OffsetToRoot > oldGate.End) { if (_model.Steps[_column].HasPlace(oldGate.End + 1, pressedRow.OffsetToRoot)) { _model.Steps[_column].SetGate(new ToffoliGate(oldT.Target, pressedRow, oldT.Controls)); } } else // new Control inside { //check if not doubled if (_row.OffsetToRoot != oldT.Target.OffsetToRoot && !oldT.Controls.Contains<RegisterRefModel>(_row)) { _model.Steps[_column].SetGate(new ToffoliGate(oldT.Target, _row, oldT.Controls)); } } } else if (oldGate.Name == GateName.CPhaseShift) { CPhaseShiftGate oldT = oldGate as CPhaseShiftGate; if (pressedRow.OffsetToRoot < oldGate.Begin) { if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, oldGate.Begin - 1)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(pressedRow); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new CPhaseShiftGate(oldT.Dist, oldT.Target, cParams)); } } else if (pressedRow.OffsetToRoot > oldGate.End) { if (_model.Steps[_column].HasPlace(oldGate.End + 1, pressedRow.OffsetToRoot)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(pressedRow); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new CPhaseShiftGate(oldT.Dist, oldT.Target, cParams)); } } else // new Control inside { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(_row); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new CPhaseShiftGate(oldT.Dist, oldT.Target, cParams)); } } else if (oldGate.Name == GateName.InvCPhaseShift) { InvCPhaseShiftGate oldT = oldGate as InvCPhaseShiftGate; if (pressedRow.OffsetToRoot < oldGate.Begin) { if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, oldGate.Begin - 1)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(pressedRow); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new InvCPhaseShiftGate(oldT.Dist, oldT.Target, cParams)); } } else if (pressedRow.OffsetToRoot > oldGate.End) { if (_model.Steps[_column].HasPlace(oldGate.End + 1, pressedRow.OffsetToRoot)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(pressedRow); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new InvCPhaseShiftGate(oldT.Dist, oldT.Target, cParams)); } } else // new Control inside { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(_row); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new InvCPhaseShiftGate(oldT.Dist, oldT.Target, cParams)); } } else if (oldGate.Name == GateName.PhaseKick) { PhaseKickGate oldT = oldGate as PhaseKickGate; if (pressedRow.OffsetToRoot < oldGate.Begin) { if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, oldGate.Begin - 1)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(pressedRow); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new PhaseKickGate(oldT.Gamma, oldT.Target, cParams)); } } else if (pressedRow.OffsetToRoot > oldGate.End) { if (_model.Steps[_column].HasPlace(oldGate.End + 1, pressedRow.OffsetToRoot)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(pressedRow); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new PhaseKickGate(oldT.Gamma, oldT.Target, cParams)); } } else // new Control inside { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(_row); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new PhaseKickGate(oldT.Gamma, oldT.Target, cParams)); } } else if (oldGate.Control == null) { int lastEmptyRow = _row.OffsetToRoot - 1; if (pressedRow.OffsetToRoot > _row.OffsetToRoot) { lastEmptyRow = lastEmptyRow + 2; } if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, lastEmptyRow)) { switch (oldGate.Name) { case GateName.Hadamard: _model.Steps[_column].SetGate(new HadamardGate(_row, pressedRow)); break; case GateName.PhaseScale: PhaseScaleGate oldPs = oldGate as PhaseScaleGate; _model.Steps[_column].SetGate(new PhaseScaleGate(oldPs.Gamma, _row, pressedRow)); break; case GateName.RotateX: RotateXGate oldRx = oldGate as RotateXGate; _model.Steps[_column].SetGate(new RotateXGate(oldRx.Gamma, _row, pressedRow)); break; case GateName.RotateY: RotateYGate oldRy = oldGate as RotateYGate; _model.Steps[_column].SetGate(new RotateYGate(oldRy.Gamma, _row, pressedRow)); break; case GateName.RotateZ: RotateZGate oldRz = oldGate as RotateZGate; _model.Steps[_column].SetGate(new RotateZGate(oldRz.Gamma, _row, pressedRow)); break; case GateName.SigmaX: _model.Steps[_column].SetGate(new CNotGate(_row, pressedRow)); break; case GateName.SigmaY: _model.Steps[_column].SetGate(new SigmaYGate(_row, pressedRow)); break; case GateName.SigmaZ: _model.Steps[_column].SetGate(new SigmaZGate(_row, pressedRow)); break; case GateName.SqrtX: _model.Steps[_column].SetGate(new SqrtXGate(_row, pressedRow)); break; case GateName.Unitary: UnitaryGate oldU = oldGate as UnitaryGate; _model.Steps[_column].SetGate(new UnitaryGate(oldU.Matrix, _row, pressedRow)); break; case GateName.Empty: _model.Steps[_column].SetGate(new CNotGate(_row, pressedRow)); _model.AddStepAfter(_column); break; default: break; } } } } else // add control inside (only CNot or Toffoli) { if (oldGate.Name == GateName.CNot) { CNotGate oldCnot = oldGate as CNotGate; //check if not doubled if (_row.OffsetToRoot != oldCnot.Target.OffsetToRoot && _row.OffsetToRoot != oldCnot.Control.Value.OffsetToRoot) { _model.Steps[_column].SetGate(new ToffoliGate(oldCnot.Target, _row, oldCnot.Control.Value)); } } else if (oldGate.Name == GateName.Toffoli) { ToffoliGate oldT = oldGate as ToffoliGate; //check if not doubled if (_row.OffsetToRoot != oldT.Target.OffsetToRoot && !oldT.Controls.Contains<RegisterRefModel>(_row)) { _model.Steps[_column].SetGate(new ToffoliGate(oldT.Target, _row, oldT.Controls)); } } else if (oldGate.Name == GateName.CPhaseShift) { CPhaseShiftGate oldT = oldGate as CPhaseShiftGate; //check if not doubled if (_row.OffsetToRoot != oldT.Target.OffsetToRoot && !oldT.Controls.Contains<RegisterRefModel>(_row)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(_row); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new CPhaseShiftGate(oldT.Dist, oldT.Target, cParams)); } } else if (oldGate.Name == GateName.InvCPhaseShift) { InvCPhaseShiftGate oldT = oldGate as InvCPhaseShiftGate; //check if not doubled if (_row.OffsetToRoot != oldT.Target.OffsetToRoot && !oldT.Controls.Contains<RegisterRefModel>(_row)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(_row); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new InvCPhaseShiftGate(oldT.Dist, oldT.Target, cParams)); } } else if (oldGate.Name == GateName.PhaseKick) { PhaseKickGate oldT = oldGate as PhaseKickGate; //check if not doubled if (_row.OffsetToRoot != oldT.Target.OffsetToRoot && !oldT.Controls.Contains<RegisterRefModel>(_row)) { List<RegisterRefModel> cList = oldT.Controls.ToList<RegisterRefModel>(); cList.Add(_row); RegisterRefModel[] cParams = cList.ToArray<RegisterRefModel>(); _model.Steps[_column].SetGate(new PhaseKickGate(oldT.Gamma, oldT.Target, cParams)); } } } } break; case ActionName.CPhaseShift: if (pressedColumn == _column) { if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, _row.OffsetToRoot)) { MainWindow window1 = App.Current.MainWindow as MainWindow; PhaseDistInputVM vm = new PhaseDistInputVM(); vm.DistText = Math.Abs(pressedRow.OffsetToRoot - _row.OffsetToRoot).ToString(); ICustomContentDialog dialog1 = window1.DialogManager.CreateCustomContentDialog( new PhaseDistInput(vm), DialogMode.OkCancel); dialog1.Ok = () => { int? dist = vm.Dist; if (dist.HasValue) { if (_row.Equals(pressedRow)) { _model.Steps[_column].SetGate(new CPhaseShiftGate(dist.Value, _row)); } else { _model.Steps[_column].SetGate(new CPhaseShiftGate(dist.Value, _row, pressedRow)); } _model.AddStepAfter(_column); } }; dialog1.Show(); } } break; case ActionName.InvCPhaseShift: if (pressedColumn == _column) { if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, _row.OffsetToRoot)) { MainWindow window1 = App.Current.MainWindow as MainWindow; PhaseDistInputVM vm = new PhaseDistInputVM(); vm.DistText = Math.Abs(pressedRow.OffsetToRoot - _row.OffsetToRoot).ToString(); ICustomContentDialog dialog1 = window1.DialogManager.CreateCustomContentDialog( new PhaseDistInput(vm), DialogMode.OkCancel); dialog1.Ok = () => { int? dist = vm.Dist; if (dist.HasValue) { if (_row.Equals(pressedRow)) { _model.Steps[_column].SetGate(new InvCPhaseShiftGate(dist.Value, _row)); } else { _model.Steps[_column].SetGate(new InvCPhaseShiftGate(dist.Value, _row, pressedRow)); } _model.AddStepAfter(_column); } }; dialog1.Show(); } } break; case ActionName.Measure: if (pressedColumn == _column) { if (_model.Steps[_column].HasPlace(pressedRow.OffsetToRoot, _row.OffsetToRoot)) { _model.Steps[_column].SetGate(new MeasureGate(pressedRow, _row)); _model.AddStepAfter(_column); } } break; case ActionName.Ungroup: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Parametric) { CircuitEvaluator eval = CircuitEvaluator.GetInstance(); //eval.InitFromModel(_model); try { _model.SetStepForGates(_column); int oldColumns = _model.Steps.Count; int oldBegin = oldGate.Begin; int oldEnd = oldGate.End; eval.Decompose(oldGate as ParametricGate); int columnsAdded = _model.Steps.Count - oldColumns; _model.ResetStepForGates(); //remove old composite gate for (int i = oldGate.Begin; i <= oldGate.End; i++) { RegisterRefModel gateRef = _model.GetRefFromOffset(i); Gate newGate = new EmptyGate(gateRef); _model.Steps[_column].SetGate(newGate); } //delete step on _column (if it is empty) bool isEmpty = true; int j = 0; while (isEmpty && j < _model.Steps[_column].Gates.Count) { if (_model.Steps[_column].Gates[j].Name != GateName.Empty) { isEmpty = false; } j++; } if (isEmpty) { _model.DeleteStep(_column); _model.Select(oldBegin, oldEnd, _column, _column + columnsAdded - 1); } else { _model.Select(oldBegin, oldEnd, _column + 1, _column + columnsAdded); } } catch (Exception ex) { string msg = "Unable to ungroup gate. Its parameters are invalid.\n" + "Inner exception:\n" + (ex.InnerException == null ? ex.Message : ex.InnerException.Message); MessageBox.Show( msg, "Unable to ungroup gate", MessageBoxButton.OK, MessageBoxImage.Error); } } else if (oldGate.Name == GateName.Composite) { CompositeGate cg = oldGate as CompositeGate; List<Gate> toAdd = _model.GetActualGates(cg); int column = _column; foreach (Gate g in toAdd) { if (g.Name != GateName.Empty) { _model.InsertStepRight(column); column++; _model.Steps[column].SetGate(g); } } //remove old composite gate for (int i = oldGate.Begin; i <= oldGate.End; i++) { RegisterRefModel gateRef = _model.GetRefFromOffset(i); Gate newGate = new EmptyGate(gateRef); _model.Steps[_column].SetGate(newGate); } //delete step on _column (if it is empty) bool isEmpty = true; int j = 0; while (isEmpty && j < _model.Steps[_column].Gates.Count) { if (_model.Steps[_column].Gates[j].Name != GateName.Empty) { isEmpty = false; } j++; } if (isEmpty) { _model.DeleteStep(_column); } } break; case ActionName.Composite: oldGate = _model.Steps[_column].Gates[_row.OffsetToRoot]; if (oldGate.Name == GateName.Empty) { MainWindow window1 = App.Current.MainWindow as MainWindow; CircuitEvaluator eval = CircuitEvaluator.GetInstance(); //eval.InitFromModel(_model); Dictionary<string, List<MethodInfo>> dict = eval.GetExtensionGates(); if (!string.IsNullOrWhiteSpace(HomeVM.SelectedComposite)) { ParametricInputVM vm = new ParametricInputVM(HomeVM.SelectedComposite, dict, _model.CompositeGates); ParametricInput ci = new ParametricInput(vm); ICustomContentDialog dialog1 = window1.DialogManager .CreateCustomContentDialog(ci, DialogMode.OkCancel); dialog1.Ok = () => { try { if (vm.IsValid) { if (vm.Method != null) { ParametricGate cg = eval.CreateParametricGate(vm.Method, vm.ParamValues); _model.Steps[_column].SetGate(cg); _model.AddStepAfter(_column); } else if (vm.CopositeGateTarget != null) { int minWidth = _model.MinWidthForComposite(vm.FunctionName); if (vm.CopositeGateTarget.Value.Width < minWidth) { StringBuilder sb = new StringBuilder("Entered parameter has too small width.\n"); sb.Append("Entered width: "); sb.Append(vm.CopositeGateTarget.Value.Width).AppendLine(); sb.Append("Minimum width: "); sb.Append(minWidth).AppendLine(); throw new Exception(sb.ToString()); } else { CompositeGate cg = new CompositeGate(vm.FunctionName, vm.CopositeGateTarget.Value); _model.Steps[_column].SetGate(cg); _model.AddStepAfter(_column); } } } } catch (Exception ex) { string msg = "Unable to add gate. The parameters are invalid.\n" + "Inner exception:\n" + (ex.InnerException != null ? ex.InnerException.Message : ex.Message); MessageBox.Show( msg, "Unable to add gate", MessageBoxButton.OK, MessageBoxImage.Error); } }; dialog1.Show(); } } break; case ActionName.Selection: _model.Select(pressedRow.OffsetToRoot, _row.OffsetToRoot, pressedColumn, _column); break; case ActionName.Pointer: default: break; } } }
public static IntPtr Box_DragDropKeyStates(DragDropKeyStates val) { IntPtr ret = NoesisGUI_PINVOKE.Box_DragDropKeyStates((int)val); return(ret); }
private void Window_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { /* * string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); * //減去輔助鍵,得到現在是左鍵還是右鍵 * dragDropKeyStates -= e.KeyStates; * Pages.Page_File page_File = new Pages.Page_File(); * page_File.Button_Convert_Click(null, null); * if (dragDropKeyStates == DragDropKeyStates.LeftMouseButton) * { * switch (e.KeyStates) * { * case DragDropKeyStates.ControlKey: * MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.LeftDrop_Ctrl }, null); * break; * case DragDropKeyStates.ShiftKey: * MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.LeftDrop_Shift }, null); * break; * case DragDropKeyStates.AltKey: * MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.LeftDrop_Alt }, null); * break; * } * } * else if (dragDropKeyStates == DragDropKeyStates.RightMouseButton) * { * switch (e.KeyStates) * { * case DragDropKeyStates.ControlKey: * MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.RightDrop_Ctrl }, null); * break; * case DragDropKeyStates.ShiftKey: * MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.RightDrop_Shift }, null); * break; * case DragDropKeyStates.AltKey: * MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.RightDrop_Alt }, null); * break; * } * }*/ } else if (e.Data.GetDataPresent(DataFormats.UnicodeText)) { dragDropKeyStates -= e.KeyStates; string s = (string)e.Data.GetData(DataFormats.UnicodeText); if (dragDropKeyStates == DragDropKeyStates.LeftMouseButton) { switch (e.KeyStates) { case DragDropKeyStates.ControlKey: MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.LeftDrop_Ctrl, ToolTip = s }, null); break; case DragDropKeyStates.ShiftKey: MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.LeftDrop_Shift, ToolTip = s }, null); break; case DragDropKeyStates.AltKey: MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.LeftDrop_Alt, ToolTip = s }, null); break; } } else if (dragDropKeyStates == DragDropKeyStates.RightMouseButton) { switch (e.KeyStates) { case DragDropKeyStates.ControlKey: MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.RightDrop_Ctrl, ToolTip = s }, null); break; case DragDropKeyStates.ShiftKey: MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.RightDrop_Shift, ToolTip = s }, null); break; case DragDropKeyStates.AltKey: MenuItem_Click(new MenuItem { Uid = App.Settings.QuickStart.RightDrop_Alt, ToolTip = s }, null); break; } } } else { var g = e.Data.GetFormats(true); foreach (var h in g) { object ss = e.Data.GetData(h); if (ss != null) { } } string s = (string)e.Data.GetData(DataFormats.EnhancedMetafile); } }
/// <summary> /// Initializes a new instance of the <see cref="DropArgs" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="keyStates">The key states.</param> /// <param name="dropTarget">The drop target.</param> /// <param name="position">The position.</param> public DropArgs(IDataObject data, DragDropKeyStates keyStates, Object dropTarget, Point position) : base(data, keyStates, dropTarget) { this.Position = position; }
/// <summary> /// Validate the key states of DragDrop. /// </summary> internal static bool IsValidDragDropKeyStates(DragDropKeyStates dragDropKeyStates) { int keyStatesAll; keyStatesAll = (int)(DragDropKeyStates.LeftMouseButton | DragDropKeyStates.RightMouseButton | DragDropKeyStates.ShiftKey | DragDropKeyStates.ControlKey | DragDropKeyStates.MiddleMouseButton | DragDropKeyStates.AltKey); if (((int)dragDropKeyStates & ~keyStatesAll) != 0) { return false; } return true; }
/// <summary> /// Initiates a drag-and-drop operation. /// </summary> /// <param name="dragSource">A reference to the dependency object that is the source of the data being /// dragged.</param> /// <param name="data">A data object that contains the data being dragged.</param> /// <param name="allowedEffects">One of the System.Windows.DragDropEffects values that specifies permitted /// effects of the drag-and-drop operation.</param> /// <param name="initialKeyState">The initial key state when the drag operation begins.</param> public static void DoDragDrop(DependencyObject dragSource, object data, DragDropEffects allowedEffects, DragDropKeyStates initialKeyState) { // TODO: Throw if IsDragDropInProgress _dragOperationInProgress = new DragOperation(dragSource, data, allowedEffects, initialKeyState); _dragOperationInProgress .Subscribe(effects => OnDragCompleted(new DragDropCompletedEventArgs { Effects = effects })); }
/// <summary> /// Initializes a new instance of the <see cref="DropArgs" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="keyStates">The key states.</param> /// <param name="dropTarget">The drop target.</param> /// <param name="position">The position.</param> public DropArgs( IDataObject data, DragDropKeyStates keyStates, Object dropTarget, Point position ) : base( data, keyStates, dropTarget ) { this.Position = position; }
/// <summary> /// Sets the copy key state which indicates the effect of the drag drop operation. /// </summary> public static void SetDragDropCopyKeyState(UIElement target, DragDropKeyStates value) { target.SetValue(DragDropCopyKeyStateProperty, value); }
private void Window_DragEnter(object sender, DragEventArgs e) { //紀錄拖曳進來時的按鍵 dragDropKeyStates = e.KeyStates; }
private static string TextFromProjectItems(this IDataObject dataObject, string projectFolder, DragDropKeyStates keystates) { var sb = new StringBuilder(); bool first = true; foreach (var item in dataObject.GetProjectItems()) { var relative = item.FileName.MakeRRelativePath(projectFolder); var ext = Path.GetExtension(item.FileName).ToLowerInvariant(); switch (ext) { case ".r": if ((keystates & DragDropKeyStates.ControlKey) != 0) { sb.Append(GetFileContent(item.FileName)); } else { var str = first ? Environment.NewLine : string.Empty; sb.AppendLine(Invariant($"{str}source('{relative}')")); first = false; } break; case ".sql": if ((keystates & DragDropKeyStates.ControlKey) != 0) { sb.Append(Invariant($"'{GetFileContent(item.FileName)}'")); } else { sb.Append(Invariant($@"iconv(paste(readLines('{relative}', encoding = 'UTF-8', warn = FALSE), collapse='\n'), from = 'UTF-8', to = 'ASCII', sub = '')")); } break; default: sb.Append(Invariant($"'{relative}'")); break; } } return(sb.ToString()); }
public static DragDropKeyStates Unbox_DragDropKeyStates(IntPtr val) { DragDropKeyStates ret = (DragDropKeyStates)NoesisGUI_PINVOKE.Unbox_DragDropKeyStates(val); return(ret); }
static DragDropAction DetectDragAction(DragDropKeyStates keys) { if ((keys & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey) { if ((keys & DragDropKeyStates.ShiftKey) == DragDropKeyStates.ShiftKey) return DragDropAction.Link; else return DragDropAction.Copy; } return DragDropAction.Move; }
/// <summary> /// Sets the drag drop copy key state indicating the effect of the drag drop operation. /// </summary> public static void SetDragDropCopyKeyState(UIElement target, DragDropKeyStates value) { target.SetValue(DragDropCopyKeyStateProperty, value); }