diff --git a/dconfig-center/dde-dconfig-editor/mainwindow.cpp b/dconfig-center/dde-dconfig-editor/mainwindow.cpp index 7ccacc3..03f0671 100644 --- a/dconfig-center/dde-dconfig-editor/mainwindow.cpp +++ b/dconfig-center/dde-dconfig-editor/mainwindow.cpp @@ -151,6 +151,26 @@ MainWindow::MainWindow(QWidget *parent) : } }); + resourceListView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(resourceListView, &QWidget::customContextMenuRequested, this, [this](const QPoint&) { + if (auto model = qobject_cast(resourceListView->model())){ + const auto index = resourceListView->currentIndex(); + if (!index.isValid()) + return; + const auto &type = model->data(index, ConfigUserRole + 1).toInt(); + if (type & ConfigType::ResourceType || type == ConfigType::SubpathType) { + const auto &appid = model->data(index, ConfigUserRole + 2).toString(); + const auto &resourceId = model->data(index, ConfigUserRole + 3).toString(); + const auto &subpath = model->data(index, ConfigUserRole + 4).toString(); + if (resourceId.isEmpty()) { + qWarning() << "error" << appid << resourceId; + return; + } + onCustomResourceMenuRequested(appid, resourceId, subpath); + } + } + }); + // set history DTitlebar *titlebar = this->titlebar(); titlebar->setIcon(QIcon(APP_ICON)); @@ -287,6 +307,24 @@ void MainWindow::refreshResourceKeys(const QString &appid, const QString &resour contentView->refreshResourceKeys(appid, resourceId, subpath, matchKeyId); } +void MainWindow::onCustomResourceMenuRequested(const QString &appid, const QString &resource, const QString &subpath) +{ + QMenu menu(resourceListView); + + QAction *resetCmdAction = menu.addAction(tr("reset value")); + + connect(resetCmdAction, &QAction::triggered, this, [this, appid, resource, subpath] { + QScopedPointer getter(new ValueHandler(appid, resource, subpath)); + QScopedPointer manager(getter->createManager()); + const auto keys = manager->keyList(); + for (const auto &item : qAsConst(keys)) { + manager->reset(item); + } + refreshResourceKeys(appid, resource, subpath); + }); + menu.exec(QCursor::pos()); +} + void MainWindow::installTranslate() { DTitlebar *titlebar = this->titlebar(); diff --git a/dconfig-center/dde-dconfig-editor/mainwindow.h b/dconfig-center/dde-dconfig-editor/mainwindow.h index 2772d3b..2dc8ae1 100644 --- a/dconfig-center/dde-dconfig-editor/mainwindow.h +++ b/dconfig-center/dde-dconfig-editor/mainwindow.h @@ -116,6 +116,8 @@ private slots: void refreshResourceSubpaths(QStandardItemModel *model, const QString &appid, const QString &resourceId); void refreshResourceKeys(const QString &appid, const QString &resourceId, const QString &subpath, const QString &matchKeyId = QString()); + + void onCustomResourceMenuRequested(const QString &appid, const QString &resource, const QString &subpath); private: void installTranslate(); diff --git a/dconfig-center/dde-dconfig-editor/translates/dde-dconfig-editor_zh_CN.ts b/dconfig-center/dde-dconfig-editor/translates/dde-dconfig-editor_zh_CN.ts index 1a102c9..0ec6926 100644 --- a/dconfig-center/dde-dconfig-editor/translates/dde-dconfig-editor_zh_CN.ts +++ b/dconfig-center/dde-dconfig-editor/translates/dde-dconfig-editor_zh_CN.ts @@ -4,32 +4,32 @@ Content - + export 导出 - + copy value 复制值 - + convert to cmd 复制命令 - + reset value 重置 - + export current configuration 导出当前配置 - + file(*.csv) 文件(*.csv) @@ -85,57 +85,62 @@ 输入应用Id - + resource 配置Id - + input filter resource 输入配置Id - + keys 配置项Key值 - + input filter keys 输入配置项Key值 - + setting history 修改历史 - + export 导出 - + OEM 定制镜像 - + + reset value + 重置 + + + config language 配置语言 - + default 默认 - + chinese 中文 - + english 英文 diff --git a/dconfig-center/dde-dconfig/main.cpp b/dconfig-center/dde-dconfig/main.cpp index 4aa2325..f30c5c5 100644 --- a/dconfig-center/dde-dconfig/main.cpp +++ b/dconfig-center/dde-dconfig/main.cpp @@ -293,8 +293,8 @@ int CommandManager::setCommand() int CommandManager::resetCommand() { // reset命令,设置指定配置项 - if (!isSetAppid() || !isSetResourceid() || !isSetKey()) { - outpuSTDError("not set appid, resource or key."); + if (!isSetAppid() || !isSetResourceid()) { + outpuSTDError("not set appid, resource"); return 1; } @@ -307,7 +307,14 @@ int CommandManager::resetCommand() { QScopedPointer manager(handler.createManager()); if (manager) { - manager->reset(key); + if (isSetKey()) { + manager->reset(key); + } else { + const auto keys = manager->keyList(); + for (const auto &item : qAsConst(keys)) { + manager->reset(item); + } + } } else { outpuSTDError(QString("not create value handler for appid=%1, resource=%2, subpath=%3.").arg(appid, resourceid, subpathid)); return 1; @@ -401,7 +408,7 @@ int main(int argc, char *argv[]) setOption.setFlags(setOption.flags() ^ QCommandLineOption::HiddenFromHelp); parser.addOption(setOption); - QCommandLineOption resetOption("reset", QCoreApplication::translate("main", "reset configure item 's value.")); + QCommandLineOption resetOption("reset", QCoreApplication::translate("main", "reset configure item's value, reset all configure item's value if not `-k` option.")); resetOption.setFlags(resetOption.flags() ^ QCommandLineOption::HiddenFromHelp); parser.addOption(resetOption); diff --git a/dconfig-center/dde-dconfig/translates/dde-dconfig_zh_CN.ts b/dconfig-center/dde-dconfig/translates/dde-dconfig_zh_CN.ts index 175375b..dd4cb5e 100644 --- a/dconfig-center/dde-dconfig/translates/dde-dconfig_zh_CN.ts +++ b/dconfig-center/dde-dconfig/translates/dde-dconfig_zh_CN.ts @@ -4,86 +4,86 @@ main - + A console tool to get and set configuration items for DTK Config. 用于管理DTK提供的配置策略的CLI工具 - + operate configure items of the user uid. 用户uid, 用户的唯一ID,对指定用户的配置项进行读写等操作 - + appid for a specific application, it is empty string if we need to manage application independent configuration. second positional argument as appid if not the option 应用Id,应用程序的唯一ID,当管理应用无关配置时此值为空,如果没有设置这个选项,则使用第二个位置参数当作此选项值 - + resource id for configure name, it's value is same as `a` option if not the option. 配置Id,配置描述文件的唯一标识,是配置描述文件的文件名,如果没有设置这个选项,则值与应用Id的值相同 - + subpath for configure. 子目录,配置描述文件安装可包含子路径,支持配置描述文件的优先级,通常情况下不设置此值 - + configure item's key. three positional argument as key if not the option 配置项Key值,如果没有设置这个选项,则使用第三个位置参数当作此选项值 - + new value to set configure item. 需要设置的配置项值,此选项在set模式下工作 - + working prefix directory. 配置策略的工作目录前缀,通常情况下不设置此值 - + method for the configure item. 指定配置项的字段信息,用于获取配置项的详细信息,值为{name | discription | visibility | permissions | version | isDefaultValue}其中一个,此选项在get模式下工作 - + language for the configuration item. 指定语言,此选项在get模式下工作,并且需要指定method选项 - + list configure information with appid, resource or subpath. list模式,列出可配置的应用Id,配置Id,及子目录 - + query content for configure, including the configure item's all keys, value ... get模式,用于查询指定配置项的信息 - + set configure item 's value. set模式,用于设置配置项的值 - - reset configure item 's value. - reset模式,用于重置配置项的值,此会清除对应的缓存值 + + reset configure item's value, reset all configure item's value if not `-k` option. + reset模式,用于重置配置项的值,此会清除对应的缓存值,若没有指定`-k`选项,则重置此配置文件的所有缓存值 - + watch value changed for some configure item. watch模式,用于监听配置项的更改 - + start dde-dconfig-editor as a gui configure tool. gui模式,用于启动GUI工具,需要安装对应的GUI工具dde-dconfig-editor