Skip to content

Conversation

@pengfeixx
Copy link
Contributor

@pengfeixx pengfeixx commented Aug 27, 2025

Add a password input box menu setting item

Log: Add a password input box menu setting item
pms: BUG-308717

Summary by Sourcery

Add support for toggling copy and cut operations in the password input context menu

New Features:

  • Introduce copyMenuEnabled and cutMenuEnabled properties on TextField to control context menu actions
  • Expose setCopyEnable() and setCutEnable() functions in PasswordEdit.qml to configure these properties

Enhancements:

  • Conditionally enable Copy and Cut menu items based on the new properties

deepin-ci-robot added a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 27, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#522
@sourcery-ai
Copy link

sourcery-ai bot commented Aug 27, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR introduces configurable enablement for copy and cut context menu items in password input fields by adding control flags and exposing setter functions to toggle these features.

Sequence diagram for toggling copy/cut menu enablement in password input

sequenceDiagram
    actor User
    participant PasswordEdit
    participant TextField
    User->>PasswordEdit: Calls setCopyEnable(enable)
    PasswordEdit->>TextField: Sets copyMenuEnabled
    User->>PasswordEdit: Calls setCutEnable(enable)
    PasswordEdit->>TextField: Sets cutMenuEnabled
    User->>TextField: Opens context menu
    TextField-->>User: Shows Copy/Cut enabled or disabled
Loading

Class diagram for updated TextField and PasswordEdit components

classDiagram
    class TextField {
        +bool copyMenuEnabled
        +bool cutMenuEnabled
        +copy()
        +cut()
    }
    class PasswordEdit {
        +setCopyEnable(enable)
        +setCutEnable(enable)
    }
    PasswordEdit --> TextField: uses
Loading

File-Level Changes

Change Details Files
Expose copyMenuEnabled and cutMenuEnabled flags in text fields
  • Added boolean properties copyMenuEnabled and cutMenuEnabled with default true
  • Extended ‘Copy’ menu item’s enabled condition to check copyMenuEnabled
  • Extended ‘Cut’ menu item’s enabled condition to check cutMenuEnabled
qt6/src/qml/TextField.qml
Provide setter functions in PasswordEdit to control menu flags
  • Added setCopyEnable(enable) to toggle control.copyMenuEnabled
  • Added setCutEnable(enable) to toggle control.cutMenuEnabled
qt6/src/qml/PasswordEdit.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Rename setCopyEnable() and setCutEnable() to setCopyEnabled() and setCutEnabled() to match the copyMenuEnabled and cutMenuEnabled property naming.
  • Expose copyMenuEnabled and cutMenuEnabled as QML property aliases on PasswordEdit instead of only providing setter functions for more straightforward usage and binding.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Rename setCopyEnable() and setCutEnable() to setCopyEnabled() and setCutEnabled() to match the copyMenuEnabled and cutMenuEnabled property naming.
- Expose copyMenuEnabled and cutMenuEnabled as QML property aliases on PasswordEdit instead of only providing setter functions for more straightforward usage and binding.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@18202781743 18202781743 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样,只是菜单不显示吧,但实际上还是能剪切吧,

deepin-ci-robot added a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 27, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#522
18202781743
18202781743 previously approved these changes Aug 27, 2025
deepin-ci-robot added a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 28, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#522
deepin-ci-robot added a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 28, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#522
Add a password input box menu setting item

Log: Add a password input box menu setting item
pms: BUG-308717
deepin-ci-robot added a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 28, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#522
@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

这段代码是一个Qt Quick的TextField组件的修改,我来分析一下它的改进点以及可能存在的问题:

改进点:

  1. 代码复用性提升

    • 新增了canCopycanCut两个属性,将复制和剪切功能的条件判断逻辑提取出来,减少了重复代码
    • 这使得代码更易于维护,如果需要修改条件判断逻辑,只需修改一处即可
  2. 性能优化

    • 通过属性提取,避免了在每次渲染时重复计算相同的条件
    • 将条件判断从模板字面量提取为属性,减少了MenuItem的重复计算
  3. 功能增强

    • 添加了键盘事件处理,对Copy和Cut快捷键进行了条件判断
    • 使用Keys.enabledonPressed处理键盘事件,提高了组件的交互性

潜在问题与建议:

  1. 逻辑一致性问题

    • canCopycanCut的判断逻辑几乎相同,只是canCut多了一个!control.readonly条件
    • 建议:可以考虑将这两个条件合并为一个更通用的属性,或者创建一个辅助函数来处理这些条件
  2. 键盘事件处理

    • canCopycanCut为false时,只是简单地接受事件但没有给出用户反馈
    • 建议:可以添加视觉或听觉反馈,或者显示提示信息,让用户为什么操作被禁止
  3. 代码结构

    • 新增的键盘事件处理代码块较长,可以考虑提取为一个单独的函数
    • 建议:将键盘事件处理逻辑提取为独立函数,提高代码可读性
  4. 安全性考虑

    • 代码中没有对用户输入进行额外的验证或过滤
    • 建议:考虑添加输入验证,特别是如果这个字段用于敏感操作时
  5. 可访问性

    • 没有为禁用状态提供适当的ARIA属性或屏幕阅读器支持
    • 建议:考虑添加适当的可访问性属性,提高组件的可用性

修改建议示例:

T.TextField {
    // ... 其他属性保持不变 ...

    // 提取通用的操作条件判断
    readonly property bool canEdit: control.echoMode === TextInput.Normal
    readonly property bool hasSelection: control.selectedText.length > 0
    readonly property bool canCopy: canEdit && hasSelection
    readonly property bool canCut: canEdit && hasSelection && !control.readonly

    // 提取键盘事件处理为独立函数
    function handleKeyEvent(event) {
        if (event.matches(StandardKey.Copy)) {
            if (!canCopy) {
                event.accepted = true
                showFeedback("复制功能不可用")
                return true
            }
        } else if (event.matches(StandardKey.Cut)) {
            if (!canCut) {
                event.accepted = true
                showFeedback("剪切功能不可用")
                return true
            }
        }
        return false
    }

    // 反馈函数
    function showFeedback(message) {
        // 实现视觉或听觉反馈
        console.log(message)
        // 或者使用Qt Quick的Toast/Notification组件
    }

    Keys.enabled: !canCopy || !canCut
    Keys.onPressed: function(event) {
        handleKeyEvent(event)
    }

    // ... 其他代码保持不变 ...
}

这些改进可以提高代码的可维护性、可读性和用户体验,同时保持原有功能的完整性。

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Aug 28, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 5420b94 into linuxdeepin:master Aug 28, 2025
16 of 17 checks passed
18202781743 pushed a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 28, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants