Skip to content

Commit

Permalink
Refactor table and open document in editor if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
xiwenc committed Sep 26, 2024
1 parent dad6b6f commit b80dd77
Show file tree
Hide file tree
Showing 17 changed files with 1,061 additions and 234 deletions.
7 changes: 5 additions & 2 deletions MxLintPaneExtension.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.Composition;
using Mendix.StudioPro.ExtensionsAPI.Services;
using Mendix.StudioPro.ExtensionsAPI.UI.Services;
using Mendix.StudioPro.ExtensionsAPI.UI.DockablePane;

namespace com.cinaq.MxLintExtension;
Expand All @@ -11,15 +12,17 @@ public class MxLintPaneExtension : DockablePaneExtension

public const string ID = "com-cinaq-mxlint-extension";
public override string Id => ID;
private readonly IDockingWindowService _dockingWindowService;

[ImportingConstructor]
public MxLintPaneExtension(ILogService logService)
public MxLintPaneExtension(IDockingWindowService dockingWindowService, ILogService logService)
{
_logService = logService;
_dockingWindowService = dockingWindowService;
}

public override DockablePaneViewModelBase Open()
{
return new MxLintPaneExtensionWebViewModel(new Uri(Path.Combine(WebServerBaseUrl.AbsoluteUri,"wwwroot")), () => CurrentApp, _logService) { Title = "MxLint" };
return new MxLintPaneExtensionWebViewModel(new Uri(Path.Combine(WebServerBaseUrl.AbsoluteUri,"wwwroot")), () => CurrentApp, _logService, _dockingWindowService) { Title = "MxLint" };
}
}
84 changes: 79 additions & 5 deletions MxLintPaneExtensionWebViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Mendix.StudioPro.ExtensionsAPI.Model;
using Mendix.StudioPro.ExtensionsAPI.Model.Projects;
using Mendix.StudioPro.ExtensionsAPI.Services;
using Mendix.StudioPro.ExtensionsAPI.UI.DockablePane;
using Mendix.StudioPro.ExtensionsAPI.UI.Services;
using Mendix.StudioPro.ExtensionsAPI.UI.WebView;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Text.Json.Nodes;


namespace com.cinaq.MxLintExtension;

Expand All @@ -14,13 +14,16 @@ public class MxLintPaneExtensionWebViewModel : WebViewDockablePaneViewModel
private readonly Uri _baseUri;
private readonly Func<IModel?> _getCurrentApp;
private readonly ILogService _logService;
private readonly IDockingWindowService _dockingWindowService;
private DateTime _lastUpdateTime;
private IWebView? _webView; // Change 1: Make _webView nullable

public MxLintPaneExtensionWebViewModel(Uri baseUri, Func<IModel?> getCurrentApp, ILogService logService)

public MxLintPaneExtensionWebViewModel(Uri baseUri, Func<IModel?> getCurrentApp, ILogService logService, IDockingWindowService dockingWindowService)
{
_baseUri = baseUri;
_getCurrentApp = getCurrentApp;
_dockingWindowService = dockingWindowService;
_logService = logService;
_lastUpdateTime = DateTime.Now.AddYears(-100); // force refresh on first run
}
Expand Down Expand Up @@ -48,6 +51,77 @@ private async void HandleWebViewMessage(object? sender, MessageReceivedEventArgs
{
_webView?.ShowDevTools();
}
if (args.Message == "openDocument")
{
_webView?.PostMessage("documentOpened");
await OpenDocument(currentApp, args.Data);
}
}


private async Task<bool> OpenDocument(IModel currentApp, JsonObject data)

Check warning on line 62 in MxLintPaneExtensionWebViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var doc = GetUnit(currentApp, data);
if (doc == null)
{
_logService.Error($"Document not found: {data}");
return false;
}

_dockingWindowService.TryOpenEditor(doc, null);
return true;
}

