Author: sh-sh-sh
Date: Wed Jun 20 18:12:33 2007
New Revision: 38933
URL: http://svn.opensuse.org/viewcvs/yast?rev=38933&view=rev
Log:
- Introduced YApplication
- moved currentDialog() from YUI to YDialog
- moved dialog stack handling from YUI to YDialog
- handle YCPWidgetIDs in properties
Added:
branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc
branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc
branches/tmp/sh/mod-ui/core/libyui/src/YDialog.h
branches/tmp/sh/mod-ui/core/libyui/src/YMacroRecorder.cc
branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc
branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h
branches/tmp/sh/mod-ui/core/libyui/src/YUI.h
branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h
branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc
branches/tmp/sh/mod-ui/core/libyui/src/YUI_core.cc
branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc
branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc
branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog Wed Jun 20 18:12:33 2007
@@ -40,6 +40,22 @@
* New header file YTypes.h for simple types to reduce header file interdependencies:
Now it's often no longer necessary to #include YAlignment.h or YWidget.h
+* YUI:
+
+ * YUI::currentDialog() is now moved to static YDialog::currentDialog()
+
+* New: YApplication
+ The idea of this class is to bundle all the "misc UI functionality" methods.
+ See YApplication.h for details.
+
+
+* YDialog:
+
+ * YUI::currentDialog() is now moved to YDialog::currentDialog()
+ * YDialog::currentDialog() now throws exceptions by default (unless bool param == true),
+ i.e. there is no more need to check for a 0 pointer after currentDialog()
+ (but exceptions need to be caught somewhere)
+
* YSplit:
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=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am Wed Jun 20 18:12:33 2007
@@ -10,6 +10,7 @@
lib_LTLIBRARIES = libyui.la
libyui_la_SOURCES = \
+ YApplication.cc \
YWidget.cc \
YUIComponent.cc \
YUI_core.cc \
@@ -80,6 +81,7 @@
pkginclude_HEADERS = \
ImplPtr.h \
UI.h \
+ YApplication.h \
YChildrenManager.h \
YOptionalWidgetFactory.h \
YPackageSelectorPlugin.h \
Added: branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc?rev=38933&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc Wed Jun 20 18:12:33 2007
@@ -0,0 +1,55 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| |
+| (c) SuSE Linux Products GmbH |
+\----------------------------------------------------------------------/
+
+ File: YApplication.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#include "YApplication.h"
+#include "YDialog.h"
+#include "YUIException.h"
+#include "YUI.h"
+
+
+struct YApplicationPrivate
+{
+ int dummy;
+};
+
+
+YApplication::YApplication()
+ : priv( new YApplicationPrivate() )
+{
+
+}
+
+
+YApplication::~YApplication()
+{
+ // NOP
+}
+
+
+YWidget *
+YApplication::findWidget( YWidgetID * id, bool doThrow ) const
+{
+ YDialog * dialog = YDialog::currentDialog( doThrow );
+
+ if ( ! dialog ) // has already thrown if doThrow == true
+ return 0;
+
+ return dialog->findWidget( id, doThrow );
+}
Added: branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h?rev=38933&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h Wed Jun 20 18:12:33 2007
@@ -0,0 +1,68 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| |
+| (c) SuSE Linux Products GmbH |
+\----------------------------------------------------------------------/
+
+ File: YApplication.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YApplication_h
+
+#include "ImplPtr.h"
+
+class YWidget;
+class YWidgetID;
+class YApplicationPrivate;
+
+/**
+ * Class for application-wide values and functions.
+ * This is a singleton. Access and create it via its static functions.
+ **/
+class YApplication
+{
+public:
+
+ /**
+ * Find a widget in the topmost dialog by its ID.
+ *
+ * If there is no widget with that ID (or no dialog at all), this function
+ * throws a YUIWidgetNotFoundException if 'doThrow' is 'true'. It returns 0
+ * if 'doThrow' is 'false'.
+ **/
+ YWidget * findWidget( YWidgetID * id, bool doThrow = true ) const;
+
+
+protected:
+
+ friend class YUI;
+ /**
+ * Constructor.
+ *
+ * Use YUI::app() to get the singleton for this class.
+ **/
+ YApplication();
+
+ /**
+ * Destructor.
+ **/
+ virtual ~YApplication();
+
+private:
+
+ ImplPtr<YApplicationPrivate> priv;
+};
+
+#define YApplication_h
+
+#endif // YApplication_h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc Wed Jun 20 18:12:33 2007
@@ -22,10 +22,14 @@
#include
#include "YDialog.h"
#include "YShortcutManager.h"
+#include "YUIException.h"
using std::string;
+std::stack YDialog::_dialogStack;
+
+
YDialog::YDialog( const YWidgetOpt & opt )
: YSingleChildContainerWidget( 0 )
{
@@ -36,6 +40,8 @@
_isCentered.setValue( opt.isCentered.value() );
_hasSmallDecorations.setValue( opt.hasSmallDecorations.value() );
_shortcutCheckPostponed = false;
+
+ _dialogStack.push( this );
}
@@ -44,6 +50,54 @@
}
+YDialog *
+YDialog::currentDialog( bool doThrow )
+{
+ if ( _dialogStack.empty() )
+ {
+ if ( doThrow )
+ YUI_THROW( YUINoDialogException() );
+ return 0;
+ }
+ else
+ return _dialogStack.top();
+}
+
+
+bool
+YDialog::deleteTopmostDialog( bool doThrow )
+{
+ if ( _dialogStack.empty() )
+ {
+ if ( doThrow )
+ YUI_THROW( YUINoDialogException() );
+ }
+ else
+ {
+ delete _dialogStack.top();
+ _dialogStack.pop();
+ }
+
+ return ! _dialogStack.empty();
+}
+
+
+void
+YDialog::deleteAllDialogs()
+{
+ while ( deleteTopmostDialog( false ) )
+ {}
+}
+
+
+int
+YDialog::openDialogsCount()
+{
+ return _dialogStack.size();
+}
+
+
+
void YDialog::setInitialSize()
{
setSize( nicesize( YD_HORIZ ), nicesize( YD_VERT ) );
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YDialog.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YDialog.h?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YDialog.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YDialog.h Wed Jun 20 18:12:33 2007
@@ -21,28 +21,64 @@
#define YDialog_h
#include "YSingleChildContainerWidget.h"
+#include <stack>
class YMacroRecorder;
class YShortcutManager;
-/**
- * @short Realizes a dialog A dialog itself is a container widget. It is never
- * contained in another widget.
- */
class YDialog : public YSingleChildContainerWidget
{
public:
/**
- * Constructor
- */
+ * Constructor.
+ **/
YDialog( const YWidgetOpt & opt );
+protected:
/**
- * Cleanup
- */
+ * Destructor.
+ * Don't delete a dialog directly, use YDialog::deleteCurrentDialog().
+ **/
virtual ~YDialog();
+public:
+ /**
+ * Delete the topmost dialog.
+ *
+ * Will throw a YUINoDialogException if there is no dialog and 'doThrow' is
+ * 'true'.
+ *
+ * Returns 'true' if there is another open dialog after deleting,
+ * 'false' if there is none.
+ **/
+ static bool deleteTopmostDialog( bool doThrow = true );
+
+ /**
+ * Delete all open dialogs.
+ **/
+ static void deleteAllDialogs();
+
+ /**
+ * Returns the number of currently open dialogs (from 1 on), i.e., the
+ * depth of the dialog stack.
+ **/
+ static int openDialogsCount();
+
+ /**
+ * Return the current (topmost) dialog.
+ *
+ * If there is none, throw a YUINoDialogException if 'doThrow' is 'true'
+ * and return 0 if 'doThrow' is false.
+ **/
+ static YDialog * currentDialog( bool doThrow = true );
+
+ /**
+ * Alias for currentDialog().
+ **/
+ static YDialog * topmostDialog( bool doThrow = true )
+ { return currentDialog( doThrow ); }
+
/**
* Returns a descriptive name of this widget class for logging,
* debugging etc.
@@ -156,6 +192,8 @@
YBoolOpt _hasSmallDecorations;
bool _shortcutCheckPostponed;
+
+ static std::stack _dialogStack;
};
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YMacroRecorder.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YMacroRecorder.cc?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YMacroRecorder.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YMacroRecorder.cc Wed Jun 20 18:12:33 2007
@@ -167,14 +167,9 @@
void YMacroRecorder::recordDialogDebugLabel()
{
- YDialog * dialog = YUIComponent::ui()->currentDialog();
-
- if ( dialog )
- {
- fprintf( _macroFile, "%s%s// %s\n",
- YMACRO_INDENT, YMACRO_INDENT,
- dialog->debugLabel().c_str() );
- }
+ fprintf( _macroFile, "%s%s// %s\n",
+ YMACRO_INDENT, YMACRO_INDENT,
+ YDialog::currentDialog()->debugLabel().c_str() );
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YProperty.cc Wed Jun 20 18:12:33 2007
@@ -19,14 +19,14 @@
#include "YProperty.h"
#include "YUIException.h"
+#include "YWidgetID.h"
+#include "YUI.h"
+#include "YApplication.h"
+using std::string;
-#if 0
-using namespace YUI;
-#endif
-
-std::string
+string
YProperty::typeAsStr( YPropertyType type )
{
switch ( type )
@@ -36,6 +36,8 @@
case YStringProperty: return "String";
case YBoolProperty: return "Bool";
case YIntegerProperty: return "Integer";
+ case YWidgetPtrProperty: return "YWidget *";
+ case YWidgetIDProperty: return "YWidgetID *";
// Intentionally omitting default branch
// so the compiler catches unhandled enum values
@@ -45,6 +47,25 @@
}
+YPropertyValue::~YPropertyValue()
+{
+}
+
+
+YWidget *
+YPropertyValue::findWidget()
+{
+ if ( _type == YWidgetPtrProperty )
+ return _widgetPtrVal;
+
+ if ( _type == YWidgetIDProperty )
+ {
+ return YUI::app()->findWidget( _widgetIdVal );
+ }
+
+ return 0;
+}
+
YPropertySet::YPropertySet()
{
@@ -53,7 +74,7 @@
void
-YPropertySet::check( const std::string & propertyName ) const
+YPropertySet::check( const string & propertyName ) const
{
if ( ! contains( propertyName ) )
YUI_THROW( YUIUnknownPropertyException( propertyName ) );
@@ -61,20 +82,20 @@
void
-YPropertySet::check( const std::string & propertyName, YPropertyType type ) const
+YPropertySet::check( const string & propertyName, YPropertyType type ) const
{
if ( ! contains( propertyName ) )
YUI_THROW( YUIUnknownPropertyException( propertyName ) );
- // YPropertySet::contains( const std::string &, YPropertyType ) will throw
+ // YPropertySet::contains( const string &, YPropertyType ) will throw
// a YUIPropertyTypeMismatchException, if applicable
}
bool
-YPropertySet::contains( const std::string & propertyName ) const throw()
+YPropertySet::contains( const string & propertyName ) const throw()
{
- for ( std::vector<YProperty>::const_iterator it = _properties.begin();
+ for ( YPropertySet::const_iterator it = _properties.begin();
it != _properties.end();
++it )
{
@@ -87,9 +108,9 @@
bool
-YPropertySet::contains( const std::string & propertyName, YPropertyType type ) const
+YPropertySet::contains( const string & propertyName, YPropertyType type ) const
{
- for ( std::vector<YProperty>::const_iterator it = _properties.begin();
+ for ( YPropertySet::const_iterator it = _properties.begin();
it != _properties.end();
++it )
{
@@ -100,8 +121,8 @@
if ( it->type() == type )
return true;
- else
- YUI_THROW( YUIPropertyTypeMismatchException( *it, type ) );
+
+ YUI_THROW( YUIPropertyTypeMismatchException( *it, type ) );
}
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YProperty.h Wed Jun 20 18:12:33 2007
@@ -23,255 +23,288 @@
#include <string>
#include <vector>
-#if 0
-namespace YUI
+using std::string;
+
+
+enum YPropertyType
+{
+ YUnknownPropertyType = 0,
+ YOtherProperty, // requires futher checking
+ YStringProperty, // const string &
+ YBoolProperty, // bool
+ YIntegerProperty, // YCP Integer == C++ long long
+ YWidgetPtrProperty, // YWidget *
+ YWidgetIDProperty // YWidgetID *
+};
+
+class YWidget;
+class YWidgetID;
+class YProperty;
+
+typedef long long YInteger;
+
+
+/**
+ * Class for widget properties.
+ **/
+class YProperty
+{
+public:
+ /**
+ * Constructor: Create a property with the specified name and type.
+ * 'isReadOnly' is for properties that cannot be set, only retrieved.
+ **/
+ YProperty( const string & name, YPropertyType type, bool isReadOnly = false )
+ : _name( name )
+ , _type( type )
+ , _isReadOnly( isReadOnly )
+ {}
+
+ /**
+ * Returns the name of this property.
+ **/
+ string name() const { return _name; }
+
+ /**
+ * Returns the type of this property.
+ **/
+ YPropertyType type() const { return _type; }
+
+ /**
+ * Returns 'true' if this property cannot be changed, only retrieved.
+ **/
+ bool isReadOnly() const { return _isReadOnly; }
+
+ /**
+ * Returns the type of this property as string.
+ **/
+ string typeAsStr() const { return YProperty::typeAsStr( _type ); }
+
+ /**
+ * Returns a string description of a property type.
+ **/
+ static string typeAsStr( YPropertyType type );
+
+private:
+
+ string _name;
+ YPropertyType _type;
+ bool _isReadOnly;
+};
+
+
+/**
+ * Transport class for the value of simple properties.
+ *
+ * More complex properties (lists of items, tree descriptions, ...) have to
+ * be handled specifically someplace else, but most properties are of
+ * simple types and can be treated in similar ways.
+ **/
+class YPropertyValue
{
-#endif
+public:
+
+ /**
+ * Constructor for string properties.
+ **/
+ YPropertyValue( const string & str ):
+ _type( YStringProperty ), _stringVal( str ) {}
+
+ /**
+ * Constructor for bool properties.
+ **/
+ YPropertyValue( bool b ):
+ _type( YBoolProperty ), _boolVal( b ) {}
+
+ /**
+ * Constructor for numerical (YCP integer) properties.
+ **/
+ YPropertyValue( YInteger num ):
+ _type( YIntegerProperty ), _integerVal( num ) {}
+
+ /**
+ * Constructor for numerical (YCP integer) properties.
+ **/
+ YPropertyValue( int num ):
+ _type( YIntegerProperty ), _integerVal( num ) {}
+
+ /**
+ * Constructor for YWidget * properties.
+ **/
+ YPropertyValue( YWidget * widget ):
+ _type( YWidgetPtrProperty ), _widgetPtrVal( widget ) {}
+
+ /**
+ * Constructor for YWidgetID * properties.
+ **/
+ YPropertyValue( YWidgetID * id ):
+ _type( YWidgetPtrProperty ), _widgetIdVal( id ) {}
+
+ /**
+ * Default constructor
+ **/
+ YPropertyValue():
+ _type( YUnknownPropertyType ) {}
+
+ /**
+ * Destructor.
+ **/
+ ~YPropertyValue();
+
+ /**
+ * Returns the type of this property value.
+ * Use this to determine which xyVal() method to use.
+ **/
+ YPropertyType type() const { return _type; }
+
+ /**
+ * Returns the type of this property value as string.
+ **/
+ string typeAsStr() const { return YProperty::typeAsStr( _type ); }
+
+ /**
+ * Methods to get the value of this property.
+ * Check with type() which one to use.
+ **/
+ string stringVal() const { return _stringVal; }
+ bool boolVal() const { return _boolVal; }
+ YInteger integerVal() const { return _integerVal; }
+ YWidget * widgetPtrVal() const { return _widgetPtrVal; }
+ YWidgetID * widgetIdVal() const { return _widgetIdVal; }
+
+ /**
+ * Find the widget that corresponds to this property value.
+ * If a widget pointer is specified, return that one.
+ * If not and a widget ID is specified, search the current topmost dialog
+ * for a widget with that ID.
+ *
+ * Throws a YUIWidgetNotFoundException if there is no widget with that ID.
+ **/
+ YWidget * findWidget();
+
+
+private:
+
+ YPropertyType _type;
+ string _stringVal;
+ bool _boolVal;
+ YInteger _integerVal;
+ YWidget * _widgetPtrVal;
+ YWidgetID * _widgetIdVal;
+};
+
+
+/**
+ * A set of properties to check names and types against.
+ **/
+class YPropertySet
+{
+public:
+ /**
+ * Constructor.
+ **/
+ YPropertySet();
+
+ /**
+ * Check if a property 'propertyName' exists in this property set.
+ * Throw a YUIUnknownPropertyException if it does not exist.
+ * Use YPropertySet::contains() for a check that simply returns 'false'
+ * if it does not exist.
+ **/
+ void check( const string & propertyName ) const;
+
+ /**
+ * Check if a property 'propertyName' exists in this property set.
+ * Throw a YUIUnknownPropertyException if it does not exist.
+ *
+ * If there is a property with that name, check also the expected type
+ * against 'type'. If the types don't match, throw a
+ * YUIPropertyTypeMismatchException.
+ * If the property is read-only, throw a YUISetReadOnlyPropertyException.
+ **/
+ void check( const string & propertyName, YPropertyType type ) const;
+
+ /**
+ * Same as above, overloaded for convenience.
+ **/
+ void check( const YProperty & prop ) const
+ { check( prop.name(), prop.type() ); }
+
+ /**
+ * Check if a property 'propertyName' exists in this property set.
+ * Returns 'true' if it exists, 'false' if not.
+ *
+ * Use YPropertySet::check() for a check that throws exceptions if
+ * there is no such property.
+ **/
+ bool contains( const string & propertyName ) const throw();
+
+ /**
+ * Check if a property 'propertyName' exists in this property set.
+ * Returns 'true' if it exists, 'false' if not.
+ *
+ * If there is a property with that name, check also the expected type
+ * against 'type'. If the types don't match, throw a
+ * YUIPropertyTypeMismatchException.
+ *
+ * If the property is read-only, throw a YUISetReadOnlyPropertyException.
+ *
+ * Use YPropertySet::check() for a check that throws exceptions if
+ * there is no such property.
+ **/
+ bool contains( const string & propertyName, YPropertyType type ) const;
+
+ /**
+ * Same as above, overloaded for convenience.
+ **/
+ bool contains( const YProperty & prop ) const
+ { return contains( prop.name(), prop.type() ); }
+
+ /**
+ * Returns 'true' if this property set does not contain anything.
+ **/
+ bool isEmpty() const { return _properties.empty(); }
+
+ /**
+ * Returns the number of properties in this set.
+ **/
+ int size() const { return (int) _properties.size(); }
+
+ /**
+ * Add a property to this property set.
+ **/
+ void add( const YProperty & prop );
+
+ /**
+ * Adds all properties of another property set.
+ *
+ * If that other set contains duplicates (properties that are already
+ * in this set), those others will never be found with lookup().
+ **/
+ void add( const YPropertySet & otherSet );
+
+ typedef std::vector<YProperty>::const_iterator const_iterator;
+
+ /**
+ * Returns an iterator that points to the first property in this set.
+ **/
+ const_iterator propertiesBegin() const;
+
+ /**
+ * Returns an iterator that points after the last property in this set.
+ **/
+ const_iterator propertiesEnd() const;
+
+private:
+
+ /**
+ * This class uses a simple std::vector as a container to hold the
+ * properties: Normally, the number of properties for each widget is so
+ * small (2..5) that using any more sophisticated container like
+ * std::set etc. would not pay off. More likely, it would add overhead.
+ **/
+ std::vector<YProperty> _properties;
+};
- enum YPropertyType
- {
- YUnknownPropertyType = 0,
- YOtherProperty, // requires futher checking
- YStringProperty, // const std::string &
- YBoolProperty, // bool
- YIntegerProperty // YCP Integer == C++ long long
-
- };
-
- typedef long long YInteger;
-
- /**
- * Description class for widget properties
- **/
- class YProperty
- {
- public:
- /**
- * Constructor: Create a property with the specified name and type.
- * 'isReadOnly' is for properties that cannot be set, only retrieved.
- **/
- YProperty( const std::string & name, YPropertyType type, bool isReadOnly = false )
- : _name( name )
- , _type( type )
- , _isReadOnly( isReadOnly )
- {}
-
- /**
- * Returns the name of this property.
- **/
- std::string name() const { return _name; }
-
- /**
- * Returns the type of this property.
- **/
- YPropertyType type() const { return _type; }
-
- /**
- * Returns 'true' if this property cannot be changed, only retrieved.
- **/
- bool isReadOnly() const { return _isReadOnly; }
-
- /**
- * Returns the type of this property as string.
- **/
- std::string typeAsStr() const { return YProperty::typeAsStr( _type ); }
-
- /**
- * Returns a string description of a property type.
- **/
- static std::string typeAsStr( YPropertyType type );
-
- private:
-
- std::string _name;
- YPropertyType _type;
- bool _isReadOnly;
- };
-
-
- /**
- * Transport class for the value of simple properties.
- *
- * More complex properties (lists of items, tree descriptions, ...) have to
- * be handled specifically someplace else, but most properties are of
- * simple types and can be treated in similar ways.
- **/
- class YPropertyValue
- {
- public:
-
- /**
- * Constructor for string properties.
- **/
- YPropertyValue( const std::string & str ):
- _type( YStringProperty ), _stringVal( str ) {}
-
- /**
- * Constructor for bool properties.
- **/
- YPropertyValue( bool b ):
- _type( YBoolProperty ), _boolVal( b ) {}
-
- /**
- * Constructor for numerical (YCP integer) properties.
- **/
- YPropertyValue( YInteger num ):
- _type( YIntegerProperty ), _integerVal( num ) {}
-
- /**
- * Constructor for numerical (YCP integer) properties.
- **/
- YPropertyValue( int num ):
- _type( YIntegerProperty ), _integerVal( num ) {}
-
- /**
- * Default constructor
- **/
- YPropertyValue():
- _type( YUnknownPropertyType ) {}
-
- /**
- * Returns the type of this property value.
- * Use this to determine which xyVal() method to use.
- **/
- YPropertyType type() const { return _type; }
-
- /**
- * Returns the type of this property value as string.
- **/
- std::string typeAsStr() const { return YProperty::typeAsStr( _type ); }
-
- /**
- * Methods to get the value of this property.
- * Check with type() which one to use.
- **/
- std::string stringVal() const { return _stringVal; }
- bool boolVal() const { return _boolVal; }
- YInteger integerVal() const { return _integerVal; }
-
- private:
-
- YPropertyType _type;
- std::string _stringVal;
- bool _boolVal;
- YInteger _integerVal;
- };
-
-
- /**
- * A set of properties to check names and types against.
- **/
- class YPropertySet
- {
- public:
- /**
- * Constructor.
- **/
- YPropertySet();
-
- /**
- * Check if a property 'propertyName' exists in this property set.
- * Throw a YUIUnknownPropertyException if it does not exist.
- * Use YPropertySet::contains() for a check that simply returns 'false'
- * if it does not exist.
- **/
- void check( const std::string & propertyName ) const;
-
- /**
- * Check if a property 'propertyName' exists in this property set.
- * Throw a YUIUnknownPropertyException if it does not exist.
- *
- * If there is a property with that name, check also the expected type
- * against 'type'. If the types don't match, throw a
- * YUIPropertyTypeMismatchException.
- * If the property is read-only, throw a YUISetReadOnlyPropertyException.
- **/
- void check( const std::string & propertyName, YPropertyType type ) const;
-
- /**
- * Same as above, overloaded for convenience.
- **/
- void check( const YProperty & prop ) const
- { check( prop.name(), prop.type() ); }
-
- /**
- * Check if a property 'propertyName' exists in this property set.
- * Returns 'true' if it exists, 'false' if not.
- *
- * Use YPropertySet::check() for a check that throws exceptions if
- * there is no such property.
- **/
- bool contains( const std::string & propertyName ) const throw();
-
- /**
- * Check if a property 'propertyName' exists in this property set.
- * Returns 'true' if it exists, 'false' if not.
- *
- * If there is a property with that name, check also the expected type
- * against 'type'. If the types don't match, throw a
- * YUIPropertyTypeMismatchException.
- *
- * If the property is read-only, throw a YUISetReadOnlyPropertyException.
- *
- * Use YPropertySet::check() for a check that throws exceptions if
- * there is no such property.
- **/
- bool contains( const std::string & propertyName, YPropertyType type ) const;
-
- /**
- * Same as above, overloaded for convenience.
- **/
- bool contains( const YProperty & prop ) const
- { return contains( prop.name(), prop.type() ); }
-
- /**
- * Returns 'true' if this property set does not contain anything.
- **/
- bool isEmpty() const { return _properties.empty(); }
-
- /**
- * Returns the number of properties in this set.
- **/
- int size() const { return (int) _properties.size(); }
-
- /**
- * Add a property to this property set.
- **/
- void add( const YProperty & prop );
-
- /**
- * Adds all properties of another property set.
- *
- * If that other set contains duplicates (properties that are already
- * in this set), those others will never be found with lookup().
- **/
- void add( const YPropertySet & otherSet );
-
- typedef std::vector<YProperty>::const_iterator const_iterator;
-
- /**
- * Returns an iterator that points to the first property in this set.
- **/
- const_iterator propertiesBegin() const;
-
- /**
- * Returns an iterator that points after the last property in this set.
- **/
- const_iterator propertiesEnd() const;
-
- private:
-
- /**
- * This class uses a simple std::vector as a container to hold the
- * properties: Normally, the number of properties for each widget is so
- * small (2..5) that using any more sophisticated container like
- * std::set etc. would not pay off. More likely, it would add overhead.
- **/
- std::vector<YProperty> _properties;
- };
-
-#if 0
-} // namespace YUI
-#endif
#endif // YProperty_h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI.h?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI.h Wed Jun 20 18:12:33 2007
@@ -36,6 +36,7 @@
using std::deque;
using std::string;
+class YApplication;
class YWidget;
class YWidgetFactory;
class YOptionalWidgetFactory;
@@ -126,7 +127,7 @@
/**
* Return the widget factory that provides all the createXY() methods for
* optional ("special") widgets and the corresponding hasXYWidget()
- * methods.
+ * methods.
*
* This will create the factory upon the first call and return a pointer to
* the one and only (singleton) factory upon each subsequent call.
@@ -134,6 +135,21 @@
**/
static YOptionalWidgetFactory * optionalWidgetFactory();
+ /**
+ * Return the global YApplication object.
+ *
+ * This will create the YApplication upon the first call and return a pointer to
+ * the one and only (singleton) YApplication upon each subsequent call.
+ * This may throw exceptions if the YApplication cannot be created.
+ **/
+ static YApplication * app();
+
+ /**
+ * Aliases for YUI::app()
+ **/
+ static YApplication * application() { return app(); }
+ static YApplication * yApp() { return app(); }
+
protected:
/**
@@ -147,18 +163,20 @@
/**
* Create the widget factory that provides all the createXY() methods for
* optional ("special") widgets and the corresponding hasXYWidget()
- * methods.
+ * methods.
*
* Derived classes are required to implement this.
**/
virtual YOptionalWidgetFactory * createOptionalWidgetFactory() = 0;
-public:
/**
- * Look up the topmost dialog.
+ * Create the YApplication object that provides global methods.
+ *
+ * Derived classes are required to implement this.
**/
- YDialog *currentDialog() const;
+ virtual YApplication * createApplication() = 0;
+public:
/**
* Block (or unblock) events. If events are blocked, any event sent
@@ -237,24 +255,16 @@
YWidget *createWidgetTree( YWidget *parent, const YCPTerm & term );
/**
- * Looks up a widget with a certain id. Returns 0 if no
- * such exists. Only the topmost dialog ist searched for the id.
- * @param id id without `id( .. )
- * @param log_error set to true if you want me to log an error if
- * the id is not existing.
- */
-
- YWidget *widgetWithId( const YCPValue & id, bool log_error=false );
+ * Find a widget in the widget tree below 'widgetRoot' with the specified ID.
+ * Throws exceptions if 'doThrow' is 'true' and there is no widget with that ID.
+ **/
+ YWidget * widgetWithId( YWidget *widgetRoot, const YCPValue & id, bool doThrow = false );
/**
- * Overloaded version of widgetWithId. Does not search for the widget id in the
- * topmost dialog but in given widget tree.
- * @param widgetRoot root of the widget tree
- * @param id id without `id( .. )
- * @param log_error set to true if you want me to log an error if
- * the id is not existing.
- */
- YWidget *widgetWithId( YContainerWidget *widgetRoot, const YCPValue & id, bool log_error=false );
+ * Find a widget in the current (topmost) dialog with the specified ID.
+ * Throws exceptions if 'doThrow' is 'true' and there is no widget with that ID.
+ **/
+ YWidget * widgetWithId( const YCPValue & id, bool doThrow = false );
/**
* Returns the default function key number for a widget with the specified
@@ -432,9 +442,9 @@
*
* This is called upon evaluating the UI::UserInput() builtin command.
* This method should remain in its own event loop until an event for the
- * topmost dialog (currentDialog() ) is available or until the specified
- * timeout (in milliseconds, 0 for "wait forever") is expired (in which
- * case it should return the pointer to a YTimeoutEvent).
+ * topmost dialog (YDialog::currentDialog() ) is available or until the
+ * specified timeout (in milliseconds, 0 for "wait forever") is expired (in
+ * which case it should return the pointer to a YTimeoutEvent).
*
* This method is to return a pointer to an event created with the "new"
* operator. The generic UI component assumes ownership of this newly
@@ -452,8 +462,8 @@
*
* This is called upon evaluating the UI::PollInput() builtin command.
* This method should just check if there are any pending events for the
- * topmost dialog (currentDialog() ). This method never waits for any
- * events - if there is no pending event, it returns 0.
+ * topmost dialog (YDialog::currentDialog() ). This method never waits for
+ * any events - if there is no pending event, it returns 0.
*
* If there is a pending event, a pointer to that event (newly created with
* the "new" operator) is returned. The generic UI component assumes
@@ -836,7 +846,7 @@
* in the same terminal
*/
- virtual int runInTerminal( const YCPString & module );
+ virtual int runInTerminal( const YCPString & module );
/**
* UI-specific getDisplayInfo() functions.
@@ -1432,16 +1442,6 @@
void rejectAllOptions( const YCPTerm & term, const YCPList & optList );
/**
- * Enters a dialog into the dialog map.
- */
- void registerDialog( YDialog * );
-
- /**
- * Removes the topmost dialog from the dialog stack and deletes it.
- */
- void removeDialog();
-
- /**
* Checks if the given value is either a symbol or a term `id().
*
* @return 'true' if 'val' is a symbol or a valid `id().
@@ -1464,16 +1464,13 @@
*/
void playNextMacroBlock();
- /**
- * Define type for the dialog map
- */
- typedef vector dialogstack_type;
- /**
- * Container for all dialogs. Each dialog has a unique id, which is
- * a YCPValue.
- */
- dialogstack_type dialogstack;
+
+
+
+ //
+ // Data members
+ //
/**
* Counter for creating unique widget ids
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h Wed Jun 20 18:12:33 2007
@@ -402,6 +402,33 @@
/**
+ * Exception class for "No widget found with that ID".
+ **/
+class YUIWidgetNotFoundException: public YUIException
+{
+public:
+ YUIWidgetNotFoundException( const string & idString )
+ : YUIException( string( "No widget with ID " ) + idString )
+ {}
+
+ virtual ~YUIWidgetNotFoundException() throw()
+ {}
+};
+
+
+class YUINoDialogException: public YUIException
+{
+public:
+ YUINoDialogException()
+ : YUIException( "No dialog existing" )
+ {}
+
+ virtual ~YUINoDialogException() throw()
+ {}
+};
+
+
+/**
* Abstract base class for widget property exceptions.
**/
class YUIPropertyException: public YUIException
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=38933&r1=38932&r2=38933&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 Wed Jun 20 18:12:33 2007
@@ -50,6 +50,7 @@
#include "YReplacePoint.h"
#include "YShortcut.h"
#include "YWizard.h"
+#include "YCPValueWidgetID.h"
using std::string;
@@ -505,19 +506,7 @@
}
- // Check environment: Do we have a dialog to receive input from?
-
- YDialog * dialog = currentDialog();
-
- if ( ! dialog )
- {
- ycperror( "%s(): No dialog existing", builtin_name );
- internalError( "No dialog existing during UserInput().\n"
- "\n"
- "Please check the log file!" );
- return YCPNull();
- }
-
+ YDialog * dialog = YDialog::currentDialog();
// Check for leftover postponed shortcut check
@@ -629,7 +618,7 @@
return 0;
}
- if ( widgetEvent->widget()->findDialog() != currentDialog() )
+ if ( widgetEvent->widget()->findDialog() != YDialog::currentDialog() )
{
/**
* Silently discard events from all but the current (topmost) dialog.
@@ -739,7 +728,6 @@
if ( dialog )
{
- registerDialog( dialog ); // must be done first!
YWidget * child = createWidgetTree( dialog, dialog_term );
if ( child )
@@ -751,7 +739,7 @@
unblockEvents();
return YCPBoolean( true );
}
- else removeDialog();
+ else YDialog::deleteTopmostDialog();
}
unblockEvents();
@@ -773,42 +761,16 @@
YCPValue YUI::evaluateCloseDialog()
{
blockEvents(); // We don't want self-generated events from UI builtins.
- YDialog *dialog = currentDialog();
- if ( ! dialog )
- {
- ycp2error ( "Can't CloseDialog: No dialog existing.");
- return YCPBoolean( false );
- }
+ closeDialog( YDialog::currentDialog() );
+ YDialog::deleteTopmostDialog();
- closeDialog( dialog );
- removeDialog();
unblockEvents();
return YCPBoolean( true );
}
-void YUI::registerDialog( YDialog *dialog )
-{
- dialogstack.push_back( dialog );
-}
-
-
-void YUI::removeDialog()
-{
- delete currentDialog();
- dialogstack.pop_back();
-}
-
-
-YDialog * YUI::currentDialog() const
-{
- if ( dialogstack.size() >= 1 ) return dialogstack.back();
- else return 0;
-}
-
-
void YUI::showDialog( YDialog * )
{
// dummy default implementation
@@ -879,7 +841,7 @@
YPropertyValue val;
- if ( new_value->isString() ) val = YPropertyValue( new_value->asString()->value() );
+ if ( new_value->isString() ) val = YPropertyValue( new_value->asString()->value() );
else if ( new_value->isInteger() ) val = YPropertyValue( new_value->asInteger()->value() );
else if ( new_value->isBoolean() ) val = YPropertyValue( new_value->asBoolean()->value() );
else
@@ -896,6 +858,29 @@
widget->setProperty( sym->symbol(), val );
ret = YCPBoolean( true );
}
+ catch ( YUIPropertyTypeMismatchException & typeMismatchException )
+ {
+ if ( typeMismatchException.property().type() == YWidgetIDProperty )
+ {
+ try
+ {
+ // This is not particularly elegant, but it's the only way with widget IDs that are
+ // YCPStrings or YCPIntegers (which is legal): It's not at all clear if that kind of
+ // YCPValue should be passed as a YCPString or as a widget ID. So now that YCPString
+ // failed, let's try again with a widget ID.
+
+ YCPValueWidgetID widgetID( new_value );
+ val = YPropertyValue( &widgetID );
+
+ widget->setProperty( sym->symbol(), val );
+ ret = YCPBoolean( true );
+ }
+ catch( YUIPropertyException & exception )
+ {
+ y2error( "Caught property exception" );
+ }
+ }
+ }
catch( YUIPropertyException & exception )
{
y2error( "Caught property exception" );
@@ -911,7 +896,7 @@
// The shortcut property has just successfully been changed
// -> time for a new check
- currentDialog()->checkShortcuts();
+ YDialog::currentDialog()->checkShortcuts();
}
unblockEvents();
@@ -983,13 +968,31 @@
try
{
YPropertyValue val = widget->getProperty( sym->symbol() );
-
+
switch ( val.type() )
{
case YStringProperty: return YCPString ( val.stringVal() );
case YBoolProperty: return YCPBoolean( val.boolVal() );
case YIntegerProperty: return YCPInteger( val.integerVal() );
-
+ case YWidgetPtrProperty:
+ {
+ YWidget * widget = val.widgetPtrVal();
+
+ if ( widget->hasId() )
+ {
+ YCPValueWidgetID * id = dynamic_cast ( widget->id() );
+
+ if ( id )
+ return id->value();
+ }
+
+ y2warning( "%s \"%s\" has no ID",
+ widget->widgetClass(),
+ widget->debugLabel().c_str() );
+
+ return YCPVoid();
+ }
+
default:
y2error( "Unknown result for setProperty( %s )", sym->symbol().c_str() );
return YCPVoid();
@@ -1001,7 +1004,7 @@
return YCPVoid();
}
}
-
+
}
else
return widget->queryWidgetTerm( property->asTerm() );
@@ -1046,8 +1049,9 @@
#if VERBOSE_REPLACE_WIDGET
replacePoint->dumpDialogWidgetTree();
#endif
+ YDialog * dialog = YDialog::currentDialog();
- YWidget::OptimizeChanges below( *currentDialog() ); // delay screen updates until this block is left
+ YWidget::OptimizeChanges below( *dialog ); // delay screen updates until this block is left
replacePoint->deleteChildren();
YWidget * child = createWidgetTree( replacePoint, newContentTerm );
@@ -1061,8 +1065,10 @@
if ( child )
{
blockEvents(); // We don't want self-generated events from UI builtins.
- currentDialog()->setInitialSize();
- currentDialog()->checkShortcuts();
+
+ dialog->setInitialSize();
+ dialog->checkShortcuts();
+
unblockEvents();
return YCPBoolean( true );
@@ -1242,15 +1248,7 @@
void YUI::evaluateDumpWidgetTree()
{
- YDialog *dialog = currentDialog();
-
- if ( ! dialog )
- {
- y2error( "DumpWidgetTree: No dialog existing." );
- return;
- }
-
- dialog->dumpDialogWidgetTree();
+ YDialog::currentDialog()->dumpDialogWidgetTree();
}
/**
@@ -1502,16 +1500,7 @@
*/
void YUI::evaluateRecalcLayout()
{
- YDialog *dialog = currentDialog();
-
- if ( ! dialog )
- {
- y2error( "RecalcLayout(): No dialog existing" );
- }
- else
- {
- dialog->setInitialSize();
- }
+ YDialog::currentDialog()->setInitialSize();
}
@@ -1554,16 +1543,7 @@
*/
void YUI::evaluatePostponeShortcutCheck()
{
- YDialog *dialog = currentDialog();
-
- if ( ! dialog )
- {
- y2error( "PostponeShortcutCheck(): No dialog existing" );
- }
- else
- {
- dialog->postponeShortcutCheck();
- }
+ YDialog::currentDialog()->postponeShortcutCheck();
}
@@ -1591,21 +1571,14 @@
*/
void YUI::evaluateCheckShortcuts()
{
- YDialog *dialog = currentDialog();
+ YDialog * dialog = YDialog::currentDialog();
- if ( ! dialog )
+ if ( ! dialog->shortcutCheckPostponed() )
{
- y2error( "CheckShortcuts(): No dialog existing" );
+ y2warning( "Use UI::CheckShortcuts() only after UI::PostponeShortcutCheck() !" );
}
- else
- {
- if ( ! dialog->shortcutCheckPostponed() )
- {
- y2warning( "Use UI::CheckShortcuts() only after UI::PostponeShortcutCheck() !" );
- }
- dialog->checkShortcuts( true );
- }
+ dialog->checkShortcuts( true );
}
@@ -1753,25 +1726,18 @@
YCPValue YUI::evaluateCollectUserInput()
{
- if ( currentDialog() )
- {
- YCPList userInputList;
+ YCPList userInputList;
#if 0
- // FIXME
- // FIXME
- // FIXME
- currentDialog()->collectUserInput( userInputList );
- // FIXME
- // FIXME
- // FIXME
+ // FIXME
+ // FIXME
+ // FIXME
+ YDialog::currentDialog()->collectUserInput( userInputList );
+ // FIXME
+ // FIXME
+ // FIXME
#endif
- return userInputList;
- }
- else
- {
- y2error( "No dialog existing" );
- return YCPNull();
- }
+
+ return userInputList;
}
@@ -1790,7 +1756,7 @@
YCPList userInputList;
widget->collectUserInput( userInputList );
-
+
return userInputList;
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_core.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_core.cc?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI_core.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_core.cc Wed Jun 20 18:12:33 2007
@@ -39,6 +39,7 @@
#include "YUI.h"
#include "YUISymbols.h"
#include "YWidget.h"
+#include "YApplication.h"
#include "YDialog.h"
#include "YRadioButton.h"
@@ -84,22 +85,10 @@
close( pipe_from_ui[1] );
}
- while ( dialogstack.size() > 0 )
- {
- YDialog * dialog = currentDialog();
-
- if ( dialog )
- {
- y2error( "Missing UI::CloseDialog() for" );
-#if 0
- // FIXME
- dialog->dumpWidgetTree();
- // FIXME
-#endif
- }
+ if ( YDialog::openDialogsCount() > 0 )
+ y2error( "%d open dialogs left over", YDialog::openDialogsCount() );
- removeDialog();
- }
+ YDialog::deleteAllDialogs();
deleteMacroRecorder();
deleteMacroPlayer();
@@ -140,6 +129,19 @@
}
+YApplication *
+YUI::app()
+{
+ static YApplication * app = 0;
+
+ if ( ! app )
+ app = ui()->createApplication();
+
+ YUI_CHECK_PTR( app );
+ return app;
+}
+
+
void
YUI::internalError( const char *msg )
{
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_widgets.cc Wed Jun 20 18:12:33 2007
@@ -2458,52 +2458,27 @@
-YWidget * YUI::widgetWithId( const YCPValue & idVal, bool log_error )
+YWidget *
+YUI::widgetWithId( const YCPValue & idVal, bool doThrow )
{
- if ( currentDialog() )
- {
- YCPValueWidgetID id( idVal );
- YWidget *widget = currentDialog()->findWidget( &id );
- if ( widget ) return widget;
- if ( log_error )
- {
- y2error( "No widget with `" YUISymbol_id "(%s)", idVal->toString().c_str() );
- ycperror( "No widget with `" YUISymbol_id "(%s)", idVal->toString().c_str() );
- }
- }
- else if ( log_error )
- {
- y2error( "No dialog existing, therefore no widget with `" YUISymbol_id "(%s)", idVal->toString().c_str() );
- ycperror( "No dialog existing, therefore no widget with `" YUISymbol_id "(%s)", idVal->toString().c_str() );
- }
+ YDialog * dialog = YDialog::currentDialog( doThrow );
- return 0;
+ if ( dialog )
+ return widgetWithId( dialog, idVal, doThrow );
+ else
+ return 0;
}
-YWidget * YUI::widgetWithId( YContainerWidget *widgetRoot, const YCPValue & idVal, bool log_error )
+YWidget *
+YUI::widgetWithId( YWidget * widgetRoot, const YCPValue & idVal, bool doThrow )
{
- if ( widgetRoot )
- {
- YCPValueWidgetID id( idVal );
- YWidget *widget = widgetRoot->findWidget( &id );
-
- if ( widget )
- return widget;
+ YUI_CHECK_PTR( widgetRoot );
+
+ YCPValueWidgetID id( idVal );
+ YWidget * widget = widgetRoot->findWidget( &id, doThrow );
- if ( log_error )
- {
- y2error( "No widget with `" YUISymbol_id "(%s)", idVal->toString().c_str() );
- ycperror( "No widget with `" YUISymbol_id "(%s)", idVal->toString().c_str() );
- }
- }
- else if ( log_error )
- {
- y2error( "No dialog existing, therefore no widget with `" YUISymbol_id "( %s )", idVal->toString().c_str() );
- ycperror( "No dialog existing, therefore no widget with `" YUISymbol_id "( %s )", idVal->toString().c_str() );
- }
-
- return 0;
+ return widget;
}
@@ -2612,8 +2587,10 @@
}
YCPValue id = idterm->value(0);
- // unique?
- if ( widgetWithId( id ) )
+
+ y2debug( "Checking if widget ID %s is unique", idterm->toString().c_str() );
+
+ if ( widgetWithId( id, false ) ) // Already have a widget with that ID?
{
y2error( "Widget id %s is not unique", id->toString().c_str() );
return YCPNull();
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=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.cc Wed Jun 20 18:12:33 2007
@@ -477,10 +477,15 @@
YWidget *
-YWidget::findWidget( YWidgetID * id ) const
+YWidget::findWidget( YWidgetID * id, bool doThrow ) const
{
if ( ! id )
+ {
+ if ( doThrow )
+ YUI_THROW( YUIWidgetNotFoundException( "Null ID" ) );
+
return 0;
+ }
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
@@ -494,13 +499,16 @@
if ( child->hasChildren() )
{
- YWidget * found = child->findWidget( id );
+ YWidget * found = child->findWidget( id, doThrow );
if ( found )
return found;
}
}
+ if ( doThrow )
+ YUI_THROW( YUIWidgetNotFoundException( id->toString() ) );
+
return 0;
}
@@ -756,7 +764,7 @@
*/
if ( symbol == YUIProperty_DialogDebugLabel )
{
- return YUIComponent::ui()->currentDialog()->queryWidget( property );
+ return YDialog::currentDialog()->queryWidget( property );
}
else
{
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h?rev=38933&r1=38932&r2=38933&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YWidget.h Wed Jun 20 18:12:33 2007
@@ -246,9 +246,12 @@
YDialog * findDialog();
/**
- * Recursively find a widget by its ID. Returns 0 if not found.
+ * Recursively find a widget by its ID.
+ * If there is no widget with that ID, this function throws a
+ * YUIWidgetNotFoundException if 'doThrow' is 'true'. It returns 0 if
+ * 'doThrow' is 'false'.
**/
- YWidget * findWidget( YWidgetID * id ) const;
+ YWidget * findWidget( YWidgetID * id, bool doThrow = true ) const;
//
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org