Exemplo n.º 1
0
 private void btnCopy_Click(object sender, RoutedEventArgs e)
 {
     var data = new DataObject();
     data.SetText(RTF, TextDataFormat.Rtf);
     data.SetText(rtf.Text, TextDataFormat.Text);
     Clipboard.SetDataObject(data);
 }
        public static void ToClipboard(this List<FrameworkElement> elements)
        {
            var builderTabbedText = new StringBuilder();
            var builderCsvText = new StringBuilder();
            foreach (var element in elements)
            {
                string tabbedText = element.DataContext.ToString();
                string csvText = element.DataContext.ToString();

                builderTabbedText.AppendLine(tabbedText);
                builderCsvText.AppendLine(csvText);
            }

            // data object to hold our different formats representing the element
            var dataObject = new DataObject();

            dataObject.SetText(builderTabbedText.ToString());

            // Convert the CSV text to a UTF-8 byte stream before adding it to the container object.
            var bytes = Encoding.UTF8.GetBytes(builderCsvText.ToString());
            var stream = new System.IO.MemoryStream(bytes);
            dataObject.SetData(DataFormats.CommaSeparatedValue, stream);

            // lets start with the text representation
            // to make is easy we will just assume the object set as the DataContext has the ToString method overrideen and we use that as the text
            dataObject.SetData(DataFormats.CommaSeparatedValue, stream);

            // now place our object in the clipboard
            Clipboard.SetDataObject(dataObject, true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the clipboard data for the specified table.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <remarks>
        /// This method sets the TEXT (tab delimited) and CSV data. Like in Excel the CSV delimiter is either comma or semicolon, depending on the current culture.
        /// </remarks>
        public static void SetClipboardData(this IList<IList<string>> table)
        {
            if (table == null)
            {
                Clipboard.Clear();
                return;
            }

            var textString = table.ToTextString();
            var csvString = table.ToCsvString();

            var dataObject = new DataObject();

            dataObject.SetText(textString);
            dataObject.SetText(csvString, TextDataFormat.CommaSeparatedValue);

            Clipboard.SetDataObject(dataObject);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Places the provided data on the clipboard overriding what is currently in the clipboard.
        /// </summary>
        /// <param name="isSingleLine">Indicates whether a single line was automatically cut/copied by
        /// the editor. If <c>true</c> the clipboard contents are tagged with a special moniker.</param>
        public static void SetClipboardData(string html, string rtf, string unicode, bool isSingleLine, bool isBoxCopy)
        {
            DataObject data = new DataObject();

            if (unicode != null)
            {
                data.SetText(unicode, TextDataFormat.UnicodeText);
                data.SetText(unicode, TextDataFormat.Text);
            }

            if (html != null)
            {
                data.SetText(GetHtmlForClipboard(html), TextDataFormat.Html);
            }

            if (rtf != null)
            {
                data.SetText(rtf, TextDataFormat.Rtf);
            }

            if (isSingleLine)
            {
                data.SetData(ClipboardLineBasedCutCopyTag, new object());
            }

            if (isBoxCopy)
            {
                data.SetData(BoxSelectionCutCopyTag, new object());
            }

            try
            {
                // Use delay rendering to set the data in the clipboard to prevent 2 clipboard change
                // notifications to clipboard change listeners.
                Clipboard.SetDataObject(data, false);
            }
            catch (System.Runtime.InteropServices.ExternalException)
            {
            }
        }
Exemplo n.º 5
0
 static NumberTextBox()
 {
     EventManager.RegisterClassHandler(
         typeof(NumberTextBox),
         DataObject.PastingEvent,
         (DataObjectPastingEventHandler)((sender, e) =>
         {
             if (!IsDataValid(e.DataObject))
             {
                 DataObject data = new DataObject();
                 data.SetText(String.Empty);
                 e.DataObject = data;
                 e.Handled = false;
             }
         }));
 }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
		/// <summary>
		/// Sets the TextDataFormat.Html on the data object to the specified html fragment.
		/// This helper methods takes care of creating the necessary CF_HTML header.
		/// </summary>
		public static void SetHtml(DataObject dataObject, string htmlFragment)
		{
			if (dataObject == null)
				throw new ArgumentNullException("dataObject");
			if (htmlFragment == null)
				throw new ArgumentNullException("htmlFragment");
			
			string htmlStart = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" + Environment.NewLine
				+ "<HTML>" + Environment.NewLine
				+ "<BODY>" + Environment.NewLine
				+ "<!--StartFragment-->" + Environment.NewLine;
			string htmlEnd = "<!--EndFragment-->" + Environment.NewLine + "</BODY>" + Environment.NewLine + "</HTML>" + Environment.NewLine;
			string dummyHeader = BuildHeader(0, 0, 0, 0);
			// the offsets are stored as UTF-8 bytes (see CF_HTML documentation)
			int startHTML = dummyHeader.Length;
			int startFragment = startHTML + htmlStart.Length;
			int endFragment = startFragment + Encoding.UTF8.GetByteCount(htmlFragment);
			int endHTML = endFragment + htmlEnd.Length;
			string cf_html = BuildHeader(startHTML, endHTML, startFragment, endFragment) + htmlStart + htmlFragment + htmlEnd;
			Debug.WriteLine(cf_html);
			dataObject.SetText(cf_html, TextDataFormat.Html);
		}
        public static IDataObject GetDataObject()
        {
            var dataObject = new DataObject();

            // Beside copying and pasting UnicodeText to/from pasteboard
            // editor inserts booleans like "VisualStudioEditorOperationsLineCutCopyClipboardTag"
            // which allows editor to know whole line was copied into pasteboard so on paste
            // it inserts line into new line, so we enumerate over all types and if length == 1
            // we just assume it's boolean we set in method above
            foreach (var type in pasteboard.Types)
            {
                if (type == DataFormats.UnicodeText)
                {
                    dataObject.SetText(pasteboard.GetStringForType(type));
                    continue;
                }
                var data = pasteboard.GetDataForType(type);
                if (data != null && data.Length == 1)
                {
                    dataObject.SetData(type, data: data [0] != 0);
                }
            }
            return(dataObject);
        }
Exemplo n.º 9
0
 protected override void InitializeDataObject(DataObject dataObj)
 {
     var s = Encoding.UTF8.GetString(ReadByteArray());
     dataObj.SetText(s);
 }
Exemplo n.º 10
0
 public override CopyDataObject Copy(bool removeSelection)
 {
     CopyDataObject temp = base.Copy(removeSelection);
     DataObject data = new DataObject();
     data.SetImage(temp.Image);
     XElement rootElement = new XElement(this.GetType().Name);
     rootElement.Add(new XElement("SessionId", sessionString));
     rootElement.Add(textManager.Serialize());
     rootElement.Add(new XElement("payload", temp.XElement));
     MathEditorData med = new MathEditorData { XmlString = rootElement.ToString() };
     data.SetData(med);
     //data.SetText(GetSelectedText());
     if (temp.Text != null)
     {
         data.SetText(temp.Text);
     }
     Clipboard.SetDataObject(data, true);
     if (removeSelection)
     {
         DeSelect();
         AdjustCarets();
     }
     return temp;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Copies the selected cells.
        /// </summary>
        /// <param name="separator">The separator.</param>
        public void Copy(string separator)
        {
            var text = this.SelectionToString(separator);
            var array = this.SelectionToArray();

            var dataObject = new DataObject();
            dataObject.SetText(text);

            if (AreAllElementsSerializable(array))
            {
                try
                {
                    dataObject.SetData(typeof(DataGrid), array);
                }
                catch (Exception e)
                {
                    // nonserializable values?
                    Debug.WriteLine(e);
                }
            }

            Clipboard.SetDataObject(dataObject);
        }
        bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y)
        {
            var dataObject = new DataObject();

            dataObject.SetText(dragData.FragmentText, TextDataFormat.Text);
            dataObject.SetText(dragData.FragmentText, TextDataFormat.UnicodeText);
            dataObject.SetText(dragData.FragmentHtml, TextDataFormat.Html);

            // TODO: The following code block *should* handle images, but GetFileContents is
            // not yet implemented.
            //if (dragData.IsFile)
            //{
            //    var bmi = new BitmapImage();
            //    bmi.BeginInit();
            //    bmi.StreamSource = dragData.GetFileContents();
            //    bmi.EndInit();
            //    dataObject.SetImage(bmi);
            //}

            UiThreadRunAsync(delegate
            {
                var results = DragDrop.DoDragDrop(this, dataObject, GetDragEffects(mask));
                managedCefBrowserAdapter.OnDragSourceEndedAt(0, 0, GetDragOperationsMask(results));
                managedCefBrowserAdapter.OnDragSourceSystemDragEnded();
            });

            return true;
        }
Exemplo n.º 13
0
        private static void SetClipboard(string dataType, string data)
        {
            DataObject copyBuffer = new DataObject();
            copyBuffer.SetData(dataType, "Y");
            copyBuffer.SetText(data);

            try
            {
                Clipboard.SetDataObject(copyBuffer);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                System.Threading.Thread.Sleep(0);
                try
                {
                    Clipboard.SetDataObject(copyBuffer);
                }
                catch (System.Runtime.InteropServices.COMException e)
                {
                    ConfigManager.LogManager.LogError("Error writing to clipboard.", e);
                }
            }
        }
Exemplo n.º 14
0
		static bool CopyWholeLine(TextArea textArea, DocumentLine line)
		{
			ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
			string text = textArea.Document.GetText(wholeLine);
			// Ensure we use the appropriate newline sequence for the OS
			text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
			DataObject data = new DataObject();
			if (ConfirmDataFormat(textArea, data, DataFormats.UnicodeText))
				data.SetText(text);
			
			// Also copy text in HTML format to clipboard - good for pasting text into Word
			// or to the SharpDevelop forums.
			if (ConfirmDataFormat(textArea, data, DataFormats.Html)) {
				IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
				HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options)));
			}
			
			if (ConfirmDataFormat(textArea, data, LineSelectedType)) {
				MemoryStream lineSelected = new MemoryStream(1);
				lineSelected.WriteByte(1);
				data.SetData(LineSelectedType, lineSelected, false);
			}
			
			var copyingEventArgs = new DataObjectCopyingEventArgs(data, false);
			textArea.RaiseEvent(copyingEventArgs);
			if (copyingEventArgs.CommandCancelled)
				return false;
			
			try {
				Clipboard.SetDataObject(data, true);
			} catch (ExternalException) {
				// Apparently this exception sometimes happens randomly.
				// The MS controls just ignore it, so we'll do the same.
				return false;
			}
			textArea.OnTextCopied(new TextEventArgs(text));
			return true;
		}
            private void CutOrDelete(IEnumerable<SnapshotSpan> projectionSpans, bool isCut)
            {
                Debug.Assert(CurrentLanguageBuffer != null);

                StringBuilder deletedText = null;

                // split into multiple deletes that only affect the language/input buffer:
                ITextBuffer affectedBuffer = (ReadingStandardInput) ? StandardInputBuffer : CurrentLanguageBuffer;
                using (var edit = affectedBuffer.CreateEdit())
                {
                    foreach (var projectionSpan in projectionSpans)
                    {
                        var spans = TextView.BufferGraph.MapDownToBuffer(projectionSpan, SpanTrackingMode.EdgeInclusive, affectedBuffer);
                        foreach (var span in spans)
                        {
                            if (isCut)
                            {
                                if (deletedText == null)
                                {
                                    deletedText = new StringBuilder();
                                }

                                deletedText.Append(span.GetText());
                            }

                            edit.Delete(span);
                        }
                    }

                    edit.Apply();
                }

                // copy the deleted text to the clipboard:
                if (deletedText != null)
                {
                    var data = new DataObject();
                    if (TextView.Selection.Mode == TextSelectionMode.Box)
                    {
                        data.SetData(BoxSelectionCutCopyTag, new object());
                    }

                    data.SetText(deletedText.ToString());
                    _window.InteractiveWindowClipboard.SetDataObject(data, true);
                }
            }
