Esempio n. 1
0
        public void TestText()
        {
            DataObject d = new DataObject();

            d.SetText("yo");

            Assert.AreEqual(false, d.ContainsAudio(), "A1");
            Assert.AreEqual(false, d.ContainsFileDropList(), "A2");
            Assert.AreEqual(false, d.ContainsImage(), "A3");
            Assert.AreEqual(true, d.ContainsText(), "A4");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A5");

            Assert.AreEqual("yo", d.GetText(), "A6");
            Assert.AreEqual("yo", d.GetData(DataFormats.StringFormat), "A6-1");

            d.SetText("<html></html>", TextDataFormat.Html);
            Assert.AreEqual(true, d.ContainsText(), "A7");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A8");
            Assert.AreEqual(true, d.ContainsText(TextDataFormat.Html), "A9");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.Rtf), "A10");
            Assert.AreEqual(true, d.ContainsText(TextDataFormat.Text), "A11");
            Assert.AreEqual(true, d.ContainsText(TextDataFormat.UnicodeText), "A12");

            // directly put a string
            d.SetData("yo");

            Assert.AreEqual(true, d.ContainsText(TextDataFormat.Text), "A13");
            Assert.AreEqual(true, d.ContainsText(TextDataFormat.UnicodeText), "A14");

            Assert.AreEqual("yo", d.GetData(DataFormats.StringFormat), "A15");
            Assert.AreEqual("yo", d.GetData(DataFormats.Text), "A16");
            Assert.AreEqual("yo", d.GetData(DataFormats.UnicodeText), "A17");
        }
Esempio n. 2
0
 public override bool ContainsText()
 {
     if (FData != null)
     {
         return(FData.ContainsText());
     }
     return(base.ContainsText());
 }
Esempio n. 3
0
        public void TestImage()
        {
            DataObject d = new DataObject();
            Image      i = new Bitmap(16, 16);

            d.SetImage(i);

            Assert.AreEqual(false, d.ContainsAudio(), "A1");
            Assert.AreEqual(false, d.ContainsFileDropList(), "A2");
            Assert.AreEqual(true, d.ContainsImage(), "A3");
            Assert.AreEqual(false, d.ContainsText(), "A4");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A5");

            Assert.AreSame(i, d.GetImage(), "A6");
        }
Esempio n. 4
0
        // Private members

        private static string GetClipboardTextOrHtml(DataObject clipboardData)
        {
            string result = string.Empty;

            if (clipboardData.ContainsText(TextDataFormat.Html))
            {
                result = clipboardData.GetText(TextDataFormat.Html);
            }
            else if (clipboardData.ContainsText(TextDataFormat.Html))
            {
                result = clipboardData.GetText(TextDataFormat.Text);
            }

            return(result);
        }
Esempio n. 5
0
        public override bool IsApplicable(EditableView pnlView)
        {
            DataObject data = (DataObject)Clipboard.GetDataObject();

            if (data != null)
            {
                if (data.GetDataPresent("Splash shapes", false) || data.ContainsImage() || ContainsFileImage(data))
                {
                    return(true);
                }
#if SAW && !SPLASH
                if (data.GetDataPresent("Splash scripts", false))
                {
                    return(CopyScripts.PasteApplicable(data));
                }
                if (data.GetDataPresent("Splash presentation", false))
                {
                    return(CopyPresentation.PasteApplicable(data));
                }
#endif
                if (data.ContainsText())
                {
                    if (CurrentPage.SelectedCount == 1 && CurrentPage.SelectedShapes[0].SupportsTextLabel)
                    {
                        return(true);
                    }
                    Shape shape = pnlView.TypingShape();
                    if (shape != null && shape.SupportsTextLabel)
                    {
                        return(true);                        // Second condition is needed because some "typing" shapes only actually do custom processing of certain keys
                    }
                }
            }
            return(false);
        }
