Esempio n. 1
0
        public override async void Paste()
        {
            var action = FileAction.Copy;

            if (Clipboard.GetData("Preferred DropEffect") is Stream act)
            {
                var effectData = new byte[4];
                act.Read(effectData, 0, effectData.Length);
                action = effectData[0] == 2 ? FileAction.Move : FileAction.Copy;
            }

            if (!Clipboard.ContainsFileDropList())
            {
                return;
            }

            Items.CollectionChanged += FocusFirstPastedItem;
            var items    = Clipboard.GetFileDropList();
            var copyTask = new TaskItem("Copying");
            await Workspace.TaskManager.RunAsync(copyTask, () => { new FilesystemAction(NotificationHost).Paste(Path, items, action); });

            _undoParameter = new Tuple <string, StringCollection, FileAction>(Path, items, action);
            if (action == FileAction.Move)
            {
                Clipboard.Clear();
                SelectedItems.Foreach(i => i.IsMarkedForMove = false);
            }
        }
Esempio n. 2
0
        public static DataTable DataGridtoDataTable(DataGrid dg)
        {
            dg.SelectAllCells();
            dg.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
            ApplicationCommands.Copy.Execute(null, dg);
            dg.UnselectAllCells();
            String result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);

            string[] Lines = result.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            string[] Fields;
            Fields = Lines[0].Split(new char[] { ',' });
            int       Cols = Fields.GetLength(0);
            DataTable dt   = new DataTable();

            //1st row must be column names; force lower case to ensure matching later on.
            for (int i = 0; i < Cols; i++)
            {
                dt.Columns.Add(Fields[i].ToUpper(), typeof(string));
            }
            DataRow Row;

            for (int i = 1; i < Lines.GetLength(0) - 1; i++)
            {
                Fields = Lines[i].Split(new char[] { ',' });
                Row    = dt.NewRow();
                for (int f = 0; f < Cols; f++)
                {
                    Row[f] = Fields[f];
                }
                dt.Rows.Add(Row);
            }
            return(dt);
        }
Esempio n. 3
0
        /// <summary>
        ///     result != null, arrays != null
        ///     Uses CultureHelper.SystemCultureInfo.
        /// </summary>
        /// <returns></returns>
        public static List <string[]> ParseClipboardData()
        {
            IDataObject dataObj = Clipboard.GetDataObject();

            if (dataObj is null)
            {
                return(new List <string[]>());
            }

            object clipboardData = dataObj.GetData(DataFormats.CommaSeparatedValue);

            if (clipboardData != null)
            {
                string clipboardDataString = GetClipboardDataString(clipboardData);
                return(CsvHelper.ParseCsv(CultureHelper.SystemCultureInfo.TextInfo.ListSeparator, clipboardDataString));
            }
            clipboardData = dataObj.GetData(DataFormats.Text);
            if (clipboardData != null)
            {
                string clipboardDataString = GetClipboardDataString(clipboardData);
                return(CsvHelper.ParseCsv("\t", clipboardDataString));
            }

            return(new List <string[]>());
        }
        public static void ImportFromWebClipboard()
        {
            var clipboard = Clipboard.ContainsText() ? Clipboard.GetText() : "could not get text from clipboard";

            Core.MainWindow.ImportDeck(clipboard);
            Core.MainWindow.ActivateWindow();
        }
Esempio n. 5
0
        internal async void ExportCardNamesToClipboard(Deck deck)
        {
            if (deck == null || !deck.GetSelectedDeckVersion().Cards.Any())
            {
                this.ShowMessage("", LocUtil.Get("ShowMessage_CopyCardNames_NoCards")).Forget();
                return;
            }

            try
            {
                var selectedLanguage = await this.ShowSelectLanguageDialog();

                if (!selectedLanguage.IsCanceled)
                {
                    Enum.TryParse(selectedLanguage.SelectedLanguage, out Locale myLang);
                    var names = deck.GetSelectedDeckVersion().Cards.ToSortedCardList()
                                .Select(c => (Cards.GetFromDbfId(c.DbfIf).GetLocName(myLang)) + (c.Count > 1 ? " x " + c.Count : ""))
                                .Aggregate((c, n) => c + Environment.NewLine + n);

                    Clipboard.SetDataObject(names);
                    Log.Info("Copied " + deck.GetDeckInfo() + " names to clipboard");
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                ErrorManager.AddError("Error copying card names", LocUtil.Get("ShowMessage_CopyCardNames_Error"));
            }
        }
Esempio n. 6
0
        public static void SetRtf(string text_rtf)
        {
            // Also convert the RTF to normal text
            using (RichTextBox rich_text_box = new RichTextBox())
            {
                rich_text_box.Rtf = text_rtf;
                string text_plain = rich_text_box.Text;

                DataObject data = new DataObject();
                data.SetData(DataFormats.Rtf, text_rtf);
                data.SetData(DataFormats.Text, text_plain);

                for (int i = 0; i < 3; ++i)
                {
                    try
                    {
                        // Try set the text - and if we succeed, exit
                        Clipboard.Clear();
                        Clipboard.SetDataObject(data, true);
                        return;
                    }
                    catch (Exception ex)
                    {
                        Logging.Warn(ex, "There was a problem setting the clipboard text, so trying again.");
                        Thread.Sleep(250);
                    }
                }

                // If we get here, try one last time!
                Clipboard.Clear();
                Clipboard.SetDataObject(data, true);
            }
        }
Esempio n. 7
0
        /// <summary>
        ///     Uses CultureHelper.SystemCultureInfo
        /// </summary>
        /// <param name="data"></param>
        public static void SetClipboardData(List <string[]> data)
        {
            if (data is null || data.Count == 0)
            {
                return;
            }

            var sb1 = new StringBuilder();
            var sb2 = new StringBuilder();

            foreach (var row in data)
            {
                sb1.Append(CsvHelper.FormatForCsv(CultureHelper.SystemCultureInfo.TextInfo.ListSeparator, row));
                sb1.Append(Environment.NewLine);

                sb2.Append(CsvHelper.FormatForCsv("\t", row));
                sb2.Append(Environment.NewLine);
            }
            string clipboardData1 = sb1.ToString();
            string clipboardData2 = sb2.ToString();

            Clipboard.Clear();
            if (!String.IsNullOrEmpty(clipboardData1))
            {
                Clipboard.SetData(DataFormats.CommaSeparatedValue, clipboardData1);
            }
            if (!String.IsNullOrEmpty(clipboardData2))
            {
                Clipboard.SetData(DataFormats.Text, clipboardData2);
            }
        }
Esempio n. 8
0
        public static void SetText(string selected_text, TextDataFormat textDataFormat)
        {
            for (int i = 0; i < 3; ++i)
            {
                try
                {
                    // Try set the text - and if we succeed, exit
                    Clipboard.Clear();
                    Clipboard.SetText(selected_text, textDataFormat);
                    return;
                }
                catch (Exception ex)
                {
                    Logging.Warn(ex, "There was a problem setting the clipboard text, so trying again.");
                    Thread.Sleep(250);
                }
            }

            // If we get here, report who has locked the clipboard...
            try
            {
                IntPtr        hwnd = GetOpenClipboardWindow();
                StringBuilder sb   = new StringBuilder(501);
                GetWindowText(hwnd.ToInt32(), sb, 500);
                string msg = String.Format("Process '{0}' has locked the clipboard and won't release it.", sb.ToString());
                Logging.Warn(msg);
                throw new Exception(msg);
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "Something has locked the clipboard, and there was a problem find out what...");
            }
        }
Esempio n. 9
0
 private static void UploadSucess(string uri)
 {
     uri = $"https://{uri}";
     if (Settings.OpenLink)
     {
         Process.Start(uri);
     }
     if (Settings.CopyLink)
     {
         _aobaDispatcher.BeginInvoke(new Action(() => Clipboard.SetText(uri)));
     }
     if (Settings.PlaySounds && Settings.SoundSuccess)
     {
         try
         {
             _successSound.Stop();
             _successSound.Play();
         }catch
         { }
     }
     if (Settings.ShowToasts && Settings.ToastSucess)
     {
         Notify(_clickUri = uri, "Upload Sucessful");
     }
     Debug.WriteLine(uri);
 }
Esempio n. 10
0
        private void OnClipboardContentChanged(object sender, EventArgs e)
        {
            try
            {
                if (!Clipboard.ContainsText())
                {
                    return;
                }

                // Count each whitespace as new url
                string content = Clipboard.GetText();
                if (content == null)
                {
                    return;
                }
                string[] urls = content.Split();

                Task.Run(() => AddBlogBatchedAsync(urls));
            }
            catch (Exception ex)
            {
                Logger.Error($"ManagerController:OnClipboardContentChanged: {ex}");
                _shellService.ShowError(new ClipboardContentException(ex), "error getting clipboard content");
            }
        }
