Powershell GUI fronted (WPF) to run categorized console scripts

⌈⌋ branch:  ClickyColoury


Artifact [7498e4f440]

Artifact 7498e4f440d7af54ab1c345ab57a19f13cd6f2ca:

  • File contrib/RichtextboxCopyPlainText.ps1 — part of check-in [8e78d588f1] at 2018-05-18 17:57:05 on branch trunk — Simpler Start-Process doesn't work. PS does not escape double quotes in -ArgumentList properly, nor allows escaping with standard CMD ^ caret etc. (user: mario size: 1045)

# encoding: utf-8
# api: clicky
# type: init-gui
# version: 0.2
# title: Copy plain text
# description: override ⌨[Ctl-C] and [Ins] to copy just text/plain from color output
# category: ui
# state: stable
# hidden: 1
# nomenu: 1
#
# That's a workaround, which prevents copying RTF from RichTextBox/FlowDoc.
# Only extracts/converts from the current text selection.
#

# hook keyboard handler on FlowDocumentViewer/RichTextBox
$GUI.output.parent.Add_KeyUp({
    Param($sender, $evt)
    # Event object $evt contains .Key, and .KeyboardDevice.Modifiers
    if (
        ($evt.Key -eq "Insert") -or
        ($evt.Key -eq "C") -and ($evt.KeyboardDevice.Modifiers -eq "Control")
    ) {
        # get currently selected text(range)
        if ($s = $GUI.Output.parent.Selection) {
            $tr = New-Object System.Windows.Documents.TextRange -ArgumentList @($s.Start,$s.End)
            if ($tr) {
                Set-Clipboard ($tr.Text)
                $evt.handled = $true
            }
        }
    }
})