Author: sh-sh-sh Date: Mon Oct 8 13:32:42 2007 New Revision: 41281 URL: http://svn.opensuse.org/viewcvs/yast?rev=41281&view=rev Log: QueryWidget( Items ) Added: branches/tmp/sh/mod-ui/core/libyui/doc/examples/MultiSelectionBox-CurrentItem.ycp branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.cc branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.h branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.cc branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.h Modified: branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table3.ycp branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.cc branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.h branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h Added: branches/tmp/sh/mod-ui/core/libyui/doc/examples/MultiSelectionBox-CurrentItem.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/doc/examples/MultiSelectionBox-CurrentItem.ycp?rev=41281&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/doc/examples/MultiSelectionBox-CurrentItem.ycp (added) +++ branches/tmp/sh/mod-ui/core/libyui/doc/examples/MultiSelectionBox-CurrentItem.ycp Mon Oct 8 13:32:42 2007 @@ -0,0 +1,49 @@ +// Advanced MultiSelectionBox example: +// +// Get and change the current item. Note that unlike with a SelectionBox, this +// is typically NOT what an application needs: The current item is the item +// that has the keyboard focus. It doesn't need to be selected. Most +// applications will want to use SelectedItems rather than CurrentItem. +{ + + UI::OpenDialog( + `VBox( + `MultiSelectionBox( `id(`toppings), "Select pizza toppings:", + [ + `item( `id(0), "Cheese" , true ), + `item( `id(1), "Tomatoes" , true ), + `item( `id(2), "Mushrooms" , false ), + `item( `id(3), "Onions" ), + `item( `id(4), "Salami" ), + `item( `id(5), "Ham" ) + ] ), + `HBox( + `PushButton(`id(`next), "&Next" ), + `HStretch(), + `PushButton(`id(`cancel), "&Close") + ) + ) + ); + + any widget = nil; + + repeat + { + widget = UI::UserInput(); + + if ( widget == `next ) + { + integer current = (integer) UI::QueryWidget(`toppings, `CurrentItem ); + + current = current + 1; + if ( current > 5 ) + current = 0; + + y2milestone( "Current: %1", current ); + UI::ChangeWidget(`toppings, `CurrentItem, current ); + } + + } until ( widget == `cancel ); + + UI::CloseDialog(); +} Modified: branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table3.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table3.ycp?rev=41281&r1=41280&r2=41281&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table3.ycp (original) +++ branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table3.ycp Mon Oct 8 13:32:42 2007 @@ -1,5 +1,6 @@ +// Table example: Exchange complete table content { - list itemlist1 = + list foodItems = [ `item(`id(3), "Spaghetti", 8), `item(`id(4), "Steak Sandwich", 12), @@ -7,23 +8,23 @@ `item(`id(2), "Salami Baguette", nil) ]; - list itemlist2 = + list carItems = [ `item(`id(0), "Mercedes", 60000), - `item(`id(1), "AUDI", 50000), + `item(`id(1), "Audi", 50000), `item(`id(2), "VW", 40000), `item(`id(3), "BMW", 60000), `item(`id(3), "Porsche", 80000) ]; - list itemslists = [ itemlist1, itemlist2 ]; + list itemLists = [ foodItems, carItems ]; - integer listnum = 0; + integer listNo = 0; UI::OpenDialog( `VBox( `Heading("Prices"), - `MinSize( 30, 10, `Table(`id(`table), `header("Name", "price"), itemlist1) ), + `MinSize( 30, 10, `Table(`id(`table), `header("Name", "Price"), foodItems ) ), `Right( `HBox( `PushButton(`id(`next), "Change &Table Contents"), @@ -35,10 +36,15 @@ while (UI::UserInput() != `cancel) { - listnum = 1 - listnum; - UI::ChangeWidget(`id(`table), `Items, select(itemslists, listnum, nil)); + // Change table contents + + listNo = 1 - listNo; + UI::ChangeWidget(`table, `Items, itemLists[ listNo ]:nil ); + + // Double check: Retrieve contents and dump to log + y2milestone( "New table content:\n%1", UI::QueryWidget(`table, `Items ) ); } - + UI::CloseDialog(); } Modified: branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am?rev=41281&r1=41280&r2=41281&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am Mon Oct 8 13:32:42 2007 @@ -15,7 +15,9 @@ YApplication.cc \ YCPDialogParser.cc \ YCPItemParser.cc \ + YCPItemWriter.cc \ YCPTreeItemParser.cc \ + YCPTreeItemWriter.cc \ YCPTableItemParser.cc \ YCPTableItemWriter.cc \ YCPPropertyHandler.cc \ @@ -95,8 +97,10 @@ YCPDialogParser.h \ YCPItem.h \ YCPItemParser.h \ + YCPItemWriter.h \ YCPTreeItem.h \ YCPTreeItemParser.h \ + YCPTreeItemWriter.h \ YCPTableItemParser.h \ YCPTableItemWriter.h \ YCPTableItem.h \ Modified: branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.cc?rev=41281&r1=41280&r2=41281&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.cc Mon Oct 8 13:32:42 2007 @@ -20,14 +20,14 @@ /-*/ -#include "ycp/YCPBoolean.h" -#include "ycp/YCPInteger.h" -#include "ycp/YCPVoid.h" -#include "ycp/YCPString.h" -#include "y2/Y2Function.h" +#include <ycp/YCPBoolean.h> +#include <ycp/YCPInteger.h> +#include <ycp/YCPVoid.h> +#include <ycp/YCPString.h> +#include <y2/Y2Function.h> #define y2log_component "ui" -#include "ycp/y2log.h" +#include <ycp/y2log.h> #include "YUI.h" #include "YUIComponent.h" Modified: branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.h?rev=41281&r1=41280&r2=41281&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/Y2UINamespace.h Mon Oct 8 13:32:42 2007 @@ -21,15 +21,15 @@ #include <y2/Y2Namespace.h> #include <y2/Y2Function.h> -#include "ycp/YCPBoolean.h" -#include "ycp/YCPInteger.h" -#include "ycp/YCPVoid.h" -#include "ycp/YCPString.h" -#include "ycp/YCPCode.h" -#include "ycp/StaticDeclaration.h" +#include <ycp/YCPBoolean.h> +#include <ycp/YCPInteger.h> +#include <ycp/YCPVoid.h> +#include <ycp/YCPString.h> +#include <ycp/YCPCode.h> +#include <ycp/StaticDeclaration.h> #define y2log_component "ui" -#include "ycp/y2log.h" +#include <ycp/y2log.h> #include "YUI.h" #include "YUIComponent.h" Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.cc?rev=41281&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.cc (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.cc Mon Oct 8 13:32:42 2007 @@ -0,0 +1,76 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YCPItemWriter.cc + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#include <ycp/YCPVoid.h> +#include <ycp/YCPBoolean.h> +#include "YCPItemWriter.h" +#include "YUISymbols.h" + + +YCPList +YCPItemWriter::itemList( YItemConstIterator begin, YItemConstIterator end ) +{ + YCPList itemList; + + for ( YItemConstIterator it = begin; it != end; ++it ) + { + const YItem * item = dynamic_cast<const YItem *> (*it); + + if ( item ) + { + itemList->add( itemTerm( item ) ); + } + } + + return itemList; +} + + +YCPValue +YCPItemWriter::itemTerm( const YItem * item ) +{ + if ( ! item ) + return YCPVoid(); + + YCPTerm itemTerm( YUISymbol_item ); // `item() + + const YCPItem * ycpItem = dynamic_cast<const YCPItem *> (item); + + if ( ycpItem && ycpItem->hasId() ) + { + YCPTerm idTerm( YUISymbol_id ); // `id() + idTerm->add( ycpItem->id() ); + itemTerm->add( idTerm ); + } + + if ( item->hasIconName() ) + { + YCPTerm iconTerm( YUISymbol_icon ); // `icon() + iconTerm->add( YCPString( item->iconName() ) ); + itemTerm->add( iconTerm ); + } + + itemTerm->add( YCPString( item->label() ) ); // label + + if ( item->selected() ) // isSelected + itemTerm->add( YCPBoolean( item->selected() ) ); + + return itemTerm; +} + + Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.h?rev=41281&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.h (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPItemWriter.h Mon Oct 8 13:32:42 2007 @@ -0,0 +1,65 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YCPItemWriter.h + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#ifndef YCPItemWriter_h +#define YCPItemWriter_h + +#include <ycp/YCPList.h> +#include <ycp/YCPTerm.h> +#include <ycp/YCPValue.h> + +#include "YCPItem.h" + + +/** + * Writer for SelectionBox, ComboBox, MultiSelectionBox item lists + **/ +class YCPItemWriter +{ +public: + + /** + * Create a YCPList from an item collection: + * + * [ + * `item(`id( `myID1 ), "Label1" ), + * `item(`id( `myID2 ), "Label2", true ), + * `item(`id( `myID3 ), `icon( "icon3.png"), "Label3", true ) + * ] + * + * Note that the simple version "Label4" (without `item() and `id()) is + * never returned here since if no ID is explicitly specified, the label + * itself is used as the ID, so every item always has an ID, so the `id() + * term and thus the `item() term have to be used. + **/ + static YCPList itemList( YItemConstIterator begin, YItemConstIterator end ); + + + /** + * Create a YCPTerm for one item: + * + * `item(`id( `myID1 ), "Label1" ) + * `item(`id( `myID2 ), "Label2", true ) + * `item(`id( `myID3 ), `icon( "icon3.png"), "Label3", true ) + **/ + static YCPValue itemTerm( const YItem * item ); + +}; + + +#endif // YCPItemWriter_h Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc?rev=41281&r1=41280&r2=41281&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc Mon Oct 8 13:32:42 2007 @@ -37,7 +37,9 @@ #include "YCPItem.h" #include "YCPTreeItem.h" #include "YCPItemParser.h" +#include "YCPItemWriter.h" #include "YCPTreeItemParser.h" +#include "YCPTreeItemWriter.h" #include "YCPTableItemParser.h" #include "YCPTableItemWriter.h" #include "YCPValueWidgetID.h" @@ -65,29 +67,31 @@ if ( propertyName == YUIProperty_Value ) { - if ( trySetCheckBoxValue ( widget, val ) ) return true; - if ( trySetSelectionBoxValue ( widget, val ) ) return true; - if ( trySetTreeValue ( widget, val ) ) return true; - if ( trySetTableValue ( widget, val ) ) return true; - if ( trySetComboBoxValue ( widget, val ) ) return true; + if ( trySetCheckBoxValue ( widget, val ) ) return true; + if ( trySetSelectionBoxValue ( widget, val ) ) return true; + if ( trySetTreeValue ( widget, val ) ) return true; + if ( trySetTableValue ( widget, val ) ) return true; + if ( trySetComboBoxValue ( widget, val ) ) return true; } if ( propertyName == YUIProperty_Values ) { - if ( trySetMultiProgressMeterValues ( widget, val ) ) return true; + if ( trySetMultiProgressMeterValues ( widget, val ) ) return true; } else if ( propertyName == YUIProperty_CurrentItem ) { - if ( trySetSelectionBoxValue ( widget, val ) ) return true; - if ( trySetTreeValue ( widget, val ) ) return true; - if ( trySetTableValue ( widget, val ) ) return true; + if ( trySetSelectionBoxValue ( widget, val ) ) return true; + if ( trySetTreeValue ( widget, val ) ) return true; + if ( trySetTableValue ( widget, val ) ) return true; + + if ( trySetMultiSelectionBoxCurrentItem( widget, val ) ) return true; } else if ( propertyName == YUIProperty_Items ) { // Make sure to try YTree and YTable before YSelectionWidget: both inherit YSelectionWidget! - if ( trySetTreeItems ( widget, val ) ) return true; - if ( trySetTableItems ( widget, val ) ) return true; - if ( trySetSelectionWidgetItems ( widget, val ) ) return true; + if ( trySetTreeItems ( widget, val ) ) return true; + if ( trySetTableItems ( widget, val ) ) return true; + if ( trySetSelectionWidgetItems ( widget, val ) ) return true; } else if ( propertyName == YUIProperty_CurrentButton ) { @@ -117,7 +121,7 @@ { if ( trySetTableCell( widget, propertyTerm, val ) ) return true; } - + y2error( "Can't handle property %s::%s - not changing anything", widget->widgetClass(), propertyName.c_str() ); @@ -147,7 +151,7 @@ val = tryGetTableValue ( widget ); if ( ! val.isNull() ) return val; val = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val; - // tryGetMultiSelectionBoxCurrentItem + val = tryGetMultiSelectionBoxCurrentItem( widget ); if ( ! val.isNull() ) return val; } else if ( propertyName == YUIProperty_CurrentButton ) { @@ -167,14 +171,11 @@ } else if ( propertyName == YUIProperty_Items ) { - val = tryGetTableItems ( widget ); if ( ! val.isNull() ) return val; - - // FIXME: TO DO: - // FIXME: TO DO: - // FIXME: TO DO: + // Make sure to try YTree and YTable before YSelectionWidget: both inherit YSelectionWidget! - // tryGetTreeItems - // tryGetSelectionWidgetItems + val = tryGetTreeItems ( widget ); if ( ! val.isNull() ) return val; + val = tryGetTableItems ( widget ); if ( ! val.isNull() ) return val; + val = tryGetSelectionWidgetItems( widget ); if ( ! val.isNull() ) return val; } y2error( "Can't handle property %s::%s - returning 'nil'", @@ -574,6 +575,32 @@ bool +YCPPropertyHandler::trySetMultiSelectionBoxCurrentItem( YWidget * widget, const YCPValue & val ) +{ + YMultiSelectionBox * multiSelBox = dynamic_cast<YMultiSelectionBox *> (widget); + + if ( ! multiSelBox ) + return false; + + YCPItem * item = findItem<YCPItem>( multiSelBox , val ); + + if ( item ) + { + multiSelBox->setCurrentItem( item ); + } + else + { + y2error( "%s \"%s\" has no item with ID %s", + widget->widgetClass(), + widget->debugLabel().c_str(), + val->toString().c_str() ); + } + + return true; +} + + +bool YCPPropertyHandler::trySetMultiProgressMeterValues( YWidget * widget, const YCPValue & val ) { YMultiProgressMeter * multiProgressMeter = dynamic_cast<YMultiProgressMeter *> (widget); @@ -747,6 +774,30 @@ YCPValue +YCPPropertyHandler::tryGetMultiSelectionBoxCurrentItem( YWidget * widget ) +{ + YMultiSelectionBox * multiSelBox = dynamic_cast<YMultiSelectionBox *> (widget); + + if ( ! multiSelBox ) + return YCPNull(); + + YItem * currentItem = multiSelBox->currentItem(); + + if ( currentItem ) + { + YCPItem * item = dynamic_cast<YCPItem *> (currentItem); + + if ( item ) + return item->id(); + else + y2error( "Item is not a YCPItem: \"%s\"", currentItem->label().c_str() ); + } + + return YCPVoid(); +} + + +YCPValue YCPPropertyHandler::tryGetTreeOpenItems( YWidget * widget ) { YTree * tree = dynamic_cast<YTree *> (widget); @@ -935,3 +986,28 @@ } +YCPValue +YCPPropertyHandler::tryGetTreeItems( YWidget * widget ) +{ + YTree * tree = dynamic_cast<YTree *> (widget); + + if ( ! tree ) + return YCPNull(); + + return YCPTreeItemWriter::itemList( tree->itemsBegin(), tree->itemsEnd() ); +} + + +YCPValue +YCPPropertyHandler::tryGetSelectionWidgetItems( YWidget * widget ) +{ + YSelectionWidget * selWidget = dynamic_cast<YSelectionWidget *> (widget); + + if ( ! selWidget ) + return YCPNull(); + + return YCPItemWriter::itemList( selWidget->itemsBegin(), selWidget->itemsEnd() ); +} + + + Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h?rev=41281&r1=41280&r2=41281&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h Mon Oct 8 13:32:42 2007 @@ -103,6 +103,7 @@ static bool trySetSelectionWidgetItems ( YWidget * widget, const YCPValue & val ); static bool trySetRadioButtonGroupCurrentButton ( YWidget * widget, const YCPValue & val ); static bool trySetMultiSelectionBoxSelectedItems ( YWidget * widget, const YCPValue & val ); + static bool trySetMultiSelectionBoxCurrentItem ( YWidget * widget, const YCPValue & val ); static bool trySetMultiProgressMeterValues ( YWidget * widget, const YCPValue & val ); /** @@ -118,11 +119,14 @@ static YCPValue tryGetComboBoxValue ( YWidget * widget ); static YCPValue tryGetRadioButtonGroupCurrentButton ( YWidget * widget ); static YCPValue tryGetMultiSelectionBoxSelectedItems( YWidget * widget ); + static YCPValue tryGetMultiSelectionBoxCurrentItem ( YWidget * widget ); static YCPValue tryGetTreeOpenItems ( YWidget * widget ); static YCPValue tryGetTreeCurrentBranch ( YWidget * widget ); static YCPValue tryGetTableCell ( YWidget * widget, const YCPTerm & propertyTerm ); static YCPValue tryGetTableItem ( YWidget * widget, const YCPTerm & propertyTerm ); static YCPValue tryGetTableItems ( YWidget * widget ); + static YCPValue tryGetTreeItems ( YWidget * widget ); + static YCPValue tryGetSelectionWidgetItems ( YWidget * widget ); /** Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc?rev=41281&r1=41280&r2=41281&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc Mon Oct 8 13:32:42 2007 @@ -16,19 +16,19 @@ /-*/ -#include "ycp/YCPVoid.h" +#include <ycp/YCPVoid.h> #include "YCPTableItemWriter.h" #include "YUISymbols.h" YCPList -YCPTableItemWriter::itemList( YItemIterator begin, YItemIterator end ) +YCPTableItemWriter::itemList( YItemConstIterator begin, YItemConstIterator end ) { YCPList itemList; - for ( YItemIterator it = begin; it != end; ++it ) + for ( YItemConstIterator it = begin; it != end; ++it ) { - YTableItem * item = dynamic_cast<YTableItem *> (*it); + const YTableItem * item = dynamic_cast<const YTableItem *> (*it); if ( item ) { @@ -54,6 +54,7 @@ { YCPTerm idTerm( YUISymbol_id ); // `id() idTerm->add( ycpItem->id() ); + itemTerm->add( idTerm ); } for ( YTableCellConstIterator it = item->cellsBegin(); it != item->cellsEnd(); ++it ) Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h?rev=41281&r1=41280&r2=41281&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h Mon Oct 8 13:32:42 2007 @@ -38,21 +38,26 @@ * * [ * `item(`id(`myID1 ), "Label1", "Label2", "Label3" ), - * `item(`id(`myID1 ), "Label1", `cell("Label2"), "Label3" ), - * `item(`id(`myID2 ), "Label1", `cell(`icon( "icon2.png"), "Label2" ), "Label3" ) - * `item(`id(`myID2 ), "Label1", `cell( "Label2", `icon( "icon2.png")), "Label3" ) + * `item(`id(`myID2 ), "Label1", `cell("Label2"), "Label3" ), + * `item(`id(`myID3 ), "Label1", `cell(`icon( "icon2.png"), "Label2" ), "Label3" ) + * `item(`id(`myID4 ), "Label1", `cell( "Label2", `icon( "icon2.png")), "Label3" ) * ] + + * Note that the simple version "Label4" (without `item() and `id()) is + * never returned here since if no ID is explicitly specified, the label + * itself is used as the ID, so every item always has an ID, so the `id() + * term and thus the `item() term have to be used. **/ - static YCPList itemList( YItemIterator begin, YItemIterator end ); + static YCPList itemList( YItemConstIterator begin, YItemConstIterator end ); /** * Create a YCPTerm for one table item: * * `item(`id(`myID1 ), "Label1", "Label2", "Label3" ) - * `item(`id(`myID1 ), "Label1", `cell( "Label2" ), "Label3" ) - * `item(`id(`myID2 ), "Label1", `cell(`icon( "icon2.png" ), "Label2" ), "Label3" ) - * `item(`id(`myID2 ), "Label1", `cell( "Label2", `icon( "icon2.png")), "Label3" ) + * `item(`id(`myID2 ), "Label1", `cell( "Label2" ), "Label3" ) + * `item(`id(`myID3 ), "Label1", `cell(`icon( "icon2.png" ), "Label2" ), "Label3" ) + * `item(`id(`myID4 ), "Label1", `cell( "Label2", `icon( "icon2.png")), "Label3" ) * * `cell() will be created only if a cell has an icon. **/ Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.cc?rev=41281&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.cc (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.cc Mon Oct 8 13:32:42 2007 @@ -0,0 +1,79 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YCPTreeItemWriter.cc + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#include <ycp/YCPVoid.h> +#include <ycp/YCPBoolean.h> +#include "YCPTreeItemWriter.h" +#include "YUISymbols.h" + + +YCPList +YCPTreeItemWriter::itemList( YItemConstIterator begin, YItemConstIterator end ) +{ + YCPList itemList; + + for ( YItemConstIterator it = begin; it != end; ++it ) + { + const YTreeItem * item = dynamic_cast<const YTreeItem *> (*it); + + if ( item ) + { + itemList->add( itemTerm( item ) ); + } + } + + return itemList; +} + + +YCPValue +YCPTreeItemWriter::itemTerm( const YTreeItem * item ) +{ + if ( ! item ) + return YCPVoid(); + + YCPTerm itemTerm( YUISymbol_item ); // `item() + + const YCPTreeItem * ycpItem = dynamic_cast<const YCPTreeItem *> (item); + + if ( ycpItem && ycpItem->hasId() ) + { + YCPTerm idTerm( YUISymbol_id ); // `id() + idTerm->add( ycpItem->id() ); + itemTerm->add( idTerm ); + } + + if ( item->hasIconName() ) + { + YCPTerm iconTerm( YUISymbol_icon ); // `icon() + iconTerm->add( YCPString( item->iconName() ) ); + itemTerm->add( iconTerm ); + } + + itemTerm->add( YCPString( item->label() ) ); // label + + if ( item->isOpen() ) // isOpen + itemTerm->add( YCPBoolean( item->isOpen() ) ); + + if ( item->hasChildren() ) // subItemList + itemTerm->add( itemList( item->childrenBegin(), item->childrenEnd() ) ); + + return itemTerm; +} + + Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.h?rev=41281&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.h (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemWriter.h Mon Oct 8 13:32:42 2007 @@ -0,0 +1,62 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YCPTreeItemWriter.h + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#ifndef YCPTreeItemWriter_h +#define YCPTreeItemWriter_h + +#include <ycp/YCPList.h> +#include <ycp/YCPTerm.h> +#include <ycp/YCPValue.h> + +#include "YCPTreeItem.h" + + +/** + * Writer for tree item lists + **/ +class YCPTreeItemWriter +{ +public: + + /** + * Create a YCPList from a tree item collection: + * + * [ + * `item(`id( `myID1 ), "Label1" ), + * `item(`id( `myID2 ), `icon( "icon2.png"), "Label2", true ), + * `item(`id( `myID3 ), `icon( "icon3.png"), "Label3", true, [ subItemList ] ), + * `item( "Label4" ) + * ] + **/ + static YCPList itemList( YItemConstIterator begin, YItemConstIterator end ); + + + /** + * Create a YCPTerm for one tree item: + * + * `item(`id( `myID1 ), "Label1" ), + * `item(`id( `myID2 ), `icon( "icon2.png"), "Label2", true ), + * `item(`id( `myID3 ), `icon( "icon3.png"), "Label3", true, [ subItemList ] ) + * `item( "Label4" ) + **/ + static YCPValue itemTerm( const YTreeItem * item ); + +}; + + +#endif // YCPTreeItemWriter_h -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org