示例#1
0
        public override DragDropEffects DoDragDrop(UIElement source, Point cursorPos)
        {
            this.ThemeItem.Load();
            ImageResourceThemeItem resourceThemeItem = (ImageResourceThemeItem)this.ThemeItem;

            byte[]      numArray    = ((ResourceThemeItem)resourceThemeItem).Save(false);
            IDataObject dataObject1 = Advent.Common.Interop.DataObject.CreateDataObject();
            IDataObject dataObject2 = dataObject1;

            VirtualFile[] virtualFileArray = new VirtualFile[1];
            virtualFileArray[0] = new VirtualFile()
            {
                Name          = this.ThemeItem.Name,
                LastWriteTime = DateTime.Now,
                Contents      = numArray
            };
            VirtualFile[] files = virtualFileArray;
            DataObjectExtensions.SetVirtualFiles(dataObject2, files);
            try
            {
                VmcStudioUtil.DragDropObject = (object)this;
                return(DataObjectExtensions.DoDragDrop(dataObject1, source, UIExtensions.Resize(resourceThemeItem.Image, 100), cursorPos, DragDropEffects.Copy));
            }
            finally
            {
                VmcStudioUtil.DragDropObject = (object)null;
            }
        }
            protected override async Task ExecuteAsync(ClipboardImplementationViewModel parameter)
            {
                var dataObject = new DataObject();

                DataObjectExtensions.SetLinkedWClipboardId(dataObject, parameter.Model.ClipboardObject.Id);

                await parameter.Model.Factory.WriteToDataObject(parameter.Model, dataObject);

                SysClipboard.SetDataObject(dataObject, false);
            }
示例#3
0
文件: DragDrop.cs 项目: WildGenie/MCS
 private static void ElementPreviewQueryContinueDrag(object sender, QueryContinueDragEventArgs e)
 {
     if (!e.EscapePressed)
     {
         return;
     }
     ((DependencyObject)sender).SetValue(Advent.Common.UI.DragDrop.IsDropOverPropertyKey, (object)false);
     DataObjectExtensions.DragLeave();
     Advent.Common.UI.DragDrop.dragEnterOriginalSource = (object)null;
 }
            protected override void Execute(BitmapImplementationViewModel parameter)
            {
                var option = (BitmapFileOption)setting.GetResolvedValue();

                var fileName = tempManager.Value.GetNewFileName(option.Extension);

                parameter.Model.GetImage().Save(fileName, option.CreateEncoder());

                var dataObject = new DataObject();

                DataObjectExtensions.SetLinkedWClipboardId(dataObject, parameter.Model.ClipboardObject.Id);
                dataObject.SetFileDropList(fileName);
                Clipboard.SetDataObject(dataObject);
            }
            protected override async void Execute(TextClipboardImplementationViewModel parameter)
            {
                var fileName = _tempManager.Value.GetNewFileName("txt");

                using (var sw = new StreamWriter(fileName, false, Encoding.Unicode))
                {
                    await sw.WriteAsync(parameter.Model.Source).ConfigureAwait(true);
                }
                var dataObject = new DataObject();

                DataObjectExtensions.SetLinkedWClipboardId(dataObject, parameter.Model.ClipboardObject.Id);
                dataObject.SetFileDropList(fileName);
                Clipboard.SetDataObject(dataObject);
            }
示例#6
0
文件: DragDrop.cs 项目: WildGenie/MCS
        private static void ElementPreviewDragLeave(object sender, DragEventArgs e)
        {
            UIElement uiElement = (UIElement)sender;

            uiElement.SetValue(Advent.Common.UI.DragDrop.IsDropOverPropertyKey, (object)false);
            POINT lpPoint;

            NativeMethods.GetCursorPos(out lpPoint);
            HitTestResult hitTestResult = VisualTreeHelper.HitTest((Visual)uiElement, uiElement.PointFromScreen(new Point((double)lpPoint.X, (double)lpPoint.Y)));

            if (hitTestResult == null || hitTestResult.VisualHit == null || hitTestResult.VisualHit != sender && !((Visual)sender).IsAncestorOf(hitTestResult.VisualHit))
            {
                DataObjectExtensions.DragLeave(e.Data);
            }
            Advent.Common.UI.DragDrop.dragEnterOriginalSource = (object)null;
        }
示例#7
0
        public static async Task <DataObject> GetDataObject(this ClipboardObject clipboardObject)
        {
            var dataObject = new DataObject();

            DataObjectExtensions.SetWClipboardId(dataObject, clipboardObject.Id);
            if (clipboardObject.Linked != null)
            {
                DataObjectExtensions.SetLinkedWClipboardId(dataObject, clipboardObject.Linked.Id);
            }

            foreach (var implementation in clipboardObject.Implementations)
            {
                await implementation.Factory.WriteToDataObject(implementation, dataObject);
            }

            return(dataObject);
        }
示例#8
0
 public override DragDropEffects GetDropEffects(IDataObject data)
 {
     if (VmcStudioUtil.DragDropObject == this)
     {
         return(DragDropEffects.None);
     }
     if (data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] strArray = data.GetData(DataFormats.FileDrop, true) as string[];
         if (strArray != null && strArray.Length == 1 && ImageResourceModel.IsImageFile(strArray[0]))
         {
             return(DragDropEffects.Copy);
         }
     }
     VirtualFile[] virtualFiles = DataObjectExtensions.GetVirtualFiles(data, false);
     return(virtualFiles != null && virtualFiles.Length == 1 && ImageResourceModel.IsImageFile(virtualFiles[0].Name) ? DragDropEffects.Copy : DragDropEffects.None);
 }
