[Gambas-user] Problem with code made menu event handling
Willy Raets
willy at ...2734...
Sun Oct 7 02:49:29 CEST 2012
Hi,
I'm working on a Add On enabled application.
Have this module called AddOns taking care of things.
I looks in a hidden folder AddOns for the file AddOnsInfo
This file content looks like this (without the ---):
---
2
AddOnOne
AddOnTwo
---
2 means two AddOns are in the AddOns folder (normal gambas application
executabes) Next are the names of these AddOns.
The names are used for in the menu and to start the add ons.
>From the file the module makes the menu items.
This all goes well.
With 1 AddOn in the file (lets say AddOnOne) the menu shows AddOnOne and
when clicking runs the application AddOnOne
With 2 AddOns in the file (lets say AddOnOne and AddOnTwo) the menu
shows AddOnOne and AddOnTwo and When clicking either one of them
AddOnTwo is ALWAYS run.
This somehow makes sense to me looking at my code.
But how do I determine what menu item is clicked and make the event
start the proper add on.
After searching in the documentation and google searches all day I'm
not finding the proper way of dealing with this.
Here is the module code:
'----------------------------------------
' Gambas module file
'
' ---------------------------------------
' Application: AddOnTest
' Module: AddOns
' Author: W.J.L. Raets
' GNU General Public Licence - Version 3
' ---------------------------------------
Private AddOnPath As String
Private AddOnNumber As Integer
Private AddOnName As New String[10]
Private hMenu As Menu
Private hMenuItem As Menu
Public Sub SetAddOnsPath(PathToAddOns As String, ParentMenu As Menu)
AddOnPath = PathToAddOns
hMenu = ParentMenu
ReadInfo
End
Private Sub ReadInfo()
Dim hFile As File
Dim sPath, sLine As String
Dim iNdex As Integer
sPath = AddOnPath & "/AddOnsInfo"
'-- Read file values --
hFile = Open sPath For Input
iNdex = 0
Line Input #hFile, sLine
AddOnNumber = Val(sLine)
If AddOnNumber <> 0 Then
For iNdex = 1 To AddOnNumber
If Not Eof(hFile) Then
Line Input #hFile, sLine
AddOnName[iNdex] = sLine
Else
AddOnNumber = AddOnNumber - 1
Endif
Next
hFile.Close
'--
For iNdex = 1 To AddOnNumber
hMenuItem = New Menu(hMenu) As "_MenuEvent"
With hMenuItem
.Name = "mnu" & AddOnName[iNdex]
.Enabled = True
.Caption = AddOnName[iNdex]
.Text = AddOnName[iNdex] & "..."
End With
Next
Endif
If hMenu.Children.Count = 0 Then
hMenu.Visible = False
Endif
End
Public Sub _MenuEvent_Click()
Dim iX, iLength As Integer
Dim AddOnToRun As String
iLength = Len(hMenuItem.Caption)
AddOnToRun = Left$(hMenuItem.Caption, (iLength - 3))
AddOnToRun = AddOnToRun & ".gambas"
Message(AddOnToRun)
AddOns.Run(AddOnToRun)
End
Public Sub Run(AddOnName As String)
Dim sPath As String
Dim hProcess As Process
sPath = AddOnPath & "/" & AddOnName
hProcess = Shell sPath Wait
hProcess.Kill
End
'-------------------------------
Maybe someone can point me in the proper direction.
Thanks,
Willy
More information about the User
mailing list