private IAbstractUnit? GetUnit(IModel currentApp, JsonObject data)
{
_logService.Info($"Looking up document: {data}");

var documentName = data["document"].ToString();

Check warning on line 79 in MxLintPaneExtensionWebViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Dereference of a possibly null reference.
if (documentName == "Security$ProjectSecurity")
{
return null;
}

var moduleName = data["module"].ToString();

Check warning on line 85 in MxLintPaneExtensionWebViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Dereference of a possibly null reference.

var module = currentApp.Root.GetModules().Single(m => m.Name == moduleName);
if (module == null)
{
_logService.Error($"Module not found: {moduleName}");
return null;
}


if (documentName == "DomainModels$DomainModel")
{
return module.DomainModel;
}


IFolder folder = null;

Check warning on line 101 in MxLintPaneExtensionWebViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Converting null literal or possible null value to non-nullable type.
while (documentName.Contains("/"))
{
var tokens = documentName.Split("/");
var folderName = tokens[0];
if (folder == null)
{
folder = module.GetFolders().FirstOrDefault(f => f.Name == folderName);

Check warning on line 108 in MxLintPaneExtensionWebViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Converting null literal or possible null value to non-nullable type.
}
else
{
folder = folder.GetFolders().FirstOrDefault(f => f.Name == folderName);

Check warning on line 112 in MxLintPaneExtensionWebViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Converting null literal or possible null value to non-nullable type.
}
documentName = documentName.Substring(folderName.Length + 1);
}
if (folder == null)
{
return module.GetDocuments().FirstOrDefault(d => d.Name == documentName);
}
else
{
return folder.GetDocuments().FirstOrDefault(d => d.Name == documentName);
}

}

