Exemple #1
0
        public static DataObject ToDataObject(this TransferDataSource data)
        {
            var retval = new DataObject ();
            foreach (var type in data.DataTypes) {
                var value = data.GetValue (type);

                if (type == TransferDataType.Text)
                    retval.SetText ((string)value);
                else if (type == TransferDataType.Uri) {
                    var uris = new StringCollection ();
                    uris.Add (((Uri)value).LocalPath);
                    retval.SetFileDropList (uris);
                } else
                    retval.SetData (type.Id, TransferDataSource.SerializeValue (value));
            }

            return retval;
        }
Exemple #2
0
		static void DragStarted(UIElement uiElt)
		{
			_isMouseDown = false;
			Mouse.Capture(uiElt);

			DataObject data = new DataObject();
			//obj.SetData(DataFormats.Text, "Text from WPF - CrossApp example");
			StringCollection files = new StringCollection();
			files.Add(@"C:\Documents and Settings\528046\Desktop\crystal_project\readme.txt");
			data.SetFileDropList(files);
			DragDropEffects supportedEffects = DragDropEffects.Move | DragDropEffects.Copy;

			// Perform DragDrop
			DragDropEffects effects = System.Windows.DragDrop.DoDragDrop(_draggedElt, data, supportedEffects);

			// Clean up
			Mouse.Capture(null);
			_draggedElt = null;
		}
        public override void Execute(object parameter)
        {
            var active = MainViewModel.ActiveDirectoryContainer.ActiveView;
            if (!active.FileSystem.IsWindowsFileSystem)
            {
                MessageBox.Show("To polecenie działa tylko w windows'owym systemie plików");
                return;
            }

            //get items to copy
            var items = MainViewModel.GetSelectedItems();
            if (items.Length == 0)
            {
                MessageBox.Show("Zaznacz obiekty do skopiowania");
                return;
            }

            //get paths to copy from items
            var paths = new StringCollection();
            foreach (IDirectoryViewItem item in items)
                paths.Add(item.FullName);

            //and here goes magic
            //set special binary data that indicates that file must be copy
            byte[] moveEffect = new byte[] { 5, 0, 0, 0 };//copy
            var dropEffect = new MemoryStream();
            dropEffect.Write(moveEffect, 0, moveEffect.Length);

            //set data object with file's paths
            DataObject data = new DataObject();
            data.SetFileDropList(paths);
            data.SetData("Preferred DropEffect", dropEffect);

            //set data object in clipboard
            Clipboard.Clear();
            //dropEffect.Close();
            Clipboard.SetDataObject(data, true);
        }
        private void tlSaveToFile_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var senderElement = sender as FrameworkElement;

            if (senderElement == null)
            {
                return;
            }

            var strData = gvData.Items.Cast <TicTacToeGame>().Select(x => x.ToString() + "," + x.ResultString.Before("(").Trim()).ToDelimitedString("\n");
            var fd      = new FileDescriptor
            {
                Name     = "KółkoKrzyżyk.txt",
                Contents = Encoding.UTF8.GetBytes(strData)
            };
            var fullPath = SaveFIleToTemp(fd);
            var dragObj  = new DataObject();

            dragObj.SetFileDropList(new StringCollection {
                fullPath
            });
            DragDrop.DoDragDrop(senderElement, dragObj, DragDropEffects.Copy);
        }
        private void contentView_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            var senderObj = sender as ScoreboardControl;

            if (senderObj == null)
            {
                // This shouldn't happen.
                return;
            }

            // Get the current mouse position
            Point mousePos = e.GetPosition(null);
            Vector diff = this.startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "starboard.xbs");

               if (File.Exists(path) == false)
               {
                   return;
               }

                var strCol = new StringCollection { path };

                var o = new DataObject(DataFormats.FileDrop, strCol);
                o.SetFileDropList(strCol);
                DragDrop.DoDragDrop(senderObj, o, DragDropEffects.Copy);
            }
        }
        void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!IsMouseCaptured)
            {
                dragStart = e.GetPosition(this);
                ShellObjectCollection collection = new ShellObjectCollection();
                System.Collections.IList list =
                    (DropDataList.SelectedItems.Count > 0) ?
                        DropDataList.SelectedItems : DropDataList.Items;

                foreach (ShellObject shellObject in list)
                {
                    collection.Add(shellObject);
                }

                if (collection.Count > 0)
                {
                    // This builds a DataObject from a "Shell IDList Array" formatted memory stream.
                    // This allows drag/clipboard operations with non-file based ShellObjects (i.e., 
                    // control panel, libraries, search query results)
                    dataObject = new DataObject(
                        "Shell IDList Array",
                        collection.BuildShellIDList());

                    // Also build a file drop list
                    System.Collections.Specialized.StringCollection paths = new System.Collections.Specialized.StringCollection();
                    foreach (ShellObject shellObject in collection)
                    {
                        if (shellObject.IsFileSystemObject)
                        {
                            paths.Add(shellObject.ParsingName);
                        }
                    }
                    if (paths.Count > 0)
                        dataObject.SetFileDropList(paths);
                }
            }
        }