示例#9
0
 public override void AcceptData(IDataObject data)
 {
     if (this.GetDropEffects(data) == DragDropEffects.None)
     {
         return;
     }
     if (data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] strArray = data.GetData(DataFormats.FileDrop, true) as string[];
         if (strArray != null && strArray.Length == 1 && ImageResourceModel.IsImageFile(strArray[0]))
         {
             ((ImageResourceThemeItem)this.ThemeItem).Image = (BitmapSource)BitmapDecoder.Create(new Uri(strArray[0]), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
         }
     }
     VirtualFile[] virtualFiles = DataObjectExtensions.GetVirtualFiles(data);
     if (virtualFiles == null || virtualFiles.Length != 1 || !ImageResourceModel.IsImageFile(virtualFiles[0].Name))
     {
         return;
     }
     ((ImageResourceThemeItem)this.ThemeItem).Image = (BitmapSource)BitmapDecoder.Create((Stream) new MemoryStream(virtualFiles[0].Contents), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
 }
示例#10
0
        public override DragDropEffects DoDragDrop(UIElement source, Point cursorPos)
        {
            Advent.Common.Interop.DataObject dataObject1 = new Advent.Common.Interop.DataObject();
            List <VirtualFile> list = new List <VirtualFile>();

            foreach (T obj in Enumerable.Where <T>(this.GetThemeItems(), (Func <T, bool>)(o => o.Visibility == Visibility.Visible)))
            {
                obj.ThemeItem.Load();
                VirtualFile virtualFile = new VirtualFile()
                {
                    Name          = obj.ThemeItem.Name,
                    LastWriteTime = DateTime.Now
                };
                if (obj.ThemeItem.IsDirty)
                {
                    virtualFile.Contents = ((ResourceThemeItem)obj.ThemeItem).Save(false);
                }
                else
                {
                    T copy = obj;
                    virtualFile.ContentsFunc = (Func <byte[]>)(() => ((ResourceThemeItem)copy.ThemeItem).OriginalBuffer);
                }
                list.Add(virtualFile);
            }
            DataObjectExtensions.SetVirtualFiles(dataObject1, list.ToArray());
            IDataObject dataObject2 = (IDataObject) new System.Windows.DataObject((object)dataObject1);

            try
            {
                VmcStudioUtil.DragDropObject = (object)list;
                return(DataObjectExtensions.DoDragDrop(dataObject2, source, cursorPos, DragDropEffects.Copy));
            }
            finally
            {
                VmcStudioUtil.DragDropObject = (object)list;
            }
        }
示例#11
0
文件: DragDrop.cs 项目: WildGenie/MCS
        private static void ParentDragEnter(object sender, DragEventArgs e)
        {
            if (e.OriginalSource != Advent.Common.UI.DragDrop.dragEnterOriginalSource)
            {
                Advent.Common.UI.DragDrop.dragEnterOriginalSource = e.OriginalSource;
                Advent.Common.UI.DragDrop.isDragEnterHandled      = false;
            }
            if (Advent.Common.UI.DragDrop.isDragEnterHandled)
            {
                return;
            }
            UIElement uiElement1 = (UIElement)null;

            foreach (UIElement uiElement2 in Advent.Common.UI.DragDrop.dragElements)
            {
                if (uiElement2.IsAncestorOf((DependencyObject)e.OriginalSource) && VisualTreeHelper.GetParent((DependencyObject)uiElement2) == sender)
                {
                    uiElement1 = uiElement2;
                    break;
                }
            }
            if (uiElement1 == null)
            {
                return;
            }
            Window ancestor           = UIExtensions.GetAncestor <Window>((DependencyObject)uiElement1);
            string descriptionMessage = Advent.Common.UI.DragDrop.GetDropDescription((DependencyObject)uiElement1);

            if (descriptionMessage != null)
            {
                descriptionMessage = descriptionMessage.Replace("{0}", "%1");
            }
            uiElement1.SetValue(Advent.Common.UI.DragDrop.IsDropOverPropertyKey, (object)true);
            DataObjectExtensions.DragEnter(ancestor, e.Data, Mouse.GetPosition((IInputElement)ancestor), e.Effects, descriptionMessage, Advent.Common.UI.DragDrop.GetDropDescriptionInsert((DependencyObject)uiElement1));
            Advent.Common.UI.DragDrop.isDragEnterHandled = true;
        }
示例#12
0
文件: DragDrop.cs 项目: WildGenie/MCS
 private static void ElementDragOver(object sender, DragEventArgs e)
 {
     DataObjectExtensions.DragOver(Mouse.GetPosition((IInputElement)UIExtensions.GetAncestor <Window>((DependencyObject)sender)), e.Effects);
 }
示例#13
0
文件: DragDrop.cs 项目: WildGenie/MCS
 private static void ElementPreviewDrop(object sender, DragEventArgs e)
 {
     ((DependencyObject)sender).SetValue(Advent.Common.UI.DragDrop.IsDropOverPropertyKey, (object)false);
     DataObjectExtensions.Drop(e.Data, Mouse.GetPosition((IInputElement)UIExtensions.GetAncestor <Window>((DependencyObject)sender)), e.Effects);
     Advent.Common.UI.DragDrop.dragEnterOriginalSource = (object)null;
 }