Special Question about IDE-Tools

Working on new editor enhancements?
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Special Question about IDE-Tools

Post by Bisonte »

Is it possible to trigger a menu item of the IDE, from an external tool ( e.g. "Restart Compiler" ) ?

And if the answer is yes... How ? ;)
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Axolotl
Enthusiast
Enthusiast
Posts: 798
Joined: Wed Dec 31, 2008 3:36 pm

Re: Special Question about IDE-Tools

Post by Axolotl »

@Bisonte,

you can try this on your own risk.

Code: Select all

EnableExplicit 
; Edit: Windows only solution: 
; Easy MenuItem Constants 
; 
#MENUINDEX_Compiler = 4   ; "Compiler" 
#MENUINDEX_RestartCompiler   = 7  ; "Re&start Compiler"    ..... this is the correct menu item for Restart Compiler 
;#MENUINDEX_RestartCompiler  = 9  ; "Compiler Options..."  ..... for test reasons -> this shows the Options Dialog 

; --- 

Procedure GetPureBasicMainWindowHandle() 
  Protected hwndMain  

  ; 
  ; simplified version 
  ; 
  hwndMain = FindWindow_("WindowClass_2", #Null)  ; handle of Purebasic main window 

  ProcedureReturn hwndMain  
EndProcedure 

; --- 

Procedure.s ReadMenuItemText(hMenu, Index) 
  Protected mii.MENUITEMINFO 
  Protected text$ 

  mii\cbSize = SizeOf(MENUITEMINFO) 
  mii\fMask = #MIIM_STRING 
  mii\fType = #MFT_STRING 

  mii\dwTypeData = 0    ; <= get the needed length 
  If GetMenuItemInfo_(hMenu, Index, #True, @mii)          ; : Debug "cch = " + mii\cch 
    text$ = Space(mii\cch)    
    mii\dwTypeData = @text$
    If GetMenuItemInfo_(hMenu, Index, #True, @mii) 
      text$ = PeekS(mii\dwTypeData, mii\cch)   ; success 
    Else 
      text$ = "" ; failure 
    EndIf 
  EndIf 
  ProcedureReturn text$ 
EndProcedure 

; --- 

Procedure GetMenuItemSubMenu(hMenu, Index) 
  Protected result, mii.MENUITEMINFO 

  mii\cbSize = SizeOf(MENUITEMINFO) 
  mii\fMask = #MIIM_SUBMENU  
  If GetMenuItemInfo_(hMenu, Index, #True, @mii) 
    ProcedureReturn mii\hSubMenu 
  EndIf 
  ProcedureReturn 0 
EndProcedure 

; --- 

Procedure SendMenuItemClick(hWnd, hMenu, Index) 
  Protected nMenuID 

  nMenuID = GetMenuItemID_(hMenu, Index) 
  PostMessage_(hWnd, #WM_COMMAND, nMenuID, #Null)   ; hit the menu...
EndProcedure 

; --- 

Procedure SendRestartCompilerClick() 
  Protected hwndPB, hMenu, hSubMenu 
  Protected text$ 

  hwndPB = GetPurebasicMainWindowHandle() 
  If hwndPB 

    hMenu = GetMenu_(hwndPB) 
    If hMenu 
;     text$ = ReadMenuItemText(hMenu, #MENUINDEX_Compiler) 
;     Debug "  MenuItem [" + #MENUINDEX_Compiler + "] = '" + text$ + "'" 

      hSubmenu = GetMenuItemSubMenu(hMenu, #MENUINDEX_Compiler) 
      If hSubmenu 
;       text$ = ReadMenuItemText(hSubMenu, #MENUINDEX_RestartCompiler) 
;       Debug "  MenuItem [" + #MENUINDEX_RestartCompiler + "] = '" + text$ + "'" 
  
        SendMenuItemClick(hwndPB, hSubmenu, #MENUINDEX_RestartCompiler) 
      EndIf 
    EndIf 
  EndIf 
EndProcedure 


SendRestartCompilerClick() 
Last edited by Axolotl on Thu Jan 02, 2025 2:26 pm, edited 1 time in total.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: Special Question about IDE-Tools

Post by Bisonte »

Nice approach, but unfortunately this will only work on Windows.
At some point freak had mentioned making IDE functions accessible
via external tools (unfortunately I can't find the post at the moment)
and it could have been that it somehow slipped past me unnoticed...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 559
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Special Question about IDE-Tools

Post by Sicro »

Bisonte wrote: Thu Jan 02, 2025 2:00 am At some point freak had mentioned making IDE functions accessible
via external tools (unfortunately I can't find the post at the moment)
Here is freak's feature thread:
viewtopic.php?t=44895

The feature was canceled:
https://github.com/fantaisie-software/p ... c/pull/169
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Axolotl
Enthusiast
Enthusiast
Posts: 798
Joined: Wed Dec 31, 2008 3:36 pm

Re: Special Question about IDE-Tools

Post by Axolotl »

Yeah, sorry. I am on windows, only.
Trying Linux, but still not sure if I stay with PB on Linux.
So another answer to your Question: Maybe this is available on Linux and MacOS:
1. Create a shortcut
2. Call the shortcut by (I dont know) SendKeys() or similar.
BTW: Is this section only intended for platform-independent solutions?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply