Author: sh-sh-sh
Date: Tue Nov 6 16:41:09 2007
New Revision: 41825
URL: http://svn.opensuse.org/viewcvs/yast?rev=41825&view=rev
Log:
ported default function key handling
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc
branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h
branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc
branches/tmp/sh/mod-ui/core/libyui/src/YUI.h
branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc
Modified: 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=41825&r1=41824&r2=41825&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc Tue Nov 6 16:41:09 2007
@@ -18,15 +18,22 @@
/-*/
+#include <map>
#include "YApplication.h"
#include "YDialog.h"
#include "YUIException.h"
+#include "YShortcut.h"
#include "YUI.h"
+using std::map;
+
+typedef map YFunctionKeyMap;
+
struct YApplicationPrivate
{
- string iconBasePath;
+ string iconBasePath;
+ YFunctionKeyMap defaultFunctionKey;
};
@@ -62,8 +69,38 @@
}
-void YApplication::setIconBasePath( const string & newIconBasePath )
+void
+YApplication::setIconBasePath( const string & newIconBasePath )
{
priv->iconBasePath = newIconBasePath;
}
+
+int
+YApplication::defaultFunctionKey( const string & label ) const
+{
+ YFunctionKeyMap::const_iterator result =
+ priv->defaultFunctionKey.find( YShortcut::cleanShortcutString( label ) );
+
+ if ( result == priv->defaultFunctionKey.end() )
+ return 0;
+ else
+ return result->second;
+}
+
+
+void
+YApplication::setDefaultFunctionKey( const string & label, int fkey )
+{
+ if ( fkey > 0 )
+ priv->defaultFunctionKey[ YShortcut::cleanShortcutString( label ) ] = fkey;
+ else
+ YUI_THROW( YUIException( "Bad function key number" ) );
+}
+
+
+void
+YApplication::clearDefaultFunctionKeys()
+{
+ priv->defaultFunctionKey.clear();
+}
Modified: 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=41825&r1=41824&r2=41825&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h Tue Nov 6 16:41:09 2007
@@ -59,6 +59,41 @@
**/
virtual void setIconBasePath( const string & newIconBasePath );
+ /**
+ * Return the default function key number for a widget with the specified
+ * label or 0 if there is none. Any keyboard shortcuts that may be
+ * contained in 'label' are stripped away before any comparison.
+ *
+ * The basic idea behind this concept is to have an easy default mapping
+ * from buttons etc. with the same semantics to function keys:
+ *
+ * "OK" -> F10
+ * "Accept" -> F10
+ * "Yes" -> F10
+ * "Next" -> F10
+ *
+ * "Cancel" -> F9
+ * "No" -> F9
+ * ...
+ *
+ * This function returns 10 for F10, F for F9 etc.;
+ * 0 means "no function key".
+ **/
+ int defaultFunctionKey( const string & label ) const;
+
+ /**
+ * Add a mapping from the specified label to the specified F-key number.
+ * This is the counterpart to defaultFunctionKey().
+ *
+ * This only affects widgets that are created after this call.
+ **/
+ void setDefaultFunctionKey( const string & label, int fkey );
+
+ /**
+ * Clear all previous label-to-function-key mappings.
+ **/
+ void clearDefaultFunctionKeys();
+
protected:
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc?rev=41825&r1=41824&r2=41825&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YPushButton.cc Tue Nov 6 16:41:09 2007
@@ -20,6 +20,8 @@
#define y2log_component "ui"
#include
+#include "YUI.h"
+#include "YApplication.h"
#include "YUISymbols.h"
#include "YPushButton.h"
@@ -46,6 +48,10 @@
: YWidget( parent )
, priv( new YPushButtonPrivate( label ) )
{
+ int fkey = YUI::app()->defaultFunctionKey( label );
+
+ if ( fkey > 0 && ! hasFunctionKey() )
+ setFunctionKey( fkey );
}
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=41825&r1=41824&r2=41825&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI.h Tue Nov 6 16:41:09 2007
@@ -128,9 +128,10 @@
/**
* 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.
+ * 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();
@@ -218,13 +219,6 @@
string & dest );
/**
- * Returns the default function key number for a widget with the specified
- * label or 0 if there is none. Any keyboard shortcuts that may be
- * contained in 'label' are stripped away before any comparison.
- **/
- int defaultFunctionKey( YCPString label );
-
- /**
* Returns the current product name
* ("SuSE Linux", "SuSE Linux Enterprise Server", "United Linux", etc.).
*
@@ -899,11 +893,6 @@
deque<YCPValue> fakeUserInputQueue;
/**
- * The current mapping of widget labels to default function keys.
- **/
- YCPMap default_fkeys;
-
- /**
* Flag that keeps track of blocked events.
* Never query this directly, use eventsBlocked() instead.
**/
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=41825&r1=41824&r2=41825&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 Tue Nov 6 16:41:09 2007
@@ -41,6 +41,7 @@
#include
#include "YUI.h"
+#include "YApplication.h"
#include "YEvent.h"
#include "YUIException.h"
#include "YUISymbols.h"
@@ -1783,51 +1784,31 @@
*/
void YUI::evaluateSetFunctionKeys( const YCPMap & new_fkeys )
{
- default_fkeys = YCPMap();
-
- for ( YCPMapIterator it = new_fkeys->begin(); it != new_fkeys->end(); ++it )
+ for ( YCPMapIterator it = new_fkeys->begin(); it != new_fkeys->end(); ++it )
+ {
+ if ( it.key()->isString() && it.value()->isInteger() )
{
- if ( it.key()->isString() && it.value()->isInteger() )
- {
- string label = YShortcut::cleanShortcutString( it.key()->asString()->value() );
- int fkey = it.value()->asInteger()->value();
+ string label = YShortcut::cleanShortcutString( it.key()->asString()->value() );
+ int fkey = it.value()->asInteger()->value();
- if ( fkey > 0 && fkey <= 24 )
- {
- y2debug( "Mapping \"%s\"\t-> F%d", label.c_str(), fkey );
- default_fkeys->add( YCPString( label ), it.value()->asInteger() );
- }
- else
- {
- y2error( "SetFunctionKeys(): Function key %d out of range for \"%s\"",
- fkey, label.c_str() );
- }
+ if ( fkey > 0 && fkey <= 24 )
+ {
+ y2debug( "Mapping \"%s\"\t-> F%d", label.c_str(), fkey );
+ app()->setDefaultFunctionKey( label, fkey );
}
else
{
- y2error( "SetFunctionKeys(): Invalid map element: "
- "Expected <string>: <integer>, not %s: %s",
- it.key()->toString().c_str(), it.value()->toString().c_str() );
+ ycperror( "SetFunctionKeys(): Function key %d out of range for \"%s\"",
+ fkey, label.c_str() );
}
}
-}
-
-
-int YUI::defaultFunctionKey( YCPString ylabel )
-{
- int fkey = 0;
-
- string label = YShortcut::cleanShortcutString( ylabel->value() );
-
- if ( label.size() > 0 )
- {
- YCPValue val = default_fkeys->value( YCPString( label ) );
-
- if ( ! val.isNull() && val->isInteger() )
- fkey = val->asInteger()->value();
+ else
+ {
+ ycperror( "SetFunctionKeys(): Invalid map element: "
+ "Expected <string>: <integer>, not %s: %s",
+ it.key()->toString().c_str(), it.value()->toString().c_str() );
+ }
}
-
- return fkey;
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org