Exemple #7
0
        private void treeDragStarted(UIElement uiElt)
        {
            _isMouseDown = false;
            Mouse.Capture(uiElt);

            DataObject data = new DataObject();

            if (tvSearchResult.SelectedItem is FormattedGrepLine)
            {
                FormattedGrepLine selectedNode = (FormattedGrepLine)tvSearchResult.SelectedItem;
                data.SetData(DataFormats.Text, selectedNode.GrepLine.LineText);
            }
            else if (tvSearchResult.SelectedItem is FormattedGrepResult)
            {
                FormattedGrepResult result = (FormattedGrepResult)tvSearchResult.SelectedItem;
                StringCollection files = new StringCollection();
                files.Add(result.GrepResult.FileNameReal);
                data.SetFileDropList(files);
            }


            DragDropEffects supportedEffects = DragDropEffects.Move | DragDropEffects.Copy;
            // Perform DragDrop
            DragDropEffects effects = System.Windows.DragDrop.DoDragDrop(_draggedElt, data, supportedEffects);

            // Clean up
            Mouse.Capture(null);
            _draggedElt = null;
        }
        public void CopyOnClipboard()
        {
            try
            {
                if (!isEmpty)
                {
                    if (IsAudio)
                    {
                        Clipboard.SetAudio(Audio);
                    }
                    else if (IsText)
                    {
                        Clipboard.SetText(Text);
                    }
                    else if (IsFile)
                    {

                        //Impostare il l'effetto taglia per rimuovere dai file temporanei
                        MemoryStream dropEffect = new MemoryStream();
                        dropEffect.Write(CUT_EFFECT, 0, CUT_EFFECT.Length);
                        DataObject data = new DataObject();
                        data.SetFileDropList(FileDropList);
                        data.SetData("Preferred DropEffect", dropEffect);
                        Clipboard.Clear();
                        Clipboard.SetDataObject(data, true);

                    }
                    else
                    {

                        MemoryStream ms = new MemoryStream(Image);
                        ms.Position = 0;
                        BitmapImage image = new BitmapImage();
                        image.BeginInit();
                        image.StreamSource = ms;
                        image.EndInit();
                        Clipboard.SetImage(image);
                    }
                }
            }
            catch (Exception ex) { Trace.TraceError("Exception in CopyOnClipboard()", ex.StackTrace); }
        }
Exemple #9
0
		public static DataObject ToDataObject (this TransferDataSource data)
		{
			var retval = new DataObject ();
			foreach (var type in data.DataTypes) {
				var value = data.GetValue (type);

				if (type == TransferDataType.Text) {
					retval.SetText ((string)value);
				}
				else if (type == TransferDataType.Uri) {
					Uri uri = (Uri)value;
					if (uri.IsFile) {
						var uris = new StringCollection ();
						uris.Add (uri.LocalPath);
						retval.SetFileDropList (uris);
					} else {
						string strOrig = uri.ToString();
						string str = strOrig + ((char)0);
						char[] chars = str.ToArray();
						byte[] bytes = Encoding.UTF8.GetBytes(chars, 0, chars.Length);
						MemoryStream stream = new MemoryStream(bytes);
						retval.SetData ("UniformResourceLocator", stream);
					}
				} else
					retval.SetData (type.Id, TransferDataSource.SerializeValue (value));
			}

			string anyUri = data.LinkUri != null ? data.LinkUri.ToString() : null;
			string anyPath = data.LinkTmpPath;
			if (anyUri != null && anyPath != null) {
				// write tmp file to disk with /path/to/tmp/Page-Title.url
				string urlContents = "[InternetShortcut]\nURL=" + anyUri;
				File.WriteAllText(anyPath, urlContents);
				StringCollection strCollect = new StringCollection();
				strCollect.Add(anyPath);
				retval.SetFileDropList(strCollect);
			}

			return retval;
		}
