Page 1 of 3

ListTree looking for a solution

Posted: Mon Feb 02, 2015 9:21 pm
by djrikki
Using the below image as a guide and focusing on foreinstance the 'HGroup 1 Window (HGROUP) node - If I want to output this tree in XML with lines such as <hgroup>, and in this example its non-container classes 'Button 1 (Button)' and 'This is is some text (Text) - can anyone make a suggestion of how I can detect the end of this node in order to output </hgroup> at the end of it?

This is the goal output which I am trying to achieve.

Code: Select all

<hgroup>
    <button>Button 1</button>
    <text>This is some text</text>
</hgroup>
But at the moment I am scratching me head on how to programmatically insert the container group end-tag in the right place.

Image

Re: ListTree looking for a solution

Posted: Tue Feb 03, 2015 2:46 pm
by bitRocky
When using GetEntry method to get the next node inside your hgroup you have to use "SameLevel" as flags parameter.

Re: ListTree looking for a solution

Posted: Wed Feb 04, 2015 10:39 pm
by djrikki
What I am trying to achieve if I have the terminalogy correct, is to find the Tail of the currently traversed Node. E.g.

Code: Select all

Fruit
    Apple
         Bramley
         Crab
    Orange
         Satsuma
         Tangerine
    Pears
Vegetables
   Carrots
   Peas
   Turnips
I want to detect that Pears is the final item of the Fruit list or that Tangerine is the final item of the Orange list.

Re: ListTree looking for a solution

Posted: Wed Feb 04, 2015 10:46 pm
by djrikki
Any solution needs to fit within the DumpLayoutTree function which resides in the manual about the GetEntry method.

Re: ListTree looking for a solution

Posted: Fri Feb 06, 2015 4:07 pm
by bitRocky
Just check if the next node with the same level is null, if yes, the current node is the last node!

Re: ListTree looking for a solution

Posted: Fri Feb 06, 2015 7:17 pm
by djrikki
Not sure how that would fit into a structure like above, e.g. Pears and Vegetables it would need to be e..g </vgroup> followed immediately on the next line by another </vgroup>.
The table above is 3 levels deep, however I will give it a go.

Re: ListTree looking for a solution

Posted: Fri Feb 06, 2015 9:18 pm
by djrikki
Nope still not having any luck, even explore 'parent', but couldn't get this to work, so here is my not working code.

Code: Select all

Function Application:DumpLayoutTree(id$, node,window)
	Local found, t = mui.DoMethod(id$, "GetEntry", node, "Head", "")
	iteration = iteration + 1
	While found = True
        	Local userdata = mui.Get(t.id,"userdata")
			
		Project.Application.Win.Layout[window][iteration] = userdata
		
		debugprint( "Project.Application.Win.Layout[" .. window .. "][" .. iteration .. "].id = " .. Project.Application.Win.Layout[window][iteration].id )
		debugprint( "Project.Application.Win.Layout[" .. window .. "][" .. iteration .. "].class = " .. Project.Application.Win.Layout[window][iteration].class )
			
		If t.Node = True		
		    Application:DumpLayoutTree(id$, t.muiid, window)
		Else
		    iteration = iteration + 1
		EndIf
				
		found, t = mui.DoMethod(id$, "GetEntry", t.muiid, "Next", "")				
	Wend	
EndFunction
Because I cannot detect closure, I cannot insert the relevant closure tag nor can I reduce the tab space and end up with unfinished code like this:

Code: Select all

