Introduction to Creating Menus
How to Create Menus
Article By: Entity119
Article Written: 19th June, 2001
To perform the steps outlined in this tutorial, I strongly recommend that you download and install both Bersirc and the Script editor, both of which are available on the main site. Basically, the aim of this excercise is to allow you to create a simple menu that can be used to perfom a menial task that would otherwise had to have been typed out. For this example, we shall be setting up a menu item that, when clicked, prompts the user for input and then searches the Google site for corresponding matches.
1) Load up Bersirc, but leave the connection idle... have a status window open, but not connected to a server. This makes our job a bit easier - no distractions
2) Load up the script editor and open menus.ops
3) Examine the code up the top and find the section that starts with procedure
MakeStatusMenu;
begin
{ Status Menu }
ClearMenu(MNU_STATUS);
AddMenuItem(MNU_STATUS, '&Network Properties', 'Servlusers');
AddMenuItem(MNU_STATUS, '-', '');
.....(etc)
Looking at this, we can see that the code clears the menu in case of any updates, then displays the options shown, the first of which is '&Network properties' . Go into bersirc, right click on your status window and you will see a Network Properties icon. That is basically the structure of a menu.
4) Creating a menu that searches Google for us
Now, I know bersirc already has a google feature built in, but this method is a bit more user freindly, as it pops up an input box for the search term. How, you ask? Easy. Find a line in the menu code above, (mine was MOTD) and then press enter to get a new line. Now, for the menu, which is *pathetically* easy to do. Just copy the line above (MOTD or whatever) and paste it in the space. You will end up with something like:
AddMenuItem(MNU_STATUS, '&Message of the Day', 'ServMOTD');
to rename the text that is displayed on the menu, edit the text after the and symbol, being sure to keep inside the quote marks. Spacing is OK. Change it to 'Search Google For'
AddMenuItem(MNU_STATUS, '&Search Google For', 'ServMOTD');
5) Now, the (ServMOTD) part of the text is just as easy. replace that with 'searchgoogle'. No &
AddMenuItem(MNU_STATUS, '&Search Google For', 'searchgoogle');
6) Position your cursor somewhere near the bottom of the screen to avoid formatting errors, and go Tools Menu -> Insert new Procedure. Name it searchgoogle. Copy the following code:
procedure searchgoogle;
var
text: string;
begin
text := PromptEx('', 'Search Google For...', '');
if text <> '' then
run('http://www.google.com/search?q='+text);
end;
7) Now, to see if your procedure is working, click save. Go into bersirc and right click on the status window, and click the Google item we created earlier. A box will pop up, insert a query and your'e off!. You could also have a Search Google menu item in the Channel Right Click menu.. just copy the AddMenuItem code and paste it in the Channel Section. Be sure to change from MNU_STATUS to MNU_CHANNEL.
8) Not happy? Want a fancy icon to sit next to your menu item? place the following code in instead of the above.
AddMenuItemEx(MNU_STATUS, '&Search Google', 'searchgoogle',
'', true, false, false, false, 0, true, 8);
Replace the 8 with a number that corresponds with the icon you want. I am working on a list that matches each icon number with a description... I'll post it soon.
Conclusion
As far as I am concerned, I am a total tool when it comes to pascal coding. For the first week of my Bersirc experimentation, the basic gist of my IRC chats was "&%^#@ pascal" [albeit on multiple servers :)] The above code was basically just copy pasting code that was there, changing the vars a little bit and creating new procedures. I strongly urge you all to do the same... it can only mean more scripts for the bersirc community.
Biography
I am a 16 year old student from Australia. Currently doing several computer units at school and learning as many programming languages as possible. I enjoy scripting, IRC, open source software and can usually be found on Austnet in #aus3isp or #Entity119. If I'm not there, leave a msg.
-- Entity119
entity119@yahoo.com
http://entity119.vr9.com