Esempio n. 11
0
        public static void CopyInspect(string name)
        {
            var clip = string.Empty;

            if (NetworkController.Instance.Server.Region == "TW")
            {
                clip = "/查看 ";
            }
            else if (NetworkController.Instance.Server.Region == "JP")
            {
                clip = "/詳細確認 ";
            }
            else if (NetworkController.Instance.Server.Region == "KR")
            {
                clip = "/살펴보기 ";
            }
            else
            {
                clip = "/inspect ";
            }

            for (var i = 0; i < 3; i++)
            {
                try
                {
                    Clipboard.SetText(clip + name);
                    break;
                }
                catch
                {
                    Thread.Sleep(100);
                    //Ignore
                }
            }
        }
Esempio n. 12
0
 public override void SetData(TransferDataType type, Func <object> dataSource)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (dataSource == null)
     {
         throw new ArgumentNullException("dataSource");
     }
     if (type == TransferDataType.Html)
     {
         WindowsClipboard.SetData(type.ToWpfDataFormat(), GenerateCFHtml(dataSource().ToString()));
     }
     else if (type == TransferDataType.Image)
     {
         var img = dataSource() as Xwt.Drawing.Image;
         if (img != null)
         {
             var src = img.ToBitmap().GetBackend() as WpfImage;
             WindowsClipboard.SetData(type.ToWpfDataFormat(), src.MainFrame);
         }
     }
     else
     {
         WindowsClipboard.SetData(type.ToWpfDataFormat(), dataSource());
     }
 }
Esempio n. 13
0
 private void HandleNewClipboardData()
 {
     if (Clipboard.ContainsText())
     {
         var asciiData = Clipboard.GetText();
         OnNewClipboardAsciiData(asciiData);
     }
 }
 private void CopyTargetBitmapCommandHandler(TargetBitmapInfo targetBitmapInfo)
 {
     Clipboard.SetFileDropList(new StringCollection
     {
         targetBitmapInfo.FilePath
     });
     PromptHelper.Instance.Prompt = targetBitmapInfo.FilePath;
 }
        private void CopyColumnCommandHandler(ColorInfo colorInfo)
        {
            var str =
                $"await WindowsApi.ScreenApi.WaitScanColorLocation(Color.FromArgb({colorInfo.Color.R}, {colorInfo.Color.G}, {colorInfo.Color.B}), WindowsApi.ScreenApi.AllScreens[{SelectedScreenInfo.Index}], WindowsApi.ScreenApi.AllScreens[{SelectedScreenInfo.Index}].GetScreenColumn({colorInfo.Point.X - Buffer / 2}, {Buffer}));";

            Clipboard.SetDataObject(str);
            PromptHelper.Instance.Prompt = str;
        }
        private void CopyCommandHandler(ColorInfo colorInfo)
        {
            var str =
                $"await WindowsApi.ScreenApi.WaitColorAt({colorInfo.Point.X}, {colorInfo.Point.Y}, Color.FromArgb({colorInfo.Color.R}, {colorInfo.Color.G}, {colorInfo.Color.B}));";

            Clipboard.SetDataObject(str);
            PromptHelper.Instance.Prompt = str;
        }
        private void CopyCodeCommandHandler(TargetBitmapInfo targetBitmapInfo)
        {
            var str =
                $"await WindowsApi.ScreenApi.WaitScanBitmapLocation(new Bitmap(\"Pictures\\\\{Path.GetFileName(targetBitmapInfo.FilePath)}\"), WindowsApi.ScreenApi.AllScreens[{SelectedScreenInfo.Index}]);";

            Clipboard.SetDataObject(str);
            PromptHelper.Instance.Prompt = str;
        }
Esempio n. 18
0
        private void FormOnClipboardUpdated(object sender, EventArgs e)
        {
            var clipboardData = Clipboard.GetDataObject(); //we are on the STA thread here

            var handler = _clipboardChangeEventHandler;    //important for thread safety

            Task.Run(() => handler?.Invoke(this, clipboardData));
        }
Esempio n. 19
0
        public override bool IsTypeAvailable(TransferDataType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            return(WindowsClipboard.ContainsData(type.ToWpfDataFormat()));
        }
Esempio n. 20
0
        public async Task InjectFilesAsync(params string[] files)
        {
            clipboardCopyInterceptor.SkipNext();

            var collection = new StringCollection();

            collection.AddRange(files);

            WindowsClipboard.SetFileDropList(collection);
        }
Esempio n. 21
0
        /// <summary>
        /// Сохраняет логи за текущую сессию в буффер обмена
        /// </summary>
        private void SaveToClipboard()
        {
            var textToClipboard = new StringBuilder();

            foreach (var log in LogModelInstance.LogMessages)
            {
                textToClipboard.Append(log.Date.ToUniversalTime() + " " + log.Message + Environment.NewLine);
            }
            Clipboard.SetText(textToClipboard.ToString());
        }
Esempio n. 22
0
 internal void ExportIdsToClipboard(Deck deck)
 {
     if (deck == null)
     {
         return;
     }
     Clipboard.SetDataObject(Helper.DeckToIdString(deck.GetSelectedDeckVersion()));
     this.ShowMessage("", "copied ids to clipboard").Forget();
     Log.Info("Copied " + deck.GetSelectedDeckVersion().GetDeckInfo() + " to clipboard");
 }
Esempio n. 23
0
        private static void CopyToClipboard(string _filename)
        {
            Console.WriteLine("Trying to copy to clipboard...");

            BitmapSource bSource = new BitmapImage(new Uri(_filename));

            Clipboard.SetImage(bSource);

            Console.WriteLine("Success!");
        }
        public static async void ImportFromWebHighlight()
        {
            SendKeys.SendWait("^c");
            await Task.Delay(200);

            var clipboard = Clipboard.ContainsText() ? Clipboard.GetText() : "could not get text from clipboard";

            Core.MainWindow.ImportDeck(clipboard);
            Core.MainWindow.ActivateWindow();
        }
Esempio n. 25
0
 public string GetAssemblyPathText()
 {
     Mouse.Click(StudioWindow.GetChildren()[0].GetChildren()[2], new Point(423, 406));
     StudioWindow.GetChildren()[0].GetChildren()[2].WaitForControlReady();
     Keyboard.SendKeys(StudioWindow.GetChildren()[0].GetChildren()[2], "{CTRL}a");
     StudioWindow.GetChildren()[0].GetChildren()[2].WaitForControlReady();
     Keyboard.SendKeys(StudioWindow.GetChildren()[0].GetChildren()[2], "{CTRL}c");
     StudioWindow.GetChildren()[0].GetChildren()[2].WaitForControlReady();
     Keyboard.SendKeys(StudioWindow.GetChildren()[0].GetChildren()[2], "{RIGHT}");
     return(Clipboard.GetText());
 }
Esempio n. 26
0
        private void CopySelectedValuesToClipboard()
        {
            var builder = new StringBuilder();

            foreach (WPBookingDTO item in BookingList.SelectedItems)
            {
                builder.AppendLine(item.WpUser.Name);
            }

            Clipboard.SetText(builder.ToString());
        }
Esempio n. 27
0
        private void OnClipboardContentChanged(object sender, EventArgs e)
        {
            if (!Clipboard.ContainsText())
            {
                return;
            }

            // Count each whitespace as new url
            string[] urls = Clipboard.GetText().Split();

            Task.Run(() => AddBlogBatchedAsync(urls));
        }
 private void OnCopy()
 {
     if (this.Image != null)
     {
         Clipboard.SetImage(this.Image as BitmapSource);
         this.MessageQueue.Enqueue("QR Code copied to clipboard.");
     }
     else
     {
         this.MessageQueue.Enqueue("No QR Code to copy.");
     }
 }
Esempio n. 29
0
        public void SetData(TransferDataType type, Func <object> dataSource)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (dataSource == null)
            {
                throw new ArgumentNullException("dataSource");
            }

            WindowsClipboard.SetData(type.ToWpfDataFormat(), dataSource());
        }
Esempio n. 30
0
 public static void Write(IntPtr hWnd, string text)
 {
     Logger.Debug("Setting textbox {0} content to be \"{1}\"", hWnd, text);
     // activate it
     PInvoke.SendMessage(hWnd, PInvoke.WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
     // this fails on Chinese...
     //SetWindowTextW(hWnd, text);
     Clipboard.SetText(text);
     // let's hope nobody modifies it...
     PInvoke.SendMessage(hWnd, PInvoke.WM_PASTE, IntPtr.Zero, IntPtr.Zero);
     // cleanup
     Clipboard.Flush();
 }