Esempio n. 6
0
        public void TestAudio()
        {
            DataObject d = new DataObject();

            byte[] b = new byte[] { 1, 2, 3 };

            d.SetAudio(b);

            Assert.AreEqual(true, d.ContainsAudio(), "A1");
            Assert.AreEqual(false, d.ContainsFileDropList(), "A2");
            Assert.AreEqual(false, d.ContainsImage(), "A3");
            Assert.AreEqual(false, d.ContainsText(), "A4");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A5");

            Assert.AreEqual(b.Length, d.GetAudioStream().Length, "A6");
        }
Esempio n. 7
0
        public void TestFileDrop()
        {
            DataObject       d  = new DataObject();
            StringCollection sc = new StringCollection();

            sc.AddRange(new string[] { "A", "B", "C" });

            d.SetFileDropList(sc);

            Assert.AreEqual(false, d.ContainsAudio(), "A1");
            Assert.AreEqual(true, d.ContainsFileDropList(), "A2");
            Assert.AreEqual(false, d.ContainsImage(), "A3");
            Assert.AreEqual(false, d.ContainsText(), "A4");
            Assert.AreEqual(false, d.ContainsText(TextDataFormat.CommaSeparatedValue), "A5");

            Assert.AreEqual(sc.Count, d.GetFileDropList().Count, "A6");
        }
Esempio n. 8
0
        /// <summary>
        /// Generates the visable label to display on the screen
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private ToolStripMenuItem GenerateLabel(DataObject obj)
        {
            ToolStripMenuItem item = new ToolStripMenuItem()
            {
                Name = Key
            };

            item.DropDown.Items.Add(new ToolStripLabel("Copy")
            {
                Name = Key
            });
            item.DropDown.Items.Add(new ToolStripLabel("Save")
            {
                Name = "Save" + Key
            });

            if (obj.ContainsText())
            {
                string Val = obj.GetText().Replace(Environment.NewLine, string.Empty);
                if (Val.Length > 120)
                {
                    Val = Val.Substring(0, 120);
                }
                item.Text = Val;
            }
            else if (obj.ContainsImage())
            {
                System.Drawing.Image thumb = obj.GetImage().GetThumbnailImage(16, 16, () => false, IntPtr.Zero);
                item.Image = thumb;
                item.Text  = "Image " + DateTime.Now.ToString("hhMMss");
            }
            else
            {
                return(new ToolStripMenuItem("Object " + DateTime.Now.ToString("hhMMss"), null)
                {
                    Name = Key
                });
            }

            return(item);
        }
Esempio n. 9
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Tab || e.KeyCode == Keys.Oemcomma || e.KeyCode == Keys.Return || e.KeyCode == Keys.Space)
            {
                this.SetFocusEditorIndex((this.focusEditor + 1) % this.editor.Length, true);
                e.Handled = true;
            }
            else if ((e.KeyCode == Keys.C || e.KeyCode == Keys.X) && e.Control)
            {
                if (this.focusEditor == -1)
                {
                    string     valString = this.editor.Select(ve => ve.Value).ToString(", ");
                    DataObject data      = new DataObject();
                    data.SetText(valString);
                    data.SetData(this.DisplayedValue);
                    Clipboard.SetDataObject(data);
                    this.SetFocusEditorIndex(-1, true);
                    if (e.KeyCode == Keys.X)
                    {
                        for (int i = 0; i < this.editor.Length; i++)
                        {
                            this.editor[i].Value = 0;
                        }
                    }
                    e.Handled = true;
                }
                else
                {
                    this.editor[this.focusEditor].OnKeyDown(e);
                }
            }
            else if (e.KeyCode == Keys.V && e.Control)
            {
                if (this.focusEditor == -1)
                {
                    DataObject data    = Clipboard.GetDataObject() as DataObject;
                    bool       success = false;
                    if (data.GetDataPresent(this.DisplayedValue.GetType()))
                    {
                        this.SetValue(data.GetData(this.DisplayedValue.GetType()));
                        this.PerformGetValue();
                        this.OnEditingFinished(FinishReason.LeapValue);
                        this.SetFocusEditorIndex(-1, true);
                        success = true;
                    }
                    else if (data.ContainsText())
                    {
                        string   valString = data.GetText();
                        string[] token     = valString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < Math.Min(token.Length, this.editor.Length); i++)
                        {
                            token[i] = token[i].Trim();
                            decimal val;
                            if (decimal.TryParse(token[i], out val))
                            {
                                this.editor[i].Value = val;
                                success = true;
                            }
                        }
                        if (success)
                        {
                            this.PerformSetValue();
                            this.PerformGetValue();
                            this.OnEditingFinished(FinishReason.LeapValue);
                            this.SetFocusEditorIndex(-1, true);
                        }
                    }

                    if (!success)
                    {
                        System.Media.SystemSounds.Beep.Play();
                    }
                    e.Handled = true;
                }
                else
                {
                    this.editor[this.focusEditor].OnKeyDown(e);
                }
            }
            else
            {
                if (this.focusEditor != -1)
                {
                    this.editor[this.focusEditor].OnKeyDown(e);
                }
                else
                {
                    for (int i = 0; i < this.editor.Length; i++)
                    {
                        this.editor[i].OnKeyDown(e);
                        if (e.Handled)
                        {
                            this.SetFocusEditorIndex(i, false);
                            break;
                        }
                    }
                }
            }
            base.OnKeyDown(e);
        }
