diff --git a/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookConfigs.java b/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookConfigs.java index 54db1b89..1e95efec 100644 --- a/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookConfigs.java +++ b/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookConfigs.java @@ -144,28 +144,28 @@ public void notebookConfigsChangeListener(JsonObject settings) { return; } - JsonElement classPathConfig = settings.get(CONFIG_CLASSPATH); + JsonElement classPathConfig = getConfig(settings, CONFIG_CLASSPATH); if (classPathConfig != null && classPathConfig.isJsonArray()) { classPath = String.join(File.pathSeparator, classPathConfig.getAsJsonArray().asList().stream().map((elem) -> elem.getAsString()).toList()); } else { classPath = null; } - JsonElement modulePathConfig = settings.get(CONFIG_MODULEPATH); + JsonElement modulePathConfig = getConfig(settings, CONFIG_MODULEPATH); if (modulePathConfig != null && modulePathConfig.isJsonArray()) { modulePath = String.join(File.pathSeparator, modulePathConfig.getAsJsonArray().asList().stream().map((elem) -> elem.getAsString()).toList()); } else { modulePath = null; } - JsonElement addModulesConfig = settings.get(CONFIG_ADDMODULES); + JsonElement addModulesConfig = getConfig(settings, CONFIG_ADDMODULES); if (addModulesConfig != null && addModulesConfig.isJsonArray()) { addModules = String.join(",", addModulesConfig.getAsJsonArray().asList().stream().map((elem) -> elem.getAsString()).toList()); } else { addModules = null; } - JsonElement enablePreviewConfig = settings.get(CONFIG_ENABLE_PREVIEW); + JsonElement enablePreviewConfig = getConfig(settings, CONFIG_ENABLE_PREVIEW); if (enablePreviewConfig != null && enablePreviewConfig.isJsonPrimitive()) { JsonPrimitive primitive = enablePreviewConfig.getAsJsonPrimitive(); enablePreview = primitive.isBoolean() && primitive.getAsBoolean(); @@ -173,25 +173,40 @@ public void notebookConfigsChangeListener(JsonObject settings) { enablePreview = false; } - JsonElement implicitImportsConfig = settings.get(CONFIG_IMPLICIT_IMPORTS); + JsonElement implicitImportsConfig = getConfig(settings, CONFIG_IMPLICIT_IMPORTS); if (implicitImportsConfig != null && implicitImportsConfig.isJsonArray()) { implicitImports = implicitImportsConfig.getAsJsonArray().asList().stream().map((elem) -> elem.getAsString()).toList(); } else { implicitImports = null; } - JsonElement notebookProjectMappingConfig = settings.get(CONFIG_PROJECTS_MAPPING); + JsonElement notebookProjectMappingConfig = getConfig(settings, CONFIG_PROJECTS_MAPPING); if (notebookProjectMappingConfig != null && notebookProjectMappingConfig.isJsonObject()) { notebookProjectMapping = notebookProjectMappingConfig.getAsJsonObject(); } else { notebookProjectMapping = new JsonObject(); } - JsonElement notebookVmOptionsConfig = settings.get(CONFIG_VM_OPTIONS); + JsonElement notebookVmOptionsConfig = getConfig(settings, CONFIG_VM_OPTIONS); if (notebookVmOptionsConfig != null && notebookVmOptionsConfig.isJsonArray()) { notebookVmOptions = notebookVmOptionsConfig.getAsJsonArray().asList().stream().map(el -> el.getAsString()).toList(); } else { notebookVmOptions = Collections.emptyList(); } } + + private static JsonElement getConfig(JsonObject settings, String key) { + if (!key.contains(".")) { + return settings.get(key); + } + + JsonElement current = settings; + for (String part : key.split("\\.")) { + if (current == null || !current.isJsonObject()) { + return null; + } + current = current.getAsJsonObject().get(part); + } + return current; + } } diff --git a/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/project/ProjectContext.java b/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/project/ProjectContext.java index 5dbb70a6..931471b4 100644 --- a/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/project/ProjectContext.java +++ b/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/project/ProjectContext.java @@ -105,7 +105,7 @@ private static CompletableFuture> selectFromMultipleProjects(Proje items.add(item); } String placeholder = defaultPrjSelected != null ? Bundle.LBL_CurrentProjectContext(defaultPrjSelected.getName()) - : items.isEmpty() ? Bundle.MSG_NoProjectFound() : Bundle.MSG_NoProjectFound(); + : items.isEmpty() ? Bundle.MSG_NoProjectFound() : Bundle.MSG_NoProjectContextFound(); ShowQuickPickParams params = new ShowQuickPickParams(title, placeholder, false, items); return client.showQuickPick(params).thenApply(selected -> { diff --git a/vscode/l10n/bundle.l10n.en.json b/vscode/l10n/bundle.l10n.en.json index 3589cd8a..cb59f12c 100644 --- a/vscode/l10n/bundle.l10n.en.json +++ b/vscode/l10n/bundle.l10n.en.json @@ -136,5 +136,6 @@ "jdk.notebook.validation.failed.error_msg": "Notebook JSON validation failed", "jdk.notebook.validation.notebook_version.failed.error_msg": "Notebook version is not supported. Please upgrade to version {majorVersion}.{minorVersion} or later.", "jdk.notebook.mime_type.not.found.cell.output": "Mime Type: {mimeType}, Content Length: {contentLength}", - "jdk.notebook.cell.language.not.found": "Doesn't support {languageId} execution" + "jdk.notebook.cell.language.not.found": "Doesn't support {languageId} execution", + "jdk.notebook.project.context.changed.restart.kernel.msg.consent": "Project context changed. Do you want to restart the notebook kernel?" } diff --git a/vscode/l10n/bundle.l10n.ja.json b/vscode/l10n/bundle.l10n.ja.json index 2e1671bb..f03aa682 100755 --- a/vscode/l10n/bundle.l10n.ja.json +++ b/vscode/l10n/bundle.l10n.ja.json @@ -136,5 +136,6 @@ "jdk.notebook.validation.failed.error_msg": "ノートブックJSON検証に失敗しました", "jdk.notebook.validation.notebook_version.failed.error_msg": "Notebook version is not supported. Please upgrade to version {majorVersion}.{minorVersion} or later.", "jdk.notebook.mime_type.not.found.cell.output": "MIMEタイプ: {mimeType}、コンテンツの長さ: {contentLength}", - "jdk.notebook.cell.language.not.found": "{languageId}の実行はサポートされていません" + "jdk.notebook.cell.language.not.found": "{languageId}の実行はサポートされていません", + "jdk.notebook.project.context.changed.restart.kernel.msg.consent": "プロジェクトのコンテキストが変更されました。ノートブックのカーネルを再起動しますか?" } diff --git a/vscode/l10n/bundle.l10n.zh-cn.json b/vscode/l10n/bundle.l10n.zh-cn.json index cb1fba6f..fc34b8e7 100755 --- a/vscode/l10n/bundle.l10n.zh-cn.json +++ b/vscode/l10n/bundle.l10n.zh-cn.json @@ -136,5 +136,6 @@ "jdk.notebook.validation.failed.error_msg": "记事本 JSON 验证失败", "jdk.notebook.validation.notebook_version.failed.error_msg": "Notebook version is not supported. Please upgrade to version {majorVersion}.{minorVersion} or later.", "jdk.notebook.mime_type.not.found.cell.output": "Mime 类型:{mimeType},内容长度:{contentLength}", - "jdk.notebook.cell.language.not.found": "不支持 {languageId} 执行" + "jdk.notebook.cell.language.not.found": "不支持 {languageId} 执行", + "jdk.notebook.project.context.changed.restart.kernel.msg.consent": "项目上下文已更改。您想要重启 Notebook 内核吗" } diff --git a/vscode/src/commands/notebook.ts b/vscode/src/commands/notebook.ts index f57fe45c..b322e730 100644 --- a/vscode/src/commands/notebook.ts +++ b/vscode/src/commands/notebook.ts @@ -155,10 +155,21 @@ const notebookChangeProjectContextHandler = async (ctx: INotebookToolbar) => { if (!res) { return; } - const oldValue = getConfigurationValue(configKeys.notebookProjectMapping, {}); - updateConfigurationValue(configKeys.notebookProjectMapping, - { ...oldValue, [uri.fsPath]: res }, - ConfigurationTarget.Workspace); + const oldValue = getConfigurationValue>(configKeys.notebookProjectMapping, {}); + const newValue = { ...oldValue, [uri.fsPath]: res }; + + if (oldValue[uri.fsPath] !== newValue[uri.fsPath]) { + updateConfigurationValue(configKeys.notebookProjectMapping, newValue, ConfigurationTarget.Workspace); + + const yes = l10n.value("jdk.extension.cache.label.confirmation.yes") + const cancel = l10n.value("jdk.extension.cache.label.confirmation.cancel") + const confirmation = await window.showWarningMessage(l10n.value("jdk.notebook.project.context.changed.restart.kernel.msg.consent"), + yes, cancel); + + if (confirmation === yes) { + await restartKernel(ctx, true); + } + } } else { throw l10n.value("jdk.extension.error_msg.doesntSupportNotebookCellExecution", { client: client?.name }); } @@ -168,13 +179,13 @@ const notebookChangeProjectContextHandler = async (ctx: INotebookToolbar) => { } } -const restartKernel = async (ctx: INotebookToolbar) => { +const restartKernel = async (ctx: INotebookToolbar, skipConfirmation = false) => { try { const uri: Uri = ctx.notebookEditor.notebookUri; const yes = l10n.value("jdk.extension.cache.label.confirmation.yes") const cancel = l10n.value("jdk.extension.cache.label.confirmation.cancel") - const confirmation = await window.showWarningMessage(l10n.value("jdk.notebook.restart.kernel.msg.consent"), + const confirmation = skipConfirmation ? yes : await window.showWarningMessage(l10n.value("jdk.notebook.restart.kernel.msg.consent"), yes, cancel); if (confirmation === yes) {