Exemple #10
0
		public void SetSystem()
		{
			var dataObj = new DataObject();

			dataObj.SetText(Text, TextDataFormat.UnicodeText);
			dataObj.SetData(typeof(NELocalClipboard), PID);

			if (IsCut.HasValue)
			{
				var dropList = new StringCollection();
				dropList.AddRange(Strings.ToArray());
				dataObj.SetFileDropList(dropList);
				dataObj.SetData("Preferred DropEffect", new MemoryStream(BitConverter.GetBytes((int)(IsCut == true ? DragDropEffects.Move : DragDropEffects.Copy | DragDropEffects.Link))));
			}

			if (Image != null)
				dataObj.SetImage(Image);

			Clipboard.SetDataObject(dataObj, true);
		}
        private void ClipboardReceived(object sender, RunWorkerCompletedEventArgs eventArgs)
        {
            if (!eventArgs.Cancelled && eventArgs.Error == null)
            {
                ArrayList data = (ArrayList)eventArgs.Result;
                if (data != null)
                {
                    DataObject dataObj = new DataObject();
                    Console.WriteLine("Count: " + data.Count);
                    for (int i = 0; i < data.Count; i++)
                    {
                        string format = (string)data[i++];
                        Console.WriteLine(format);
                        dataObj.SetData(format, data[i]);
                    }

                    if (dataObj.ContainsFileDropList())
                    {
                        StringCollection files = dataObj.GetFileDropList();
                        dataObj = new DataObject();
                        StringCollection adjusted = new StringCollection();
                        foreach (string f in files)
                        {
                            if (!f.StartsWith("\\"))
                            {
                                string toadd = "\\\\" + Ip + "\\" + f.Replace(":", "");
                                Console.WriteLine(toadd);
                                adjusted.Add(toadd);
                            }
                            else
                            {
                                adjusted.Add(f);
                            }
                        }
                        dataObj.SetFileDropList(adjusted);
                    }
                    Clipboard.SetDataObject(dataObj);

                }
            }
        }
Exemple #12
0
        protected override void OnMouseMove(MouseEventArgs args)
        {
            if(args.LeftButton == MouseButtonState.Pressed
                && clickedIn) {
                Point cursorAt = args.GetPosition(this);

                if(Math.Abs(cursorAt.X - clickStarted.X) > 5 ||
                    Math.Abs(cursorAt.Y - clickStarted.Y) > 5) {
                    DataObject dragData = new DataObject(
                        typeof(Node),
                        Node);
                    string root = System.IO.Path.GetDirectoryName(
                        Node.Project.SavePath);

                    if(Node is File)
                        dragData.SetFileDropList(new StringCollection {
                                Path.Combine(root, (DataContext as File).RealPath)
                            });
                    else if(Node is OtherFile)
                        dragData.SetFileDropList(new StringCollection {
                                Path.Combine(root, (DataContext as OtherFile).RealPath)
                            });
                    else if(Node is ExternalFile)
                        dragData.SetFileDropList(new StringCollection {
                                (DataContext as ExternalFile).RealPath
                            });
                    else if(Node is ExternalFolder)
                        dragData.SetFileDropList(new StringCollection {
                                (DataContext as ExternalFolder).RealPath
                            });

                    DragDrop.DoDragDrop(this, DataContext, DragDropEffects.Move | DragDropEffects.Link);

                    args.Handled = true;
                }
            }
            else {
                clickedIn = false;
                base.OnMouseMove(args);
            }
        }
        public void SetClipboard(string Ip, Object obj)
        {
            try
            {
                ArrayList data = (ArrayList)obj;
                if (data != null)
                {
                    DataObject dataObj = new DataObject();
                    Console.WriteLine("Count: " + data.Count);
                    for (int i = 0; i < data.Count; i++)
                    {
                        string format = (string)data[i++];
                        Console.WriteLine(format);
                        dataObj.SetData(format, data[i]);
                    }
                    if (dataObj.ContainsFileDropList())
                    {
                        StringCollection files = dataObj.GetFileDropList();
                        dataObj = new DataObject();
                        StringCollection adjusted = new StringCollection();
                        foreach (string f in files)
                        {
                            if (!f.StartsWith("\\"))
                            {
                                string toadd = "\\\\" + Ip + "\\" + f.Replace(":", "");
                                Console.WriteLine(toadd);
                                adjusted.Add(toadd);
                            }
                            else
                            {
                                adjusted.Add(f);
                            }
                        }
                        dataObj.SetFileDropList(adjusted);
                    }
                    Clipboard.SetDataObject(dataObj);

                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }