Exemplo n.º 1
0
        private void RadRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
        {
            if (e.Command is SaveCommand)
            {
                e.Cancel = true;
                SaveDocument(); // A custom logic for saving document so you can change the properties of the Save File dialog.
            }

            if (e.Command is PasteCommand)
            {
                // Altering the PasteCommand to ensure only plain text is pasted in RadRichTextBox.
                // Obtain the content from the clipboard.
                RadDocument documentFromClipboard = ClipboardEx.GetDocument().ToDocument();

                TxtFormatProvider provider = new TxtFormatProvider();
                // Convert it to plain text.
                string plainText = provider.Export(documentFromClipboard);

                // Create a RadDocument instance from the plain text.
                RadDocument documentToInsert = provider.Import(plainText);
                // Set this document as a content to the clipboard.
                ClipboardEx.SetDocument(new DocumentFragment(documentToInsert));
            }

            if (e.Command is InsertTableCommand)
            {
                // Disable the possibility to insert tables into the document.
                MessageBox.Show("Inserting tables is not allowed.");
                e.Cancel = true;
            }
        }
Exemplo n.º 2
0
        private void gridStatistics_KeyDown(object sender, KeyEventArgs e)
        {
            // Handle Ctrl + C for copy
            if (e.KeyCode == Keys.V && e.Control)
            {
                StringBuilder sb = new StringBuilder();
                foreach (DataGridViewRow row in gridStatistics.Rows)
                {
                    if (row.IsNewRow)
                    {
                        continue;
                    }

                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        if (sb[sb.Length - 1] != '\n') // Not L10N
                        {
                            sb.Append('\t');           // Not L10N
                        }
                        sb.Append(cell.Value);
                    }
                    sb.Append('\n'); // Not L10N
                }
                try
                {
                    ClipboardEx.Clear();
                    ClipboardEx.SetText(sb.ToString());
                }
                catch (ExternalException)
                {
                    MessageDlg.Show(this, ClipboardHelper.GetOpenClipboardMessage(Resources.RTDetails_gridStatistics_KeyDown_Failed_setting_data_to_clipboard));
                }
            }
        }
Exemplo n.º 3
0
        private bool SendPlainImage(BitmapImage img)
        {
            bool isok = false;

            DispatcherEx.xInvoke(() =>
            {
                HwndInfo hwndInfo = this.GetActivedEditorHwnd();
                if (hwndInfo.Handle > 0)
                {
                    this.FocusEditor(true);
                    WinApi.Editor.MoveCaretToEnding(hwndInfo);
                    var dict = ClipboardEx.Backup();
                    Clipboard.Clear();
                    Clipboard.SetImage(img);
                    string text = this.GetPlainTextUnCached();
                    WinApi.PressCtrlV();
                    DateTime now = DateTime.Now;
                    while ((DateTime.Now - now).TotalSeconds < 2.0)
                    {
                        string newText = this.GetPlainTextUnCached();
                        if (newText != text)
                        {
                            isok = true;
                        }
                        DispatcherEx.DoEvents();
                    }
                    Util.WriteTimeElapsed(now, "等待时间");
                    ClipboardEx.Restore(dict);
                    return;
                }
            });
            return(isok);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Use the DocumentGrid to set the PrecursorConcentration values on all of the precursors in the document.
        /// </summary>
        private void SetPrecursorConcentrations(DocumentGridForm documentGrid)
        {
            RunUI(() => documentGrid.ChooseView(Resources.SkylineViewContext_GetDocumentGridRowSources_Precursors));
            WaitForConditionUI(() => documentGrid.IsComplete);
            var viewEditor = ShowDialog <ViewEditor>(documentGrid.DataboundGridControl.NavBar.CustomizeView);

            RunUI(() =>
            {
                viewEditor.ActiveAvailableFieldsTree.SelectColumn(PropertyPath.Root.Property("Proteins")
                                                                  .LookupAllItems().Property("Peptides").LookupAllItems().Property("Precursors").LookupAllItems()
                                                                  .Property("PrecursorConcentration"));
                viewEditor.ChooseColumnsTab.AddColumn(
                    PropertyPath.Parse("Proteins!*.Peptides!*.Precursors!*.PrecursorConcentration"));
                viewEditor.ViewName = "PrecursorConcentrations";
            });
            OkDialog(viewEditor, viewEditor.OkDialog);
            WaitForConditionUI(() => documentGrid.IsComplete);
            var colPrecursorConcentration =
                documentGrid.DataboundGridControl.FindColumn(PropertyPath.Root.Property("PrecursorConcentration"));

            Assert.IsNotNull(colPrecursorConcentration);
            // These are the concentrations of the light, heavy4, heavy3, heavy2, heavy1
            double[] concentrations = { 0.125, 200, 20, 2, .5 };
            // Set the clipboard text to the list of concentrations repeated twice since there are two peptides
            ClipboardEx.SetText(string.Join(Environment.NewLine, concentrations.Concat(concentrations)));
            RunUI(() =>
            {
                documentGrid.DataGridView.CurrentCell =
                    documentGrid.DataGridView.Rows[0].Cells[colPrecursorConcentration.Index];
                documentGrid.DataGridView.SendPaste();
            });
        }
        private async void CopyExecute()
        {
            var dataPackage = new DataPackage();

            dataPackage.SetText(MeUrlPrefixConverter.Convert(_username));
            ClipboardEx.TrySetContent(dataPackage);

            await TLMessageDialog.ShowAsync(Strings.Android.LinkCopied, Strings.Android.AppName, Strings.Android.OK);
        }
Exemplo n.º 6
0
        private void mCopy_Click(object sender, RoutedEventArgs e)
        {
            string text = this.GetSelectedNodeText();

            if (!string.IsNullOrEmpty(text))
            {
                ClipboardEx.SetTextSafe(text);
            }
        }
Exemplo n.º 7
0
        private async void CopyExecute()
        {
            var dataPackage = new DataPackage();

            dataPackage.SetText(_inviteLink);
            ClipboardEx.TrySetContent(dataPackage);

            await TLMessageDialog.ShowAsync(Strings.Resources.LinkCopied, Strings.Resources.AppName, Strings.Resources.OK);
        }
Exemplo n.º 8
0
        private async void CopyExecute()
        {
            var dataPackage = new DataPackage();

            dataPackage.SetText(ShareLink.AbsoluteUri);
            ClipboardEx.TrySetContent(dataPackage);

            await MessagePopup.ShowAsync(Strings.Resources.LinkCopied, Strings.Resources.AppName, Strings.Resources.OK);
        }
Exemplo n.º 9
0
 /// <summary>
 /// [UI Thread] : クリップボードから文字列を取得する。
 ///
 /// 空の場合や取得できない場合はnullが返る。
 /// </summary>
 /// <returns></returns>
 public static string GetText()
 {
     try
     {
         return(ClipboardEx.GetText());
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 10
0
        private static void OnCopyToClipboardClick(object sender, EventArgs e)
        {
            var item = (ToolStripItem)sender;
            var text = item.Tag as string;

            if (text == null)
            {
                text = ((Func <string>)item.Tag)();
            }
            ClipboardEx.SetTextSafe(text);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 右クリックメニュー「読み筋を表示のままの文字列でクリップボードに貼り付ける(&P)」
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PastePvToClipboard_Click(object sender, EventArgs e)
        {
            if (pvTextOnClick == null)
            {
                return;
            }

            ClipboardEx.SetText(pvTextOnClick);

            ResetContextMenu();
        }
Exemplo n.º 12
0
 private static string GetClipboardText()
 {
     try
     {
         return(ClipboardEx.GetText());
     }
     catch (ExternalException)
     {
         Assert.Fail(ClipboardHelper.GetOpenClipboardMessage("Failure getting data from the clipboard."));
     }
     return(null);
 }
Exemplo n.º 13
0
 private static string GetClipboardHtml()
 {
     try
     {
         return((string)ClipboardEx.GetData(DataFormats.Html));
     }
     catch (ExternalException)
     {
         Assert.Fail(ClipboardHelper.GetOpenClipboardMessage("Failure getting data from the clipboard."));
     }
     return(null);
 }
Exemplo n.º 14
0
 private static string GetClipboardHtml()
 {
     try
     {
         return((string)ClipboardEx.GetData(DataFormats.Html));
     }
     catch (ExternalException)
     {
         Assert.Fail(ClipboardHelper.GetPasteErrorMessage());
     }
     return(null);
 }
Exemplo n.º 15
0
 private static string GetClipboardText()
 {
     try
     {
         return(ClipboardEx.GetText());
     }
     catch (ExternalException)
     {
         Assert.Fail(ClipboardHelper.GetPasteErrorMessage());
     }
     return(null);
 }
        private async void CopyLinkExecute(ProxyViewModel proxy)
        {
            var response = await ProtoService.SendAsync(new GetProxyLink(proxy.Id));

            if (response is Text text && Uri.TryCreate(text.TextValue, UriKind.Absolute, out Uri uri))
            {
                var dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage();
                dataPackage.SetText(text.TextValue);
                ClipboardEx.TrySetContent(dataPackage);
                await MessagePopup.ShowAsync(Strings.Resources.LinkCopied, Strings.Resources.UseProxyTelegram, Strings.Resources.OK);
            }
        }
 private void HandleTextBoxCommandPreviewExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (e.Command == ApplicationCommands.Cut)
     {
         var textBox = (TextBox)sender;
         if (textBox.SelectionLength == textBox.Text.Length)
         {
             ClipboardEx.SetText(textBox.Text);
             SetNullText(textBox);
             e.Handled = true;
         }
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// [UI Thread] : クリップボードに文字列を設定する。
        ///
        /// 注意 : Clipboard.SetText() を実行するスレッドは Single Thread Apartment モードに設定されていなければならない
        /// UI Threadからこのメソッドを呼び出すこと。
        /// </summary>
        /// <param name="o"></param>
        public static void SetText(string s)
        {
            try
            {
                if (s.Empty())
                {
                    return;
                }

                ClipboardEx.SetText(s);
            }
            catch (Exception) { }
        }
Exemplo n.º 19
0
 private static string GetClipBoardText(IWin32Window parent)
 {
     try
     {
         return(ClipboardEx.GetText());
     }
     catch (ExternalException)
     {
         MessageDlg.Show(parent, ClipboardHelper.GetOpenClipboardMessage(
                             Resources.SettingsUIUtil_GetClipBoardText_Failed_getting_data_from_the_clipboard));
         return(null);
     }
 }
Exemplo n.º 20
0
        private async void OnShareToClipboard(ShareProviderOperation operation)
        {
            var webLink = await operation.Data.GetWebLinkAsync();

            var dataPackage = new DataPackage();

            dataPackage.SetText(webLink.ToString());

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                ClipboardEx.TrySetContent(dataPackage);
                operation.ReportCompleted();
            });
        }
Exemplo n.º 21
0
        /// <summary>
        /// 右クリックメニュー「読み筋をKIF形式でクリップボードに貼り付ける(&K)」
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PasteKifToClipboard_Click(object sender, EventArgs e)
        {
            // KIF形式で保存する

            var kifu = KifuManager.ToStringFromRootSfenAndMoves(KifuFileType.KIF,
                                                                boardDataOnRightClick.rootSfen, boardDataOnRightClick.moves);

            if (kifu == null)
            {
                return;
            }

            ClipboardEx.SetText(kifu);

            ResetContextMenu();
        }
Exemplo n.º 22
0
 private static void ExcuteJsInner(string injectJs, int chromeDevHwnd)
 {
     ClipboardEx.UseClipboardWithAutoRestore(() =>
     {
         DispatcherEx.xInvoke(() =>
         {
             ClipboardEx.SetTextSafe(injectJs);
             WinApi.BringTopAndDoAction(chromeDevHwnd, () =>
             {
                 WinApi.PressCtrlV();
                 Thread.Sleep(500);
                 WinApi.PressEnterKey();
             }, 4);
         });
     });
 }
Exemplo n.º 23
0
        public CopyColorForm(Color color, Point invocationOrigin, int indexUnderMouse = 1)
        {
            InitializeComponent();
            SuspendLayout();

            colorBox.Color = color;

            StartPosition = FormStartPosition.Manual;

            var lastLabelPosition = new Point(12, 42);

            for (int i = 0; i < _formats.Count; ++i)
            {
                var format         = _formats[i];
                var formattedColor = format(color);
                var l = new CopyCodeLinkLabel()
                {
                    Text     = formattedColor,
                    Location = new Point(
                        lastLabelPosition.X,
                        lastLabelPosition.Y + 18 + 3
                        ),
                    Padding  = new Padding(0, 0, 0, 10),
                    AutoSize = true,
                };

                l.Click += (s, e) =>
                {
                    ClipboardEx.SetText(formattedColor);
                    Close();
                };

                Controls.Add(l);

                if (i == indexUnderMouse)
                {
                    Location = new Point(
                        invocationOrigin.X - (l.Location.X + 20),
                        invocationOrigin.Y - (l.Location.Y + 20)
                        );
                }

                lastLabelPosition = l.Location;
            }

            ResumeLayout(true);
        }
Exemplo n.º 24
0
        protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.C:
                if (Control.ModifierKeys == Keys.Control)
                {
                    foreach (var p in Panels)
                    {
                        var filePanel = p as FileDiffPanel;
                        if (filePanel != null && filePanel.SelectionLength != 0)
                        {
                            var  lines = filePanel.GetSelectedLines();
                            var  sb    = new StringBuilder();
                            bool first = true;
                            foreach (var line in lines)
                            {
                                if (first)
                                {
                                    first = false;
                                }
                                else
                                {
                                    sb.Append('\n');
                                }
                                sb.Append(line.Text);
                            }
                            if (sb.Length != 0)
                            {
                                if (sb[sb.Length - 1] == '\r')
                                {
                                    sb.Remove(sb.Length - 1, 1);
                                }
                            }
                            ClipboardEx.SetTextSafe(sb.ToString());
                            break;
                        }
                    }

                    e.IsInputKey = true;
                }
                break;
            }
            base.OnPreviewKeyDown(e);
        }
        /// <summary>
        /// Copy the data from the curves in the ZedGraphControl to the clipboard.
        /// </summary>
        public static void CopyGraphData(ZedGraphControl zedGraphControl)
        {
            var graphData = GraphData.GetGraphData(zedGraphControl.MasterPane);

            if (graphData.Panes.Count == 0)
            {
                return;
            }
            try
            {
                ClipboardEx.Clear();
                ClipboardEx.SetText(graphData.ToString());
            }
            catch (ExternalException)
            {
                MessageBox.Show(ClipboardHelper.GetOpenClipboardMessage(Resources.CopyGraphDataToolStripMenuItem_CopyGraphData_Failed_setting_data_to_clipboard), Program.Name);
            }
        }
        /// <summary>
        /// Use the DocumentGrid to set the PrecursorConcentration values on all of the precursors in the document.
        /// </summary>
        private void SetPrecursorConcentrations(DocumentGridForm documentGrid)
        {
            RunUI(() => documentGrid.ChooseView(PRECURSOR_CONCENTRATIONS_VIEW));
            WaitForConditionUI(() => documentGrid.IsComplete);
            var colPrecursorConcentration = documentGrid.DataboundGridControl.FindColumn(
                PropertyPath.Root.Property(nameof(Precursor.PrecursorConcentration)));

            Assert.IsNotNull(colPrecursorConcentration);
            // These are the concentrations of the light, heavy4, heavy3, heavy2, heavy1
            double[] concentrations = { 0.125, 200, 20, 2, .5 };
            // Set the clipboard text to the list of concentrations repeated twice since there are two peptides
            ClipboardEx.SetText(string.Join(Environment.NewLine, concentrations.Concat(concentrations)));
            RunUI(() =>
            {
                documentGrid.DataGridView.CurrentCell =
                    documentGrid.DataGridView.Rows[0].Cells[colPrecursorConcentration.Index];
                documentGrid.DataGridView.SendPaste();
            });
        }
Exemplo n.º 27
0
        private void CopyToClipboard()
        {
            const string separator = "---------------------------";

            var sb = new StringBuilder();

            sb.AppendLine(separator);
            sb.AppendLine(_title);
            sb.AppendLine(separator);
            sb.AppendLine(_message);
            sb.AppendLine(separator);
            foreach (var button in _buttons)
            {
                sb.Append(button.Text);
                sb.Append("   ");
            }
            sb.AppendLine();
            sb.AppendLine(separator);
            ClipboardEx.SetTextSafe(sb.ToString());
        }
Exemplo n.º 28
0
        public void CopyMessage()
        {
            const string  separator = "---------------------------"; // Not L10N
            List <string> lines     = new List <String>();

            lines.Add(separator);
            lines.Add(Text);
            lines.Add(separator);
            lines.Add(Message);
            lines.Add(separator);
            lines.Add(TextUtil.SpaceSeparate(VisibleButtons.Select(btn => btn.Text)));
            if (null != DetailMessage)
            {
                lines.Add(separator);
                lines.Add(DetailMessage);
            }
            lines.Add(separator);
            lines.Add(string.Empty);
            ClipboardEx.SetText(TextUtil.LineSeparate(lines));
        }
Exemplo n.º 29
0
        public void PasteNewText()
        {
            DocumentFragment clipboardDocument     = null;
            string           clipboardText         = null;
            bool             clipboardContainsData = false;

            if (ClipboardEx.ContainsDocument(null))
            {
                clipboardDocument     = ClipboardEx.GetDocument();
                clipboardContainsData = true;
            }
            else if (ClipboardEx.ContainsText(null))
            {
                clipboardText         = ClipboardEx.GetText(null);
                clipboardContainsData = true;
            }

            if (!clipboardContainsData)
            {
                return;
            }

            this.radRichTextEditor1.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas"));

            if (clipboardDocument != null)
            {
                RadDocument       doc    = new RadDocument();
                RadDocumentEditor editor = new RadDocumentEditor(doc);
                editor.InsertFragment(clipboardDocument);

                string text = provider.Export(doc);

                this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.Insert(text);
            }
            else if (!string.IsNullOrEmpty(clipboardText))
            {
                this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.Insert(clipboardText);
            }
        }
Exemplo n.º 30
0
        public static void InvokeUploadFinishedUI(UploadResult result, HSSettings settingsContext)
        {
            Debug.Assert(result != null);
            Debug.Assert(!string.IsNullOrWhiteSpace(result.Url));

            switch (settingsContext.ActionAfterUpload)
            {
            case UploadHandlingAction.Flyout:
                (new UploadResultForm(result, settingsContext)).Show();
                break;

            case UploadHandlingAction.CopyToClipboard:
            {
                var success = ClipboardEx.SetText(result.Url);
                if (settingsContext.ShowCopyConfirmation)
                {
                    if (success)
                    {
                        NotificationManager.ShowCopyConfirmation(result.Url);
                    }
                    else
                    {
                        NotificationManager.CopyingFailed(result.Url);
                    }
                }
            }
            break;

            case UploadHandlingAction.None:
                // Intentionally left empty
                break;

            default:
                // Intentionally left empty
                break;
            }
        }