Esempio n. 10
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            try
            {
                DataObject data = (DataObject)Clipboard.GetDataObject();
                if (data.GetDataPresent("Splash data", false))
                {
                    PasteSplashData(transaction, pnlView);
                }
#if SAW && !SPLASH
                else if (data.GetDataPresent("Splash scripts", false))
                {
                    CopyScripts.Paste(transaction);
                }
                else if (data.GetDataPresent("Splash presentation", false))
                {
                    CopyPresentation.Paste(transaction, pnlView);
                }
#endif
                else if (data.ContainsImage())
                {
                    Image        image      = data.GetImage();
                    MemoryStream strmMemory = new MemoryStream(10000);
                    image.Save(strmMemory, ImageFormat.Png);
                    image.Dispose();
                    ImportedImage objImported = new ImportedImage(strmMemory, CurrentDocument, transaction);                     //= ImportedImage.CreateForPaste(strmMemory)
                    transaction.Create(objImported);
                    objImported.PlaceAt(pnlView.ViewableArea().Centre());
                    //  strmMemory.Dispose()
                    CurrentPage.AddNew(objImported, transaction);
                }
                else if (ContainsFileImage(data))
                {
                    ImportedImage imported = new ImportedImage(data.GetFileDropList()[0], CurrentDocument, transaction);
                    transaction.Create(imported);
                    imported.PlaceAt(pnlView.ViewableArea().Centre());
                    CurrentPage.AddNew(imported, transaction);
                    CurrentPage.SelectOnly(imported);
                }
                else if (data.ContainsText())
                {
                    string text = data.GetText();
                    if (!string.IsNullOrEmpty(text))
                    {
                        // try and apply it to a shape - only if there is one and only one selected
                        Shape shape = pnlView.TypingShape();
                        if (shape != null && shape.SupportsTextLabel)                         // Second condition is needed because some "typing" shapes only actually do custom processing of certain keys
                        {
                            transaction.Edit(shape);
                            shape.TextType(text);
                        }
                        else if (CurrentPage.SelectedCount == 1)
                        {
                            shape = CurrentPage.SelectedShapes[0];
                            if (shape.SupportsTextLabel)
                            {
                                // When pasting in without the cursor, the entire current text is replaced, if any
                                transaction.Edit(shape);
                                if (!shape.HasText(true))
                                {
                                    shape.CreateLabel((Shape.TextStyleC)Editor.StyleParameterDefaultObject(Parameters.FontFace));
                                }
                                // StyleParameterDefaultObject returns the object for that param - which will be all the text styles
                                shape.LabelText = text.Replace("\r\n", "\r");
                            }
                        }
                    }
                }
            }
            catch (Exception ex) when(!Globals.Root.IsDebug)
            {
                Utilities.LogSubError(ex);
                transaction.Cancel();                 // must be before message box
                MessageBox.Show(Strings.Item("Paste_Failed"));
            }
        }
