Compare commits
145
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dff9ed3bf4
|
||
|
|
a354340237
|
||
|
|
aad589a6ab
|
||
|
|
8429d9e421
|
||
|
|
90f6d17bec
|
||
|
|
6b3ba569dd
|
||
|
|
bc133169e3
|
||
|
|
3d20036bff
|
||
|
|
7e479a96f8
|
||
|
|
86bb0d4e1c
|
||
|
|
2182b71f1f
|
||
|
|
bd7bc46d8c
|
||
|
|
547dbf2cc5
|
||
|
|
a28e618c07
|
||
|
|
15a54bcf2e
|
||
|
|
a49b0b5db3
|
||
|
|
301365a7e6
|
||
|
|
d7a4c37c1f
|
||
|
|
4cec71703b
|
||
|
|
f01150be05
|
||
|
|
da81ebd777
|
||
|
|
b46fedb327
|
||
|
|
33df906449
|
||
|
|
b7e2c56272
|
||
|
|
5c345b6f7c
|
||
|
|
41a99962aa
|
||
|
|
fd6e651478
|
||
|
|
f27e73575d
|
||
|
|
843657a6b3
|
||
|
|
18158a8282
|
||
|
|
759d84e20b
|
||
|
|
345e248ff7
|
||
|
|
6145b5cea2
|
||
|
|
0c87b0bbf7
|
||
|
|
4d7ec45027
|
||
|
|
798e00571a
|
||
|
|
7a12a28b67
|
||
|
|
201aa4fc5a
|
||
|
|
40cd554953
|
||
|
|
022978bb9b
|
||
|
|
fde97a01a9
|
||
|
|
b03c9f2853
|
||
|
|
fa273aff13
|
||
|
|
096b7f8fd4
|
||
|
|
9b1b64884b | ||
|
|
623bc085f6
|
||
|
|
383a1ea467
|
||
|
|
6bf5d6c7e6
|
||
|
|
c9bfccc91c
|
||
|
|
4d8d5a6ef5
|
||
|
|
04040a2a03
|
||
|
|
139e8f6250
|
||
|
|
1f4807c81c
|
||
|
|
ec87e28a46
|
||
|
|
8a915ea354
|
||
|
|
943411fb1a
|
||
|
|
ab85673eea
|
||
|
|
f9bf82e3f8
|
||
|
|
a6d8a1de43
|
||
|
|
ecf977364b
|
||
|
|
c52e1a3b16
|
||
|
|
63bf0cc828
|
||
|
|
380e6783d6
|
||
|
|
e4ca134655
|
||
|
|
4efe14bce7
|
||
|
|
eee3b9e288
|
||
|
|
b3fc6c9c82
|
||
|
|
8a7e45d901
|
||
|
|
47b05b52fa
|
||
|
|
81487fb32d
|
||
|
|
326fe24cba
|
||
|
|
35165139a8
|
||
|
|
9a126611a2
|
||
|
|
511fb8d4eb
|
||
|
|
b243515190
|
||
|
|
ff790e31cf
|
||
|
|
cc589a07b3
|
||
|
|
3c6faf9a6e
|
||
|
|
f4dad1d269
|
||
|
|
409805e863
|
||
|
|
ecd849601b
|
||
|
|
65d79295ec
|
||
|
|
301890485f
|
||
|
|
5b81c5acf2
|
||
|
|
6445f3144d
|
||
|
|
2c3f3894dd
|
||
|
|
03bcbab5ce
|
||
|
|
1bf693f7ab
|
||
|
|
44a61443fa
|
||
|
|
844d98559b
|
||
|
|
db1e889f15
|
||
|
|
2537472bd3
|
||
|
|
3f567bf4a0
|
||
|
|
b870ba9d41
|
||
|
|
50e18d835e
|
||
|
|
b591aa8625
|
||
|
|
efe5d4fc5d
|
||
|
|
c77bd2a281
|
||
|
|
f28768634f
|
||
|
|
7049a6a4aa
|
||
|
|
be33bb28aa
|
||
|
|
cc67055ccc
|
||
|
|
e85884212b
|
||
|
|
c5e19eb0b5
|
||
|
|
5a6c17757e
|
||
|
|
0ce468a3ad
|
||
|
|
f4c1a1665b
|
||
|
|
fbcf654812
|
||
|
|
6f90a7dc53
|
||
|
|
d4c5f90c87
|
||
|
|
69b299f2db
|
||
|
|
bb3120ebe4
|
||
|
|
e1950f9121
|
||
|
|
1cf81dcb44
|
||
|
|
05c3eab2f8
|
||
|
|
1b1148a410
|
||
|
|
9fe28f072b
|
||
|
|
5e2cf83da8
|
||
|
|
48e83a9b45
|
||
|
|
56855acfb4
|
||
|
|
eb844cc72c
|
||
|
|
a3d29bec81
|
||
|
|
371b1e81c8
|
||
|
|
286631daf9
|
||
|
|
ee98f6d7c0
|
||
|
|
be31260753
|
||
|
|
0d529e1b0d
|
||
|
|
148885248b
|
||
|
|
78a0158956
|
||
|
|
4f4bf5c35c
|
||
|
|
c078d3d0a7
|
||
|
|
92702273df
|
||
|
|
cf04a100ff
|
||
|
|
034cbfce02
|
||
|
|
f6f4b95108
|
||
|
|
b5d490c49a
|
||
|
|
1745ee237d
|
||
|
|
466afe20a0
|
||
|
|
5a36ffc272
|
||
|
|
41fe64c74d
|
||
|
|
a9f093ca26
|
||
|
|
f5455ecd36
|
||
|
|
9df123ff94
|
||
|
|
5162692902
|
||
|
|
aeeccb4696
|
No files matched your search
@@ -0,0 +1,5 @@
|
||||
# Internal records stay out of source archives.
|
||||
agents.md export-ignore
|
||||
CLAUDE.md export-ignore
|
||||
PRD.md export-ignore
|
||||
tasks export-ignore
|
||||
@@ -1,77 +0,0 @@
|
||||
# Builds the patched engines once; release.yml downloads them.
|
||||
name: engines
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
macos:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- runner: macos-15
|
||||
arch: arm64
|
||||
- runner: macos-15-intel
|
||||
arch: x86_64
|
||||
runs-on: ${{ matrix.runner }}
|
||||
timeout-minutes: 355
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
CCACHE_DIR: ${{ github.workspace }}/.ccache
|
||||
CCACHE_MAXSIZE: 6G
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Key
|
||||
id: key
|
||||
run: echo "key=$(scripts/engines-key.sh)" >> "$GITHUB_OUTPUT"
|
||||
- name: Already built?
|
||||
id: done
|
||||
run: |
|
||||
if gh release view "engines-${{ steps.key.outputs.key }}" --json assets \
|
||||
--jq '.assets[].name' 2>/dev/null | grep -qx "engines-macos-${{ matrix.arch }}.tar.zst"; then
|
||||
echo "built=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
- name: Tools
|
||||
if: steps.done.outputs.built != 'true'
|
||||
run: brew install make gnu-sed bison flex gettext autoconf automake libtool ccache nasm zstd
|
||||
- name: Compiler cache
|
||||
if: steps.done.outputs.built != 'true'
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: .ccache
|
||||
key: ccache-macos-${{ matrix.arch }}-${{ steps.key.outputs.key }}-${{ github.run_id }}
|
||||
restore-keys: ccache-macos-${{ matrix.arch }}-
|
||||
- name: Upstream sources
|
||||
if: steps.done.outputs.built != 'true'
|
||||
run: scripts/fetch-references.sh
|
||||
- name: LibreOffice (patched)
|
||||
if: steps.done.outputs.built != 'true'
|
||||
run: scripts/build-libreoffice.sh
|
||||
- name: MuPDF (patched), Git, git-lfs, OCR data, CEF
|
||||
if: steps.done.outputs.built != 'true'
|
||||
run: |
|
||||
scripts/build-mupdf.sh
|
||||
scripts/build-git.sh
|
||||
scripts/fetch-git-lfs.sh
|
||||
scripts/fetch-tessdata.sh
|
||||
scripts/fetch-cef.sh
|
||||
- name: Keep the compiler cache, even after a timeout
|
||||
if: always() && steps.done.outputs.built != 'true'
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: .ccache
|
||||
key: ccache-macos-${{ matrix.arch }}-${{ steps.key.outputs.key }}-${{ github.run_id }}
|
||||
- name: Publish
|
||||
if: steps.done.outputs.built != 'true'
|
||||
run: |
|
||||
archive=engines-macos-${{ matrix.arch }}.tar.zst
|
||||
tar -C engines -cf - lo-src/instdir mupdf-build mupdf-src git git-src/COPYING git-src/LGPL-2.1 cef tessdata |
|
||||
zstd -19 -T0 -o "$archive"
|
||||
tag=engines-${{ steps.key.outputs.key }}
|
||||
gh release view "$tag" >/dev/null 2>&1 ||
|
||||
gh release create "$tag" --prerelease --title "$tag" --notes "Pinned, patched engines; built by engines.yml."
|
||||
gh release upload "$tag" "$archive" --clobber
|
||||
@@ -1,58 +0,0 @@
|
||||
# Builds macOS apps for a release tag and attaches them.
|
||||
name: release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: Release tag to attach the packages to, such as v0.1.0
|
||||
required: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
macos:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- runner: macos-15
|
||||
arch: arm64
|
||||
- runner: macos-15-intel
|
||||
arch: x86_64
|
||||
runs-on: ${{ matrix.runner }}
|
||||
timeout-minutes: 120
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ inputs.tag }}
|
||||
- name: Engines
|
||||
run: |
|
||||
brew install zstd
|
||||
tag=engines-$(scripts/engines-key.sh)
|
||||
gh release download "$tag" --pattern "engines-macos-${{ matrix.arch }}.tar.zst" ||
|
||||
{ echo "::error::no $tag for ${{ matrix.arch }}; run the engines workflow first"; exit 1; }
|
||||
mkdir -p engines
|
||||
zstd -dc "engines-macos-${{ matrix.arch }}.tar.zst" | tar -C engines -xf -
|
||||
- name: Upstream sources and ElyMark's page
|
||||
run: |
|
||||
scripts/fetch-references.sh
|
||||
scripts/build-mark-content.sh
|
||||
- name: Tests that need no window
|
||||
run: |
|
||||
tests/scripts/types.sh
|
||||
tests/scripts/icons.sh
|
||||
python3 tests/scripts/comments.py
|
||||
- name: Packages
|
||||
run: packaging/macos/release.sh 1
|
||||
- name: Attach to the release
|
||||
run: |
|
||||
version=${{ inputs.tag }}
|
||||
gh release view "$version" >/dev/null 2>&1 || gh release create "$version" --title "Ely Office $version" --notes "Built by release.yml."
|
||||
gh release upload "$version" dist/*.dmg --clobber
|
||||
if [ "${{ matrix.arch }}" = arm64 ]; then
|
||||
gh release upload "$version" dist/ElyOffice-*-source.tar.gz dist/ElyOffice-*-upstream-source.tar.gz --clobber
|
||||
fi
|
||||
@@ -0,0 +1,15 @@
|
||||
# Contributing
|
||||
|
||||
## Opening a pull request on git.zacharyzhang.com
|
||||
|
||||
Forking is disabled on this server. Open pull requests with AGit instead:
|
||||
|
||||
1. Register an account at https://git.zacharyzhang.com
|
||||
2. Clone, commit your changes, then push to a `refs/for/<target-branch>` ref:
|
||||
|
||||
```bash
|
||||
git clone https://git.zacharyzhang.com/ZacharyZhang-NY/ElyOffice.git
|
||||
git push origin HEAD:refs/for/main -o topic=<short-name> -o title="<PR title>" -o description="<PR body>"
|
||||
```
|
||||
|
||||
3. To update the pull request, push again with the same `topic`.
|
||||
Generated
+18
-17
@@ -1919,7 +1919,7 @@ checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34"
|
||||
|
||||
[[package]]
|
||||
name = "ely-agent"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"ely-platform",
|
||||
"ely-ui",
|
||||
@@ -1927,7 +1927,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-doc"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"csv",
|
||||
@@ -1948,7 +1948,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-files"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"ely-platform",
|
||||
@@ -1964,7 +1964,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ely-gpui-component"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/ZacharyZhang-NY/Ely-GPUI-Components?rev=69265b4fd4da888e2d8e1268021af4d358e67afb#69265b4fd4da888e2d8e1268021af4d358e67afb"
|
||||
source = "git+https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components?rev=5d6efd46ec0c93b381ec7578561a1273c366025b#5d6efd46ec0c93b381ec7578561a1273c366025b"
|
||||
dependencies = [
|
||||
"alacritty_terminal",
|
||||
"anyhow",
|
||||
@@ -2001,14 +2001,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-ipc"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ely-lok"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"ely-gpui-component",
|
||||
@@ -2028,7 +2028,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-mail"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"ely-platform",
|
||||
"ely-ui",
|
||||
@@ -2036,7 +2036,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-mark"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.23.1",
|
||||
@@ -2058,7 +2058,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-office"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"directories",
|
||||
@@ -2078,7 +2078,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-pdf"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"ely-files",
|
||||
"ely-gpui-component",
|
||||
@@ -2094,7 +2094,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-pdf-engine"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"ely-ipc",
|
||||
@@ -2110,7 +2110,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-platform"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arboard",
|
||||
@@ -2143,7 +2143,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-show"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"ely-files",
|
||||
"ely-gpui-component",
|
||||
@@ -2162,7 +2162,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-table"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"ely-gpui-component",
|
||||
"ely-lok",
|
||||
@@ -2178,7 +2178,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-tree"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"ely-files",
|
||||
"ely-gpui-component",
|
||||
@@ -2196,7 +2196,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ely-ui"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"directories",
|
||||
@@ -2207,13 +2207,14 @@ dependencies = [
|
||||
"gpui-pre-platform",
|
||||
"log",
|
||||
"notify",
|
||||
"semver",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ely-web-content"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cef",
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ members = ["apps/*", "crates/*"]
|
||||
exclude = ["engines", "reference"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
edition = "2024"
|
||||
rust-version = "1.95"
|
||||
license = "AGPL-3.0-or-later"
|
||||
@@ -17,7 +17,7 @@ encoding_rs = "0.8"
|
||||
jiff = "0.2"
|
||||
anyhow = "1"
|
||||
directories = "6"
|
||||
ely-gpui-component = { git = "https://github.com/ZacharyZhang-NY/Ely-GPUI-Components", rev = "69265b4fd4da888e2d8e1268021af4d358e67afb" }
|
||||
ely-gpui-component = { git = "https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components", rev = "5d6efd46ec0c93b381ec7578561a1273c366025b" }
|
||||
env_logger = "0.11"
|
||||
gpui = { package = "gpui-pre", version = "=0.3.8", default-features = false, features = ["stacker"] }
|
||||
gpui_platform = { package = "gpui-pre-platform", version = "=0.3.8", features = ["font-kit"] }
|
||||
|
||||
@@ -529,7 +529,7 @@ AI 或脚本修改文件与其他外部修改使用同一套处理规则。ElyMa
|
||||
|
||||
### 15.2 接入基线
|
||||
|
||||
后端以 Kigi CLI(https://github.com/ZacharyZhang-NY/Kigi-CLI,Rust)为基础,以 Rust 依赖直接嵌入,不用 ACP(用户 2026-10-05 定)。提供商登录(订阅账号或 API 密钥)、模型与端点配置沿用 Kigi 的实现,不另写一套。不解析终端装饰文本来伪造结构化事件。
|
||||
后端以 Kigi CLI(https://git.zacharyzhang.com/ZacharyZhang-NY/Kigi-CLI,Rust)为基础,以 Rust 依赖直接嵌入,不用 ACP(用户 2026-10-05 定)。提供商登录(订阅账号或 API 密钥)、模型与端点配置沿用 Kigi 的实现,不另写一套。不解析终端装饰文本来伪造结构化事件。
|
||||
|
||||
会话恢复只在 Kigi 的会话存储支持并通过验证时启用。不能把本地历史回放当成后端会话已经恢复。
|
||||
|
||||
@@ -870,10 +870,10 @@ UI 自动测试、内核测试和手工交互测试互相补充。三端的输
|
||||
核对日期:2026-10-01。来源用于确认接口、项目结构和许可条件,不证明 Ely 已完成接入。产品功能、默认设置与性能目标由本文定义。正式实现应记录所采用版本的固定提交和许可证,而不是只引用默认分支。
|
||||
|
||||
[S1] Ely GPUI Components,README,组件库使用方式、主题及许可证。
|
||||
`https://github.com/ZacharyZhang-NY/Ely-GPUI-Components/blob/main/README.md`
|
||||
`https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components/blob/main/README.md`
|
||||
|
||||
[S2] Ely GPUI Components,TASKS,组件分类与 host/prove 等状态定义。
|
||||
`https://github.com/ZacharyZhang-NY/Ely-GPUI-Components/blob/main/TASKS.md`
|
||||
`https://git.zacharyzhang.com/ZacharyZhang-NY/Ely-GPUI-Components/blob/main/TASKS.md`
|
||||
|
||||
[S3] LibreOfficeKit 官方文档,C/C++ 接口、分块渲染和输入回调。
|
||||
`https://docs.libreoffice.org/libreofficekit.html`
|
||||
|
||||
@@ -39,7 +39,7 @@ site/ 官网(Vite 8、pnpm、TypeScript,无框架;等轴 SVG 积木
|
||||
|
||||
## 组件映射
|
||||
|
||||
依赖 `ely-gpui-component`(pin 69265b4,gpui 为 crates.io 的 `gpui-pre` =0.3.8)。名字取自 `reference/Ely-GPUI-Components/src`。gpui 用法规则见该仓库 `AGENTS.md`。`tests/scripts/agents_md.py` 核对下表每个名字都是组件库公开项。
|
||||
依赖 `ely-gpui-component`(pin 5d6efd4,gpui 为 crates.io 的 `gpui-pre` =0.3.8)。名字取自 `reference/Ely-GPUI-Components/src`。gpui 用法规则见该仓库 `AGENTS.md`。`tests/scripts/agents_md.py` 核对下表每个名字都是组件库公开项。
|
||||
|
||||
| 需要 | 用 |
|
||||
| --- | --- |
|
||||
@@ -139,7 +139,10 @@ packaging/icons/build.sh 由 assets/icons 的母版渲染 icns、png、ico
|
||||
tests/scripts/icons.sh 八个图标齐全、未过期,macOS 为 squircle,其余无底形
|
||||
tests/scripts/release-macos.sh dist 里首批六个 .app:以访达的方式打开文件(启动与运行中),引擎都取自包内,带齐许可,不含系统会登记的内嵌包,每个二进制要求的系统不高于应用所写;源码包齐全
|
||||
tests/scripts/hardened-macos.sh ELY_SIGN_IDENTITY 签名(hardened runtime)的 ElyMark 照样画出页面
|
||||
tests/engines/*.sh 引擎探测(LOK、MuPDF、libetpan)
|
||||
tests/engines/*.sh 引擎探测(LOK、MuPDF、libetpan);LOK 探测本构建的内核,不挂载官方镜像
|
||||
scripts/inert-lo.sh 路径.app 构建出的 LibreOffice.app 去掉文档类型、URL 类型、快速查看与聚焦插件并注销(build-libreoffice.sh 调用)
|
||||
scripts/extract-official-lo.sh 用 7zz 把官方镜像的 Frameworks 与 Resources 解到 engines/lo-official(不挂载,无包,“未打补丁即拒绝”的单测用)
|
||||
tests/scripts/lo-unregistered.sh “打开方式”里没有 LibreOffice,构建出的包不声明任何文件类型
|
||||
tests/scripts/lokview.sh 真窗口里的 LokView:输入法、键入、点击、拖动,AX 树里的段落文本;ELY_CLIPBOARD_TEST=1 再测复制粘贴(会覆盖系统剪贴板)
|
||||
tests/scripts/doc-shell.sh 真窗口 ElyDoc:空白标签进 AX 树,启动后 Cmd+N 打开新建对话框(需辅助功能权限)
|
||||
tests/scripts/doc-props.sh 真窗口 ElyDoc 属性栏:段前段后连续键入、回车、失焦,读 AX 值与命令数(需辅助功能权限)
|
||||
@@ -155,6 +158,9 @@ tests/scripts/mark-output.sh 真窗口 ElyMark:专注模式与外观持久
|
||||
tests/scripts/mark-outside.sh 真窗口 ElyMark:外部替换、改名、删除、冲突比较、自动保存、退出与崩溃后的恢复(需辅助功能权限)
|
||||
tests/scripts/mark-tools.sh 真窗口 ElyMark:查找替换、正则、Tab、列表、表格、拖放与粘贴图片(需辅助功能权限;ELY_CLIPBOARD_TEST=1 再测粘贴)
|
||||
tests/scripts/comments-rules.sh comments.py 对长注释与跨行注释报错
|
||||
tests/scripts/bad-settings.sh 通用设置读不出时 ElyDoc 照样启动,文件不被覆盖
|
||||
tests/scripts/one-instance.sh 第二份 ElyDoc 被拒,第一份的工作目录不动
|
||||
tests/scripts/update.sh 装好的 ElyTree 从本机服务的新版下载、替换、重新打开(需辅助功能权限)
|
||||
tests/scripts/settings.sh 真窗口:ElyPDF 设置里选深色,ElyTree 即刻变深;作者名写入、不丢外观;ElyTree 拒绝非 Git 程序;设置文件读不出时提示且不覆盖;主窗口重开回到原处(需辅助功能与屏幕录制权限)
|
||||
tests/scripts/privacy.sh 真窗口 ElyDoc:键入的文字不进日志;worker 的日志进应用日志;设置里的诊断先列出所含内容,导出的文件去掉家目录与姓名、不含正文(需辅助功能权限)
|
||||
tests/scripts/panels.sh 真窗口 ElyDoc:左侧栏默认不宽于 230、拖动内侧边缘变宽、宽度存入设置、重启后照旧(需辅助功能权限)
|
||||
@@ -163,12 +169,14 @@ tests/scripts/recovery.sh 真窗口 ElyDoc:恢复点、崩溃后副本、
|
||||
tests/scripts/pdf-recovery.sh 真窗口 ElyPDF:加锁文件的封存恢复点、空闲引擎退出后重开时再问密码(需辅助功能权限)
|
||||
tests/scripts/autosave.sh 真窗口 ElyDoc:自动保存开关、停手即写、外部改动不覆盖(需辅助功能权限)
|
||||
tests/scripts/print.sh 真窗口 ElyDoc:打印用文档自己的纸张,取消不动文档(需辅助功能权限)
|
||||
tests/scripts/show-fullscreen.sh 真窗口 ElyShow:F5 放映的窗口盖住整块屏幕(菜单栏与程序坞之上,需辅助功能权限)
|
||||
tests/scripts/types.sh packaging/types.tsv 的文件类型在 Linux 桌面项、Windows 安装程序与 macOS 文档类型里一致,从不设为默认
|
||||
tests/scripts/layout.sh 真窗口:六个应用在 640、800、1100 宽下无元素越出窗口左右,留截图(需辅助功能与屏幕录制权限)
|
||||
tests/scripts/ooxml.py <用例> <文件> 不经 LibreOffice 读 DOCX、XLSX、PPTX 并按自算的预期核对(往返用例调用)
|
||||
tests/scripts/webview.sh 真窗口 CEF 页面:输入法组字与提交、键入、焦点、主题变量、缩放、不可离开所在文件夹
|
||||
cd site && pnpm deploy 官网构建并经 wrangler 发到 Cloudflare Workers(只有静态资源),地址 https://ely-office.zhangyanghaha0407.workers.dev
|
||||
cd site && pnpm test && pnpm e2e 官网单测(几何、道路连通)与 Playwright 端到端(悬停、聚焦、按压、命中归属)
|
||||
cd site/video/scenes && npm run verify 发布视频:群像与离场两个渲染器在切场处屏幕角点一致,离场全程各屏播自己的录屏帧(真页面渲染)
|
||||
cargo check --workspace
|
||||
cargo test --workspace
|
||||
rm -rf target/debug/incremental 每次构建或测试后都删(用户定:增量缓存会占满磁盘)
|
||||
@@ -179,8 +187,8 @@ cargo run -p ely-doc 启动一个应用(ElyDoc 先 cargo build -p ely
|
||||
|
||||
## 决策
|
||||
|
||||
- 2026-10-01:上游版本以 `scripts/fetch-references.sh` 为准。LibreOffice 26.2.6(8221e31)、MuPDF 1.28.5(8ad45e9)、gpui 为 `gpui-pre` =0.3.8 与 `gpui-pre-platform` =0.3.8(crates.io,2026-10-07 起,随组件库 K01)、组件库 69265b4(2026-10-08 起)。
|
||||
- 2026-10-02:组件库 7380afb 起:对话框与面板的 Enter 提交改走字段的 key-down 动作(macOS IME 天然守卫,不再提前提交);面板族文案经组件 `i18n::text`(内建 en/zh-CN,应用目录可覆盖);核心控件带 role/aria;对话框带角色、名称与说明,Cancel/Close 与禁用说明本地化。同仓库 `~/Documents/GitHub/Ely-GPUI-Components` 修复并经 SSH 推送(本机 HTTPS keychain 令牌失效)。2026-10-04 组件库 b6cb94c:`NumberInput::on_commit` 只在 Enter、失焦、步进、拖动时触发,键入不触发;改文档的数值框用它,否则每个键入数字都成一条内核命令与一步撤销。同批带入上游的 Checkbox、Switch、Select 等 role/aria 与 RenderSurface。c0f17ee:`ToggleButton::disabled`(不可按、无 Tab 停靠、说明不可用,提示可写原因)。967d1e4:`ContextMenu::manual`(按属主编号的请求在某点打开,右键不开),供行在按下之后才到的菜单,如内核给的拼写建议。
|
||||
- 2026-10-01:上游版本以 `scripts/fetch-references.sh` 为准。LibreOffice 26.2.6(8221e31)、MuPDF 1.28.5(8ad45e9)、gpui 为 `gpui-pre` =0.3.8 与 `gpui-pre-platform` =0.3.8(crates.io,2026-10-07 起,随组件库 K01)、组件库 5d6efd4(2026-10-09 起)。
|
||||
- 2026-10-02:组件库 7380afb 起:对话框与面板的 Enter 提交改走字段的 key-down 动作(macOS IME 天然守卫,不再提前提交);面板族文案经组件 `i18n::text`(内建 en/zh-CN,应用目录可覆盖);核心控件带 role/aria;对话框带角色、名称与说明,Cancel/Close 与禁用说明本地化。同仓库 `~/Documents/GitHub/Ely-GPUI-Components` 修复并推送(2026-10-09 起推到 git.zacharyzhang.com,HTTPS,令牌在本机钥匙串)。2026-10-04 组件库 b6cb94c:`NumberInput::on_commit` 只在 Enter、失焦、步进、拖动时触发,键入不触发;改文档的数值框用它,否则每个键入数字都成一条内核命令与一步撤销。同批带入上游的 Checkbox、Switch、Select 等 role/aria 与 RenderSurface。c0f17ee:`ToggleButton::disabled`(不可按、无 Tab 停靠、说明不可用,提示可写原因)。967d1e4:`ContextMenu::manual`(按属主编号的请求在某点打开,右键不开),供行在按下之后才到的菜单,如内核给的拼写建议。
|
||||
- 2026-10-06:审查者为探针复制的源码树须用自己的 `CARGO_TARGET_DIR`(`scripts/review.sh` 写明);写完结论前删掉这些副本与其构建目录(曾积到 /tmp 近 900 GB,磁盘写满、链接失败):曾编进本仓库 `target/`,ely-lok 里烘焙的源码路径指向已删的副本,单测找不到 worker。
|
||||
- 2026-10-03:每条任务由 `scripts/review.sh` 在 herdr 分栏里交给 codex(gpt-6.1-sol,effort high;本机 `codex` 别名已带 `--yolo`,重复传参会报错)审查,最多三轮。此前各轮用 gpt-6-astra xhigh。
|
||||
- 2026-10-01:macOS 的 LOK 用自建 LibreOffice 26.2.6.3 加 `patches/libreoffice/0001-lok-macos-tile-painting.patch`(已验证出图块)。2026-10-03 加 `0002-lok-dispatch-to-document-frame.patch`:`postUnoCommand` 原发往桌面的活动框架,另一文档关闭后命令落空或落到别的文档;改发本文档的框架。2026-10-04 加 `0003-lok-char-style-and-spacing-states.patch`:LOK 原不发当前字符样式与段前段后,属性栏无从同步;补发 `.uno:CharStyle`(界面名,无字符样式为空)与 `.uno:ULSpacing`(`上,下`,1/100 mm);混合选区的状态发 `{"commandName","dontcare":true}`,`ely_lok::MIXED` 表示,段落样式跨段不一致也算混合(原样报首段),字符样式带来的字体、字号、粗斜体等在选区内不一致也算混合(原样只看直接格式)。`.uno:ULSpacing` 缺的成员归零,故两值同发;属性栏记住已发未回显的两值状态(段距、页边距),连续编辑以它为底。同日加 `0004-lok-panel-states.patch`:补发页面尺寸、页面项(横向、版式、页码格式)、页边距、分栏、页眉页脚开关与版式、四种锚点与六种环绕(真假或禁用)、标题行重复;页面项缺的成员同样归零,故转向时页面项与尺寸都发。`0005-jsdialog-skip-disposed-dialogs.patch`:对话框守卫关闭对话框后,JSDialog 空闲任务仍为它生成整窗更新,读已释放窗口崩溃(实测崩溃报告),补丁让已释放的对话框不再生成消息。`0006-page-size-takes-the-page-item.patch`:`.uno:AttributePageSize` 也收页面项,转向是一次改动、一步撤销。`0007-lok-aqua-anyinput-without-peeking.patch`:worker 的请求经主 GCD 队列派发,而 Aqua 的 `AnyInput` 用 `nextEventMatchingMask` 窥探时会转动 run loop、在内核空闲任务中途执行请求(实测:表格删列与排版空闲任务交错,`SwLayIdle::DoIdleJob_` 段错误,约三成全量测试复现);补丁让 LOK 下的 `AnyInput` 改问客户端,worker 以 `registerAnyInputCallback` 报告是否有待处理请求,请求只在顶层让出时执行(补丁后连续十次全绿)。`0008-lok-toc-caption-formula-without-dialogs.patch`:目录、题注、公式在内核只有对话框入口;补丁给 `.uno:InsertMultiIndex` 加 `Title`(默认目录)、`.uno:InsertCaptionDialog` 加 `Category`(程序名)与 `Text`(照内核题注对话框的选项)、`.uno:InsertObjectStarMath` 加 `Formula`(文字转公式,选中公式时整体替换,一步撤销),并加 `getCommandValues(".uno:Formula")` 读选中公式。插入目录后光标落在目录内(内核原样)。`0009-lok-word-count-values.patch`:`getCommandValues(".uno:WordCount")` 给文档与选区的字数、字符数;内核的 `.uno:StateWordCount` 状态是英文串,只作重读的信号。构建加 `--with-myspell-dicts`,随包词典取自 LibreOffice 的 dictionaries 子模块(core 钉的 9925407,来源与许可见各目录 README 与 license),装在 `Resources/extensions`。构建后只留 `dict-en`(25 MB,英语拼写、断词、同义词):界面语言是英文与简体中文,中文无 Hunspell 词典;全部 65 个(473 MB)时 LOK 首启 5.4 秒、再启 2.3 秒,只留英文为 1.1 秒与 0.7 秒(PERF-01 要求 3 秒内可操作)。词典语种已由用户定:英文。`0010-lok-outline-values.patch`:`getCommandValues(".uno:Outline")` 给各标题的文字、级别、位置(twips)与是否当前(光标所在处按文档顺序之前最近的标题,`GetOutlinePos`;分栏时位置比不出先后),`.uno:Bookmarks` 的每项加位置(版面不显示的书签无位置);导航栏的跳转都按位置。`0011-lok-font-lists-present-when-a-member-is-used.patch`:LOK 把以 `;` 连写的字体列表整串当作字体名,列表中有字体已用上也报缺失(实测报出界面字体的回退列表);补丁让列表中任一成员用上即不算缺失,文档里写的列表全缺时照报。`0012-lok-calc-cursor-references-merge.patch`:Calc 在回调注册后补发单元格光标;`.uno:SheetReferences?sheet=N` 给引用某表的公式格数、命名区域数、第一个公式格,以及用 INDIRECT 的公式与名称数(这类引用运行时才知指向,删除说明里单独列出);合并带 `MoveContents` 时不弹对话框,并修上游“多个数据格的 API 合并什么也不做”。worker 以 `SAL_LOK_OPTIONS=sc_print_twips_msgs`(macOS 另加 `unipoll`)运行,Calc 的光标、选区与 `.uno:SheetGeometryData` 同为文档 twips;视图把可见区经 `setClientVisibleArea` 报给内核。`0013-lok-author-option.patch`:`lo_setOption("author", 名)` 设内核用户全名,新批注与修订以此署名。`0014-lok-calc-formula-entry-and-names.patch`:公式语法错误不弹询问、补全不切走编辑、提交清引用标记、名称的可撤销定Line truncated
|
||||
@@ -195,8 +203,8 @@ cargo run -p ely-doc 启动一个应用(ElyDoc 先 cargo build -p ely
|
||||
- 2026-10-01:MailCore 2 的子模块 libetpan 过旧,改钉 libetpan master `4d47862`。
|
||||
- 2026-10-01:每个应用的全部数据在 `<本机数据目录>/ElyOffice/<slug>/`,路径由 `ely_platform::data_dir` 给出。卸载只动这里,且先问。用户文档永不碰。
|
||||
- 2026-10-04(用户定):macOS 包标识前缀 `ely.zacharyzhang.office`(`packaging/macos/bundle.sh`);发布者 ZacharyZhang,网址 zacharyzhang.com(macOS `NSHumanReadableCopyright`,Windows 卸载项 `Publisher` 与 `URLInfoAbout`;Linux 桌面文件无此字段)。界面语言英文与简体中文,以后再加。拼写词典只随英文:LibreOffice 的词典库没有中文(中文不用 Hunspell 拼写)。内核界面语言固定英文,函数名照英文;ElyTable 把内核英文的选区统计(Sum、Average 等七个固定名)换成界面语言,数值照内核。批注与修订的作者取各用户的账户全名(无全名用登录名,与内核自身次序一致),由补丁 0013 的 `setOption("author")` 在 worker 启动时设定;作者设置页随设置任务接入。邮件合并字段写法 `«列名»` 由我定(用户交我决定)。
|
||||
- 2026-10-01:更新清单是 JSON:`{"version", "assets": {"<os>-<arch>": {"url", "sha256"}}}`,只走 https(本机回环除外)。检查、下载、校验在 `ely_platform::update`,从不静默安装。包管理器安装的 Linux 版本不自更新。清单地址由设置给出,尚未配置。
|
||||
- 2026-10-05(用户定):ElyAgent 的后端与内置模型的登录配置以 Kigi CLI(https://github.com/ZacharyZhang-NY/Kigi-CLI,Rust)为基础,以 Rust 依赖直接嵌入,不用 ACP;沿用其提供商登录(订阅账号或 API 密钥)与模型配置。
|
||||
- 2026-10-01:更新清单是 JSON:`{"version", "assets": {"<os>-<arch>": {"url", "sha256"}}}`,只走 https(本机回环除外)。检查、下载、校验在 `ely_platform::update`,从不静默安装。包管理器安装的 Linux 版本不自更新。2026-10-09 起(用户定:0.1.2 加自动更新):每个应用一份清单,`<slug>.json`,随发布上传,应用经 git.zacharyzhang.com 的 API 读最新发布(`api/v1/repos/ZacharyZhang-NY/ElyOffice/releases/latest`),在其文件里找 `<slug>.json`(`ely_platform::release::asset_url`;Gitea 没有 `releases/latest/download` 路径;`ELY_UPDATE_MANIFEST` 直接给清单地址,测试用);只在从 `.app` 运行时可用(开发构建没有);照 PRD §4.2 自动检查默认关闭:设置“通用”的“启动时检查更新”(通用设置 `check_updates`)打开后启动时查一次、查不到只记日志,应用菜单的“检查更新…”随时手动查(已是最新或查不到都以提示写明);有新版即在窗口上方显示组件库的 `UpdateBanner`(文案进内建中英目录,组件库 5d6efd4):横幅在标题栏下方(`Shell` 的页眉里,`Updates` 自己是一个视图);下载(进度)、校验散列、“重新启动以更新”只走正常的退出流程(有未保存的照常询问;取消即什么也不装,按钮仍在);应用真正退出时(`on_app_quit`)以本程序的安装模式(`--ely-install-update dmg 包 进程号`,`ely_ui::run` 最先识别)起一个独立进程:等本进程结束,`ely_platform::install` 挂载 dmg、把同名 .app 拷到旁边再换掉原包(换上前失败即放回原包),无论成败都 `open` 该包;失败的原因写在数据目录 `updates/failed.txt`,重开的应用以提示写明。下载完成只归属于它下载的那个版本;下载中或已下载时再查不覆盖。`packaging/macos/release.sh` 为每个应用写出清单(版本、本机架构的 dmg 地址与 SHA-256),dmg 里另有指向“应用程序”的替身,可直接拖入。新包换上即为装好,旧副本删不掉只记警告。`tests/scripts/update.sh`:装好的 ElyMark 在默认设置下启动不发任何请求;按“检查更新…”后从本机服务的 9.9.9 下载;有未保存的文字时“重新启动以更新”先问,取消则原包不动,“不保存”后装上新版并重新打开(新版本身的进程在跑)。
|
||||
- 2026-10-05(用户定):ElyAgent 的后端与内置模型的登录配置以 Kigi CLI(https://git.zacharyzhang.com/ZacharyZhang-NY/Kigi-CLI,Rust)为基础,以 Rust 依赖直接嵌入,不用 ACP;沿用其提供商登录(订阅账号或 API 密钥)与模型配置。
|
||||
- 2026-10-05(用户定):八个应用都不许卡顿:键入、选择、滚动、文档渲染都要即时(GPUI 的 120 FPS 手感),树莓派 3 上也要流畅。输入延迟与帧时间是验收项,要实测;界面线程不等内核、不持 worker 锁做同步请求,空闲不做事。
|
||||
- 2026-10-05:LOK 的输入与事件路径(实测后定)。原样:视图的事件监听长轮询 worker(持 worker 锁最多 50 毫秒,worker 读线程也随之阻塞最多 250 毫秒),按键排在锁后,键入锁等待中位 290 毫秒、最长 9 秒;输入队列在界面执行器上逐条跳回界面线程,每键约一帧,连续键入积压到 1 至 2 秒。现在:worker 有新事件即主动推送(`tag::EVENTS`,推送线程在输出锁下取批,批次即发送时状态),客户端读线程把回复与事件分开,事件存入 `client::Feed`,视图以异步方式等它(`Feed::next`,有新批次时唤醒,不占线程、不碰 worker 锁;原先每个打开的文档阻塞一个后台线程最多一秒,文档多于核数时会饿死输入与图块;监听任务归视图所有,视图释放即停);每个视图一条后台通道(`view/lane.rs`),输入优先、图块其次,连续执行,界面线程只收落地结果;文档尺寸与页框只在内核报尺寸变化时在后台读;批次弄脏的已显示图块即刻重绘,不等下一帧;视图的 `Reported` 事件只在内核回报或输入落地时发出,滚动与图块到达不触发应用的观察钩子;编辑与光标移动后应用要读的内核列表(ElyDoc 导航、字数、审阅,ElyTable 工作表与几何、单元格规则、格式面板)经 `ely_lok::read_off` 在后台读,一次一个,结果按发起者核对。实测(macOS,`tests/scripts/lag.sh`):按打字速度键入时输入落地 0 至 1 毫秒,图块 1 至 3 毫秒,按键到新图块 ElyDoc 中位 19 毫秒、ElyTable 3 毫秒;连续快速键入(脚本一次送出近百字)时,各次运行在 3 至 225 毫秒的中位之间摆动:新文档首次键入时内核有一次 150 至 230 毫秒的冷启动(首块图块与拼写等初始化),同一批字排在它之后;原为中位 1 秒、p95 1.9 秒。树莓派 3 未实测(本机无设备)。界面线程不碰 worker:应用对内核的读取、保存与另存为的导出、导出 PDF、比较、邮件合并都经 `Tabs::read_in`(或 `ely_lok::read_off`)在后台执行,回到窗口时按发起的标签与读取时的状态核对;保存导出期间标签状态为“正在保存”,同一标签的后续保存排队到它结束;另存为在写入前按文件身份再查一次目标是否已被别的标签持有;导出期间又有编辑时,“保存后关闭”不关闭,回到关闭询问;关闭标签时的撤销历史也在后台读;邮件合并预览与比较在发起时就保留自己的标签号与工作目录;读取失败不立即重试,等下一次状态变化;载入时一并在后台读版面与撤销历史(`ely_lok::layout`,`LokView::open` 接收版面)。窗口关闭回调先不放行,在后台逐个读标签的撤销历史并关闭(有改动的照常询问),最后一个标签关闭后移除窗口;内核文档的关闭也在后台(2026-10-06 起,原先同步读历史、在界面线程持 worker 锁关闭)。
|
||||
- 2026-10-04(用户定):八个应用的内容区一律随系统深浅色:Doc 页面、Table 网格、Show 幻灯片、PDF 页面、邮件正文、Mark 编辑区、Agent 输出。自动颜色随之翻转,文件里写明的颜色照原样;打印与导出 PDF 仍为浅色。各引擎(LOK、MuPDF、CEF)接入应用主题,不留引擎默认色。LOK:`ely.xcd` 定义 `COLOR_SCHEME_ELY_DARK` 与 `COLOR_SCHEME_ELY_LIGHT`(文档底色、自动文字色、网格、链接等取 Ely 默认色板;内核自带的深色方案颜色留空、按应用外观取默认值,传方案名不改外观,所以不用它),`LokView` 在主题深浅变化时经有序队列发 `.uno:ChangeTheme`(不算编辑),页面底色深色取 `surface`、浅色取 `paper`;Omarchy 色板与这两套固定色可能略有差别。导出 PDF 实测仍为白底。图块作废时旧图仍显示,新图到达后替换,编辑与主题切换都不闪。
|
||||
@@ -257,3 +265,16 @@ cargo run -p ely-doc 启动一个应用(ElyDoc 先 cargo build -p ely
|
||||
- 2026-10-06:ElyPDF 文字、图片与对象编辑(C11.3,PDF-03、04,§11.3)。字体(用户定):文档自带字体(能写新字时)或 MuPDF 内置的 Helvetica、Times、Courier(不嵌入,WinAnsi)与 Noto 中日韩(不嵌入,UTF-16 的 Adobe CJK 字体),不扫描系统字体;自带字体以 CID 字体(Identity-H,按字形号写)写入。对象(用户定):图片与表单 XObject。文字块以 MuPDF 的 stext 为准(同一读法,块序号稳定);可编辑的块须横排,且每个字形都在页面自身的内容流里(以不落盘的过滤试跑核对,表单里的字不可改)。改字是一步:用内容过滤的 `text_filter` 去掉该块的字形(按字形原点在用户空间 0.5 点内且字符相符,不靠白块遮盖),再在原首行基线处按框宽排版写新字(空格处折行,太长的词断开,行距沿用原块);所有检查(块文字未变、横排、字形都在页面内容里、字体画得出每个字、排版)都在开步之前,拒绝时文档与重做都不动;画不出某字即告知是哪个字,界面请用户换字体;换了字体、字号改变或新文字越出原块的框时先出预览(在快照副本上改并画出该区域,文档与撤销历史都不动),确认后才写。行距取首行与下一条不同基线的距离(同一基线的几段不算行),没有即字号的 1.2 倍。新文字在点击处起框。新增内容第一次写入时把页面原内容包进 `q … Q`(以 `%Ely` 标记,只包一次)。图片与表单:清点处理器按 `q`、`Q`、`cm` 跟踪,列出页面顶层的每次 `Do` 与其页面框;移动、缩放(右下角柄,保持比例、左上不动)以 `X = C·T·C⁻¹` 包住该次绘制重写内容流,删除即不写该次 `Do`,替换图片是新图片资源、按比例放进原框中央;添加图片落在当前页中央(像素按点、缩到页面一半以内)。MuPDF 的字体与图片资源缓存不随撤销与放弃回退(实测:预览后再写,字体引用指向已不存在的对象),每次放弃、撤销、重做后清空。编辑工具在“编辑”菜单(编辑文字和图片、添加文字、添加图片…),Esc 退出(键位上下文在窗口根上,页面与面板里都管用);替换、添加与删除图片和表单、拖动移动与缩放、写字与预览的确认都绑定发起的标签与视图版本,执行前视图须未变且无排队的编辑,否则提示不执行;任何编辑落地即关掉此前的预览;图层读取在回来时总清掉进行中的标记,编辑之前发出的读取作废后重读;右侧编辑面板:文字、字体、字号、颜色、框宽,应用、删除文字;对象:替换图片…、删除。真窗口(macOS)改过一次字:同字体同位置替换,标签为已编辑。
|
||||
- 2026-10-06:ElyPDF 页面组织(C11.2,PDF-02)。worker 打开即开 MuPDF journal;插入空白页、从文件插入(整份 PDF 嫁接)、删除、移动、旋转(90 度倍数,写页面的 `/Rotate`)、裁剪(按所见的上右下左边距设 `/CropBox`,全零即去掉)、撤销与重做都是一步,回复带历史标记(worker 按 MuPDF 的撤销位置记每步是编辑还是保存,标记是最后一个已做的编辑;撤销重做跳过保存步)。删除时指向已删页的书签保留但失去跳转,链接移除,表单字段去掉已删页上的控件;页码标签由 MuPDF 的删除与插入随之平移。坏的编辑(删光、页码乱序、非 90 度、边距超出页面)拒绝并回滚整步。保存(Save、Save As 走外壳)先 `pdf_save_snapshot` 写出(不动内存中的文档与撤销历史,靠补丁 0001),再打开该副本以 `garbage=2` 紧缩写到工作目录(已删页的对象不留在文件里),加密文件以用户输入的密码重开副本、照原加密写出(密码只在 worker 内存);外壳读回字节、原子写入。提取(选中页写新文件,经 `ely_files::export`,不覆盖打开着的文件,被别的标签持有即拒绝)在快照副本上删去其余页再紧缩写出,原文档的撤销与重做都不动;拆分按每份页数写到所选文件夹(`名称-序号.pdf`,先以 `ely_files::claim_all` 占下全部目标,任一已存在即一个不写;原 ElyShow 的同名函数移入 ely-files 共用)。合并即从文件插入到末尾再另存;插入的页带着自己的批注、链接与表单字段(指向源文件自身页的链接改指插入后的页,字段并入表单,重名的加序号,如 `field0 2`(名称按需分配,长名也终止),源表单的默认外观 `/DA` 与默认对齐 `/Q` 给到没有自己值的字段树根,源表单的字体资源并入目标 `/DR`,同名而不同的字体改名为 `名称_2` 并改写字段外观里的引用(按 PDF 名称语法解 `#xx` 转义,写出时照样转义);源文件的书签不并入)。删除时表单控件按被删页的 `/Annots` 认定,不只看可省略的 `/P`。裁剪边距以所见为准:先按视图旋转、再按页面 `/Rotate` 换到页面自身方向,并按 `/UserUnit` 换算。编辑失败也通知外壳队列已动,等着的保存、关闭不会挂住。结构编辑后区间点选的起点作废。应用:每个视图一条编辑队列,一次一条、按序执行,落地后重读页数、尺寸与书签,清掉图块、文字、缩略图、找到的词与选择,视图版本加一,此前发出的读取回来即丢;查找在编辑后重查。修改标记是当前历史与载入或上次保存时的历史不同,撤销回到保存点即为已保存(外壳新增 `Engine::saved` 与 `Session::reverted`:引擎回报未修改时 Dirty 回到 Saved,保存中、冲突、失败不变)。左栏是页面缩略图(`side.rs`;有书签时上方分段切换到书签):点选、Shift 连选、Cmd 增减,右键菜单,拖到某页之前即移动(移动后仍选中),Delete 删除;无选中时作用于当前页。“页面”菜单与“编辑”菜单的撤销(Cmd+Z)、重做(Shift+Cmd+Z)。裁剪对话框以毫米输入。MuPDF 的构建改为在 `engines/mupdf-src`(reference 只读)打 `patches/mupdf` 后编译。
|
||||
- 2026-10-06:ElyPDF 阅读(C11.1,PDF-01)。MuPDF 只链进 `ely-pdf-worker`(`crates/ely-pdf-engine`,build.rs 把 C 垫片 `shim/ely_mupdf.c` 与 `libmupdf.a`、`libmupdf-third.a` 只链给这个二进制),应用不链 MuPDF。build.rs 以协议、垫片与 worker 源码的散列为版本戳,应用启动 worker 先握手(`HELLO`),戳不同即拒绝(单测不重建 worker,旧二进制曾被误用)。worker 在打开第一个文件时才启动(PERF-01),`tests/scripts/pdf-idle.sh` 查空白窗口无子进程。垫片每个调用都在 `fz_try`/`fz_catch` 里,返回码加最后一条错误信息,MuPDF 的跳转从不越过 Rust。worker 与应用之间是 `ely-ipc` 的帧(从 ely-lok 抽出,两者共用):打开(锁定即报)、解锁、页数、页框、渲染一块(设备像素、缩放、旋转、深色)、按阅读顺序的字符与外框、页内搜索(每处命中及其全部四边形,跨行短语算一处,数量不设上限)、书签(JSON)、关闭;文件读不出只报错,worker 照常工作。查看器:打开时只读页数、前 100 页尺寸与书签,其余尺寸后台每批 100 页补齐;视图只排屏上的页(连续、单页、双页;适合宽度、适合页面、实际大小与缩放档;视图旋转 90°),按 512 设备像素一块请求,一次一块、由近及远,只留屏上的块(横纵两向),后台回来的块不在屏上即弃;画不出的块记下不再请求,换文档或重开前不重试;深色外观下页面按亮度反相(MuPDF `fz_invert_pixmap_luminance`,色相保留)。文字选择按字符、可跨页,复制按行换行,未读的页先读;查找每批 20 页在后台进行,命中逐个跳转并标出,Esc 关闭(组件库 617a8d6);书签栏用 `lists::Outline`,点即跳到页与位置。切换视图、缩放、旋转后仍停在正在读的那页。加密文件打开时问密码(外壳的密码框,见上一条),错了再问,取消即不打开。没有页的文件报错并关闭,不开标签。双页时同一行在视口内的两页都可为当前页;当前页只在横纵两向都可见的页里定,跳转在目标页左缘不在视口时横向移过去。图块按视口半开区间取。首次按下时文字未读,读到后照原按下处起选;查找结果按查找实例与所属标签核对,只在该标签为当前时跳转。书签为空时不留左栏。启动参数里的文件直接打开。
|
||||
- 2026-10-09(用户定:“打开方式”里不得出现 LibreOffice):系统会登记磁盘上能找到的 .app、挂载镜像里的 .app 与运行过的包,构建目录里的 `LibreOffice.app` 与测试挂载的官方镜像曾因此成为 xlsx 等的默认程序。现构建后由 `scripts/inert-lo.sh` 去掉其全部文件与 URL 声明、快速查看与聚焦插件,注销它,并在 `engines/` 放 `.metadata_never_index`;Ely 只取其 Frameworks 与 Resources。任何脚本与测试都不挂载 LibreOffice 镜像:LOK 探测用本构建的内核,单测所需的官方内核由 `scripts/extract-official-lo.sh` 以 7zz 解成无包的文件夹。`tests/scripts/lo-unregistered.sh` 以 NSWorkspace 核对 docx、xlsx、pptx、odt、csv 的“打开方式”里没有 LibreOffice。
|
||||
- 2026-10-09(用户报:ElyTable 点格跳到别处、拖不出选区):Calc 在 `sc_print_twips_msgs` 下以打印 twips(行高原值)报光标、选区与 `.uno:SheetGeometryData`,图块与鼠标却在图块 twips(每行按 `ScViewData::ToPixel` 截成整像素),两者随行号漂移(5000 行处约 140 行)。视图对外一律打印 twips;`LokView::set_geometry` 收下工作表几何后,`sheet::Axis::tile`、`print` 照内核的截断换算(每像素 twips 取图块的像素与 twips 之比),绘制、显示、跳转与冻结都先换成图块 twips,鼠标以图块 twips 发出(`tile_point`),拖动句柄仍为打印 twips;`.uno:` 读回与应用(表头、填充柄)照旧用打印 twips,表头的起点取 `LokView::scrolled_start`。内核读鼠标用的比例原取最后一块图块,worker 现于每次 `setClientVisibleArea` 前以 `setClientZoom` 告知图块比例,点击不再依赖先画过图块。
|
||||
- 2026-10-09(用户报:ElyPDF 改字报“这种字体画不出 V”):文档自带的子集字体常无可用的 Unicode 表(LibreOffice 导出的子集表为占位,0x00 起逐一对应字形号),按 Unicode 找字形一律失败。现以“文档自带字体”写字时直接用页面上的那个字体对象(`shim/ely_pen.c`;`pdf_load_font` 按对象缓存,与文字层的字体同一对象),以它自己的编码写:按文字提取的读法(ToUnicode,缺项或坏值退回 cid_to_ucs,同 pdf-op-run.c)倒出 Unicode 到编码的表,排版取它的宽度(`pdf_lookup_hmtx`),原有的 ToUnicode 与宽度不动,两个字共用一个字形时各写各的编码(原先按字形号写、重建 ToUnicode,共用字形的字被改写,且 CMap 漏写条目数,PDFKit 读不出字)。删去原文字块后页面资源里可能已无该字体,故按对象号以新名字重新引用。只支持编码即 CID 的字体(简单字体与 Identity-H),其余拒绝并说明;页面上没有的字仍报缺字。排版按同一套宽度量出的框,比较时留 0.01 点的余量(原块宽度即这些宽度之和,浮点误差曾使末字折行)。
|
||||
- 2026-10-09:ElyTable 的自动筛选(R2.9)。内核会重新推算未命名的自动筛选区:每次打开筛选列表时向下扩到紧邻的数据行(`ExtendDataArea`、`ExtendBackColorArea`,为接上后来追加的行),命令从单格找到它时按连续数据区重算(`ScDocShell::GetDBData`:应用条件、关闭筛选及其撤销);选区下方紧邻的合计行因此进了列表、随数据一起被隐藏,存后重开的筛选区同样会扩。补丁 `0040-lok-calc-autofilter-keeps-its-rows.patch`:LOK 下已有的自动筛选区保持设定时的行(同 Excel),不再隐式扩展(光标在区内时;光标在同表另一块数据里即按那一块);单格开筛选时仍取整个数据区。代价:紧贴在筛选区下方追加的行不自动并入,需重新选定后再开筛选。
|
||||
- 2026-10-09:ElyTree 的差异按文件类型着色(R2.12)。组件库 7f2ac3e 至 b0dbfd4:`DiffViewer`(建立时按路径定下读法) 按路径的扩展名判定散文与纯文本(md、markdown、txt、rst、adoc、org、csv、tsv、log 等,无扩展名同,不着色),代码按语言着色(组件库 b0dbfd4 的 `forms::syntax`:Rust、JavaScript/TypeScript、类 C、Python、Ruby、Shell、YAML、INI、SQL、Lua、Haskell、Lisp、Erlang、TeX 与其他 `#` 语言各有行注释记号、关键字与常量;Shell 与 YAML 的 `#` 只在词首起注释;Makefile、Dockerfile、CMakeLists.txt 先按文件名认),不是完整的语法分析器(字符串插值、块注释、多行字符串照通用词法)(原先一律套 `//` 的通用词法,Markdown 的 `#`、Python 的注释都被当作代码上色)。同批带入上游的块编辑器跨块选择、浮层滚轮、输入法候选框位置、插入点按设备像素对齐与格式修正。
|
||||
- 2026-10-09:ElyMark 的表格(R2.13)。表格的空格与分隔行写法有许多种(`|a|b|`、`|---|`、对齐空格),逐字重现做不到,原先凡写不回原样的表格都成了原文块。现在一块的序列化与原文在把其中每张表格化成规范形式(各列对齐方式加各格的原文,`tables.js` 的 `canon`)后相同,即为可视块(`preserve.js` 的 `kept`),引用与列表里的表格同样;格内有 Milkdown 会改写的写法(`[[…]]`、引用式链接等)即不同,整块仍为原文块,与段落的规则一致。Milkdown 的列表项必须以段落开头,表格作列表项的第一块时无法放进编辑器,照原文块保留。未改的表格照旧逐字写回,改过的表格按文档多数表格的写法重写(`style.js` 按表格的行节点投票:单元格两侧有无空格、是否按列对齐,经 remark-gfm 的 `tableCellPadding` 与 `tablePipeAlign`;原先投票的解析器不认 GFM,表格从未计票),分隔行随之重写(如 `|---|` 成 `| - |`)。
|
||||
- 2026-10-09:ElyTable 新插图表的位置(R2.10)。内核按“定位区域”把图表放在其旁、并挤回当前可见区;带参数的请求(Ely 经 `FN_PARAM_5` 给区域)原把定位区域取为光标格,图表压在数据上或旁边的另一块数据上。补丁 `0041-lok-calc-chart-beside-its-data.patch`:LOK 下有请求区域时,图表放进数据区右侧(隔一列)第一块够大、无合并格的空单元格(逐列向右找,跨过旁边的数据块),右侧没有依次找下方、左侧、上方,再按行带找全表第一块够大的空处(尺寸从候选格起累加,表尾也快),不受可见区限制;空处按图表所在的工作表查,数据在别的表时从光标起找;整张表没有空处即插入失败、文档不动;`LokView` 在新选中对象(原先无选中)时把它滚入视口,拖动中的对象不滚动。
|
||||
- 2026-10-09:ElyPDF 编辑与缩放不闪白(R2.6)。旧图块不再随编辑或比例变化即刻丢弃:编辑落地时全部当前图块、比例变化时离开视图的同页图块,连同当时的页面尺寸进入“底图”(`apps/ely-pdf/src/backdrop.rs`),按其在页面中的比例位置画在该页新图块之下,直到该页在视口里的新图块到齐、或页面尺寸与旋转变了才释放;每页画什么由 `PdfView::pieces` 决定,绘制与测试同用它。只有改内容的编辑保留底图并沿用已测的页面尺寸(前 100 页以外不再被占位尺寸覆盖);增删、移动、旋转、裁剪页面与撤销重做(`PdfView::edit_pages`)清空底图,因同一序号可能已是另一页。关闭标签时底图随图块交给窗口释放。原先比较整份尺寸表(超过 100 页的混合纸张文档尺寸表后段为占位,比较失败即全部清空)且只认同比例的图块(编辑后右栏收起、比例变化即清空),都会闪白。
|
||||
- 2026-10-09:文档的缩放锚点(R2.7)。窄于视口的文档居中,缩放原按视口坐标求锚点、漏了居中的偏移,锚点随缩放漂移;现锚点先减去缩放前的偏移,缩放后按新的偏移(`LokView::slack`,绘制同用)换回。按键与菜单的缩放(无指针)另保持首页左缘在视口内;指针与捏合的缩放保持指针下的点不动(文档边界以外即止)。
|
||||
- 2026-10-09:退出(缺陷清单 X-01)。Cmd+Q 与应用菜单的“退出”由应用级动作接收:主窗口的宿主在 `Closing::own_window` 里登记自己的退出流程(`ely_ui::commands::route_quit`),任何窗口(含设置窗口)发出的退出都经它逐个关闭标签、询问未保存的;宿主的窗口已不在时才直接退出;没有宿主的应用(ElyTree)直接退出。`Host::quitting` 在退出开始时运行(ElyMark 先记下打开的标签)。原先只有主窗口根上截退出,设置窗口在前时 Cmd+Q 不问即退,并把这次运行记为干净结束、删掉恢复点。
|
||||
- 2026-10-09:作者名与读不出的设置(缺陷清单 X-02)。签名用的名字取启动时读入的通用设置(`ely_ui::settings::current`;文件读不出时为默认值,设置窗口另以 Banner 写明),`ely_platform::user::named(作者名)` 为空即用账户名;不再在引擎启动时重读文件(原先 `settings.json` 读不出时 Doc、Table、Show 以致命错误退出)。LOK worker 记下设定的作者名,引擎重启照用它。`tests/scripts/bad-settings.sh` 核对读不出的设置下 ElyDoc 照样启动、文件不被覆盖。
|
||||
- 2026-10-09:每个应用只跑一份(缺陷清单 X-03)。`ely_ui::run` 在写日志之前取应用数据目录的 `instance.lock`(`ely_platform::instance::hold`;Unix 为 fcntl 记录锁,进程结束即放,被拒时以 `F_GETLK` 向系统问出持锁的进程号,不另存进程号文件,同时启动的几份也报得准;Windows 为 LockFileEx,不报进程号);已有一份在跑时第二份不启动,报“已在运行(进程号)”。原先第二份启动即清空第一份的工作目录、把它的恢复点当作干净结束删掉、改写崩溃锁。macOS 经访达打开文件本就交给运行中的那份;`open -n` 与 Linux 每文件一个进程时第二份被拒,文件须在已开的窗口里打开(未做转交)。`tests/scripts/one-instance.sh` 核对。
|
||||
- 2026-10-09(用户定):代码与发布从 GitHub 搬到自建的 Gitea(git.zacharyzhang.com;GitHub 账号被封,推送与发布都被拒)。公开仓库 `ZacharyZhang-NY/ElyOffice`(原样推上 main、缺陷清单分支与 v0.1.0、v0.1.1 标签),组件库为同站的 `ZacharyZhang-NY/Ely-GPUI-Components`(Cargo 的 git 依赖与 `fetch-references.sh` 随之改址,钉的提交不变)。v0.1.1 的六个 dmg 与两个源码包重新发在 Gitea 的 v0.1.1 发布里。官网的下载与源码链接指向 Gitea(`releases/latest` 会跳到最新发布页)。`.github/workflows` 删去(它们靠 GitHub 的 macOS 机器与 `gh`,发布改在本机以 `packaging/macos/release.sh` 构建、经 Gitea API 上传)。发布视频里写的地址已在源文件改为 Gitea,已发布的成片仍是旧地址,重渲染后才更新。上游项目(LibreOffice、MuPDF、git-lfs、tessdata 等)照旧从它们自己的 GitHub 地址取。
|
||||
@@ -24,17 +24,18 @@ impl Docs {
|
||||
let Some(counts) = self.active_tab().and_then(|tab| tab.extra.counts) else {
|
||||
return status.when_some(zoom, |status, zoom| status.right(zoom));
|
||||
};
|
||||
let (words, characters) = (counts.words.to_string(), counts.characters.to_string());
|
||||
let count = |key, n: u64| ely_ui::i18n::counted(cx, key, n, &[("n", &n.to_string())]);
|
||||
let label = match counts.selected_words {
|
||||
0 => Self::text(
|
||||
cx,
|
||||
"doc.count.words",
|
||||
&[("words", &words), ("characters", &characters)],
|
||||
),
|
||||
selected => Self::text(
|
||||
0 => {
|
||||
let words = count("doc.count.word", counts.words);
|
||||
let characters = count("doc.count.character", counts.characters);
|
||||
Self::text(cx, "doc.count.words", &[("words", &words), ("characters", &characters)])
|
||||
}
|
||||
selected => ely_ui::i18n::counted(
|
||||
cx,
|
||||
"doc.count.selected",
|
||||
&[("selected", &selected.to_string()), ("words", &words)],
|
||||
counts.words,
|
||||
&[("selected", &selected.to_string()), ("words", &counts.words.to_string())],
|
||||
),
|
||||
};
|
||||
status.right(StatusBarItem::new("doc-count").label(label)).when_some(zoom, |status, zoom| status.right(zoom))
|
||||
|
||||
@@ -85,6 +85,14 @@ impl Host for Docs {
|
||||
self.offer_spelling(id, view, cx);
|
||||
}
|
||||
|
||||
/// A dialog about a closed tab goes with it.
|
||||
fn tab_closed(&mut self, tab: &ely_office::Tab<Extra, ely_office::Lok>, cx: &mut Context<Self>) {
|
||||
if matches!(self.dialog, Some(Dialog::Output { tab: of, .. }) if of == tab.id) {
|
||||
self.dialog = None;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn search_leaves(&mut self, cx: &mut Context<Self>) {
|
||||
self.mark_place(cx);
|
||||
}
|
||||
@@ -126,7 +134,7 @@ pub fn open(app: AppId, window: &mut Window, cx: &mut App) -> Entity<Root> {
|
||||
let root = ely_ui::document_root(app, docs.clone().into(), &ely_ui::commands::FILE, menus, window, cx);
|
||||
docs.update(cx, |docs, cx| {
|
||||
docs.core.root = root.downgrade();
|
||||
docs.core.window = Some(window.window_handle());
|
||||
docs.own_window(window, cx);
|
||||
window.focus(&docs.core.focus, cx);
|
||||
});
|
||||
let launched = ely_ui::launch_files(cx);
|
||||
@@ -209,7 +217,6 @@ impl Render for Docs {
|
||||
.on_action(cx.listener(Self::on_open))
|
||||
.on_action(cx.listener(Self::on_save))
|
||||
.on_action(cx.listener(Self::on_save_as))
|
||||
.on_action(cx.listener(Self::on_quit))
|
||||
.on_action(cx.listener(Self::on_close_tab))
|
||||
.child(shell)
|
||||
.children(self.core_dialog(cx))
|
||||
|
||||
@@ -36,6 +36,10 @@ pub fn menu(cx: &gpui::App) -> gpui::Menu {
|
||||
pub struct Merge {
|
||||
docs: WeakEntity<Docs>,
|
||||
pub table: Option<Table>,
|
||||
/// The template's tab, active when the data was chosen.
|
||||
pub source: Option<u64>,
|
||||
/// Tabs opened as previews; none is a template.
|
||||
pub previews: std::collections::HashSet<u64>,
|
||||
/// The record to preview, from 1.
|
||||
record: usize,
|
||||
pdf: bool,
|
||||
@@ -46,6 +50,8 @@ impl Merge {
|
||||
Merge {
|
||||
docs,
|
||||
table: None,
|
||||
source: None,
|
||||
previews: std::collections::HashSet::new(),
|
||||
record: 1,
|
||||
pdf: false,
|
||||
}
|
||||
@@ -62,11 +68,20 @@ impl Docs {
|
||||
}
|
||||
|
||||
pub(crate) fn choose_csv(&mut self, cx: &mut Context<Self>) {
|
||||
self.pick(false, cx, |docs, path, cx| match read_csv(&path) {
|
||||
let Some(source) = self.core.active else {
|
||||
let text = Docs::text(cx, "command.blocked.no_document", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
};
|
||||
if self.merge.read(cx).previews.contains(&source) {
|
||||
let text = Docs::text(cx, "doc.merge.from_preview", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
}
|
||||
self.pick(false, cx, move |docs, path, cx| match read_csv(&path) {
|
||||
Ok(table) => {
|
||||
log::info!("doc: merge data has {} rows", table.rows.len());
|
||||
docs.merge.update(cx, |merge, cx| {
|
||||
merge.table = Some(table);
|
||||
merge.source = Some(source);
|
||||
merge.record = 1;
|
||||
cx.notify();
|
||||
});
|
||||
@@ -84,20 +99,20 @@ impl Docs {
|
||||
});
|
||||
}
|
||||
|
||||
/// The tab a merge starts from: the active one.
|
||||
/// The template's tab, while it is open.
|
||||
fn source(&self, cx: &mut Context<Self>) -> Option<u64> {
|
||||
if self.core.active.is_none() {
|
||||
let text = Docs::text(cx, "command.blocked.no_document", &[]);
|
||||
let source = self.merge.read(cx).source.filter(|source| self.tab(*source).is_some());
|
||||
if source.is_none() {
|
||||
let text = Docs::text(cx, "doc.merge.gone", &[]);
|
||||
self.toast(text, Severity::Warning, cx);
|
||||
}
|
||||
self.core.active
|
||||
source
|
||||
}
|
||||
|
||||
/// Types a field's marker at the cursor.
|
||||
/// Types a field's marker at the template's cursor.
|
||||
pub(crate) fn insert_field(&mut self, header: &str, cx: &mut Context<Self>) {
|
||||
let Some(tab) = self.active_tab() else {
|
||||
let text = Docs::text(cx, "command.blocked.no_document", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
let Some(tab) = self.source(cx).and_then(|source| self.tab(source)) else {
|
||||
return;
|
||||
};
|
||||
tab.view.update(cx, |view, _| view.insert(&marker(header)));
|
||||
}
|
||||
@@ -194,7 +209,12 @@ impl Render for Merge {
|
||||
})
|
||||
};
|
||||
let row = || div().flex().flex_wrap().items_center().gap_1();
|
||||
let template = self.source.and_then(|source| {
|
||||
let docs = self.docs.upgrade()?;
|
||||
Some(docs.read(cx).tab(source)?.name.clone())
|
||||
});
|
||||
let group = PropertyGroup::new(table.name.clone())
|
||||
.row(text("doc.merge.template"), div().child(template.unwrap_or_else(|| text("doc.merge.gone"))))
|
||||
.row(text("doc.merge.data"), choose)
|
||||
.row(text("doc.merge.fields"), row().children(fields))
|
||||
.row(
|
||||
|
||||
@@ -164,6 +164,7 @@ impl Docs {
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
log::info!("doc: previewing merge record {}", at + 1);
|
||||
self.merge.update(cx, |merge, _| merge.previews.insert(into));
|
||||
self.load_into(into, Source::Copy(copy), cx);
|
||||
self.core.waiting.push((
|
||||
into,
|
||||
@@ -260,9 +261,8 @@ impl Docs {
|
||||
let folder = folder.display().to_string();
|
||||
let text = match written {
|
||||
Ok(count) => {
|
||||
let count = count.to_string();
|
||||
let text =
|
||||
Docs::text(cx, "doc.merge.done", &[("n", &count), ("folder", &folder)]);
|
||||
let n = count.to_string();
|
||||
let text = ely_ui::i18n::counted(cx, "doc.merge.done", count as u64, &[("n", &n), ("folder", &folder)]);
|
||||
return docs.toast(text, Severity::Success, cx);
|
||||
}
|
||||
Err((n, error)) => Docs::text(
|
||||
|
||||
@@ -22,9 +22,9 @@ fn records_fill_previews_and_files() {
|
||||
let csv = dir.path().join("people.csv");
|
||||
std::fs::write(&csv, "Name,City\nAda,London\n«City»,上海\n").expect("the csv writes");
|
||||
let table = read_csv(&csv).expect("the csv reads");
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.insert_field("Name", cx)));
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.field_here("Name", cx)));
|
||||
type_into(&mut cx, &docs, " of ");
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.insert_field("City", cx)));
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.field_here("City", cx)));
|
||||
let source = cx.update(|app| docs.read(app).core.tabs[0].name.to_string());
|
||||
cx.update(|app| {
|
||||
docs.update(app, |docs, cx| {
|
||||
@@ -171,7 +171,7 @@ fn a_merge_keeps_its_source_when_the_tab_changes() {
|
||||
let table = read_csv(&csv).expect("the csv reads");
|
||||
cx.update(|app| {
|
||||
docs.update(app, |docs, cx| {
|
||||
docs.insert_field("Name", cx);
|
||||
docs.field_here("Name", cx);
|
||||
docs.preview_record(source, &table, 0, cx);
|
||||
docs.core.active = Some(other);
|
||||
})
|
||||
@@ -191,6 +191,14 @@ fn a_merge_keeps_its_source_when_the_tab_changes() {
|
||||
});
|
||||
let preview = dir.path().join("preview.odt");
|
||||
let id = cx.update(|app| docs.read(app).core.tabs[2].id);
|
||||
// The preview is active now; the template stays.
|
||||
cx.update(|app| {
|
||||
docs.update(app, |docs, cx| {
|
||||
docs.core.active = Some(id);
|
||||
assert_eq!(docs.source(cx), Some(source), "the template stays after a preview");
|
||||
assert!(docs.merge.read(cx).previews.contains(&id), "the preview is known");
|
||||
})
|
||||
});
|
||||
with_window(&mut cx, &docs, |docs, window, cx| {
|
||||
docs.write_as(id, preview.clone(), None, window, cx)
|
||||
});
|
||||
@@ -227,7 +235,7 @@ fn two_generations_keep_their_own_templates() {
|
||||
for text in ["SourceA ", "SourceB "] {
|
||||
sources.push(blank(&mut cx, &docs));
|
||||
type_into(&mut cx, &docs, text);
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.insert_field("Name", cx)));
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.field_here("Name", cx)));
|
||||
settled(&cx, &docs);
|
||||
}
|
||||
let csv = dir.path().join("one.csv");
|
||||
@@ -265,3 +273,40 @@ fn two_generations_keep_their_own_templates() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_template_chosen_with_the_data_stays_through_a_preview() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(docs) = docs(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let template = blank(&mut cx, &docs);
|
||||
type_into(&mut cx, &docs, "Dear ");
|
||||
let csv = dir.path().join("two.csv");
|
||||
std::fs::write(&csv, "Name\nAda\nGrace\n").expect("the csv writes");
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.choose_csv(cx)));
|
||||
cx.simulate_path_prompt_response(move |_| Some(vec![csv]));
|
||||
settle(&cx, |app| docs.read(app).merge.read(app).table.is_some());
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.insert_field("Name", cx)));
|
||||
let table = cx.update(|app| docs.read(app).merge.read(app).table.clone().expect("the data"));
|
||||
// As the panel's buttons do: preview, then generate.
|
||||
cx.update(|app| docs.update(app, |docs, cx| {
|
||||
let source = docs.source(cx).expect("the template");
|
||||
docs.preview_record(source, &table, 0, cx);
|
||||
}));
|
||||
settle(&cx, |app| tabs(app, &docs) == 2 && docs.read(app).core.active != Some(template));
|
||||
let out = dir.path().join("out");
|
||||
std::fs::create_dir(&out).expect("the folder");
|
||||
cx.update(|app| docs.update(app, |docs, cx| {
|
||||
let source = docs.source(cx).expect("the template, not the preview");
|
||||
assert_eq!(source, template);
|
||||
docs.generate(source, table.clone(), false, out.clone(), cx);
|
||||
}));
|
||||
let stem = cx.update(|app| docs.read(app).tab(template).expect("a tab").name.to_string());
|
||||
let target = |n: usize| out.join(format!("{stem} {n}.docx"));
|
||||
settle(&cx, |_| target(2).exists());
|
||||
let (first, second) = (text_of(&mut cx, &docs, &target(1)), text_of(&mut cx, &docs, &target(2)));
|
||||
assert!(first.contains("Dear Ada") && second.contains("Dear Grace"), "{first:?} {second:?}");
|
||||
}
|
||||
@@ -29,7 +29,7 @@ impl Docs {
|
||||
self.ask_output(true, cx);
|
||||
}
|
||||
|
||||
fn ask_output(&mut self, print: bool, cx: &mut Context<Self>) {
|
||||
pub(crate) fn ask_output(&mut self, print: bool, cx: &mut Context<Self>) {
|
||||
let Some(tab) = self.active_tab() else {
|
||||
let text = Docs::text(cx, "command.blocked.no_document", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
@@ -81,10 +81,8 @@ impl Docs {
|
||||
let path = source.work.join("print.pdf");
|
||||
let printing = path.clone();
|
||||
return self.write_pdf(tab, path, pdf, cx, move |docs, written, cx| match written {
|
||||
Ok(()) => ely_office::print_later(printing, cx, |docs, error, cx| {
|
||||
docs.output_failed(&error, cx)
|
||||
}),
|
||||
Err(error) => docs.output_failed(&error.to_string(), cx),
|
||||
Ok(()) => ely_office::print_later(printing, cx),
|
||||
Err(error) => docs.print_failed(&error.to_string(), cx),
|
||||
});
|
||||
}
|
||||
let Some(dir) = ely_office::folder(source) else {
|
||||
|
||||
@@ -463,3 +463,12 @@ fn an_outside_change_asks_and_keep_mine_overwrites() {
|
||||
mod find;
|
||||
mod more;
|
||||
mod overlap;
|
||||
|
||||
impl Docs {
|
||||
/// Chooses the active tab as template, then types a field.
|
||||
pub(crate) fn field_here(&mut self, header: &str, cx: &mut gpui::Context<Self>) {
|
||||
let active = self.core.active;
|
||||
self.merge.update(cx, |merge, _| merge.source = active);
|
||||
self.insert_field(header, cx);
|
||||
}
|
||||
}
|
||||
@@ -215,3 +215,51 @@ fn an_edit_that_just_landed_still_asks_and_selection_does_not() {
|
||||
});
|
||||
settle(&cx, |app| docs.read(app).tab(id).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_quit_from_either_window_asks_first() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(docs) = docs(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let id = blank(&mut cx, &docs);
|
||||
commit(&mut cx, &docs, "Unsaved");
|
||||
let view = cx.update(|app| docs.read(app).active_tab().expect("a tab").view.clone());
|
||||
settle(&cx, |app| view.read(app).settled());
|
||||
cx.update(ely_ui::commands::bind_quit);
|
||||
let home = cx.add_window(|_, _| Blank);
|
||||
cx.update_window(home.into(), |_, window, app| docs.update(app, |docs, cx| docs.own_window(window, cx)))
|
||||
.expect("the window lives");
|
||||
// The settings window has no quit of its own.
|
||||
let settings = cx.add_window(|_, _| Blank);
|
||||
for from in [home.into(), settings.into()] {
|
||||
cx.dispatch_action(from, ely_ui::commands::Quit);
|
||||
settle(&cx, |app| matches!(docs.read(app).core.dialog, Some(Dialog::Unsaved { .. })));
|
||||
assert!(cx.update(|app| docs.read(app).tab(id).is_some()), "the tab waits for an answer");
|
||||
assert_eq!(cx.update(|app| app.active_window()), Some(home.into()), "the question's window comes forward");
|
||||
// Cancel, as the dialog's button does.
|
||||
cx.update(|app| docs.update(app, |docs, cx| {
|
||||
docs.close_cancelled(cx);
|
||||
docs.core.dialog = None;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_a_tab_takes_its_export_dialog() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(docs) = docs(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let id = blank(&mut cx, &docs);
|
||||
cx.update(|app| docs.update(app, |docs, cx| docs.ask_output(false, cx)));
|
||||
assert!(cx.update(|app| matches!(docs.read(app).dialog, Some(crate::actions::Dialog::Output { .. }))));
|
||||
with_window(&mut cx, &docs, |docs, window, cx| docs.request_close(id, After::Tab, window, cx));
|
||||
settle(&cx, |app| docs.read(app).tab(id).is_none());
|
||||
// Drawn now, a dialog for the gone tab would crash.
|
||||
assert!(cx.update(|app| docs.read(app).dialog.is_none()), "the dialog went with its tab");
|
||||
}
|
||||
@@ -86,10 +86,10 @@ fn interleaved_previews_keep_their_sources() {
|
||||
};
|
||||
let alpha = blank(&mut cx, &docs);
|
||||
type_into(&mut cx, &docs, "SourceAlpha ");
|
||||
update_doc(&mut cx, &docs, |docs, cx| docs.insert_field("Name", cx));
|
||||
update_doc(&mut cx, &docs, |docs, cx| docs.field_here("Name", cx));
|
||||
let beta = blank(&mut cx, &docs);
|
||||
type_into(&mut cx, &docs, "SourceBeta ");
|
||||
update_doc(&mut cx, &docs, |docs, cx| docs.insert_field("Name", cx));
|
||||
update_doc(&mut cx, &docs, |docs, cx| docs.field_here("Name", cx));
|
||||
settled(&cx, &docs);
|
||||
let csv = dir.path().join("two.csv");
|
||||
std::fs::write(&csv, "Name\nAda\nGrace\n").expect("the csv writes");
|
||||
|
||||
@@ -56,6 +56,19 @@ const CHECK: &str = r#"
|
||||
inline: seen(view.querySelector('.milkdown p .katex')),
|
||||
display: seen(view.querySelector('.milkdown p .katex-display')),
|
||||
tasks: view.querySelectorAll('li[data-item-type="task"]').length,
|
||||
boxes: [...view.querySelectorAll('li[data-item-type="task"]')].map((item) => {
|
||||
const mark = getComputedStyle(item, '::before');
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(item.querySelector('p'));
|
||||
const line = range.getClientRects()[0];
|
||||
const top = item.getBoundingClientRect().top + parseFloat(mark.marginTop);
|
||||
const size = parseFloat(getComputedStyle(item).fontSize);
|
||||
const shown = mark.display !== 'none' && mark.visibility === 'visible' && parseFloat(mark.opacity) > 0;
|
||||
// A laid-out box pushes the text 1.5em in.
|
||||
const inset = (item.querySelector('p').getBoundingClientRect().left - item.getBoundingClientRect().left) / size;
|
||||
const drawn = shown && mark.content !== 'none' && parseFloat(mark.borderTopWidth) > 0 && Math.abs(inset - 1.5) < 0.05;
|
||||
return [parseFloat(mark.width) / size, parseFloat(mark.height) / size, top + parseFloat(mark.height) / 2 - (line.top + line.height / 2), drawn];
|
||||
}),
|
||||
cells: view.querySelectorAll('.milkdown td').length,
|
||||
notes: view.querySelectorAll('[data-type="footnote_definition"]').length,
|
||||
blocks,
|
||||
|
||||
@@ -29,6 +29,14 @@ impl Desk {
|
||||
return;
|
||||
}
|
||||
tab.extra.heard = changed;
|
||||
self.save_after_pause(id, cx);
|
||||
}
|
||||
|
||||
/// Counts unsaved text as an edit; saves after the pause.
|
||||
pub fn save_after_pause(&mut self, id: u64, cx: &mut Context<Self>) {
|
||||
let Some(tab) = self.tab_mut(id) else {
|
||||
return;
|
||||
};
|
||||
tab.extra.policy.edit(Instant::now());
|
||||
cx.spawn(async move |desk, cx| {
|
||||
let wait = DEBOUNCE + Duration::from_millis(50);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use ely_files::{Fingerprint, Policy, PolicyEngine};
|
||||
use ely_files::Fingerprint;
|
||||
use ely_gpui_component::{
|
||||
buttons::{Button, ButtonVariant},
|
||||
git::{self as merging, Region, Take, ThreeWayMerge},
|
||||
@@ -102,7 +102,7 @@ impl Desk {
|
||||
Choice::Mine => {
|
||||
if let Some(tab) = self.tab_mut(id) {
|
||||
tab.session.rebase(fingerprint);
|
||||
tab.extra.policy = PolicyEngine::new(Policy::MarkAutoSave, true);
|
||||
tab.extra.restart_autosave();
|
||||
}
|
||||
self.set_outside(id, Outside::Clear, cx);
|
||||
self.save(id, None, window, cx);
|
||||
@@ -120,7 +120,7 @@ impl Desk {
|
||||
return self.set_outside(id, Outside::Unread(why), cx);
|
||||
}
|
||||
tab.extra.base = disk.text.clone();
|
||||
tab.extra.policy = PolicyEngine::new(Policy::MarkAutoSave, true);
|
||||
tab.extra.restart_autosave();
|
||||
tab.doc.lock().expect("the text lock").source = disk;
|
||||
let view = tab.view.clone();
|
||||
view.update(cx, |view, cx| view.adopt(merged, cx));
|
||||
|
||||
@@ -81,6 +81,11 @@ impl Host for Desk {
|
||||
&mut self.core
|
||||
}
|
||||
|
||||
/// A quit records the open tabs first.
|
||||
fn quitting(&mut self, cx: &mut Context<Self>) {
|
||||
self.leave(cx);
|
||||
}
|
||||
|
||||
/// A quit or close stopped: the kept list follows again.
|
||||
fn close_cancelled(&mut self, cx: &mut Context<Self>) {
|
||||
self.keeping.leaving = false;
|
||||
@@ -215,7 +220,7 @@ pub fn open(app: AppId, window: &mut Window, cx: &mut App) -> Entity<Root> {
|
||||
let asked = ely_ui::launch_files(cx);
|
||||
desk.update(cx, |desk, cx| {
|
||||
desk.core.root = root.downgrade();
|
||||
desk.core.window = Some(window.window_handle());
|
||||
desk.own_window(window, cx);
|
||||
window.focus(&desk.core.focus, cx);
|
||||
// Launch files stand alone; unsaved text still returns.
|
||||
if asked.is_empty() {
|
||||
@@ -403,10 +408,6 @@ impl Render for Desk {
|
||||
.on_action(cx.listener(Self::on_export))
|
||||
.on_action(cx.listener(Self::on_print))
|
||||
.on_action(cx.listener(Self::on_close_tab))
|
||||
.on_action(cx.listener(|desk, quit, window, cx| {
|
||||
desk.leave(cx);
|
||||
desk.on_quit(quit, window, cx)
|
||||
}))
|
||||
.on_action(cx.listener(|desk, _: &InsertTable, _, cx| desk.table("insert", cx)))
|
||||
.on_action(cx.listener(|desk, _: &RowAbove, _, cx| desk.table("row-above", cx)))
|
||||
.on_action(cx.listener(|desk, _: &RowBelow, _, cx| desk.table("row-below", cx)))
|
||||
|
||||
@@ -343,9 +343,7 @@ impl Desk {
|
||||
if !job.lost.whole() {
|
||||
self.warn_lost(&job.lost, None, cx);
|
||||
}
|
||||
return ely_office::print_later(pdf, cx, |desk, why, cx| {
|
||||
desk.exported(Err(io::Error::other(why)), cx)
|
||||
});
|
||||
return ely_office::print_later(pdf, cx);
|
||||
};
|
||||
// Never over the open file, not even through a link.
|
||||
let moved = not_open(self, &to)
|
||||
|
||||
@@ -55,6 +55,14 @@ pub struct Extra {
|
||||
pub restored: bool,
|
||||
}
|
||||
|
||||
impl Extra {
|
||||
/// Autosave from scratch; a write in flight no longer counts.
|
||||
pub fn restart_autosave(&mut self) {
|
||||
self.policy = PolicyEngine::new(Policy::MarkAutoSave, true);
|
||||
self.writing = None;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Extra {
|
||||
fn default() -> Self {
|
||||
Extra {
|
||||
@@ -217,11 +225,26 @@ impl Desk {
|
||||
Ok(read) => read,
|
||||
Err(error) => return self.set_outside(id, Outside::Unread(error.to_string()), cx),
|
||||
};
|
||||
// Keys the page has not sent yet count first.
|
||||
if !self.settled(id, cx) {
|
||||
return self.when_settled(id, move |desk, _, cx| desk.disk_read(id, path, Ok((fingerprint, disk)), cx));
|
||||
}
|
||||
let current = tab.doc.lock().expect("the text lock").current.clone();
|
||||
let kept = disk.text == tab.extra.base;
|
||||
let dirty = tab.dirty(cx);
|
||||
log::info!("mark: {} changed outside; unsaved {dirty}", path.display());
|
||||
match (disk.text == current, dirty) {
|
||||
(true, _) | (false, false) => self.take_disk(id, disk, fingerprint, cx),
|
||||
// The same text: only the file underneath is new.
|
||||
(true, _) => {
|
||||
if let Some(view) = self.adopt_disk(id, &disk, fingerprint, cx) {
|
||||
// What shows is now saved: the tab is clean.
|
||||
let saved = crate::engine::mark(&disk.text);
|
||||
view.update(cx, |view, cx| view.saved(&saved, cx));
|
||||
}
|
||||
}
|
||||
// The text as last saved: the edits stay unsaved.
|
||||
(false, true) if kept => self.keep_edits(id, disk, fingerprint, cx),
|
||||
(false, false) => self.take_disk(id, disk, fingerprint, cx),
|
||||
(false, true) => {
|
||||
let tab = self.tab_mut(id).expect("open");
|
||||
tab.session.external_modified();
|
||||
@@ -247,14 +270,47 @@ impl Desk {
|
||||
fingerprint: Fingerprint,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if let Some(view) = self.adopt_disk(id, &disk, fingerprint, cx) {
|
||||
view.update(cx, |view, cx| view.refresh(disk, cx));
|
||||
}
|
||||
}
|
||||
|
||||
/// A new file with the saved text; edits stay.
|
||||
fn keep_edits(&mut self, id: u64, disk: Source, fingerprint: Fingerprint, cx: &mut Context<Self>) {
|
||||
let Some(tab) = self.tab_mut(id) else {
|
||||
return;
|
||||
};
|
||||
tab.session.rebase(fingerprint);
|
||||
tab.doc.lock().expect("the text lock").source = disk;
|
||||
// A conflict stopped autosave, maybe mid-write; it resumes.
|
||||
tab.extra.restart_autosave();
|
||||
let (registry, path) = (tab.registry, tab.session.path().map(Path::to_path_buf));
|
||||
if let (Some(registry), Some(path)) = (registry, path)
|
||||
&& let Err(error) = self.core.sessions.track(registry, &path)
|
||||
{
|
||||
log::warn!("mark: the replaced file did not register: {error}");
|
||||
}
|
||||
self.set_outside(id, Outside::Clear, cx);
|
||||
self.save_after_pause(id, cx);
|
||||
}
|
||||
|
||||
/// The tab takes the file as saved; returns its view.
|
||||
fn adopt_disk(
|
||||
&mut self,
|
||||
id: u64,
|
||||
disk: &Source,
|
||||
fingerprint: Fingerprint,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<gpui::Entity<crate::view::MarkView>> {
|
||||
let tab = self.tab_mut(id)?;
|
||||
if let Err(error) = tab.session.reload_at(fingerprint) {
|
||||
return self.set_outside(id, Outside::Unread(error.to_string()), cx);
|
||||
self.set_outside(id, Outside::Unread(error.to_string()), cx);
|
||||
return None;
|
||||
}
|
||||
tab.extra.base = disk.text.clone();
|
||||
tab.extra.policy = PolicyEngine::new(Policy::MarkAutoSave, true);
|
||||
tab.extra.restart_autosave();
|
||||
// Its bytes (BOM, line ends) are what saves keep now.
|
||||
tab.doc.lock().expect("the text lock").source = disk.clone();
|
||||
let (view, registry) = (tab.view.clone(), tab.registry);
|
||||
let path = tab.session.path().map(Path::to_path_buf);
|
||||
// An atomic replace is a new file underneath.
|
||||
@@ -263,8 +319,8 @@ impl Desk {
|
||||
{
|
||||
log::warn!("mark: the replaced file did not register: {error}");
|
||||
}
|
||||
view.update(cx, |view, cx| view.refresh(disk, cx));
|
||||
self.set_outside(id, Outside::Clear, cx);
|
||||
Some(view)
|
||||
}
|
||||
|
||||
pub fn set_outside(&mut self, id: u64, outside: Outside, cx: &mut Context<Self>) {
|
||||
@@ -345,3 +401,29 @@ fn watch(dirs: &[PathBuf], cx: &mut Context<Desk>) -> notify::Result<Recommended
|
||||
log::info!("mark: watching {} folders", dirs.len());
|
||||
Ok(watcher)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use ely_files::Action;
|
||||
|
||||
use super::Extra;
|
||||
|
||||
#[test]
|
||||
fn a_restarted_autosave_saves_the_next_edit() {
|
||||
let mut extra = Extra::default();
|
||||
extra.policy.set_has_path();
|
||||
extra.policy.edit(Instant::now());
|
||||
// A write was in flight when the disk changed.
|
||||
extra.writing = Some(1);
|
||||
extra.restart_autosave();
|
||||
// As autosave settles a heard write, then edits.
|
||||
if let Some(revision) = extra.writing.take() {
|
||||
extra.policy.save_finished(revision, true);
|
||||
}
|
||||
let now = Instant::now();
|
||||
extra.policy.edit(now);
|
||||
assert!(matches!(extra.policy.tick(now + Duration::from_secs(5)), Action::SaveDue(_)));
|
||||
}
|
||||
}
|
||||
@@ -116,12 +116,22 @@ a {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
/* A text-sized box, centred on the first line. */
|
||||
.milkdown li[data-item-type='task']::before {
|
||||
content: '☐ ';
|
||||
content: '';
|
||||
flex: none;
|
||||
box-sizing: border-box;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
margin-top: calc(0.25em + (1lh - 1em) / 2);
|
||||
border: 0.09em solid var(--ely-fg-muted);
|
||||
border-radius: 0.2em;
|
||||
}
|
||||
|
||||
.milkdown li[data-item-type='task'][data-checked='true']::before {
|
||||
content: '☑ ';
|
||||
border-color: var(--ely-link);
|
||||
background: var(--ely-link);
|
||||
box-shadow: inset 0 0 0 0.18em var(--ely-bg);
|
||||
}
|
||||
|
||||
.milkdown hr {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Blocks Milkdown cannot write back stay raw text (§14.3).
|
||||
import { editorViewCtx, remarkCtx, schemaCtx, serializerCtx } from '@milkdown/kit/core'
|
||||
import { canon } from './tables.js'
|
||||
import { Fragment } from '@milkdown/kit/prose/model'
|
||||
import { Selection } from '@milkdown/kit/prose/state'
|
||||
import { $nodeSchema } from '@milkdown/kit/utils'
|
||||
@@ -51,6 +52,11 @@ export function faithful(ctx, original) {
|
||||
const schema = ctx.get(schemaCtx)
|
||||
const serializer = ctx.get(serializerCtx)
|
||||
const written = (nodes) => serializer(schema.topNodeType.create(null, nodes)).replace(/\n+$/, '')
|
||||
// Table spacing is free; every cell's source must match.
|
||||
const kept = (node, text) => {
|
||||
const own = written([node])
|
||||
return own === text || canon(own) === canon(text)
|
||||
}
|
||||
const rawOf = ([from, to]) => {
|
||||
const text = original.slice(from, to)
|
||||
return schema.nodes.ely_raw.create(null, text ? schema.text(text) : null)
|
||||
@@ -68,8 +74,7 @@ export function faithful(ctx, original) {
|
||||
if (!blank)
|
||||
parsed.forEach((node, _, index) => {
|
||||
gap(last, at[index][0])
|
||||
const exact = written([node]) === original.slice(...at[index])
|
||||
nodes.push(exact ? node : rawOf(at[index]))
|
||||
nodes.push(kept(node, original.slice(...at[index])) ? node : rawOf(at[index]))
|
||||
places.push(at[index])
|
||||
last = at[index][1]
|
||||
})
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
// The document's own markers, so blocks write back unchanged.
|
||||
import { unified } from 'unified'
|
||||
import remarkParse from 'remark-parse'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import { visit } from 'unist-util-visit'
|
||||
|
||||
/** remark-stringify options most of `text` already uses. */
|
||||
/** Writing options most of `text` already uses; tables' for remark-gfm. */
|
||||
export function style(text) {
|
||||
const votes = {}
|
||||
const vote = (key, value) => {
|
||||
votes[key] ??= new Map()
|
||||
votes[key].set(value, (votes[key].get(value) ?? 0) + 1)
|
||||
}
|
||||
visit(unified().use(remarkParse).parse(text), (node) => {
|
||||
visit(unified().use(remarkParse).use(remarkGfm).parse(text), (node) => {
|
||||
const at = node.position?.start.offset
|
||||
if (at === undefined) return
|
||||
const head = text.slice(at, at + 12)
|
||||
@@ -34,6 +35,17 @@ export function style(text) {
|
||||
case 'heading':
|
||||
if (node.depth <= 2) vote('setext', head[0] !== '#')
|
||||
break
|
||||
case 'table': {
|
||||
// Row nodes leave out quote and list prefixes.
|
||||
const rows = node.children.map((row) => text.slice(row.position.start.offset, row.position.end.offset).trim())
|
||||
const padded = /\| /.test(rows[0])
|
||||
const cells = rows.flatMap((row) => row.replace(/^\||\|$/g, '').split('|'))
|
||||
const inner = (cell) => (padded ? cell.replace(/^ | $/g, '') : cell)
|
||||
vote('tableCellPadding', padded)
|
||||
// Aligned cells carry spaces beyond the padding.
|
||||
vote('tablePipeAlign', cells.some((cell) => /^\s|\s$/.test(inner(cell))))
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
const most = (key) => [...votes[key].entries()].sort((a, b) => b[1] - a[1])[0][0]
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// Tables compare by alignment and cell source, not spacing.
|
||||
import { unified } from 'unified'
|
||||
import remarkParse from 'remark-parse'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import { SKIP, visit } from 'unist-util-visit'
|
||||
|
||||
const reader = unified().use(remarkParse).use(remarkGfm)
|
||||
|
||||
/** A cell's own source, without its padding. */
|
||||
function cell(text, node) {
|
||||
const kids = node.children
|
||||
return kids.length ? text.slice(kids[0].position.start.offset, kids.at(-1).position.end.offset) : ''
|
||||
}
|
||||
|
||||
/** `text` with each table's spacing made canonical. */
|
||||
export function canon(text) {
|
||||
const tables = []
|
||||
visit(reader.parse(text), 'table', (node) => {
|
||||
tables.push(node)
|
||||
return SKIP
|
||||
})
|
||||
let out = text
|
||||
// Later tables first, so earlier offsets hold.
|
||||
for (const table of tables.reverse()) {
|
||||
const width = table.children[0].children.length
|
||||
// GFM fills a short row with empty cells.
|
||||
const rows = table.children.map((row) => {
|
||||
const cells = row.children.map((node) => cell(text, node))
|
||||
return [...cells, ...Array(Math.max(0, width - cells.length)).fill('')].join('|')
|
||||
})
|
||||
const shape = [table.align.join(','), ...rows].join('\n')
|
||||
out = `${out.slice(0, table.position.start.offset)}\u0000${shape}\u0000${out.slice(table.position.end.offset)}`
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import { keymap } from '@milkdown/kit/prose/keymap'
|
||||
import { liftListItem, sinkListItem } from '@milkdown/kit/prose/schema-list'
|
||||
import { redo, redoDepth, undoDepth } from '@milkdown/kit/prose/history'
|
||||
import { $prose, callCommand } from '@milkdown/kit/utils'
|
||||
import { insertTableCommand } from '@milkdown/kit/preset/gfm'
|
||||
import { insertTableCommand, remarkGFMPlugin } from '@milkdown/kit/preset/gfm'
|
||||
import {
|
||||
addColumnAfter,
|
||||
addColumnBefore,
|
||||
@@ -87,7 +87,9 @@ export async function visual(root, markdown, editable, texts, changed, edge) {
|
||||
.config((ctx) => {
|
||||
ctx.set(rootCtx, root)
|
||||
ctx.set(defaultValueCtx, markdown)
|
||||
ctx.update(remarkStringifyOptionsCtx, (prev) => ({ ...prev, ...style(markdown) }))
|
||||
const { tableCellPadding, tablePipeAlign, ...marks } = style(markdown)
|
||||
ctx.update(remarkStringifyOptionsCtx, (prev) => ({ ...prev, ...marks }))
|
||||
ctx.set(remarkGFMPlugin.options.key, { tableCellPadding, tablePipeAlign })
|
||||
ctx.update(editorViewOptionsCtx, (prev) => ({ ...prev, editable: () => editable }))
|
||||
})
|
||||
.use(commonmark)
|
||||
|
||||
@@ -9,10 +9,10 @@ use gpui::{AnyElement, App, Context, IntoElement, Pixels, Point, Styled as _, ca
|
||||
use crate::content::{Aim, Tool};
|
||||
use crate::layout::Placed;
|
||||
use crate::pages::{rect_on, to_view};
|
||||
use crate::view::PdfView;
|
||||
use crate::view::{PdfView, Unread};
|
||||
|
||||
/// How far a click may move, in window pixels.
|
||||
const CLICK: f32 = 3.0;
|
||||
pub(crate) const CLICK: f32 = 3.0;
|
||||
/// Pages read for their annotations at once.
|
||||
const BATCH: usize = 20;
|
||||
|
||||
@@ -77,31 +77,49 @@ impl PdfView {
|
||||
if self.reading_notes {
|
||||
return;
|
||||
}
|
||||
let wanted: Vec<usize> = pages.into_iter().filter(|page| !self.notes.contains_key(page)).take(BATCH).collect();
|
||||
let wanted: Vec<usize> = (pages.into_iter())
|
||||
.filter(|page| !self.notes.contains_key(page) && !self.unread.contains(&Unread::Notes(*page)))
|
||||
.take(BATCH)
|
||||
.collect();
|
||||
if wanted.is_empty() {
|
||||
return;
|
||||
}
|
||||
let asked = wanted.clone();
|
||||
self.reading_notes = true;
|
||||
let (doc, version) = (self.doc, self.version);
|
||||
self.off(
|
||||
// Page by page: one bad page spares the rest.
|
||||
move |worker| {
|
||||
(wanted.into_iter())
|
||||
.map(|page| Ok((page, worker.marks(doc, page)?, worker.links(doc, page)?)))
|
||||
.collect::<std::io::Result<Vec<_>>>()
|
||||
let read = (wanted.into_iter())
|
||||
.map(|page| (page, worker.marks(doc, page).and_then(|marks| Ok((marks, worker.links(doc, page)?)))))
|
||||
.collect::<Vec<_>>();
|
||||
Ok(read)
|
||||
},
|
||||
move |view, read, cx| {
|
||||
move |view, read: std::io::Result<Vec<_>>, cx| {
|
||||
view.reading_notes = false;
|
||||
if view.version != version {
|
||||
return cx.notify();
|
||||
}
|
||||
match read {
|
||||
Ok(read) => {
|
||||
for (page, marks, links) in read {
|
||||
// No worker at all: every page asked failed.
|
||||
let read = read.unwrap_or_else(|error| {
|
||||
let why = error.to_string();
|
||||
asked.into_iter().map(|page| (page, Err(std::io::Error::other(why.clone())))).collect()
|
||||
});
|
||||
let mut first = None;
|
||||
for (page, page_read) in read {
|
||||
match page_read {
|
||||
Ok((marks, links)) => {
|
||||
view.notes.insert(page, marks);
|
||||
view.links.insert(page, links);
|
||||
}
|
||||
Err(error) => {
|
||||
view.unread.insert(Unread::Notes(page));
|
||||
first.get_or_insert(error);
|
||||
}
|
||||
}
|
||||
Err(error) => view.fail("reading annotations", &error, cx),
|
||||
}
|
||||
if let Some(error) = first {
|
||||
view.fail("reading annotations", &error, cx);
|
||||
}
|
||||
cx.notify();
|
||||
},
|
||||
@@ -111,7 +129,7 @@ impl PdfView {
|
||||
|
||||
/// Reads every field name in the form, once an edit.
|
||||
pub fn ask_names(&mut self, cx: &mut Context<Self>) {
|
||||
if self.form_names.is_some() || self.reading_names {
|
||||
if self.form_names.is_some() || self.reading_names || self.unread.contains(&Unread::Names) {
|
||||
return;
|
||||
}
|
||||
self.reading_names = true;
|
||||
@@ -125,7 +143,10 @@ impl PdfView {
|
||||
}
|
||||
match read {
|
||||
Ok(names) => view.form_names = Some(names),
|
||||
Err(error) => view.fail("reading field names", &error, cx),
|
||||
Err(error) => {
|
||||
view.unread.insert(Unread::Names);
|
||||
view.fail("reading field names", &error, cx)
|
||||
}
|
||||
}
|
||||
cx.notify();
|
||||
},
|
||||
@@ -253,11 +274,12 @@ impl PdfView {
|
||||
if annots.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.settled_edit(what, cx, move |worker, doc| {
|
||||
let name = ely_platform::user::name()?;
|
||||
let author = ely_ui::settings::current(cx).author.clone();
|
||||
self.edit_at(what, move |worker, doc| {
|
||||
let name = ely_platform::user::named(&author)?;
|
||||
annots.iter_mut().for_each(|annot| annot.author = name.clone());
|
||||
worker.annotate(doc, &annots)
|
||||
});
|
||||
}, cx);
|
||||
}
|
||||
|
||||
/// A press with a drawing or form tool.
|
||||
|
||||
@@ -72,7 +72,7 @@ impl Viewer {
|
||||
let turned = unturn(margins, view.read(cx).rotate);
|
||||
let points = turned.map(|side| side * MM);
|
||||
view.update(cx, |view, cx| {
|
||||
view.edit("cropping pages", move |worker, doc| worker.crop_pages(doc, &pages, points), cx)
|
||||
view.edit_pages("cropping pages", move |worker, doc| worker.crop_pages(doc, &pages, points), cx)
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
@@ -136,7 +136,7 @@ impl Viewer {
|
||||
}
|
||||
|
||||
fn failed_write(&self, name: &str, error: &io::Error, cx: &mut App) {
|
||||
if error.kind() == io::ErrorKind::PermissionDenied {
|
||||
if ely_pdf_engine::refused(error).is_some() {
|
||||
return self.failed(error, cx);
|
||||
}
|
||||
let text = Self::text(cx, "office.error.save", &[("name", name), ("error", &error.to_string())]);
|
||||
@@ -183,7 +183,7 @@ impl Viewer {
|
||||
written.map(|()| targets.len())
|
||||
},
|
||||
move |viewer, done, _, cx| match done {
|
||||
Ok(count) => viewer.toast_output(Self::text(cx, "pdf.split.done", &[("count", &count.to_string())]), opened.clone(), cx),
|
||||
Ok(count) => viewer.toast_output(ely_ui::i18n::counted(cx, "pdf.split.done", count as u64, &[("count", &count.to_string())]), opened.clone(), cx),
|
||||
Err(error) => viewer.failed_write(&stem, &error, cx),
|
||||
},
|
||||
cx,
|
||||
@@ -205,8 +205,7 @@ impl Viewer {
|
||||
};
|
||||
let card = match self.ask.as_ref()? {
|
||||
Ask::Crop { pages, margins, .. } => {
|
||||
let count = pages.len().to_string();
|
||||
let title = Self::text(cx, "pdf.crop.title", &[("count", &count)]);
|
||||
let title = ely_ui::i18n::counted(cx, "pdf.crop.title", pages.len() as u64, &[("count", &pages.len().to_string())]);
|
||||
let sides = ["top", "right", "bottom", "left"];
|
||||
let rows = sides.iter().enumerate().fold(DescriptionList::new(), |rows, (at, side)| {
|
||||
let name = label(&format!("pdf.crop.{side}"));
|
||||
|
||||
@@ -15,7 +15,7 @@ use gpui::{
|
||||
};
|
||||
|
||||
use crate::document::{RemoveAttachment, SaveAttachment};
|
||||
use crate::view::PdfView;
|
||||
use crate::view::{PdfView, Unread};
|
||||
use crate::viewer::Viewer;
|
||||
|
||||
/// A size as people read it.
|
||||
@@ -30,7 +30,7 @@ pub fn size(bytes: u64) -> String {
|
||||
impl PdfView {
|
||||
/// Reads the attachments once an edit.
|
||||
pub fn ask_files(&mut self, cx: &mut Context<Self>) {
|
||||
if self.files.is_some() || self.reading_files {
|
||||
if self.files.is_some() || self.reading_files || self.unread.contains(&Unread::Files) {
|
||||
return;
|
||||
}
|
||||
self.reading_files = true;
|
||||
@@ -44,7 +44,10 @@ impl PdfView {
|
||||
}
|
||||
match read {
|
||||
Ok(files) => view.files = Some(files),
|
||||
Err(error) => view.fail("reading attachments", &error, cx),
|
||||
Err(error) => {
|
||||
view.unread.insert(Unread::Files);
|
||||
view.fail("reading attachments", &error, cx)
|
||||
}
|
||||
}
|
||||
cx.notify();
|
||||
},
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
//! Old tiles stay under a page until new ones land.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::RenderImage;
|
||||
|
||||
use crate::layout::{Placed, visible};
|
||||
use crate::pages::{TILE, TileKey};
|
||||
use crate::view::PdfView;
|
||||
|
||||
/// A tile no longer current and its page's size then.
|
||||
pub struct Old {
|
||||
pub key: TileKey,
|
||||
pub image: Arc<RenderImage>,
|
||||
pub size: (f32, f32),
|
||||
}
|
||||
|
||||
/// A page on screen: place, device size, tiles in view.
|
||||
pub struct Showing {
|
||||
pub place: Placed,
|
||||
pub device: (i32, i32),
|
||||
pub keys: Vec<(TileKey, [i32; 4])>,
|
||||
}
|
||||
|
||||
/// Where `key`'s tile sat in its page, as fractions.
|
||||
fn fraction(key: &TileKey, size: (f32, f32)) -> [f32; 4] {
|
||||
let (w, h) = match key.rotate.rem_euclid(180) {
|
||||
90 => (size.1, size.0),
|
||||
_ => size,
|
||||
};
|
||||
let scale = key.scale as f32 / 1000.0;
|
||||
let (dw, dh) = ((w * scale).ceil(), (h * scale).ceil());
|
||||
let (x, y) = ((key.tx * TILE) as f32, (key.ty * TILE) as f32);
|
||||
[x / dw, y / dh, (TILE as f32).min(dw - x) / dw, (TILE as f32).min(dh - y) / dh]
|
||||
}
|
||||
|
||||
impl PdfView {
|
||||
/// The pages in view and the tiles each needs.
|
||||
pub fn showing(&self, sf: f32, dark: bool) -> Vec<Showing> {
|
||||
let laid = self.laid_out();
|
||||
let (room_w, room_h) = (f32::from(self.room.size.width), f32::from(self.room.size.height));
|
||||
let (left, top) = (-f32::from(self.scroll.offset().x), -f32::from(self.scroll.offset().y));
|
||||
let scale = (laid.scale * sf * 1000.0).round() as u32;
|
||||
visible(&laid, top, top + room_h)
|
||||
.filter(|p| p.x < left + room_w && p.x + p.w > left)
|
||||
.map(|place| {
|
||||
let (dw, dh) = ((place.w * sf).ceil() as i32, (place.h * sf).ceil() as i32);
|
||||
let ys = crate::pages::span(top - place.y, top + room_h - place.y, sf, dh);
|
||||
let xs = crate::pages::span(left - place.x, left + room_w - place.x, sf, dw);
|
||||
let keys = ys
|
||||
.flat_map(|ty| xs.clone().map(move |tx| (tx, ty)))
|
||||
.map(|(tx, ty)| {
|
||||
let key = TileKey { page: place.page, scale, rotate: self.rotate, dark, tx, ty };
|
||||
(key, [tx * TILE, ty * TILE, TILE.min(dw - tx * TILE), TILE.min(dh - ty * TILE)])
|
||||
})
|
||||
.collect();
|
||||
Showing { place: *place, device: (dw, dh), keys }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// What a page draws, bottom first, in page fractions.
|
||||
pub fn pieces(&self, showing: &Showing) -> Vec<(Arc<RenderImage>, [f32; 4])> {
|
||||
let (dw, dh) = (showing.device.0 as f32, showing.device.1 as f32);
|
||||
let current = showing.keys.iter().filter_map(|(key, rect)| {
|
||||
let at = [rect[0] as f32 / dw, rect[1] as f32 / dh, rect[2] as f32 / dw, rect[3] as f32 / dh];
|
||||
self.tiles.get(key).map(|image| (image.clone(), at))
|
||||
});
|
||||
if showing.keys.iter().all(|(key, _)| self.tiles.contains_key(key)) {
|
||||
return current.collect();
|
||||
}
|
||||
// Old tiles of this page fill in underneath.
|
||||
let page = showing.place.page;
|
||||
let size = self.sizes[page];
|
||||
let scale = showing.keys.first().map(|(key, _)| key.scale);
|
||||
let rescaled = self
|
||||
.tiles
|
||||
.iter()
|
||||
.filter(|(key, _)| key.page == page && key.rotate == self.rotate && Some(key.scale) != scale)
|
||||
.map(|(key, image)| (image.clone(), fraction(key, size)));
|
||||
let kept = self
|
||||
.backdrop
|
||||
.iter()
|
||||
.filter(|old| old.key.page == page && old.key.rotate == self.rotate && old.size == size)
|
||||
.map(|old| (old.image.clone(), fraction(&old.key, old.size)));
|
||||
kept.chain(rescaled).chain(current).collect()
|
||||
}
|
||||
|
||||
/// Keeps every tile under its page, as before an edit.
|
||||
pub fn keep_all(&mut self) {
|
||||
let sizes = &self.sizes;
|
||||
let old = self.tiles.drain().map(|(key, image)| Old { key, image, size: sizes[key.page] });
|
||||
self.backdrop.extend(old);
|
||||
}
|
||||
|
||||
/// Moves unseen tiles under their page; drops covered ones.
|
||||
pub fn settle(&mut self, showing: &[Showing]) {
|
||||
let shown = |page: usize| showing.iter().find(|s| s.place.page == page);
|
||||
let seen = |key: &TileKey| shown(key.page).is_some_and(|s| s.keys.iter().any(|(k, _)| k == key));
|
||||
let leaving: Vec<TileKey> = self.tiles.keys().filter(|key| !seen(key)).copied().collect();
|
||||
for key in leaving {
|
||||
let image = self.tiles.remove(&key).expect("a tile just listed");
|
||||
match shown(key.page) {
|
||||
Some(_) => self.backdrop.push(Old { key, image, size: self.sizes[key.page] }),
|
||||
None => self.retired.push(image),
|
||||
}
|
||||
}
|
||||
let covered = |page: usize| shown(page).is_none_or(|s| s.keys.iter().all(|(key, _)| self.tiles.contains_key(key)));
|
||||
let (sizes, rotate) = (&self.sizes, self.rotate);
|
||||
let (gone, kept): (Vec<Old>, Vec<Old>) = std::mem::take(&mut self.backdrop).into_iter().partition(|old| {
|
||||
covered(old.key.page) || old.key.rotate != rotate || sizes.get(old.key.page) != Some(&old.size)
|
||||
});
|
||||
self.backdrop = kept;
|
||||
for old in gone {
|
||||
self.retired.push(old.image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_tile_keeps_its_place_as_a_fraction_of_its_page() {
|
||||
let key = TileKey { page: 0, scale: 2000, rotate: 0, dark: false, tx: 1, ty: 0 };
|
||||
// A 612 by 792 page at 2x: 1224 by 1584.
|
||||
assert_eq!(fraction(&key, (612.0, 792.0)), [512.0 / 1224.0, 0.0, 512.0 / 1224.0, 512.0 / 1584.0]);
|
||||
let turned = TileKey { rotate: 90, ..key };
|
||||
assert_eq!(fraction(&turned, (612.0, 792.0)), [512.0 / 1584.0, 0.0, 512.0 / 1584.0, 512.0 / 1224.0]);
|
||||
}
|
||||
}
|
||||
+32
-10
@@ -8,7 +8,7 @@ use gpui::{AnyElement, App, Context, IntoElement, Pixels, Point, Styled as _, di
|
||||
|
||||
use crate::layout::Placed;
|
||||
use crate::pages::rect_on;
|
||||
use crate::view::PdfView;
|
||||
use crate::view::{PdfView, Unread};
|
||||
|
||||
/// What a press on a page does.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
@@ -76,6 +76,10 @@ pub struct Drag {
|
||||
pub from: (f32, f32),
|
||||
pub now: (f32, f32),
|
||||
pub scale: bool,
|
||||
/// Where the press landed, in window pixels.
|
||||
pub pressed: (f32, f32),
|
||||
/// The pointer went past a click's slack.
|
||||
pub moved: bool,
|
||||
}
|
||||
|
||||
/// The corner handle's reach, in page points.
|
||||
@@ -107,6 +111,11 @@ fn inside(rect: &[f32; 4], (x, y): (f32, f32)) -> bool {
|
||||
x >= rect[0] && x <= rect[2] && y >= rect[1] && y <= rect[3]
|
||||
}
|
||||
|
||||
/// Whether `outer` holds all of `inner`.
|
||||
fn covers(outer: &[f32; 4], inner: &[f32; 4]) -> bool {
|
||||
outer[0] <= inner[0] && outer[1] <= inner[1] && outer[2] >= inner[2] && outer[3] >= inner[3]
|
||||
}
|
||||
|
||||
impl PdfView {
|
||||
/// A drag or drawing is under way.
|
||||
pub fn gesturing(&self) -> bool {
|
||||
@@ -130,7 +139,9 @@ impl PdfView {
|
||||
if !self.tool.edits() || self.reading_layer {
|
||||
return;
|
||||
}
|
||||
let Some(page) = pages.iter().copied().find(|page| !self.layers.contains_key(page)) else {
|
||||
let Some(page) = (pages.iter().copied())
|
||||
.find(|page| !self.layers.contains_key(page) && !self.unread.contains(&Unread::Layer(*page)))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
self.reading_layer = true;
|
||||
@@ -147,7 +158,10 @@ impl PdfView {
|
||||
Ok(layer) => {
|
||||
view.layers.insert(page, layer);
|
||||
}
|
||||
Err(error) => view.fail("reading what the page holds", &error, cx),
|
||||
Err(error) => {
|
||||
view.unread.insert(Unread::Layer(page));
|
||||
view.fail("reading what the page holds", &error, cx)
|
||||
}
|
||||
}
|
||||
cx.notify();
|
||||
},
|
||||
@@ -174,16 +188,21 @@ impl PdfView {
|
||||
Some(Aim::Object { page: on, index }) if on == page => layer.drawn.get(index).filter(|d| corner(&d.rect)).map(|_| (index, true)),
|
||||
_ => None,
|
||||
};
|
||||
let hit = held.or_else(|| layer.drawn.iter().rposition(|d| inside(&d.rect, point)).map(|index| (index, false)));
|
||||
let text = layer.blocks.iter().position(|b| b.editable && inside(&b.rect, point));
|
||||
// Text wins over an object drawn all around it.
|
||||
let around = |rect: &[f32; 4]| text.is_some_and(|t| covers(rect, &layer.blocks[t].rect));
|
||||
let hit = held.or_else(|| {
|
||||
let object = layer.drawn.iter().rposition(|d| inside(&d.rect, point) && !around(&d.rect));
|
||||
object.map(|index| (index, false))
|
||||
});
|
||||
self.aim = match hit {
|
||||
Some((index, scale)) => {
|
||||
let rect = layer.drawn[index].rect;
|
||||
self.drag = Some(Drag { page, index, rect, from: point, now: point, scale });
|
||||
let pressed = (f32::from(at.x), f32::from(at.y));
|
||||
self.drag = Some(Drag { page, index, rect, from: point, now: point, scale, pressed, moved: false });
|
||||
Some(Aim::Object { page, index })
|
||||
}
|
||||
None => (layer.blocks.iter())
|
||||
.position(|b| b.editable && inside(&b.rect, point))
|
||||
.map(|index| Aim::Text { page, index }),
|
||||
None => text.map(|index| Aim::Text { page, index }),
|
||||
};
|
||||
cx.notify();
|
||||
}
|
||||
@@ -193,6 +212,8 @@ impl PdfView {
|
||||
return;
|
||||
};
|
||||
if let Some(drag) = self.drag.as_mut().filter(|drag| drag.page == page) {
|
||||
let far = (f32::from(at.x) - drag.pressed.0).abs() + (f32::from(at.y) - drag.pressed.1).abs();
|
||||
drag.moved |= far >= crate::annotate::CLICK;
|
||||
drag.now = point;
|
||||
cx.notify();
|
||||
}
|
||||
@@ -203,7 +224,8 @@ impl PdfView {
|
||||
let Some(drag) = self.drag.take() else {
|
||||
return;
|
||||
};
|
||||
if (drag.now.0 - drag.from.0).abs() < 1.0 && (drag.now.1 - drag.from.1).abs() < 1.0 {
|
||||
// A hand that shakes a little still clicks.
|
||||
if !drag.moved {
|
||||
return cx.notify();
|
||||
}
|
||||
// A queued edit may renumber what was dragged.
|
||||
@@ -264,7 +286,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn a_drag_moves_or_scales_from_the_top_left() {
|
||||
let mut drag = Drag { page: 0, index: 0, rect: [10.0, 20.0, 110.0, 70.0], from: (50.0, 40.0), now: (60.0, 45.0), scale: false };
|
||||
let mut drag = Drag { page: 0, index: 0, rect: [10.0, 20.0, 110.0, 70.0], from: (50.0, 40.0), now: (60.0, 45.0), scale: false, pressed: (0.0, 0.0), moved: true };
|
||||
assert_eq!(drag.change(), [1.0, 0.0, 0.0, 1.0, 10.0, 5.0]);
|
||||
assert_eq!(drag.shown(), [20.0, 25.0, 120.0, 75.0]);
|
||||
drag = Drag { from: (110.0, 70.0), now: (210.0, 80.0), scale: true, ..drag };
|
||||
|
||||
+62
-14
@@ -17,6 +17,10 @@ pub struct Queued {
|
||||
op: Op,
|
||||
pick: Option<BTreeSet<usize>>,
|
||||
doc: Doc,
|
||||
/// The edit may add, drop, move or reshape pages.
|
||||
pages: bool,
|
||||
/// Aimed at a point: runs on the state it meets.
|
||||
follow: bool,
|
||||
}
|
||||
|
||||
/// The document as an edit left it.
|
||||
@@ -36,20 +40,48 @@ impl PdfView {
|
||||
op: impl FnOnce(&mut Worker, Doc) -> io::Result<String> + Send + 'static,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.edit_picking(what, None, op, cx);
|
||||
self.queue_edit(what, None, false, op, cx);
|
||||
}
|
||||
|
||||
/// Queues a point-aimed edit; only moving pages refuse it.
|
||||
pub fn edit_at(
|
||||
&mut self,
|
||||
what: &'static str,
|
||||
op: impl FnOnce(&mut Worker, Doc) -> io::Result<String> + Send + 'static,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.moving || self.queue.iter().any(|queued| queued.pages) {
|
||||
let text = crate::viewer::Viewer::text(cx, "pdf.pages.changed", &[]);
|
||||
cx.emit(crate::view::Failed(text.to_string()));
|
||||
return cx.notify();
|
||||
}
|
||||
log::info!("pdf: queues {what}");
|
||||
self.queue.push_back(Queued { what, op: Box::new(op), pick: None, doc: self.doc, pages: false, follow: true });
|
||||
self.next_edit(cx);
|
||||
}
|
||||
|
||||
/// Queues an edit to the pages themselves.
|
||||
pub fn edit_pages(
|
||||
&mut self,
|
||||
what: &'static str,
|
||||
op: impl FnOnce(&mut Worker, Doc) -> io::Result<String> + Send + 'static,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.queue_edit(what, None, true, op, cx);
|
||||
}
|
||||
|
||||
/// Queues `op`; once it lands, `pick` is picked.
|
||||
pub fn edit_picking(
|
||||
pub fn queue_edit(
|
||||
&mut self,
|
||||
what: &'static str,
|
||||
pick: Option<BTreeSet<usize>>,
|
||||
pages: bool,
|
||||
op: impl FnOnce(&mut Worker, Doc) -> io::Result<String> + Send + 'static,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
log::info!("pdf: queues {what}");
|
||||
// Aimed at what is shown now; later states refuse it.
|
||||
self.queue.push_back(Queued { what, op: Box::new(op), pick, doc: self.doc });
|
||||
self.queue.push_back(Queued { what, op: Box::new(op), pick, doc: self.doc, pages, follow: false });
|
||||
self.next_edit(cx);
|
||||
}
|
||||
|
||||
@@ -57,10 +89,12 @@ impl PdfView {
|
||||
if self.editing {
|
||||
return;
|
||||
}
|
||||
let Some(Queued { what, op, pick, doc }) = self.queue.pop_front() else {
|
||||
let Some(Queued { what, op, pick, doc, pages, follow }) = self.queue.pop_front() else {
|
||||
return;
|
||||
};
|
||||
self.editing = true;
|
||||
// Earlier edits have landed; a point still means the same.
|
||||
let doc = if follow { self.doc } else { doc };
|
||||
(self.editing, self.moving) = (true, pages);
|
||||
self.off(
|
||||
move |worker| {
|
||||
let mark = op(worker, doc)?;
|
||||
@@ -70,10 +104,10 @@ impl PdfView {
|
||||
Ok(Fresh { doc, mark, pages, first, marks: worker.outline(doc)? })
|
||||
},
|
||||
move |view, fresh, cx| {
|
||||
view.editing = false;
|
||||
(view.editing, view.moving) = (false, false);
|
||||
match fresh {
|
||||
Ok(fresh) => {
|
||||
view.refresh(fresh, cx);
|
||||
view.refresh(fresh, pages, cx);
|
||||
if let Some(pick) = pick {
|
||||
view.anchor = pick.first().copied();
|
||||
view.picked = pick;
|
||||
@@ -93,19 +127,31 @@ impl PdfView {
|
||||
}
|
||||
|
||||
/// Everything read before the edit goes.
|
||||
fn refresh(&mut self, fresh: Fresh, cx: &mut Context<Self>) {
|
||||
fn refresh(&mut self, fresh: Fresh, pages: bool, cx: &mut Context<Self>) {
|
||||
self.version += 1;
|
||||
self.edited += 1;
|
||||
(self.doc, self.mark) = (fresh.doc, fresh.mark);
|
||||
self.sizes = sizes(fresh.pages, &fresh.first);
|
||||
let measured = sizes(fresh.pages, &fresh.first);
|
||||
if pages || fresh.pages != self.sizes.len() {
|
||||
// A page may now stand where another stood.
|
||||
self.retire_tiles();
|
||||
self.sizes = measured;
|
||||
self.thumbs_stale.clear();
|
||||
for (_, image) in self.thumbs.drain() {
|
||||
self.retired.push(image);
|
||||
}
|
||||
} else {
|
||||
// Same pages: old pictures stay until repainted.
|
||||
self.keep_all();
|
||||
self.thumbs_stale.extend(self.thumbs.keys().copied());
|
||||
let read = fresh.first.len();
|
||||
self.sizes[..read].copy_from_slice(&measured[..read]);
|
||||
}
|
||||
self.marks = fresh.marks;
|
||||
self.retire_tiles();
|
||||
self.failed.clear();
|
||||
self.unread.clear();
|
||||
self.text.clear();
|
||||
self.asking_text.clear();
|
||||
for (_, image) in self.thumbs.drain() {
|
||||
self.retired.push(image);
|
||||
}
|
||||
self.thumbs_failed.clear();
|
||||
// Indices shift with any edit; aims start over.
|
||||
(self.layers, self.aim, self.drag) = (Default::default(), None, None);
|
||||
@@ -127,8 +173,10 @@ impl PdfView {
|
||||
/// The file now holds history `mark`.
|
||||
pub fn saved(&mut self, mark: &str, cx: &mut Context<Self>) {
|
||||
self.saved = mark.to_string();
|
||||
self.saves += 1;
|
||||
// The file changed; read it again.
|
||||
self.signatures = None;
|
||||
self.unread.retain(|unread| !matches!(unread, crate::view::Unread::Signatures(_)));
|
||||
cx.emit(Reported);
|
||||
}
|
||||
|
||||
@@ -144,6 +192,6 @@ impl PdfView {
|
||||
|
||||
pub fn undo(&mut self, redo: bool, cx: &mut Context<Self>) {
|
||||
let what = if redo { "redo" } else { "undo" };
|
||||
self.edit(what, move |worker, doc| worker.undo(doc, redo), cx);
|
||||
self.edit_pages(what, move |worker, doc| worker.undo(doc, redo), cx);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
mod annotate;
|
||||
mod ask;
|
||||
mod attach;
|
||||
mod backdrop;
|
||||
mod content;
|
||||
mod document;
|
||||
mod editing;
|
||||
|
||||
@@ -161,14 +161,16 @@ impl Viewer {
|
||||
cx.notify();
|
||||
let pages: Vec<(usize, Vec<OcrLine>)> = run.read.into_iter().filter(|(_, lines)| replace || !lines.is_empty()).collect();
|
||||
let (read, skipped) = (pages.len().to_string(), run.skipped.to_string());
|
||||
let summary = Self::text(cx, "pdf.ocr.done", &[("read", &read), ("skipped", &skipped)]);
|
||||
let summary = ely_ui::i18n::counted(cx, "pdf.ocr.done", pages.len() as u64, &[("read", &read), ("skipped", &skipped)]);
|
||||
let Some(view) = self.tab(tab).map(|tab| tab.view.clone()).filter(|_| !pages.is_empty()) else {
|
||||
return self.toast(summary, Severity::Info, cx);
|
||||
};
|
||||
self.on_same(&view, run.version, cx, |view, cx| {
|
||||
let laid = self.on_same(&view, run.version, cx, |view, cx| {
|
||||
view.edit("adding recognised text", move |worker, doc| worker.text_layer(doc, &pages, replace), cx)
|
||||
});
|
||||
self.toast(summary, Severity::Success, cx);
|
||||
if laid {
|
||||
self.toast(summary, Severity::Success, cx);
|
||||
}
|
||||
}
|
||||
|
||||
/// The OCR dialog: the ask, then the progress.
|
||||
|
||||
@@ -81,7 +81,7 @@ impl PdfView {
|
||||
let pages = self.chosen_pages();
|
||||
let before = pages.iter().filter(|page| **page < to).count();
|
||||
let landed = (to - before..to - before + pages.len()).collect();
|
||||
self.edit_picking("moving pages", Some(landed), move |worker, doc| worker.move_pages(doc, &pages, to), cx);
|
||||
self.queue_edit("moving pages", Some(landed), true, move |worker, doc| worker.move_pages(doc, &pages, to), cx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,14 +105,14 @@ impl Viewer {
|
||||
}
|
||||
view.update(cx, |view, cx| {
|
||||
view.picked.clear();
|
||||
view.edit("deleting pages", move |worker, doc| worker.delete_pages(doc, &pages), cx);
|
||||
view.edit_pages("deleting pages", move |worker, doc| worker.delete_pages(doc, &pages), cx);
|
||||
});
|
||||
}
|
||||
|
||||
fn turn_pages(&mut self, by: i32, cx: &mut Context<Self>) {
|
||||
self.on_pages(cx, |view, cx| {
|
||||
let pages = view.chosen_pages();
|
||||
view.edit("turning pages", move |worker, doc| worker.rotate_pages(doc, &pages, by), cx);
|
||||
view.edit_pages("turning pages", move |worker, doc| worker.rotate_pages(doc, &pages, by), cx);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ impl Viewer {
|
||||
self.on_pages(cx, |view, cx| {
|
||||
let at = view.chosen_pages().last().copied().expect("one page at least");
|
||||
let size = view.sizes[at];
|
||||
view.edit("inserting a page", move |worker, doc| worker.insert_blank(doc, at + 1, size), cx);
|
||||
view.edit_pages("inserting a page", move |worker, doc| worker.insert_blank(doc, at + 1, size), cx);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ impl Viewer {
|
||||
self.pick(false, cx, |viewer, path: PathBuf, cx| {
|
||||
viewer.on_pages(cx, |view, cx| {
|
||||
let at = view.chosen_pages().last().copied().expect("one page at least") + 1;
|
||||
view.edit(
|
||||
view.edit_pages(
|
||||
"inserting pages",
|
||||
move |worker, doc| worker.insert_file(doc, at, &path).map(|(_, mark)| mark),
|
||||
cx,
|
||||
|
||||
@@ -95,7 +95,7 @@ impl Viewer {
|
||||
id,
|
||||
move |worker, doc| worker.get()?.print_copy(*doc, &out),
|
||||
move |viewer, done, _, cx| match done {
|
||||
Ok(()) => ely_office::print_later(printing, cx, |viewer, error, cx| viewer.panel_failed(&error, cx)),
|
||||
Ok(()) => ely_office::print_later(printing, cx),
|
||||
Err(error) => viewer.failed(&error, cx),
|
||||
},
|
||||
cx,
|
||||
@@ -177,7 +177,7 @@ impl Viewer {
|
||||
},
|
||||
move |viewer, done, _, cx| match done {
|
||||
Ok(count) => {
|
||||
let text = Self::text(cx, "pdf.export.images_done", &[("count", &count.to_string())]);
|
||||
let text = ely_ui::i18n::counted(cx, "pdf.export.images_done", count as u64, &[("count", &count.to_string())]);
|
||||
match folder.clone() {
|
||||
Some(folder) => viewer.toast_output(text, folder, cx),
|
||||
None => viewer.toast(text, Severity::Success, cx),
|
||||
@@ -203,6 +203,8 @@ impl Viewer {
|
||||
Err(error) => return self.failed(&error, cx),
|
||||
}
|
||||
let (work, path, revision) = (tab.work.join("export.out"), tab.session.path().map(PathBuf::from), tab.session.revision());
|
||||
// Unsaved edits: the file on disk is not "before".
|
||||
let compared = path.clone().filter(|_| !tab.view.read(cx).modified());
|
||||
let opened = target.clone();
|
||||
log::info!("pdf: exports {}", if kind == Kind::Text { "text" } else { "an optimized copy" });
|
||||
self.read_in(
|
||||
@@ -214,7 +216,7 @@ impl Viewer {
|
||||
}
|
||||
let bytes = std::fs::read(&work)?;
|
||||
std::fs::remove_file(&work)?;
|
||||
let before = path.as_deref().map(std::fs::metadata).transpose()?.map(|meta| meta.len());
|
||||
let before = compared.as_deref().map(std::fs::metadata).transpose()?.map(|meta| meta.len());
|
||||
ely_files::export(&target, path.as_deref(), &bytes, revision)?;
|
||||
Ok((before, bytes.len() as u64))
|
||||
},
|
||||
|
||||
+41
-57
@@ -1,6 +1,6 @@
|
||||
//! Only the pages on screen, drawn in tiles (PDF-01, PERF-05).
|
||||
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
|
||||
use ely_gpui_component::theme::ActiveTheme as _;
|
||||
use gpui::{
|
||||
@@ -10,7 +10,7 @@ use gpui::{
|
||||
};
|
||||
use image::{Frame, ImageBuffer, Rgba};
|
||||
|
||||
use crate::layout::{GAP, Layout, Mode, Placed, layout, visible};
|
||||
use crate::layout::{GAP, Layout, Mode, Placed, layout};
|
||||
use crate::view::{PdfView, Reported};
|
||||
|
||||
/// A tile's side in device pixels.
|
||||
@@ -58,7 +58,7 @@ pub fn rect_on(rect: [f32; 4], size: (f32, f32), rotate: i32, scale: f32) -> (f3
|
||||
}
|
||||
|
||||
/// Tiles covering `[from, to)` view pixels of a `side`-pixel page.
|
||||
fn span(from: f32, to: f32, sf: f32, side: i32) -> std::ops::RangeInclusive<i32> {
|
||||
pub(crate) fn span(from: f32, to: f32, sf: f32, side: i32) -> std::ops::RangeInclusive<i32> {
|
||||
let first = (from.max(0.0) * sf).floor() as i32 / TILE;
|
||||
let last = ((to * sf).ceil() as i32 - 1).min(side - 1).max(0) / TILE;
|
||||
first..=last
|
||||
@@ -69,11 +69,13 @@ fn drawn_tile(image: Arc<RenderImage>, page: usize, view: gpui::Entity<PdfView>)
|
||||
canvas(
|
||||
|_, _, _| {},
|
||||
move |bounds, _, window, cx| match window.paint_image(bounds, bounds, Default::default(), image, 0, false) {
|
||||
Ok(()) if !view.read(cx).drawn => {
|
||||
view.update(cx, |view, _| view.drawn = true);
|
||||
log::info!("pdf: first tile drawn, page {page}");
|
||||
}
|
||||
Ok(()) => {}
|
||||
Ok(()) => view.update(cx, |view, _| {
|
||||
let area = f64::from(f32::from(bounds.size.width) * f32::from(bounds.size.height));
|
||||
if view.painted == 0.0 && area > 0.0 {
|
||||
log::info!("pdf: first tile drawn, page {page}");
|
||||
}
|
||||
view.painted += area;
|
||||
}),
|
||||
Err(error) => log::error!("pdf: drawing a page failed: {error}"),
|
||||
},
|
||||
)
|
||||
@@ -127,18 +129,14 @@ impl PdfView {
|
||||
(colors.sunken, if dark { colors.surface } else { colors.paper })
|
||||
};
|
||||
let laid = self.laid_out();
|
||||
let (room_w, room_h) = (f32::from(self.room.size.width), f32::from(self.room.size.height));
|
||||
if let Some((x, y)) = self.go_to.take() {
|
||||
self.scroll.set_offset(point(px(-x), px(-y)));
|
||||
}
|
||||
let (left, top) = (-f32::from(self.scroll.offset().x), -f32::from(self.scroll.offset().y));
|
||||
let shown: Vec<Placed> = visible(&laid, top, top + room_h)
|
||||
.filter(|p| p.x < left + room_w && p.x + p.w > left)
|
||||
.copied()
|
||||
.collect();
|
||||
let top = -f32::from(self.scroll.offset().y);
|
||||
let showing = self.showing(sf, dark);
|
||||
// The current page: first showing more than a sliver.
|
||||
if let Some(first) = shown.iter().find(|p| p.y + p.h > top + GAP * 3.0) {
|
||||
let paired = shown.iter().any(|p| p.page == self.current) && first.page / 2 == self.current / 2;
|
||||
if let Some(first) = showing.iter().map(|s| s.place).find(|p| p.y + p.h > top + GAP * 3.0) {
|
||||
let paired = showing.iter().any(|s| s.place.page == self.current) && first.page / 2 == self.current / 2;
|
||||
let now = match self.mode {
|
||||
Mode::Single => self.current,
|
||||
// Either page of a pair in view may be current.
|
||||
@@ -150,47 +148,33 @@ impl PdfView {
|
||||
cx.emit(Reported);
|
||||
}
|
||||
}
|
||||
let scale = (laid.scale * sf * 1000.0).round() as u32;
|
||||
let (mut wanted, mut pages, mut seen) = (Vec::new(), Vec::new(), HashSet::new());
|
||||
for place in &shown {
|
||||
let (dw, dh) = ((place.w * sf).ceil() as i32, (place.h * sf).ceil() as i32);
|
||||
let (ys, xs) = (
|
||||
span(top - place.y, top + room_h - place.y, sf, dh),
|
||||
span(left - place.x, left + room_w - place.x, sf, dw),
|
||||
);
|
||||
let mut tiles = Vec::new();
|
||||
for ty in ys {
|
||||
for tx in xs.clone() {
|
||||
let key = TileKey { page: place.page, scale, rotate: self.rotate, dark, tx, ty };
|
||||
let rect = [tx * TILE, ty * TILE, TILE.min(dw - tx * TILE), TILE.min(dh - ty * TILE)];
|
||||
seen.insert(key);
|
||||
match self.tiles.get(&key) {
|
||||
Some(image) => tiles.push(
|
||||
drawn_tile(image.clone(), place.page, cx.entity())
|
||||
.absolute()
|
||||
.left(px(rect[0] as f32 / sf))
|
||||
.top(px(rect[1] as f32 / sf))
|
||||
.w(px(rect[2] as f32 / sf))
|
||||
.h(px(rect[3] as f32 / sf))
|
||||
.into_any_element(),
|
||||
),
|
||||
None if !self.failed.contains(&key) => wanted.push((key, rect)),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
pages.push((*place, tiles));
|
||||
}
|
||||
// Tiles out of view go.
|
||||
let retired = &mut self.retired;
|
||||
self.tiles.retain(|key, image| {
|
||||
let kept = seen.contains(key);
|
||||
if !kept {
|
||||
retired.push(image.clone());
|
||||
}
|
||||
kept
|
||||
});
|
||||
let pages_shown: Vec<usize> = shown.iter().map(|place| place.page).collect();
|
||||
let wanted: Vec<(TileKey, [i32; 4])> = showing
|
||||
.iter()
|
||||
.flat_map(|s| s.keys.iter().copied())
|
||||
.filter(|(key, _)| !self.tiles.contains_key(key) && !self.failed.contains(key))
|
||||
.collect();
|
||||
let pages: Vec<(Placed, Vec<AnyElement>)> = showing
|
||||
.iter()
|
||||
.map(|s| {
|
||||
let (w, h) = (s.place.w, s.place.h);
|
||||
let tiles = self
|
||||
.pieces(s)
|
||||
.into_iter()
|
||||
.map(|(image, at)| {
|
||||
drawn_tile(image, s.place.page, cx.entity())
|
||||
.absolute()
|
||||
.left(px(at[0] * w))
|
||||
.top(px(at[1] * h))
|
||||
.w(px(at[2] * w))
|
||||
.h(px(at[3] * h))
|
||||
.into_any_element()
|
||||
})
|
||||
.collect();
|
||||
(s.place, tiles)
|
||||
})
|
||||
.collect();
|
||||
self.settle(&showing);
|
||||
let pages_shown: Vec<usize> = showing.iter().map(|s| s.place.page).collect();
|
||||
self.ask_layers(&pages_shown, cx);
|
||||
self.ask_notes(pages_shown.iter().copied(), cx);
|
||||
self.paint(wanted, cx);
|
||||
|
||||
@@ -46,9 +46,9 @@ fn masked(window: &mut Window, cx: &mut Context<Viewer>) -> Entity<TextInput> {
|
||||
impl Viewer {
|
||||
/// A refusal names what is missing.
|
||||
pub(crate) fn failed(&self, error: &io::Error, cx: &mut App) {
|
||||
match error.kind() {
|
||||
io::ErrorKind::PermissionDenied => self.toast(crate::view::restricted(&error.to_string(), cx), Severity::Warning, cx),
|
||||
_ => self.panel_failed(&error.to_string(), cx),
|
||||
match ely_pdf_engine::refused(error) {
|
||||
Some(needed) => self.toast(crate::view::restricted(needed, cx), Severity::Warning, cx),
|
||||
None => self.panel_failed(&error.to_string(), cx),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ impl Viewer {
|
||||
},
|
||||
move |viewer, done, _, cx| match done {
|
||||
Ok(0) => viewer.toast_output(Self::text(cx, "pdf.clean.done", &[("name", &shown)]), opened.clone(), cx),
|
||||
Ok(n) => viewer.toast_output(Self::text(cx, "pdf.redact.done", &[("name", &shown), ("count", &n.to_string())]), opened.clone(), cx),
|
||||
Ok(n) => viewer.toast_output(ely_ui::i18n::counted(cx, "pdf.redact.done", n as u64, &[("name", &shown), ("count", &n.to_string())]), opened.clone(), cx),
|
||||
Err(error) => viewer.failed(&error, cx),
|
||||
},
|
||||
cx,
|
||||
@@ -200,8 +200,8 @@ impl Viewer {
|
||||
let (title, body) = match removal {
|
||||
Removal::Clean { reach, what, .. } => ("pdf.clean.title", self.clean_rows(reach, *what, &this, cx)),
|
||||
Removal::Redact { regions, .. } => {
|
||||
let count = regions.len().to_string();
|
||||
("pdf.redact.title", div().child(Self::text(cx, "pdf.redact.count", &[("count", &count)])).into_any_element())
|
||||
let count = ely_ui::i18n::counted(cx, "pdf.redact.count", regions.len() as u64, &[("count", ®ions.len().to_string())]);
|
||||
("pdf.redact.title", div().child(count).into_any_element())
|
||||
}
|
||||
};
|
||||
let title = Self::text(cx, title, &[("name", &name)]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Page pictures, and bookmarks if any (PDF-01, PDF-02).
|
||||
|
||||
use std::{collections::BTreeSet, ops::Range};
|
||||
use std::{collections::BTreeSet, ops::Range, sync::Arc};
|
||||
|
||||
use ely_gpui_component::{
|
||||
buttons::SegmentedControl,
|
||||
@@ -9,7 +9,7 @@ use ely_gpui_component::{
|
||||
theme::{ActiveTheme as _, ControlSize},
|
||||
};
|
||||
use gpui::{
|
||||
Action, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, Role,
|
||||
Action, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, RenderImage, Role,
|
||||
StatefulInteractiveElement as _, Styled as _, WeakEntity, Window, div, img, prelude::FluentBuilder as _, px,
|
||||
uniform_list,
|
||||
};
|
||||
@@ -104,7 +104,8 @@ impl PdfView {
|
||||
if self.thumbing {
|
||||
return;
|
||||
}
|
||||
let Some(page) = rows.clone().find(|page| !self.thumbs.contains_key(&(*page, dark)) && !self.thumbs_failed.contains(page)) else {
|
||||
let due = |page: &usize| !self.thumbs.contains_key(&(*page, dark)) || self.thumbs_stale.contains(&(*page, dark));
|
||||
let Some(page) = rows.clone().find(|page| due(page) && !self.thumbs_failed.contains(page)) else {
|
||||
return;
|
||||
};
|
||||
let (w, h) = self.sizes[page];
|
||||
@@ -127,6 +128,7 @@ impl PdfView {
|
||||
});
|
||||
match painted.map(|bgra| crate::pages::picture((tile[2] as u32, tile[3] as u32), bgra)) {
|
||||
Ok(Some(image)) => {
|
||||
view.thumbs_stale.remove(&(page, dark));
|
||||
if let Some(old) = view.thumbs.insert((page, dark), image) {
|
||||
view.retired.push(old);
|
||||
}
|
||||
@@ -145,13 +147,20 @@ impl PdfView {
|
||||
}
|
||||
}
|
||||
|
||||
impl PdfView {
|
||||
/// The picture a row draws; an old one until repainted.
|
||||
pub fn picture(&self, page: usize, dark: bool) -> Option<Arc<RenderImage>> {
|
||||
self.thumbs.get(&(page, dark)).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
/// One row: the page number and its picture.
|
||||
fn row(view: &Entity<PdfView>, page: usize, dark: bool, cx: &App) -> gpui::AnyElement {
|
||||
let read = view.read(cx);
|
||||
let colors = &cx.theme().colors;
|
||||
let (w, h) = read.sizes[page];
|
||||
let picked = read.picked.contains(&page);
|
||||
let picture = read.thumbs.get(&(page, dark)).cloned();
|
||||
let picture = read.picture(page, dark);
|
||||
let count = read.sizes.len();
|
||||
let label = Viewer::text(cx, "pdf.page.label", &[("n", &(page + 1).to_string())]);
|
||||
let (clicked, pressed, dropped) = (view.clone(), view.clone(), view.clone());
|
||||
|
||||
@@ -17,7 +17,7 @@ use ely_platform::trust::{self, Trust};
|
||||
use gpui::{AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, StatefulInteractiveElement as _, Styled as _, TaskExt as _, Window, div};
|
||||
|
||||
use crate::redact::beside;
|
||||
use crate::view::PdfView;
|
||||
use crate::view::{PdfView, Unread};
|
||||
use crate::viewer::Viewer;
|
||||
|
||||
/// A signature field and the system's word on its certificate.
|
||||
@@ -47,11 +47,13 @@ pub struct Signer {
|
||||
impl PdfView {
|
||||
/// Reads and checks the signatures of the file at `path`.
|
||||
pub fn ask_signatures(&mut self, path: PathBuf, cx: &mut Context<Self>) {
|
||||
if self.signatures.as_ref().is_some_and(|(read, _)| *read == path) || self.reading_signatures {
|
||||
let failed = self.unread.contains(&Unread::Signatures(path.clone()));
|
||||
if self.signatures.as_ref().is_some_and(|(read, _)| *read == path) || self.reading_signatures || failed {
|
||||
return;
|
||||
}
|
||||
self.reading_signatures = true;
|
||||
let (doc, asked) = (self.doc, path.clone());
|
||||
// A save in between makes this read stale: dropped.
|
||||
let (doc, asked, saves) = (self.doc, path.clone(), self.saves);
|
||||
self.off(
|
||||
move |worker| {
|
||||
let fields = worker.signatures(doc, &path)?;
|
||||
@@ -64,9 +66,16 @@ impl PdfView {
|
||||
},
|
||||
move |view, read: io::Result<Vec<Checked>>, cx| {
|
||||
view.reading_signatures = false;
|
||||
if view.saves != saves {
|
||||
log::info!("pdf: a signature read from before a save is dropped");
|
||||
return cx.notify();
|
||||
}
|
||||
match read {
|
||||
Ok(read) => view.signatures = Some((asked, read)),
|
||||
Err(error) => view.fail("reading signatures", &error, cx),
|
||||
Err(error) => {
|
||||
view.unread.insert(Unread::Signatures(asked));
|
||||
view.fail("reading signatures", &error, cx)
|
||||
}
|
||||
}
|
||||
cx.notify();
|
||||
},
|
||||
|
||||
@@ -18,6 +18,7 @@ mod notes;
|
||||
mod organize;
|
||||
mod output;
|
||||
mod protect;
|
||||
mod reads;
|
||||
mod removal;
|
||||
mod sign;
|
||||
mod structure;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Editing text and objects from the app (C11.3).
|
||||
|
||||
use ely_pdf_engine::sample::{Extras, pdf_with};
|
||||
use ely_pdf_engine::sample::{Extras, one_page, pdf_with};
|
||||
use gpui::{Entity, Modifiers, MouseButton, TestAppContext, VisualTestContext};
|
||||
|
||||
use super::input::over;
|
||||
@@ -339,3 +339,91 @@ fn a_drag_follows_the_hand_when_the_page_shifts_under_it() {
|
||||
let rect = cx.update(|_, app| view.read(app).layers[&0].drawn[1].rect);
|
||||
assert!((rect[0] - 122.0).abs() < 0.5, "moved as far as the hand: {rect:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_on_a_full_page_picture_aims_at_the_text_and_a_shake_stays_a_click() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = dir.path().join("scan.pdf");
|
||||
let extras = Extras { picture: true, backdrop: true, ..Extras::default() };
|
||||
std::fs::write(&path, pdf_with(&[(612.0, 792.0, &["Hello world"])], &[], &extras)).expect("writes");
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
settle(cx, |app| view.read(app).room.size.width > gpui::px(100.0));
|
||||
cx.update(|_, app| view.update(app, |view, cx| {
|
||||
view.zoom = crate::layout::Zoom::Scale(1.0);
|
||||
view.set_tool(Tool::Edit, cx)
|
||||
}));
|
||||
settle(cx, |app| view.read(app).layers.contains_key(&0));
|
||||
click(cx, &view, (80.0, 66.0));
|
||||
assert!(matches!(cx.update(|_, app| view.read(app).aim), Some(Aim::Text { .. })), "the text, not the picture under it");
|
||||
// A two-pixel wobble on the picture moves nothing.
|
||||
let from = over(cx, &view, 0, (300.0, 400.0));
|
||||
cx.simulate_mouse_down(from, MouseButton::Left, Modifiers::none());
|
||||
let to = from + gpui::point(gpui::px(2.0), gpui::px(0.0));
|
||||
cx.simulate_mouse_move(to, MouseButton::Left, Modifiers::none());
|
||||
cx.simulate_mouse_up(to, MouseButton::Left, Modifiers::none());
|
||||
frames(cx);
|
||||
assert!(matches!(cx.update(|_, app| view.read(app).aim), Some(Aim::Object { .. })), "the picture is aimed");
|
||||
assert_eq!(cx.update(|_, app| view.read(app).edited), 0, "and not moved");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_small_picture_on_text_under_a_page_form_still_aims() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = dir.path().join("layered.pdf");
|
||||
// The page-size form comes last, on top of both.
|
||||
let content = "q 10 0 0 10 80 722 cm /Im1 Do Q BT /F1 18 Tf 72 720 Td (Hello world) Tj ET q /Fm1 Do Q";
|
||||
let form = "0 0 1 rg 500 50 20 20 re f";
|
||||
let objects = [
|
||||
"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>".to_string(),
|
||||
format!("<< /Type /XObject /Subtype /Form /BBox [0 0 612 792] /Length {} >>\nstream\n{form}\nendstream", form.len()),
|
||||
"<< /Type /XObject /Subtype /Image /Width 1 /Height 1 /ColorSpace /DeviceGray /BitsPerComponent 8 /Length 1 >>\nstream\nA\nendstream".to_string(),
|
||||
];
|
||||
let page = " /Resources << /Font << /F1 5 0 R >> /XObject << /Fm1 6 0 R /Im1 7 0 R >> >>";
|
||||
std::fs::write(&path, one_page("", page, content, &objects)).expect("writes");
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
settle(cx, |app| view.read(app).room.size.width > gpui::px(100.0));
|
||||
cx.update(|_, app| view.update(app, |view, cx| {
|
||||
view.zoom = crate::layout::Zoom::Scale(1.0);
|
||||
view.set_tool(Tool::Edit, cx)
|
||||
}));
|
||||
settle(cx, |app| view.read(app).layers.contains_key(&0));
|
||||
// The picture sits at 80..90 across, 60..70 down.
|
||||
click(cx, &view, (85.0, 65.0));
|
||||
assert!(matches!(cx.update(|_, app| view.read(app).aim), Some(Aim::Object { index: 0, .. })), "the small picture");
|
||||
click(cx, &view, (140.0, 66.0));
|
||||
assert!(matches!(cx.update(|_, app| view.read(app).aim), Some(Aim::Text { .. })), "the text, not the form around it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_preview_overtaken_by_an_edit_says_so() {
|
||||
use ely_gpui_component::primitives::Severity;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let (viewer, cx, view) = editing(&mut cx, dir.path());
|
||||
// The window's toasts live on its root.
|
||||
let root = cx.update(|window, app| {
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Pdf, viewer.clone().into(), &ely_ui::commands::FILE, Vec::new(), window, app);
|
||||
viewer.update(app, |viewer, _| viewer.core.root = root.downgrade());
|
||||
root
|
||||
});
|
||||
click(cx, &view, (80.0, 66.0));
|
||||
type_in(cx, &viewer, "Hi world\nSecond line");
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| {
|
||||
// A new font asks for a preview first.
|
||||
viewer.edit_panel.update(cx, |panel, _| panel.font = "times".into());
|
||||
viewer.write_text(false, cx);
|
||||
// An edit lands before the preview answers.
|
||||
if let Some(view) = viewer.active_view() {
|
||||
view.update(cx, |view, _| view.version += 1);
|
||||
}
|
||||
}));
|
||||
let changed = cx.update(|_, app| Viewer::text(app, "pdf.object.changed", &[]));
|
||||
settle(cx, |app| root.read(app).toasts(app).iter().any(|(text, severity)| *severity == Some(Severity::Warning) && *text == changed));
|
||||
frames(cx);
|
||||
assert!(cx.update(|_, app| viewer.read(app).preview.is_none()), "no stale preview");
|
||||
assert_eq!(cx.update(|_, app| view.read(app).edited), 0, "nothing written");
|
||||
}
|
||||
@@ -185,3 +185,172 @@ fn tiles_beside_the_view_are_neither_asked_nor_kept() {
|
||||
}));
|
||||
settle(cx, |app| columns(app).contains(&last) && !columns(app).contains(&0));
|
||||
}
|
||||
|
||||
/// Flags any notify leaving a shown page with nothing drawn.
|
||||
fn never_bare(cx: &mut VisualTestContext, view: &Entity<PdfView>) -> (gpui::Subscription, std::rc::Rc<std::cell::Cell<bool>>) {
|
||||
let (sf, dark) = cx.update(|window, app| (window.scale_factor(), ely_gpui_component::theme::ActiveTheme::theme(app).is_dark()));
|
||||
let bare = std::rc::Rc::new(std::cell::Cell::new(false));
|
||||
let seen = bare.clone();
|
||||
let watch = cx.update(|_, app| {
|
||||
app.observe(view, move |view, app| {
|
||||
let read = view.read(app);
|
||||
if read.showing(sf, dark).iter().any(|page| read.pieces(page).is_empty()) {
|
||||
seen.set(true);
|
||||
}
|
||||
})
|
||||
});
|
||||
(watch, bare)
|
||||
}
|
||||
|
||||
/// Only new tiles drawn, and none on its way.
|
||||
fn repainted(view: &PdfView) -> bool {
|
||||
view.backdrop.is_empty() && !view.painting && !view.tiles.is_empty()
|
||||
}
|
||||
|
||||
fn note() -> ely_pdf_engine::NewAnnot {
|
||||
ely_pdf_engine::NewAnnot {
|
||||
page: 0,
|
||||
shape: ely_pdf_engine::Shape::Note((100.0, 500.0)),
|
||||
rgb: None,
|
||||
contents: "Look".into(),
|
||||
author: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_keeps_the_page_drawn_until_its_repaint_lands() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[file(dir.path(), "one.pdf", &[(612.0, 792.0, &["Hello"])])], true);
|
||||
let view = shown(cx, &viewer);
|
||||
settle(cx, |app| repainted(view.read(app)));
|
||||
let before: Vec<_> = cx.update(|_, app| view.read(app).tiles.values().cloned().collect());
|
||||
let (_watch, bare) = never_bare(cx, &view);
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.annotate("adding a note", vec![note()], cx)));
|
||||
settle(cx, |app| view.read(app).edited == 1 && repainted(view.read(app)));
|
||||
assert!(!bare.get(), "the page never goes blank");
|
||||
let after = cx.update(|_, app| view.read(app).tiles.values().cloned().collect::<Vec<_>>());
|
||||
assert!(
|
||||
after.iter().all(|image| before.iter().all(|old| !std::sync::Arc::ptr_eq(old, image))),
|
||||
"every tile was painted again"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_scale_keeps_the_old_tiles_until_new_ones_land() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[file(dir.path(), "one.pdf", &[(612.0, 792.0, &["Hello"])])], true);
|
||||
let view = shown(cx, &viewer);
|
||||
settle(cx, |app| repainted(view.read(app)));
|
||||
let scale = cx.update(|_, app| view.read(app).laid_out().scale);
|
||||
let (_watch, bare) = never_bare(cx, &view);
|
||||
cx.simulate_resize(gpui::size(px(700.), px(800.)));
|
||||
// The new size lays out before any new tile lands.
|
||||
cx.run_until_parked();
|
||||
let (sf, dark) = cx.update(|window, app| (window.scale_factor(), ely_gpui_component::theme::ActiveTheme::theme(app).is_dark()));
|
||||
let now = cx.update(|_, app| {
|
||||
let read = view.read(app);
|
||||
read.showing(sf, dark).iter().map(|page| read.pieces(page).len()).collect::<Vec<_>>()
|
||||
});
|
||||
assert!(now.iter().all(|count| *count > 0), "drawn right after the resize: {now:?}");
|
||||
settle(cx, |app| view.read(app).laid_out().scale != scale && repainted(view.read(app)));
|
||||
assert!(!bare.get(), "the page never goes blank");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_past_the_first_hundred_sizes_keeps_the_page_drawn() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut pages: Vec<(f32, f32, &[&str])> = vec![(612.0, 792.0, &["Page"]); 100];
|
||||
pages.push((612.0, 900.0, &["Taller"]));
|
||||
let mut cx = TestAppContext::single();
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[file(dir.path(), "mixed.pdf", &pages)], true);
|
||||
let view = shown(cx, &viewer);
|
||||
settle(cx, |app| view.read(app).sizes[100] == (612.0, 900.0) && repainted(view.read(app)));
|
||||
let (_watch, bare) = never_bare(cx, &view);
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.annotate("adding a note", vec![note()], cx)));
|
||||
settle(cx, |app| view.read(app).edited == 1 && repainted(view.read(app)));
|
||||
assert!(!bare.get(), "the page never goes blank");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_on_page_101_keeps_its_measured_size_and_its_tiles() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut pages: Vec<(f32, f32, &[&str])> = vec![(612.0, 792.0, &["Page"]); 100];
|
||||
pages.push((612.0, 900.0, &["Taller"]));
|
||||
let mut cx = TestAppContext::single();
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[file(dir.path(), "mixed.pdf", &pages)], true);
|
||||
let view = shown(cx, &viewer);
|
||||
settle(cx, |app| view.read(app).sizes[100] == (612.0, 900.0));
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.show(100, 0.0, cx)));
|
||||
settle(cx, |app| view.read(app).current == 100 && repainted(view.read(app)));
|
||||
let (_watch, bare) = never_bare(cx, &view);
|
||||
let late = ely_pdf_engine::NewAnnot { page: 100, ..note() };
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.annotate("adding a note", vec![late], cx)));
|
||||
settle(cx, |app| view.read(app).edited == 1 && repainted(view.read(app)));
|
||||
assert!(!bare.get(), "page 101 never goes blank");
|
||||
assert_eq!(cx.update(|_, app| view.read(app).sizes[100]), (612.0, 900.0), "its measured size holds");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn old_tiles_are_painted_and_freed_with_their_tab() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[file(dir.path(), "one.pdf", &[(612.0, 792.0, &["Hello"])])], true);
|
||||
let view = shown(cx, &viewer);
|
||||
settle(cx, |app| repainted(view.read(app)));
|
||||
// Nothing new is asked; only old tiles can paint.
|
||||
let before = cx.update(|_, app| {
|
||||
view.update(app, |view, cx| {
|
||||
let keys: Vec<_> = view.tiles.keys().copied().collect();
|
||||
view.failed.extend(keys);
|
||||
view.keep_all();
|
||||
cx.notify();
|
||||
view.painted
|
||||
})
|
||||
});
|
||||
cx.run_until_parked();
|
||||
let (painted, kept) = cx.update(|_, app| (view.read(app).painted, view.read(app).backdrop.len()));
|
||||
// Old tiles cover what shows of the page.
|
||||
let shown = cx.update(|window, app| {
|
||||
let read = view.read(app);
|
||||
let room = read.room;
|
||||
read.showing(window.scale_factor(), false).iter().map(|s| {
|
||||
let (left, top) = (-f32::from(read.scroll.offset().x), -f32::from(read.scroll.offset().y));
|
||||
let w = (s.place.x + s.place.w).min(left + f32::from(room.size.width)) - s.place.x.max(left);
|
||||
let h = (s.place.y + s.place.h).min(top + f32::from(room.size.height)) - s.place.y.max(top);
|
||||
f64::from(w.max(0.0) * h.max(0.0))
|
||||
}).sum::<f64>()
|
||||
});
|
||||
assert!(kept > 0 && painted - before >= shown * 0.99, "{kept} old tiles painted {} of {shown}", painted - before);
|
||||
cx.update(|_, app| view.update(app, |view, _| view.retire_all()));
|
||||
assert!(cx.update(|_, app| view.read(app).backdrop.is_empty()), "closing hands every old tile over");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_keeps_page_pictures_until_they_repaint() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[file(dir.path(), "one.pdf", &[(612.0, 792.0, &["Hello"])])], true);
|
||||
let view = shown(cx, &viewer);
|
||||
let dark = cx.update(|_, app| ely_gpui_component::theme::ActiveTheme::theme(app).is_dark());
|
||||
settle(cx, |app| view.read(app).picture(0, dark).is_some() && repainted(view.read(app)));
|
||||
let old = cx.update(|_, app| view.read(app).picture(0, dark).expect("a picture"));
|
||||
// A picture on its way holds back the repaint.
|
||||
cx.update(|_, app| view.update(app, |view, _| view.thumbing = true));
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.annotate("adding a note", vec![note()], cx)));
|
||||
settle(cx, |app| view.read(app).edited == 1 && repainted(view.read(app)));
|
||||
// Dropped from the atlas, it returns only if drawn.
|
||||
cx.update(|window, _| window.drop_image(old.clone())).expect("drops");
|
||||
super::frames(cx);
|
||||
assert!(cx.update(|window, _| window.has_image_atlas_entry(&old)), "the old picture shows meanwhile");
|
||||
cx.update(|_, app| view.update(app, |view, cx| {
|
||||
view.thumbing = false;
|
||||
cx.notify()
|
||||
}));
|
||||
settle(cx, |app| view.read(app).thumbs_stale.is_empty());
|
||||
let new = cx.update(|_, app| view.read(app).picture(0, dark).expect("a picture"));
|
||||
assert!(!std::sync::Arc::ptr_eq(&new, &old), "the new picture replaces it");
|
||||
super::frames(cx);
|
||||
assert!(cx.update(|window, _| window.has_image_atlas_entry(&new)), "and is drawn");
|
||||
}
|
||||
@@ -315,3 +315,48 @@ fn a_default_name_avoids_a_field_with_no_widget() {
|
||||
send(cx, &viewer, Change::Design(typed, Vec::new()));
|
||||
assert_eq!(notes(cx, &view).fields.len(), 1, "the field lands");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quick_strokes_queue_behind_each_other() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = dir.path().join("one.pdf");
|
||||
let page: (f32, f32, &[&str]) = (612.0, 792.0, &["Hello"]);
|
||||
std::fs::write(&path, pdf_with(&[page], &[], &Extras::default())).expect("writes");
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
let note = |y: f32| ely_pdf_engine::NewAnnot { page: 0, shape: ely_pdf_engine::Shape::Note((100.0, y)), rgb: None, contents: "n".into(), author: String::new() };
|
||||
// The second lands while the first still runs.
|
||||
cx.update(|_, app| view.update(app, |view, cx| {
|
||||
view.annotate("a first note", vec![note(500.0)], cx);
|
||||
view.annotate("a second note", vec![note(400.0)], cx);
|
||||
}));
|
||||
settle(cx, |app| view.read(app).settled());
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| viewer.side.update(cx, |side, cx| {
|
||||
side.pane = crate::side::Pane::Notes;
|
||||
cx.notify();
|
||||
})));
|
||||
let count = |cx: &mut gpui::VisualTestContext| {
|
||||
settle(cx, |app| view.read(app).settled() && view.read(app).notes.contains_key(&0));
|
||||
cx.update(|_, app| view.read(app).notes[&0].annots.len())
|
||||
};
|
||||
assert_eq!(count(cx), 2, "both notes landed");
|
||||
let rotate = |view: &mut PdfView, cx: &mut gpui::Context<PdfView>| {
|
||||
view.edit_pages("rotating", |worker, doc| worker.rotate_pages(doc, &[0], 90), cx)
|
||||
};
|
||||
// A running rotation would move the point: refused.
|
||||
cx.update(|_, app| view.update(app, |view, cx| {
|
||||
rotate(view, cx);
|
||||
view.annotate("a note while turning", vec![note(300.0)], cx);
|
||||
}));
|
||||
assert_eq!(count(cx), 2, "refused while pages move");
|
||||
// A rotation waiting behind another edit: refused too.
|
||||
cx.update(|_, app| view.update(app, |view, cx| {
|
||||
view.annotate("a third note", vec![note(250.0)], cx);
|
||||
rotate(view, cx);
|
||||
view.annotate("a note behind a turn", vec![note(200.0)], cx);
|
||||
}));
|
||||
assert_eq!(count(cx), 3, "only the note before the turn");
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.annotate("a settled note", vec![note(150.0)], cx)));
|
||||
assert_eq!(count(cx), 4, "taken once pages are still");
|
||||
}
|
||||
@@ -33,6 +33,39 @@ fn pages_export_as_images_and_text() {
|
||||
assert!(text.contains("First") && text.contains("Second"), "{text}");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn a_write_the_system_refuses_reports_it_without_a_crash() {
|
||||
use std::os::unix::fs::PermissionsExt as _;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = file(dir.path(), "doc.pdf", &[(612.0, 792.0, &["First"])]);
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
shown(cx, &viewer);
|
||||
let locked = dir.path().join("locked");
|
||||
std::fs::create_dir(&locked).expect("a folder");
|
||||
std::fs::set_permissions(&locked, std::fs::Permissions::from_mode(0o500)).expect("read-only");
|
||||
let id = cx.update(|_, app| viewer.read(app).core.tabs[0].id);
|
||||
let txt = locked.join("doc.txt");
|
||||
let how = Optimizing { compress: true, from: 300, to: 0 };
|
||||
// The window's toasts live on its root.
|
||||
let root = cx.update(|window, app| {
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Pdf, viewer.clone().into(), &ely_ui::commands::FILE, Vec::new(), window, app);
|
||||
viewer.update(app, |viewer, _| viewer.core.root = root.downgrade());
|
||||
root
|
||||
});
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| viewer.write_export(id, Kind::Text, how, txt.clone(), cx)));
|
||||
let failed = |app: &gpui::App| {
|
||||
let toasts = root.read(app).toasts(app);
|
||||
toasts.iter().any(|(text, severity)| {
|
||||
*severity == Some(ely_gpui_component::primitives::Severity::Danger) && text.contains("Permission denied")
|
||||
})
|
||||
};
|
||||
settle(cx, failed);
|
||||
std::fs::set_permissions(&locked, std::fs::Permissions::from_mode(0o700)).expect("writable again");
|
||||
assert!(!txt.exists(), "nothing is written");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_damaged_file_opens_repaired_and_saves_as_a_new_file() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
@@ -162,3 +195,27 @@ fn a_picture_never_drawn_is_checked_before_an_overwrite() {
|
||||
settle(cx, |app| viewer.read(app).active_tab().and_then(|tab| tab.risk) == Some(ely_office::Risk::Repaired));
|
||||
assert_eq!(std::fs::read(&path).expect("reads"), bytes, "Save turned into Save As");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edited_document_does_not_quote_the_files_size() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = file(dir.path(), "doc.pdf", &[(612.0, 792.0, &["First"])]);
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
// The window's toasts live on its root.
|
||||
let root = cx.update(|window, app| {
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Pdf, viewer.clone().into(), &ely_ui::commands::FILE, Vec::new(), window, app);
|
||||
viewer.update(app, |viewer, _| viewer.core.root = root.downgrade());
|
||||
root
|
||||
});
|
||||
let note = ely_pdf_engine::NewAnnot { page: 0, shape: ely_pdf_engine::Shape::Note((100.0, 500.0)), rgb: None, contents: "n".into(), author: String::new() };
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.annotate("a note", vec![note], cx)));
|
||||
settle(cx, |app| view.read(app).settled() && view.read(app).modified());
|
||||
let id = cx.update(|_, app| viewer.read(app).core.tabs[0].id);
|
||||
let out = dir.path().join("small.pdf");
|
||||
let how = Optimizing { compress: true, from: 300, to: 150 };
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| viewer.write_export(id, Kind::Optimized, how, out.clone(), cx)));
|
||||
let done = cx.update(|_, app| crate::viewer::Viewer::text(app, "pdf.export.done", &[("name", "small.pdf")]));
|
||||
settle(cx, |app| root.read(app).toasts(app).iter().any(|(text, _)| *text == done));
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
//! Reads that fail are kept, not asked each frame (P-08).
|
||||
|
||||
use ely_pdf_engine::sample::{Extras, pdf_with};
|
||||
use gpui::TestAppContext;
|
||||
|
||||
use super::{settle, shown, windowed};
|
||||
|
||||
/// Two pages; the first's square has an unreadable rectangle.
|
||||
fn bad_then_good() -> Vec<u8> {
|
||||
let nines = "9".repeat(50);
|
||||
let objects = [
|
||||
"<< /Type /Catalog /Pages 2 0 R >>".to_string(),
|
||||
"<< /Type /Pages /Kids [3 0 R 4 0 R] /Count 2 >>".to_string(),
|
||||
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Annots [5 0 R] >>".to_string(),
|
||||
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Annots [6 0 R] >>".to_string(),
|
||||
format!("<< /Type /Annot /Subtype /Square /Rect [0 0 {nines} 100] >>"),
|
||||
"<< /Type /Annot /Subtype /Text /Rect [100 500 120 520] /Contents (fine) >>".to_string(),
|
||||
];
|
||||
let mut pdf = b"%PDF-1.7\n".to_vec();
|
||||
let mut offsets = Vec::new();
|
||||
for (i, body) in objects.iter().enumerate() {
|
||||
offsets.push(pdf.len());
|
||||
pdf.extend(format!("{} 0 obj\n{body}\nendobj\n", i + 1).bytes());
|
||||
}
|
||||
let xref = pdf.len();
|
||||
pdf.extend(format!("xref\n0 {}\n0000000000 65535 f \n", objects.len() + 1).bytes());
|
||||
for offset in offsets {
|
||||
pdf.extend(format!("{offset:010} 00000 n \n").bytes());
|
||||
}
|
||||
pdf.extend(format!("trailer\n<< /Size {} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n", objects.len() + 1).bytes());
|
||||
pdf
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_bad_page_spares_the_rest_of_its_batch() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = dir.path().join("two.pdf");
|
||||
std::fs::write(&path, bad_then_good()).expect("writes");
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
settle(cx, |app| !view.read(app).reading_notes);
|
||||
cx.update(|_, app| view.update(app, |view, cx| {
|
||||
view.notes.clear();
|
||||
view.unread.clear();
|
||||
view.ask_notes([0, 1], cx)
|
||||
}));
|
||||
settle(cx, |app| !view.read(app).reading_notes);
|
||||
let (good, bad) = cx.update(|_, app| {
|
||||
let view = view.read(app);
|
||||
(view.notes.contains_key(&1), view.unread.contains(&crate::view::Unread::Notes(0)))
|
||||
});
|
||||
assert!(bad, "the bad page is kept as failed");
|
||||
assert!(good, "the good page is read all the same");
|
||||
assert!(!cx.update(|_, app| view.read(app).unread.contains(&crate::view::Unread::Notes(1))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_signature_read_from_before_a_save_counts_for_nothing() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = dir.path().join("one.pdf");
|
||||
let page: (f32, f32, &[&str]) = (612.0, 792.0, &["Hello"]);
|
||||
std::fs::write(&path, pdf_with(&[page], &[], &Extras::default())).expect("writes");
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
let gone = dir.path().join("gone.pdf");
|
||||
// The read fails, but a save lands before its answer.
|
||||
cx.update(|_, app| view.update(app, |view, cx| {
|
||||
view.ask_signatures(gone.clone(), cx);
|
||||
let same = view.saved.clone();
|
||||
view.saved(&same, cx);
|
||||
}));
|
||||
settle(cx, |app| !view.read(app).reading_signatures);
|
||||
assert!(cx.update(|_, app| view.read(app).unread.is_empty()), "a stale failure blocks nothing");
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.ask_signatures(gone.clone(), cx)));
|
||||
assert!(cx.update(|_, app| view.read(app).reading_signatures), "asked again after the save");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_read_is_not_asked_again() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = dir.path().join("one.pdf");
|
||||
let page: (f32, f32, &[&str]) = (612.0, 792.0, &["Hello"]);
|
||||
std::fs::write(&path, pdf_with(&[page], &[], &Extras::default())).expect("writes");
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
assert!(cx.update(|_, app| view.read(app).form_names.is_none()), "not read yet");
|
||||
// A dead worker fails every read.
|
||||
let pid = cx.update(|_, app| viewer.read(app).core.worker.lock().expect("the lock").get().expect("a worker").pid());
|
||||
std::process::Command::new("kill").args(["-9", &pid.to_string()]).status().expect("kills");
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.ask_names(cx)));
|
||||
settle(cx, |app| !view.read(app).reading_names);
|
||||
assert!(cx.update(|_, app| view.read(app).unread.contains(&crate::view::Unread::Names)), "the failure is kept");
|
||||
cx.update(|_, app| view.update(app, |view, cx| view.ask_names(cx)));
|
||||
assert!(!cx.update(|_, app| view.read(app).reading_names), "not asked again");
|
||||
}
|
||||
@@ -234,3 +234,33 @@ fn a_cancelled_run_cannot_touch_the_next() {
|
||||
assert!(cx.update(|_, app| viewer.read(app).ocr.is_some()), "the second run goes on");
|
||||
settle(cx, |app| viewer.read(app).ocr.is_none() && view.read(app).edited == 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_text_layer_reports_no_success() {
|
||||
use ely_gpui_component::primitives::Severity;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = scanned(dir.path());
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
// The window's toasts live on its root.
|
||||
let root = cx.update(|window, app| {
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Pdf, viewer.clone().into(), &ely_ui::commands::FILE, Vec::new(), window, app);
|
||||
viewer.update(app, |viewer, _| viewer.core.root = root.downgrade());
|
||||
root
|
||||
});
|
||||
let tab = cx.update(|_, app| viewer.read(app).core.tabs[0].id);
|
||||
let run = cx.update(|window, app| viewer.update(app, |viewer, cx| {
|
||||
viewer.ask_ocr(window, cx);
|
||||
viewer.start_ocr(cx);
|
||||
viewer.ocr_runs - 1
|
||||
}));
|
||||
// An edit still runs when the text is laid.
|
||||
cx.update(|_, app| view.update(app, |view, _| view.editing = true));
|
||||
let line = ely_pdf_engine::OcrLine { rect: [72.0, 700.0, 300.0, 720.0], text: "Hello".into() };
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| viewer.ocr_read((tab, run, 0), Ok(Some(vec![line])), cx)));
|
||||
settle(cx, |app| viewer.read(app).ocr.is_none());
|
||||
let toasts = cx.update(|_, app| root.read(app).toasts(app));
|
||||
assert!(toasts.iter().any(|(_, severity)| *severity == Some(Severity::Warning)), "{toasts:?}");
|
||||
assert!(!toasts.iter().any(|(_, severity)| *severity == Some(Severity::Success)), "{toasts:?}");
|
||||
}
|
||||
@@ -23,6 +23,17 @@ pub struct Failed(pub String);
|
||||
/// The document changed what it shows.
|
||||
pub struct Reported;
|
||||
|
||||
/// A page or document read that failed once.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Unread {
|
||||
Notes(usize),
|
||||
Layer(usize),
|
||||
Names,
|
||||
Files,
|
||||
/// The signatures of the file at this path.
|
||||
Signatures(std::path::PathBuf),
|
||||
}
|
||||
|
||||
pub struct PdfView {
|
||||
worker: Arc<Mutex<Mupdf>>,
|
||||
pub doc: Doc,
|
||||
@@ -37,10 +48,14 @@ pub struct PdfView {
|
||||
pub tiles: HashMap<TileKey, Arc<RenderImage>>,
|
||||
/// Images no longer drawn, freed at the next render.
|
||||
pub retired: ely_gpui_component::primitives::Retired,
|
||||
/// A tile reached the screen; logged once (PERF-05).
|
||||
pub drawn: bool,
|
||||
/// Tile pixels painted; the first paint is logged (PERF-05).
|
||||
pub painted: f64,
|
||||
/// Tiles the worker could not draw; not asked again.
|
||||
pub failed: HashSet<TileKey>,
|
||||
/// Reads that failed; not asked again until an edit.
|
||||
pub unread: HashSet<Unread>,
|
||||
/// Old tiles shown under their page until covered.
|
||||
pub backdrop: Vec<crate::backdrop::Old>,
|
||||
pub text: HashMap<usize, Arc<Vec<Char>>>,
|
||||
pub asking_text: HashSet<usize>,
|
||||
pub marks: Vec<Bookmark>,
|
||||
@@ -63,12 +78,18 @@ pub struct PdfView {
|
||||
/// Edits waiting their turn, and whether one runs.
|
||||
pub queue: VecDeque<crate::edits::Queued>,
|
||||
pub editing: bool,
|
||||
/// The running edit may move pages.
|
||||
pub moving: bool,
|
||||
/// History marks: now, and at the last load or save.
|
||||
pub mark: String,
|
||||
pub saved: String,
|
||||
/// Saves so far: a read from before one is stale.
|
||||
pub saves: u64,
|
||||
/// Page pictures for the side panel, by page and darkness.
|
||||
pub thumbs: HashMap<(usize, bool), Arc<RenderImage>>,
|
||||
pub thumbs_failed: HashSet<usize>,
|
||||
/// Pictures from before an edit; shown until repainted.
|
||||
pub thumbs_stale: HashSet<(usize, bool)>,
|
||||
/// A picture is on its way from the worker.
|
||||
pub thumbing: bool,
|
||||
/// Pages picked in the side panel, and the anchor.
|
||||
@@ -143,7 +164,8 @@ impl PdfView {
|
||||
pub fn retire_all(&mut self) -> ely_gpui_component::primitives::Retired {
|
||||
let mut images = std::mem::take(&mut self.retired);
|
||||
let tiles = self.tiles.drain().map(|(_, image)| image);
|
||||
for image in tiles.chain(self.thumbs.drain().map(|(_, image)| image)) {
|
||||
let old = self.backdrop.drain(..).map(|old| old.image);
|
||||
for image in tiles.chain(old).chain(self.thumbs.drain().map(|(_, image)| image)) {
|
||||
images.push(image);
|
||||
}
|
||||
images
|
||||
@@ -164,8 +186,10 @@ impl PdfView {
|
||||
scroll: ScrollHandle::new(),
|
||||
tiles: HashMap::new(),
|
||||
retired: Default::default(),
|
||||
drawn: false,
|
||||
painted: 0.0,
|
||||
failed: HashSet::new(),
|
||||
unread: HashSet::new(),
|
||||
backdrop: Vec::new(),
|
||||
text: HashMap::new(),
|
||||
asking_text: HashSet::new(),
|
||||
marks: loaded.marks,
|
||||
@@ -180,10 +204,13 @@ impl PdfView {
|
||||
edited: 0,
|
||||
queue: VecDeque::new(),
|
||||
editing: false,
|
||||
moving: false,
|
||||
saved: loaded.mark.clone(),
|
||||
saves: 0,
|
||||
mark: loaded.mark,
|
||||
thumbs: HashMap::new(),
|
||||
thumbs_failed: HashSet::new(),
|
||||
thumbs_stale: HashSet::new(),
|
||||
thumbing: false,
|
||||
picked: BTreeSet::new(),
|
||||
anchor: None,
|
||||
@@ -223,10 +250,10 @@ impl PdfView {
|
||||
pub fn fail(&self, what: &str, error: &io::Error, cx: &mut Context<Self>) {
|
||||
// Engine text may quote the document: the user sees it.
|
||||
log::error!("pdf: {what} failed ({:?})", error.kind());
|
||||
let text = match error.kind() {
|
||||
let text = match ely_pdf_engine::refused(error) {
|
||||
_ if ely_pdf_engine::is_stale(error) => ely_ui::i18n::text(cx, "pdf.object.changed", &[]),
|
||||
io::ErrorKind::PermissionDenied => restricted(&error.to_string(), cx),
|
||||
_ => ely_ui::i18n::text(cx, "pdf.failed", &[("what", what), ("error", &error.to_string())]),
|
||||
Some(needed) => restricted(needed, cx),
|
||||
None => ely_ui::i18n::text(cx, "pdf.failed", &[("what", what), ("error", &error.to_string())]),
|
||||
};
|
||||
cx.emit(Failed(text.to_string()));
|
||||
}
|
||||
@@ -311,6 +338,9 @@ impl PdfView {
|
||||
|
||||
/// Every page tile goes; images are freed next render.
|
||||
pub fn retire_tiles(&mut self) {
|
||||
for old in self.backdrop.drain(..) {
|
||||
self.retired.push(old.image);
|
||||
}
|
||||
for (_, image) in self.tiles.drain() {
|
||||
self.retired.push(image);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ pub fn open(app: AppId, window: &mut Window, cx: &mut App) -> Entity<Root> {
|
||||
let root = ely_ui::document_root(app, viewer.clone().into(), &commands::FILE, crate::keys::menus(cx), window, cx);
|
||||
viewer.update(cx, |viewer, cx| {
|
||||
viewer.core.root = root.downgrade();
|
||||
viewer.core.window = Some(window.window_handle());
|
||||
viewer.own_window(window, cx);
|
||||
window.focus(&viewer.core.focus, cx);
|
||||
});
|
||||
for path in ely_ui::launch_files(cx) {
|
||||
@@ -247,7 +247,6 @@ impl Render for Viewer {
|
||||
.on_action(cx.listener(Self::on_save_as))
|
||||
.on_action(cx.listener(Self::on_export))
|
||||
.on_action(cx.listener(Self::on_print))
|
||||
.on_action(cx.listener(Self::on_quit))
|
||||
.on_action(cx.listener(Self::on_close_tab))
|
||||
.child(shell)
|
||||
.children(self.core_dialog(cx))
|
||||
|
||||
@@ -92,15 +92,17 @@ impl PdfView {
|
||||
rgb: 0,
|
||||
bx: [at[0], at[1], self.sizes[page].0 - at[0]],
|
||||
};
|
||||
self.settled_edit("placing a typed signature", cx, move |worker, doc| match worker.put_text(doc, page, &writing, 0.0)? {
|
||||
let write = move |worker: &mut ely_pdf_engine::Worker, doc| match worker.put_text(doc, page, &writing, 0.0)? {
|
||||
Wrote::Done(mark) => Ok(mark),
|
||||
Wrote::Missing(c) => Err(io::Error::new(io::ErrorKind::InvalidInput, format!("the font has no “{c}”"))),
|
||||
Wrote::Unwritable => Err(io::Error::other("the document's font cannot write")),
|
||||
Wrote::Preview(..) => Err(io::Error::other("a preview where a write was asked")),
|
||||
});
|
||||
};
|
||||
self.edit_at("placing a typed signature", write, cx);
|
||||
}
|
||||
Stamp::Picture { path, aspect } => {
|
||||
let at = placed(aspect, rect, click);
|
||||
self.settled_edit("placing a signature picture", cx, move |worker, doc| worker.add_image(doc, page, &path, at));
|
||||
self.edit_at("placing a signature picture", move |worker, doc| worker.add_image(doc, page, &path, at), cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,8 @@ impl Viewer {
|
||||
let (asked, viewer) = (writing.clone(), cx.weak_entity());
|
||||
view.update(cx, |view, cx| {
|
||||
let doc = view.doc;
|
||||
view.read(
|
||||
// A stale answer still reaches `previewed`, which says so.
|
||||
view.off(
|
||||
move |worker| worker.put_text(doc, page, &asked, PREVIEW),
|
||||
move |_, answer, cx| {
|
||||
// The viewer edits this view; wait until it is free.
|
||||
@@ -95,7 +96,19 @@ impl Viewer {
|
||||
replacing: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let same = self.tab(tab).is_some_and(|open| open.view.read(cx).version == version);
|
||||
if !same {
|
||||
let text = Self::text(cx, "pdf.object.changed", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
}
|
||||
match answer {
|
||||
Ok(Wrote::Unwritable) => {
|
||||
let note = Self::text(cx, "pdf.text.unwritable", &[]);
|
||||
self.edit_panel.update(cx, |panel, cx| {
|
||||
panel.note = Some(note);
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
Ok(Wrote::Missing(c)) => {
|
||||
let note = Self::text(cx, "pdf.text.missing", &[("char", &c.to_string())]);
|
||||
self.edit_panel.update(cx, |panel, cx| {
|
||||
@@ -128,6 +141,7 @@ impl Viewer {
|
||||
move |worker, doc| match worker.put_text(doc, page, &writing, 0.0)? {
|
||||
Wrote::Done(mark) => Ok(mark),
|
||||
Wrote::Missing(c) => Err(io::Error::other(format!("the font has no {c}"))),
|
||||
Wrote::Unwritable => Err(io::Error::other("the document's font cannot write")),
|
||||
Wrote::Preview(..) => Err(io::Error::other("a write came back as a preview")),
|
||||
},
|
||||
cx,
|
||||
@@ -168,25 +182,27 @@ impl Viewer {
|
||||
self.pick(false, cx, move |viewer, path: PathBuf, cx| {
|
||||
viewer.on_same(&view, version, cx, |view, cx| {
|
||||
view.edit("replacing an image", move |worker, doc| worker.replace_image(doc, page, index, &path), cx)
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Runs `step` on `view` if no edit came since `version`.
|
||||
/// Whether `step` ran: no edit came since `version`.
|
||||
pub(crate) fn on_same(
|
||||
&self,
|
||||
view: &gpui::Entity<crate::view::PdfView>,
|
||||
version: u64,
|
||||
cx: &mut Context<Self>,
|
||||
step: impl FnOnce(&mut crate::view::PdfView, &mut Context<crate::view::PdfView>),
|
||||
) {
|
||||
) -> bool {
|
||||
// Landed or queued, an edit since may move the target.
|
||||
let open = self.core.tabs.iter().any(|tab| tab.view == *view);
|
||||
if !open || view.read(cx).version != version || !view.read(cx).settled() {
|
||||
let text = Self::text(cx, "pdf.object.changed", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
self.toast(text, Severity::Warning, cx);
|
||||
return false;
|
||||
}
|
||||
view.update(cx, step);
|
||||
true
|
||||
}
|
||||
|
||||
/// Asks for a picture; it lands mid-page.
|
||||
|
||||
@@ -186,8 +186,8 @@ impl Deck {
|
||||
return log::info!("show: a chart dialog for tab {tab} came late");
|
||||
}
|
||||
let editing = Editing::new(tab, chart, window, cx);
|
||||
deck.dialog = Some(Dialog::Chart(Box::new(editing)));
|
||||
cx.notify();
|
||||
// Refused while another dialog is open; it says so.
|
||||
let _ = deck.open_dialog(Dialog::Chart(Box::new(editing)), cx);
|
||||
})
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
|
||||
+20
-10
@@ -108,6 +108,21 @@ pub fn findings(check: &Check, slides: &[ShowSlide], missing_fonts: &[String]) -
|
||||
}
|
||||
|
||||
impl Deck {
|
||||
/// Shows a finding's slide; master view numbers masters instead.
|
||||
pub(crate) fn go_to_finding(&mut self, part: usize, cx: &mut Context<Self>) {
|
||||
let Some(tab) = self.active_tab() else {
|
||||
return;
|
||||
};
|
||||
if tab.extra.masters {
|
||||
let text = Deck::text(cx, "show.masters.busy", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
}
|
||||
let view = tab.view.clone();
|
||||
view.update(cx, |view, _| view.show_part(part));
|
||||
self.dialog = None;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Reads every slide and master, then lists what to fix.
|
||||
pub fn check_show(&mut self, cx: &mut Context<Self>) {
|
||||
let Some(tab) = self.active_tab() else {
|
||||
@@ -128,8 +143,8 @@ impl Deck {
|
||||
Ok((check, slides)) if deck.dialog_due(asked, id) => {
|
||||
let found = findings(&check, &slides, &missing);
|
||||
log::info!("show: the check found {} things", found.len());
|
||||
deck.dialog = Some(Dialog::Check(found));
|
||||
cx.notify();
|
||||
// Refused while another dialog is open; it says so.
|
||||
let _ = deck.open_dialog(Dialog::Check(found), cx);
|
||||
}
|
||||
Ok(_) => log::info!("show: the check is no longer due"),
|
||||
Err(error) => deck.engine_failed(&format!("the check: {error}"), cx),
|
||||
@@ -183,14 +198,9 @@ impl Deck {
|
||||
let firsts: Vec<Option<usize>> = found.iter().map(|f| f.slides.first().copied()).collect();
|
||||
let list = list.on_change(move |keys, _, cx| {
|
||||
let first = keys.first().and_then(|key| key.parse::<usize>().ok()).and_then(|at| firsts[at]);
|
||||
this.update(cx, |deck, cx| {
|
||||
if let (Some(part), Some(tab)) = (first, deck.active_tab()) {
|
||||
let view = tab.view.clone();
|
||||
view.update(cx, |view, _| view.show_part(part));
|
||||
deck.dialog = None;
|
||||
}
|
||||
cx.notify();
|
||||
})
|
||||
if let Some(part) = first {
|
||||
this.update(cx, |deck, cx| deck.go_to_finding(part, cx));
|
||||
}
|
||||
});
|
||||
card.child(list).into_any_element()
|
||||
}
|
||||
|
||||
+15
-63
@@ -1,16 +1,15 @@
|
||||
//! ElyShow's window: decks over one LOK worker (§10.1).
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
collections::HashSet,
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use ely_gpui_component::{feedback::EmptyState, primitives::IconName, shell::StatusBar};
|
||||
use ely_lok::{
|
||||
LokView, Sheets, Worker,
|
||||
history::Step,
|
||||
show::{Design, Objects},
|
||||
LokView, Worker,
|
||||
show::Design,
|
||||
};
|
||||
use ely_office::{Core, Kind, prelude::*};
|
||||
use ely_platform::AppId;
|
||||
@@ -18,61 +17,13 @@ use ely_ui::{Root, Shell, commands};
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, RenderImage, SharedString, Styled as _, Window, div,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
||||
};
|
||||
|
||||
use crate::design::Panel;
|
||||
use crate::slides::Strip;
|
||||
|
||||
/// Parts, edits, caret and selected frame.
|
||||
pub type Seen = (u64, u64, bool, Option<ely_lok::Rect>);
|
||||
|
||||
/// What ElyShow keeps per deck.
|
||||
#[derive(Default)]
|
||||
pub struct Extra {
|
||||
pub slides: Sheets,
|
||||
/// The document as the last read saw it.
|
||||
pub read_at: Option<ely_lok::Doc>,
|
||||
/// What the view showed at the last read.
|
||||
pub read: Option<Seen>,
|
||||
pub reading: bool,
|
||||
pub design: Option<Design>,
|
||||
pub objects: Option<Objects>,
|
||||
pub notes: Option<ely_lok::show::Notes>,
|
||||
pub remarks: Vec<ely_lok::show::Remark>,
|
||||
/// The shown slide's transition and effects; none on a master.
|
||||
pub motion: Option<(ely_lok::show::Transition, Vec<ely_lok::show::Effect>)>,
|
||||
pub media: Vec<ely_lok::show::Media>,
|
||||
/// Counts completed reads.
|
||||
pub reads: u64,
|
||||
/// The slide size in twips.
|
||||
pub size: (i64, i64),
|
||||
/// Undo and redo lists at the last read.
|
||||
pub history: Option<(Vec<Step>, Vec<Step>)>,
|
||||
/// A size sent, in 1/100 mm, until read back.
|
||||
pub size_asked: Option<(i64, i64)>,
|
||||
/// A transition sent for a slide, until read back.
|
||||
pub transition_asked: Option<(String, ely_lok::show::Transition, u64)>,
|
||||
/// Pictures by slide name; stale ones show until repainted.
|
||||
pub thumbs: HashMap<String, Arc<RenderImage>>,
|
||||
pub retired: ely_gpui_component::primitives::Retired,
|
||||
pub stale: HashSet<String>,
|
||||
/// Pictures that failed; retried after the next read.
|
||||
pub failed: HashSet<String>,
|
||||
pub painting: bool,
|
||||
/// The parts are masters.
|
||||
pub masters: bool,
|
||||
/// The scheme the pictures were painted with.
|
||||
pub dark: Option<bool>,
|
||||
}
|
||||
|
||||
impl Extra {
|
||||
/// The size to show, in 1/100 mm: asked, else read.
|
||||
pub fn shown_size(&self) -> (i64, i64) {
|
||||
self.size_asked
|
||||
.unwrap_or_else(|| crate::design::mm100(self.size))
|
||||
}
|
||||
}
|
||||
pub use crate::extra::Extra;
|
||||
|
||||
pub struct Deck {
|
||||
pub core: Core<Deck>,
|
||||
@@ -137,7 +88,13 @@ impl Host for Deck {
|
||||
}
|
||||
|
||||
fn observed(&mut self, id: u64, view: &Entity<LokView>, cx: &mut Context<Self>) {
|
||||
view.update(cx, |view, cx| view.fit_page(cx));
|
||||
// A new deck fits once; a zoom then stays.
|
||||
if let Some(tab) = self.tab_mut(id)
|
||||
&& !tab.extra.fitted
|
||||
{
|
||||
tab.extra.fitted = true;
|
||||
view.update(cx, |view, cx| view.fit_page(cx));
|
||||
}
|
||||
// Pictures follow the kernel's light or dark scheme.
|
||||
let dark = view.read(cx).dark();
|
||||
if let Some(tab) = self.tab_mut(id)
|
||||
@@ -176,7 +133,7 @@ pub fn open(app: AppId, window: &mut Window, cx: &mut App) -> Entity<Root> {
|
||||
let root = ely_ui::document_root(app, deck.clone().into(), &ely_ui::commands::FILE, menus, window, cx);
|
||||
deck.update(cx, |deck, cx| {
|
||||
deck.core.root = root.downgrade();
|
||||
deck.core.window = Some(window.window_handle());
|
||||
deck.own_window(window, cx);
|
||||
window.focus(&deck.core.focus, cx);
|
||||
});
|
||||
let launched = ely_ui::launch_files(cx);
|
||||
@@ -263,6 +220,7 @@ impl Deck {
|
||||
}
|
||||
(tab.extra.reading, tab.extra.read) = (true, Some(seen));
|
||||
let landed = tab.extra.transition_landed(view.read(cx));
|
||||
let sized = tab.extra.size_landed(view.read(cx));
|
||||
let doc = tab.doc.clone();
|
||||
ely_lok::read_off(
|
||||
&self.core.worker,
|
||||
@@ -339,12 +297,6 @@ impl Deck {
|
||||
{
|
||||
tab.extra.stale = tab.extra.thumbs.keys().cloned().collect();
|
||||
}
|
||||
let read = crate::design::mm100(size);
|
||||
if tab.extra.size_asked.is_some_and(|(w, h)| {
|
||||
(w - read.0).abs() <= 50 && (h - read.1).abs() <= 50
|
||||
}) {
|
||||
tab.extra.size_asked = None;
|
||||
}
|
||||
(tab.extra.slides, tab.extra.design) = (slides, Some(design));
|
||||
tab.extra.objects = Some(objects);
|
||||
(tab.extra.notes, tab.extra.remarks) = (Some(notes), remarks);
|
||||
@@ -352,6 +304,7 @@ impl Deck {
|
||||
tab.extra.settle_transition(landed);
|
||||
tab.extra.reads += 1;
|
||||
tab.extra.size = size;
|
||||
tab.extra.settle_size(sized);
|
||||
tab.extra.failed.clear();
|
||||
deck.paint_next(id, cx);
|
||||
deck.read_fonts(id, cx);
|
||||
@@ -491,7 +444,6 @@ impl Render for Deck {
|
||||
.on_action(cx.listener(Self::on_save_as))
|
||||
.on_action(cx.listener(Self::on_export))
|
||||
.on_action(cx.listener(Self::on_print))
|
||||
.on_action(cx.listener(Self::on_quit))
|
||||
.on_action(cx.listener(Self::on_close_tab))
|
||||
.child(shell)
|
||||
.children(self.core_dialog(cx))
|
||||
|
||||
@@ -59,9 +59,18 @@ impl Deck {
|
||||
log::info!("show: the slides already measure {w} x {h}");
|
||||
return;
|
||||
}
|
||||
tab.extra.size_asked = Some((w, h));
|
||||
let (w, h) = (w.to_string(), h.to_string());
|
||||
self.design_command("slide.size", &[&w, &h, "true"], cx);
|
||||
let (id, view) = (tab.id, tab.view.clone());
|
||||
let before = view.read(cx).sent();
|
||||
tab.extra.size_asked = Some(((w, h), before + 1));
|
||||
let (sw, sh) = (w.to_string(), h.to_string());
|
||||
self.run_in(Some(id), "slide.size", &[&sw, &sh, "true"], cx);
|
||||
// Refused before sending: run_in said so already.
|
||||
if view.read(cx).sent() == before
|
||||
&& let Some(tab) = self.tab_mut(id)
|
||||
{
|
||||
tab.extra.size_asked = None;
|
||||
}
|
||||
self.force_reread(id, cx);
|
||||
}
|
||||
|
||||
/// Enters or leaves the master view.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! ElyShow's one open dialog.
|
||||
|
||||
use ely_gpui_component::forms::TextInput;
|
||||
use ely_gpui_component::{forms::TextInput, primitives::Severity};
|
||||
use ely_office::prelude::*;
|
||||
use gpui::{App, Context, Entity, IntoElement as _};
|
||||
|
||||
use crate::deck::Deck;
|
||||
@@ -41,6 +42,18 @@ pub(crate) fn edit(
|
||||
}
|
||||
|
||||
impl Deck {
|
||||
/// Opens `dialog`, or hands it back while another is open.
|
||||
pub(crate) fn open_dialog(&mut self, dialog: Dialog, cx: &mut Context<Self>) -> Result<(), Dialog> {
|
||||
if self.dialog.is_some() {
|
||||
let text = Deck::text(cx, "show.dialog.busy", &[]);
|
||||
self.toast(text, Severity::Warning, cx);
|
||||
return Err(dialog);
|
||||
}
|
||||
self.dialog = Some(dialog);
|
||||
cx.notify();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A read that will open a dialog; earlier ones lapse.
|
||||
pub fn ask_dialog(&mut self) -> u64 {
|
||||
self.dialog_asked += 1;
|
||||
@@ -56,9 +69,9 @@ impl Deck {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether read `asked` may open its dialog now.
|
||||
/// Whether read `asked` still stands; `open_dialog` checks the rest.
|
||||
pub fn dialog_due(&self, asked: u64, id: u64) -> bool {
|
||||
self.dialog_asked == asked && self.dialog.is_none() && self.core.active == Some(id)
|
||||
self.dialog_asked == asked && self.core.active == Some(id)
|
||||
}
|
||||
|
||||
/// The open dialog, drawn.
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
//! What ElyShow keeps per deck.
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use ely_lok::{
|
||||
Sheets,
|
||||
history::Step,
|
||||
show::{Design, Objects},
|
||||
};
|
||||
use gpui::RenderImage;
|
||||
|
||||
/// Parts, edits, caret and selected frame.
|
||||
pub type Seen = (u64, u64, bool, Option<ely_lok::Rect>);
|
||||
|
||||
/// What ElyShow keeps per deck.
|
||||
#[derive(Default)]
|
||||
pub struct Extra {
|
||||
pub slides: Sheets,
|
||||
/// The document as the last read saw it.
|
||||
pub read_at: Option<ely_lok::Doc>,
|
||||
/// What the view showed at the last read.
|
||||
pub read: Option<Seen>,
|
||||
pub reading: bool,
|
||||
pub design: Option<Design>,
|
||||
pub objects: Option<Objects>,
|
||||
pub notes: Option<ely_lok::show::Notes>,
|
||||
pub remarks: Vec<ely_lok::show::Remark>,
|
||||
/// The shown slide's transition and effects; none on a master.
|
||||
pub motion: Option<(ely_lok::show::Transition, Vec<ely_lok::show::Effect>)>,
|
||||
pub media: Vec<ely_lok::show::Media>,
|
||||
/// Counts completed reads.
|
||||
pub reads: u64,
|
||||
/// The slide size in twips.
|
||||
pub size: (i64, i64),
|
||||
/// Undo and redo lists at the last read.
|
||||
pub history: Option<(Vec<Step>, Vec<Step>)>,
|
||||
/// A size sent (1/100 mm) and its input, until read.
|
||||
pub size_asked: Option<((i64, i64), u64)>,
|
||||
/// A transition sent for a slide, until read back.
|
||||
pub transition_asked: Option<(String, ely_lok::show::Transition, u64)>,
|
||||
/// Pictures by slide name; stale ones show until repainted.
|
||||
pub thumbs: HashMap<String, Arc<RenderImage>>,
|
||||
pub retired: ely_gpui_component::primitives::Retired,
|
||||
pub stale: HashSet<String>,
|
||||
/// Pictures that failed; retried after the next read.
|
||||
pub failed: HashSet<String>,
|
||||
pub painting: bool,
|
||||
/// The parts are masters.
|
||||
pub masters: bool,
|
||||
/// The scheme the pictures were painted with.
|
||||
pub dark: Option<bool>,
|
||||
/// The view was fitted to the slide once.
|
||||
pub fitted: bool,
|
||||
}
|
||||
|
||||
impl Extra {
|
||||
/// The size to show, in 1/100 mm: asked, else read.
|
||||
pub fn shown_size(&self) -> (i64, i64) {
|
||||
self.size_asked
|
||||
.map_or_else(|| crate::design::mm100(self.size), |(size, _)| size)
|
||||
}
|
||||
|
||||
/// The size input that landed before this read began.
|
||||
pub fn size_landed(&self, view: &ely_lok::LokView) -> Option<u64> {
|
||||
let (_, seq) = self.size_asked?;
|
||||
view.reached(seq).then_some(seq)
|
||||
}
|
||||
|
||||
/// Forgets the asked size once read back, taken or refused.
|
||||
pub fn settle_size(&mut self, landed: Option<u64>) {
|
||||
let read = crate::design::mm100(self.size);
|
||||
if self.size_asked.is_some_and(|((w, h), seq)| {
|
||||
landed == Some(seq) || (w - read.0).abs() <= 50 && (h - read.1).abs() <= 50
|
||||
}) {
|
||||
self.size_asked = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ mod check;
|
||||
mod deck;
|
||||
mod design;
|
||||
mod dialog;
|
||||
mod extra;
|
||||
mod guides;
|
||||
mod insert;
|
||||
mod list;
|
||||
|
||||
@@ -34,8 +34,8 @@ impl Deck {
|
||||
match ely_lok::templates("presnt") {
|
||||
Ok(templates) => {
|
||||
log::info!("show: {} bundled templates", templates.len());
|
||||
self.dialog = Some(Dialog::New(Choosing { templates }));
|
||||
cx.notify();
|
||||
// Refused while another dialog is open; it says so.
|
||||
let _ = self.open_dialog(Dialog::New(Choosing { templates }), cx);
|
||||
}
|
||||
Err(error) => self.engine_failed(&error.to_string(), cx),
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ pub struct NotesField {
|
||||
field: Option<Entity<TextInput>>,
|
||||
shown: Option<(u64, usize, String)>,
|
||||
/// The state the shown slide number was read in.
|
||||
at: Option<ely_lok::Doc>,
|
||||
pub(crate) at: Option<ely_lok::Doc>,
|
||||
_events: Option<gpui::Subscription>,
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ impl Deck {
|
||||
return log::warn!("show: notes for slide {part} have no read state");
|
||||
};
|
||||
log::info!("show: notes for slide {part} changed");
|
||||
self.notes.shown = Some((tab, part, text.clone()));
|
||||
// `shown` stays the kernel's until a read confirms the send.
|
||||
self.run_on(tab, &at, "notes.set", &[&text, &part.to_string()], cx);
|
||||
self.force_reread(tab, cx);
|
||||
}
|
||||
@@ -90,6 +90,9 @@ impl Deck {
|
||||
if !typing && self.notes.shown.as_ref() != Some(&read) {
|
||||
field.update(cx, |field, cx| field.set_text(notes.text, cx));
|
||||
self.notes.shown = Some(read);
|
||||
} else if let Some(shown) = self.notes.shown.as_mut().filter(|shown| (shown.0, shown.1) == (id, part)) {
|
||||
// A read while typing moves the base, not the draft.
|
||||
shown.2 = notes.text;
|
||||
}
|
||||
Some(field)
|
||||
}
|
||||
|
||||
@@ -148,7 +148,8 @@ impl Deck {
|
||||
|worker, doc| ely_lok::show::slide_show(&worker.values(doc, ely_lok::show::SLIDE_SHOW)?),
|
||||
move |deck, read, _, cx| match read {
|
||||
Ok(slides) if deck.dialog_due(asked, id) => {
|
||||
deck.dialog = Some(Dialog::Output(Output {
|
||||
// Refused while another dialog is open; it says so.
|
||||
let output = Output {
|
||||
tab: id,
|
||||
print,
|
||||
kind: Kind::Slides,
|
||||
@@ -156,8 +157,8 @@ impl Deck {
|
||||
per: 3,
|
||||
current,
|
||||
hidden: slides.iter().map(|slide| slide.hidden).collect(),
|
||||
}));
|
||||
cx.notify();
|
||||
};
|
||||
let _ = deck.open_dialog(Dialog::Output(output), cx);
|
||||
}
|
||||
Ok(_) => log::info!("show: the output dialog is no longer due"),
|
||||
Err(error) => deck.engine_failed(&format!("the slides: {error}"), cx),
|
||||
@@ -185,7 +186,7 @@ impl Deck {
|
||||
let path = work.join("print.pdf");
|
||||
let printing = path.clone();
|
||||
return self.write_pdf(&output, path, cx, move |_, cx| {
|
||||
ely_office::print_later(printing, cx, |deck, error, cx| deck.output_failed(&error, cx))
|
||||
ely_office::print_later(printing, cx)
|
||||
});
|
||||
}
|
||||
let Some(dir) = ely_office::folder(source) else {
|
||||
@@ -292,8 +293,8 @@ impl Deck {
|
||||
},
|
||||
move |deck, written, _, cx| match written {
|
||||
Ok(count) => {
|
||||
let count = count.to_string();
|
||||
let text = Deck::text(cx, "show.output.pictures_done", &[("n", &count), ("folder", &shown)]);
|
||||
let n = count.to_string();
|
||||
let text = ely_ui::i18n::counted(cx, "show.output.pictures_done", count as u64, &[("n", &n), ("folder", &shown)]);
|
||||
deck.toast_output(text, opened.clone(), cx);
|
||||
}
|
||||
Err(error) if error.kind() == io::ErrorKind::AlreadyExists => {
|
||||
|
||||
@@ -13,6 +13,11 @@ use super::{Kind, Output, Range};
|
||||
use crate::deck::Deck;
|
||||
use crate::dialog::Dialog;
|
||||
|
||||
/// A typed slide number on the deck; 0 means all.
|
||||
fn slide_number(value: f64, last: u32) -> u32 {
|
||||
value.round().clamp(1.0, f64::from(last.max(1))) as u32
|
||||
}
|
||||
|
||||
/// What goes out, which slides, how many a page.
|
||||
pub fn output_dialog(
|
||||
this: gpui::Entity<Deck>,
|
||||
@@ -79,7 +84,7 @@ pub fn output_dialog(
|
||||
let bound = |id: &'static str, value: u32, first: bool| {
|
||||
// A typed number counts before blur commits it.
|
||||
let set = move |this: &gpui::Entity<Deck>, value: f64, cx: &mut gpui::App| {
|
||||
let value = value.round() as u32;
|
||||
let value = slide_number(value, last);
|
||||
change(this, cx, &|output| {
|
||||
if let Range::Slides(from, to) = &mut output.range {
|
||||
*(if first { from } else { to }) = value;
|
||||
@@ -135,3 +140,16 @@ pub fn output_dialog(
|
||||
.on_click(move |_, _, cx| this.update(cx, |deck, cx| deck.output(cx)))
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::slide_number;
|
||||
|
||||
#[test]
|
||||
fn a_typed_number_stays_on_the_deck() {
|
||||
assert_eq!(slide_number(0.0, 5), 1, "0 would export every slide");
|
||||
assert_eq!(slide_number(-3.0, 5), 1);
|
||||
assert_eq!(slide_number(2.6, 5), 3);
|
||||
assert_eq!(slide_number(9.0, 5), 5);
|
||||
}
|
||||
}
|
||||
@@ -19,20 +19,21 @@ use gpui::{
|
||||
use crate::deck::Deck;
|
||||
use crate::dialog::Dialog;
|
||||
|
||||
/// Each comment as a thread quoted with its slide.
|
||||
fn threads(remarks: &[Remark], cx: &App) -> Result<Vec<Thread>, String> {
|
||||
/// Threads quoted with their slides; unreadable comments apart.
|
||||
fn threads(remarks: &[Remark], cx: &App) -> (Vec<Thread>, Vec<(String, String)>) {
|
||||
let authors: Vec<&str> = remarks
|
||||
.iter()
|
||||
.map(|remark| remark.author.as_str())
|
||||
.collect();
|
||||
remarks
|
||||
let (good, bad): (Vec<_>, Vec<_>) = remarks
|
||||
.iter()
|
||||
.map(|remark| {
|
||||
let at = remark
|
||||
.at
|
||||
.parse::<jiff::civil::DateTime>()
|
||||
.and_then(|at| at.to_zoned(jiff::tz::TimeZone::system()))
|
||||
.map_err(|error| format!("a bad comment time {}: {error}", remark.at))?;
|
||||
.map_err(|error| (remark.at.clone(), error.to_string()))?
|
||||
.timestamp();
|
||||
let hue = authors
|
||||
.iter()
|
||||
.position(|name| *name == remark.author)
|
||||
@@ -43,14 +44,16 @@ fn threads(remarks: &[Remark], cx: &App) -> Result<Vec<Thread>, String> {
|
||||
quote: Some(Deck::text(cx, "show.remark.slide", &[("n", &slide)])),
|
||||
comments: vec![Comment {
|
||||
author: Peer::new(remark.author.clone(), remark.author.clone(), hue),
|
||||
at: at.timestamp(),
|
||||
at,
|
||||
body: remark.text.clone().into(),
|
||||
reactions: Vec::new(),
|
||||
}],
|
||||
resolved: false,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
.partition(Result::is_ok);
|
||||
let bad = bad.into_iter().filter_map(Result::err).collect();
|
||||
(good.into_iter().filter_map(Result::ok).collect(), bad)
|
||||
}
|
||||
|
||||
impl Deck {
|
||||
@@ -77,8 +80,8 @@ impl Deck {
|
||||
input.set_text(text, cx);
|
||||
input
|
||||
});
|
||||
self.dialog = Some(Dialog::Remark { tab, edit, field });
|
||||
cx.notify();
|
||||
// Refused while another dialog is open; it says so.
|
||||
let _ = self.open_dialog(Dialog::Remark { tab, edit, field }, cx);
|
||||
}
|
||||
|
||||
/// Sends the dialog's text: a new comment or an edit.
|
||||
@@ -166,14 +169,15 @@ impl Deck {
|
||||
.active_tab()
|
||||
.map(|tab| tab.extra.remarks.clone())
|
||||
.unwrap_or_default();
|
||||
let threads = match threads(&remarks, cx) {
|
||||
Ok(threads) => threads,
|
||||
Err(error) => {
|
||||
log::error!("show: {error}");
|
||||
let message = InlineMessage::new(Severity::Danger, error);
|
||||
return div().p_2().child(message).into_any_element();
|
||||
}
|
||||
};
|
||||
let (threads, bad) = threads(&remarks, cx);
|
||||
for (at, error) in &bad {
|
||||
log::error!("show: a bad comment time {at}: {error}");
|
||||
}
|
||||
// One line however many: the comments below stay in view.
|
||||
let bad = bad.first().map(|(at, _)| {
|
||||
let n = bad.len().to_string();
|
||||
InlineMessage::new(Severity::Danger, Deck::text(cx, "show.remark.bad", &[("n", &n), ("at", at)]))
|
||||
});
|
||||
let active = self.shown_remark();
|
||||
let act = |id: &'static str,
|
||||
key: &str,
|
||||
@@ -227,6 +231,7 @@ impl Deck {
|
||||
.gap_2()
|
||||
.p_2()
|
||||
.child(head)
|
||||
.children(bad)
|
||||
.child(div().flex_1().min_h_0().child(sidebar))
|
||||
.into_any_element()
|
||||
}
|
||||
@@ -289,3 +294,32 @@ impl Deck {
|
||||
(!pins.is_empty()).then(|| div().absolute().inset_0().children(pins).into_any_element())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ely_lok::show::Remark;
|
||||
use gpui::TestAppContext;
|
||||
|
||||
use super::threads;
|
||||
|
||||
#[test]
|
||||
fn one_unreadable_time_spares_the_other_comments() {
|
||||
let cx = TestAppContext::single();
|
||||
cx.update(|cx| ely_ui::i18n::install_as("en-US", cx));
|
||||
let remark = |id: &str, at: &str| Remark {
|
||||
id: id.into(),
|
||||
author: "A".into(),
|
||||
text: "t".into(),
|
||||
at: at.into(),
|
||||
part: 0,
|
||||
anchor: (0, 0, 0, 0),
|
||||
};
|
||||
// The kernel writes an empty date as 0-00-00.
|
||||
let remarks = [remark("1", "2025-03-01"), remark("2", "0-00-00"), remark("3", "2025-03-01T10:15:00")];
|
||||
let (good, bad) = cx.update(|cx| threads(&remarks, cx));
|
||||
let keys: Vec<_> = good.iter().map(|thread| thread.key.to_string()).collect();
|
||||
assert_eq!(keys, ["1", "3"]);
|
||||
assert_eq!(bad.len(), 1);
|
||||
assert_eq!(bad[0].0, "0-00-00");
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ use ely_lok::{Doc, Worker, show::ShowSlide};
|
||||
use ely_office::prelude::*;
|
||||
use ely_platform::AppId;
|
||||
use gpui::{
|
||||
AnyElement, AnyWindowHandle, App, AppContext as _, Context, Entity, EntityId, IntoElement,
|
||||
ParentElement as _, PlatformDisplay, Window, WindowBounds, WindowOptions,
|
||||
AnyElement, AnyWindowHandle, App, AppContext as _, Bounds, Context, Entity, EntityId, IntoElement,
|
||||
ParentElement as _, Pixels, PlatformDisplay, Window, WindowBounds, WindowOptions,
|
||||
};
|
||||
|
||||
use super::{Show, audience::Audience, presenter::Presenter};
|
||||
@@ -80,9 +80,20 @@ fn copy(
|
||||
}
|
||||
}
|
||||
|
||||
/// macOS covers its menu bar and Dock by simple fullscreen.
|
||||
const SIMPLE: bool = cfg!(target_os = "macos");
|
||||
|
||||
/// A show window's bounds: fullscreen, or macOS's simple kind.
|
||||
fn bounds(area: Bounds<Pixels>) -> WindowBounds {
|
||||
match SIMPLE {
|
||||
true => WindowBounds::Windowed(area),
|
||||
false => WindowBounds::Fullscreen(area),
|
||||
}
|
||||
}
|
||||
|
||||
fn options(display: &Rc<dyn PlatformDisplay>) -> WindowOptions {
|
||||
WindowOptions {
|
||||
window_bounds: Some(WindowBounds::Fullscreen(display.bounds())),
|
||||
window_bounds: Some(bounds(display.bounds())),
|
||||
display_id: Some(display.id()),
|
||||
titlebar: None,
|
||||
focus: true,
|
||||
@@ -91,6 +102,13 @@ fn options(display: &Rc<dyn PlatformDisplay>) -> WindowOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// Hides the menu bar and Dock over a macOS show.
|
||||
fn cover(window: &mut Window) {
|
||||
if SIMPLE {
|
||||
window.toggle_simple_fullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens one show window; its root scope holds the keys.
|
||||
pub fn show_window(
|
||||
show: &Entity<Show>,
|
||||
@@ -102,6 +120,7 @@ pub fn show_window(
|
||||
Ok(match presenter {
|
||||
true => cx
|
||||
.open_window(options(display), |window, cx| {
|
||||
cover(window);
|
||||
let view = cx.new(|cx| Presenter::new(show, cx));
|
||||
window.focus(&view.read(cx).focus.clone(), cx);
|
||||
view
|
||||
@@ -109,6 +128,7 @@ pub fn show_window(
|
||||
.into(),
|
||||
false => cx
|
||||
.open_window(options(display), |window, cx| {
|
||||
cover(window);
|
||||
let view = cx.new(|cx| Audience::new(show, cx));
|
||||
window.focus(&view.read(cx).focus.clone(), cx);
|
||||
view
|
||||
@@ -121,7 +141,9 @@ impl Deck {
|
||||
/// Plays a copy from the first or shown slide.
|
||||
pub fn start_show(&mut self, here: bool, cx: &mut Context<Self>) {
|
||||
if self.show.is_some() || self.show_starting {
|
||||
return log::info!("show: already playing or starting");
|
||||
log::info!("show: already playing or starting");
|
||||
let text = Deck::text(cx, "show.play.busy", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
}
|
||||
let Some(id) = self.core.active else {
|
||||
return;
|
||||
@@ -160,7 +182,9 @@ impl Deck {
|
||||
let Some(first) = first.filter(|_| deck.core.active == Some(id)) else {
|
||||
discard(worker, doc, path, cx);
|
||||
if deck.core.active != Some(id) {
|
||||
return log::info!("show: tab {id} is no longer shown");
|
||||
log::info!("show: tab {id} is no longer shown");
|
||||
let text = Deck::text(cx, "show.play.gone", &[]);
|
||||
return deck.toast(text, Severity::Warning, cx);
|
||||
}
|
||||
let text = Deck::text(cx, "show.play.none", &[]);
|
||||
return deck.toast(text, Severity::Warning, cx);
|
||||
@@ -176,11 +200,11 @@ impl Deck {
|
||||
};
|
||||
match cx.displays().len() {
|
||||
1 => deck.open_show(starting, cx),
|
||||
_ => {
|
||||
deck.show_starting = true;
|
||||
deck.dialog = Some(Dialog::Show(starting));
|
||||
cx.notify();
|
||||
}
|
||||
_ => match deck.open_dialog(Dialog::Show(starting), cx) {
|
||||
Ok(()) => deck.show_starting = true,
|
||||
Err(Dialog::Show(refused)) => discard(worker, refused.doc, refused.copy, cx),
|
||||
Err(_) => unreachable!("the show dialog comes back"),
|
||||
},
|
||||
}
|
||||
},
|
||||
cx,
|
||||
@@ -194,6 +218,8 @@ impl Deck {
|
||||
let (Some(tab), Some(audience)) = (self.tab(starting.tab), displays.get(starting.audience))
|
||||
else {
|
||||
log::warn!("show: the tab or screen {} is gone", starting.audience);
|
||||
let text = Deck::text(cx, "show.play.gone", &[]);
|
||||
self.toast(text, Severity::Warning, cx);
|
||||
return discard(worker, starting.doc, starting.copy, cx);
|
||||
};
|
||||
let presenter = (displays.iter())
|
||||
@@ -313,3 +339,59 @@ impl Deck {
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpui::{Bounds, WindowBounds, point, px, size};
|
||||
|
||||
#[test]
|
||||
fn a_show_covers_the_display_on_every_platform() {
|
||||
let area = Bounds::new(point(px(0.), px(0.)), size(px(1920.), px(1080.)));
|
||||
let want = match cfg!(target_os = "macos") {
|
||||
true => WindowBounds::Windowed(area),
|
||||
false => WindowBounds::Fullscreen(area),
|
||||
};
|
||||
assert_eq!(super::bounds(area), want);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_start_whose_screen_is_gone_says_so_and_drops_its_copy() {
|
||||
use ely_office::prelude::*;
|
||||
use gpui::AppContext as _;
|
||||
|
||||
use crate::tests::{settle, update};
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = gpui::TestAppContext::single();
|
||||
let Some(deck) = crate::tests::deck(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
update(&mut cx, &deck, |deck, cx| deck.new_blank(cx));
|
||||
settle(&cx, |app| deck.read(app).active_tab().is_some_and(|tab| !tab.extra.slides.list.is_empty()));
|
||||
// The window's toasts live on its root.
|
||||
let handle = cx.update(|app| deck.read(app).core.window).expect("a window");
|
||||
let root = cx
|
||||
.update_window(handle, |_, window, app| {
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Show, deck.clone().into(), &ely_ui::commands::FILE, Vec::new(), window, app);
|
||||
deck.update(app, |deck, _| deck.core.root = root.downgrade());
|
||||
root
|
||||
})
|
||||
.expect("the window lives");
|
||||
let path = dir.path().join("copy.odp");
|
||||
let starting = cx.update(|app| {
|
||||
let deck = deck.read(app);
|
||||
let tab = deck.active_tab().expect("a tab");
|
||||
let mut worker = deck.core.worker.lock().expect("the worker lock");
|
||||
let (_, doc, slides) = super::copy(&mut worker, &tab.doc, (&path, None)).expect("a copy");
|
||||
super::Starting { tab: tab.id, slides, first: 0, doc, copy: path.clone(), audience: 99, presenter: false }
|
||||
});
|
||||
update(&mut cx, &deck, |deck, cx| {
|
||||
deck.show_starting = true;
|
||||
deck.open_show(starting, cx);
|
||||
});
|
||||
settle(&cx, |_| !path.exists());
|
||||
let (toasts, gone) = cx.update(|app| (root.read(app).toasts(app), crate::deck::Deck::text(app, "show.play.gone", &[])));
|
||||
assert!(toasts.iter().any(|(text, _)| *text == gone), "{toasts:?}");
|
||||
assert!(cx.update(|app| !deck.read(app).show_starting && deck.read(app).show.is_none()));
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,8 @@ use crate::dialog::{Dialog, edit};
|
||||
impl Deck {
|
||||
pub fn ask_table(&mut self, cx: &mut Context<Self>) {
|
||||
if let Some(tab) = self.core.active {
|
||||
self.dialog = Some(Dialog::Table {
|
||||
tab,
|
||||
columns: 3,
|
||||
rows: 3,
|
||||
});
|
||||
cx.notify();
|
||||
// Refused while another dialog is open; it says so.
|
||||
let _ = self.open_dialog(Dialog::Table { tab, columns: 3, rows: 3 }, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use gpui::{AppContext as _, Entity, TestAppContext};
|
||||
use crate::deck::Deck;
|
||||
|
||||
mod motion;
|
||||
mod notes;
|
||||
mod objects;
|
||||
mod output;
|
||||
mod play;
|
||||
@@ -44,7 +45,7 @@ pub(super) fn deck(cx: &mut TestAppContext, dir: &Path) -> Option<Entity<Deck>>
|
||||
|
||||
/// Steps the scheduler until `done` or ten seconds pass.
|
||||
#[track_caller]
|
||||
fn settle(cx: &TestAppContext, done: impl Fn(&gpui::App) -> bool) {
|
||||
pub(super) fn settle(cx: &TestAppContext, done: impl Fn(&gpui::App) -> bool) {
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
|
||||
while std::time::Instant::now() < deadline {
|
||||
if !cx.executor().tick() {
|
||||
@@ -58,7 +59,7 @@ fn settle(cx: &TestAppContext, done: impl Fn(&gpui::App) -> bool) {
|
||||
panic!("the state never settled");
|
||||
}
|
||||
|
||||
fn update(
|
||||
pub(super) fn update(
|
||||
cx: &mut TestAppContext,
|
||||
deck: &Entity<Deck>,
|
||||
f: impl FnOnce(&mut Deck, &mut gpui::Context<Deck>),
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
//! The notes field under the slide (SHOW-08).
|
||||
|
||||
use ely_office::prelude::*;
|
||||
use gpui::TestAppContext;
|
||||
|
||||
use super::objects::blank;
|
||||
use super::slides::{in_window, type_in};
|
||||
use super::{settle, update};
|
||||
|
||||
#[test]
|
||||
fn typed_notes_reach_the_slide() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let notes = |app: &gpui::App| {
|
||||
deck.read(app)
|
||||
.active_tab()
|
||||
.and_then(|tab| tab.extra.notes.clone())
|
||||
};
|
||||
settle(&cx, |app| notes(app).is_some());
|
||||
let field = in_window(&mut cx, &deck, |deck, window, cx| {
|
||||
deck.notes_input(window, cx)
|
||||
});
|
||||
let field = field.expect("the field");
|
||||
type_in(&mut cx, &field, "Start with the totals");
|
||||
update(&mut cx, &deck, |deck, cx| deck.commit_notes(cx));
|
||||
settle(&cx, |app| {
|
||||
notes(app).is_some_and(|notes| notes.text == "Start with the totals")
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notes_refused_as_stale_stay_typed_and_go_next_time() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let notes = |app: &gpui::App| deck.read(app).active_tab().and_then(|tab| tab.extra.notes.clone());
|
||||
let text = |app: &gpui::App| notes(app).map(|notes| notes.text);
|
||||
settle(&cx, |app| notes(app).is_some());
|
||||
let field = in_window(&mut cx, &deck, |deck, window, cx| deck.notes_input(window, cx)).expect("the field");
|
||||
let stale = cx.update(|app| deck.read(app).notes.at.clone());
|
||||
type_in(&mut cx, &field, "first");
|
||||
update(&mut cx, &deck, |deck, cx| deck.commit_notes(cx));
|
||||
settle(&cx, |app| text(app).as_deref() == Some("first"));
|
||||
in_window(&mut cx, &deck, |deck, window, cx| deck.notes_input(window, cx));
|
||||
// Typing began before the edit above was read back.
|
||||
type_in(&mut cx, &field, "second");
|
||||
update(&mut cx, &deck, |deck, cx| {
|
||||
deck.notes.at = stale;
|
||||
deck.commit_notes(cx);
|
||||
});
|
||||
settle(&cx, |app| deck.read(app).active_tab().is_some_and(|tab| tab.view.read(app).settled()));
|
||||
cx.run_until_parked();
|
||||
in_window(&mut cx, &deck, |deck, window, cx| deck.notes_input(window, cx));
|
||||
assert_eq!(cx.update(|app| field.read(app).text().to_string()), "second", "the typing stays");
|
||||
assert_eq!(cx.update(|app| text(app)).as_deref(), Some("first"), "the stale send was refused");
|
||||
update(&mut cx, &deck, |deck, cx| deck.commit_notes(cx));
|
||||
settle(&cx, |app| text(app).as_deref() == Some("second"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_read_while_typing_keeps_the_new_draft() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let text = |app: &gpui::App| deck.read(app).active_tab().and_then(|tab| tab.extra.notes.clone()).map(|notes| notes.text);
|
||||
settle(&cx, |app| text(app).is_some());
|
||||
let field = in_window(&mut cx, &deck, |deck, window, cx| deck.notes_input(window, cx)).expect("the field");
|
||||
type_in(&mut cx, &field, "first");
|
||||
update(&mut cx, &deck, |deck, cx| deck.commit_notes(cx));
|
||||
// Back in the field before the send is read back.
|
||||
in_window(&mut cx, &deck, |_, window, cx| window.focus(&gpui::Focusable::focus_handle(field.read(cx), cx), cx));
|
||||
type_in(&mut cx, &field, "second");
|
||||
settle(&cx, |app| text(app).as_deref() == Some("first"));
|
||||
in_window(&mut cx, &deck, |deck, window, cx| deck.notes_input(window, cx));
|
||||
// The blur redraws before its commit runs.
|
||||
in_window(&mut cx, &deck, |deck, window, cx| {
|
||||
window.blur(cx);
|
||||
deck.notes_input(window, cx)
|
||||
});
|
||||
assert_eq!(cx.update(|app| field.read(app).text().to_string()), "second", "the draft stays");
|
||||
update(&mut cx, &deck, |deck, cx| deck.commit_notes(cx));
|
||||
settle(&cx, |app| text(app).as_deref() == Some("second"));
|
||||
}
|
||||
@@ -145,3 +145,56 @@ fn a_click_on_media_finds_it_and_elsewhere_does_not() {
|
||||
assert_eq!(cx.update(|app| show.read(app).media_at(centre)), Some(0));
|
||||
assert_eq!(cx.update(|app| show.read(app).media_at((0.01, 0.01))), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_start_says_the_show_is_busy() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
// The window's toasts live on its root.
|
||||
let root = super::slides::in_window(&mut cx, &deck, |deck, window, cx| {
|
||||
let this = cx.entity();
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Show, this.into(), &ely_ui::commands::FILE, Vec::new(), window, cx);
|
||||
deck.core.root = root.downgrade();
|
||||
root
|
||||
});
|
||||
update(&mut cx, &deck, |deck, cx| {
|
||||
deck.show_starting = true;
|
||||
deck.start_show(false, cx);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
let (toasts, busy) = cx.update(|app| (root.read(app).toasts(app), Deck::text(app, "show.play.busy", &[])));
|
||||
assert!(toasts.iter().any(|(text, _)| *text == busy), "{toasts:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_start_left_for_another_tab_says_so() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let first = cx.update(|app| deck.read(app).core.active.expect("a tab"));
|
||||
update(&mut cx, &deck, |deck, cx| deck.new_blank(cx));
|
||||
settle(&cx, |app| deck.read(app).core.tabs.len() == 2 && deck.read(app).core.active != Some(first));
|
||||
let second = cx.update(|app| deck.read(app).core.active.expect("a tab"));
|
||||
let root = super::slides::in_window(&mut cx, &deck, |deck, window, cx| {
|
||||
let this = cx.entity();
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Show, this.into(), &ely_ui::commands::FILE, Vec::new(), window, cx);
|
||||
deck.core.root = root.downgrade();
|
||||
root
|
||||
});
|
||||
update(&mut cx, &deck, |deck, cx| {
|
||||
deck.core.active = Some(first);
|
||||
deck.start_show(false, cx);
|
||||
// Another tab comes forward while the copy is read.
|
||||
deck.core.active = Some(second);
|
||||
});
|
||||
let gone = cx.update(|app| Deck::text(app, "show.play.gone", &[]));
|
||||
settle(&cx, |app| root.read(app).toasts(app).iter().any(|(text, _)| *text == gone));
|
||||
assert!(cx.update(|app| !deck.read(app).show_starting && deck.read(app).show.is_none()));
|
||||
}
|
||||
@@ -11,7 +11,7 @@ use crate::deck::Deck;
|
||||
use crate::dialog::Dialog;
|
||||
|
||||
/// Runs `f` on the deck inside its window.
|
||||
fn in_window<R>(
|
||||
pub(super) fn in_window<R>(
|
||||
cx: &mut TestAppContext,
|
||||
deck: &Entity<Deck>,
|
||||
f: impl FnOnce(&mut Deck, &mut Window, &mut gpui::Context<Deck>) -> R,
|
||||
@@ -25,7 +25,7 @@ fn in_window<R>(
|
||||
.expect("the window lives")
|
||||
}
|
||||
|
||||
fn type_in(cx: &mut TestAppContext, field: &Entity<TextInput>, text: &str) {
|
||||
pub(super) fn type_in(cx: &mut TestAppContext, field: &Entity<TextInput>, text: &str) {
|
||||
let text = text.to_string();
|
||||
cx.update(|app| field.update(app, |field, cx| field.set_text(text, cx)));
|
||||
}
|
||||
@@ -105,28 +105,20 @@ fn the_table_dialog_inserts_a_table() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_notes_reach_the_slide() {
|
||||
fn an_open_dialog_is_not_pushed_aside() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let notes = |app: &gpui::App| {
|
||||
deck.read(app)
|
||||
.active_tab()
|
||||
.and_then(|tab| tab.extra.notes.clone())
|
||||
};
|
||||
settle(&cx, |app| notes(app).is_some());
|
||||
let field = in_window(&mut cx, &deck, |deck, window, cx| {
|
||||
deck.notes_input(window, cx)
|
||||
});
|
||||
let field = field.expect("the field");
|
||||
type_in(&mut cx, &field, "Start with the totals");
|
||||
update(&mut cx, &deck, |deck, cx| deck.commit_notes(cx));
|
||||
settle(&cx, |app| {
|
||||
notes(app).is_some_and(|notes| notes.text == "Start with the totals")
|
||||
});
|
||||
update(&mut cx, &deck, |deck, cx| deck.ask_table(cx));
|
||||
update(&mut cx, &deck, |deck, cx| deck.ask_new(cx));
|
||||
// The chart dialog opens after a background read.
|
||||
update(&mut cx, &deck, |deck, cx| deck.ask_chart(cx));
|
||||
cx.run_until_parked();
|
||||
let kept = cx.update(|app| matches!(deck.read(app).dialog, Some(crate::dialog::Dialog::Table { .. })));
|
||||
assert!(kept, "the table dialog stays");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -384,3 +376,88 @@ fn a_comment_picked_on_another_slide_shows_its_slide_again() {
|
||||
settle(&cx, |app| current(app) == Some(0));
|
||||
assert_eq!(cx.update(|app| deck.read(app).shown_remark()), Some(key));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_zoom_stays_through_later_reports() {
|
||||
use ely_gpui_component::shell::ZoomStep;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let view = |app: &gpui::App| deck.read(app).active_tab().expect("a tab").view.clone();
|
||||
settle(&cx, |app| view(app).read(app).fitting());
|
||||
update(&mut cx, &deck, |deck, cx| deck.zoom(ZoomStep::In, cx));
|
||||
let zoom = cx.update(|app| view(app).read(app).zoom());
|
||||
update(&mut cx, &deck, |deck, cx| {
|
||||
let (id, view) = deck.active_tab().map(|tab| (tab.id, tab.view.clone())).expect("a tab");
|
||||
deck.observed(id, &view, cx);
|
||||
});
|
||||
cx.update(|app| {
|
||||
let view = view(app);
|
||||
assert!(!view.read(app).fitting(), "a report does not fit the slide again");
|
||||
assert_eq!(view.read(app).zoom(), zoom, "the zoom stays");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_check_row_does_not_jump_among_masters() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
update(&mut cx, &deck, |deck, cx| deck.masters(true, cx));
|
||||
settle(&cx, |app| deck.read(app).active_tab().is_some_and(|tab| tab.extra.masters));
|
||||
update(&mut cx, &deck, |deck, cx| {
|
||||
deck.dialog = Some(crate::dialog::Dialog::Check(Vec::new()));
|
||||
deck.go_to_finding(0, cx);
|
||||
});
|
||||
assert!(cx.update(|app| deck.read(app).dialog.is_some()), "the check stays open");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_size_does_not_stay_shown() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let before = cx.update(|app| deck.read(app).active_tab().expect("a tab").extra.size);
|
||||
update(&mut cx, &deck, |deck, cx| deck.resize((-500, -500), cx));
|
||||
settle(&cx, |app| {
|
||||
deck.read(app).active_tab().is_some_and(|tab| tab.extra.size_asked.is_none())
|
||||
});
|
||||
let extra = cx.update(|app| {
|
||||
let tab = deck.read(app).active_tab().expect("a tab");
|
||||
(tab.extra.size, tab.extra.shown_size())
|
||||
});
|
||||
assert_eq!(extra.0, before, "the kernel kept its size");
|
||||
assert_eq!(extra.1, crate::design::mm100(before), "the fields show it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_size_the_kernel_does_not_take_clears_after_its_read() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some(deck) = blank(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
update(&mut cx, &deck, |deck, cx| {
|
||||
deck.resize((30_000, 19_050), cx);
|
||||
// As if the kernel refused: it keeps another size.
|
||||
let id = deck.core.active.expect("a tab");
|
||||
let tab = deck.tab_mut(id).expect("a tab");
|
||||
let (_, seq) = tab.extra.size_asked.expect("asked");
|
||||
tab.extra.size_asked = Some(((40_000, 19_050), seq));
|
||||
});
|
||||
settle(&cx, |app| {
|
||||
deck.read(app).active_tab().is_some_and(|tab| tab.extra.size_asked.is_none())
|
||||
});
|
||||
let read = cx.update(|app| crate::design::mm100(deck.read(app).active_tab().expect("a tab").extra.size));
|
||||
assert!((read.0 - 30_000).abs() <= 50, "the kernel's own size shows: {read:?}");
|
||||
}
|
||||
@@ -81,7 +81,7 @@ impl Book {
|
||||
}
|
||||
(Asked::Refresh, Ok(_)) => book.warn_key("table.pivot.none", cx),
|
||||
(_, Ok(Found::Pivot(Some(pivot)))) => {
|
||||
book.dialog = Some(Dialog::Pivot {
|
||||
book.open_dialog(Dialog::Pivot {
|
||||
tab: id,
|
||||
source: pivot.source,
|
||||
fields: pivot.fields,
|
||||
@@ -120,7 +120,7 @@ impl Book {
|
||||
if picked.top.iter().any(String::is_empty) {
|
||||
return self.warn_key("table.pivot.headers", cx);
|
||||
}
|
||||
self.dialog = Some(Dialog::Pivot {
|
||||
self.open_dialog(Dialog::Pivot {
|
||||
tab: id,
|
||||
source: picked.data,
|
||||
fields: picked.top,
|
||||
@@ -146,7 +146,7 @@ impl Book {
|
||||
range: ely_office::chart::field(range, "table.chart.range", window, cx),
|
||||
look: ely_office::chart::LookFields::new(&look, window, cx),
|
||||
};
|
||||
self.dialog = Some(Dialog::Chart {
|
||||
self.open_dialog(Dialog::Chart {
|
||||
tab: id,
|
||||
chart: chart.map(Box::new),
|
||||
look: Box::new(look),
|
||||
|
||||
@@ -101,6 +101,17 @@ impl Host for Book {
|
||||
self.sync_bars(view, cx);
|
||||
}
|
||||
}
|
||||
|
||||
/// A closed tab's dialog and list go with it.
|
||||
fn tab_closed(&mut self, tab: &ely_office::Tab<Extra, ely_office::Lok>, cx: &mut Context<Self>) {
|
||||
if self.dialog.as_ref().and_then(crate::dialog::Dialog::tab) == Some(tab.id) {
|
||||
self.dialog = None;
|
||||
}
|
||||
if self.choices.as_ref().is_some_and(|choices| choices.tab == tab.id) {
|
||||
self.choices = None;
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/// The window root with a blank workbook.
|
||||
@@ -143,7 +154,7 @@ pub fn open(app: AppId, window: &mut Window, cx: &mut App) -> Entity<Root> {
|
||||
let root = ely_ui::document_root(app, book.clone().into(), &ely_ui::commands::FILE, menus, window, cx);
|
||||
book.update(cx, |book, cx| {
|
||||
book.core.root = root.downgrade();
|
||||
book.core.window = Some(window.window_handle());
|
||||
book.own_window(window, cx);
|
||||
window.focus(&book.core.focus, cx);
|
||||
});
|
||||
let launched = ely_ui::launch_files(cx);
|
||||
@@ -229,7 +240,10 @@ impl Book {
|
||||
match read {
|
||||
Ok((sheets, geometry, at)) => {
|
||||
log::info!("table: tab {id} has {} sheets", sheets.list.len());
|
||||
view.update(cx, |view, _| view.set_part(sheets.current));
|
||||
view.update(cx, |view, cx| {
|
||||
view.set_part(sheets.current);
|
||||
view.set_geometry(geometry.clone(), cx);
|
||||
});
|
||||
let extra = &mut tab.extra;
|
||||
extra.sheets = sheets;
|
||||
extra.geometry = geometry;
|
||||
@@ -369,7 +383,6 @@ impl Render for Book {
|
||||
.on_action(cx.listener(Self::on_open_file))
|
||||
.on_action(cx.listener(Self::on_save))
|
||||
.on_action(cx.listener(Self::on_save_as))
|
||||
.on_action(cx.listener(Self::on_quit))
|
||||
.on_action(cx.listener(Self::on_close_tab))
|
||||
.on_action(cx.listener(Self::on_export))
|
||||
.on_action(cx.listener(Self::on_print))
|
||||
|
||||
@@ -121,7 +121,7 @@ impl Book {
|
||||
|worker, doc| doc.selection_text(worker),
|
||||
move |book, text, _, cx| match text {
|
||||
Ok(text) if filled(&text) > 1 => {
|
||||
book.dialog = Some(Dialog::Merge { tab });
|
||||
book.open_dialog(Dialog::Merge { tab });
|
||||
cx.notify();
|
||||
}
|
||||
Ok(_) => book.run_in(id, "cells.merge", &["false"], cx),
|
||||
@@ -150,7 +150,7 @@ impl Book {
|
||||
return self.toast(text, ely_gpui_component::primitives::Severity::Warning, cx);
|
||||
};
|
||||
let field = cx.new(|cx| TextInput::new(window, cx));
|
||||
self.dialog = Some(Dialog::Size { tab, column, field });
|
||||
self.open_dialog(Dialog::Size { tab, column, field });
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ impl Book {
|
||||
fn data_dialog(&mut self, id: u64, asked: Asked, picked: Selection, state: ReadState, cx: &mut Context<Self>) {
|
||||
log::info!("table: {asked:?} on {}", picked.range);
|
||||
let header = picked.header;
|
||||
self.dialog = Some(match asked {
|
||||
self.open_dialog(match asked {
|
||||
Asked::Sort => {
|
||||
let (first, ..) = picked.area.expect("a data area");
|
||||
Dialog::Sort {
|
||||
@@ -311,10 +311,10 @@ impl Book {
|
||||
move |book, picked, _, window, cx| {
|
||||
let (c1, _, c2, _) = picked.area.expect("a data area");
|
||||
if c1 != c2 {
|
||||
return book.warn_key("table.columns.one", cx);
|
||||
return book.warn_key("table.columns.same", cx);
|
||||
}
|
||||
let other = cx.new(|cx| TextInput::new(window, cx));
|
||||
book.dialog = Some(Dialog::Columns {
|
||||
book.open_dialog(Dialog::Columns {
|
||||
tab: id,
|
||||
separators: vec!["9".into()],
|
||||
other,
|
||||
@@ -394,9 +394,10 @@ impl Book {
|
||||
.filter(|entry| entry.selected)
|
||||
.map(|entry| SharedString::from(entry.text.clone()))
|
||||
.collect();
|
||||
book.dialog = Some(Dialog::Column {
|
||||
book.open_dialog(Dialog::Column {
|
||||
tab: id,
|
||||
column,
|
||||
row,
|
||||
entries: filter.entries,
|
||||
picked,
|
||||
});
|
||||
@@ -413,12 +414,15 @@ impl Book {
|
||||
let Some(Dialog::Column {
|
||||
tab,
|
||||
column,
|
||||
row,
|
||||
entries,
|
||||
picked,
|
||||
}) = self.dialog.take()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
// The kernel filters the cursor's range: go to the button.
|
||||
self.run_in(Some(tab), "cell.goto", &[&sheet::address(column, row)], cx);
|
||||
match sort {
|
||||
Some(rising) => {
|
||||
let key = SortKey {
|
||||
|
||||
@@ -94,6 +94,8 @@ pub enum Dialog {
|
||||
Column {
|
||||
tab: u64,
|
||||
column: u32,
|
||||
/// The button's row: its cell names the filtered range.
|
||||
row: u32,
|
||||
entries: Vec<Entry>,
|
||||
picked: Vec<SharedString>,
|
||||
},
|
||||
@@ -150,6 +152,35 @@ pub enum Dialog {
|
||||
},
|
||||
}
|
||||
|
||||
impl Dialog {
|
||||
/// The workbook it asks about; imports have none yet.
|
||||
pub fn tab(&self) -> Option<u64> {
|
||||
match self {
|
||||
Dialog::Rename { tab, .. }
|
||||
| Dialog::Show { tab, .. }
|
||||
| Dialog::Delete { tab, .. }
|
||||
| Dialog::Size { tab, .. }
|
||||
| Dialog::Merge { tab, .. }
|
||||
| Dialog::Define { tab, .. }
|
||||
| Dialog::Names { tab, .. }
|
||||
| Dialog::Sort { tab, .. }
|
||||
| Dialog::Filter { tab, .. }
|
||||
| Dialog::Dedupe { tab, .. }
|
||||
| Dialog::Columns { tab, .. }
|
||||
| Dialog::Column { tab, .. }
|
||||
| Dialog::Validation { tab, .. }
|
||||
| Dialog::Conditional { tab, .. }
|
||||
| Dialog::Formats { tab, .. }
|
||||
| Dialog::Pivot { tab, .. }
|
||||
| Dialog::Chart { tab, .. }
|
||||
| Dialog::Export { tab, .. }
|
||||
| Dialog::Page { tab, .. }
|
||||
| Dialog::Protect { tab, .. } => Some(*tab),
|
||||
Dialog::Import(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Book {
|
||||
/// The define dialog's sheets: its own workbook's.
|
||||
pub(crate) fn define_scopes(&self) -> Option<Vec<String>> {
|
||||
|
||||
@@ -58,8 +58,8 @@ pub fn label(status: &str, cx: &App) -> SharedString {
|
||||
if let Some((_, key)) = ERRORS.iter().find(|(known, _)| *known == status) {
|
||||
return Book::text(cx, key, &[]);
|
||||
}
|
||||
let parts: Vec<String> = status
|
||||
.split("; ")
|
||||
let parts: Vec<String> = fields(status)
|
||||
.into_iter()
|
||||
.map(|part| {
|
||||
let known = part.split_once(": ").and_then(|(name, value)| {
|
||||
let (_, key) = FIGURES.iter().find(|(known, _)| *known == name)?;
|
||||
@@ -74,6 +74,24 @@ pub fn label(status: &str, cx: &App) -> SharedString {
|
||||
parts.join(" ").into()
|
||||
}
|
||||
|
||||
/// The status split at each "Name: "; values keep semicolons.
|
||||
fn fields(status: &str) -> Vec<&str> {
|
||||
let starts = |rest: &str| {
|
||||
rest.split_once(": ")
|
||||
.is_some_and(|(name, _)| !name.is_empty() && name.chars().all(|c| c.is_ascii_alphabetic() || c == ' '))
|
||||
};
|
||||
let mut out = Vec::new();
|
||||
let mut from = 0;
|
||||
for (at, _) in status.match_indices("; ") {
|
||||
if starts(&status[at + 2..]) {
|
||||
out.push(&status[from..at]);
|
||||
from = at + 2;
|
||||
}
|
||||
}
|
||||
out.push(&status[from..]);
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
@@ -89,6 +107,13 @@ mod tests {
|
||||
super::Book::text(app, "table.figure.sum", &[("value", "42")])
|
||||
);
|
||||
assert_eq!(label.as_ref(), expect, "known names relabel, others stay");
|
||||
// The kernel's formatted values pass through untouched.
|
||||
ely_ui::i18n::install_as("en-US", app);
|
||||
let custom = super::label("Average: 8128.00 kg; net; Sum: 16256.00 kg; net", app);
|
||||
assert_eq!(custom.as_ref(), "Average 8128.00 kg; net Sum 16256.00 kg; net", "a format's own semicolons stay");
|
||||
for value in ["8128.00", "8128.33333333333", "0.0000000001", "1234567890.25", "$1,234.50"] {
|
||||
assert_eq!(super::label(&format!("Sum: {value}"), app).as_ref(), format!("Sum {value}"));
|
||||
}
|
||||
for (english, key) in super::ERRORS {
|
||||
assert_eq!(super::label(english, app), super::Book::text(app, key, &[]));
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ impl Book {
|
||||
let name = cx.new(|cx| TextInput::new(window, cx));
|
||||
let range = cx.new(|cx| TextInput::new(window, cx));
|
||||
range.update(cx, |range, cx| range.set_text(refers, cx));
|
||||
book.dialog = Some(Dialog::Define {
|
||||
book.open_dialog(Dialog::Define {
|
||||
tab: id,
|
||||
name,
|
||||
range,
|
||||
@@ -206,7 +206,7 @@ impl Book {
|
||||
let range = cx.new(|cx| TextInput::new(window, cx));
|
||||
let formula = first.formula.clone();
|
||||
range.update(cx, |range, cx| range.set_text(formula, cx));
|
||||
book.dialog = Some(Dialog::Names {
|
||||
book.open_dialog(Dialog::Names {
|
||||
tab: id,
|
||||
names,
|
||||
chosen: 0,
|
||||
|
||||
@@ -99,7 +99,7 @@ impl Book {
|
||||
};
|
||||
let length = if column { width } else { height };
|
||||
let pick = |pair: (i32, i32)| if column { pair.0 } else { pair.1 };
|
||||
let (frozen, scroll) = (pick(read.frozen()), pick(read.scroll()));
|
||||
let (frozen, first) = (pick(read.frozen()), pick(read.scrolled_start()));
|
||||
let mut spans = Vec::new();
|
||||
let mut take = |index: u32| {
|
||||
let (start, end) = (along(axis.start(index)), along(axis.start(index + 1)));
|
||||
@@ -114,7 +114,7 @@ impl Book {
|
||||
0
|
||||
};
|
||||
(0..held).for_each(&mut take);
|
||||
let mut index = axis.at(frozen + scroll).max(held);
|
||||
let mut index = axis.at(first).max(held);
|
||||
while index < axis.count() && along(axis.start(index)) < length {
|
||||
take(index);
|
||||
index += 1;
|
||||
|
||||
@@ -49,7 +49,7 @@ impl Book {
|
||||
let Some(tab) = self.core.active else {
|
||||
return self.warn_key("command.blocked.no_document", cx);
|
||||
};
|
||||
self.dialog = Some(Dialog::Export {
|
||||
self.open_dialog(Dialog::Export {
|
||||
tab,
|
||||
format: Format::Pdf,
|
||||
});
|
||||
@@ -144,10 +144,8 @@ impl Book {
|
||||
tab,
|
||||
move |worker, doc| doc.export_pdf(worker, &url, &WHOLE),
|
||||
move |book, written, _, cx| match written {
|
||||
Ok(()) => ely_office::print_later(path, cx, |book, error, cx| {
|
||||
book.output_failed(&error, cx)
|
||||
}),
|
||||
Err(error) => book.output_failed(&error.to_string(), cx),
|
||||
Ok(()) => ely_office::print_later(path, cx),
|
||||
Err(error) => book.print_failed(&error.to_string(), cx),
|
||||
},
|
||||
cx,
|
||||
);
|
||||
|
||||
@@ -82,6 +82,15 @@ fn cell_ok(cell: &str) -> bool {
|
||||
&& row_number(digits).is_some()
|
||||
}
|
||||
|
||||
/// Whole columns or rows, like `$A:$D`; one `$` each.
|
||||
fn whole(from: &str, to: &str, number: fn(&str) -> Option<u32>) -> bool {
|
||||
let end = |end: &str| {
|
||||
let end = end.strip_prefix('$').unwrap_or(end);
|
||||
end.bytes().all(|byte| byte.is_ascii_alphanumeric()).then(|| number(&end.to_ascii_uppercase()))?
|
||||
};
|
||||
matches!((end(from), end(to)), (Some(first), Some(last)) if first <= last)
|
||||
}
|
||||
|
||||
/// Areas as the kernel takes them, or None.
|
||||
fn areas(text: &str) -> Option<String> {
|
||||
let tokens: Vec<&str> = text
|
||||
@@ -90,7 +99,9 @@ fn areas(text: &str) -> Option<String> {
|
||||
.filter(|token| !token.is_empty())
|
||||
.collect();
|
||||
let ok = |token: &&str| match token.split_once(':') {
|
||||
Some((from, to)) => cell_ok(from) && cell_ok(to),
|
||||
Some((from, to)) => {
|
||||
cell_ok(from) && cell_ok(to) || whole(from, to, column_number) || whole(from, to, row_number)
|
||||
}
|
||||
None => cell_ok(token),
|
||||
};
|
||||
tokens.iter().all(ok).then(|| tokens.join(","))
|
||||
@@ -143,7 +154,7 @@ impl Book {
|
||||
rows: field(sheet::rows_ref(layout.rows), "table.page.rows_hint", cx),
|
||||
columns: field(sheet::columns_ref(layout.columns), "table.page.columns_hint", cx),
|
||||
};
|
||||
self.dialog = Some(Dialog::Page {
|
||||
self.open_dialog(Dialog::Page {
|
||||
tab: id,
|
||||
landscape: layout.landscape,
|
||||
scale: layout.scale,
|
||||
@@ -228,6 +239,11 @@ mod tests {
|
||||
assert_eq!(areas("A1:B"), None);
|
||||
assert_eq!(areas("XFE1"), None);
|
||||
assert_eq!(areas("S!A1"), None);
|
||||
assert_eq!(areas("$A:$D, 1:3").as_deref(), Some("$A:$D,1:3"));
|
||||
assert_eq!(areas("A:3"), None);
|
||||
for bad in ["$$A:$$D", "$$1:$$3", "$A:$$D", "A:D,$$E:$$F", "+1:2", "D:A"] {
|
||||
assert_eq!(areas(bad), None, "{bad}");
|
||||
}
|
||||
assert_eq!(span("$1:$3", row_number), Some(Some((1, 3))));
|
||||
assert_eq!(span("2", row_number), Some(Some((2, 2))));
|
||||
assert_eq!(span("3:1", row_number), None);
|
||||
|
||||
@@ -58,7 +58,7 @@ impl Book {
|
||||
confirm: masked("table.protect.confirm", cx),
|
||||
now,
|
||||
};
|
||||
book.dialog = Some(Dialog::Protect {
|
||||
book.open_dialog(Dialog::Protect {
|
||||
tab: id,
|
||||
protecting: Box::new(protecting),
|
||||
});
|
||||
|
||||
@@ -143,7 +143,7 @@ impl Book {
|
||||
} else {
|
||||
rule
|
||||
};
|
||||
self.dialog = Some(Dialog::Validation {
|
||||
self.open_dialog(Dialog::Validation {
|
||||
tab: id,
|
||||
rule: Box::new(rule),
|
||||
fields: Box::new(fields),
|
||||
@@ -275,7 +275,7 @@ impl Book {
|
||||
};
|
||||
let value1 = cx.new(|cx| TextInput::new(window, cx));
|
||||
let value2 = cx.new(|cx| TextInput::new(window, cx));
|
||||
self.dialog = Some(Dialog::Conditional {
|
||||
self.open_dialog(Dialog::Conditional {
|
||||
tab: id,
|
||||
kind: "cell",
|
||||
operator: "greater",
|
||||
@@ -338,7 +338,7 @@ impl Book {
|
||||
book.toast(text, Severity::Info, cx);
|
||||
}
|
||||
Ok(formats) => {
|
||||
book.dialog = Some(Dialog::Formats {
|
||||
book.open_dialog(Dialog::Formats {
|
||||
tab: id,
|
||||
formats,
|
||||
chosen: 0,
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::book::Book;
|
||||
|
||||
/// The open choices menu: tab, values, request.
|
||||
pub struct Choices {
|
||||
tab: u64,
|
||||
pub(crate) tab: u64,
|
||||
pub(crate) values: Vec<String>,
|
||||
request: (u64, Point<Pixels>),
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ impl Book {
|
||||
return self.warn("table.show.none", cx);
|
||||
};
|
||||
let tab = tab.id;
|
||||
self.dialog = Some(Dialog::Show {
|
||||
self.open_dialog(Dialog::Show {
|
||||
tab,
|
||||
hidden,
|
||||
chosen,
|
||||
@@ -246,7 +246,7 @@ impl Book {
|
||||
};
|
||||
let field = cx.new(|cx| TextInput::new(window, cx));
|
||||
field.update(cx, |field, cx| field.set_text(name, cx));
|
||||
self.dialog = Some(Dialog::Rename { tab, at, index, field });
|
||||
self.open_dialog(Dialog::Rename { tab, at, index, field });
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ impl Book {
|
||||
},
|
||||
move |book, read, _, cx| match read {
|
||||
Ok((references, at, name)) => {
|
||||
book.dialog = Some(Dialog::Delete {
|
||||
book.open_dialog(Dialog::Delete {
|
||||
tab: id,
|
||||
at,
|
||||
index,
|
||||
|
||||
@@ -114,19 +114,15 @@ pub(crate) fn delete(
|
||||
let mut detail = if references.formulas + references.names == 0 {
|
||||
Book::text(cx, "table.delete.alone", &[])
|
||||
} else {
|
||||
Book::text(
|
||||
cx,
|
||||
"table.delete.refs",
|
||||
&[
|
||||
("formulas", &references.formulas.to_string()),
|
||||
("first", &references.first),
|
||||
("names", &references.names.to_string()),
|
||||
],
|
||||
)
|
||||
let count = |key, n: u64| ely_ui::i18n::counted(cx, key, n, &[("n", &n.to_string())]);
|
||||
let formulas = count("table.delete.formulas", references.formulas);
|
||||
let names = count("table.delete.names", references.names);
|
||||
let args = [("formulas", formulas.as_ref()), ("first", &references.first), ("names", &names)];
|
||||
Book::text(cx, "table.delete.refs", &args)
|
||||
};
|
||||
if references.dynamic > 0 {
|
||||
let count = references.dynamic.to_string();
|
||||
let dynamic = Book::text(cx, "table.delete.dynamic", &[("count", &count)]);
|
||||
let dynamic = ely_ui::i18n::counted(cx, "table.delete.dynamic", references.dynamic, &[("count", &count)]);
|
||||
detail = format!("{detail} {dynamic}").into();
|
||||
}
|
||||
let label = Book::text(cx, "table.delete.go", &[]);
|
||||
|
||||
@@ -300,3 +300,41 @@ fn the_panel_reads_number_formats_and_find_counts_cells() {
|
||||
.is_some_and(|finder| finder.all.len() == 3)
|
||||
});
|
||||
}
|
||||
|
||||
/// Two blocks: keys in A, other numbers in C.
|
||||
const BLOCKS: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
|
||||
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
|
||||
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.spreadsheet">
|
||||
<office:body><office:spreadsheet><table:table table:name="S">
|
||||
<table:table-row><table:table-cell><text:p>K</text:p></table:table-cell><table:table-cell/><table:table-cell><text:p>L</text:p></table:table-cell></table:table-row>
|
||||
<table:table-row><table:table-cell office:value-type="float" office:value="3"><text:p>3</text:p></table:table-cell><table:table-cell/><table:table-cell office:value-type="float" office:value="9"><text:p>9</text:p></table:table-cell></table:table-row>
|
||||
<table:table-row><table:table-cell office:value-type="float" office:value="1"><text:p>1</text:p></table:table-cell><table:table-cell/><table:table-cell office:value-type="float" office:value="7"><text:p>7</text:p></table:table-cell></table:table-row>
|
||||
<table:table-row><table:table-cell office:value-type="float" office:value="2"><text:p>2</text:p></table:table-cell><table:table-cell/><table:table-cell office:value-type="float" office:value="8"><text:p>8</text:p></table:table-cell></table:table-row>
|
||||
</table:table></office:spreadsheet></office:body>
|
||||
</office:document>"#;
|
||||
|
||||
#[test]
|
||||
fn a_column_button_sorts_its_own_block_not_the_cursors() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some((_window, book)) = book(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
update(&mut cx, &book, |book, cx| {
|
||||
book.new_from_text("blocks.fods", BLOCKS, cx)
|
||||
});
|
||||
settle(&cx, |app| sheet_names(app, &book) == ["S"]);
|
||||
run(&mut cx, &book, "cell.goto", &["A1"]);
|
||||
run(&mut cx, &book, "data.autofilter", &[]);
|
||||
run(&mut cx, &book, "cell.goto", &["C3"]);
|
||||
let id = cx.update(|app| book.read(app).core.active.expect("a tab"));
|
||||
update(&mut cx, &book, |book, cx| {
|
||||
book.ask_column(id, &Request::Filter { column: 0, row: 0 }, cx)
|
||||
});
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Column { .. }));
|
||||
update(&mut cx, &book, |book, cx| book.column_asked(Some(true), cx));
|
||||
assert_eq!(cells(&mut cx, &book, "A2:A4"), "1\n2\n3");
|
||||
assert_eq!(cells(&mut cx, &book, "C2:C4"), "9\n7\n8");
|
||||
}
|
||||
@@ -44,3 +44,27 @@ fn a_failed_command_still_moves_the_state_on() {
|
||||
update(&mut cx, &book, |book, cx| book.run_active("sheet.rename", &["Plan", "1"], cx));
|
||||
settle(&cx, |app| sheet_names(app, &book) == ["Plan"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_print_says_printing_failed() {
|
||||
use ely_gpui_component::primitives::Severity;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some((window, book)) = book(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
// The window's toasts live on its root.
|
||||
let root = window
|
||||
.update(&mut cx, |_, window, cx| {
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Table, book.clone().into(), &ely_ui::commands::FILE, Vec::new(), window, cx);
|
||||
book.update(cx, |book, _| book.core.root = root.downgrade());
|
||||
root
|
||||
})
|
||||
.expect("the window");
|
||||
let gone = dir.path().join("gone.pdf");
|
||||
update(&mut cx, &book, |_, cx| ely_office::print_later(gone, cx));
|
||||
cx.run_until_parked();
|
||||
let (toasts, prefix) = cx.update(|app| (root.read(app).toasts(app), ely_office::text(app, "office.print.failed", &[("error", "")])));
|
||||
assert!(toasts.iter().any(|(text, severity)| *severity == Some(Severity::Danger) && text.starts_with(prefix.as_ref())), "{toasts:?}");
|
||||
}
|
||||
@@ -377,3 +377,124 @@ fn text_files_wait_their_turn_for_the_import_dialog() {
|
||||
names.sort();
|
||||
assert_eq!(names, ["a.csv", "b.csv"], "both files open");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_import_waits_behind_a_dialog_that_displaces_it() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some((window, book)) = book(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
blank(&mut cx, &book);
|
||||
let path = dir.path().join("wait.csv");
|
||||
std::fs::write(&path, "Id,Ignored\n1E3,hidden\n").expect("writes");
|
||||
update(&mut cx, &book, |book, cx| book.ask_import(path.clone(), cx));
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Import(pending) if !pending.reading));
|
||||
update(&mut cx, &book, |book, _| {
|
||||
if let Some(Dialog::Import(pending)) = &mut book.dialog {
|
||||
pending.how.columns = vec![Column::Text, Column::Skip];
|
||||
}
|
||||
});
|
||||
window
|
||||
.update(&mut cx, |_, window, cx| {
|
||||
book.update(cx, |book, cx| book.on_export(&ely_ui::commands::Export, window, cx))
|
||||
})
|
||||
.expect("the window");
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Export { .. }));
|
||||
update(&mut cx, &book, |book, cx| {
|
||||
book.dialog = None;
|
||||
cx.notify();
|
||||
});
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Import(pending) if pending.path.ends_with("wait.csv")));
|
||||
cx.run_until_parked();
|
||||
update(&mut cx, &book, |book, cx| book.import_asked(cx));
|
||||
settle(&cx, |app| book.read(app).active_tab().is_some_and(|tab| tab.name == "wait.csv"));
|
||||
// Text keeps `1E3`; the skipped column stays empty.
|
||||
assert_eq!(cells(&mut cx, &book, "A2:B2").trim_end(), "1E3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_a_tab_takes_its_dialog_and_frees_the_import() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some((window, book)) = book(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
blank(&mut cx, &book);
|
||||
window
|
||||
.update(&mut cx, |_, window, cx| {
|
||||
book.update(cx, |book, cx| book.on_export(&ely_ui::commands::Export, window, cx))
|
||||
})
|
||||
.expect("the window");
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Export { .. }));
|
||||
let id = cx.update(|app| book.read(app).core.tabs[0].id);
|
||||
update(&mut cx, &book, |book, cx| book.close_tab(id, cx));
|
||||
let path = dir.path().join("after.csv");
|
||||
std::fs::write(&path, "Name\nx\n").expect("writes");
|
||||
update(&mut cx, &book, |book, cx| book.ask_import(path.clone(), cx));
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Import(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_whole_column_print_area_still_applies() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some((_window, book)) = book(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
blank(&mut cx, &book);
|
||||
update(&mut cx, &book, |book, cx| book.ask_page(cx));
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Page { .. }));
|
||||
type_in(&mut cx, &book, area, "A:D");
|
||||
update(&mut cx, &book, |book, cx| book.page_asked(cx));
|
||||
let layout = read(&mut cx, &book, sheet::print_layout, sheet::LAYOUT);
|
||||
assert_eq!(layout.areas.len(), 1, "set: {:?}", layout.areas);
|
||||
// The kernel's own text comes back into the dialog.
|
||||
update(&mut cx, &book, |book, cx| book.ask_page(cx));
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Page { .. }));
|
||||
let shown = cx.update(|app| match book.read(app).dialog.as_ref() {
|
||||
Some(dialog) => area(dialog).read(app).text().to_string(),
|
||||
None => unreachable!("a page dialog"),
|
||||
});
|
||||
assert_eq!(shown, layout.areas[0]);
|
||||
update(&mut cx, &book, |book, cx| {
|
||||
if let Some(Dialog::Page { landscape, .. }) = &mut book.dialog {
|
||||
*landscape = true;
|
||||
}
|
||||
book.page_asked(cx)
|
||||
});
|
||||
let layout = read(&mut cx, &book, sheet::print_layout, sheet::LAYOUT);
|
||||
assert!(layout.landscape, "applied with {shown}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_default_encoding_follows_the_apps_language() {
|
||||
use ely_gpui_component::i18n::I18n;
|
||||
use ely_lok::sheet::csv::Encoding;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let Some((_window, book)) = book(&mut cx, dir.path()) else {
|
||||
eprintln!("SKIP: no LOK build");
|
||||
return;
|
||||
};
|
||||
let path = dir.path().join("gb.csv");
|
||||
// 你好 in GB18030: not UTF-8.
|
||||
std::fs::write(&path, [0xC4, 0xE3, 0xBA, 0xC3, b'\n']).expect("writes");
|
||||
for (tag, expected) in [("zh-CN", Encoding::Gb18030), ("en-US", Encoding::Windows1252)] {
|
||||
cx.update(|app| I18n::set_locale(tag, app));
|
||||
update(&mut cx, &book, |book, cx| book.ask_import(path.clone(), cx));
|
||||
asked(&cx, &book, |dialog| matches!(dialog, Dialog::Import(_)));
|
||||
let found = cx.update(|app| match book.read(app).dialog.as_ref() {
|
||||
Some(Dialog::Import(pending)) => pending.how.encoding,
|
||||
_ => unreachable!("an import dialog"),
|
||||
});
|
||||
assert_eq!(found, expected, "{tag}");
|
||||
update(&mut cx, &book, |book, cx| {
|
||||
book.dialog = None;
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
}
|
||||
+30
-16
@@ -154,22 +154,20 @@ fn decode(bytes: &[u8], encoding: Encoding) -> Option<String> {
|
||||
.map(|text| text.into_owned())
|
||||
}
|
||||
|
||||
/// Rows as Calc's text import reads them (impex.cxx).
|
||||
fn split(text: &str, how: &Import) -> Vec<Vec<String>> {
|
||||
/// Calc's text-import rows (impex.cxx), one at a time.
|
||||
fn split<'a>(text: &'a str, how: &'a Import) -> impl Iterator<Item = Vec<String>> + 'a {
|
||||
let mut chars = text.chars().peekable();
|
||||
let mut rows = Vec::new();
|
||||
while chars.peek().is_some() {
|
||||
std::iter::from_fn(move || {
|
||||
chars.peek()?;
|
||||
let mut row = Vec::new();
|
||||
loop {
|
||||
let (value, more) = field(&mut chars, how);
|
||||
row.push(value);
|
||||
if !more {
|
||||
break;
|
||||
return Some(row);
|
||||
}
|
||||
}
|
||||
rows.push(row);
|
||||
}
|
||||
rows
|
||||
})
|
||||
}
|
||||
|
||||
/// One field, and whether the record goes on.
|
||||
@@ -233,15 +231,19 @@ impl Book {
|
||||
|
||||
pub(crate) fn ask_import(&mut self, path: PathBuf, cx: &mut Context<Self>) {
|
||||
let reading = path.clone();
|
||||
let chinese = ely_ui::i18n::resolve(&ely_platform::locale::system()) == "zh-CN";
|
||||
// The language the app shows, not the system's.
|
||||
let chinese = cx.global::<ely_gpui_component::i18n::I18n>().locale().tag == "zh-CN";
|
||||
cx.spawn(async move |this, cx| {
|
||||
let bytes = cx
|
||||
.background_spawn(async move { std::fs::read(&reading) })
|
||||
// Guessing checks the whole file: off the window thread.
|
||||
let pending = cx
|
||||
.background_spawn(async move {
|
||||
std::fs::read(&reading).map(|bytes| Pending::new(reading, bytes, chinese))
|
||||
})
|
||||
.await;
|
||||
in_window(&this, cx, |book, _, cx| match bytes {
|
||||
Ok(bytes) => {
|
||||
log::info!("table: import asks for {} bytes", bytes.len());
|
||||
book.imports.push_back(Pending::new(path, bytes, chinese));
|
||||
in_window(&this, cx, |book, _, cx| match pending {
|
||||
Ok(pending) => {
|
||||
log::info!("table: import asks for {} bytes", pending.bytes.len());
|
||||
book.imports.push_back(pending);
|
||||
book.next_import(cx);
|
||||
}
|
||||
Err(error) => book.failed_open(&path.display().to_string(), &error, cx),
|
||||
@@ -250,14 +252,26 @@ impl Book {
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
/// Opens `dialog`; a displaced import waits its turn again.
|
||||
pub(crate) fn open_dialog(&mut self, dialog: Dialog) {
|
||||
if let Some(Dialog::Import(pending)) = self.dialog.replace(dialog) {
|
||||
log::info!("table: import waits behind another dialog");
|
||||
self.imports.push_front(*pending);
|
||||
}
|
||||
}
|
||||
|
||||
/// The next waiting import asks, once no dialog is open.
|
||||
pub(crate) fn next_import(&mut self, cx: &mut Context<Self>) {
|
||||
if self.dialog.is_some() {
|
||||
return;
|
||||
}
|
||||
if let Some(pending) = self.imports.pop_front() {
|
||||
// A finished scan keeps the reader's column choices.
|
||||
let unread = pending.reading;
|
||||
self.dialog = Some(Dialog::Import(Box::new(pending)));
|
||||
self.scan_import(cx);
|
||||
if unread {
|
||||
self.scan_import(cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,9 +95,10 @@ impl Tree {
|
||||
Ask::Force { repo, plan } => {
|
||||
let lost = match plan.lost.len() {
|
||||
0 => label("tree.force.nothing"),
|
||||
n => text(
|
||||
n => ely_ui::i18n::counted(
|
||||
cx,
|
||||
"tree.force.lost",
|
||||
n as u64,
|
||||
&[("n", &n.to_string()), ("commits", &plan.lost.join("\n"))],
|
||||
),
|
||||
};
|
||||
|
||||
@@ -101,8 +101,8 @@ impl Tree {
|
||||
};
|
||||
let lines = (!shown.picked.is_empty() && self.partial(shown)).then(|| {
|
||||
let this = this.clone();
|
||||
let n = shown.picked.len().to_string();
|
||||
Button::new("tree-lines", text(cx, key, &[("n", &n)]))
|
||||
let n = shown.picked.len();
|
||||
Button::new("tree-lines", ely_ui::i18n::counted(cx, key, n as u64, &[("n", &n.to_string())]))
|
||||
.variant(ButtonVariant::Primary)
|
||||
.size(ControlSize::Sm)
|
||||
.on_click(move |_, _, cx| {
|
||||
|
||||
@@ -205,9 +205,10 @@ impl Tree {
|
||||
let short = |oid: &str| oid[..oid.len().min(7)].to_string();
|
||||
let left = match plan.left.len() {
|
||||
0 => label("tree.move.nothing"),
|
||||
n => text(
|
||||
n => ely_ui::i18n::counted(
|
||||
cx,
|
||||
"tree.move.left",
|
||||
n as u64,
|
||||
&[("n", &n.to_string()), ("commits", &plan.left.join("\n"))],
|
||||
),
|
||||
};
|
||||
|
||||
@@ -209,13 +209,7 @@ impl Tree {
|
||||
.iter()
|
||||
.filter(|entry| entry.state != State::Ignored)
|
||||
.count();
|
||||
let (icon, title) = match changed {
|
||||
0 => (IconName::CircleCheck, text(cx, "tree.clean", &[])),
|
||||
n => (
|
||||
IconName::GitBranch,
|
||||
text(cx, "tree.changed", &[("n", &n.to_string())]),
|
||||
),
|
||||
};
|
||||
let (icon, title) = summary(changed, cx);
|
||||
EmptyState::new(("tree-summary", opened.id), icon, title).into_any_element()
|
||||
}
|
||||
}
|
||||
@@ -263,3 +257,25 @@ impl Render for Tree {
|
||||
.children(self.dialog(cx))
|
||||
}
|
||||
}
|
||||
|
||||
/// The work tree's line: clean, or how many files changed.
|
||||
pub(crate) fn summary(changed: usize, cx: &App) -> (IconName, SharedString) {
|
||||
match changed {
|
||||
0 => (IconName::CircleCheck, text(cx, "tree.clean", &[])),
|
||||
n => (IconName::GitBranch, ely_ui::i18n::counted(cx, "tree.changed", n as u64, &[("n", &n.to_string())])),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[gpui::test]
|
||||
fn the_summary_counts_files_in_both_languages(cx: &mut gpui::TestAppContext) {
|
||||
cx.update(|cx| {
|
||||
ely_ui::i18n::install_as("en-US", cx);
|
||||
let said = |n: usize, cx: &gpui::App| super::summary(n, cx).1.to_string();
|
||||
assert_eq!([said(0, cx), said(1, cx), said(2, cx)], ["Nothing to commit", "1 file changed", "2 files changed"]);
|
||||
ely_ui::i18n::install_as("zh-CN", cx);
|
||||
assert_eq!([said(1, cx), said(2, cx)], ["1 个文件有改动", "2 个文件有改动"]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ mod doc;
|
||||
mod feed;
|
||||
mod frames;
|
||||
mod install;
|
||||
mod load;
|
||||
pub use install::{install_dir, templates};
|
||||
use install::worker_bin;
|
||||
pub use doc::{Pdf, Sheet, Sheets};
|
||||
@@ -37,6 +38,8 @@ pub struct Worker {
|
||||
session: u64,
|
||||
stderr: ely_ipc::Relay,
|
||||
check: Check,
|
||||
/// The name new comments sign with, once set.
|
||||
author: Option<String>,
|
||||
}
|
||||
|
||||
/// The start-up check: to run, passed, or why it failed.
|
||||
@@ -73,9 +76,16 @@ pub struct Doc {
|
||||
id: u64,
|
||||
/// The document's revision when this handle was taken.
|
||||
pub(crate) rev: u64,
|
||||
/// LOK_DOCTYPE: 0 text, 1 spreadsheet, 2 presentation.
|
||||
kind: u64,
|
||||
}
|
||||
|
||||
impl Doc {
|
||||
/// Whether this is a spreadsheet.
|
||||
pub fn is_sheet(&self) -> bool {
|
||||
self.kind == 1
|
||||
}
|
||||
|
||||
/// Whether this handle saw a later state than `other`.
|
||||
pub fn newer_than(&self, other: &Doc) -> bool {
|
||||
self.rev > other.rev
|
||||
@@ -181,6 +191,7 @@ impl Worker {
|
||||
session: SESSIONS.fetch_add(1, std::sync::atomic::Ordering::SeqCst),
|
||||
stderr,
|
||||
check: Check::Pending(profile_dir.to_path_buf()),
|
||||
author: None,
|
||||
};
|
||||
Ok(worker)
|
||||
}
|
||||
@@ -194,47 +205,15 @@ impl Worker {
|
||||
/// The name new comments and tracked changes carry.
|
||||
pub fn set_author(&mut self, name: &str) -> io::Result<()> {
|
||||
log::info!("lok: the author is set");
|
||||
// Wanted even if this worker fails; a restart sends it.
|
||||
self.author = Some(name.to_string());
|
||||
self.request(tag::SET_AUTHOR, &Pack::new().str(name).bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Loads `url`; macros never run (LOK-11).
|
||||
pub fn load(&mut self, url: &str) -> io::Result<Doc> {
|
||||
self.unlock(url, "")
|
||||
}
|
||||
|
||||
/// Loads text `url` as a sheet, read as `how` says.
|
||||
pub fn import(&mut self, url: &str, how: &crate::sheet::csv::Import) -> io::Result<Doc> {
|
||||
use crate::sheet::csv::{COLUMNS, ENCODINGS};
|
||||
let at = |found: Option<usize>| found.expect("a listed choice") as u64;
|
||||
let pack = Pack::new()
|
||||
.str(url)
|
||||
.u64(u64::from(how.separator))
|
||||
.u64(how.quote.map_or(0, u64::from))
|
||||
.u64(at(ENCODINGS.iter().position(|e| *e == how.encoding)))
|
||||
.u64(how.columns.len() as u64);
|
||||
let pack = how.columns.iter().fold(pack, |pack, column| {
|
||||
pack.u64(at(COLUMNS.iter().position(|c| c == column)))
|
||||
});
|
||||
let payload = self.request(tag::IMPORT, &pack.bytes())?;
|
||||
let id = Unpack::new(&payload).u64()?;
|
||||
self.feed.opened(id);
|
||||
Ok(Doc { worker: self.session, id, rev: 0 })
|
||||
}
|
||||
|
||||
/// Loads `url` with its password; a locked one is PermissionDenied.
|
||||
pub fn unlock(&mut self, url: &str, password: &str) -> io::Result<Doc> {
|
||||
let request = Pack::new().str(url).str(password).bytes();
|
||||
let payload = self.request(tag::LOAD, &request).map_err(|error| {
|
||||
if error.to_string() == crate::ipc::LOCKED {
|
||||
io::Error::new(io::ErrorKind::PermissionDenied, error.to_string())
|
||||
} else {
|
||||
error
|
||||
}
|
||||
})?;
|
||||
let id = Unpack::new(&payload).u64()?;
|
||||
self.feed.opened(id);
|
||||
Ok(Doc { worker: self.session, id, rev: 0 })
|
||||
/// The name last asked for; a restart signs with it.
|
||||
pub fn author(&self) -> Option<&str> {
|
||||
self.author.as_deref()
|
||||
}
|
||||
|
||||
/// Runs a macro by its URL (LOK-11 probe).
|
||||
|
||||
@@ -55,14 +55,16 @@ impl Doc {
|
||||
Ok(Sheets { current, list })
|
||||
}
|
||||
|
||||
/// Tells the kernel the area the view shows, in twips.
|
||||
pub fn visible_area(&self, worker: &mut Worker, (x, y, w, h): Rect) -> io::Result<()> {
|
||||
/// Tells the kernel the shown area and the tile scale.
|
||||
pub fn visible_area(&self, worker: &mut Worker, (x, y, w, h): Rect, (tile, tile_twips): (u32, i32)) -> io::Result<()> {
|
||||
let request = Pack::new()
|
||||
.u64(worker.doc_id(self)?)
|
||||
.i64(x.into())
|
||||
.i64(y.into())
|
||||
.i64(w.into())
|
||||
.i64(h.into())
|
||||
.i64(tile.into())
|
||||
.i64(tile_twips.into())
|
||||
.bytes();
|
||||
worker.request(tag::VISIBLE_AREA, &request)?;
|
||||
Ok(())
|
||||
@@ -96,6 +98,15 @@ impl Doc {
|
||||
Ok((unpack.i64()?, unpack.i64()?))
|
||||
}
|
||||
|
||||
/// The size and the client zoom it was measured at.
|
||||
pub fn size_at(&self, worker: &mut Worker) -> io::Result<((i64, i64), (i32, i32))> {
|
||||
let payload = worker.request(tag::DOC_SIZE, &Pack::new().u64(worker.doc_id(self)?).bytes())?;
|
||||
let mut unpack = Unpack::new(&payload);
|
||||
let size = (unpack.i64()?, unpack.i64()?);
|
||||
let number = |value: i64| i32::try_from(value).map_err(io::Error::other);
|
||||
Ok((size, (number(unpack.i64()?)?, number(unpack.i64()?)?)))
|
||||
}
|
||||
|
||||
/// Page rectangles in twips; empty without pages.
|
||||
pub fn pages(&self, worker: &mut Worker) -> io::Result<Vec<Rect>> {
|
||||
let payload = worker.request(tag::PAGES, &Pack::new().u64(worker.doc_id(self)?).bytes())?;
|
||||
@@ -178,7 +189,38 @@ impl Doc {
|
||||
.u64(u64::from(pixels.0))
|
||||
.u64(u64::from(pixels.1))
|
||||
.bytes();
|
||||
crate::show::layers(&worker.request(tag::SLIDE_LAYERS, &request)?)
|
||||
let head = worker.request(tag::SLIDE_LAYERS, &request)?;
|
||||
let mut unpack = Unpack::new(&head);
|
||||
let (width, height, count) = (unpack.u64()?, unpack.u64()?, unpack.u64()?);
|
||||
// Layers arrive in pieces that keep each frame small.
|
||||
let mut whole = Pack::new().u64(width).u64(height).u64(count);
|
||||
for index in 0..count {
|
||||
let (json, painted) = (unpack.str()?, unpack.u64()?);
|
||||
whole = whole.str(&json).u64(painted);
|
||||
if painted != 0 {
|
||||
whole = whole.blob(&self.slide_layer(worker, index)?);
|
||||
}
|
||||
}
|
||||
crate::show::layers(&whole.bytes())
|
||||
}
|
||||
|
||||
/// Layer `index` of the last layers read, piece by piece.
|
||||
fn slide_layer(&self, worker: &mut Worker, index: u64) -> io::Result<Vec<u8>> {
|
||||
let id = worker.doc_id(self)?;
|
||||
let mut pixels = Vec::new();
|
||||
loop {
|
||||
let ask = Pack::new().u64(id).u64(index).u64(pixels.len() as u64).bytes();
|
||||
let reply = worker.request(tag::SLIDE_LAYER, &ask)?;
|
||||
let mut unpack = Unpack::new(&reply);
|
||||
let (total, piece) = (unpack.u64()?, unpack.blob()?);
|
||||
pixels.extend_from_slice(&piece);
|
||||
if pixels.len() as u64 >= total {
|
||||
return Ok(pixels);
|
||||
}
|
||||
if piece.is_empty() {
|
||||
return Err(io::Error::other(format!("layer {index} stopped at byte {}", pixels.len())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Saves to `url` as `format`; failure surfaces (LOK-09).
|
||||
|
||||
@@ -181,17 +181,17 @@ mod tests {
|
||||
};
|
||||
feed.push(1, first);
|
||||
feed.push(1, second);
|
||||
let batch = feed.wait(&Doc { worker: 0, id: 1, rev: 0 }, 0, 0).expect("a batch");
|
||||
let batch = feed.wait(&Doc { worker: 0, id: 1, rev: 0, kind: 0 }, 0, 0).expect("a batch");
|
||||
assert_eq!((batch.seq, batch.all, batch.rects.len()), (2, true, 1));
|
||||
assert_eq!(
|
||||
batch.states,
|
||||
[("b".to_string(), "1".to_string()), ("a".into(), "2".into())]
|
||||
);
|
||||
let idle = feed.wait(&Doc { worker: 0, id: 1, rev: 0 }, 2, 0).expect("the snapshot");
|
||||
let idle = feed.wait(&Doc { worker: 0, id: 1, rev: 0, kind: 0 }, 2, 0).expect("the snapshot");
|
||||
assert!(idle.rects.is_empty() && idle.states.is_empty() && idle.seq == 2);
|
||||
feed.closed(1);
|
||||
assert!(
|
||||
feed.wait(&Doc { worker: 0, id: 1, rev: 0 }, 2, 0).is_err(),
|
||||
feed.wait(&Doc { worker: 0, id: 1, rev: 0, kind: 0 }, 2, 0).is_err(),
|
||||
"a closed document"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//! Loading documents: by URL, with a password, or as text.
|
||||
|
||||
use std::io;
|
||||
|
||||
use super::{Doc, Worker};
|
||||
use crate::ipc::{Pack, Unpack, tag};
|
||||
|
||||
impl Worker {
|
||||
/// Loads `url`; macros never run (LOK-11).
|
||||
pub fn load(&mut self, url: &str) -> io::Result<Doc> {
|
||||
self.unlock(url, "")
|
||||
}
|
||||
|
||||
/// Loads text `url` as a sheet, read as `how` says.
|
||||
pub fn import(&mut self, url: &str, how: &crate::sheet::csv::Import) -> io::Result<Doc> {
|
||||
use crate::sheet::csv::{COLUMNS, ENCODINGS};
|
||||
let at = |found: Option<usize>| found.expect("a listed choice") as u64;
|
||||
let pack = Pack::new()
|
||||
.str(url)
|
||||
.u64(u64::from(how.separator))
|
||||
.u64(how.quote.map_or(0, u64::from))
|
||||
.u64(at(ENCODINGS.iter().position(|e| *e == how.encoding)))
|
||||
.u64(how.columns.len() as u64);
|
||||
let pack = how.columns.iter().fold(pack, |pack, column| {
|
||||
pack.u64(at(COLUMNS.iter().position(|c| c == column)))
|
||||
});
|
||||
let payload = self.request(tag::IMPORT, &pack.bytes())?;
|
||||
self.opened(&payload)
|
||||
}
|
||||
|
||||
/// Loads `url` with its password; a locked one is PermissionDenied.
|
||||
pub fn unlock(&mut self, url: &str, password: &str) -> io::Result<Doc> {
|
||||
let request = Pack::new().str(url).str(password).bytes();
|
||||
let payload = self.request(tag::LOAD, &request).map_err(|error| {
|
||||
if error.to_string() == crate::ipc::LOCKED {
|
||||
io::Error::new(io::ErrorKind::PermissionDenied, error.to_string())
|
||||
} else {
|
||||
error
|
||||
}
|
||||
})?;
|
||||
self.opened(&payload)
|
||||
}
|
||||
|
||||
/// A load's reply: the document's number and kind.
|
||||
fn opened(&mut self, payload: &[u8]) -> io::Result<Doc> {
|
||||
let mut reply = Unpack::new(payload);
|
||||
let (id, kind) = (reply.u64()?, reply.u64()?);
|
||||
self.feed.opened(id);
|
||||
Ok(Doc { worker: self.session, id, rev: 0, kind })
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ mod analysis;
|
||||
mod charts;
|
||||
mod check;
|
||||
mod commands;
|
||||
mod filter;
|
||||
mod format;
|
||||
mod formula;
|
||||
mod handouts;
|
||||
@@ -282,30 +283,22 @@ fn a_production_worker_refuses_run_macro() {
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn an_unpatched_build_is_rejected() {
|
||||
let dmg = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../engines/LibreOffice_26.2.6_MacOS_aarch64.dmg");
|
||||
if !dmg.try_exists().expect("the dmg check") {
|
||||
eprintln!("SKIP: no official dmg");
|
||||
// A plain folder: a mounted .app would be registered.
|
||||
let frameworks = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../engines/lo-official/Contents/Frameworks");
|
||||
if !frameworks.try_exists().expect("the folder check") {
|
||||
eprintln!("SKIP: run scripts/extract-official-lo.sh");
|
||||
return;
|
||||
}
|
||||
let mount = tempfile::tempdir().expect("a temp dir");
|
||||
let attached = std::process::Command::new("hdiutil")
|
||||
.args(["attach", "-nobrowse", "-readonly", "-mountpoint"])
|
||||
.arg(mount.path())
|
||||
.arg(&dmg)
|
||||
.status()
|
||||
.expect("hdiutil runs");
|
||||
assert!(attached.success(), "the official dmg mounts");
|
||||
let frameworks = mount.path().join("LibreOffice.app/Contents/Frameworks");
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let outcome = Worker::spawn(&frameworks, &dir.path().join("profile"));
|
||||
assert!(outcome.is_err(), "the unpatched build must be rejected");
|
||||
let detached = std::process::Command::new("hdiutil")
|
||||
.args(["detach", "-quiet"])
|
||||
.arg(mount.path())
|
||||
.status()
|
||||
.expect("hdiutil detaches");
|
||||
assert!(detached.success());
|
||||
let Err(error) = Worker::spawn(&frameworks, &dir.path().join("profile")) else {
|
||||
panic!("the unpatched build must be rejected");
|
||||
};
|
||||
assert_eq!(error.kind(), std::io::ErrorKind::InvalidData, "{error}");
|
||||
assert!(
|
||||
error.to_string().contains("does not paint tiles (unpatched)"),
|
||||
"rejected for the tile check, not {error}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loaded 100 of 364 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user