From d7e8104519e70fd4563334b5d3c542e012f58c03 Mon Sep 17 00:00:00 2001 From: DueGin <1917764907@qq.com> Date: Mon, 19 Oct 2026 13:33:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=92=8C=E6=96=B0=E5=BB=BA=E6=97=A5=E7=A8=8B=E6=94=B9=E5=9C=A8?= =?UTF-8?q?=E5=8F=B3=E4=BE=A7=E6=8A=BD=E5=B1=89=EF=BC=8C=E3=80=8C=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E3=80=8D=E5=88=86=E5=8C=BA=E5=8F=AF=E6=8A=98=E5=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 任务行去掉「备注和进展」「添加子任务」按钮,点「编辑」在右侧抽屉打开任务详情:日程字段停下来自动保存,子任务、备注和进展都在这里 - 新建日程改在右侧抽屉填写:主窗口里抽屉在列表右边,面板里从右侧滑出盖住列表 - 主窗口「任务 › 全部」的分区点标题可折叠,折叠状态会记住 - SelfTest 新增 drawer 场景,支持 background 模式 Co-Authored-By: Claude Opus 5 --- AGENTS.md | 2 +- CHANGELOG.md | 14 + README.md | 14 +- Sources/ITimer/JournalView.swift | 35 +-- Sources/ITimer/MainView.swift | 4 +- Sources/ITimer/MenuBarView.swift | 434 ++++++++++++++++---------- Sources/ITimer/ScheduleComposer.swift | 111 +++---- Sources/ITimer/SelfTest.swift | 289 +++++++++++++++-- Sources/ITimer/TaskDrawer.swift | 335 ++++++++++++++++++++ docs/FEATURES.md | 25 +- 10 files changed, 956 insertions(+), 307 deletions(-) create mode 100644 Sources/ITimer/TaskDrawer.swift diff --git a/AGENTS.md b/AGENTS.md index 8135136..62646de 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -53,4 +53,4 @@ iTimer 是一个 macOS 菜单栏计时器,用 SwiftUI 写,Swift Package 管 swift test # 核心逻辑测试 ``` -界面自测在 `Sources/ITimer/SelfTest.swift`。`goal`、`workflow` 两个场景支持 background 模式:不激活 App,事件直接发给窗口,不占用前台和鼠标。 +界面自测在 `Sources/ITimer/SelfTest.swift`。`goal`、`workflow`、`record`、`drawer` 几个场景支持 background 模式:不激活 App,事件直接发给窗口,不占用前台和鼠标。 diff --git a/CHANGELOG.md b/CHANGELOG.md index 217132a..48bde67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ ## [未发布] +### 新增 + +- 主窗口「任务 › 全部」里的分区可以折叠:点「到点待开始」「进行中」「已暂停」「接下来」「时间待定」「今日完成」的标题,收起或展开这一组任务,折叠状态会记住。 + +### 变更 + +- 新建日程不再占满整个界面,改在右侧抽屉里填写:主窗口里抽屉在列表右边,列表照常可用;菜单栏面板里抽屉从右侧滑出盖住列表,点左侧露出的列表、点 × 或按 Esc 关闭。 +- 任务行去掉「备注和进展」和「添加子任务」两个按钮,改为点「编辑」在右侧抽屉打开任务详情;再点一次「编辑」、点 × 或按 Esc 关闭。 +- 任务详情里改名称、日期、时间、预计、提醒、标签,停下来就自动保存,不再有「保存」按钮;名称里输入的 `#标签` 会并入标签。 +- 子任务改在任务详情的「子任务」一栏添加:回车添加一条,可以连续输入;这一栏也列出已有子任务,可以直接开始、暂停,点一下打开它的详情,子任务的详情里可以点回父任务。 +- 备注和进展改在任务详情里写。有备注或进展的任务,任务行上显示一个小气泡。 +- 今日完成的任务也改为点「编辑」打开详情,可以改名称和标签、查看子任务、写备注和进展。 +- 右键菜单的「备注和进展」「编辑日程…」合并为「编辑…」;「子任务 › 添加子任务…」打开任务详情,并把光标放进添加子任务的输入框。 + ## [1.10.5] - 2026-10-16 ### 变更 diff --git a/README.md b/README.md index 7df318e..f5f3331 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ - **单核**:只有一个任务在计时的时间,也是连续天数(🔥)的依据:每天单核满 25 分钟 +1。 - **专注度(0–100)**:单核时间全额计入,并行计 55%,脑裂计 15%,再按每小时切换次数扣分(最多 15 分)。 - 85+ 心流 · 65+ 稳定 · 40+ 分散 · 其余 过载 -- **子任务**:一个任务下面可以挂一层子任务,用来拆步骤。点任务行上的「添加子任务」按钮(或右键 › 子任务 › 添加子任务…),父任务下方会出现输入框,回车添加一条,可以连续添加,Esc 结束;新子任务先放在「时间待定」,想做时点开始即可。也可以右键一个已有任务 › 子任务 › 归入其他任务。子任务不能再往下嵌套。父任务和它没完成的子任务在列表里是一组,子任务缩进排在父任务下面,整组跟着组里最靠前的那一项走,例如有一个子任务在计时,整组就排在「进行中」。父任务行显示完成进度(如 `1/3`),点进度胶囊(或右键 › 折叠子任务)可以把子任务收起来,折叠状态会记住,收起时如果有子任务在计时,胶囊旁会亮一个小圆点,添加子任务时会自动展开。删除父任务会一并删除它的子任务。 +- **子任务**:一个任务下面可以挂一层子任务,用来拆步骤。点任务行上的「编辑」按钮打开任务详情,在「子任务」一栏输入,回车添加一条,可以连续添加(右键 › 子任务 › 添加子任务… 会直接把光标放进这一栏);新子任务先放在「时间待定」,想做时点开始即可。也可以右键一个已有任务 › 子任务 › 归入其他任务。子任务不能再往下嵌套。父任务和它没完成的子任务在列表里是一组,子任务缩进排在父任务下面,整组跟着组里最靠前的那一项走,例如有一个子任务在计时,整组就排在「进行中」。父任务行显示完成进度(如 `1/3`),点进度胶囊(或右键 › 折叠子任务)可以把子任务收起来,折叠状态会记住,收起时如果有子任务在计时,胶囊旁会亮一个小圆点,添加子任务时会自动展开。删除父任务会一并删除它的子任务。 - **标签**:每个任务可以打多个自由标签,不需要预先创建。 -- **备注与进展**:每个任务有一条常驻备注(结论、约束、下次接着做什么),以及按时间追加的进展评论。做着做着随手记一句,比事后回忆准。 +- **备注与进展**:每个任务有一条常驻备注(结论、约束、下次接着做什么),以及按时间追加的进展评论,都在任务详情里写。做着做着随手记一句,比事后回忆准。 - **工作流**:把要按顺序推进的事画在一张无限画布上。卡片就是普通任务(照常计时、进统计、写日历),连线表示「先做完这个,才轮到那个」。可以建多个工作流,一个任务同一时间只在一个工作流里;连线不能绕成环。上游全部完成的卡片亮成橙色「可开始」,还有上游没完成的显示「等待上游」,任务列表里也会标出「等上游」。每张卡片可以单独打开「上游完成后自动开始」(卡片上显示 ⚡),这样上一步一完成它就开始计时;没打开的只会亮起来等你开始,不替你多开线程。等待上游只是提示,想先开始也可以直接开始。 - **目标**:一件要花几周甚至几个月的大事,例如「iTimer 商业化」「做完个人网站」。每个目标有一张路线图,上面是一个个里程碑,连线表示「先达成这个,才轮到那个」,同样不能绕成环。目标可以写一段说明:为什么做、怎样算成功。 - **里程碑**:路线图上的每张卡片就是一个工作流,双击进去照常拆步骤、计时。一个工作流同一时间只在一个目标里。里程碑可以写完成标准、定目标日期(卡片上显示「还剩 N 天」或「已逾期 N 天」);投入时长是它所有任务(含子任务)的计时总和。状态有五种:等待上游(上游里程碑还没达成,自己也还没开始)、可开始、推进中(有任务开始过)、待确认(任务都做完了)、已达成。任务做完不等于达成,要你点一下「标记达成」,因为里程碑看的是结果,比如「拿到 10 个付费用户」;达成之后,下游的里程碑才亮成「可开始」。 @@ -52,19 +52,19 @@ **弹出面板** - 主卡片:最久的那个线程的大号计时;右上角是「线程槽」,一格一个线程,槽位数就是脑裂线,最后一格描了粉边,一眼看出还剩几个名额。 - 今日色带:从今天第一次计时到现在的负载条,青色专注、橙色并行、粉色脑裂。 -- 每个任务一行:左侧圆钮暂停或继续,◎「只做这个」一键暂停其他所有线程,✓ 完成,添加子任务,双击标题改名,删除要连点两下。右键有完整菜单;菜单开着时计时数字会暂停,关掉后跳回正确的时间。 -- 今日完成:做完的事不会消失,可以一键「再来一段」。忘记结束导致多计时的话,点铅笔按钮(或右键 › 修改计时时间…),修改每段实际计时的开始、结束日期和时间,再点「保存」。暂停间隔不计入时长;完成日期随最后一段结束时间更新,统计和已同步的日历事件也会更新。 +- 每个任务一行:左侧圆钮暂停或继续,◎「只做这个」一键暂停其他所有线程,✓ 完成,编辑按钮打开任务详情,双击标题改名,删除要连点两下。右键有完整菜单;菜单开着时计时数字会暂停,关掉后跳回正确的时间。 +- 今日完成:做完的事不会消失,可以一键「再来一段」,编辑按钮同样打开任务详情(可以改名称、标签,写备注和进展)。忘记结束导致多计时的话,点铅笔按钮(或右键 › 修改计时时间…),修改每段实际计时的开始、结束日期和时间,再点「保存」。暂停间隔不计入时长;完成日期随最后一段结束时间更新,统计和已同步的日历事件也会更新。 - 输入框的占位文字会随负载变化:「再开一个就到脑裂线了…」,开新线程前先提醒你一下。 - 最近做过的事以胶囊形式列出,点一下直接开始,输入时会自动过滤。 - 输入框支持 `写周报 #汇报 #PPT`:`#` 打标签。输入 `#` 时下方会出现已有标签的补全。 - 列表按状态分成「到点待开始 / 进行中 / 已暂停 / 接下来 / 时间待定 / 今日完成」,分区旁的数字是处于这个状态的任务数。 - 任务行显示 `#标签`;右键菜单里的「子任务」「标签」可以直接添加子任务或切换标签。 -- 任务行的气泡按钮打开「备注和进展」:备注随时改,进展按时间追加,记过的任务会亮起气泡。 -- 日程表单:日期一行直接列出「待定 / 今天 / 明天 / 后天 / 下周一」,其他日期点右侧日历按钮选;表单里还有标签一行,点选即可。 +- 任务详情:点任务行的编辑按钮,详情从右侧抽屉滑出。上面是日程(名称、日期、时间、预计、提醒、标签),改完停下来就自动保存;下面是子任务(可以直接开始,点一下打开子任务的详情)和备注、进展。再点一次编辑按钮、点左侧露出的列表、点 × 或按 Esc 关闭。有备注或进展的任务,任务行上会显示一个小气泡。 +- 日程表单:点「日程」,表单同样从右侧抽屉滑出。日期一行直接列出「待定 / 今天 / 明天 / 后天 / 下周一」,其他日期点右侧日历按钮选;表单里还有标签一行,点选即可。 **主窗口**:布局和滴答清单类似。 - 最左边是常驻的图标栏:任务 ⌘1、目标 ⌘2、工作流 ⌘3、分析 ⌘4,底部是设置。图标上有角标:任务有在计时就亮小圆点,目标显示待确认的里程碑数,独立工作流里有步骤在计时也亮小圆点。 -- 任务:图标栏右边是一列清单,有全部、到点待开始(有任务到点时才出现)、进行中、已暂停、接下来、时间待定、今日完成,下面按标签列出,每项后面是任务数。点一项,右边的日程列表就只显示这一类,内容和弹出面板一样。顶部的 + 新建任务(⌘N)。 +- 任务:图标栏右边是一列清单,有全部、到点待开始(有任务到点时才出现)、进行中、已暂停、接下来、时间待定、今日完成,下面按标签列出,每项后面是任务数。点一项,右边的日程列表就只显示这一类,内容和弹出面板一样。顶部的 + 新建任务(⌘N)。任务详情和日程表单在列表右边单独一栏打开,列表照常可以用。在「全部」里,点分区标题(如「已暂停」)可以把这一组收起来,再点展开,折叠状态会记住。 - 目标、工作流:图标栏右边同样有一列列表。目标列表是各个目标和它下面的里程碑,工作流列表是不属于任何目标的工作流。顶部的 + 和底部按钮用来新建(目标 ⌥⌘N,工作流 ⇧⌘N),右边是路线图或工作流画布。 - 分析:没有列表,注意力分析占满右边。 - 工具栏左侧的按钮(⌃⌘S)收起或展开这列列表。收起后只剩图标栏,照样能切换模块。 diff --git a/Sources/ITimer/JournalView.swift b/Sources/ITimer/JournalView.swift index fb4b68a..5cfe4cc 100644 --- a/Sources/ITimer/JournalView.swift +++ b/Sources/ITimer/JournalView.swift @@ -1,43 +1,24 @@ import ITimerCore import SwiftUI -/// Note and comments for one task. Replaces the task list the way the -/// schedule composer does, so the latched popup height never has to grow. +/// Note and comments for one task, the last part of its detail drawer. struct JournalView: View { var task: TaskItem var store: TaskStore var now: Date - var onClose: () -> Void @State private var note: String @State private var draft = "" @FocusState private var commentFocused: Bool - init(task: TaskItem, store: TaskStore, now: Date, onClose: @escaping () -> Void) { + init(task: TaskItem, store: TaskStore, now: Date) { self.task = task self.store = store self.now = now - self.onClose = onClose _note = State(initialValue: task.note) } var body: some View { VStack(alignment: .leading, spacing: 12) { - HStack(alignment: .firstTextBaseline) { - VStack(alignment: .leading, spacing: 1) { - Text(task.title) - .font(.headline) - .lineLimit(1) - Text(subtitle) - .font(.caption) - .foregroundStyle(.secondary) - } - Spacer() - Button("完成", action: close) - .buttonStyle(.borderedProminent) - .controlSize(.small) - .accessibilityIdentifier("journal-close") - } - noteField Text("进展") @@ -58,13 +39,6 @@ struct JournalView: View { .onDisappear(perform: commitNote) } - private var subtitle: String { - var parts: [String] = [] - if !task.tags.isEmpty { parts.append(task.tags.map { "#\($0)" }.joined(separator: " ")) } - parts.append(task.isRunning ? "计时中" : task.isPending ? "未开始" : task.isCompleted ? "已完成" : "已暂停") - return parts.joined(separator: " · ") - } - private var noteField: some View { VStack(alignment: .leading, spacing: 4) { Text("备注") @@ -169,9 +143,4 @@ struct JournalView: View { draft = "" commentFocused = true } - - private func close() { - commitNote() - onClose() - } } diff --git a/Sources/ITimer/MainView.swift b/Sources/ITimer/MainView.swift index 3c8e243..22322cb 100644 --- a/Sources/ITimer/MainView.swift +++ b/Sources/ITimer/MainView.swift @@ -159,9 +159,9 @@ struct MainView: View { switch destination { case .tasks: let filter = TaskFilter(raw: taskFilterRaw) + // Caps the list's width itself, so its side drawer can sit at + // the window's right edge. MenuBarView(store: store, embedded: true, filter: filter) - .frame(maxWidth: 760) - .frame(maxWidth: .infinity) .navigationTitle(filter == .all ? "任务" : "任务 › \(filter.title)") case .goals: ContentUnavailableView { diff --git a/Sources/ITimer/MenuBarView.swift b/Sources/ITimer/MenuBarView.swift index 3c53ad2..15c0e5f 100644 --- a/Sources/ITimer/MenuBarView.swift +++ b/Sources/ITimer/MenuBarView.swift @@ -13,9 +13,12 @@ struct MenuBarView: View { @State private var editingID: UUID? @State private var renameDraft = "" @State private var latchedHeight: CGFloat? + /// New schedule being filled in, in the side drawer. @State private var composer: ScheduleDraft? - /// Task whose note and comments fill the panel, like the composer. - @State private var journalID: UUID? + /// Task whose details fill the side drawer. + @State private var detailID: UUID? + /// Details opened to add a subtask: its field takes focus once. + @State private var subtaskFocusID: UUID? /// Completed timing draft, kept stable while the observable clock ticks. @State private var recordToEdit: TaskItem? /// Brain buddy's speech; replaces the verdict line for a few seconds. @@ -27,10 +30,9 @@ struct MenuBarView: View { @State private var openMenus = 0 /// Parents whose subtasks are folded away, as comma-joined ids. @AppStorage("collapsedParents") private var collapsedParentsRaw = "" - /// Parent whose inline "add subtask" field is open. - @State private var subtaskParentID: UUID? - @State private var subtaskDraft = "" - @FocusState private var subtaskFocused: Bool + /// Sections folded on the main window's 全部 page, as comma-joined + /// keys ("paused", "doneToday", …). + @AppStorage("collapsedSections") private var collapsedSectionsRaw = "" var body: some View { // While the panel is open the status label is frozen and the store @@ -38,7 +40,7 @@ struct MenuBarView: View { // panel's own timers stay live without touching the label. // Paused while a context menu is open; resumes on close. TimelineView(SecondTicks(paused: openMenus > 0)) { context in - content(now: max(context.date, store.now)) + layout(now: max(context.date, store.now)) } .onReceive(NotificationCenter.default.publisher(for: NSMenu.didBeginTrackingNotification)) { _ in openMenus += 1 @@ -46,7 +48,6 @@ struct MenuBarView: View { .onReceive(NotificationCenter.default.publisher(for: NSMenu.didEndTrackingNotification)) { _ in openMenus = max(0, openMenus - 1) } - .padding(embedded ? 18 : 16) // Height is latched while the panel is open: MenuBarExtra windows // resize unreliably mid-interaction (observed as broken layout after // completing a task). Recomputed next time the panel opens. @@ -106,7 +107,7 @@ struct MenuBarView: View { .onReceive(NotificationCenter.default.publisher(for: .iTimerPanelClosed)) { _ in // Reopening the panel should show the list, not a stale form. guard !embedded else { return } - composer = nil + closeDrawer() recordToEdit = nil // onDisappear rarely fires here, so release the latch now or the // next open keeps a stale height (e.g. after adding schedules). @@ -114,6 +115,78 @@ struct MenuBarView: View { } } + /// The list, with the side drawer to its right: a column of its own in + /// the main window, sliding over the list in the fixed-width panel. + @ViewBuilder + private func layout(now: Date) -> some View { + if embedded { + HStack(spacing: 0) { + content(now: now) + .padding(18) + .frame(maxWidth: 760) + .frame(maxWidth: .infinity) + if drawerOpen { + HStack(spacing: 0) { + Divider() + drawer(now: now) + } + .transition(.move(edge: .trailing)) + } + } + } else { + content(now: now) + .padding(16) + .overlay(alignment: .trailing) { + ZStack(alignment: .trailing) { + if drawerOpen { + // The strip of list left showing closes it. + Color.black.opacity(0.18) + .contentShape(Rectangle()) + .onTapGesture(perform: closeDrawer) + .accessibilityIdentifier("drawer-scrim") + .transition(.opacity) + drawer(now: now) + .shadow(color: .black.opacity(0.18), radius: 10, x: -2) + .transition(.move(edge: .trailing)) + } + } + } + } + } + + private var detailTask: TaskItem? { + detailID.flatMap { id in store.tasks.first { $0.id == id } } + } + + private var drawerOpen: Bool { composer != nil || detailTask != nil } + + @ViewBuilder + private func drawer(now: Date) -> some View { + if composer != nil { + SideDrawer(title: "新建日程", onClose: closeDrawer) { + ScheduleComposer( + draft: composerBinding, + now: now, + onSave: saveComposer, + onStartNow: startComposerNow + ) + } + } else if let task = detailTask { + SideDrawer(title: "任务详情", onClose: closeDrawer) { + TaskDetailView( + task: task, + store: store, + now: now, + onOpen: { openDetail($0) }, + focusSubtask: subtaskFocusID == task.id, + onSubtaskFocused: { subtaskFocusID = nil }, + onSubtaskAdded: { unfoldSubtasks(of: task.id) } + ) + .id(task.id) + } + } + } + private func content(now: Date) -> some View { let today = ReportCache.shared.report(store: store, range: .today) return VStack(alignment: .leading, spacing: 14) { @@ -131,28 +204,6 @@ struct MenuBarView: View { } .scrollIndicators(.never) .frame(maxHeight: .infinity, alignment: .top) - } else if let journalID, let task = store.tasks.first(where: { $0.id == journalID }) { - ScrollView { - JournalView(task: task, store: store, now: now) { self.journalID = nil } - .padding(1) - } - .scrollIndicators(.never) - .frame(maxHeight: .infinity, alignment: .top) - } else if composer != nil { - // Takes the hero + list + input space so the latched popup - // height never has to grow while the panel is open. - ScrollView { - ScheduleComposer( - draft: composerBinding, - now: now, - onSave: saveComposer, - onStartNow: startComposerNow, - onCancel: { composer = nil } - ) - .padding(1) - } - .scrollIndicators(.never) - .frame(maxHeight: .infinity, alignment: .top) } else { hero(now: now, today: today) taskList(now: now) @@ -182,8 +233,8 @@ struct MenuBarView: View { let listHeight: CGFloat = open + done == 0 ? 58 : min(rows, 380) let suggestions: CGFloat = store.suggestions(limit: 1).isEmpty ? 0 : 32 let note: CGFloat = heroNote(now: store.now) == nil ? 0 : 18 - // The floor leaves room for the schedule composer, which replaces - // hero + list without resizing the panel. + // The floor leaves room for the side drawer and the record editor, + // which cover or replace hero + list without resizing the panel. return max(366 + listHeight + suggestions + note, 500) } @@ -425,18 +476,21 @@ struct MenuBarView: View { ScrollView { VStack(alignment: .leading, spacing: 2) { ForEach(sections) { section in - sectionTitle(section.kind.title, count: section.count, tint: section.kind.tint) - ForEach(section.groups) { group in - groupRows(group, now: now) + sectionTitle(section.kind.title, count: section.count, tint: section.kind.tint, fold: section.kind.key) + if !isFolded(section.kind.key) { + ForEach(section.groups) { group in + groupRows(group, now: now) + } } } if !done.isEmpty { - sectionTitle("今日完成", count: done.count) - ForEach(nestedEntries(done)) { entry in + sectionTitle("今日完成", count: done.count, fold: Self.doneKey) + ForEach(isFolded(Self.doneKey) ? [] : nestedEntries(done)) { entry in DoneRow( task: entry.task, store: store, - onJournal: { openJournal(entry.task.id) }, + selected: detailID == entry.task.id, + onEdit: { toggleDetail(entry.task.id) }, onEditTime: { openRecordEditor(entry.task) } ) .draggable(entry.task.id.uuidString) @@ -469,6 +523,35 @@ struct MenuBarView: View { } var tint: Color? { self == .due ? .orange : nil } + + /// Stored fold key; the same words as the 任务 page's filters. + var key: String { + switch self { + case .due: "due" + case .running: "running" + case .paused: "paused" + case .upcoming: "upcoming" + case .undated: "undated" + } + } + } + + private static let doneKey = "doneToday" + + /// Only the main window's 全部 page folds sections; elsewhere the list + /// is one section, or the panel, whose height is sized to its rows. + private var foldsSections: Bool { embedded && filter == .all } + + private func isFolded(_ key: String) -> Bool { + foldsSections && collapsedSectionsRaw.split(separator: ",").contains { $0 == key } + } + + private func toggleSection(_ key: String) { + var folded = Set(collapsedSectionsRaw.split(separator: ",").map(String.init)) + if !folded.insert(key).inserted { folded.remove(key) } + withAnimation(.easeOut(duration: 0.15)) { + collapsedSectionsRaw = folded.sorted().joined(separator: ",") + } } /// A parent with its open subtasks, or a task on its own. @@ -523,8 +606,7 @@ struct MenuBarView: View { } } - /// The parent row, its subtasks indented under it unless folded, and - /// the open "add subtask" field last. + /// The parent row and its subtasks indented under it unless folded. private func groupRows(_ group: TaskGroup, now: Date) -> some View { VStack(alignment: .leading, spacing: 2) { // Draggable onto a workflow canvas in the main window. @@ -535,9 +617,6 @@ struct MenuBarView: View { .draggable(child.id.uuidString) .padding(.leading, 18) } - if subtaskParentID == group.head.id { - subtaskField(group.head) - } } } @@ -553,6 +632,12 @@ struct MenuBarView: View { collapsedParentsRaw = folded.map(\.uuidString).sorted().joined(separator: ",") } + /// Adding a subtask shows the parent's subtasks again. + private func unfoldSubtasks(of parentID: UUID) { + guard collapsedParents.contains(parentID) else { return } + withAnimation(.easeOut(duration: 0.15)) { setSubtasks(of: parentID, collapsed: false) } + } + /// A subtask hidden under its folded parent. Once the parent is done /// (it has no toggle there) its subtasks show again. private func isFoldedAway(_ task: TaskItem) -> Bool { @@ -581,63 +666,6 @@ struct MenuBarView: View { return entries } - /// Inline field under a parent. Each Return adds one step (time to be - /// decided, not started) and keeps the field open for the next. - private func subtaskField(_ parent: TaskItem) -> some View { - HStack(spacing: 6) { - Image(systemName: "arrow.turn.down.right") - .font(.system(size: 10, weight: .semibold)) - .foregroundStyle(.tertiary) - TextField("「\(parent.title)」的子任务,回车添加", text: $subtaskDraft) - .textFieldStyle(.plain) - .font(.callout) - .focused($subtaskFocused) - .onSubmit { commitSubtask(under: parent.id) } - .onExitCommand(perform: endSubtask) - .onChange(of: subtaskFocused) { _, focused in - if !focused && subtaskDraft.trimmingCharacters(in: .whitespaces).isEmpty { endSubtask() } - } - .accessibilityIdentifier("subtask-input-\(parent.id.uuidString)") - } - .padding(.leading, 28) - .padding(.trailing, 8) - .padding(.vertical, 6) - .background(Theme.focused.opacity(0.07), in: RoundedRectangle(cornerRadius: 7, style: .continuous)) - } - - private func beginSubtask(under parentID: UUID) { - composer = nil - journalID = nil - recordToEdit = nil - editingID = nil - subtaskDraft = "" - subtaskParentID = parentID - subtaskFocused = true - if collapsedParents.contains(parentID) { - withAnimation(.easeOut(duration: 0.15)) { setSubtasks(of: parentID, collapsed: false) } - } - } - - private func commitSubtask(under parentID: UUID) { - guard store.addSchedule( - title: subtaskDraft, - parentID: parentID, - start: nil, - plannedDuration: nil, - reminderLead: nil - ) != nil else { - if subtaskDraft.trimmingCharacters(in: .whitespaces).isEmpty { endSubtask() } - return - } - subtaskDraft = "" - subtaskFocused = true - } - - private func endSubtask() { - subtaskDraft = "" - subtaskParentID = nil - } - private func row(_ task: TaskItem, now: Date, nested: Bool = false) -> some View { TaskRow( task: task, @@ -646,9 +674,9 @@ struct MenuBarView: View { nested: nested, editingID: $editingID, renameDraft: $renameDraft, - onEdit: { composer = .editing(task, asOf: now) }, - onAddSubtask: { beginSubtask(under: task.id) }, - onJournal: { openJournal(task.id) }, + selected: detailID == task.id, + onEdit: { toggleDetail(task.id) }, + onAddSubtask: { openDetail(task.id, addingSubtask: true) }, subtasksCollapsed: collapsedParents.contains(task.id), onToggleSubtasks: { let folded = collapsedParents.contains(task.id) @@ -657,8 +685,35 @@ struct MenuBarView: View { ) } - private func sectionTitle(_ title: String, count: Int, tint: Color? = nil) -> some View { + /// With a fold key on the 全部 page, the whole title row folds and + /// unfolds its section. + @ViewBuilder + private func sectionTitle(_ title: String, count: Int, tint: Color? = nil, fold key: String? = nil) -> some View { + if let key, foldsSections { + let folded = isFolded(key) + Button { toggleSection(key) } label: { + sectionLabel(title, count: count, tint: tint, folded: folded) + .frame(maxWidth: .infinity, alignment: .leading) + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .help(folded ? "展开「\(title)」" : "折叠「\(title)」") + .accessibilityLabel(folded ? "展开\(title)" : "折叠\(title)") + .accessibilityIdentifier("toggle-section-\(key)") + } else { + sectionLabel(title, count: count, tint: tint, folded: nil) + } + } + + /// `folded` nil = the section cannot fold, so no chevron. + private func sectionLabel(_ title: String, count: Int, tint: Color?, folded: Bool?) -> some View { HStack(spacing: 4) { + if let folded { + Image(systemName: "chevron.right") + .font(.system(size: 8, weight: .bold)) + .foregroundStyle(tint.map { AnyShapeStyle($0) } ?? AnyShapeStyle(.secondary)) + .rotationEffect(.degrees(folded ? 0 : 90)) + } Text(title) .foregroundStyle(tint.map { AnyShapeStyle($0) } ?? AnyShapeStyle(.secondary)) Text("\(count)") @@ -862,55 +917,71 @@ struct MenuBarView: View { /// Whatever is typed in the quick field becomes the schedule's name. private func openComposer() { - journalID = nil recordToEdit = nil - composer = .new(title: draft, asOf: store.now) - draft = "" editingID = nil + withAnimation(.easeOut(duration: 0.2)) { + detailID = nil + composer = .new(title: draft, asOf: store.now) + } + draft = "" } - private func openJournal(_ id: UUID) { - composer = nil + /// Shows the task's details in the drawer, replacing whatever it held. + private func openDetail(_ id: UUID, addingSubtask: Bool = false) { recordToEdit = nil editingID = nil - journalID = id + subtaskFocusID = addingSubtask ? id : nil + if addingSubtask { unfoldSubtasks(of: id) } + withAnimation(.easeOut(duration: 0.2)) { + composer = nil + detailID = id + } + } + + /// A row's edit button: opens its details, or closes them when they + /// are already showing. + private func toggleDetail(_ id: UUID) { + if detailID == id { + closeDrawer() + } else { + openDetail(id) + } + } + + private func closeDrawer() { + subtaskFocusID = nil + withAnimation(.easeOut(duration: 0.2)) { + composer = nil + detailID = nil + } } private func openRecordEditor(_ task: TaskItem) { - composer = nil - journalID = nil + closeDrawer() editingID = nil - endSubtask() recordToEdit = task } private var composerBinding: Binding { Binding( get: { composer ?? .new(asOf: store.now) }, - set: { composer = $0 } + // The focused name field commits as the drawer slides away; + // that write must not bring the drawer back. + set: { if composer != nil { composer = $0 } } ) } private func saveComposer() { guard let value = composer, value.titleValid else { return } - let labels = value.resolved - if let id = value.editingID { - if store.tasks.first(where: { $0.id == id })?.title != labels.title { - store.rename(id: id, title: labels.title) - } - store.setTags(id: id, labels.tags) - store.updateSchedule(id: id, start: value.scheduledStart, plannedDuration: value.duration, reminderLead: value.reminderLead) - } else { - guard store.addSchedule( - title: value.title, - tags: value.tags, - parentID: value.parentID, - start: value.scheduledStart, - plannedDuration: value.duration, - reminderLead: value.reminderLead - ) != nil else { return } - } - composer = nil + guard store.addSchedule( + title: value.title, + tags: value.tags, + parentID: value.parentID, + start: value.scheduledStart, + plannedDuration: value.duration, + reminderLead: value.reminderLead + ) != nil else { return } + closeDrawer() } /// Same as adding, but timing starts right away instead of at a set time. @@ -925,7 +996,7 @@ struct MenuBarView: View { reminderLead: value.reminderLead ) else { return } store.resume(id: task.id) - composer = nil + closeDrawer() } private func revealMain() { @@ -952,12 +1023,12 @@ struct TaskRow: View { var nested = false @Binding var editingID: UUID? @Binding var renameDraft: String - /// Opens the schedule composer for this item (time, estimate, reminder). + /// Its details are open in the side drawer. + var selected = false + /// Opens (or closes) its details: schedule, subtasks, note and progress. var onEdit: () -> Void = {} - /// Opens the composer as a new subtask of this row. + /// Opens its details with the add-subtask field focused. var onAddSubtask: () -> Void = {} - /// Opens the note and comments for this row. - var onJournal: () -> Void = {} /// The subtasks are folded away under this row. var subtasksCollapsed = false /// Folds or unfolds the subtasks; nil where they are not nested. @@ -1007,6 +1078,9 @@ struct TaskRow: View { ForEach(task.tags, id: \.self) { tag in TagPill(tag: tag) } + if task.hasJournal { + JournalMark(hint: journalHint) + } Text(subtitle) .font(.caption.monospacedDigit()) .foregroundStyle(subtitleWarns ? AnyShapeStyle(Color.orange) : AnyShapeStyle(.secondary)) @@ -1030,6 +1104,12 @@ struct TaskRow: View { RoundedRectangle(cornerRadius: 10, style: .continuous) .fill(isDue ? Color.orange.opacity(hovering ? 0.12 : 0.07) : Color.primary.opacity(hovering ? 0.05 : 0)) ) + .overlay { + if selected { + RoundedRectangle(cornerRadius: 10, style: .continuous) + .strokeBorder(Theme.focused.opacity(0.55), lineWidth: 1) + } + } .contentShape(Rectangle()) .onHover { inside in // The open menu covers the row; a hover flip would rebuild it. @@ -1174,20 +1254,11 @@ struct TaskRow: View { commitRename() } } else { - if task.isRoot { - IconButton(title: "添加子任务", systemImage: "text.badge.plus", identifier: "add-subtask-\(task.id.uuidString)", action: onAddSubtask) - } - IconButton( - title: journalHint, - systemImage: task.hasJournal ? "text.bubble.fill" : "text.bubble", - tint: task.hasJournal ? Theme.focused : .primary, - identifier: "journal-\(task.id.uuidString)", - action: onJournal - ) IconButton( - title: task.isUndated ? "编辑:定个时间、预计时长、标签" : task.isPending ? "编辑:名称、时间、预计时长、提醒、标签" : "编辑:名称、预计时长、提醒、标签", + title: task.isRoot ? "编辑:日程、子任务、备注和进展" : "编辑:日程、备注和进展", systemImage: "slider.horizontal.3", - identifier: "edit-schedule-\(task.id.uuidString)", + tint: selected ? Theme.focused : .primary, + identifier: "edit-task-\(task.id.uuidString)", action: onEdit ) } @@ -1263,18 +1334,18 @@ struct TaskRow: View { Button("完成") { store.complete(id: task.id) } } Divider() - Button(journalHint, action: onJournal) if let onToggleSubtasks, !store.subtasks(of: task.id).isEmpty { Button(subtasksCollapsed ? "展开子任务" : "折叠子任务", action: onToggleSubtasks) } if task.isRoot { - LabelMenus(task: task, store: store, onEditLabels: beginLabelEdit, onAddSubtask: beginSubtask) + LabelMenus(task: task, store: store, onEditLabels: beginLabelEdit, onAddSubtask: onAddSubtask) } else { LabelMenus(task: task, store: store, onEditLabels: beginLabelEdit) } WorkflowMenu(task: task, store: store) Divider() - Button(task.isPending ? "编辑日程…" : "编辑预计与提醒…", action: onEdit) + // Opens only; the row's button also closes what is already open. + Button("编辑…") { if !selected { onEdit() } } Button("改名", action: beginRename) Button("删除", role: .destructive) { store.delete(id: task.id) } } @@ -1298,23 +1369,13 @@ struct TaskRow: View { return children == 0 ? "再点一次删除" : "再点一次删除(连同 \(children) 个子任务)" } - private var journalHint: String { - if !task.note.isEmpty && !task.comments.isEmpty { return "备注和 \(task.comments.count) 条进展" } - if !task.comments.isEmpty { return "\(task.comments.count) 条进展" } - if !task.note.isEmpty { return "有备注" } - return "备注和进展" - } + private var journalHint: String { JournalMark.hint(for: task) } private func commitRename() { if store.retitle(id: task.id, input: renameDraft) { editingID = nil } } - - /// Opens the composer as a new subtask of this row. - private func beginSubtask() { - onAddSubtask() - } } /// Thin progress line against the estimate; past 100% it turns orange and @@ -1349,7 +1410,10 @@ private struct PlanBar: View { struct DoneRow: View { var task: TaskItem var store: TaskStore - var onJournal: () -> Void = {} + /// Its details are open in the side drawer. + var selected = false + /// Opens (or closes) its details: name, tags, note and progress. + var onEdit: () -> Void = {} var onEditTime: () -> Void = {} @State private var hovering = false @@ -1363,11 +1427,20 @@ struct DoneRow: View { .font(.callout) .foregroundStyle(.primary.opacity(0.7)) .lineLimit(1) + if task.hasJournal { + JournalMark(hint: JournalMark.hint(for: task)) + } Spacer(minLength: 6) Text(DurationFormat.prose(task.duration(asOf: store.now))) .font(.callout.weight(.medium).monospacedDigit()) .foregroundStyle(.secondary) - IconButton(title: "备注和进展", systemImage: task.hasJournal ? "text.bubble.fill" : "text.bubble", tint: task.hasJournal ? Theme.focused : .primary, identifier: "journal-\(task.id.uuidString)", action: onJournal) + IconButton( + title: "编辑:名称、标签、备注和进展", + systemImage: "slider.horizontal.3", + tint: selected ? Theme.focused : .primary, + identifier: "edit-task-\(task.id.uuidString)", + action: onEdit + ) IconButton(title: "修改计时时间", systemImage: "pencil", identifier: "edit-record-time-\(task.id.uuidString)", action: onEditTime) .disabled(task.segments.isEmpty) IconButton(title: "再来一段", systemImage: "arrow.counterclockwise", identifier: "again-\(task.id.uuidString)") { @@ -1381,6 +1454,12 @@ struct DoneRow: View { RoundedRectangle(cornerRadius: 8, style: .continuous) .fill(Color.primary.opacity(hovering ? 0.05 : 0)) ) + .overlay { + if selected { + RoundedRectangle(cornerRadius: 8, style: .continuous) + .strokeBorder(Theme.focused.opacity(0.55), lineWidth: 1) + } + } .contentShape(Rectangle()) .onHover { inside in guard !MenuTracking.isOpen else { return } @@ -1388,7 +1467,7 @@ struct DoneRow: View { } .contextMenu { Button("再来一段") { store.resume(id: task.id) } - Button("备注和进展", action: onJournal) + Button("编辑…") { if !selected { onEdit() } } Button("修改计时时间…", action: onEditTime) .disabled(task.segments.isEmpty) Divider() @@ -1396,10 +1475,31 @@ struct DoneRow: View { Divider() Button("删除", role: .destructive) { store.delete(id: task.id) } } + // Keeps the buttons' own identifiers instead of the row's. + .accessibilityElement(children: .contain) .accessibilityIdentifier("done-row-\(task.id.uuidString)") } } +/// On a row: the task has a note or progress, kept in its details. +struct JournalMark: View { + var hint: String + + var body: some View { + Image(systemName: "text.bubble.fill") + .font(.system(size: 9)) + .foregroundStyle(Theme.focused.opacity(0.8)) + .help(hint) + .accessibilityLabel(hint) + } + + static func hint(for task: TaskItem) -> String { + if !task.note.isEmpty && !task.comments.isEmpty { return "有备注和 \(task.comments.count) 条进展" } + if !task.comments.isEmpty { return "有 \(task.comments.count) 条进展" } + return "有备注" + } +} + /// Soft fade on one edge so scrolled-off content reads as "more", not "cut". struct EdgeFade: View { var edge: Edge diff --git a/Sources/ITimer/ScheduleComposer.swift b/Sources/ITimer/ScheduleComposer.swift index 209dd63..eaf553d 100644 --- a/Sources/ITimer/ScheduleComposer.swift +++ b/Sources/ITimer/ScheduleComposer.swift @@ -7,6 +7,9 @@ struct ScheduleDraft: Equatable { var title: String = "" /// Start can only change before the item has been started. var startEditable = true + /// Estimate and reminder only mean something until the task is done; + /// a finished one keeps just its name and tags editable. + var scheduleEditable = true var start: Date /// false = time to be decided (时间待定); `start` is kept so switching /// back restores the last picked slot. @@ -33,6 +36,7 @@ struct ScheduleDraft: Equatable { editingID: task.id, title: task.title, startEditable: task.isPending, + scheduleEditable: !task.isCompleted, start: task.scheduledStart ?? (task.isPending ? ScheduleOptions.suggestedStart(after: now) : now), hasTime: !task.isUndated, duration: task.plannedDuration, @@ -59,15 +63,18 @@ struct ScheduleDraft: Equatable { } } -/// Inline form for creating or editing a schedule. Deliberately built from -/// plain buttons and a field-style time picker: popover/menu pickers steal -/// focus and make the MenuBarExtra panel dismiss itself. +/// Form for creating or editing a schedule, shown in the side drawer. +/// Deliberately built from plain buttons and a field-style time picker: +/// popover/menu pickers steal focus and make the MenuBarExtra panel +/// dismiss itself. A new schedule ends in 添加日程 / 现在就开始; an edit has +/// no buttons — the task details save it as it changes. struct ScheduleComposer: View { @Binding var draft: ScheduleDraft var now: Date + /// New: adds the schedule. Editing: saves now (Return in the name). var onSave: () -> Void - var onStartNow: () -> Void - var onCancel: () -> Void + /// New only: adds it and starts timing right away. + var onStartNow: () -> Void = {} var knownTags: [String] = TaskStore.shared.knownTags @FocusState private var titleFocused: Bool /// Inline day list. Not a Menu/Picker: those take focus and the @@ -81,28 +88,24 @@ struct ScheduleComposer: View { var body: some View { VStack(alignment: .leading, spacing: 12) { - HStack(alignment: .firstTextBaseline) { - Text(isNew ? "新建日程" : "编辑日程") - .font(.headline) - Spacer() - Button("取消", action: onCancel) - .buttonStyle(.plain) - .font(.callout) - .foregroundStyle(.secondary) - .accessibilityIdentifier("schedule-cancel") - } titleField form - Text(summary) - .font(.caption) - .foregroundStyle(.secondary) - .lineLimit(1) - .accessibilityIdentifier("schedule-summary") - actions + if draft.scheduleEditable { + Text(summary) + .font(.caption) + .foregroundStyle(.secondary) + .lineLimit(1) + .accessibilityIdentifier("schedule-summary") + } + if isNew { + actions + } } .accessibilityElement(children: .contain) .accessibilityIdentifier("schedule-composer") .onAppear { + // An edit opens without focus: a stray key would replace the name. + guard isNew else { return } DispatchQueue.main.async { titleFocused = true } } } @@ -110,7 +113,7 @@ struct ScheduleComposer: View { // MARK: title private var titleField: some View { - TextField("日程名称", text: $draft.title) + TextField(isNew ? "日程名称" : "任务名称", text: $draft.title) .textFieldStyle(.plain) .font(.title3) .focused($titleFocused) @@ -129,35 +132,37 @@ struct ScheduleComposer: View { private var form: some View { VStack(spacing: 0) { - if draft.startEditable { - row("日期") { dayRow } - if dayListOpen { - dayList - } - divider - if draft.hasTime { - row("时间") { timeControls } + if draft.scheduleEditable { + if draft.startEditable { + row("日期") { dayRow } + if dayListOpen { + dayList + } divider + if draft.hasTime { + row("时间") { timeControls } + divider + } } - } - row("预计") { - SegmentBar( - options: ScheduleOptions.durations.map { (Self.shortDuration($0), Optional($0)) } + [("不定", nil)], - selection: $draft.duration - ) - .accessibilityIdentifier("schedule-duration") - } - if draft.hasTime || !draft.startEditable { - divider - row("提醒") { + row("预计") { SegmentBar( - options: ScheduleOptions.reminderLeads.map { (Self.shortReminder($0), $0) }, - selection: $draft.reminderLead + options: ScheduleOptions.durations.map { (Self.shortDuration($0), Optional($0)) } + [("不定", nil)], + selection: $draft.duration ) - .accessibilityIdentifier("schedule-reminder") + .accessibilityIdentifier("schedule-duration") + } + if draft.hasTime || !draft.startEditable { + divider + row("提醒") { + SegmentBar( + options: ScheduleOptions.reminderLeads.map { (Self.shortReminder($0), $0) }, + selection: $draft.reminderLead + ) + .accessibilityIdentifier("schedule-reminder") + } } + divider } - divider row("标签") { TagEditor(tags: $draft.tags, known: knownTags) } @@ -354,18 +359,16 @@ struct ScheduleComposer: View { private var actions: some View { HStack(spacing: 8) { - if isNew { - Button(action: onStartNow) { - Label("现在就开始", systemImage: "play.fill") - } - .buttonStyle(ActionButtonStyle()) - .disabled(!draft.titleValid) - .help("跳过排期,按这个预计时长立即计时") - .accessibilityIdentifier("schedule-start-now") + Button(action: onStartNow) { + Label("现在就开始", systemImage: "play.fill") } + .buttonStyle(ActionButtonStyle()) + .disabled(!draft.titleValid) + .help("跳过排期,按这个预计时长立即计时") + .accessibilityIdentifier("schedule-start-now") Spacer() Button(action: onSave) { - Label(isNew ? "添加日程" : "保存", systemImage: isNew ? "plus" : "checkmark") + Label("添加日程", systemImage: "plus") } .buttonStyle(ActionButtonStyle(prominent: true)) .disabled(!draft.titleValid) diff --git a/Sources/ITimer/SelfTest.swift b/Sources/ITimer/SelfTest.swift index b13c3de..6ac71f1 100644 --- a/Sources/ITimer/SelfTest.swift +++ b/Sources/ITimer/SelfTest.swift @@ -21,6 +21,7 @@ enum SelfTest { case "goal-search": passed = await exerciseGoalSearch() case "milestone": passed = await exerciseMilestoneExpansion() case "record": passed = await exerciseRecordTimes() + case "drawer": passed = await exerciseDrawer() default: passed = await exercise() } note(passed ? "PASS" : "FAIL") @@ -295,57 +296,61 @@ enum SelfTest { render(MenuBarView(store: store), size: NSSize(width: 380, height: 640), to: "/tmp/itimer-schedule-popup.png") var draft = ScheduleDraft.new(title: "准备季度汇报 #汇报 #PPT", asOf: now) render( - ScheduleComposer( - draft: Binding(get: { draft }, set: { draft = $0 }), - now: now, - onSave: {}, onStartNow: {}, onCancel: {} - ) - .padding(16), - size: NSSize(width: 380, height: 520), + SideDrawer(title: "新建日程", onClose: {}) { + ScheduleComposer( + draft: Binding(get: { draft }, set: { draft = $0 }), + now: now, + onSave: {} + ) + }, + size: NSSize(width: SideDrawer.width, height: 570), to: "/tmp/itimer-composer.png" ) render( - ScheduleComposer( - draft: Binding(get: { draft }, set: { draft = $0 }), - now: now, - onSave: {}, onStartNow: {}, onCancel: {}, - dayListOpen: true - ) - .padding(16), - size: NSSize(width: 380, height: 720), + SideDrawer(title: "新建日程", onClose: {}) { + ScheduleComposer( + draft: Binding(get: { draft }, set: { draft = $0 }), + now: now, + onSave: {}, + dayListOpen: true + ) + }, + size: NSSize(width: SideDrawer.width, height: 770), to: "/tmp/itimer-composer-days.png" ) var far = ScheduleDraft.new(title: "续签合同", asOf: now) far.start = Calendar.current.date(byAdding: .month, value: 5, to: far.start) ?? far.start render( - ScheduleComposer( - draft: Binding(get: { far }, set: { far = $0 }), - now: now, - onSave: {}, onStartNow: {}, onCancel: {}, - dayListOpen: true - ) - .padding(16), - size: NSSize(width: 380, height: 720), + SideDrawer(title: "新建日程", onClose: {}) { + ScheduleComposer( + draft: Binding(get: { far }, set: { far = $0 }), + now: now, + onSave: {}, + dayListOpen: true + ) + }, + size: NSSize(width: SideDrawer.width, height: 770), to: "/tmp/itimer-composer-far.png" ) var pending = ScheduleDraft.new(title: "接入 AI #想法", asOf: now) pending.hasTime = false render( - ScheduleComposer( - draft: Binding(get: { pending }, set: { pending = $0 }), - now: now, - onSave: {}, onStartNow: {}, onCancel: {} - ) - .padding(16), - size: NSSize(width: 380, height: 460), + SideDrawer(title: "新建日程", onClose: {}) { + ScheduleComposer( + draft: Binding(get: { pending }, set: { pending = $0 }), + now: now, + onSave: {} + ) + }, + size: NSSize(width: SideDrawer.width, height: 510), to: "/tmp/itimer-composer-undated.png" ) guard let child = store.addSubtask(parentID: review.id, title: "看完鉴权模块") else { note("subtask failed") return false } - // The row's "add subtask" field: undated, and shown in the parent's - // progress count. + // The details drawer's "add subtask" field: undated, and shown in the + // parent's progress count. guard let step = store.addSchedule(title: "补单测 #测试", parentID: review.id, start: nil, plannedDuration: nil, reminderLead: nil), step.isUndated, step.parentID == review.id, step.tags == ["测试"], store.subtasks(of: review.id).count == 2 else { @@ -720,6 +725,226 @@ enum SelfTest { } } +// MARK: - Side drawer + +extension SelfTest { + /// The task list's side drawer: a row's edit button opens its details + /// beside the list (main window) or over it (panel); name, subtasks and + /// progress are edited there; rows carry no note or subtask buttons. + /// Window events only, so it also runs in background mode. + static func exerciseDrawer() async -> Bool { + let store = TaskStore.shared + let now = Date() + guard let parent = store.addSchedule(title: "准备季度汇报 #汇报", start: now.addingTimeInterval(3 * 3600), plannedDuration: 3600, reminderLead: nil), + let step = store.addSchedule(title: "收集数据", parentID: parent.id, start: nil, plannedDuration: nil, reminderLead: nil), + let running = store.addTask(title: "回消息 #沟通", at: now.addingTimeInterval(-1500)), + let done = store.addTask(title: "整理周报", at: now.addingTimeInterval(-3600)) else { + note("drawer fixture could not be created") + return false + } + store.complete(id: done.id, at: now.addingTimeInterval(-600)) + store.setNote(id: parent.id, "先对齐口径,再出图。") + store.addComment(id: parent.id, text: "数据源确认完毕", at: now.addingTimeInterval(-900)) + + NSApp.windows.filter { $0.identifier?.rawValue.hasPrefix("main") == true }.forEach { $0.orderOut(nil) } + let window = NSWindow(contentRect: NSRect(x: 120, y: 120, width: 980, height: 700), styleMask: [.titled], backing: .buffered, defer: false) + window.title = "iTimer 侧边抽屉自检" + window.isReleasedWhenClosed = false + window.appearance = NSAppearance(named: .aqua) + window.contentView = NSHostingView(rootView: MenuBarView(store: store, embedded: true).background(Theme.canvas)) + await activateUnlessBackground() + bringForward(window) + defer { window.orderOut(nil) } + try? await Task.sleep(for: .milliseconds(600)) + + func present(_ identifier: String) -> Bool { find(identifier: identifier, depth: 40) != nil } + func press(_ identifier: String) -> Bool { + guard let element = find(identifier: identifier, depth: 40) else { + note("missing \(identifier)") + return false + } + return AXUIElementPerformAction(element, kAXPressAction as CFString) == .success + } + /// Clicks a text field and returns its field editor once it has focus. + func focusField(_ identifier: String, in window: NSWindow, holding text: String) async -> NSTextView? { + guard let element = find(identifier: identifier, depth: 40), let center = screenCenter(of: element) else { + note("missing field \(identifier)") + return nil + } + await click(in: window, at: window.convertPoint(fromScreen: center)) + guard await wait(for: 2, label: "focus \(identifier)", until: { + (window.firstResponder as? NSTextView)?.string == text + }) else { return nil } + return window.firstResponder as? NSTextView + } + let id = { (task: TaskItem) in task.id.uuidString } + + guard present("edit-task-\(id(parent))"), present("edit-task-\(id(done))"), + !present("journal-\(id(parent))"), !present("add-subtask-\(id(parent))"), + !present("journal-\(id(done))") else { + note("rows still carry note or subtask buttons, or lack the edit button: edit=\(present("edit-task-\(id(parent))")) doneEdit=\(present("edit-task-\(id(done))")) row=\(present("task-row-\(id(parent))")) panel=\(present("menu-panel")) windows=\(windowSummary())") + return false + } + note("rows offer the edit button only") + + // 全部 folds a section from its title and remembers it; the app's + // defaults are the user's, so put them back after. + let defaults = UserDefaults.standard + let savedSections = defaults.string(forKey: "collapsedSections") + defer { defaults.set(savedSections, forKey: "collapsedSections") } + defaults.set("", forKey: "collapsedSections") + try? await Task.sleep(for: .milliseconds(200)) + guard press("toggle-section-upcoming"), + await wait(for: 2, label: "接下来 folded", until: { + !present("task-row-\(id(parent))") && !present("task-row-\(id(step))") + }), + present("task-row-\(id(running))"), + defaults.string(forKey: "collapsedSections") == "upcoming", + press("toggle-section-doneToday"), + await wait(for: 2, label: "今日完成 folded", until: { !present("done-row-\(id(done))") }) else { + note("sections did not fold from their titles: \(defaults.string(forKey: "collapsedSections") ?? "nil")") + return false + } + snapshot(window, to: "/tmp/itimer-sections-folded.png") + guard press("toggle-section-upcoming"), press("toggle-section-doneToday"), + await wait(for: 2, label: "sections unfolded", until: { + present("task-row-\(id(parent))") && present("done-row-\(id(done))") + }), + defaults.string(forKey: "collapsedSections") == "" else { + note("sections did not unfold: \(defaults.string(forKey: "collapsedSections") ?? "nil")") + return false + } + note("全部 folds and unfolds sections from their titles and remembers it") + + guard press("edit-task-\(id(parent))"), + await wait(for: 3, label: "details drawer", until: { present("task-detail") }) else { return false } + try? await Task.sleep(for: .milliseconds(400)) + guard let drawer = find(identifier: "side-drawer", depth: 40).flatMap(screenCenter(of:)), + window.convertPoint(fromScreen: drawer).x > window.frame.width * 0.6, + present("task-row-\(id(running))"), present("journal-note"), present("detail-subtask-\(id(step))") else { + note("details did not open in a right-hand drawer beside the list") + return false + } + snapshot(window, to: "/tmp/itimer-drawer-main.png") + window.appearance = NSAppearance(named: .darkAqua) + try? await Task.sleep(for: .milliseconds(150)) + snapshot(window, to: "/tmp/itimer-drawer-main-dark.png") + window.appearance = NSAppearance(named: .aqua) + note("edit opened the details beside the list: schedule, subtasks, note and progress") + + // The name saves itself after a pause; `#` moves into the tags. + guard let title = await focusField("schedule-title", in: window, holding: parent.title) else { return false } + title.selectAll(nil) + title.insertText("准备年度汇报 #复盘", replacementRange: NSRange(location: NSNotFound, length: 0)) + guard await wait(for: 3, label: "name saved", until: { + store.tasks.first { $0.id == parent.id }.map { $0.title == "准备年度汇报" && $0.tags == ["汇报", "复盘"] } ?? false + }) else { + note("name edit did not save: \(store.tasks.first { $0.id == parent.id }.map { "\($0.title) \($0.tags)" } ?? "gone")") + return false + } + note("name and tags saved from the drawer without a Save button") + + guard let field = await focusField("subtask-input-\(id(parent))", in: window, holding: "") else { return false } + field.insertText("整理图表", replacementRange: NSRange(location: NSNotFound, length: 0)) + await key(in: window, characters: "\r", code: 36) + guard await wait(for: 2, label: "subtask added", until: { + store.subtasks(of: parent.id).contains { $0.title == "整理图表" && $0.isUndated && $0.isPending } + }), await wait(for: 2, label: "field kept", until: { + (window.firstResponder as? NSTextView)?.string == "" + }) else { + note("subtask field did not add an undated step and stay ready") + return false + } + note("subtask added from the drawer; field ready for the next") + + guard press("detail-subtask-\(id(step))"), + await wait(for: 2, label: "subtask details", until: { present("task-detail-parent") }), + press("task-detail-parent"), + await wait(for: 2, label: "parent details", until: { present("subtask-input-\(id(parent))") }) else { + note("could not move between a subtask's and its parent's details") + return false + } + note("drawer moves between a subtask and its parent") + + guard press("edit-task-\(id(parent))"), + await wait(for: 2, label: "toggle closed", until: { !present("side-drawer") }) else { + note("the edit button did not close its own details") + return false + } + guard press("edit-task-\(id(done))"), + await wait(for: 2, label: "done details", until: { present("task-detail") }), + present("schedule-title"), !present("schedule-duration"), !present("subtask-input-\(id(done))") else { + note("finished task details should offer name, tags and journal only") + return false + } + guard press("drawer-close"), + await wait(for: 2, label: "closed", until: { !present("side-drawer") }) else { return false } + note("finished task opens name, tags and journal; close button closes") + window.orderOut(nil) + + // The fixed-width panel: the drawer slides over the list. + let panel = NSWindow(contentRect: NSRect(x: 160, y: 120, width: 380, height: 640), styleMask: [.titled], backing: .buffered, defer: false) + panel.title = "iTimer 面板抽屉自检" + panel.isReleasedWhenClosed = false + panel.appearance = NSAppearance(named: .aqua) + panel.contentView = NSHostingView(rootView: MenuBarView(store: store).background(.regularMaterial)) + bringForward(panel) + defer { panel.orderOut(nil) } + try? await Task.sleep(for: .milliseconds(600)) + guard !present("toggle-section-upcoming") else { + note("the panel should not fold sections") + return false + } + guard press("edit-task-\(id(parent))"), + await wait(for: 3, label: "panel drawer", until: { present("task-detail") && present("drawer-scrim") }) else { + note("panel drawer did not open over the list") + return false + } + try? await Task.sleep(for: .milliseconds(400)) + snapshot(panel, to: "/tmp/itimer-drawer-popup.png") + // The scrim covers 日程, so close first, as a user would. + guard press("drawer-close"), + await wait(for: 2, label: "panel closed", until: { !present("side-drawer") }), + press("new-schedule"), + await wait(for: 3, label: "panel composer", until: { present("schedule-composer") && present("schedule-start-now") }) else { + note("新建日程 did not open in the drawer") + return false + } + try? await Task.sleep(for: .milliseconds(400)) + snapshot(panel, to: "/tmp/itimer-drawer-popup-new.png") + note("panel: details and 新建日程 slide over the list") + + // Closing must stick, and add nothing, while the name field still + // has focus and text: the field commits as it leaves. + let schedules = store.tasks.count + for (way, close) in [("close button", { press("drawer-close") }), ("Esc", { await key(in: panel, characters: "\u{1B}", code: 53); return true })] as [(String, () async -> Bool)] { + if !present("schedule-composer") { + guard press("new-schedule"), + await wait(for: 3, label: "composer again", until: { present("schedule-composer") }) else { return false } + } + guard await wait(for: 2, label: "name focus", until: { panel.firstResponder is NSTextView }), + let name = panel.firstResponder as? NSTextView else { + note("新建日程 did not focus its name field") + return false + } + name.insertText("先不排了", replacementRange: NSRange(location: NSNotFound, length: 0)) + try? await Task.sleep(for: .milliseconds(200)) + guard await close(), + await wait(for: 2, label: "composer closed (\(way))", until: { !present("side-drawer") }) else { + note("新建日程 did not close with the \(way)") + return false + } + try? await Task.sleep(for: .milliseconds(800)) + guard !present("side-drawer"), store.tasks.count == schedules else { + note("新建日程 reopened after closing with the \(way): drawer=\(present("side-drawer")) added=\(store.tasks.count - schedules)") + return false + } + note("新建日程 stays closed after the \(way), nothing added") + } + return true + } +} + // MARK: - Completed record editor extension SelfTest { diff --git a/Sources/ITimer/TaskDrawer.swift b/Sources/ITimer/TaskDrawer.swift new file mode 100644 index 0000000..a15225b --- /dev/null +++ b/Sources/ITimer/TaskDrawer.swift @@ -0,0 +1,335 @@ +import ITimerCore +import SwiftUI + +/// The task list's right-hand drawer: beside the list in the main window, +/// sliding over it in the panel. A title bar with a close button (Esc), +/// the content scrolling below. +struct SideDrawer: View { + static var width: CGFloat { 340 } + + var title: String + var onClose: () -> Void + @ViewBuilder var content: Content + + var body: some View { + VStack(spacing: 0) { + HStack(spacing: 8) { + Text(title) + .font(.headline) + Spacer() + IconButton(title: "关闭(Esc)", systemImage: "xmark", identifier: "drawer-close", action: onClose) + .keyboardShortcut(.cancelAction) + } + .padding(.leading, 16) + .padding(.trailing, 10) + .padding(.vertical, 10) + Divider() + ScrollView { + content + .padding(16) + .frame(maxWidth: .infinity, alignment: .leading) + } + .scrollIndicators(.never) + } + .frame(width: Self.width) + .frame(maxHeight: .infinity, alignment: .top) + .background(Theme.canvas) + .accessibilityElement(children: .contain) + .accessibilityIdentifier("side-drawer") + } +} + +/// Everything about one task, edited in place: name, time, estimate, +/// reminder and tags save themselves after a pause, like the note; subtasks +/// and progress are added right here. +struct TaskDetailView: View { + var task: TaskItem + var store: TaskStore + var now: Date + /// Opens another task's details: a subtask, or the parent. + var onOpen: (UUID) -> Void + /// Opened to add a subtask: the field takes focus, then says so. + var focusSubtask = false + var onSubtaskFocused: () -> Void = {} + var onSubtaskAdded: () -> Void = {} + @State private var draft: ScheduleDraft + /// The draft as last loaded or saved; `draft` differing from it is an + /// edit still waiting to be saved. + @State private var saved: ScheduleDraft + @State private var subtaskDraft = "" + @FocusState private var subtaskFocused: Bool + + init( + task: TaskItem, + store: TaskStore, + now: Date, + onOpen: @escaping (UUID) -> Void, + focusSubtask: Bool = false, + onSubtaskFocused: @escaping () -> Void = {}, + onSubtaskAdded: @escaping () -> Void = {} + ) { + self.task = task + self.store = store + self.now = now + self.onOpen = onOpen + self.focusSubtask = focusSubtask + self.onSubtaskFocused = onSubtaskFocused + self.onSubtaskAdded = onSubtaskAdded + let draft = ScheduleDraft.editing(task, asOf: now) + _draft = State(initialValue: draft) + _saved = State(initialValue: draft) + } + + var body: some View { + VStack(alignment: .leading, spacing: 18) { + status + ScheduleComposer(draft: $draft, now: now, onSave: commit) + if task.isRoot { + subtasks + } + JournalView(task: task, store: store, now: now) + } + .accessibilityElement(children: .contain) + .accessibilityIdentifier("task-detail") + // Each save rewrites the data file and the calendar event, so wait + // for a pause; closing the drawer mid-pause still saves. + .task(id: draft) { + try? await Task.sleep(nanoseconds: 600_000_000) + guard !Task.isCancelled else { return } + commit() + } + .onDisappear(perform: commit) + // Started, postponed, renamed or retagged from the list meanwhile. + .onChange(of: Fields(task)) { _, _ in reload() } + .onAppear { if focusSubtask { takeSubtaskFocus() } } + .onChange(of: focusSubtask) { _, wants in if wants { takeSubtaskFocus() } } + } + + /// What the form shows; a change from elsewhere reloads it. + private struct Fields: Equatable { + var title: String + var tags: [String] + var start: Date? + var duration: TimeInterval? + var reminder: TimeInterval? + var pending: Bool + var completed: Bool + + init(_ task: TaskItem) { + title = task.title + tags = task.tags + start = task.scheduledStart + duration = task.plannedDuration + reminder = task.reminderLead + pending = task.isPending + completed = task.isCompleted + } + } + + // MARK: status + + private var status: some View { + VStack(alignment: .leading, spacing: 4) { + HStack(spacing: 6) { + Circle() + .fill(statusColor) + .frame(width: 6, height: 6) + Text(statusText) + .font(.caption.weight(.medium).monospacedDigit()) + .foregroundStyle(.secondary) + } + .accessibilityElement(children: .combine) + .accessibilityIdentifier("task-detail-status") + if let parent = store.parent(of: task) { + Button { onOpen(parent.id) } label: { + HStack(spacing: 3) { + Text("↳ 属于「\(parent.title)」") + .lineLimit(1) + Image(systemName: "chevron.right") + .font(.system(size: 8, weight: .semibold)) + } + .font(.caption) + .foregroundStyle(.secondary) + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .help("打开「\(parent.title)」的详情") + .accessibilityIdentifier("task-detail-parent") + } + } + } + + private var statusColor: Color { + if task.isRunning { return Theme.focused } + if task.isDue(asOf: now) { return .orange } + return Color.secondary.opacity(task.isCompleted ? 0.4 : 0.7) + } + + private var statusText: String { + let spent = task.duration(asOf: now) + if task.isCompleted { return "已完成 · 共 \(DurationFormat.prose(spent))" } + if task.isRunning { return "计时中 · \(DurationFormat.clock(spent))" } + if !task.isPending { return "已暂停 · 已计 \(DurationFormat.prose(spent))" } + if task.isUndated { return "时间待定" } + return task.isDue(asOf: now) ? "到点待开始" : "未开始" + } + + // MARK: subtasks + + private var subtasks: some View { + let children = store.subtasks(of: task.id) + let finished = children.filter(\.isCompleted).count + return VStack(alignment: .leading, spacing: 6) { + HStack(spacing: 4) { + sectionTitle("子任务") + if !children.isEmpty { + Text("\(finished)/\(children.count)") + .font(.caption2.weight(.medium).monospacedDigit()) + .foregroundStyle(finished == children.count ? AnyShapeStyle(Theme.focused) : AnyShapeStyle(.secondary)) + } + } + if children.isEmpty && task.isCompleted { + Text("没有子任务。") + .font(.caption) + .foregroundStyle(.tertiary) + } + VStack(alignment: .leading, spacing: 2) { + ForEach(children) { child in + subtaskRow(child) + } + } + // A finished task takes no new steps. + if !task.isCompleted { + subtaskField + } + } + } + + private func subtaskRow(_ child: TaskItem) -> some View { + HStack(spacing: 6) { + if child.isCompleted { + Image(systemName: "checkmark.circle.fill") + .font(.system(size: 13)) + .foregroundStyle(Theme.focused.opacity(0.8)) + .frame(width: 22, height: 22) + } else { + IconButton( + title: child.isRunning ? "暂停" : child.isPending ? "开始计时" : "继续", + systemImage: child.isRunning ? "pause.fill" : "play.fill", + tint: Theme.focused, + identifier: "detail-subtask-toggle-\(child.id.uuidString)" + ) { + if child.isRunning { store.pause(id: child.id) } else { store.resume(id: child.id) } + } + } + Button { onOpen(child.id) } label: { + HStack(spacing: 6) { + Text(child.title) + .font(.callout) + .foregroundStyle(child.isCompleted ? AnyShapeStyle(.secondary) : AnyShapeStyle(.primary)) + .lineLimit(1) + Spacer(minLength: 4) + Text(subtaskState(child)) + .font(.caption.monospacedDigit()) + .foregroundStyle(child.isDue(asOf: now) ? AnyShapeStyle(Color.orange) : AnyShapeStyle(.secondary)) + Image(systemName: "chevron.right") + .font(.system(size: 8, weight: .semibold)) + .foregroundStyle(.tertiary) + } + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .help("打开「\(child.title)」的详情") + .accessibilityIdentifier("detail-subtask-\(child.id.uuidString)") + } + .padding(.vertical, 1) + } + + private func subtaskState(_ child: TaskItem) -> String { + if child.isCompleted { return DurationFormat.prose(child.duration(asOf: now)) } + if !child.isPending { return DurationFormat.clock(child.duration(asOf: now)) } + guard let start = child.scheduledStart else { return "待定" } + return TaskRow.timeLabel(start, now: now) + } + + /// Each Return adds one step (time to be decided, not started) and + /// keeps the field for the next. + private var subtaskField: some View { + HStack(spacing: 6) { + Image(systemName: "plus") + .font(.system(size: 10, weight: .semibold)) + .foregroundStyle(.tertiary) + .frame(width: 22) + TextField("添加子任务,回车添加", text: $subtaskDraft) + .textFieldStyle(.plain) + .font(.callout) + .focused($subtaskFocused) + .onSubmit(commitSubtask) + .accessibilityIdentifier("subtask-input-\(task.id.uuidString)") + } + .padding(.trailing, 8) + .padding(.vertical, 6) + .background( + subtaskFocused ? Theme.focused.opacity(0.07) : Color.primary.opacity(0.04), + in: RoundedRectangle(cornerRadius: 7, style: .continuous) + ) + } + + private func takeSubtaskFocus() { + DispatchQueue.main.async { subtaskFocused = true } + onSubtaskFocused() + } + + private func commitSubtask() { + guard store.addSchedule( + title: subtaskDraft, + parentID: task.id, + start: nil, + plannedDuration: nil, + reminderLead: nil + ) != nil else { return } + subtaskDraft = "" + subtaskFocused = true + onSubtaskAdded() + } + + private func sectionTitle(_ title: String) -> some View { + Text(title) + .font(.caption.weight(.semibold)) + .foregroundStyle(.secondary) + } + + // MARK: saving + + /// Writes what changed since the last save. A blank name is not saved; + /// the stored one stays. + private func commit() { + guard draft != saved, let current = store.tasks.first(where: { $0.id == task.id }) else { return } + let value = draft + let before = saved + saved = value + if value.titleValid { + let labels = value.resolved + if labels.title != current.title { + store.rename(id: task.id, title: labels.title) + } + store.setTags(id: task.id, labels.tags) + } else if value.tags != before.tags { + store.setTags(id: task.id, value.tags) + } + guard value.scheduleEditable, + value.scheduledStart != before.scheduledStart + || value.duration != before.duration + || value.reminderLead != before.reminderLead else { return } + store.updateSchedule(id: task.id, start: value.scheduledStart, plannedDuration: value.duration, reminderLead: value.reminderLead) + } + + /// Saves anything pending, then shows what the store now holds. + private func reload() { + commit() + guard let current = store.tasks.first(where: { $0.id == task.id }) else { return } + let fresh = ScheduleDraft.editing(current, asOf: now) + draft = fresh + saved = fresh + } +} diff --git a/docs/FEATURES.md b/docs/FEATURES.md index eb1dfb2..915d9b2 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -34,7 +34,7 @@ ## 3. 弹出面板 -代码:`Sources/ITimer/MenuBarView.swift`、`RecordTimeEditor.swift`、`BrainBuddy.swift`、`Theme.swift` +代码:`Sources/ITimer/MenuBarView.swift`、`TaskDrawer.swift`、`ScheduleComposer.swift`、`JournalView.swift`、`RecordTimeEditor.swift`、`BrainBuddy.swift`、`Theme.swift` | 功能 | 说明 | 版本 | |---|---|---| @@ -47,42 +47,44 @@ | 快速输入 | 输入任务名回车立即计时;`#` 打标签,输入 `#` 时补全已有标签;占位文字随负载提醒,例如「再开一个就到脑裂线了…」 | 1.0(标签补全 1.5.0 起,负载提示 1.3.2 起) | | 最近做过的事 | 以胶囊列出,点一下直接开始,输入时自动过滤,悬停显示 ▶ | 1.3.2 | | 按状态分区 | 到点待开始 / 进行中 / 已暂停 / 接下来 / 时间待定 / 今日完成,分区旁的数字是处于这个状态的任务数 | 1.3.2(时间待定 1.4.0 起) | -| 任务行 | 左侧圆钮暂停或继续,另有 ◎ 只做这个、✓ 完成、添加子任务、备注和进展、编辑、删除(要连点两下);双击标题改名;显示 `#标签`、子任务进度、「等上游」 | 1.0 | -| 任务右键菜单 | 开始/暂停/继续/完成、只做这个、备注和进展、子任务、标签、工作流、编辑、改名、删除;菜单开着时计时数字暂停,关掉后跳回正确时间 | 1.0(计时暂停 1.6.0 起) | -| 今日完成 | 做完的事留在列表里,可以修改计时时间或一键「再来一段」 | 1.3.2 | +| 任务行 | 左侧圆钮暂停或继续,另有 ◎ 只做这个、✓ 完成、编辑(打开任务详情,再点一次关闭)、删除(要连点两下);双击标题改名;显示 `#标签`、子任务进度、有备注或进展时的小气泡、「等上游」;详情打开着的那一行描边 | 1.0(未发布起备注和子任务按钮改到任务详情) | +| 任务右键菜单 | 开始/暂停/继续/完成、只做这个、子任务、标签、工作流、编辑、改名、删除;「子任务 › 添加子任务…」打开任务详情并聚焦添加子任务的输入框;菜单开着时计时数字暂停,关掉后跳回正确时间 | 1.0(计时暂停 1.6.0 起) | +| 右侧抽屉 | 任务详情和新建日程在右侧抽屉里打开:主窗口里是列表右边的一栏,列表照常可用;面板里从右侧滑出盖住列表,点左侧露出的列表关闭;都可以点 × 或按 Esc 关闭 | 未发布 | +| 任务详情 | 顶部是状态(未开始、计时中、已暂停、已完成及时长),下面依次是日程(名称、日期、时间、预计、提醒、标签,停下来自动保存)、子任务、备注和进展;子任务的详情可以点回父任务;已完成的任务只能改名称和标签 | 未发布 | +| 今日完成 | 做完的事留在列表里,可以打开任务详情、修改计时时间或一键「再来一段」 | 1.3.2 | | 底部按钮 | 打开 iTimer、设置、退出 | 1.0 | ## 4. 日程与日程提醒 -代码:`Sources/ITimer/ScheduleComposer.swift`、`ReminderCenter.swift`、`Sources/ITimerCore/Schedule.swift` +代码:`Sources/ITimer/ScheduleComposer.swift`、`TaskDrawer.swift`、`ReminderCenter.swift`、`Sources/ITimerCore/Schedule.swift` | 功能 | 说明 | 版本 | |---|---|---| -| 新建日程 | 面板里点「日程」,填名称、日期、时间、预计时长、提醒、标签;输入框里已经打的字会带过来当名称 | 1.3.2 | +| 新建日程 | 面板里点「日程」,在右侧抽屉里填名称、日期、时间、预计时长、提醒、标签;输入框里已经打的字会带过来当名称 | 1.3.2(未发布起改在右侧抽屉) | | 日期选择 | 日期一行平铺 待定 / 今天 / 明天 / 后天 / 下周一,其他日期点右侧日历按钮选,日历可以往后翻任意个月 | 1.3.2(1.4.1 起可翻月,1.5.0 起平铺快捷选项) | | 时间待定 | 日程可以先不定时间:不会到点、不提醒、不写日历,单独列在「时间待定」,之后再定时间或直接开始 | 1.4.0 | | 到点不自动开始 | 到了时间只标成「到点待开始」,要你点开始才计时;可以推迟 10 分钟 | 1.3.2 | | 预计时长与超时 | 预计 30 分钟到 4 小时,或不定;超过预计后计时继续,超出部分标橙色 | 1.3.2 | | 日程提醒通知 | 可选不提醒、准时、提前 5 / 15 / 30 / 60 分钟;到点通知上有「开始计时」「推迟 10 分钟」按钮;计时用完预计时长时再提醒一次 | 1.3.2 | -| 编辑日程 | 没开始的可以改名称、时间、预计、提醒、标签;已经开始的可以改名称、预计、提醒、标签 | 1.3.2 | +| 编辑日程 | 在任务详情里改,停下来自动保存:没开始的可以改名称、时间、预计、提醒、标签;已经开始的可以改名称、预计、提醒、标签;已完成的可以改名称、标签 | 1.3.2(未发布起改在任务详情,自动保存) | ## 5. 子任务、标签、备注 -代码:`Sources/ITimerCore/Store.swift`、`Sources/ITimer/Labels.swift`、`JournalView.swift`、`MenuBarView.swift` +代码:`Sources/ITimerCore/Store.swift`、`Sources/ITimer/Labels.swift`、`TaskDrawer.swift`、`JournalView.swift`、`MenuBarView.swift` | 功能 | 说明 | 版本 | |---|---|---| -| 子任务 | 任务下挂一层子任务,不能再往下嵌套;点「添加子任务」后可以连续输入,Esc 结束;新子任务先放在「时间待定」;已有任务可以「归入其他任务」 | 1.6.0 | +| 子任务 | 任务下挂一层子任务,不能再往下嵌套;在任务详情的「子任务」一栏添加,回车添加一条,可以连续输入;这一栏列出已有子任务,可以开始、暂停或打开它的详情;新子任务先放在「时间待定」;已有任务可以「归入其他任务」 | 1.6.0(未发布起改在任务详情添加) | | 子任务成组 | 父任务和它没完成的子任务是一组,子任务缩进排在父任务下面,整组排在组里最靠前那一项所在的分区 | 1.7.0 | | 子任务进度与折叠 | 父任务显示完成进度(如 `1/3`),点进度胶囊折叠,折叠状态会记住;收起时有子任务在计时,胶囊旁亮小圆点;添加子任务时自动展开 | 1.6.0 | | 删除父任务 | 连同子任务一起删除,确认提示里写明子任务数 | 1.6.0 | | 标签 | 每个任务可以有多个自由标签,不用预先创建;右键菜单可以切换标签 | 1.0(右键切换 1.5.0 起) | | 标签配色 | 刻意避开专注、并行、脑裂用的青、橙、粉三种颜色 | 1.5.0 | -| 备注与进展 | 每个任务一条常驻备注,加上按时间追加的进展;有内容的任务气泡按钮会亮起 | 1.6.0 | +| 备注与进展 | 每个任务一条常驻备注,加上按时间追加的进展,在任务详情里写;有内容的任务,任务行显示小气泡 | 1.6.0(未发布起改在任务详情) | ## 6. 主窗口 -代码:`Sources/ITimer/MainView.swift`、`MainRail.swift`、`MainSidebar.swift`、`TaskListPanel.swift`、`MainWindow.swift`、`GoalCommands.swift` +代码:`Sources/ITimer/MainView.swift`、`MainRail.swift`、`MainSidebar.swift`、`TaskListPanel.swift`、`MenuBarView.swift`、`MainWindow.swift`、`GoalCommands.swift` | 功能 | 说明 | 版本 | |---|---|---| @@ -90,6 +92,7 @@ | 列表栏 | 任务、目标、工作流三个模块在图标栏右边有一列列表,⌃⌘S 收起或展开,收起后只剩图标栏;分析模块没有列表 | 1.7.0 | | 目标列表搜索 | 在列表顶部按目标名或里程碑名搜索;目标名匹配时显示全部里程碑,里程碑名匹配时显示它和所属目标;搜索时临时展开,清除后恢复原来的折叠状态,右侧画布保留 | 1.10.0 | | 任务清单 | 全部、到点待开始(有任务到点时才出现)、进行中、已暂停、接下来、时间待定、今日完成,下面按标签列出,每项带任务数;点一项,右边只显示这一类 | 1.7.0 | +| 分区折叠 | 「全部」里点分区标题(到点待开始、进行中、已暂停、接下来、时间待定、今日完成)收起或展开这一组任务,标题和任务数保留,折叠状态会记住;弹出面板不折叠 | 未发布 | | 记住位置 | 切到别的模块再回来,目标和工作流回到上次打开的那一个;删掉了就回到这个模块的空状态 | 1.7.0 | | 新建快捷键 | ⌘N 新建任务、⇧⌘N 新建工作流、⌥⌘N 新建目标,主窗口关着也能用;新建的目标和工作流直接进入改名 | 1.7.0 | | 目标菜单 | 顶部菜单栏的「目标」菜单列出所有目标,点一下打开它的路线图 | 1.7.0 | From bf5716ce6e2e13d1ed6b022323092c462f11d404 Mon Sep 17 00:00:00 2001 From: DueGin <1917764907@qq.com> Date: Mon, 19 Oct 2026 13:33:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?iTimer=201.11.0:=20=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=94=B9=E5=9C=A8=E5=8F=B3=E4=BE=A7=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=EF=BC=8C=E3=80=8C=E5=85=A8=E9=83=A8=E3=80=8D=E5=88=86?= =?UTF-8?q?=E5=8C=BA=E5=8F=AF=E6=8A=98=E5=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5 --- CHANGELOG.md | 5 ++++- Support/Info.plist | 4 ++-- docs/FEATURES.md | 18 +++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48bde67..601f966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ## [未发布] +## [1.11.0] - 2026-10-19 + ### 新增 - 主窗口「任务 › 全部」里的分区可以折叠:点「到点待开始」「进行中」「已暂停」「接下来」「时间待定」「今日完成」的标题,收起或展开这一组任务,折叠状态会记住。 @@ -209,7 +211,8 @@ - 在面板里暂停、完成任务时,面板不再塌掉或自己关上:面板开着时冻结菜单栏文字,并锁定面板高度。 -[未发布]: https://github.com/DueGin/iTimer/compare/v1.10.5...HEAD +[未发布]: https://github.com/DueGin/iTimer/compare/v1.11.0...HEAD +[1.11.0]: https://github.com/DueGin/iTimer/compare/v1.10.5...v1.11.0 [1.10.5]: https://github.com/DueGin/iTimer/compare/v1.10.4...v1.10.5 [1.10.4]: https://github.com/DueGin/iTimer/compare/v1.10.3...v1.10.4 [1.10.3]: https://github.com/DueGin/iTimer/compare/v1.10.2...v1.10.3 diff --git a/Support/Info.plist b/Support/Info.plist index 15bb384..355828f 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -19,9 +19,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.10.5 + 1.11.0 CFBundleVersion - 21 + 22 LSMinimumSystemVersion 14.0 LSUIElement diff --git a/docs/FEATURES.md b/docs/FEATURES.md index 915d9b2..cbba4a8 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -1,6 +1,6 @@ # iTimer 功能清单 -当前版本 **1.10.5**(build 21)· 更新于 2026-10-16 +当前版本 **1.11.0**(build 22)· 更新于 2026-10-19 这份清单列出 iTimer 现在有的功能,一行一个,写明它做什么、从哪个版本开始有。改动功能的提交要同时更新这里,规则见 [AGENTS.md](../AGENTS.md)。每个版本具体改了什么见 [CHANGELOG](../CHANGELOG.md),面向用户的完整用法见 [README](../README.md)。 @@ -47,10 +47,10 @@ | 快速输入 | 输入任务名回车立即计时;`#` 打标签,输入 `#` 时补全已有标签;占位文字随负载提醒,例如「再开一个就到脑裂线了…」 | 1.0(标签补全 1.5.0 起,负载提示 1.3.2 起) | | 最近做过的事 | 以胶囊列出,点一下直接开始,输入时自动过滤,悬停显示 ▶ | 1.3.2 | | 按状态分区 | 到点待开始 / 进行中 / 已暂停 / 接下来 / 时间待定 / 今日完成,分区旁的数字是处于这个状态的任务数 | 1.3.2(时间待定 1.4.0 起) | -| 任务行 | 左侧圆钮暂停或继续,另有 ◎ 只做这个、✓ 完成、编辑(打开任务详情,再点一次关闭)、删除(要连点两下);双击标题改名;显示 `#标签`、子任务进度、有备注或进展时的小气泡、「等上游」;详情打开着的那一行描边 | 1.0(未发布起备注和子任务按钮改到任务详情) | +| 任务行 | 左侧圆钮暂停或继续,另有 ◎ 只做这个、✓ 完成、编辑(打开任务详情,再点一次关闭)、删除(要连点两下);双击标题改名;显示 `#标签`、子任务进度、有备注或进展时的小气泡、「等上游」;详情打开着的那一行描边 | 1.0(1.11.0起备注和子任务按钮改到任务详情) | | 任务右键菜单 | 开始/暂停/继续/完成、只做这个、子任务、标签、工作流、编辑、改名、删除;「子任务 › 添加子任务…」打开任务详情并聚焦添加子任务的输入框;菜单开着时计时数字暂停,关掉后跳回正确时间 | 1.0(计时暂停 1.6.0 起) | -| 右侧抽屉 | 任务详情和新建日程在右侧抽屉里打开:主窗口里是列表右边的一栏,列表照常可用;面板里从右侧滑出盖住列表,点左侧露出的列表关闭;都可以点 × 或按 Esc 关闭 | 未发布 | -| 任务详情 | 顶部是状态(未开始、计时中、已暂停、已完成及时长),下面依次是日程(名称、日期、时间、预计、提醒、标签,停下来自动保存)、子任务、备注和进展;子任务的详情可以点回父任务;已完成的任务只能改名称和标签 | 未发布 | +| 右侧抽屉 | 任务详情和新建日程在右侧抽屉里打开:主窗口里是列表右边的一栏,列表照常可用;面板里从右侧滑出盖住列表,点左侧露出的列表关闭;都可以点 × 或按 Esc 关闭 | 1.11.0 | +| 任务详情 | 顶部是状态(未开始、计时中、已暂停、已完成及时长),下面依次是日程(名称、日期、时间、预计、提醒、标签,停下来自动保存)、子任务、备注和进展;子任务的详情可以点回父任务;已完成的任务只能改名称和标签 | 1.11.0 | | 今日完成 | 做完的事留在列表里,可以打开任务详情、修改计时时间或一键「再来一段」 | 1.3.2 | | 底部按钮 | 打开 iTimer、设置、退出 | 1.0 | @@ -60,13 +60,13 @@ | 功能 | 说明 | 版本 | |---|---|---| -| 新建日程 | 面板里点「日程」,在右侧抽屉里填名称、日期、时间、预计时长、提醒、标签;输入框里已经打的字会带过来当名称 | 1.3.2(未发布起改在右侧抽屉) | +| 新建日程 | 面板里点「日程」,在右侧抽屉里填名称、日期、时间、预计时长、提醒、标签;输入框里已经打的字会带过来当名称 | 1.3.2(1.11.0起改在右侧抽屉) | | 日期选择 | 日期一行平铺 待定 / 今天 / 明天 / 后天 / 下周一,其他日期点右侧日历按钮选,日历可以往后翻任意个月 | 1.3.2(1.4.1 起可翻月,1.5.0 起平铺快捷选项) | | 时间待定 | 日程可以先不定时间:不会到点、不提醒、不写日历,单独列在「时间待定」,之后再定时间或直接开始 | 1.4.0 | | 到点不自动开始 | 到了时间只标成「到点待开始」,要你点开始才计时;可以推迟 10 分钟 | 1.3.2 | | 预计时长与超时 | 预计 30 分钟到 4 小时,或不定;超过预计后计时继续,超出部分标橙色 | 1.3.2 | | 日程提醒通知 | 可选不提醒、准时、提前 5 / 15 / 30 / 60 分钟;到点通知上有「开始计时」「推迟 10 分钟」按钮;计时用完预计时长时再提醒一次 | 1.3.2 | -| 编辑日程 | 在任务详情里改,停下来自动保存:没开始的可以改名称、时间、预计、提醒、标签;已经开始的可以改名称、预计、提醒、标签;已完成的可以改名称、标签 | 1.3.2(未发布起改在任务详情,自动保存) | +| 编辑日程 | 在任务详情里改,停下来自动保存:没开始的可以改名称、时间、预计、提醒、标签;已经开始的可以改名称、预计、提醒、标签;已完成的可以改名称、标签 | 1.3.2(1.11.0起改在任务详情,自动保存) | ## 5. 子任务、标签、备注 @@ -74,13 +74,13 @@ | 功能 | 说明 | 版本 | |---|---|---| -| 子任务 | 任务下挂一层子任务,不能再往下嵌套;在任务详情的「子任务」一栏添加,回车添加一条,可以连续输入;这一栏列出已有子任务,可以开始、暂停或打开它的详情;新子任务先放在「时间待定」;已有任务可以「归入其他任务」 | 1.6.0(未发布起改在任务详情添加) | +| 子任务 | 任务下挂一层子任务,不能再往下嵌套;在任务详情的「子任务」一栏添加,回车添加一条,可以连续输入;这一栏列出已有子任务,可以开始、暂停或打开它的详情;新子任务先放在「时间待定」;已有任务可以「归入其他任务」 | 1.6.0(1.11.0起改在任务详情添加) | | 子任务成组 | 父任务和它没完成的子任务是一组,子任务缩进排在父任务下面,整组排在组里最靠前那一项所在的分区 | 1.7.0 | | 子任务进度与折叠 | 父任务显示完成进度(如 `1/3`),点进度胶囊折叠,折叠状态会记住;收起时有子任务在计时,胶囊旁亮小圆点;添加子任务时自动展开 | 1.6.0 | | 删除父任务 | 连同子任务一起删除,确认提示里写明子任务数 | 1.6.0 | | 标签 | 每个任务可以有多个自由标签,不用预先创建;右键菜单可以切换标签 | 1.0(右键切换 1.5.0 起) | | 标签配色 | 刻意避开专注、并行、脑裂用的青、橙、粉三种颜色 | 1.5.0 | -| 备注与进展 | 每个任务一条常驻备注,加上按时间追加的进展,在任务详情里写;有内容的任务,任务行显示小气泡 | 1.6.0(未发布起改在任务详情) | +| 备注与进展 | 每个任务一条常驻备注,加上按时间追加的进展,在任务详情里写;有内容的任务,任务行显示小气泡 | 1.6.0(1.11.0起改在任务详情) | ## 6. 主窗口 @@ -92,7 +92,7 @@ | 列表栏 | 任务、目标、工作流三个模块在图标栏右边有一列列表,⌃⌘S 收起或展开,收起后只剩图标栏;分析模块没有列表 | 1.7.0 | | 目标列表搜索 | 在列表顶部按目标名或里程碑名搜索;目标名匹配时显示全部里程碑,里程碑名匹配时显示它和所属目标;搜索时临时展开,清除后恢复原来的折叠状态,右侧画布保留 | 1.10.0 | | 任务清单 | 全部、到点待开始(有任务到点时才出现)、进行中、已暂停、接下来、时间待定、今日完成,下面按标签列出,每项带任务数;点一项,右边只显示这一类 | 1.7.0 | -| 分区折叠 | 「全部」里点分区标题(到点待开始、进行中、已暂停、接下来、时间待定、今日完成)收起或展开这一组任务,标题和任务数保留,折叠状态会记住;弹出面板不折叠 | 未发布 | +| 分区折叠 | 「全部」里点分区标题(到点待开始、进行中、已暂停、接下来、时间待定、今日完成)收起或展开这一组任务,标题和任务数保留,折叠状态会记住;弹出面板不折叠 | 1.11.0 | | 记住位置 | 切到别的模块再回来,目标和工作流回到上次打开的那一个;删掉了就回到这个模块的空状态 | 1.7.0 | | 新建快捷键 | ⌘N 新建任务、⇧⌘N 新建工作流、⌥⌘N 新建目标,主窗口关着也能用;新建的目标和工作流直接进入改名 | 1.7.0 | | 目标菜单 | 顶部菜单栏的「目标」菜单列出所有目标,点一下打开它的路线图 | 1.7.0 |