コード例 #1
0
        public void ClipboardFetchFilesItemTest()
        {
            string file1 = Path.GetTempFileName();
            string file2 = Path.GetTempFileName();

            var dummyFiles = new StringCollection();

            dummyFiles.Add(file1);
            dummyFiles.Add(file2);

            Clipboard.Clear();
            Clipboard.SetFileDropList(dummyFiles);

            StringCollection copiedList = Clipboard.GetFileDropList();
            Assert.AreEqual(copiedList.Count, dummyFiles.Count);

            var factory = new ClipboardFileFactory();

            var item = factory.CreateNewClipboardItem(IntPtr.Zero) as ClipboardFileCollection;
            Assert.IsNotNull(item);

            Assert.AreEqual(item.Paths.Count(), 2);

            List<string> localList = item.Paths.ToList();

            for (int i = 0; i < localList.Count; i++)
            {
                Assert.AreEqual(localList[i], dummyFiles[i]);
            }

            File.Delete(file1);
            File.Delete(file2);
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: Zargess/Shapeshifter-old
        private async void Clipboard_ContentChanged(object sender, object e)
        {
            //handle clipboard data
            ClipboardSnapshot snapshot = ClipboardSnapshot.CreateSnapshot();
            if (snapshot.ContainsData)
            {

                var factory = (ClipboardItemFactory)null;
                IEnumerable<string> priorities = snapshot.FormatPriorities;
                foreach (string format in priorities)
                {

                    if (format == StandardDataFormats.Bitmap)
                    {

                        //images
                        factory = new ClipboardImageFactory(snapshot);
                        break;

                    }
                    else if (format == StandardDataFormats.Text || format == StandardDataFormats.Uri || format == StandardDataFormats.Rtf || format == StandardDataFormats.Html)
                    {

                        //text
                        factory = new ClipboardTextFactory(snapshot);
                        break;

                    }
                    else if (format == StandardDataFormats.StorageItems)
                    {

                        //files
                        factory = new ClipboardFileFactory(snapshot);
                        break;

                    }
                }

                if (factory == null)
                {
                    factory = new ClipboardCustomDataFactory(snapshot);
                }

                ClipboardItem clipboardItem = await factory.CreateNewClipboardItem();
                _clipboardItems.Insert(0, clipboardItem);

                ClipboardDataAdded(clipboardItem);

                if (SettingsHelper.GetSetting("UseIncineration", "1") == "1")
                {
                    App.Incinerate();
                }
            }
        }
コード例 #3
0
        public void ClipboardFetchFileItemTest()
        {
            string file = Path.GetTempFileName(); //brug GetTempFileName i stedet for. den er nice. den laver selv en temp fil, og returnerer path'en.

            var dummyFiles = new StringCollection();
            dummyFiles.Add(file);
            Clipboard.Clear();
            Clipboard.SetFileDropList(dummyFiles);

            var factory = new ClipboardFileFactory();

            var item = factory.CreateNewClipboardItem(IntPtr.Zero) as ClipboardFile;
            Assert.IsNotNull(item);

            Assert.AreEqual(item.Path, dummyFiles[0]);
            File.Delete(file);
        }
コード例 #4
0
        private IntPtr OnWindowMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            try
            {
                if (msg == WM_CLIPBOARDUPDATE)
                {

                    var sequenceNumber = GetClipboardSequenceNumber();
                    if (IsReadyForSnapshotActions && sequenceNumber != _lastSequenceNumber && !IgnoreClipboardActivity)
                    {
                        _lastSequenceNumber = sequenceNumber;

                        IgnoreClipboardActivity = true;

                        //handle clipboard data
                        ClipboardSnapshot snapshot = ClipboardSnapshot.CreateSnapshot(hwnd);
                        if (snapshot.ContainsData &&
                            hwnd != snapshot.OutsideClipboardOwnerHandle)
                        {
                            Trace.WriteLine("A snapshot with data was discovered from source [" +
                                            snapshot.OutsideClipboardOwnerHandle + "]");

                            var factory = (ClipboardItemFactory) null;
                            IEnumerable<uint> priorities = snapshot.FormatPriorities;
                            foreach (uint format in priorities)
                            {
                                if (format == KnownClipboardFormats.CF_DIB || format == KnownClipboardFormats.CF_DIBV5 ||
                                    format == KnownClipboardFormats.CF_DIF ||
                                    format == KnownClipboardFormats.CF_DSPBITMAP ||
                                    format == KnownClipboardFormats.CF_DSPMETAFILEPICT ||
                                    format == KnownClipboardFormats.CF_DSPENHMETAFILE ||
                                    format == KnownClipboardFormats.CF_ENHMETAFILE)
                                {
                                    Trace.WriteLine("The snapshot is an image snapshot");

                                    //images
                                    factory = new ClipboardImageFactory(snapshot);
                                    break;
                                }
                                else if (format == KnownClipboardFormats.CF_DSPTEXT ||
                                         format == KnownClipboardFormats.CF_UNICODETEXT)
                                {
                                    Trace.WriteLine("The snapshot is a text snapshot");

                                    //text
                                    factory = new ClipboardTextFactory(snapshot);
                                    break;
                                }
                                else if (format == KnownClipboardFormats.CF_HDROP)
                                {
                                    Trace.WriteLine("The snapshot is a file snapshot");

                                    //files
                                    factory = new ClipboardFileFactory(snapshot);
                                    break;
                                }
                            }

                            if (factory == null)
                            {
                                Trace.WriteLine("The snapshot is of no known format (custom data)");

                                factory = new ClipboardCustomDataFactory(snapshot);
                            }

                            ClipboardItem clipboardItem = factory.CreateNewClipboardItem(WindowHandle,
                                                                                         _clipboardItems.Take(100));
                            if (clipboardItem != null)
                            {

                                if (_clipboardItems.Contains(clipboardItem))
                                {
                                    SwapClipboardItemPositions(_clipboardItems.IndexOf(clipboardItem), 0);
                                }
                                else
                                {
                                    _clipboardItems.Insert(0, clipboardItem);
                                    if (ClipboardDataAdded != null)
                                    {
                                        ClipboardDataAdded(clipboardItem);
                                    }

                                    switch (_clipboardItems.Count)
                                    {
                                        case 1:
                                            NotificationHelper.ShowInstructions(
                                                "You have 1 item in your clipboard now. Try copying just one more.");
                                            break;

                                        case 2:
                                            string mode = SettingsHelper.GetSetting("ManagementMode", "Mixed");
                                            if (mode == "Integrated")
                                            {
                                                NotificationHelper.ShowInstructions(
                                                    "Nicely done! Now try holding down CTRL + V (it's important that you hold it down).");
                                            }
                                            else if (mode == "External")
                                            {
                                                NotificationHelper.ShowInstructions(
                                                    "Nicely done! Now note the Shapeshifter windows on your taskbar. They represent the clipboard data.");
                                            }
                                            else if (mode == "Mixed")
                                            {
                                                NotificationHelper.ShowInstructions(
                                                    "Nicely done! Now try holding down CTRL + V (it's important that you hold it down), or clicking the Shapeshifter icon on your taskbar.");
                                            }
                                            break;
                                    }
                                }

                                if (SettingsHelper.GetSetting("UseIncineration", "1") == "1")
                                {
                                    App.Incinerate();
                                }
                            }

                        }

                        IgnoreClipboardActivity = false;

                    }
                }
                else if (msg == WM_DWMCOLORIZATIONCOLORCHANGED)
                {
                    if (AeroColorChanged != null)
                    {
                        AeroColorChanged(wParam.ToInt64());
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                if(Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                //caught due to a bug in .NET under Windows 7 when closing the application from tray icon
            }

            return IntPtr.Zero;
        }