/// <summary> /// Отправка данных в буфер обмена /// </summary> /// <param name="data"></param> public static void SendToClipboard(ClipboardBufferData data) { // копируем в буфер обмена System.Windows.Forms.IDataObject dataObj = new DataObject(); dataObj.SetData(clipboard_format.Name, false, data); Clipboard.SetDataObject(dataObj, false); }
private void TreeViewExplorer_MouseMove(object sender, MouseEventArgs e) { TreeViewItem item = TreeViewExtensions.GetNearestContainer(e.OriginalSource as UIElement); if ((e.LeftButton == MouseButtonState.Pressed) && (item != null)) { var mousePos = e.GetPosition(null); var diff = startPoint - mousePos; if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) { if (selectedItems.Count != 0) { List <ProjectElementBase> elements = new List <ProjectElementBase>(); foreach (TreeViewItem i in selectedItems) { if (i != null) { ProjectElementBase elem = i.Tag as ProjectElementBase; elements.Add(elem); } } if (ClipboardBufferData.CheckGroupValid(elements) != GroupType.IllegalGroup) { var dragData = new DataObject(new ClipboardBufferData(ClipboardOperationType.Cut, elements)); DragDrop.DoDragDrop(TreeViewExplorer, dragData, DragDropEffects.Move | DragDropEffects.None); } } } } }
private void Copy_Executed(object sender, ExecutedRoutedEventArgs e) { if (selectedItems.Count != 0) { List <ProjectElementBase> elements = new List <ProjectElementBase>(); foreach (TreeViewItem i in selectedItems) { if (i != null) { ProjectElementBase elem = i.Tag as ProjectElementBase; elements.Add(elem); } } ClipboardBufferData data = new ClipboardBufferData(ClipboardOperationType.Copy, elements); if (ClipboardBufferData.CanSendToClipboard(data)) { ClipboardBufferData.SendToClipboard(data); } foreach (TreeViewItem i in selectedItems) { if (i != null) { ProjectElementBase elem = i.Tag as ProjectElementBase; elem.Copy_Executed(sender, e); } } } }
private bool CanPaste(ClipboardBufferData data) { bool res1 = (data.GroupType == GroupType.ProjectElements); if (res1 == false) { return(false); } foreach (ProjectElementBase paste_elem in data.Elements) { if (paste_elem is ProjectFolder) { foreach (ProjectElementBase child in (paste_elem as ProjectFolder).GetProjectFilesRecursive()) { if (child.Path == Path) { return(false); } } } } foreach (ProjectElementBase elem in Childrens) { foreach (ProjectElementBase paste_elem in data.Elements) { if ((paste_elem.Path.Equals(elem.Path)) || (paste_elem.Path.Equals(Path))) { return(false); } } } return(true); }
private void Paste(ClipboardBufferData data) { if (data.GroupType == GroupType.ProjectElements) { try { //1. В зависимости от операции - переместить или скопировать элементы физически if (data.OperationType == ClipboardOperationType.Copy) { CopyElementsToCurrentFolder(data); } if (data.OperationType == ClipboardOperationType.Cut) { MoveElementsToCurrentFolder(data); } //2. Добавление элементов в текущую папку(логически) Project.Compiler.UpdateFileList(); SchematixCore.Core.UpdateExplorerPanel(); } catch (System.IO.IOException ex) { Schematix.Core.Logger.Log.Error("Paste error.", ex); System.Windows.MessageBox.Show(string.Format("Paste error.\n", ex.Message), "File system error ocurred", System.Windows.MessageBoxButton.OK); } } }
private void TreeViewExplorer_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(ClipboardBufferData))) { ClipboardBufferData data = e.Data.GetData(typeof(ClipboardBufferData)) as ClipboardBufferData; Point currentPosition = e.GetPosition(TreeViewExplorer); TreeViewItem item = TreeViewExtensions.GetNearestContainer(e.OriginalSource as UIElement); //Можно ли вставить данные сюда? if (item == null) { return; } var elem = item.Tag as ProjectElementBase; if (elem == null) { return; } if (elem is IDropable) { (elem as IDropable).Drop(data); } } }
private void TreeViewExplorer_DragOver(object sender, DragEventArgs e) { try { Point currentPosition = e.GetPosition(TreeViewExplorer); if ((Math.Abs(currentPosition.X - startPoint.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(currentPosition.Y - startPoint.Y) > SystemParameters.MinimumVerticalDragDistance)) { // Verify that this is a valid drop and then store the drop target TreeViewItem item = TreeViewExtensions.GetNearestContainer(e.OriginalSource as UIElement); //Можно ли вставить данные сюда? var elem = item.Tag as ProjectElementBase; ClipboardBufferData data = e.Data.GetData(typeof(ClipboardBufferData)) as ClipboardBufferData; e.Effects = ((elem is IDropable) && ((elem as IDropable).CanDrop(data))) ? DragDropEffects.Move : DragDropEffects.None; e.Handled = true; return; } e.Effects = DragDropEffects.None; e.Handled = true; return; } catch (Exception) { } }
private void Copy_CanExecute(object sender, CanExecuteRoutedEventArgs e) { if (selectedItems.Count != 0) { List <ProjectElementBase> elements = new List <ProjectElementBase>(); foreach (TreeViewItem i in selectedItems) { if (i != null) { ProjectElementBase elem = i.Tag as ProjectElementBase; elements.Add(elem); } } e.CanExecute = (ClipboardBufferData.CheckGroupValid(elements) != GroupType.IllegalGroup); foreach (TreeViewItem i in selectedItems) { if (i != null) { ProjectElementBase elem = i.Tag as ProjectElementBase; elem.Copy_CanExecute(sender, e); } } } }
public override void Paste_Executed(object sender, ExecutedRoutedEventArgs e) { if (ClipboardBufferData.CanGetFromClipboard() == true) { ClipboardBufferData data = ClipboardBufferData.GetFromClipboard(); Paste(data); } }
/// <summary> /// Получение данных с буфера обмена /// </summary> /// <returns></returns> public static ClipboardBufferData GetFromClipboard() { IDataObject dataObj = Clipboard.GetDataObject(); ClipboardBufferData data = null; if (dataObj.GetDataPresent(clipboard_format.Name)) { data = dataObj.GetData(clipboard_format.Name) as ClipboardBufferData; } return(data); }
/// <summary> /// Можно ли получить данные с буфера обмена /// </summary> /// <returns></returns> public static bool CanGetFromClipboard() { IDataObject dataObj = Clipboard.GetDataObject(); bool res = dataObj.GetDataPresent(clipboard_format.Name); if (res == true) { ClipboardBufferData data = dataObj.GetData(clipboard_format.Name) as ClipboardBufferData; dataObj.SetData(clipboard_format.Name, data); } return(res); }
public override void Paste_CanExecute(object sender, CanExecuteRoutedEventArgs e) { if (ClipboardBufferData.CanGetFromClipboard() == true) { ClipboardBufferData data = ClipboardBufferData.GetFromClipboard(); ClipboardBufferData.SendToClipboard(data); bool res = CanPaste(data); if (res == true) { e.CanExecute = true; } } }
private void Paste(ClipboardBufferData data) { if (data.GroupType == GroupType.ProjectsAndSolutionsFolder) { //1. Удаление элементов (логически) foreach (ProjectElementBase elem in data.Elements) { RemoveElementFromSolution(elem.Path, SchematixCore.Core.Solution); } //2. Добавление элементов в текущую папку(логически) AddElementRange(data.Elements); } SchematixCore.Core.UpdateExplorerPanel(); }
/// <summary> /// Скопировать элементы в текущую папку /// </summary> /// <param name="data"></param> private void CopyElementsToCurrentFolder(ClipboardBufferData data) { foreach (ProjectElementBase elem in data.Elements) { if (elem is ProjectFolder) { FileOperations.DirectoryCopy((elem as ProjectFolder), this); } else { if (elem is ProjectElement) { FileOperations.FileCopy((elem as ProjectElement), this); } } } }
/// <summary> /// Переместить элементы в текущую папку /// </summary> /// <param name="data"></param> private void MoveElementsToCurrentFolder(ClipboardBufferData data) { foreach (ProjectElementBase elem in data.Elements) { RemoveElementFromSolution(elem.Path, SchematixCore.Core.Solution); if (elem is ProjectFolder) { FileOperations.DirectoryMove((elem as ProjectFolder), this); } else { if (elem is ProjectElement) { FileOperations.FileMove((elem as ProjectElement), this); } } } }
public bool CanDrop(ClipboardBufferData data) { return(CanPaste(data)); }
/// <summary> /// Возможно ли отправить данные в буфер обмена /// </summary> /// <param name="data"></param> /// <returns></returns> public static bool CanSendToClipboard(ClipboardBufferData data) { return(IsSerializable(data)); }
public void Drop(ClipboardBufferData data) { rootFolder.Drop(data); }
public void Drop(ClipboardBufferData data) { Paste(data); }
public bool CanDrop(ClipboardBufferData data) { return(rootFolder.CanDrop(data)); }