View Full Version : Tree menu
Brave Heart
01-10-2007, 03:47 PM
Hi
I have a project with about 100 pages. What is the best idea to be
used with Tree menu for page jump?
Thanks
RizlaUK
01-10-2007, 05:21 PM
hey, the tree can be quite tempermental at times, so with that in mind i wont bother trying to explain how to do it so i just made this quick example for you,
set the node data like "Page1" without the quotes and any node that dosent jump to a page set the data to "0" without the quotes or you will get errors
Brave Heart
01-11-2007, 12:50 AM
Thanks dear for your help.
How can I use "On Select" instead of "On Double-Click"?
I tried touse the same script written under "On double-Click" but I
got errors.
Thank you.
RizlaUK
01-11-2007, 04:14 AM
yeah, like i say the tree can be quite tempermental, i havent successfully used the tree to jump page with onselect, in fact i seem to get all werid things going on whenever i put code in the onselect event it seems to enter into some kind of loop, and just lock up
but in double click all seem to be fine
sorry i couldent be of more help, maybe one of the more experianced users can help
azmanar
01-11-2007, 05:14 AM
Hi,
I have 2 examples (http://azman.info/ams) about Tree Page Jump:
1. Tree Page Jump onDoubleClick
2. Tree Page Jump onSelect
For each example, you need to view codes at:
1. GLOBAL FUNCTION AREA
2. On Each Page at the PRELOAD and ONSHOW.
So far both examples work without an endless loop or locking up.
Try them at your end and customise to your needs.
Hope this helps.
RizlaUK
01-11-2007, 08:27 AM
azmanar, both your examples work fine and are very usefull, but if a project has many pages it will be a lot of code, i was trying to go for simplicity,
maybe you can help me out here
this is the code im useing to jump page, the node data is "Page1", "Page2" etc
tblTreeProps = Tree.GetNode(this, e_NodeIndex)
JumpTo = tblTreeProps.Data
if JumpTo ~= "0" then
Page.Jump(JumpTo)
end
when the code is placed in double click it works perfect but if i put it in the on select event the tree goes crazy, i just can not work out why it will work in one event but not in an other
i even tryed error checking with the below code but it still dose the same thing without giving any error warnings
tblTreeProps = Tree.GetNode(this, e_NodeIndex)
JumpTo = tblTreeProps.Data
if JumpTo ~= "0" then
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
Page.Jump(JumpTo)
end
end
i attached the apz, if you have the time i would be greatful for some advice
or is it that my code is just not up to the job ?
TJ_Tigger
01-11-2007, 09:54 AM
Works here with a single click. I have added some (uncommented) code that I hope will help with populating the tree and how to use it to navigate. I even added the capability to break your pages into sets like you hade in an earlier example. I don't know how this would work with 100 pages.
Give it a shot I didn't change much only the page names to be able to divide into sets, on page 1 there is a function to populate the tree with pages dynamically and minor tweaks (if then check) to the On Select script.
Tigg
TJ_Tigger
01-11-2007, 10:14 AM
Here is one where I duplicated the pages to show how it works with multiple pages. There are a few other tweaks as well like only expanding the section of the tree for the current page section.
Tigg
TJ_Tigger
01-11-2007, 10:29 AM
Here is the function for populating a tree with all the pages in your project for those who might not want to download the project. There is a lot of potential and ways to accomplish this task. This will divide pages into groups of up to 9 if the page begins with the numbers 1-9. If the page name begins with 0 or an alphabetic character it won't be added to the list, or at least it shouldn't, I dont think I tested it.
100 Pages is a lot of pages. With the capability to dynamically set information on a page do you need 100 pages.
function PopTree(strTName)
local strTName = strTName;
local tPages = Application.GetPages();
if tPages then
Tree.RemoveNode(strTName, "0");
nSets = 7;
for x = 1,nSets do
local bCurrent = false
if x == String.ToNumber(String.Left(Application.GetCurrent Page(), 1)) then bCurrent = true end
-- Initialize node data table
local tblNodeData = {};
tblNodeData.Text = "Page Set "..string.format("%02.f", ""..x);
tblNodeData.Data = "";
tblNodeData.Expanded = bCurrent;
tblNodeData.NodeIndex = ""..x;
tblNodeData.ImageIndex = 0;
tblNodeData.SelectedImageIndex = 0;
-- Insert the node
Tree.InsertNode("Tree1", ""..x,tblNodeData);
end
for i,v in tPages do
if tPages[i] ~= Application.GetCurrentPage() then
nSet = String.ToNumber(String.Left(tPages[i], 1));
if nSet > 0 then
--this line assumes that you have only single digit sets. If you have more than 9 then you will have to find where the page name starts
strPName = String.Mid(tPages[i], 2, -1);
local tblNodeData = {};
tblNodeData.Text = strPName;
tblNodeData.Data = tPages[i];
tblNodeData.Expanded = false;
tblNodeData.NodeIndex = nSet.."."..i;
tblNodeData.ImageIndex = 0;
tblNodeData.SelectedImageIndex = 0;
-- Insert the node
Tree.InsertNode("Tree1", nSet.."."..i, tblNodeData);
end
end
end
end
end
Bruce
01-11-2007, 11:08 AM
Tigg on a roll! LOL Gotta love 'em! :yes
RizlaUK
01-11-2007, 11:12 AM
Hey Tigg, works for you huh, i guessing iv got something wrong on my system, i think it maybe time for a low level format and start again,
the changes you made fix the bug i was having, but i still get the odd eratic page change, but every 5 or so page jumps, i have to click the tree node 2 or 3 times to get it to jump to that page (but its better than just locking up or going into a crazy loop)
but as you say it worked for you then it must be my system or my ams install that is at fault, i'll try reinstalling ams 1st and see if the original one works, if not them i'll format my hdd (to kill any bugs) and give it a try with a fresh system
and that function to pop the tree is well handy, thanks, that will save some work
well, guess its time to backup and destory
usernameCasper
07-23-2007, 05:49 AM
Hey guys,
Im back after almost 1 year, and wanted to pick up
an old project, when I have the same problem.
I tried over 10 ways to do it, setting up a log of
debugging progress. It's making a loop when you
select a node in the tree object, when you want
to jump to another page, on the third select instruction.
This was the main issue for over 10 attempts to make a
pagejump.
Unfortunately, I didn't save the source from the attempts
to solve the problem, but saving it to one file, not in file
cabinets to make version management.
But I logged the main issue, so you get a better idea how
the loop works.
Results of scriptcode execution with their instructions:
*) Startup application
1) Select node 2
└> e_NodeIndex: 2 ┐-OK √
2) Select node 1 <┘
└> e_NodeIndex: 1 ┐-OK √
3) Select node 2 <┘
└> e_NodeIndex: 2 ┐-OK √
OK X-┌ e_NodeIndex: 1 <┘
└> e_NodeIndex: ┐-OK X
OK √-┌ e_NodeIndex: 2 <┘
└> e_NodeIndex: ┐-OK X
OK X-┌ e_NodeIndex: 1 <┘
┌----┘
4) Select node 1
└> e_NodeIndex: 1 ┐-OK √
OK √-┌ e_NodeIndex: 1 <┘
└> e_NodeIndex: ┐-OK X
OK √-┌ e_NodeIndex: 1 <┘
┌----┘
5) Select node 2
└> e_NodeIndex: 2 ┐-OK √
etc. <┘
Legend:
----------------------
OK √ = Value is correct
OK X = Value is incorrect
Codeblock for loop (in this example):
step: 2,3,4
Script in headlines:
On Select --> Page.Jump(e_NodeIndex)
On Preload --> Tree.SetSelectedNode("Tree1", ""); --> Thats why e_NodeIndex: ..., where ... = NULL/blanc/empty string, with this method, you bypass the looping, while it loops in a strange manor to bypass the infinite loop.
Conclusion:
Every page have their own Tree object (static) and have their own memory management. When you jump pages, each page will save the results of the instructions being performed or were performered during that page, so when you switch pages, you see different results of the Tree object, like expanded/collapsed nodes, different data/text for a certain node.
To bypass it, save the results being performed on a tree when something is select/expand in the global variables, so that when you jump to another page the Tree can be created dynamically. This works fine for me, although the short loop still exist when you select different nodes (kinda weird, looks like the e_NodeIndex got differents memory storages with their own values, while the e_NodeIndex is not being overwrite, caused by the instruction Select, wrong parsing instructionset??)
Its still buggy though, cause sometimes the page loads different values for nodes when jumps, for example the expanded nodes.
IMHO, the Tree->Page Navigation is pretty bugged.
Maybe an idea for the Suggestion Forum?
i guessing iv got something wrong on my system, i think it maybe time for a low level format and start again,
No need for, the way Tig did is the way to go, make it dynamically (or give variables values to static trees to manage the trees seperately).
Your sincerely,
Casper
usernameCasper
07-23-2007, 06:09 AM
EDIT:
After testing Tig's source at the attachment, the runned process is still in an infinite loop when switching couple pages.
Put the code below into a new project, it works fine for me, although sometimes buggy (when you have to click twice on a node) when you perform to many switches.
------------------------------[[ SCRIPT: Global Script ]]------------------------------
blnNodeExpanded_1 = false;
blnNodeExpanded_2 = false;
blnNodeExpanded_3 = false;
function treeHandler_ExpandedNodes()
if e_NodeIndex == "1" and e_Expanded == true then
blnNodeExpanded_1 = true;
elseif e_NodeIndex == "1" and e_Expanded == false then
blnNodeExpanded_1 = false;
elseif e_NodeIndex == "2" and e_Expanded == true then
blnNodeExpanded_2 = true;
elseif e_NodeIndex == "2" and e_Expanded == false then
blnNodeExpanded_2 = false;
elseif e_NodeIndex == "3" and e_Expanded == true then
blnNodeExpanded_3 = true;
elseif e_NodeIndex == "3" and e_Expanded == false then
blnNodeExpanded_3 = false;
end
end
function treeHandler_OpbouwenTree()
Tree.SetSelectedNode("Tree1", "");
Tree.EnsureVisible("Tree1", Application.GetCurrentPage());
if blnNodeExpanded_1 == true then
Tree.ExpandNode("Tree1","1");
end
if blnNodeExpanded_2 == true then
Tree.ExpandNode("Tree1","2");
end
if blnNodeExpanded_3 == true then
Tree.ExpandNode("Tree1","3");
end
end
function treeHandler_Geselecteerd()
end
------------------------------[[ SCRIPT: Page: 2.1, Event: On Preload Script ]]------------------------------
treeHandler_OpbouwenTree();
------------------------------[[ SCRIPT: Page: 2.1, Object: Tree1, Event: On Select Script ]]------------------------------
Page.Jump(e_NodeIndex);
------------------------------[[ SCRIPT: Page: 2.1, Object: Tree1, Event: On Expanded Script ]]------------------------------
treeHandler_ExpandedNodes();
------------------------------[[ SCRIPT: Page: 1, Event: On Preload Script ]]------------------------------
treeHandler_OpbouwenTree();
------------------------------[[ SCRIPT: Page: 1, Object: Tree1, Event: On Select Script ]]------------------------------
Page.Jump(e_NodeIndex);
------------------------------[[ SCRIPT: Page: 1, Object: Tree1, Event: On Expanded Script ]]------------------------------
treeHandler_ExpandedNodes();
------------------------------[[ SCRIPT: Page: 2, Event: On Preload Script ]]------------------------------
treeHandler_OpbouwenTree();
------------------------------[[ SCRIPT: Page: 2, Object: Tree1, Event: On Select Script ]]------------------------------
Page.Jump(e_NodeIndex);
------------------------------[[ SCRIPT: Page: 2, Object: Tree1, Event: On Expanded Script ]]------------------------------
treeHandler_ExpandedNodes();
You pass the values of the variables to the static tree on each page, so they update the tree on that page.
This is the best sollution I had so far, I will look it further today and keep you posted when I can fix the bug.
-Casper
usernameCasper
07-24-2007, 09:07 AM
Hey guys,
Ive token a look this morning at an old app I wanted to make to manage page navigation.
There were alot of bugs I experienced due to complete scripting.
For example: Like when you want to expand a node in a tree, action e_Expanded is performed in the On Expand section, but after that action, e_NodeIndex in section On Select is also performed == bug ?
Cause I dont see a relation to perform 2 actions, while it can be done in one, but the worst thing is, is that you dont want to perform an On Select action.
Other things are the weird loops, memory isnt overwrite when it should be ?
I had so many things in my head how to solve this problem, while only 2 options succeed.
In the attachment below, I used dynamically declaration of initialized variables, meaning the code for large project is less for treenavigation and clearly for programming. You also can use static declaration of variables if you want.
Take a look at it, Ive tested untill I didn't saw anymore bugs, there could be still any in it, so I'm glad to hear any bugs or something else. IMO, works like a charm :)
Have a nice day,
-Casper
spider
08-04-2007, 09:06 PM
why don't thy the " Web.SetVisible"
usernameCasper
08-13-2007, 10:25 AM
cause you cant get all things in a web, if you want to r/w from extern scripts, you get too much i/o from HD, causing extreme lagg and afaik buttons can't be embedded in web browers?
Plinsky
08-21-2007, 05:53 PM
I have to use tree with more than 9 items/subitems...
On select, some picture have to be loaded in "Image1" which is present at the same single page. So, I have the same picture on position 1 and 10...
Tree index is:
1
1.1
1.2
...
1.9
1.10 - this is the same as 1.1 ( I try to put 1.11 but the picture is the same! )
I'm not expert... So, is there some trick or something, to overcome this?
Thank you for answers!
steventam
05-20-2009, 11:23 AM
Hi everyone,
I am new to this software. While creating a tree menu, ran into a problem with the entire tree execute the same command. I am trying to create a tree menu consist of more than 50 sub-category which will bring up a PDF file when the user simply double click on it. Where and How do I assign each of the sub-branches under that particular tree to be able to execute each action that I assigned to. Please advise.
Thanks!
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.