From 7fef3349ecbb242c673491b25307391cf5fca26d Mon Sep 17 00:00:00 2001 From: Kamil Mierzejewski Date: Tue, 18 Apr 2023 17:07:19 +0200 Subject: [PATCH] Updated editor window to allow select between remote and local PlantUML server. --- src/vba/PlantUMLEdit.frm | 72 ++++++++++++++++++++++++++++----------- src/vba/PlantUMLEdit.frx | Bin 4120 -> 3608 bytes src/vba/PlantUml.bas | 37 ++++++++++++++------ 3 files changed, 78 insertions(+), 31 deletions(-) diff --git a/src/vba/PlantUMLEdit.frm b/src/vba/PlantUMLEdit.frm index a117917..b8d3a42 100644 --- a/src/vba/PlantUMLEdit.frm +++ b/src/vba/PlantUMLEdit.frm @@ -8,7 +8,6 @@ Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} PlantUMLEdit ClientWidth = 11415 ShowModal = 0 'False StartUpPosition = 1 'CenterOwner - TypeInfoVer = 105 End Attribute VB_Name = "PlantUMLEdit" Attribute VB_Base = "0{17C463E1-DDBC-4909-9F38-832D32AA2A81}{E0193FC7-C9E4-49DD-89A6-0C928B3CF82B}" @@ -62,11 +61,6 @@ Failed: Hide End Sub -Private Sub BrowseForJarButton_Click() - PlantUml.BrowseForJar - JarLocationTextBox.text = GetSetting("PlantUML_Plugin", "Settings", "JarPath") -End Sub - Private Sub UpdateDiagram(Optional Force As Boolean = False) If Initializing Then Exit Sub @@ -74,7 +68,7 @@ Private Sub UpdateDiagram(Optional Force As Boolean = False) WorkingLabel.Caption = "Working..." Dim continue As Boolean Do - continue = PlantUml.UpdateDiagram(Target, Code.text, TypeCombo.text, Force) + continue = PlantUml.UpdateDiagram(Target, Code.Text, TypeCombo.Text, Force) DoEvents Loop While continue And Not Force WorkingLabel.Caption = "" @@ -91,31 +85,72 @@ End Sub Private Sub FormatCombo_Change() - SaveSetting "PlantUML_Plugin", "Settings", "Format", FormatCombo.text + SaveSetting "PlantUML_Plugin", "Settings", "Format", FormatCombo.Text UpdateDiagram True End Sub -Private Sub JarLocationTextBox_Enter() - BrowseForJarButton.SetFocus - BrowseForJarButton_Click +Private Sub ServerComboBox_Change() + If Initializing Then + Exit Sub + End If + + If ServerComboBox.ListIndex = -1 Then + PlantUml.SetRemoteHttpAddress ServerComboBox.Value + Exit Sub + ElseIf ServerComboBox.ListIndex = 0 Then + PlantUml.SetRemoteHttpAddress ServerComboBox.Value + PlantUml.SetJarPath "" + ElseIf ServerComboBox.ListIndex < ServerComboBox.ListCount - 1 Then + PlantUml.SetJarPath ServerComboBox.Value + Else + PlantUml.BrowseForJar + End If + + SetupServerCombo End Sub Private Sub TypeCombo_Change() - EndLabel.Caption = "@end" & TypeCombo.text + EndLabel.Caption = "@end" & TypeCombo.Text Code_Change End Sub +Private Sub SetupServerCombo() + Initializing = True + Dim LocalJarPath As String + + ServerComboBox.Clear + ServerComboBox.AddItem PlantUml.GetRemoteHttpAddress() + + LocalJarPath = PlantUml.GetJarPath(False) + If LocalJarPath > "" Then + ServerComboBox.AddItem LocalJarPath + ServerComboBox.Value = LocalJarPath + ServerComboBox.Style = fmStyleDropDownList + Else + ServerComboBox.Value = PlantUml.GetRemoteHttpAddress() + ServerComboBox.Style = fmStyleDropDownCombo + End If + ServerComboBox.AddItem "Browse for 'plantuml.jar'..." + + MeasureTextBox.Text = ServerComboBox.Value + If MeasureTextBox.Width > ServerComboBox.Width - 16 Then + ServerComboBox.ControlTipText = ServerComboBox.Value + Else + ServerComboBox.ControlTipText = "" + End If + Initializing = False +End Sub + Private Sub UserForm_Activate() Hidden = False + SetupServerCombo Initializing = True - - JarLocationTextBox.Text = GetSetting("PlantUML_Plugin", "Settings", "JarPath") FormatCombo.Text = GetSetting("PlantUML_Plugin", "Settings", "Format", "svg") On Error Resume Next Set Target = ActiveWindow.Selection.ShapeRange(1) - TypeCombo.text = Target.Tags("diagram_type") - Code.text = Target.Tags("plantuml") + TypeCombo.Text = Target.Tags("diagram_type") + Code.Text = Target.Tags("plantuml") Code.SelStart = 0 Initializing = False @@ -152,7 +187,7 @@ Private Sub oFormResize_Resizing(ByVal X As Single, ByVal Y As Single) For Each Tag In Split(.Tag, ",") Select Case Tag Case "width" - .width = .width + X + .Width = .Width + X Case "height" .height = .height + Y Case "bottom" @@ -213,6 +248,3 @@ Public Sub Edit(Optional shp As Shape) End If End Sub -Private Sub UserForm_Terminate() - PlantUml.StopServer -End Sub diff --git a/src/vba/PlantUMLEdit.frx b/src/vba/PlantUMLEdit.frx index 47502f06ebada6b497ef45ed92a9436ee4eb47b9..9dada12efd919ce69bbbdd5b06fa0345eb19141a 100644 GIT binary patch delta 529 zcmXw$!Asj<7{;G3HffS3U1g}%4OT(4q86tf+$ftUh=&M*4tg6Ygn4L9ji1u7Ln{h9 zOoi@M@VI1$$nm~Xb2sF>Wv8&^1v_5w`i}vO zQO6wQ@3VAc9Mh$_-J|5OBGi3mA<`mB#@PrRnZy0v0eb|}!PuKPV;28-&u~4BWpU&bYl)>q zOx!eqs=kzd-EpaG4T%)F*0fORgr6E+S%Xxv2Xbjf7X6^^CUZa)yV%mXP-4cFZj+n^ z-+l!&qG6cDFYb_i=rA2SfWcfcKj!BBW*v|0ck_{*#NP)t`X?`0WtNFPEPL+OcHli( P^O}<31ZYgr5Buvq=X!te delta 601 zcma)&&ubGw6vy9eHk+O7E+nNtHll3`wWPF-poO9YyChPIL`CeuOVCZpp^$Xab&C8q1n6 zJ{=k##BgwjUA^sGocMI@=QoieB9Di9Uwq+wx-Z`HF#S@@v12@uvpD+`MUjil_kvy1 zmTR!0h-jbJ%`LO5VS6eX9GY)LhM#8V`I7Wjrl|xU;e zTT3~O3bgy8+p4KfQ?1k*d}bB5ISio)|1m&q3 zsOQgG+bTdy)uS*}2a#whXlGm9D-(6E$4yk|7xHue@@+V=y@N=hCQ|DdCLd3elpX{8 zkbhfCBF$Iq8^Yj+_-FXUUfl8$+N2xIm(VIuljbJ07`EH$g;mv)+63rIbj0WOLQbMC ry6*VnVKx40m*%s0m9d$;OJkf?Q_jtJ5I)y8`JHpj7kcTx!_&>b5VVvh diff --git a/src/vba/PlantUml.bas b/src/vba/PlantUml.bas index 2580403..94bf879 100644 --- a/src/vba/PlantUml.bas +++ b/src/vba/PlantUml.bas @@ -67,10 +67,15 @@ Function GetJarPath(Optional Interactive As Boolean = True) End If End Function +Sub SetJarPath(path As String) + SaveSetting "PlantUML_Plugin", "Settings", "JarPath", path +End Sub + Function BrowseForJar() With Application.FileDialog(msoFileDialogOpen) .AllowMultiSelect = False .Title = "Path to plantuml.jar" + .Filters.Clear .Filters.Add "Jar Files", "*.jar", 1 .InitialFileName = GetJarPath(False) .Show @@ -78,7 +83,7 @@ Function BrowseForJar() Exit Function End If BrowseForJar = .SelectedItems(1) - SaveSetting "PlantUML_Plugin", "Settings", "JarPath", .SelectedItems(1) + SetJarPath .SelectedItems(1) End With End Function @@ -113,8 +118,10 @@ Function WriteToTmpBinFile(content() As Byte, format As String) WriteToTmpBinFile = FileName End Function -Function GetPicowebEndpoint() - GetPicowebEndpoint = GetSetting("PlantUML_Plugin", "Settings", "PicowebEndpoint") +Function GetPicowebEndpoint() As String + If GetJarPath(False) > "" Then + GetPicowebEndpoint = GetSetting("PlantUML_Plugin", "Settings", "PicowebEndpoint", "8880") + End If End Function Function GetPicowebAddress() @@ -133,10 +140,18 @@ Function GetHttpServerAddress() GetHttpServerAddress = GetPicowebAddress() If GetHttpServerAddress = "" Then - GetHttpServerAddress = GetSetting("PlantUML_Plugin", "Settings", "HttpServerAddress", "https://www.plantuml.com") + GetHttpServerAddress = GetRemoteHttpAddress() End If End Function +Function GetRemoteHttpAddress() + GetRemoteHttpAddress = GetSetting("PlantUML_Plugin", "Settings", "HttpServerAddress", "https://www.plantuml.com") +End Function + +Function SetRemoteHttpAddress(address As String) + SaveSetting "PlantUML_Plugin", "Settings", "HttpServerAddress", address +End Function + Public Sub StartServer() If Not PlantServer Is Nothing Or GetPicowebEndpoint() = "" Then Exit Sub @@ -174,7 +189,7 @@ Function GenerateDiagramHttp(body As String, Tag As String, format As String) WinHttpReq.Open "GET", GetHttpServerAddress() & "/plantuml/" & format & "/~h" & StringToHex(request), True WinHttpReq.Send WinHttpReq.WaitForResponse - Dim response() as Byte + Dim response() As Byte response = WinHttpReq.ResponseBody GenerateDiagramHttp = WriteToTmpBinFile(response, format) End Function @@ -233,7 +248,7 @@ Public Function UpdateDiagram(shp As Shape, body As String, Tag As String, Optio End If shp.Tags.Add "plantuml", body - shp.Tags.Add "diagram_type", tag + shp.Tags.Add "diagram_type", Tag If body = "" Then shp.Fill.Transparency = 1# @@ -266,7 +281,7 @@ Public Sub SetPicture(shp As Shape, fname As String, format As String) shp.Fill.UserPicture (fname) Dim w As Single, h As Single, scaleX As Single, scaleY As Single - scaleX = GetScale(shp.Tags("orig_width"), shp.width) + scaleX = GetScale(shp.Tags("orig_width"), shp.Width) scaleY = GetScale(shp.Tags("orig_height"), shp.height) If format = "svg" Then @@ -279,24 +294,24 @@ Public Sub SetPicture(shp As Shape, fname As String, format As String) Set wia = CreateObject("WIA.ImageFile") wia.LoadFile fname w = wia.Width - h = wia.Height + h = wia.height End If shp.Tags.Add "orig_width", w shp.Tags.Add "orig_height", h - shp.width = w * scaleX + shp.Width = w * scaleX shp.height = h * scaleY Kill fname End Sub -Sub PlantUMLBtn_GetEnabled(control As IRibbonControl, ByRef returnedVal) +Sub PlantUMLBtn_GetEnabled(Control As IRibbonControl, ByRef returnedVal) On Error Resume Next returnedVal = Not Application.ActiveWindow.View.Slide Is Nothing End Sub -Sub PlantUMLEdit_GetVisible(control As IRibbonControl, ByRef returnedVal) +Sub PlantUMLEdit_GetVisible(Control As IRibbonControl, ByRef returnedVal) returnedVal = ActiveWindow.Selection.ShapeRange.Count = 1 And ActiveWindow.Selection.ShapeRange(1).Tags("diagram_type") > "" End Sub