Exemplo n.º 16
0
 public override void CopyImpl()
 {
     if (rtf != null)
     {
         var dataObject = new DataObject();
         dataObject.SetData(DataFormats.Rtf, rtf);
         dataObject.SetText(text);
         Clipboard.SetDataObject(dataObject);
     }
     else
     {
         System.Windows.Clipboard.SetText(text);
     }
 }
Exemplo n.º 17
0
		bool CopyToClipboard(string text, string htmlText, bool isFullLineData, bool isBoxData) {
			try {
				var dataObj = new DataObject();
				dataObj.SetText(text);
				if (isFullLineData)
					dataObj.SetData(VS_COPY_FULL_LINE_DATA_FORMAT, true);
				if (isBoxData)
					dataObj.SetData(VS_COPY_BOX_DATA_FORMAT, true);
				if (htmlText != null)
					dataObj.SetData(DataFormats.Html, htmlText);
				Clipboard.SetDataObject(dataObj);
				return true;
			}
			catch (ExternalException) {
				return false;
			}
		}
Exemplo n.º 18
0
		/// <summary>
		/// Creates a data object containing the selection's text.
		/// </summary>
		public virtual DataObject CreateDataObject(TextArea textArea)
		{
			DataObject data = new DataObject();
			
			// Ensure we use the appropriate newline sequence for the OS
			string text = TextUtilities.NormalizeNewLines(GetText(), Environment.NewLine);
			
			// Enable drag/drop to Word, Notepad++ and others
			if (EditingCommandHandler.ConfirmDataFormat(textArea, data, DataFormats.UnicodeText)) {
				data.SetText(text);
			}
			
			// Enable drag/drop to SciTe:
			// We cannot use SetText, thus we need to use typeof(string).FullName as data format.
			// new DataObject(object) calls SetData(object), which in turn calls SetData(Type, data),
			// which then uses Type.FullName as format.
			// We immitate that behavior here as well:
			if (EditingCommandHandler.ConfirmDataFormat(textArea, data, typeof(string).FullName)) {
				data.SetData(typeof(string).FullName, text);
			}
			
			// Also copy text in HTML format to clipboard - good for pasting text into Word
			// or to the SharpDevelop forums.
			if (EditingCommandHandler.ConfirmDataFormat(textArea, data, DataFormats.Html)) {
				HtmlClipboard.SetHtml(data, CreateHtmlFragment(new HtmlOptions(textArea.Options)));
			}
			return data;
		}
