Skip to content

Commit

Permalink
Updated editor window to allow select between remote and local PlantU…
Browse files Browse the repository at this point in the history
…ML server.
  • Loading branch information
kmierzeje committed Apr 18, 2023
1 parent 60ac4d2 commit 7fef334
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 31 deletions.
72 changes: 52 additions & 20 deletions src/vba/PlantUMLEdit.frm
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -62,19 +61,14 @@ 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
End If
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 = ""
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -213,6 +248,3 @@ Public Sub Edit(Optional shp As Shape)
End If
End Sub

Private Sub UserForm_Terminate()
PlantUml.StopServer
End Sub
Binary file modified src/vba/PlantUMLEdit.frx
Binary file not shown.
37 changes: 26 additions & 11 deletions src/vba/PlantUml.bas
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,23 @@ 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
If .SelectedItems.Count = 0 Then
Exit Function
End If
BrowseForJar = .SelectedItems(1)
SaveSetting "PlantUML_Plugin", "Settings", "JarPath", .SelectedItems(1)
SetJarPath .SelectedItems(1)
End With
End Function

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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#
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 7fef334

Please sign in to comment.