Esempio n. 11
0
        public void Drop(IDropInfo dropInfo)
        {
            // There is nothing we can do here.
            if (dropInfo == null)
            {
                return;
            }
            // Data is populated from external and internal drag & drop. If it is null there is nothing we can do here.
            if (dropInfo.Data == null)
            {
                return;
            }
            // Check if target is not group, if yes, then there is nothing we can do here.
            bool targetIsTreeViewItem = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) && dropInfo.VisualTargetItem is TreeViewItem;

            if (targetIsTreeViewItem)
            {
                TreeViewItem treeViewItem = (TreeViewItem)dropInfo.VisualTargetItem;
                ItemVM       itemVM       = (ItemVM)treeViewItem.DataContext;
                if (!itemVM.IsGroup)
                {
                    return;
                }
            }

            // Target is group proced with the other checks...

            var insertIndex  = dropInfo.InsertIndex != dropInfo.UnfilteredInsertIndex ? dropInfo.UnfilteredInsertIndex : dropInfo.InsertIndex;
            var itemsControl = dropInfo.VisualTarget as ItemsControl;

            if (itemsControl != null)
            {
                var editableItems = itemsControl.Items as IEditableCollectionView;
                if (editableItems != null)
                {
                    var newItemPlaceholderPosition = editableItems.NewItemPlaceholderPosition;
                    if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtBeginning && insertIndex == 0)
                    {
                        ++insertIndex;
                    }
                    else if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtEnd && insertIndex == itemsControl.Items.Count)
                    {
                        --insertIndex;
                    }
                }
            }

            var destinationList = dropInfo.TargetCollection.TryGetList();
            var data            = ExtractData(dropInfo.Data).OfType <object>().ToList();

            // If this is a move for sure it is from the internal Drag & Drop, so delete the source item.
            DragDropEffects dragDropEffects = GetDragDropEffects(dropInfo);

            if (dragDropEffects == DragDropEffects.Move)
            {
                if (dropInfo.DragInfo != null)
                {
                    // This is a drag & drop item from treeview its self
                    var sourceList = dropInfo.DragInfo.SourceCollection.TryGetList();
                    if (sourceList != null)
                    {
                        foreach (var o in data)
                        {
                            var index = sourceList.IndexOf(o);
                            if (index != -1)
                            {
                                sourceList.RemoveAt(index);
                                // so, is the source list the destination list too ?
                                if (destinationList != null && Equals(sourceList, destinationList) && index < insertIndex)
                                {
                                    --insertIndex;
                                }
                            }
                        }
                    }
                }
            }

            // Add item
            if (destinationList != null)
            {
                // check for cloning
                var cloneData = dropInfo.Effects.HasFlag(DragDropEffects.Copy) || dropInfo.Effects.HasFlag(DragDropEffects.Link);
                foreach (var o in data)
                {
                    // ----------------------------------------------
                    // This is a Drag & Drop from the external source
                    // ----------------------------------------------
                    if (dropInfo.Data is DataObject)
                    {
                        DataObject dataObject = o as DataObject;
                        if (dataObject != null)
                        {
                            // ******************************************************************************************************************************************
                            // FileDrop. Queries a data object for the presence of data in the System.Windows.DataFormats.FileDrop data format.
                            // ******************************************************************************************************************************************
                            if (dataObject.ContainsFileDropList() && dataObject.GetDataPresent(DataFormats.FileDrop, true))
                            {
                                // We can have more than one file dropped.
                                var droppedFilePaths = dataObject.GetFileDropList();
                                foreach (string droppedFilePath in droppedFilePaths)
                                {
                                    string        shortcutsDirectoryPath = Helper.GetShortcutsPath();
                                    string        guid          = NewData.NewGuid();
                                    string        name          = Path.GetFileName(droppedFilePath);
                                    DirectoryInfo directoryInfo = new DirectoryInfo(droppedFilePath);
                                    if (directoryInfo.Parent == null)
                                    {
                                        // This is the root. In that case name is empty so we need to set the name differently.
                                        DriveInfo driveInfo = new DriveInfo(droppedFilePath);
                                        // Something like this: Local Disk (C:)
                                        string volumeLabel = driveInfo.VolumeLabel;
                                        if (string.IsNullOrEmpty(volumeLabel))
                                        {
                                            volumeLabel = "Drive";
                                        }
                                        name = $"{volumeLabel} ({driveInfo.Name.Replace(@"\", "")})";
                                    }

                                    ItemVM obj2Insert = null;

                                    // Check if the dropped file is a .lnk file. We just copy the .lnk files to the sortcuts folder and use them from there.
                                    if (Path.GetExtension(droppedFilePath).Equals(Constants.EXT_LNK, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        // This is a .lnk file. In this case we copy this file to our shortcuts
                                        string shortcutLnkFilePath = Path.Combine(shortcutsDirectoryPath, guid + Constants.EXT_LNK);
                                        File.Copy(droppedFilePath, shortcutLnkFilePath);
                                        obj2Insert = new ItemVM(guid, false, false, name, shortcutLnkFilePath, Constants.EXT_LNK);
                                    }
                                    // Check if the dropped file is a .url file. We just copy the .url files to the sortcuts folder and use them from there.
                                    else if (Path.GetExtension(droppedFilePath).Equals(Constants.EXT_URL, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        // This is a .url file. In this case we copy this file to our shortcuts
                                        string shortcutUrlFilePath = Path.Combine(shortcutsDirectoryPath, guid + Constants.EXT_URL);
                                        File.Copy(droppedFilePath, shortcutUrlFilePath);
                                        obj2Insert = new ItemVM(guid, false, false, name, shortcutUrlFilePath, Constants.EXT_URL);
                                    }
                                    else
                                    {
                                        obj2Insert = new ItemVM(guid, false, false, name, droppedFilePath, Constants.EXT_LNK);
                                    }

                                    destinationList.Insert(insertIndex++, obj2Insert);
                                    SaveShortcutSettings();
                                }
                            }
                            // ******************************************************************************************************************************************
                            // AbsoluteUri. Queries a data object for the presence of data in the System.Windows.DataFormats.UnicodeText format.
                            // ******************************************************************************************************************************************
                            else if (dataObject.ContainsText() && dataObject.GetDataPresent(DataFormats.Text, true))
                            {
                                string dataText = (string)dataObject.GetData(DataFormats.Text, true);
                                Uri    uri;
                                bool   isAbsoluteUri = Uri.TryCreate(dataText, UriKind.Absolute, out uri);
                                if (isAbsoluteUri)
                                {
                                    ItemVM obj2Insert = new ItemVM(NewData.NewGuid(), false, false, uri.AbsoluteUri, uri.AbsoluteUri, Constants.EXT_URL);
                                    destinationList.Insert(insertIndex++, obj2Insert);
                                    // Save shortcut settings.
                                    SaveShortcutSettings();
                                }
                            }
                            else
                            {
                                // ******************************************************************************************************************************************
                                // ShellIDListArray. Perhaps data contain virtual files
                                // ******************************************************************************************************************************************
                                // Returns a list of formats in which the data in this data object is stored, or can be converted to.
                                string[] formats = dataObject.GetFormats();
                                foreach (string format in formats)
                                {
                                    if (format == "Shell IDList Array")
                                    {
                                        // Virtual file/s been draged.
                                        string message = "To create this kind of shortcut please do:\n";
                                        message += "1. Drag to create a desktop shortcut first,\n";
                                        message += "2. Drag the shortcut from desktop to MDSHO,\n";
                                        message += "3. Delete the shortcut from desktop if you want.";
                                        Window parent = Helper.GetWindowFromWindowItemVM(this);
                                        MessageBox.Show(parent, message, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                                    }
                                }
                            }
                        }
                    }
                    // ---------------------------------------------------------------------------
                    // This is a Drag & Drop from the internal source. Item from treeview its self
                    // ---------------------------------------------------------------------------
                    else
                    {
                        var obj2Insert = o;
                        if (cloneData)
                        {
                            var cloneable = o as ICloneable;
                            if (cloneable != null)
                            {
                                obj2Insert = cloneable.Clone();
                            }
                        }
                        destinationList.Insert(insertIndex++, obj2Insert);
                        // Save shortcut settings.
                        SaveShortcutSettings();
                    }
                }
            }
        }
Esempio n. 12
0
 internal override bool ContainsText() => _data != null?_data.ContainsText() : false;