Book a Demo

Author Topic: Hide or minimise Project Browser  (Read 4818 times)

DarrenDickens

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Hide or minimise Project Browser
« on: July 17, 2017, 10:28:19 pm »
Is it possible to minimise the "Project Browser" via the Automation interface?

I ask because I am running a script (from Excel VBA) outside EA which is adding and deleting items in the model. While this is going on the Project Browser is flickering away as items are being added/deleted.

My script sets the following before updating
Code: [Select]
mRep.BatchAppend = True
mRep.EnableCache = True
mRep.EnableUIUpdates = False

My script sets the following after updating
Code: [Select]
mRep.EnableUIUpdates = True
mRep.EnableCache = False
mRep.BatchAppend = False
Call mRep.RefreshModelView(0)

According to the documentation I would have expected this to prevent the Project Browser from getting updated. Am I doing something wrong?

As an alternative is it possible to remove the Project Browser from the visible windows in EA via Automation? If the answer is yes, is it also possible to control the scripting window and other main EA windows?

I have managed to use AppActivate and SendKeys "%0^{F4}" but this is a bit of a fudge as there is a (small) possibility that another window gets focus and receives the keys. It also messes up my workflow when the focus is taken away from my main application (if the VBA script is running in the background). The "%0" is Alt+0 which (fortunately) always displays the Project Browser, i.e. doesn't toggle it. The "^{F4}" is Ctrl+F4 which hides the Project Browser.

Thanks
Darren

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Hide or minimise Project Browser
« Reply #1 on: July 18, 2017, 07:22:42 am »
The only official control I know of is the System Output which can be turned on programmatically. An non-official API can pop up the properties. But that's it. So you're bound to sending keyboard shortcuts to the application.

q.

DarrenDickens

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Hide or minimise Project Browser
« Reply #2 on: August 15, 2017, 02:14:02 am »
Just in case anyone comes across this thread and tries the SendKeys solution that I proposed...there is a problem with SendKeys in that sometimes it will turn off the NumLock key! My final code ended up like this...

  • This is Excel VBA code
  • OutputInternalError is a little routine I wrote that is effectively the same as Debug.Print
Code: [Select]
Option Explicit

' This module was based on https://www.mrexcel.com/forum/excel-questions/677200-vba-remember-numlock-state.html

#If VBA7 Then
Private Declare PtrSafe Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
#Else
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
#End If

' The SendKeys routine will sometimes turn off NumLock
' This routine fixes it
Public Sub FixSendKeys(ByVal sAppTitle As String, _
                       ByVal sKeys As String)
    Dim lSavedNumLockState As Boolean
   
    ' Save the current NumLock state
    lSavedNumLockState = NumLockStateIsOn

    ' Activate the required application and then send the keys to it
    '
    ' This might change (usually turn off) the NumLock key (the fault being fixed by this whole routine)
    AppActivate sAppTitle
    Application.SendKeys sKeys, True

    ' Check to see if the NumLock state has changed (fault of SendKeys)
    If lSavedNumLockState <> NumLockStateIsOn Then
        ' Simulate pressing NumLock key to set it back again
        Application.SendKeys "{NUMLOCK}", True
   
        ' Check again to make sure it has now changed
        If lSavedNumLockState <> NumLockStateIsOn Then
            ' Still hasn't changed
            OutputInternalError "NUMLOCK key still wrong"
        End If
    End If
End Sub

Private Function NumLockStateIsOn() As Boolean
    Const VK_NUMLOCK As Long = &H90
   
    ' IMPORTANT NOTE: It is necessary to call DoEvents to force a refresh of the keyboard state
    '                 Without DoEvents the keyboard state will sometimes return an old cached version
    DoEvents
    NumLockStateIsOn = (GetKeyState(VK_NUMLOCK) = 1)
End Function

and

Code: [Select]

Public Function GetEAWindowTitle() As String
    Dim sResult As String
    Dim vArr As Variant
   
   
   
    If IsModelEap() Then
        vArr = Split(mRep.ConnectionString, "\")
        sResult = vArr(UBound(vArr))
        sResult = Left(sResult, Len(sResult) - 4)
    Else
        vArr = Split(mRep.ConnectionString, " ---")
        sResult = vArr(0)
    End If
   
    sResult = sResult & " - Enterprise Architect"
   
    GetEAWindowTitle = sResult
End Function

Public Sub CloseEAProjectBrowser()
    ' Alt+0     View->Project Browser   (always opens the project browser - even if already open)
    ' Ctrl+F4   Close                   (closes the open window, i.e. the project browser)
    Call FixSendKeys(GetEAWindowTitle, "%0^{F4}")
End Sub

Public Sub OpenEAProjectBrowser()
    ' Alt+0     View->Project Browser   (always opens the project browser - even if already open)
    Call FixSendKeys(GetEAWindowTitle, "%0")
End Sub