...
	<WINDOW ID="MAIN" MENUSTRIP="" MuiID="MAIN" Width="Screen:100" Height=":100" Notify="Activate;CloseRequest;MouseObject" open="true" Title="Default Application Window" Borderless="false" CloseGadget="true" DepthGadget="true"  SizeGadget="true"  AppWindow="false" >
		<VGROUP ID="win0-vgroup0" Frame="group" FrameTitle="frame-title" Background="Groupback">
				<REGISTER ID=" win0-register0"  Notify="ActivePage" >
						<VGROUP ID="win0-vgroup1" Frame="group" FrameTitle="frame-title" Background="Groupback">
								<LISTVIEW ID=" win0-vgroup1-listview-0"  Weight="100"  Notify="ClickColumn;DoubleClick;"  AdjustWidth="true"  AdjustHeight="true"  AutoVisible="true"  MultiSelect="default"  MinLineHeight="20"  ScrollerPos="right"  CycleChain="true">
									<Column Title="Name">
 										<Item>Richard Lake</Item>
										<Item>Laura Campbell</Item>
									</Column>
									<Column Title="Age">
 										<Item>38</Item>
										<Item>29</Item>
									</Column>
								</LISTVIEW>
		<HGROUP ID="win0-hgroup0" Frame="group" FrameTitle="frame-title" Background="Groupback">
				<LABEL ID="win0-colour-0" ControlChar="l"  Hidden="true"  Centered="true"  DoubleFrame="true"  LeftAligned="true"  Font="Normal" >Select a Label</LABEL>
		<COLORADJUST ID="win0-colour-1" ShortHelp="shorthelp-coloradjust"  HelpNode="coloradjust-node"  Weight="100"  Disabled="true"  Hidden="true"  Notify="Rgb" Rgb="$FF00FF" />
								<VGROUP ID="win0-vgroup2" Frame="group" FrameTitle="frame-title" Background="Groupback">
										<RADIO ID=" win0-othertab-0"  Weight="100"  Active="2"  CycleChain="true">
											<Item>Red</Item>
											<Item>Green</Item>
											<Item>Blue</Item>
										</RADIO>
		<HOLLYWOOD ID="win0-othertab-1" Weight="100"  MinWidth="100"  MaxWidth="1000"  MinHeight="100"  MaxHeight="1000" />
				<HGROUP ID="win0-hgroup1" Frame="group" FrameTitle="frame-title" Background="Groupback">
		<BUTTON ID="win0-hgroup1-button1" ShortHelp="shorthelp-text"  HelpNode="button-node"  Weight="100"  ControlChar="b"  Disabled="true"  Hidden="true"  Label="Action"  HiChar="b"  Notify="Pressed;Selected" Toggle="true" />
								<TEXT ID="win0-hgroup1-text4" Hidden="true"  HiChar="t"  Preparse="preparse-text" >This is some text</TEXT>
										<HGROUP ID="win0-hgroup2" Frame="group" FrameTitle="frame-title" Background="Groupback">
		<STRING ID="win0-hgroup2-string1" ShortHelp="shorthelp-string"  HelpNode="string-node"  Weight="100"  ControlChar="s"  Disabled="true"  Hidden="true"  Notify="Acknowledge;Contents" Contents="this is a string"  Maxlen="80"  Accept="accept"  Reject="reject"  Secret="true"  AdvanceOnCR="true" />
														<POPLIST ID=" win0-hgroup2-poplist1"  Weight="100"  Notify="Acknowledge;Contents" Contents="Apple"  CycleChain="true">
															<Item>Apple</Item>
														</POPLIST>
		<POPDRAWER ID="win0-hgroup2-popdrawer1" ShortHelp="shorthelp-popdrawer"  HelpNode="popdrawer-node"  Weight="100"  ControlChar="d"  Disabled="true"  Hidden="true"  Notify="Acknowledge;Contents" Title="PopDrawer"  Contents="PROGDIR:"  SaveMode="true" />
		<POPFILE ID="win0-hgroup2-popfile1" ShortHelp="shorthelp-popfile"  HelpNode="popfile-node"  Weight="100"  ControlChar="f"  Disabled="true"  Hidden="true"  Notify="Acknowledge;Contents" Contents="defaultvalue"  RejectPattern="#?.accepted"  RejectPattern="#?.test"  SaveMode="true"  RejectIcons="true"  ShowPattern="true" />
						<HGROUP ID="win0-hgroup3" Frame="group" FrameTitle="frame-title" Background="Groupback">
		<TEXTEDITOR ID="win0-hgroup3-texteditor1" ShortHelp="shorthelp-texteditor"  HelpNode="texteditor-node"  Weight="100"  ControlChar="t"  Disabled="true"  Hidden="true"  Notify="AreaMarked;CursorX;CursorY;HasChanged;Pen;RedoAvailable;StyleBold;StyleItalic;StyleUnderline;UndoAvailable" Contents="This is some text"  Columns="80"  Rows="40"  FixedFont="true"  ReadOnly="true"  ScrollBars="true"  FixedFont="hardwrap"  WrapWords="true"  ConvertTabs="true" />
		<POPPEN ID="win0-hgroup3-poppen1" ShortHelp="shorthelp-poppen"  HelpNode="poppen-node"  Weight="100"  Disabled="true"  Hidden="true"  Notify="Rgb" Title="Select a Pen"  Rgb="$FF00FF" />
												<HGROUP ID="win0-hgroup4" Frame="group" FrameTitle="frame-title" Background="Groupback">
														<VGROUP ID="win0-vgroup3" Frame="group" FrameTitle="frame-title" Background="Groupback">
		<SLIDER ID="win0-vgroup3-slider1" ShortHelp="shorthelp-slider"  HelpNode="slider-node"  Weight="100"  ControlChar="s"  Disabled="true"  Hidden="true"  Horiz="true"  Level="65"  Min="50"  Max="75"  Format="%ld"  Quiet="true"  Reverse="true"  Notify="Stringify" Stringify="MyFunction" />
		<IMAGE ID="win0-vgroup3-image1" ShortHelp="shorthelp-image"  HelpNode="image-node"  Weight="100"  Source="brush:100" />
																				<HGROUP ID="win0-hgroup5" Frame="group" FrameTitle="frame-title" Background="Groupback">
																						<CYCLE ID=" win0-hgroup5-cycle1"  Weight="100"  Notify="Active" Active="0"  CycleChain="true">
																							<Item>Red</Item>
																							<Item>Yellow</Item>
																							<Item>Pink</Item>
																							<Item>Green</Item>
																						</CYCLE>
		<HGROUP ID="win0-hgroup6" Frame="group" FrameTitle="frame-title" Background="Groupback">
				<FLOATTEXT ID="win0-hgroup6-floattext1" Hidden="true"  Justify="true"  Font="Normal" >This is some floattext</FLOATTEXT>
		<POPFONT ID="win0-hgroup6-popfont1" Weight="100"  ControlChar="f"  Disabled="true"  Hidden="true"  Notify="Acknowledge;Contents" Title="Select a Font..."  Contents="topaz/8"  MinHeight="5"  MaxHeight="32"  FixedWidthOnly="true" />
		<RECTANGLE ID="win0-hgroup6-rectangle" BarTitle="rectangle-test"  Hbar="true" />
		<GAUGE ID="win0-hgroup6-gauge" Weight="100"  Hidden="true"  Notify="Current" Horiz="false"  Current="75"  Min="50"  Max="100"  InfoText="%ld %% completed..." />
										<Scale/>
		<CHECKMARK ID="win0-hgroup6-checkmark1" ShortHelp="shorthelp-text"  HelpNode="checkmark-node"  Weight="100"  Disabled="true"  Hidden="true"  Notify="Selected" Toggle="true" />
														<TOOLBAR ID=" win0-toolbar0"  Weight="100"  Notify="Active;MouseOver"  BarPos="left"  Horiz="true"  EnableKeys="true"  LabelPos="bottom"  ViewMode="textgfx"  IgnoreAppearance="true"  CycleChain="true">
		<TOOLBARBUTTON ID="win0-toolbar0-button1" ShortHelp="shorthelp-toolbarbutton"  HelpNode="toolbarbutton-node"  Disabled="true"  Hidden="true"  Notify="Pressed;Selected" />
																</Toolbar>
		<HGROUP ID="win0-hgroup7" Frame="group" FrameTitle="frame-title" Background="Groupback">
				<SCROLLGROUP ID=" win0-scrollgroup0" >
						<VIRTGROUP ID=" win0-virtgroup0" >
								<LISTTREE ID=" win0-virtgroup0-listtree"  Weight="100"  Disabled="false"  ShortHelp="shorthelp-listtree" HelpNode="listtree-node" Notify="Active;DoubleClick"  CycleChain="true">
								</LISTTREE>
	</WINDOW>
...
See how I am struggling to format </scrollgroup>, </virtgroup> </vgroup> and other container group tags.

Re: ListTree looking for a solution

Posted: Fri Feb 06, 2015 10:23 pm
by bitRocky
You have to print the closing tag after the DumpLayoutTree() call.
Because it gets called recursively for every listnode.
And use SameLevel flag for the GetEntry method.
This should work.
I will try to give a code example tomorrow.

Re: ListTree looking for a solution

Posted: Fri Feb 06, 2015 11:07 pm
by djrikki
Thanks.

Re: ListTree looking for a solution

Posted: Sat Feb 07, 2015 8:37 pm
by bitRocky
Hi,

here is a C source code, I hope you can make some use of it:

Code: Select all

printCID(long i, enum CLASSID cid, BOOL end) {
	long j;

	for(j=1; j <= i; j++) {bug("  "); }
	bug("%s%s\n", end ? "/" : "", CLASSIDStr[cid]);
}
...
	DEC_QUICK(MM_WinMain_Test)
	{
		GETDATA;
		//struct MP_ *m = (APTR)msg;
		Object				*lt = data->ltMenu;
		structTN			*tn = NULL, *hd = NULL, *tnP = NULL, *ln = NULL, *pn = NULL;
		struct MenuEntry	*entry;
		long				i=0, j;

		Bug("DumpTree\n");
		tn = LT_Head(lt, NULL);
		while (tn)
		{
			entry = tn->tn_User;
			if (entry) {
				printCID(i, entry->cid, FALSE);
				if (LT_IsListNode(tn)){
					i++;
				}
			}
			tnP = tn; hd = 1;
			if (LT_IsListNode(tn) && (hd = LT_Head(lt, tn))){
				tn = hd;
			}else{
				if (!hd){
					i--;
					printCID(i, entry->cid, TRUE);
				}
				tn = LT_NextSame(lt, tn);
				while (!tn) {
					i--;
					pn = LT_Parent(lt, tnP);
					if (pn){
						entry = pn->tn_User;
						printCID(i, entry->cid, TRUE);
						tn = LT_NextSame(lt, pn); tnP = pn;
					}else{
						break;
					}
				}
			}
			if (!tn) {
				while( (pn = LT_Parent(lt, tnP)) && !(tn = LT_NextSame(lt, pn)) )
					{ tnP = pn; };
			}
		}// while	
		return 0;
	}
And this is the output:

Code: Select all

 Application
   Window
     Button
     Checkmark
     Gauge
     HGroup
       HGroup
         Cycle
         HGroup
           HGroup
             Listtree
               Image
             /Listtree
           /HGroup
         /HGroup
       /HGroup
       Coloradjust
     /HGroup
   /Window
   Window
   /Window
 /Application
And this is the tree:
Image