private async Task<bool> Refresh(IModel currentApp)
Expand Down
Binary file modified resources/App/App.mpr
Binary file not shown.
197 changes: 197 additions & 0 deletions resources/App/extensions/MxLintExtension/MendixCLIExtension.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v8.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v8.0": {
"MendixCLIExtension/1.0.0": {
"dependencies": {
"Mendix.StudioPro.ExtensionsAPI": "10.13.0"
},
"runtime": {
"MendixCLIExtension.dll": {}
}
},
"Mendix.StudioPro.ExtensionsAPI/10.13.0": {
"dependencies": {
"System.ComponentModel.Composition": "8.0.0",
"System.Security.Cryptography.Pkcs": "8.0.0",
"System.ServiceModel.Primitives": "8.0.0"
},
"runtime": {
"lib/net8.0/Mendix.StudioPro.ExtensionsAPI.dll": {
"assemblyVersion": "10.13.0.0",
"fileVersion": "10.13.0.0"
}
}
},
"Microsoft.Extensions.ObjectPool/6.0.16": {
"runtime": {
"lib/net6.0/Microsoft.Extensions.ObjectPool.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.1623.17406"
}
}
},
"System.ComponentModel.Composition/8.0.0": {
"runtime": {
"lib/net8.0/System.ComponentModel.Composition.dll": {
"assemblyVersion": "8.0.0.0",
"fileVersion": "8.0.23.53103"
}
}
},
"System.Formats.Asn1/8.0.0": {},
"System.Security.AccessControl/6.0.0": {},
"System.Security.Cryptography.Pkcs/8.0.0": {
"dependencies": {
"System.Formats.Asn1": "8.0.0"
},
"runtime": {
"lib/net8.0/System.Security.Cryptography.Pkcs.dll": {
"assemblyVersion": "8.0.0.0",
"fileVersion": "8.0.23.53103"
}
},
"runtimeTargets": {
"runtimes/win/lib/net8.0/System.Security.Cryptography.Pkcs.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "8.0.0.0",
"fileVersion": "8.0.23.53103"
}
}
},
"System.Security.Cryptography.Xml/6.0.1": {
"dependencies": {
"System.Security.AccessControl": "6.0.0",
"System.Security.Cryptography.Pkcs": "8.0.0"
},
"runtime": {
"lib/net6.0/System.Security.Cryptography.Xml.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.822.36306"
}
}
},
"System.ServiceModel.Primitives/8.0.0": {
"dependencies": {
"Microsoft.Extensions.ObjectPool": "6.0.16",
"System.Security.Cryptography.Xml": "6.0.1"
},
"runtime": {
"lib/net8.0/System.ServiceModel.Primitives.dll": {
"assemblyVersion": "8.0.0.0",
"fileVersion": "8.0.23.60704"
}
},
"resources": {
"lib/net8.0/cs/System.ServiceModel.Primitives.resources.dll": {
"locale": "cs"
},
"lib/net8.0/de/System.ServiceModel.Primitives.resources.dll": {
"locale": "de"
},
"lib/net8.0/es/System.ServiceModel.Primitives.resources.dll": {
"locale": "es"
},
"lib/net8.0/fr/System.ServiceModel.Primitives.resources.dll": {
"locale": "fr"
},
"lib/net8.0/it/System.ServiceModel.Primitives.resources.dll": {
"locale": "it"
},
"lib/net8.0/ja/System.ServiceModel.Primitives.resources.dll": {
"locale": "ja"
},
"lib/net8.0/ko/System.ServiceModel.Primitives.resources.dll": {
"locale": "ko"
},
"lib/net8.0/pl/System.ServiceModel.Primitives.resources.dll": {
"locale": "pl"
},
"lib/net8.0/pt-BR/System.ServiceModel.Primitives.resources.dll": {
"locale": "pt-BR"
},
"lib/net8.0/ru/System.ServiceModel.Primitives.resources.dll": {
"locale": "ru"
},
"lib/net8.0/tr/System.ServiceModel.Primitives.resources.dll": {
"locale": "tr"
},
"lib/net8.0/zh-Hans/System.ServiceModel.Primitives.resources.dll": {
"locale": "zh-Hans"
},
"lib/net8.0/zh-Hant/System.ServiceModel.Primitives.resources.dll": {
"locale": "zh-Hant"
}
}
}
}
},
"libraries": {
"MendixCLIExtension/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Mendix.StudioPro.ExtensionsAPI/10.13.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-DZ6GftL5OU+Nz4sqTvoQmOY3TgrMviCC03CTYHIpwtSr0W1r/iWbwggwzA2xWlZmnaEKoK1Ljz2NeQk0Izdqjg==",
"path": "mendix.studiopro.extensionsapi/10.13.0",
"hashPath": "mendix.studiopro.extensionsapi.10.13.0.nupkg.sha512"
},
"Microsoft.Extensions.ObjectPool/6.0.16": {
"type": "package",
"serviceable": true,
"sha512": "sha512-OVX5tlKg6LY+XKqlUn7i9KY+6Liut0iewWff2DNr7129i/NJ8rpUzbmxavPydZgcLREEWHklXZiPKCS895tNIQ==",
"path": "microsoft.extensions.objectpool/6.0.16",
"hashPath": "microsoft.extensions.objectpool.6.0.16.nupkg.sha512"
},
"System.ComponentModel.Composition/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-bGhUX5BTivJ9Wax0qnJy7uGq7dn/TQkEpJ2Fpu1etg8dbPwyDkUzNPc1d3I2/jUr9y4wDI3a1dkSmi8X21Pzbw==",
"path": "system.componentmodel.composition/8.0.0",
"hashPath": "system.componentmodel.composition.8.0.0.nupkg.sha512"
},
"System.Formats.Asn1/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-AJukBuLoe3QeAF+mfaRKQb2dgyrvt340iMBHYv+VdBzCUM06IxGlvl0o/uPOS7lHnXPN6u8fFRHSHudx5aTi8w==",
"path": "system.formats.asn1/8.0.0",
"hashPath": "system.formats.asn1.8.0.0.nupkg.sha512"
},
"System.Security.AccessControl/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-AUADIc0LIEQe7MzC+I0cl0rAT8RrTAKFHl53yHjEUzNVIaUlhFY11vc2ebiVJzVBuOzun6F7FBA+8KAbGTTedQ==",
"path": "system.security.accesscontrol/6.0.0",
"hashPath": "system.security.accesscontrol.6.0.0.nupkg.sha512"
},
"System.Security.Cryptography.Pkcs/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ULmp3xoOwNYjOYp4JZ2NK/6NdTgiN1GQXzVVN1njQ7LOZ0d0B9vyMnhyqbIi9Qw4JXj1JgCsitkTShboHRx7Eg==",
"path": "system.security.cryptography.pkcs/8.0.0",
"hashPath": "system.security.cryptography.pkcs.8.0.0.nupkg.sha512"
},
"System.Security.Cryptography.Xml/6.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-5e5bI28T0x73AwTsbuFP4qSRzthmU2C0Gqgg3AZ3KTxmSyA+Uhk31puA3srdaeWaacVnHhLdJywCzqOiEpbO/w==",
"path": "system.security.cryptography.xml/6.0.1",
"hashPath": "system.security.cryptography.xml.6.0.1.nupkg.sha512"
},
"System.ServiceModel.Primitives/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-hVzK77Bl00H+1V7ho7h03tKlgxAIKssV3eUnRdH+gTCZCK4Ywnv2CR35AV9ly/tRpvsGwNL1d/jkAwB1MWw3Fw==",
"path": "system.servicemodel.primitives/8.0.0",
"hashPath": "system.servicemodel.primitives.8.0.0.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file modified resources/App/extensions/MxLintExtension/MxLintExtension.dll
Binary file not shown.
Binary file modified resources/App/extensions/MxLintExtension/MxLintExtension.pdb
Binary file not shown.
File renamed without changes.
Loading

0 comments on commit b80dd77

Please sign in to comment.