[yast-commit] r41271 - in /branches/tmp/sh/mod-ui/core/libyui/src: YCPPropertyHandler.cc YCPPropertyHandler.h YUI_builtins.cc YWidget.cc
Author: sh-sh-sh Date: Fri Oct 5 22:02:39 2007 New Revision: 41271 URL: http://svn.opensuse.org/viewcvs/yast?rev=41271&view=rev Log: fixed changeWidgetTerm Modified: 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/YUI_builtins.cc branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc 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=41271&r1=41270&r2=41271&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc Fri Oct 5 22:02:39 2007 @@ -89,11 +89,6 @@ if ( trySetTableItems ( widget, val ) ) return true; if ( trySetSelectionWidgetItems ( widget, val ) ) return true; } - else if ( propertyName == YUIProperty_Cell || - propertyName == YUIProperty_Item ) - { - if ( trySetTableCell ( widget, val ) ) return true; - } else if ( propertyName == YUIProperty_CurrentButton ) { if ( trySetRadioButtonGroupCurrentButton( widget, val ) ) return true; @@ -110,6 +105,28 @@ } +bool +YCPPropertyHandler::setComplexProperty( YWidget * widget, + const YCPTerm & propertyTerm, + const YCPValue & val ) +{ + string propertyName = propertyTerm->name(); + + if ( propertyName == YUIProperty_Cell || + propertyName == YUIProperty_Item ) + { + if ( trySetTableCell( widget, propertyTerm, val ) ) return true; + } + + y2error( "Can't handle property %s::%s - not changing anything", + widget->widgetClass(), propertyName.c_str() ); + + return false; +} + + + + YCPValue YCPPropertyHandler::getComplexProperty( YWidget * widget, const string & propertyName ) { @@ -404,79 +421,77 @@ bool -YCPPropertyHandler::trySetTableCell( YWidget * widget, const YCPValue & val ) +YCPPropertyHandler::trySetTableCell( YWidget * widget, const YCPTerm & propTerm, const YCPValue & val ) { YTable * table = dynamic_cast<YTable *> (widget ); if ( ! table ) return false; - if ( val->isTerm() ) + if ( propTerm->size() == 2 && + propTerm->value(1)->isInteger() ) { - YCPTerm term = val->asTerm(); + YCPValue itemId = propTerm->value(0); + int column = propTerm->value(1)->asInteger()->value(); - if ( term->size() == 2 - && term->value(1)->isInteger() ) - { - YCPValue itemId = term->value(0); - int column = term->value(1)->asInteger()->value(); + YCPTableItem * item = findItem<YCPTableItem>( table, itemId ); - YCPTableItem * item = findItem<YCPTableItem>( table, itemId ); + if ( item ) + { + YTableCell * cell = item->cell( column ); - if ( item ) + if ( cell ) { - YTableCell * cell = item->cell( column ); - - if ( cell ) + if ( val->isString() ) { - YCPValue newContent = term->value(0); - - if ( newContent->isString() ) - { - cell->setLabel( newContent->asString()->value() ); - table->cellChanged( cell ); - } - else if ( newContent->isInteger() ) // for backwards compatibility - { - cell->setLabel( newContent->toString().c_str() ); - table->cellChanged( cell ); - } - else if ( newContent->isTerm() - && newContent->asTerm()->name() == YUISymbol_icon // `icon() - && newContent->asTerm()->size() == 1 - && newContent->asTerm()->value(0)->isString() ) - { - YCPString iconName = newContent->asTerm()->value(0)->asString(); - cell->setIconName( iconName->value().c_str() ); - table->cellChanged( cell ); - } - else // any other type - { - string msg = "Expected string, integer, or `icon(\"myicon.png\"), not "; - msg += newContent->toString().c_str(); - YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Item, - YOtherProperty ), - table, msg ) ); - } + cell->setLabel( val->asString()->value() ); + table->cellChanged( cell ); + } + else if ( val->isInteger() ) // for backwards compatibility + { + cell->setLabel( val->toString().c_str() ); + table->cellChanged( cell ); + } + else if ( val->isVoid() ) // for backwards compatibility + { + cell->setLabel( "" ); + table->cellChanged( cell ); + } + else if ( val->isTerm() + && val->asTerm()->name() == YUISymbol_icon // `icon() + && val->asTerm()->size() == 1 + && val->asTerm()->value(0)->isString() ) + { + YCPString iconName = val->asTerm()->value(0)->asString(); + cell->setIconName( iconName->value().c_str() ); + table->cellChanged( cell ); } - else // ! cell + else // any other type { - y2error( "%s item %s doesn't have a column #%d", - table->widgetClass(), - itemId->toString().c_str(), - column ); + string msg = "Expected string, integer, or `icon(\"myicon.png\"), not "; + msg += val->toString().c_str(); + YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Item, + YOtherProperty ), + table, msg ) ); } } - else // ! item + else // ! cell { - y2error( "%s %s has no item with ID %s", + y2error( "%s item %s doesn't have a column #%d", table->widgetClass(), - table->debugLabel().c_str(), - itemId->toString().c_str() ); + itemId->toString().c_str(), + column ); } - - return true; } + else // ! item + { + y2error( "%s %s has no item with ID %s", + table->widgetClass(), + table->debugLabel().c_str(), + itemId->toString().c_str() ); + } + + return true; } YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Items, 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=41271&r1=41270&r2=41271&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h Fri Oct 5 22:02:39 2007 @@ -58,6 +58,14 @@ const string & propertyName, const YCPValue & val ); + /** + * Set a complex property from a term (like `Item(`someID) ) + * + * Return 'true' on success, 'false' on failure. + **/ + static bool setComplexProperty( YWidget * widget, + const YCPTerm & propertyTerm, + const YCPValue & val ); /** * Get a complex property. @@ -91,7 +99,7 @@ static bool trySetComboBoxValue ( YWidget * widget, const YCPValue & val ); static bool trySetTreeItems ( YWidget * widget, const YCPValue & val ); static bool trySetTableItems ( YWidget * widget, const YCPValue & val ); - static bool trySetTableCell ( YWidget * widget, const YCPValue & val ); + static bool trySetTableCell ( YWidget * widget, const YCPTerm & propTerm, const YCPValue & val ); static bool trySetSelectionWidgetItems ( YWidget * widget, const YCPValue & val ); static bool trySetRadioButtonGroupCurrentButton ( YWidget * widget, const YCPValue & val ); static bool trySetMultiSelectionBoxSelectedItems ( YWidget * widget, const YCPValue & val ); Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc?rev=41271&r1=41270&r2=41271&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc Fri Oct 5 22:02:39 2007 @@ -878,48 +878,58 @@ return YCPNull(); } - YCPValue id = YCPDialogParser::parseIdTerm( id_value ); - YWidget *widget = YCPDialogParser::findWidgetWithId( id ); + YCPValue id = YCPDialogParser::parseIdTerm( id_value ); + YWidget * widget = YCPDialogParser::findWidgetWithId( id ); if ( ! widget ) return YCPBoolean( false ); - if ( property->isSymbol() ) - { - blockEvents(); // We don't want self-generated events from UI::ChangeWidget(). - string oldShortcutString = widget->shortcutString(); - YCPSymbol sym = property->asSymbol(); - YCPValue ret = YCPVoid(); + blockEvents(); // We don't want self-generated events from UI::ChangeWidget(). + YCPValue ret = YCPVoid(); - YPropertySet propSet = widget->propertySet(); + YPropertySet propSet = widget->propertySet(); + + if ( propSet.size() == 5 ) // unchanged from YWidget, no properties supported + { + // FIXME: Get rid of this + // FIXME: Get rid of this + // FIXME: Get rid of this - if ( propSet.size() == 5 ) // unchanged from YWidget, no properties supported + if ( property->isSymbol() ) { - // FIXME: Get rid of this - // FIXME: Get rid of this - // FIXME: Get rid of this + YCPSymbol sym = property->asSymbol(); y2debug( "Old style UI::ChangeWidget() for %s::%s", - widget->widgetClass(), sym->symbol().c_str() ); + widget->widgetClass(), sym->toString().c_str() ); ret = widget->changeWidget( sym, newValue ); - // FIXME: Get rid of this - // FIXME: Get rid of this - // FIXME: Get rid of this } else { - // y2milestone( "New style UI::ChangeWidget() for %s::%s", widget->widgetClass(), sym->symbol().c_str() ); - - string propertyName = sym->symbol(); - YPropertyValue val; - - if ( newValue->isString() ) val = YPropertyValue( newValue->asString()->value() ); - else if ( newValue->isInteger() ) val = YPropertyValue( newValue->asInteger()->value() ); - else if ( newValue->isBoolean() ) val = YPropertyValue( newValue->asBoolean()->value() ); - else - val = YPropertyValue( false ); // Dummy value, will be rejected anyway - - try + y2error( "Bad argument for UI::ChangeWidget(): %s", + property->toString().c_str() ); + } + + // FIXME: Get rid of this + // FIXME: Get rid of this + // FIXME: Get rid of this + } + else + { + try + { + if ( property->isSymbol() ) { + string oldShortcutString = widget->shortcutString(); + string propertyName = property->asSymbol()->symbol(); + // y2milestone( "New style UI::ChangeWidget() for %s::%s", widget->widgetClass(), propertyName.c_str() ); + + YPropertyValue val; + + if ( newValue->isString() ) val = YPropertyValue( newValue->asString()->value() ); + else if ( newValue->isInteger() ) val = YPropertyValue( newValue->asInteger()->value() ); + else if ( newValue->isBoolean() ) val = YPropertyValue( newValue->asBoolean()->value() ); + else + val = YPropertyValue( false ); // Dummy value, will be rejected anyway + bool success = widget->setProperty( propertyName, val ); if ( ! success ) @@ -929,35 +939,35 @@ } ret = YCPBoolean( success ); + + if ( oldShortcutString != widget->shortcutString() ) + YDialog::currentDialog()->checkShortcuts(); } - catch( YUIException & exception ) + else if ( property->isTerm() ) { - YUI_CAUGHT( exception ); - ycperror( "UI::ChangeWidget() failed for property %s of %s with ID %s, new value: %s", - property->toString().c_str(), - widget->widgetClass(), - id->toString().c_str(), - newValue->toString().c_str() ); - - ret = YCPNull(); + bool success = YCPPropertyHandler::setComplexProperty( widget, property->asTerm(), newValue ); + ret = YCPBoolean( success ); + } + else + { + YUI_THROW( YUIException( string( "Bad UI::ChangeWidget args: " ) + + property->toString() ) ); } } - - - if ( oldShortcutString != widget->shortcutString() ) - YDialog::currentDialog()->checkShortcuts(); - - unblockEvents(); - return ret; + catch( YUIException & exception ) + { + YUI_CAUGHT( exception ); + ycperror( "UI::ChangeWidget() failed for property %s of %s with ID %s, new value: %s", + property->toString().c_str(), + widget->widgetClass(), + id->toString().c_str(), + newValue->toString().c_str() ); + } } - else - { - blockEvents(); // We don't want self-generated events from UI::ChangeWidget(). - YCPValue result = widget->changeWidgetTerm( property->asTerm(), newValue ); - unblockEvents(); - return result; - } + unblockEvents(); + + return ret; } @@ -1018,7 +1028,7 @@ if ( property->isSymbol() ) // The normal case: UI::QueryWidget(`myWidget, `SomeProperty) { string propertyName = property->asSymbol()->symbol(); - YPropertyValue val = widget->getProperty( propertyName ); + YPropertyValue val = widget->getProperty( propertyName ); switch ( val.type() ) { @@ -1038,7 +1048,8 @@ } else { - YUI_THROW( YUIException( "Bad QueryWidget args" ) ); + YUI_THROW( YUIException( string( "Bad UI::QueryWidget args: " ) + + property->toString() ) ); } } catch( YUIException & exception ) Modified: branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc?rev=41271&r1=41270&r2=41271&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc Fri Oct 5 22:02:39 2007 @@ -758,8 +758,8 @@ { string symbol = property->symbol(); - if ( symbol == YUIProperty_Enabled ) return YCPBoolean( isEnabled() ); - if ( symbol == YUIProperty_Notify ) return YCPBoolean( notify() ); + if ( symbol == YUIProperty_Enabled ) return YCPBoolean( isEnabled() ); + if ( symbol == YUIProperty_Notify ) return YCPBoolean( notify() ); if ( symbol == YUIProperty_WidgetClass ) return YCPString( widgetClass() ); if ( symbol == YUIProperty_DebugLabel ) return YCPString( debugLabel() ); if ( symbol == YUIProperty_DialogDebugLabel ) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org