Treeview Switchbar Tutorial

Contributed by Synthet|c

Introduction :
In this tutorial, i will be explaining the easiest way to make a treeview switchbar.. All the coding was made by me: shawnreid aka synthet|c and [jamie[] aka [morpheus] It is free source and you may use the example treeview switchbar but i would prefer if you didnt call it your own (none the less give us credit for the work we deserve) any problems send to [email protected]. In order to use this you must have the following files:

ktools.dl

mdx.dll

views.mdx,

You will also need the aliases i provide below.

alias ktool { return "dll/path/ktools.dll" }
alias udll { return "dll/path/mdx.dll" }
alias vdll { return "ext/path/views.mdx" }

After putting the following aliases in your remotes we can get down to business, if you don't have ktools.dll mdx.dll or views.mdx you can go to the following URLs find these files:

ktools.dll - http://www.creationcorner.org
mdx.dll - http://www.dim-bulb.net/~dragonzap/dlls/ (Note: You can also get views.mdx here).

Now we move on to the basics in the next part.

The Basics :
Here is where it gets more complicated.In this part you fill the given the init event code and a treeview dialog as an example.

First you will need the dialog, i will supply a sample:


dialog switchbar {
� title "switchbar"
� size -1 -1 160 2000
� list 1, 1 -1 163 400, size
}

That is a� nice plain example, now moving on to the more complex part -- the init event code. If you have problems always refer to the introduction, i don't mind helping in emails or on� IRC. This is the init event code, i will try to explain it as much as i can :
on *:dialog:switchbar:init:0:{
� mdx.load
;here it is loading the dll mdx. you can change this with the mark function in mdx.
� dll $udll SetDialog $dname style
� dll $udll SetControlMDX $dname 1 treeview haslines hasbuttons showsel rowselect insertdroptarget > $vdll
;Here we set the treeview function
� var %s = $dll($ktool,DockWindow,$dialog(switchbar).hwnd > left)
;docking the switchbar (Note: you can change left to right and it will dock on the opposite side a nice timbit of info :-?)
� load.switchbar
� ;this is the main part of the switchbar, it is the main alias you will be given a sample and how to use it in the next part.
}

There you go the init event code now were moving along right to chapter 3!

/switchbar.load :
As mentioned above this is the most important part in making a treeview switchbar, here we will learn how to list channels, servers, querys, get, chat, and send windows. I will provide a sample and a document of what is happening in the alias. Here is the alias sample:

alias load.switchbar {
� ;clearing switchbar for refresh.
did -r switchbar 1
� ;setting icons, you may change them (i use shell.dll with my icons in there change them to fit the example)
did -i switchbar 1 1 iconsize normal small
did -i switchbar 1 1 seticon normal 72,system\dlls\shell.dll
did -i switchbar 1 1 seticon normal 68,system\dlls\shell.dll
did -i switchbar 1 1 seticon normal 71,system\dlls\shell.dll
did -i switchbar 1 1 seticon normal 66,system\dlls\shell.dll
did -i switchbar 1 1 seticon normal 76,system\dlls\shell.dll
did -i switchbar 1 1 seticon normal 76,system\dlls\shell.dll
did -i switchbar 1 1 seticon normal 76,system\dlls\shell.dll
var %a = 1
while (%a <= $scid(0)) {
� ;loading the connected servers!
scon %a
did -i switchbar 1 1 cb root
did -a switchbar 1 +eb 1 1 $iif($scid(%a).network == $null,$scid(%a).server,$scid(%a).network)
did -i switchbar 1 1 cb last
did -a switchbar 1 +e 2 2 Channels $tab Channels
did -i switchbar 1 1 cb last
var %x = 1
� ;listing channels!
while (%x <= $chan(0)) {
did -a switchbar 1 + 2 2 $chan(%x) $tab $chan(%x)
inc %x
}
did -i switchbar 1 1 cb up
did -a switchbar 1 +e 3 3 Queries $tab Queries
did -i switchbar 1 1 cb last
var %x = 1
� ;listing queries!
while (%x <= $query(0)) {
did -a switchbar 1 + 3 3 $query(%x) $tab $query(%x)
inc %x
}
inc %a
}
� ;Making branch for dcc.
did -i switchbar 1 1 cb root
did -a switchbar 1 +eb 7 7 DCC $tab DCC
did -i switchbar 1 1 cb last
did -a switchbar 1 + 7 7 Get $tab Get
did -i switchbar 1 1 cb last
var %x = 1
� ;listing get files
while (%x <= $get(0)) {
did -a switchbar 1 + 7 7 $get(%x) $tab $get(%x)
inc %x
}
did -i switchbar 1 1 cb up
did -a switchbar 1 + 7 7 Send $tab Send
did -i switchbar 1 1 cb last
var %x = 1
� ;listing send files
while (%x <= $send(0)) {
did -a switchbar 1 + 7 7 $send(%x) $tab $send(%x)
inc %x
}
did -i switchbar 1 1 cb up
did -a switchbar 1 + 7 7 Chat $tab Chat
did -i switchbar 1 1 cb last
var %x = 1
� ;Listing chat windows
while (%x <= $chat(0)) {
did -a switchbar 1 + 7 7 $chat(%x) $tab $chat(%x)
inc %x
}
did -i switchbar 1 1 cb up
}

there you go a simple /load.switchbar alias. I know it wasnt explained in much detail but look at the coding and its really easy to use (the branches).For more help on this download Roger Adam's (pr0n^king) MDX tutorial.

Events :
You are still here? heh. Congrats you made it this far. Here is� where it starts getting easy until the sclick events! Right here i will just show you the events, you need to copy them into your script and they should work fine.

alias query { query $1- | .timer -m 1 1 load.switchbar }
alias server { server $1- | .timer -m 1 1 load.switchbar }

on *:join:#:{ if ($nick == $me) { .timer -m 1 1 load.switchbar } }
on *:connect:{ .timer -m 1 1 load.switchbar }
on *:part:#:{ if ($nick == $me) { .timer -m 1 1 load.switchbar } }
on *:open:@:{ .timer -m 1 1 load.switchbar }
on *:close:@:{ .timer -m 1 1 load.switchbar }
on *:open:?:{ .timer -m 1 1 load.switchbar }
on *:close:?:{ .timer -m 1 1 load.switchbar }
on *:close:*:{ if ($target == "status window") { .timer -m 1 1 load.switchbar } }

They are pretty much self explanatory.

SCLICK Events! (Chapter 5):
Now comes the hardest part, this might be a little bit complex but i will try to explain it to the best of my ability.
Like before i'll paste the code and explain it, before reading this you should have a basic understanding of Multi Serv aliases.
Type /help multi serv for more information on the subject.

on *:dialog:switchbar:sclick:*:{
� if ($did == 1) {
��tokenize 32 $did(1,1,1)
��if ($4) && (!$5) {
���� scon $calc($4 - 1)
�����;right here it is changing the scon so you can show the status window on the selected server
���� window -a "status window"
�����;activating status window the the scon server.
�� }
��elseif ($5 = 2) && ($6) {
����scon $calc($4 - 1)
����;right here it is changing the scon so you can show the channel window on the selected server
����window -a $chan($calc($6 - 1))
����;activating channel window the the scon server.
�� }
��elseif ($5 = 3) && ($6) {
���� scon $calc($4 - 1)
���� ;right here it is changing the scon so you can show the query window on the selected server
���� window -a $query($calc($6 - 1))
���� ;activating query window the the scon server.
�� }
�� ;that is basically all you need for the channel/query/server windows
���if ($calc($4 - 1) > $scid(0)) {
�� ;Checking to see if it is the DCC branch
����if ($6) {
������if ($5 == 2) {
��� �� ;Checking if the active branch is gets.
������� window -a "Get $get($calc($6 - 1)) $get($calc($6 - 1)).file $+ "
��� �� ;Activating, or showing the selected get window
����� }
������elseif ($5 == 3) {
�� �� �� ;Checking if the active branch is sends.
�������� window -a "Send $send($calc($6 - 1)) $send($calc($6 - 1)).file $+ "
����� �� ;Activating, or showing the selected send window
����� }
������elseif ($5 == 4) {
� �� �� ;Checking if the active branch is Chats.
������� window -a = $+ $chat($calc($6 - 1))
����� �� ;Activating, or showing the selected chat window
����� }
����}
��}
}

Now you have a better understanding of a treeview switchbar and how it works for more help on the subject type /help for related subjects such as /window, $get, $send, $chat, $chan, and multi serv.

What Will I Be Adding Next:
well in this chapter i forgot some things that i didnt have the energy to make such as a @win branch, next version i will add that, and highlighting if you have suggestions email me.

All content is copyright by mircscripts.org and cannot be used without permission. For more details, click here.