Exemplo n.º 19
0
        private static void OnPasteMultiple(object sender, ExecutedRoutedEventArgs args)
        {
            var textEditor = (TextEditor)sender;
            var textArea = textEditor.TextArea;

            if (textArea?.Document == null)
                return;

            var completionWindow = new CompletionWindow(textArea);

            // ----- Create completion list.
            var completionList = completionWindow.CompletionList;
            var completionData = completionList.CompletionData;
            var stringBuilder = new StringBuilder();
            foreach (var text in ClipboardRing.GetEntries())
            {
                // Replace special characters for display.
                stringBuilder.Clear();
                stringBuilder.Append(text);
                stringBuilder.Replace("\n", "\\n");
                stringBuilder.Replace("\r", "\\r");
                stringBuilder.Replace("\t", "\\t");

                // Use TextBlock for TextTrimming.
                var textBlock = new TextBlock
                {
                    Text = stringBuilder.ToString(),
                    TextTrimming = TextTrimming.CharacterEllipsis,
                    MaxWidth = 135
                };
                completionData.Add(new CompletionData(text, text, null, textBlock));
            }

            // ----- Show completion window.
            completionList.SelectedItem = completionData[0];
            completionWindow.Show();

            // ----- Handle InsertionRequested event.
            completionList.InsertionRequested += (s, e) =>
                                                 {
                                                     var ta = completionWindow.TextArea;
                                                     var cl = completionWindow.CompletionList;
                                                     var text = cl.SelectedItem.Text;

                                                     // Copy text into clipboard.
                                                     var data = new DataObject();
                                                     if (EditingCommandHandler.ConfirmDataFormat(ta, data, DataFormats.UnicodeText))
                                                         data.SetText(text);

                                                     var copyingEventArgs = new DataObjectCopyingEventArgs(data, false);
                                                     ta.RaiseEvent(copyingEventArgs);
                                                     if (copyingEventArgs.CommandCancelled)
                                                         return;

                                                     try
                                                     {
                                                         Clipboard.SetDataObject(data, true);
                                                     }
                                                     catch (ExternalException)
                                                     {
                                                     }

                                                     ClipboardRing.Add(text);
                                                 };
        }
