Ui

uI- and webview-related helpers


Functions


The UI module provides functionality for creating basic desktop interactions, managing clipboard content, and displaying web-based user interfaces through webviews.

Key Concepts

  • System dialogs and alerts
  • Clipboard operations
  • Web-based interfaces via webview
  • File selection dialogs
  • User notifications

Basic Usage

System Dialogs

; basic popup
result: popup "Warning" "Are you sure?"

; different dialog types
popup.info "Info" "Operation complete"
popup.warning "Warning" "Low disk space"
popup.error "Error" "Connection failed"

; with different buttons
response: popup.yesNo "Question" "Save changes?"
response: popup.okCancel "Confirm" "Proceed?"
response: popup.retryCancel "Failed" "Try again?"

System Notifications

; basic notification
alert "Title" "Message"

; with different types
alert.info "Info" "Download complete"
alert.warning "Warning" "Battery low"
alert.error "Error" "Update failed"

File Selection

; select file
file: dialog "Select file"

; select folder
folder: dialog.folder "Select folder"

; with starting path
config: dialog .path: "~/Documents" "Select config"

Clipboard Operations

; set clipboard content
clip "text to copy"

; get clipboard content
text: unclip
print ["Clipboard contains:" text]

WebView Interface

; basic webview with HTML content
webview {
    <html>
        <body>
            <h1>Hello World</h1>
        </body>
    </html>
}

; with custom window properties
webview
    .title:"My App"
    .width: 800
    .height: 600
    .fixed: true 
    .debug
{!html
    <html>
        <body>
            <h1>Custom Window</h1>
        </body>
    </html>
}

Tip
If you are using a text editor that supports this syntax (e.g. VSCode), using !html in front of {..}-enclosed blocks will enable proper HTML highlighting.

Tip
WebView's .debug attribute opens Chrome's DevTools for easier development and debugging.

Common Patterns

Interactive Dialog Flow

getUserInput: function [default][
    response: popup.okCancel "Input needed" "Use default settings?"
    if response -> 
        return default
    
    file: dialog "Select custom config"
    if empty? file ->
        return default
        
    return file
]

; usage
config: getUserInput "config.ini"

Note
Dialog or popup buttons, behavior and general look'n'feel might vary slightly depending on the operating system.

Clipboard Manager

define :clipboardManager [
    history: []
    
    save: method [text][
        clip text
        \history: \history ++ text
    ]
    
    last: method [][
        if empty? \history -> 
            return null
            
        return last \history
    ]
    
    clear: method [][
        clip ""
        \history: []
    ]
]

; usage
clipboardManager: to :clipboardManager []!

clipboardManager\save "important text"
previous: clipboardManager\last