Author: sh-sh-sh Date: Thu Apr 3 15:24:10 2008 New Revision: 46031 URL: http://svn.opensuse.org/viewcvs/yast?rev=46031&view=rev Log: help handling Modified: trunk/libyui/package/yast2-libyui.changes trunk/libyui/src/YDialog.cc trunk/libyui/src/YDialog.h trunk/libyui/src/YPushButton.cc trunk/libyui/src/YPushButton.h trunk/libyui/src/YUISymbols.h Modified: trunk/libyui/package/yast2-libyui.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/package/yast2-libyui.chang... ============================================================================== --- trunk/libyui/package/yast2-libyui.changes (original) +++ trunk/libyui/package/yast2-libyui.changes Thu Apr 3 15:24:10 2008 @@ -1,9 +1,16 @@ ------------------------------------------------------------------- +Thu Apr 3 15:03:35 CEST 2008 - sh@suse.de + +- Added YPushButton::setHelpButton() and isHelpButton() +- Automatically show topmost YWidget::helpText() when a help button + is activated +- V 2.16.41 + +------------------------------------------------------------------- Tue Apr 1 17:49:15 CEST 2008 - sh@suse.de - Added "HelpText" property to YWidget for easier support of YCP wizard layouts without permanent help panel (fate #303291) -- V 2.16.41 ------------------------------------------------------------------- Thu Mar 20 19:17:19 CET 2008 - sh@suse.de Modified: trunk/libyui/src/YDialog.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YDialog.cc?rev=46031&a... ============================================================================== --- trunk/libyui/src/YDialog.cc (original) +++ trunk/libyui/src/YDialog.cc Thu Apr 3 15:24:10 2008 @@ -23,6 +23,12 @@ #include "YDialog.h" #include "YShortcutManager.h" #include "YPushButton.h" + +#include "YUI.h" +#include "YWidgetFactory.h" +#include "YLayoutBox.h" +#include "YRichText.h" +#include "YAlignment.h" #include "YUIException.h" using std::string; @@ -256,6 +262,41 @@ // If there was no event or if filterInvalidEvents() discarded // an invalid event, go back and get the next one. + + if ( event->widget() ) + { + YPushButton * button = dynamic_cast<YPushButton *> ( event->widget() ); + + if ( button && button->isHelpButton() ) + { + string helpText; + YWidget * widget = button; + + while ( widget ) + { + if ( ! widget->helpText().empty() ) + { + yuiDebug() << "Found help text for " << widget << endl; + helpText = widget->helpText(); + } + + widget = widget->parent(); + } + + if ( ! helpText.empty() ) + { + yuiMilestone() << "Showing help text" << endl; + showText( helpText, true ); + yuiMilestone() << "Help dialog closed" << endl; + } + else + yuiWarning() << "No help text in dialog " << this << endl; + + delete event; + event = 0; + } + } + } while ( ! event ); return event; @@ -419,3 +460,28 @@ } +void +YDialog::showText( const string & text, bool useRichText ) +{ + try + { + YDialog * dialog = YUI::widgetFactory()->createPopupDialog(); + YAlignment * minSize = YUI::widgetFactory()->createMinSize( dialog, 45, 15 ); + YLayoutBox * vbox = YUI::widgetFactory()->createVBox( minSize ); + YUI::widgetFactory()->createRichText( vbox, text, ! useRichText ); + YPushButton * okButton = YUI::widgetFactory()->createPushButton( vbox, "&OK" ); + okButton->setDefaultButton(); + + YEvent * event = dialog->waitForEvent(); + + if ( event ) + delete event; + dialog->destroy(); + } + catch ( YUIException exception ) + { + // Don't let the application die just because help couldn't be displayed. + + YUI_CAUGHT( exception ); + } +} Modified: trunk/libyui/src/YDialog.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YDialog.h?rev=46031&am... ============================================================================== --- trunk/libyui/src/YDialog.h (original) +++ trunk/libyui/src/YDialog.h Thu Apr 3 15:24:10 2008 @@ -256,6 +256,13 @@ **/ virtual void activate() = 0; + /** + * Show the specified text in a pop-up dialog with a local event loop. + * This is useful for help texts. + * 'richText' indicates if YRichText formatting should be applied. + **/ + static void showText( const string & text, bool richText = false ); + protected: Modified: trunk/libyui/src/YPushButton.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YPushButton.cc?rev=460... ============================================================================== --- trunk/libyui/src/YPushButton.cc (original) +++ trunk/libyui/src/YPushButton.cc Thu Apr 3 15:24:10 2008 @@ -36,11 +36,13 @@ : label( label ) , isDefaultButton( false ) , setDefaultButtonRecursive( false ) + , isHelpButton( false ) {} string label; bool isDefaultButton; bool setDefaultButtonRecursive; + bool isHelpButton; }; @@ -113,6 +115,19 @@ } +bool YPushButton::isHelpButton() const +{ + return priv->isHelpButton; +} + + +void YPushButton::setHelpButton( bool helpButton ) +{ + priv->isHelpButton = helpButton; +} + + + const YPropertySet & YPushButton::propertySet() { Modified: trunk/libyui/src/YPushButton.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YPushButton.h?rev=4603... ============================================================================== --- trunk/libyui/src/YPushButton.h (original) +++ trunk/libyui/src/YPushButton.h Thu Apr 3 15:24:10 2008 @@ -60,6 +60,15 @@ virtual void setLabel( const string & label ); /** + * Set this button's icon from an icon file in the UI's default icon + * directory. Clear the icon if the name is empty. + * + * This default implementation does nothing. + * UIs that can handle icons can choose to overwrite this method. + **/ + virtual void setIcon( const string & iconName ) {} + + /** * Returns 'true' if this is the dialog's default button, i.e. the one * button that gets activated if the user hits the [Return] key anywhere in * the dialog. @@ -70,18 +79,32 @@ * Make this button the default button. * * Derived classes should reimplement this, but call this base class - * function in the overwritten function. + * function in the overwritten function. **/ virtual void setDefaultButton( bool def = true ); /** - * Set this button's icon from an icon file in the UI's default icon - * directory. Clear the icon if the name is empty. + * Returns 'true' if this is a "Help" button. * - * This default implementation does nothing. - * UIs that can handle icons can choose to overwrite this method. + * When activated, a help button will traverse up its widget hierarchy and + * search for the topmost widget with a helpText() set and display that + * help text in a pop-up dialog (with a local event loop). + * + * NOTE that this is only done during YDialog::waitForEvent() (i.e. in YCP + * UI::WaitForEvent(), UI::UserInput(), UI::TimeoutUserInput() ) and not + * during YDialog::pollEvent() (i.e. YCP UI::PollInput()) since displaying + * the help text will block the application until the user closes the help + * text. **/ - virtual void setIcon( const string & iconName ) {} + bool isHelpButton() const; + + /** + * Make this button a help button. + * + * Derived classes are free to reimplement this, but they should call this + * base class method in the overloaded function. + **/ + virtual void setHelpButton( bool helpButton = true ); /** * Set a property. @@ -111,7 +134,7 @@ * Reimplemented from YWidget. **/ virtual const YPropertySet & propertySet(); - + /** * Get the string of this widget that holds the keyboard shortcut. * Modified: trunk/libyui/src/YUISymbols.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YUISymbols.h?rev=46031... ============================================================================== --- trunk/libyui/src/YUISymbols.h (original) +++ trunk/libyui/src/YUISymbols.h Thu Apr 3 15:24:10 2008 @@ -196,6 +196,7 @@ #define YUIOpt_disabled "disabled" #define YUIOpt_easterEgg "easterEgg" #define YUIOpt_editable "editable" +#define YUIOpt_helpButton "helpButton" #define YUIOpt_hstretch "hstretch" #define YUIOpt_hvstretch "hvstretch" #define YUIOpt_immediate "immediate" -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org