Code:
{define-proc public {paste-data grid:RecordGrid}:void
def c ={Clipboard.get-system-clipboard}
def data = {c.get-string}
||貼り付け範囲の測定(行、列の最大)
let rows:int = 0
let cols:int = 0
def lines = {data.split split-chars = '\n'}
set rows = lines.size
{for ln in lines do
set cols ={max cols, {ln.split split-chars = '\t'}.size}
}
{if-non-null cell = grid.ui.grid-focus then
{if-non-null col = cell.column then
||貼り付け範囲の作成
def first-row:int = cell.record-index
def first-column:int = {grid.columns.find col}
def row-count:int = {min rows, grid.records.size - first-row}
def column-count:int = {min cols, grid.columns.size - first-column}
def region = {RecordGridRegion first-row,first-column ,row-count, column-count}
||++ {popup-message
||++ {VBox
||++ "貼り付け範囲",
||++ {Table columns= 2,
||++ "コピー行数", rows, "コピー列数", cols,
||++ "開始行",first-row, "開始列",first-column,
||++ "範囲行数", row-count, "範囲列数", column-count
||++ }
||++ }
||++ }
||範囲の選択と貼り付け
{with grid.region-selection-enabled? = true do
{grid.select-region region}
{grid.do-command "paste"}
}
||表示位置のリセット
set grid.current-index = cell.record-index
}
}
}
{def rf-list =
{{Array-of RecordField}}
}
{def cols = 20}
{def rows = 20}
{for i:int = 1 to cols do
{rf-list.append
{RecordField {String i}, nullable?= true}
}
}
{def rfs =
{RecordFields
{RecordField "index", nullable?= true}
,{RecordField "select", domain = bool}
,{splice rf-list}
}
}
{def rs = {RecordSet rfs}}
{for i:int = 1 to rows do
def new-r = {rs.new-record}
set new-r["index"] = i
{for j:int = 1 to cols do
set new-r[{String j}] = {String i * j}
}
{rs.append new-r}
}
{def grid = {RecordGrid width = 8in, height = 3in, record-source = rs }}
{value grid}
{def paste-cb = {CommandButton label = "貼り付け", {on Action do {paste-data grid}}}}
{def copy-cb =
{CommandButton
label = "コピー",
{on Action do
{grid.select-all}
{grid.do-command "copy"}
{grid.select-nothing}
}
}
}
{HBox copy-cb, paste-cb}