Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Sep 24, 2025

是重构分支实现时的行为错误.

Summary by Sourcery

Bug Fixes:

  • Use application name instead of window title in TaskManager context menu

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 24, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes incorrect labeling in the task manager context menu by using the application name role instead of the window title for active items

File-Level Changes

Change Details Files
Use application name for context menu items instead of window title for active entries
  • Replaced WinTitleRole with NameRole when appending the ‘name’ field for activeAppModel menus
panels/dock/taskmanager/dockglobalelementmodel.cpp

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 and they look great!


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.

…itle

是重构分支实现时的行为错误.

PMS: BUG-335633
Log:
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改主要是改进了菜单名称的获取逻辑,我来分析一下改进前后的代码并提供审查意见:

改进点分析

  1. 代码可读性提升

    • 将原来的三元表达式改为明确的if语句,使逻辑更清晰
    • 添加了注释说明特殊情况的处理
  2. 健壮性增强

    • 增加了对空应用名的检查处理
    • 提供了后备方案(使用窗口标题)作为应用名为空的情况
  3. 代码质量改进

    • 将字符串提取为变量,避免重复计算
    • 逻辑结构更加清晰和易于维护

潜在问题和改进建议

  1. 错误处理

    • index.data(TaskManager::NameRole) 返回无效值时,代码已经做了处理,但建议增加对 QJsonDocument::fromJson(actions) 的错误处理,防止解析失败导致程序异常。
  2. 国际化考虑

    • "Open" 作为默认文本应该使用 tr("Open") 以支持国际化
    • 建议确认是否所有用户界面文本都正确使用了翻译函数
  3. 性能优化

    • 如果频繁调用此函数,可以考虑缓存 appNameInMenu 的值
    • QJsonDocument::fromJson(actions) 的解析可能比较耗时,如果 actions 数据不变,可以考虑缓存解析结果
  4. 代码安全性

    • 应该检查 actions 是否为空或无效的 JSON 字符串
    • 建议添加对 JSON 解析异常的处理

改进建议代码示例

QString DockGlobalElementModel::getMenus(const QModelIndex &index) const
{
    // ... 前面的代码保持不变 ...

    QString appNameInMenu = tr("Open");
    if (model == m_activeAppModel) {
        appNameInMenu = index.data(TaskManager::NameRole).toString();
        // In case a window does not belong to a known application, use the window title instead
        if (appNameInMenu.isEmpty()) {
            appNameInMenu = index.data(TaskManager::WinTitleRole).toString();
        }
    }
    menusArray.append(QJsonObject{{"id", ""}, {"name", appNameInMenu}});

    auto actions = model->index(row, 0).data(TaskManager::ActionsRole).toByteArray();
    if (!actions.isEmpty()) {
        QJsonParseError error;
        auto doc = QJsonDocument::fromJson(actions, &error);
        if (error.error == QJsonParseError::NoError) {
            for (auto action : doc.array()) {
                // ... 处理 action ...
            }
        } else {
            qWarning() << "Failed to parse actions JSON:" << error.errorString();
        }
    } else {
        qWarning() << "Empty actions received for row" << row;
    }

    // ... 后面的代码保持不变 ...
}

这些改进可以提高代码的健壮性和可维护性,同时更好地处理异常情况。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@BLumia BLumia merged commit 72f8b43 into linuxdeepin:master Sep 24, 2025
10 of 11 checks passed
@BLumia BLumia deleted the pms-335633 branch September 24, 2025 06:41
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