Esempio n. 1
0
        public async Task Should_Create_With_Known_Format()
        {
            //arrange
            var testFormat = "Test_Format";

            await RunOnSTA(() =>
            {
                SysClipboard.Clear();
                SysClipboard.SetData(testFormat, "Test");
            });

            _formatsExtractor.Setup(x => x.Extract(It.IsAny <ClipboardTrigger>(), It.IsAny <IDataObject>())).Returns(new[] { new TestEquatableFormat(new ClipboardFormat(testFormat, testFormat, "Test", new ClipboardFormatCategory("Test Category", "Test"))) });
            _listenerMock.Setup(x => x.IsInterestedIn(It.IsAny <ClipboardObject>())).Returns(true);

            //act
            using (var sut = new ClipboardObjectsManager(_clipboardObjectManager.Object, new[] { _formatsExtractor.Object }, new[] { _clipboardFilter.Object }, _serviceProviderMock.Object))
            {
                sut.AddListener(_listenerMock.Object);
                sut.AddTriggerToQueue();

                await Task.Delay(100);
            }

            //assert
            _listenerMock.Verify(x => x.OnResolvedTrigger(It.IsAny <ResolvedClipboardTrigger>()), Times.Once());
            _listenerMock.Verify(x => x.IsInterestedIn(It.IsAny <ClipboardObject>()), Times.Once());

            _clipboardObjectManager.Verify(x => x.AddImplementationsAsync(It.IsAny <ClipboardObject>(), It.IsAny <IEnumerable <EqualtableFormat> >()), Times.Once());
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the CSV export process
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // select all cells
                ResultGrid.SelectAllCells();
                // copy data to clipboard
                ResultGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, ResultGrid);
                // clipboard contains data... unselect all cells
                ResultGrid.UnselectAllCells();
                // save data from clipboard to variable
                var result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                // data is in variable, clear clipboard
                Clipboard.Clear();

                // create a Save-File Dialog
                var sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter = @"CSV files (*.csv)|*.csv";
                // if dialog displayed successfully
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // write data to file using a StreamWriter
                    var writer = new StreamWriter(sfd.OpenFile());
                    writer.WriteLine(result);
                    writer.Close();
                    MessageBox.Show("CSV Export complete");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CSV Export failed. \n" + ex.Message);
                Debug.WriteLine(ex);
            }
        }
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ResultGrid.SelectAllCells();
                ResultGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, ResultGrid);
                ResultGrid.UnselectAllCells();
                var result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                Clipboard.Clear();

                var sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter = @"CSV files (*.csv)|*.csv";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var writer = new StreamWriter(sfd.OpenFile());
                    writer.WriteLine(result);
                    writer.Close();
                }

                MessageBox.Show("CSV Export complete.");
            }
            catch (Exception ex)
            {
                MessageBox.Show("CSV Export failed. \n" + ex.Message);
            }
        }
Esempio n. 4
0
        public MainWindow()
        {
            InitializeComponent();
            Clipboard.Clear();

            DataContext = this;

            _screen          = CopyScreen();
            Canvas.Width     = _screen.Width;
            Canvas.Height    = _screen.Height;
            ImageMask.Source = _screen;
            Image.Source     = _screen;
            Image.Visibility = Visibility.Collapsed;

            ResizeAdorner                    = new ResizeAdorner(AdornerRectangle);
            ResizeAdorner.ShowHandles        = true;
            ResizeAdorner.OnHandleMouseDown += ResizeAdorner_OnHandleMouseDown;

            var winds           = WinApi.GetWindows();
            var WS_CLIPCHILDREN = 0x02000000L;
            var WS_BORDER       = 0x00800000L;

            foreach (IntPtr win in winds)
            {
                var p = WinApi.GetWindowLongPtr(win, WinApi.GWL.GWL_STYLE);

                if (((long)p & WS_CLIPCHILDREN) == WS_CLIPCHILDREN ||
                    ((long)p & WS_BORDER) == WS_BORDER
                    )
                {
                    WinApi.GetWindowRect(win, out WinApi.RECT rect);
                    wins.Add(rect);
                }
            }
        }
Esempio n. 5
0
        private void BtnClipboard_OnClick(object sender, RoutedEventArgs e)
        {
            Clipboard.Clear();
            StringBuilder builder = new StringBuilder();
            TextWriter    writer  = new StringWriter(builder);

            _exception.XML.Save(writer);

            Clipboard.SetText(builder.ToString());
        }
