Skip to content

Commit d1077c8

Browse files
authored
Fixing problem when no language is set to desc or pref (#162)
* Fixing problem when no language is set to desc or pref * Add shortcuts for linux and windows * Fix loading on open new window * Adjust shortcuts for win and mac
1 parent df71f99 commit d1077c8

File tree

11 files changed

+106
-148
lines changed

11 files changed

+106
-148
lines changed

core/apps/ame/src/app/startup.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class StartupService {
5353
switchMap(() => this.electronTunnelService.startUpData$.asObservable()),
5454
sample(this.mxGraphService.graphInitialized$.pipe(filter(Boolean))),
5555
filter(data => {
56-
if (data) {
56+
if (data?.model) {
5757
return true;
5858
} else {
5959
this.fileHandlingService.createEmptyModel();

core/apps/ame/src/assets/i18n/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@
8989
"ASPECT_MISSING_TITLE": "Aspect Model is missing",
9090
"ASPECT_MISSING_CONTENT": "To start modelling, please create a new or load an existing model first. After that you can add new node types",
9191
"LOAD_MODEL_INFO_TITLE": "Load a Model to Continue",
92-
"LOAD_MODEL_INFO_MESSAGE": "To view the file contents, please load a model first."
92+
"LOAD_MODEL_INFO_MESSAGE": "To view the file contents, please load a model first.",
93+
"FALLBACK_TO_DEFAULT_LANGUAGE_TITLE": "Fallback to Default Language.",
94+
"FALLBACK_TO_DEFAULT_LANGUAGE_DESC_MESSAGE": "The specified language for {{subject}}'s description was not found in {{fileName}}. Proceeding with the default language settings.",
95+
"FALLBACK_TO_DEFAULT_LANGUAGE_PREF_MESSAGE": "The specified language for {{subject}}'s preferred name was not found in {{fileName}}. Proceeding with the default language settings."
9396
},
9497
"TOOLBAR": {
9598
"NEW_LOAD": "New/Load",

core/electron-libs/app-menu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const {
4848
SIGNAL_ZOOM_OUT,
4949
SIGNAL_LOAD_FROM_TEXT,
5050
} = require('./events');
51-
const {icons, models, inDevMode} = require('./consts');
51+
const {icons, paths, inDevMode} = require('./consts');
5252
const {isMac} = require('./os-checker');
5353
const path = require('path');
5454

@@ -117,7 +117,7 @@ const fileSubmenu = [
117117
label: 'SimpleAspect.ttl',
118118
icon: getIcon(icons.LOAD_DEFAULT_EXAMPLE.enabled),
119119
click: (menuItem, browserWindow, _) => {
120-
return getFileInfo(path.join(models, 'SimpleAspect.ttl'))
120+
return getFileInfo(path.join(paths.models, 'SimpleAspect.ttl'))
121121
.then(fileInfo => browserWindow.webContents.send(SIGNAL_LOAD_SPECIFIC_FILE, fileInfo))
122122
.catch(error => console.error(error));
123123
},
@@ -127,7 +127,7 @@ const fileSubmenu = [
127127
label: 'Movement.ttl',
128128
icon: getIcon(icons.LOAD_MOVEMENT_EXAMPLE.enabled),
129129
click: (menuItem, browserWindow, _) => {
130-
return getFileInfo(path.join(models, 'Movement.ttl'))
130+
return getFileInfo(path.join(paths.models, 'Movement.ttl'))
131131
.then(fileInfo => browserWindow.webContents.send(SIGNAL_LOAD_SPECIFIC_FILE, fileInfo))
132132
.catch(error => console.error(error));
133133
},

core/electron-libs/mac/shortcuts.js

Lines changed: 0 additions & 131 deletions
This file was deleted.

core/electron-libs/shortcuts.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for
5+
* additional information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
*/
13+
14+
const {app, globalShortcut, BrowserWindow, Menu, nativeTheme} = require('electron');
15+
const platformData = require('./os-checker');
16+
17+
function registerGlobalShortcuts() {
18+
const shortcutsGlobal = [
19+
{key: 'CommandOrControl+W', action: () => BrowserWindow.getFocusedWindow()?.close()},
20+
{key: 'CommandOrControl+M', action: () => BrowserWindow.getFocusedWindow()?.minimize()},
21+
{key: 'CommandOrControl+Shift+M', action: () => BrowserWindow.getFocusedWindow()?.maximize()},
22+
{key: 'CommandOrControl+Shift+F', action: () => BrowserWindow.getFocusedWindow()?.setFullScreen(true)},
23+
{key: 'CommandOrControl+Shift+G', action: () => BrowserWindow.getFocusedWindow()?.setFullScreen(false)},
24+
];
25+
26+
const shortcutsMac = [
27+
{key: 'CommandOrControl+Q', action: () => (BrowserWindow.getFocusedWindow() ? app.quit() : null)},
28+
{key: 'Command+Option+I', action: () => BrowserWindow.getFocusedWindow().webContents.openDevTools()},
29+
{key: 'CommandOrControl+R', action: () => BrowserWindow.getFocusedWindow()?.reload()},
30+
{
31+
key: 'CommandOrControl+Shift+R',
32+
action: () => BrowserWindow.getFocusedWindow()?.webContents.reloadIgnoringCache(),
33+
},
34+
];
35+
36+
const shortcutsWin = [{key: 'Control+Shift+I', action: () => BrowserWindow.getFocusedWindow().webContents.openDevTools()}];
37+
38+
shortcutsGlobal.forEach(({key, action}) => {
39+
globalShortcut.register(key, action);
40+
});
41+
42+
if (platformData.isMac) {
43+
shortcutsMac.forEach(({key, action}) => {
44+
globalShortcut.register(key, action);
45+
});
46+
}
47+
48+
if (platformData.isWin) {
49+
shortcutsWin.forEach(({key, action}) => {
50+
globalShortcut.register(key, action);
51+
});
52+
}
53+
}
54+
55+
function unregisterGlobalShortcuts() {
56+
globalShortcut.unregisterAll();
57+
}
58+
59+
module.exports = {
60+
registerGlobalShortcuts,
61+
unregisterGlobalShortcuts,
62+
};

core/libs/editor/src/lib/editor-toolbar/editor-toolbar.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ export class EditorToolbarComponent implements AfterViewInit, OnInit, OnDestroy
8080
clearInterval(this.checkChangesInterval);
8181
}
8282

83-
openWindow() {
84-
this.electronSignalsService.call('openWindow', null);
85-
}
86-
8783
// Deactivates the bug where the shape can not be removed
8884
blurActiveButton() {
8985
requestAnimationFrame(() => {

core/libs/instantiator/src/lib/instantiator.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {RdfService} from '@ame/rdf/services';
3030
import {RdfModel, RdfModelUtil} from '@ame/rdf/utils';
3131
import {NotificationsService} from '@ame/shared';
3232
import {AbstractEntityInstantiator} from './instantiators/abstract-entity-instantiator';
33+
import {LanguageTranslationService} from '@ame/translation';
3334

3435
@Injectable({
3536
providedIn: 'root',
@@ -39,6 +40,7 @@ export class InstantiatorService {
3940
private namespaceCacheService: NamespacesCacheService,
4041
public rdfService: RdfService,
4142
public notificationsService: NotificationsService,
43+
public translate: LanguageTranslationService,
4244
) {}
4345

4446
public instantiateFile(rdfModel: RdfModel, cachedFile: CachedFile, fileName: string): CachedFile {
@@ -56,6 +58,7 @@ export class InstantiatorService {
5658
this.namespaceCacheService,
5759
new Map<string, Array<BaseMetaModelElement>>(),
5860
this.notificationsService,
61+
this.translate,
5962
);
6063

6164
if (aspect) {

core/libs/instantiator/src/lib/meta-model-element-instantiator.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
LocaleConstraintInstantiator,
5151
MeasurementCharacteristicInstantiator,
5252
OperationInstantiator,
53+
PredefinedEntityInstantiator,
5354
PredefinedPropertyInstantiator,
5455
PropertyInstantiator,
5556
QuantifiableCharacteristicInstantiator,
@@ -67,11 +68,11 @@ import {
6768
import {CachedFile, NamespacesCacheService} from '@ame/cache';
6869
import {RdfModel, RdfModelUtil} from '@ame/rdf/utils';
6970
import {GeneralConfig, NotificationsService} from '@ame/shared';
70-
import {PredefinedEntityInstantiator} from './instantiators';
7171
import {syncElementWithChildren} from './helpers';
7272
import {Samm, SammC, SammE, SammU} from '@ame/vocabulary';
7373
import {setUniqueElementName} from '@ame/utils';
7474
import {InstantiatorListElement} from '@ame/rdf/models';
75+
import {LanguageTranslationService} from '@ame/translation';
7576

7677
export class MetaModelElementInstantiator {
7778
private characteristicInstantiator: CharacteristicInstantiator;
@@ -92,6 +93,7 @@ export class MetaModelElementInstantiator {
9293
public namespaceCacheService?: NamespacesCacheService,
9394
public recursiveModelElements?: Map<string, Array<BaseMetaModelElement>>,
9495
public notificationsService?: NotificationsService,
96+
public translate?: LanguageTranslationService,
9597
) {
9698
this.samm = this.rdfModel.samm;
9799
this.sammC = this.rdfModel.sammC;
@@ -454,7 +456,13 @@ export class MetaModelElementInstantiator {
454456
* @param skipSetExternal - skip the external reference
455457
* @returns the external rdfModel and the instantiated model
456458
*/
457-
getExternalElement<T>(quad: NamedNode | Quad_Object, skipSetExternal = false): {externalRdfModel: RdfModel; externalReference: T} {
459+
getExternalElement<T>(
460+
quad: NamedNode | Quad_Object,
461+
skipSetExternal = false,
462+
): {
463+
externalRdfModel: RdfModel;
464+
externalReference: T;
465+
} {
458466
let externalReference = this.namespaceCacheService.findElementOnExtReference<T>(quad.value);
459467
const externalRdfModel = this.getRdfModelByElement(quad);
460468

@@ -504,6 +512,14 @@ export class MetaModelElementInstantiator {
504512
if (this.rdfModel.getLocale(quad)) {
505513
metaModelElement.addDescription(this.rdfModel.getLocale(quad), quad.object.value);
506514
} else {
515+
this.notificationsService.error({
516+
title: this.translate.language.NOTIFICATION_SERVICE.FALLBACK_TO_DEFAULT_LANGUAGE_TITLE,
517+
message: this.translate.translateService.instant('NOTIFICATION_SERVICE.FALLBACK_TO_DEFAULT_LANGUAGE_DESC_MESSAGE', {
518+
subject: quad.subject.value,
519+
fileName: metaModelElement?.fileName,
520+
}),
521+
timeout: 5000,
522+
});
507523
metaModelElement.addDescription('en', quad.object.value);
508524
}
509525
}
@@ -512,6 +528,14 @@ export class MetaModelElementInstantiator {
512528
if (this.rdfModel.getLocale(quad)) {
513529
metaModelElement.addPreferredName(this.rdfModel.getLocale(quad), quad.object.value);
514530
} else {
531+
this.notificationsService.error({
532+
title: this.translate.language.NOTIFICATION_SERVICE.FALLBACK_TO_DEFAULT_LANGUAGE_TITLE,
533+
message: this.translate.translateService.instant('NOTIFICATION_SERVICE.FALLBACK_TO_DEFAULT_LANGUAGE_PREF_MESSAGE', {
534+
subject: quad.subject.value,
535+
fileName: metaModelElement?.fileName,
536+
}),
537+
timeout: 5000,
538+
});
515539
metaModelElement.addPreferredName('en', quad.object.value);
516540
}
517541
}

core/libs/rdf/src/lib/utils/rdf-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export class RdfModel {
251251
}
252252

253253
getLocale(quad: Quad): string {
254-
return quad ? locale.getByTag(quad.object['language']).tag : null;
254+
return quad?.object?.['language'] ? locale.getByTag(quad.object['language']).tag : null;
255255
}
256256

257257
public resolveRecursiveBlankNodes(uri: string, writer: Writer): Quad[] {

core/libs/translation/src/lib/models/language.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ export interface NotificationService {
560560
ASPECT_MISSING_CONTENT: string;
561561
LOAD_MODEL_INFO_TITLE: string;
562562
LOAD_MODEL_INFO_MESSAGE: string;
563+
FALLBACK_TO_DEFAULT_LANGUAGE_TITLE: string;
564+
FALLBACK_TO_DEFAULT_LANGUAGE_DESC_MESSAGE: string;
565+
FALLBACK_TO_DEFAULT_LANGUAGE_PREF_MESSAGE: string;
563566
}
564567
export interface SammMigration {
565568
CHECK_WORKSPACE: string;

0 commit comments

Comments
 (0)