Exemplo n.º 20
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 CopySelectedItemsToClipboard()
        {
            var dataObject = new DataObject();

            var selectedItemsText = string.Join(
                                        Environment.NewLine,
                                        from x in CurrentArgumentList.SelectedItems.Cast<CmdArgItem>() select x.Command);
            dataObject.SetText(selectedItemsText);

            var selectedItemsJson = JsonConvert.SerializeObject(
                from x in CurrentArgumentList.SelectedItems.Cast<CmdArgItem>()
                select new CmdArgClipboardItem { Enabled = x.Enabled, Command = x.Command });
            dataObject.SetData(CmdArgsPackage.ClipboardCmdItemFormat, selectedItemsJson);

            Clipboard.SetDataObject(dataObject);
        }
Exemplo n.º 22
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;
		}
Exemplo n.º 23
0
        public void CopySelection() {
            if (VisualComponent == null) {
                return;
            }

            if (!HasSelectedEntries) {
                _editorOperations.CopySelection();
                return;
            }

            var selectedEntries = GetSelectedHistoryEntrySpans();
            var normalizedCollection = new NormalizedSnapshotSpanCollection(selectedEntries);
            var text = GetSelectedText();
            var rtf = _rtfBuilderService.GenerateRtf(normalizedCollection, VisualComponent.TextView);
            var data = new DataObject();
            data.SetText(text, TextDataFormat.Text);
            data.SetText(text, TextDataFormat.UnicodeText);
            data.SetText(rtf, TextDataFormat.Rtf);
            data.SetData(DataFormats.StringFormat, text);
            Clipboard.SetDataObject(data, false);
        }
        public IEnumerable<IResult> CopySelectedSlotCode()
        {
            yield return new DelegateResult(() =>
            {
                if (this.SelectedSlot == null ||
                    (this.SelectedSlot.BackpackSlot is IPackable) == false)
                {
                    if (MyClipboard.SetText("") != MyClipboard.Result.Success)
                    {
                        MessageBox.Show("Clipboard failure.",
                                        "Error",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                    return;
                }

                // just a hack until I add a way to override the unique ID in Encode()
                var copy = (IPackable)this.SelectedSlot.BackpackSlot.Clone();
                copy.UniqueId = 0;

                var data = BackpackDataHelper.Encode(copy);
                var sb = new StringBuilder();
                sb.Append("BL2(");
                sb.Append(Convert.ToBase64String(data, Base64FormattingOptions.None));
                sb.Append(")");

                /*
                if (MyClipboard.SetText(sb.ToString()) != MyClipboard.Result.Success)
                {
                    MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                */

                var dobj = new DataObject();
                dobj.SetText(sb.ToString());
                if (MyClipboard.SetDataObject(dobj, false) != MyClipboard.Result.Success)
                {
                    MessageBox.Show("Clipboard failure.",
                                    "Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            });
        }
Exemplo n.º 25
0
        protected override void InitializeDataObject(DataObject dataObj)
        {
            var sb = new StringBuilder();

            ulong offs = start;
            for (;;) {
                int b = ReadByte(offs);
                if (b < 0)
                    sb.Append("??");
                else
                    sb.Append(string.Format(hexByteFormatString, (byte)b));

                if (offs++ >= end)
                    break;
            }

            dataObj.SetText(sb.ToString());
        }
Exemplo n.º 26
0
        private void dtGridActors_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)// && !IsDragging)
            {

                 int i = dtGridActors.SelectedIndex;
                 if (i < 0) return;
                 AtomDTOData currAtomData = (AtomDTOData)dtGridActors.Items[i];
                 Point position = e.GetPosition(null);

                 if (Math.Abs(position.X - _startPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
                    Math.Abs(position.Y - _startPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
                 {
                     _allOpsCursor = null;
                     GiveFeedbackEventHandler handler = new GiveFeedbackEventHandler(dtGridActors_GiveFeedback);
                     this.dtGridActors.GiveFeedback += handler;

                     IsDragging = true;
                     try
                     {
                         DataObject data = new DataObject(typeof(FormationTree), currAtomData.atom);
                         data.SetText("Actor");
                         DragDropEffects de = DragDrop.DoDragDrop(dtGridActors, data, DragDropEffects.Move);
                     }
                     catch (Exception ex)
                     {
                         //this.treeViewForce.GiveFeedback -= handler;
                         //this.treeViewForce.GiveFeedback += handler;
                     }
                     this.dtGridActors.GiveFeedback -= handler;
                     IsDragging = false;
                 }
            }
        }
Exemplo n.º 27
0
        protected override void InitializeDataObject(DataObject dataObj)
        {
            var sb = new StringBuilder();

            sb.Append(allocStringStart);
            sb.Append(eol);
            ulong offs = start;
            for (int i = 0; ; i++) {
                if (i >= BYTES_PER_LINE) {
                    i = 0;
                    sb.Append(eol);
                }
                if (i == 0)
                    sb.Append('\t');
                else
                    sb.Append(' ');

                int b = ReadByte(offs);
                if (b < 0)
                    sb.Append(unknownHex);
                else
                    sb.Append(string.Format(hexFormat, (byte)b));

                if (offs++ >= end)
                    break;
                sb.Append(',');
            }
            sb.Append(eol);
            sb.Append(allocStringEnd);
            sb.AppendLine();

            dataObj.SetText(sb.ToString());
        }
        /// <summary>
        /// Allow drag and drop of the items.  The items are converted to their text form to allow dragging
        /// and dropping in topic files.  They can also be dragged and dropped as topics within the tree view
        /// to rearrange the topics.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void tvContent_MouseMove(object sender, MouseEventArgs e)
        {
            DataObject data = new DataObject();
            TocEntry currentTopic = this.CurrentTopic;
            Point currentPosition = e.GetPosition(null);
            string textToCopy;

            if(e.LeftButton == MouseButtonState.Pressed &&
              (Math.Abs(currentPosition.X - startDragPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
              Math.Abs(currentPosition.Y - startDragPoint.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                // Make sure we are actually within a tree view item
                var item = (e.OriginalSource as FrameworkElement).ParentElementOfType<TreeViewItem>();

                // Make sure the items match to prevent inadvertent drag and drops if the mouse is clicked and
                // dragged outside of an item into an item.
                if(item != null && (item.Header as TocEntry) == currentTopic)
                {
                    textToCopy = this.GetTextToCopy();

                    if(textToCopy != null)
                        data.SetText(textToCopy);

                    data.SetData(typeof(TocEntry), currentTopic);

                    DragDrop.DoDragDrop(tvContent, data, DragDropEffects.All);

                    // Make sure the drag source is selected when done.  This keeps the item selected to make
                    // it easier to go back to the same location when dragging topics into a file editor to
                    // create a link.
                    currentTopic.IsSelected = true;
                }
                else
                    startDragPoint = currentPosition;
            }
        }
Exemplo n.º 29
0
        void CopyText(DataObject dataObj, List<HexLine> lines)
        {
            var sb = new StringBuilder(lines.Count == 0 ? 0 : lines.Count * (lines[0].Text.Length + Environment.NewLine.Length));

            foreach (var line in lines) {
                sb.Append(line.Text);
                sb.AppendLine();
            }

            dataObj.SetText(sb.ToString());
        }
Exemplo n.º 30
0
        public virtual void CsvPaste() {
            using (var interactive = Prepare()) {
                interactive.Invoke(() => {
                    var dataObject = new DataObject();
                    dataObject.SetText("fob");
                    var stream = new MemoryStream(UTF8Encoding.Default.GetBytes("\"abc,\",\"fob\",\"\"\"fob,\"\"\",oar,baz\"x\"oar,\"baz,\"\"x,\"\"oar\",,    ,oar,\",\"\",\"\"\",baz\"x\"'oar,\"baz\"\"x\"\"',oar\",\"\"\"\",\"\"\",\"\"\",\",\",\\\r\n1,2,3,4,9,10,11,12,13,19,33,22,,,,,,\r\n4,5,6,5,2,3,4,3,1,20,44,33,,,,,,\r\n7,8,9,6,3,4,0,9,4,33,55,33,,,,,,"));
                    dataObject.SetData(DataFormats.CommaSeparatedValue, stream);
                    Clipboard.SetDataObject(dataObject, true);
                });

                interactive.App.ExecuteCommand("Edit.Paste");

                interactive.WaitForText(
                    ">[",
                    ".  ['abc,', '\"fob\"', '\"fob,\"', 'oar', 'baz\"x\"oar', 'baz,\"x,\"oar', None, None, 'oar', ',\",\"', 'baz\"x\"\\'oar', 'baz\"x\"\\',oar', '\"\"\"\"', '\",\"', ',', '\\\\'],",
                    ".  [1, 2, 3, 4, 9, 10, 11, 12, 13, 19, 33, 22, None, None, None, None, None, None],",
                    ".  [4, 5, 6, 5, 2, 3, 4, 3, 1, 20, 44, 33, None, None, None, None, None, None],",
                    ".  [7, 8, 9, 6, 3, 4, 0, 9, 4, 33, 55, 33, None, None, None, None, None, None],",
                    ".]",
                    "."
                );
            }
        }
        public void DoCopyConversationTextFormatted_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            DataObject selectionData = new DataObject();

            string richTextFormat = System.Windows.DataFormats.Rtf;
            MemoryStream richTextStream = new MemoryStream();
            ConversationTextBox.Selection.Save(richTextStream, richTextFormat);
            selectionData.SetData(richTextFormat, richTextStream);

            selectionData.SetText(ConversationTextBox.Selection.Text);

            Clipboard.SetDataObject(selectionData, true);
        }