Esempio n. 6
0
 private void PopulateFile()
 {
     Clipboard.Clear();
     Clipboard.SetText(replayPath);
     Thread.Sleep(500);
     SendKeys.SendWait("^v");
     Thread.Sleep(150);
     SendKeys.SendWait("{ENTER}");
     Clipboard.Clear();
 }
        private async Task <bool> CheckClipboardForNetDeckImport()
        {
            try
            {
                if (Clipboard.ContainsText())
                {
                    var clipboardContent = Clipboard.GetText();
                    if (clipboardContent.StartsWith("netdeckimport"))
                    {
                        var clipboardLines = clipboardContent.Split('\n').ToList();
                        var deckName       = clipboardLines.FirstOrDefault(line => line.StartsWith("name:"));
                        if (!string.IsNullOrEmpty(deckName))
                        {
                            clipboardLines.Remove(deckName);
                            deckName = deckName.Replace("name:", "").Trim();
                        }
                        var url = clipboardLines.FirstOrDefault(line => line.StartsWith("url:"));
                        if (!string.IsNullOrEmpty(url))
                        {
                            clipboardLines.Remove(url);
                            url = url.Replace("url:", "").Trim();
                        }
                        clipboardLines.RemoveAt(0);                         //"netdeckimport"

                        var deck = ParseCardString(clipboardLines.Aggregate((c, n) => c + "\n" + n));
                        if (deck != null)
                        {
                            deck.Url  = url;
                            deck.Note = url;
                            deck.Name = deckName;
                            SetNewDeck(deck);
                            if (Config.Instance.AutoSaveOnImport)
                            {
                                await SaveDeckWithOverwriteCheck();
                            }
                            ActivateWindow();
                        }
                        Clipboard.Clear();
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine(e.ToString());
                return(false);
            }
            return(false);
        }
Esempio n. 8
0
        private static void ShowMessageBox(string text, int lineCount)
        {
            var result = MessageBox.Show(
                $"{text}\n\n{Strings.copyResultToClipboard}",
                Strings.linesCountMsgBoxTitle,
                MessageBoxButton.YesNo,
                MessageBoxImage.Question
                );

            if (result != MessageBoxResult.Yes)
            {
                return;
            }
            Clipboard.Clear();
            Clipboard.SetText($"{lineCount.ToString()}");
        }
Esempio n. 9
0
 private static void CopyToClipboardRecursiveRetry(string obj, int retryCount, int maxRetryCount)
 {
     if (obj == null)
     {
         return;
     }
     obj = obj.Replace('`', '\'');
     try
     {
         Clipboard.Clear();
         Thread.Sleep(50);
         Clipboard.SetDataObject(obj);
     }
     catch (COMException ex)
     {
         if (retryCount < maxRetryCount)
         {
             Thread.Sleep(200);
             CopyToClipboardRecursiveRetry(obj, retryCount + 1, maxRetryCount);
         }
     }
 }
Esempio n. 10
0
        public async Task Should_Not_Create_ClipboardObject_If_Clipboard_Empty()
        {
            //arrange
            await RunOnSTA(() =>
            {
                SysClipboard.Clear();
            });

            //act
            using (var sut = new ClipboardObjectsManager(_clipboardObjectManager.Object, new[] { _formatsExtractor.Object }, new[] { _clipboardFilter.Object }, _serviceProviderMock.Object))
            {
                sut.AddListener(_listenerMock.Object);
                sut.AddTriggerToQueue();

                await Task.Delay(100);
            }

            //assert
            _listenerMock.Verify(x => x.OnResolvedTrigger(It.IsAny <ResolvedClipboardTrigger>()), Times.Never());
            _listenerMock.Verify(x => x.IsInterestedIn(It.IsAny <ClipboardObject>()), Times.Never());

            _clipboardObjectManager.Verify(x => x.AddImplementationsAsync(It.IsAny <ClipboardObject>(), It.IsAny <IEnumerable <EqualtableFormat> >()), Times.Never());
        }
Esempio n. 11
0
        private IntPtr MainWindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case WM_DRAWCLIPBOARD:

                if (_getCopyValue && Clipboard.ContainsText())
                {
                    _getCopyValue = false;
                    var selectedText = Clipboard.GetText().Trim();
                    if (selectedText.Length > 1)
                    {
                        LblEnglish.Text = selectedText;
                        Translate();
                        Clipboard.Clear();
                    }
                }

                // Send message along, there might be other programs listening to the copy command.
                SendMessage(_clipboardViewerNext, msg, wParam, lParam);
                break;

            case WM_CHANGECBCHAIN:
                if (wParam == _clipboardViewerNext)
                {
                    _clipboardViewerNext = lParam;
                }
                else
                {
                    SendMessage(_clipboardViewerNext, msg, wParam, lParam);
                }

                break;
            }

            return(IntPtr.Zero);
        }
Esempio n. 12
0
 public void Clear() => Clipboard.Clear();
Esempio n. 13
0
 public void Clear()
 {
     WindowsClipboard.Clear();
 }