Ejemplo n.º 1
0
 static bool DoEnablePaste(ISolutionFolder container, System.Windows.IDataObject dataObject)
 {
     if (dataObject == null)
     {
         return(false);
     }
     if (dataObject.GetDataPresent(typeof(ISolutionItem).ToString()))
     {
         Guid          guid         = Guid.Parse(dataObject.GetData(typeof(ISolutionItem).ToString()).ToString());
         ISolutionItem solutionItem = container.ParentSolution.GetItemByGuid(guid);
         if (solutionItem == null || solutionItem == container)
         {
             return(false);
         }
         if (solutionItem is ISolutionFolder)
         {
             return(solutionItem.ParentFolder != container &&
                    !((ISolutionFolder)solutionItem).IsAncestorOf(container));
         }
         else
         {
             return(solutionItem.ParentFolder != container);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        public static void DoPaste(ISolutionFolderNode folderNode)
        {
            System.Windows.IDataObject dataObject = SD.Clipboard.GetDataObject();
            if (!DoEnablePaste(folderNode.Folder, dataObject))
            {
                LoggingService.Warn("SolutionFolderNode.DoPaste: Pasting was not enabled.");
                return;
            }

            ExtTreeNode folderTreeNode = (ExtTreeNode)folderNode;

            if (dataObject.GetDataPresent(typeof(ISolutionItem).ToString()))
            {
                Guid          guid         = Guid.Parse(dataObject.GetData(typeof(ISolutionItem).ToString()).ToString());
                ISolutionItem solutionItem = folderNode.Solution.GetItemByGuid(guid);
                if (solutionItem != null)
                {
                    MoveItem(solutionItem, folderNode.Folder);
                    ExtTreeView treeView = (ExtTreeView)folderTreeNode.TreeView;
                    foreach (ExtTreeNode node in treeView.CutNodes)
                    {
                        ExtTreeNode oldParent = node.Parent as ExtTreeNode;
                        node.Remove();

                        node.InsertSorted(folderTreeNode);
                        if (oldParent != null)
                        {
                            oldParent.Refresh();
                        }
                    }
                    ProjectService.SaveSolution();
                }
            }
            folderTreeNode.Expand();
        }
Ejemplo n.º 3
0
        private void ExtractImageInSTAThreadContext(object imageDetails)
        {
            ImageDetails imageInfo  = (ImageDetails)imageDetails;
            Range        imageRange = imageInfo.imageRange;
            string       filePath   = imageInfo.filePath;

            try
            {
                imageRange.Copy();

                System.Windows.IDataObject data = System.Windows.Clipboard.GetDataObject();
                using (Bitmap bitmap = (Bitmap)data.GetData(typeof(System.Drawing.Bitmap)))
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                    bitmap.Save(filePath);
                }
                System.Windows.Clipboard.Clear();
            }
            catch (OutOfMemoryException)
            {
                // try again
                System.Windows.Clipboard.Clear();
                ExtractImage(imageRange, filePath);
            }
        }
Ejemplo n.º 4
0
        protected override void Execute(CodeActivityContext context)
        {
            string text = "";

            System.Windows.Media.Imaging.BitmapSource image = null;
            int counter = 0;

            while (string.IsNullOrEmpty(text) && image == null)
            {
                counter++;
                try
                {
                    if (SendCtrlC.Get(context))
                    {
                        var keys = FlaUI.Core.Input.Keyboard.Pressing(FlaUI.Core.WindowsAPI.VirtualKeyShort.LCONTROL, FlaUI.Core.WindowsAPI.VirtualKeyShort.KEY_C);
                        keys.Dispose();
                    }
                    System.Windows.IDataObject idat = null;
                    Exception threadEx = null;
                    System.Threading.Thread staThread = new System.Threading.Thread(() =>
                    {
                        try
                        {
                            if (System.Windows.Clipboard.ContainsText())
                            {
                                idat = System.Windows.Clipboard.GetDataObject();
                                text = (string)idat.GetData(typeof(string));
                            }
                            if (System.Windows.Clipboard.ContainsImage())
                            {
                                idat  = System.Windows.Clipboard.GetDataObject();
                                image = System.Windows.Clipboard.GetImage();
                                // var tmp = System.Windows.Clipboard.GetImage();
                                // image = new ImageElement(tmp);
                                //image = (System.Drawing.Image)idat.GetData(typeof(System.Drawing.Image));
                            }
                        }

                        catch (Exception ex)
                        {
                            threadEx = ex;
                        }
                    });
                    staThread.SetApartmentState(System.Threading.ApartmentState.STA);
                    staThread.Start();
                    staThread.Join();
                }
                catch (Exception ex)
                {
                    Log.Debug(ex.Message);
                    System.Threading.Thread.Sleep(250);
                }
                if (counter == 3)
                {
                    break;
                }
            }
            context.SetValue(StringResult, text);
            context.SetValue(ImageResult, image);
        }
Ejemplo n.º 5
0
        public static void SetDescription(System.Windows.IDataObject dataObject, System.Windows.DragDropEffects effect, string message, string insert = null)
        {
            DropImageType type;

            switch (effect)
            {
            case System.Windows.DragDropEffects.Copy:
                type = DropImageType.Copy;
                break;

            case System.Windows.DragDropEffects.Link:
                type = DropImageType.Link;
                break;

            case System.Windows.DragDropEffects.Move:
                type = DropImageType.Move;
                break;

            case System.Windows.DragDropEffects.None:
                type = DropImageType.None;
                break;

            default:
                type = DropImageType.NoImage;
                break;
            }

            SetDescription((IDataObject)dataObject, type, message, insert);
        }
    internal static MemoryStream GetFileContents(System.Windows.IDataObject dataObject, int index)
    {
        //cast the default IDataObject to a com IDataObject
        IDataObject comDataObject;

        comDataObject = (IDataObject)dataObject;
        System.Windows.DataFormat Format = System.Windows.DataFormats.GetDataFormat("FileContents");
        if (Format == null)
        {
            return(null);
        }
        FORMATETC formatetc = new FORMATETC();

        formatetc.cfFormat = (short)Format.Id;
        formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
        formatetc.lindex   = index;
        formatetc.tymed    = TYMED.TYMED_ISTREAM | TYMED.TYMED_HGLOBAL;
        //create STGMEDIUM to output request results into
        STGMEDIUM medium = new STGMEDIUM();

        //using the com IDataObject interface get the data using the defined FORMATETC
        comDataObject.GetData(ref formatetc, out medium);
        switch (medium.tymed)
        {
        case TYMED.TYMED_ISTREAM: return(GetIStream(medium));

        default: throw new NotSupportedException();
        }
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Executes the paste operation on the given element.
        /// </summary>
        /// <param name="modelElement">Element.</param>
        /// <returns>Validation result, indicating problems during the paste operation.</returns>
        public static ValidationResult ExecutePaste(ModelElement modelElement)
        {
            System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject();

            ValidationResult result = null;

            using (Transaction transaction = modelElement.Store.TransactionManager.BeginTransaction("Paste"))
            {
                result = ModelElementOperations.Merge(modelElement, idataObject);
                transaction.Commit();
            }

            ModelProtoGroup group = ModelElementOperations.GetModelProtoGroup(idataObject);

            if (group != null)
            {
                if (group.Operation == ModelProtoGroupOperation.Move)
                {
                    System.Windows.Clipboard.Clear();
                    ElementsInMoveMode.Clear();
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     result != null, arrays != null
        ///     Uses CultureHelper.SystemCultureInfo.
        /// </summary>
        /// <returns></returns>
        public static List <string[]> ParseClipboardData()
        {
            IDataObject dataObj = Clipboard.GetDataObject();

            if (dataObj is null)
            {
                return(new List <string[]>());
            }

            object clipboardData = dataObj.GetData(DataFormats.CommaSeparatedValue);

            if (clipboardData != null)
            {
                string clipboardDataString = GetClipboardDataString(clipboardData);
                return(CsvHelper.ParseCsv(CultureHelper.SystemCultureInfo.TextInfo.ListSeparator, clipboardDataString));
            }
            clipboardData = dataObj.GetData(DataFormats.Text);
            if (clipboardData != null)
            {
                string clipboardDataString = GetClipboardDataString(clipboardData);
                return(CsvHelper.ParseCsv("\t", clipboardDataString));
            }

            return(new List <string[]>());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Converts a <see cref="IDataObject"/> into an <see cref="IShellItemArray"/>
        /// </summary>
        /// <param name="dataobject">The Interface you want to convert</param>
        /// <returns></returns>
        public static IShellItemArray ToShellItemArray(this System.Windows.IDataObject dataobject)
        {
            IShellItemArray shellItemArray;
            var             iid = new Guid(InterfaceGuids.IShellItemArray);

            Shell32.SHCreateShellItemArrayFromDataObject((System.Runtime.InteropServices.ComTypes.IDataObject)dataobject, iid, out shellItemArray);
            return(shellItemArray);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Invalidates the drag image.
 /// </summary>
 /// <param name="dataObject">The data object for which to invalidate the drag image.</param>
 /// <remarks>This call tells the drag image manager to reformat the internal
 /// cached drag image, based on the already set drag image bitmap and current drop
 /// description.</remarks>
 public static void InvalidateDragImage(System.Windows.IDataObject dataObject)
 {
     if (dataObject.GetDataPresent("DragWindow"))
     {
         IntPtr hwnd = GetIntPtrFromData(dataObject.GetData("DragWindow"));
         PostMessage(hwnd, WM_INVALIDATEDRAGIMAGE, IntPtr.Zero, IntPtr.Zero);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataObjectAdapterWpfToAltaxo"/> class, using an System.Windows data object.
        /// </summary>
        /// <param name="dao">The System.Windows data object to wrap.</param>
        /// <exception cref="System.ArgumentNullException">dao</exception>
        public DataObjectAdapterWpfToAltaxo(System.Windows.IDataObject dao)
        {
            if (null == dao)
            {
                throw new ArgumentNullException("dao");
            }

            o = dao;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OutlookDataObject" /> class and adds the specified object to it.
        /// </summary>
        /// <param name="dataObject">The data to store.</param>
        public OutlookDataObject(IWindowsDataObject dataObject)
        {
            Check.ArgumentNull(dataObject, nameof(dataObject));
            Check.InvalidCast(dataObject is IComDataObject, nameof(dataObject));

            DataObject               = dataObject;
            ComDataObject            = (IComDataObject)DataObject;
            OleDataObject            = DataObject.GetType().GetField("_innerData", BindingFlags.NonPublic | BindingFlags.Instance).GetValue <IWindowsDataObject>(DataObject);
            GetDataFromHGlobalMethod = OleDataObject.GetType().GetMethod("GetDataFromHGLOBLAL", BindingFlags.NonPublic | BindingFlags.Instance);
        }
Ejemplo n.º 13
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// handle pst files
        /// </summary>
        /// -----------------------------------------------------------------------------------
        public override bool TryHandleDrop(System.Windows.IDataObject dataObject, out Seed seed)
        {
            string[] fileNames = (string[])dataObject.GetData("FileNameW");
            string   fileName  = null;

            if (fileNames != null)
            {
                fileName = fileNames[0];
            }
            return(TryHandleLocation(fileName, out seed));
        }
Ejemplo n.º 14
0
        public override void Paste()
        {
            System.Windows.IDataObject dataObject = SD.Clipboard.GetDataObject();
            if (dataObject == null)
            {
                return;
            }

            if (dataObject.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = (string[])dataObject.GetData(DataFormats.FileDrop);
                foreach (string fileName in files)
                {
                    if (System.IO.Directory.Exists(fileName))
                    {
                        if (!FileUtility.IsBaseDirectory(fileName, Directory))
                        {
                            CopyDirectoryHere(fileName, false);
                        }
                    }
                    else
                    {
                        CopyFileHere(fileName, false);
                    }
                }
            }
            else if (dataObject.GetDataPresent(typeof(FileNode)))
            {
                FileOperationClipboardObject clipboardObject = (FileOperationClipboardObject)dataObject.GetData(typeof(FileNode).ToString());

                if (File.Exists(clipboardObject.FileName))
                {
                    CopyFileHere(clipboardObject.FileName, clipboardObject.PerformMove);
                    if (clipboardObject.PerformMove)
                    {
                        Clipboard.Clear();
                    }
                }
            }
            else if (dataObject.GetDataPresent(typeof(DirectoryNode)))
            {
                FileOperationClipboardObject clipboardObject = (FileOperationClipboardObject)dataObject.GetData(typeof(DirectoryNode).ToString());

                if (System.IO.Directory.Exists(clipboardObject.FileName))
                {
                    CopyDirectoryHere(clipboardObject.FileName, clipboardObject.PerformMove);
                    if (clipboardObject.PerformMove)
                    {
                        Clipboard.Clear();
                    }
                }
            }
            ProjectService.SaveSolution();
        }
        public override void GetApplicationDragDropInformation(System.Windows.IDataObject data, out string[] filenames, out MemoryStream[] filestreams)
        {
            ////wrap standard IDataObject in OutlookDataObject
            //OutlookDataObject dataObject = new OutlookDataObject(data);

            ////get the names and data streams of the files dropped
            //filenames = (string[])dataObject.GetData("FileGroupDescriptorW");
            //filestreams = (MemoryStream[])dataObject.GetData("FileContents");
            filenames   = null;
            filestreams = null;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OutlookDataObject"/> class.
        /// </summary>
        /// <param name="underlyingDataObject">The underlying data object to wrap.</param>
        public OutlookDataObject(System.Windows.IDataObject underlyingDataObject)
        {
            //get the underlying dataobject and its ComType IDataObject interface to it
            this.underlyingDataObject    = underlyingDataObject;
            this.comUnderlyingDataObject = (System.Runtime.InteropServices.ComTypes.IDataObject) this.underlyingDataObject;

            //get the internal ole dataobject and its GetDataFromHGLOBLAL so it can be called later
            FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("_innerData", BindingFlags.NonPublic | BindingFlags.Instance);

            this.oleUnderlyingDataObject   = (System.Windows.IDataObject)innerDataField.GetValue(this.underlyingDataObject);
            this.getDataFromHGLOBLALMethod = this.oleUnderlyingDataObject.GetType().GetMethod("GetDataFromHGLOBLAL", BindingFlags.NonPublic | BindingFlags.Instance);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// PasteCommand can execute.
        /// </summary>
        private bool PasteCommand_CanExecute()
        {
            List <ModelElement> modelElements = new List <ModelElement>();

            if (this.SelectedItem is ModelTreeViewModel)
            {
                foreach (BaseModelElementViewModel vm in this.ModelTreeViewModel.SelectedItems)
                {
                    if (vm.GetHostedElement() == null)
                    {
                        continue;
                    }

                    modelElements.Add(vm.GetHostedElement());
                }
            }
            else if (this.SelectedItem is DiagramViewModel)
            {
                foreach (BaseModelElementViewModel vm in this.DiagramViewModel.SelectedItems)
                {
                    if (vm.GetHostedElement() == null)
                    {
                        continue;
                    }

                    modelElements.Add(vm.GetHostedElement());
                }
            }

            if (modelElements.Count == 0)
            {
                modelElements.Add(this.ModelContext);
            }

            if (modelElements.Count == 1)
            {
                try
                {
                    System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject();
                    if (idataObject != null)
                    {
                        CopyAndPasteOperations.ProcessMoveMode(idataObject);
                        return(CopyAndPasteOperations.CanExecutePaste(modelElements[0], idataObject));
                    }
                }
                catch { }

                return(false);
            }

            return(false);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Returns an Altaxo data object from a Windows (Wpf) data object. If the Windows data object is just an adapter from an Altaxo data object,
        /// this Altaxo data object is returned. If this is not the case, an <see cref="DataObjectAdapterWpfToAltaxo"/> is created, wrapping the provided data object,
        /// and this adapter is returned.
        /// </summary>
        /// <param name="wpfDo">The WPF data object.</param>
        /// <returns>An Altaxo data object.</returns>
        public static Altaxo.Serialization.Clipboard.IDataObject FromWpfDataObject(System.Windows.IDataObject wpfDo)
        {
            var adapter = wpfDo as DataObjectAdapterAltaxoToWpf;

            if (null != adapter)                  // is it an adapter from Altaxo to Wpf
            {
                return(adapter.DataObjectAltaxo); // if yes, then we use the underlying Altaxo data object directly, without wrapping it in another adapter
            }
            else
            {
                return(new DataObjectAdapterWpfToAltaxo(wpfDo)); // else we have to wrap it in an adapter
            }
        }
Ejemplo n.º 19
0
        private void ExtractImage(Range imageRange, string filePath)
        {
            imageRange.Copy();

            System.Windows.IDataObject data = System.Windows.Clipboard.GetDataObject();
            using (Bitmap bitmap = (Bitmap)data.GetData(typeof(System.Drawing.Bitmap)))
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                bitmap.Save(filePath);
            }
            System.Windows.Clipboard.Clear();
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Helper method of the cut opeation.
        /// </summary>
        /// <param name="eventManager">Event manager.</param>
        /// <param name="idataObject">Data object.</param>
        public static void ProcessMoveMode(ViewModelEventManager eventManager, System.Windows.IDataObject idataObject)
        {
            bool isInMoveMode = false;

            if (idataObject != null)
            {
                ModelProtoGroup group = ModelElementOperations.GetModelProtoGroup(idataObject);
                if (group != null)
                {
                    if (group.Operation == ModelProtoGroupOperation.Move)
                    {
                        isInMoveMode = true;

                        List <System.Guid> guids = new List <System.Guid>();
                        foreach (ModelProtoElement root in group.ProtoRootElements)
                        {
                            guids.Add(root.ElementId);
                        }
                        foreach (System.Guid id in guids)
                        {
                            if (!ElementsInMoveMode.Contains(id))
                            {
                                eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(true, ModelElementCustomEventNames.ModelElementMoveModeStatus, id);
                                ElementsInMoveMode.Add(id);
                            }
                        }
                        for (int i = ElementsInMoveMode.Count - 1; i >= 0; i--)
                        {
                            if (!guids.Contains(ElementsInMoveMode[i]))
                            {
                                eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(false, ModelElementCustomEventNames.ModelElementMoveModeStatus, ElementsInMoveMode[i]);
                                ElementsInMoveMode.RemoveAt(i);
                            }
                        }
                    }
                }
            }

            if (!isInMoveMode)
            {
                // remove all elements from the current list and notify them to change status
                foreach (System.Guid id in ElementsInMoveMode)
                {
                    eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(false, ModelElementCustomEventNames.ModelElementMoveModeStatus, id);
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Executes the paste operation on the given element.
        /// </summary>
        /// <param name="modelElement">Element.</param>
        /// <returns>Validation result, indicating problems during the paste operation.</returns>
        public static ValidationResult ExecutePaste(ModelElement modelElement)
        {
            System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject();

            ValidationResult result = null;

            using (Transaction transaction = modelElement.Store.TransactionManager.BeginTransaction("Paste", true))
            {
                result = ModelElementOperations.Merge(modelElement, idataObject);

                List <Guid> shapes = DiagramsShapeStore.GetFromStore(modelElement.Id);
                if (shapes != null)
                {
                    foreach (Guid s in shapes)
                    {
                        NodeShape shape = modelElement.Store.ElementDirectory.FindElement(s) as NodeShape;
                        if (shape != null)
                        {
                            using (Transaction tShape = modelElement.Store.TransactionManager.BeginTransaction("Create shape", true))
                            {
                                shape.FixUpMissingShapes();
                                tShape.Commit();
                            }
                            using (Transaction tLinkShapes = modelElement.Store.TransactionManager.BeginTransaction("Fixup missing link shapes", true))
                            {
                                shape.FixUpMissingLinkShapes();
                                tLinkShapes.Commit();
                            }
                        }
                    }
                }
                transaction.Commit();
            }

            ModelProtoGroup group = ModelElementOperations.GetModelProtoGroup(idataObject);

            if (group != null)
            {
                if (group.Operation == ModelProtoGroupOperation.Move)
                {
                    System.Windows.Clipboard.Clear();
                    ElementsInMoveMode.Clear();
                }
            }

            return(result);
        }
Ejemplo n.º 22
0
        public static void SetDropDescription(System.Windows.IDataObject dataObject, DropImageType type, string format, string insert)
        {
            if (format != null && format.Length > 259)
            {
                throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
            }
            if (insert != null && insert.Length > 259)
            {
                throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");
            }
            DropDescription dropDescription;

            dropDescription.type      = type;
            dropDescription.szMessage = format;
            dropDescription.szInsert  = insert;
            SetDropDescription(dataObject, dropDescription);
        }
Ejemplo n.º 23
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// If the data object can be handled hand back a seed to it.
        /// </summary>
        /// -----------------------------------------------------------------------------------
        public override bool TryHandleDrop(System.Windows.IDataObject dataObject, out Seed seed)
        {
            MemoryStream urlStream = (MemoryStream)dataObject.GetData("UniformResourceLocatorW");
            string       url       = null;

            if (urlStream != null)
            {
                byte[] buffer = new byte[urlStream.Length];
                urlStream.Read(buffer, 0, (int)urlStream.Length);
                url = System.Text.Encoding.Unicode.GetString(buffer);
            }

            if (url == null)
            {
                url = Utilities.GetFileNameFromDropObject(dataObject);
            }

            return(TryHandleLocation(url, out seed));
        }
Ejemplo n.º 24
0
        private static void SetBoolFormat(System.Windows.IDataObject dataObject, string format, bool val)
        {
            FillFormatETC(format, TYMED.TYMED_HGLOBAL, out FORMATETC formatETC);
            IntPtr num = Marshal.AllocHGlobal(4);

            try
            {
                Marshal.Copy(BitConverter.GetBytes(val ? 1 : 0), 0, num, 4);
                STGMEDIUM medium;
                medium.pUnkForRelease = (object)null;
                medium.tymed          = TYMED.TYMED_HGLOBAL;
                medium.unionmember    = num;
                ((System.Runtime.InteropServices.ComTypes.IDataObject)dataObject).SetData(ref formatETC, ref medium, true);
            }
            catch
            {
                Marshal.FreeHGlobal(num);
                throw;
            }
        }
Ejemplo n.º 25
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         Int32  _timeout = Timeout.Get(context);
         string data     = "";
         Thread.Sleep(_timeout);
         latch = new CountdownEvent(1);
         Thread td = new Thread(() =>
         {
             System.Windows.Forms.IDataObject dataBefore = System.Windows.Forms.Clipboard.GetDataObject();
             //SendKeys.SendWait("^{C}");
             KeyDown_Copy();
             System.Windows.IDataObject dataCurrent = System.Windows.Clipboard.GetDataObject();
             if (dataCurrent.GetDataPresent(System.Windows.DataFormats.Text))
             {
                 data = (string)dataCurrent.GetData(System.Windows.DataFormats.Text);
             }
             System.Windows.Clipboard.Clear();
             System.Windows.Clipboard.SetDataObject(dataBefore);
             refreshData(latch);
         });
         td.TrySetApartmentState(ApartmentState.STA);
         td.IsBackground = true;
         td.Start();
         latch.Wait();
         Result.Set(context, data);
     }
     catch (Exception e)
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw;
         }
     }
 }
Ejemplo n.º 26
0
        private void OnStatusPaste(object sender, System.EventArgs e)
        {
            System.ComponentModel.Design.MenuCommand menuCommand = (System.ComponentModel.Design.MenuCommand)sender;
            if (this.SelectedElement == null && this.SelectedRole == null)
            {
                menuCommand.Enabled = false;
                return;
            }

            try
            {
                System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject();
                if (idataObject != null)
                {
                    CopyPaste.CopyAndPasteOperations.ProcessMoveMode(idataObject);

                    if (this.SelectedElement != null)
                    {
                        menuCommand.Enabled = CopyPaste.CopyAndPasteOperations.CanExecutePaste(this.SelectedElement, idataObject);
                    }
                    else if (this.SelectedRole != null)
                    {
                        menuCommand.Enabled = CopyPaste.CopyAndPasteOperations.CanExecutePaste(this.CurrentParentElement, idataObject);
                    }
                    else
                    {
                        menuCommand.Enabled = false;
                    }
                }
            }
            catch
            {
                menuCommand.Enabled = false;
            }
            menuCommand.Visible = true;
        }
        /// <summary>
        /// Paste command can execute.
        /// </summary>
        public virtual bool OnPasteCommandCanExecute()
        {
            try
            {
                System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject();
                if (this.ViewModelStore != null)
                {
                    if (this.EventManager != null)
                    {
                        CopyAndPasteOperations.ProcessMoveMode(this.EventManager, idataObject);
                    }
                }
                else
                {
                }
                if (idataObject != null)
                {
                    return(CopyAndPasteOperations.CanExecutePaste(this.Element, idataObject));
                }
            }
            catch { }

            return(false);
        }
Ejemplo n.º 28
0
        public static void SetDropDescription(System.Windows.IDataObject dataObject, DropDescription dropDescription)
        {
            FillFormatETC("DropDescription", TYMED.TYMED_HGLOBAL, out FORMATETC formatETC);
            IntPtr num = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DropDescription)));

            try
            {
                Marshal.StructureToPtr((object)dropDescription, num, false);
                STGMEDIUM medium;
                medium.pUnkForRelease = (object)null;
                medium.tymed          = TYMED.TYMED_HGLOBAL;
                medium.unionmember    = num;
                ((System.Runtime.InteropServices.ComTypes.IDataObject)dataObject).SetData(ref formatETC, ref medium, true);
            }
            catch
            {
                Marshal.FreeHGlobal(num);
                throw;
            }
            if (dropDescription.szMessage != null)
            {
                SetBoolFormat(dataObject, "IsShowingText", true);
            }
        }
        public static IEnumerable <(string FilePath, Stream Stream)> GetFileGroupDescriptorW(WindowsIDataObject windowsDataObject)
        {
            if (!(windowsDataObject is ComIDataObject))
            {
                yield break;
            }

            var fileNames = GetFileGroupDescriptorWFileNames(windowsDataObject);

            for (var i = 0; i < fileNames.Length; i++)
            {
                Stream stream = null;
                if (!fileNames[i].IsDirectory)
                {
                    stream = GetStream(windowsDataObject, i);
                }

                yield return(fileNames[i].FileName, stream);
            }
        }
 public abstract void GetApplicationDragDropInformation(System.Windows.IDataObject data, out string[] filenames, out MemoryStream[] filestreams);