From d17b6f2f9e9142552af0b164c3b86387833d96c9 Mon Sep 17 00:00:00 2001 From: Eduardo Fiss Beloni Date: Wed, 23 Apr 2014 11:59:24 -0300 Subject: [PATCH] Xtt script ConfirmDialog --- xtt/lib/xtt/gtk/xtt_xnav_gtk.cpp | 29 +++++++++++++++++++++++++++++ xtt/lib/xtt/gtk/xtt_xnav_gtk.h | 1 + xtt/lib/xtt/src/xtt_xnav.h | 3 +++ xtt/lib/xtt/src/xtt_xnav_command.cpp | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 0 deletions(-) diff --git a/xtt/lib/xtt/gtk/xtt_xnav_gtk.cpp b/xtt/lib/xtt/gtk/xtt_xnav_gtk.cpp index 47e1450..001e8c7 100644 --- a/xtt/lib/xtt/gtk/xtt_xnav_gtk.cpp +++ b/xtt/lib/xtt/gtk/xtt_xnav_gtk.cpp @@ -467,3 +467,32 @@ void XNavGtk::popup_button_cb( GtkWidget *w, gpointer data) //xnav->reset_cursor(); } +static void xnav_confirm_dialog_ok( void *ctx, void *data) +{ + ((XNav *)ctx)->dialog_ok = 1; + gtk_main_quit(); +} + +static void xnav_confirm_dialog_cancel( void *ctx, void *data) +{ + ((XNav *)ctx)->dialog_cancel = 1; + gtk_main_quit(); +} + +int XNavGtk::confirm_dialog( char *title, char *text) +{ + dialog_ok = 0; + dialog_cancel = 0; + wow->DisplayQuestion( this, title, text, xnav_confirm_dialog_ok, + xnav_confirm_dialog_cancel, 0); + + gtk_main(); + + if ( dialog_ok) { + return 1; + } + if ( dialog_cancel) { + return 0; + } + return 0; +} diff --git a/xtt/lib/xtt/gtk/xtt_xnav_gtk.h b/xtt/lib/xtt/gtk/xtt_xnav_gtk.h index 4570334..d005188 100644 --- a/xtt/lib/xtt/gtk/xtt_xnav_gtk.h +++ b/xtt/lib/xtt/gtk/xtt_xnav_gtk.h @@ -115,6 +115,7 @@ class XNavGtk : public XNav { xmenu_eItemType item_type, xmenu_mUtility caller, unsigned int priv, char *arg, int x, int y); + int confirm_dialog( char *title, char *text); static void menu_position_func( GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data); static GtkWidget *build_menu( GtkWidget *Parent, diff --git a/xtt/lib/xtt/src/xtt_xnav.h b/xtt/lib/xtt/src/xtt_xnav.h index 1af10ab..62b658a 100644 --- a/xtt/lib/xtt/src/xtt_xnav.h +++ b/xtt/lib/xtt/src/xtt_xnav.h @@ -332,6 +332,8 @@ class XNav { void *current_cmd_ctx; int elog_enabled; int elog_checked; + int dialog_ok; + int dialog_cancel; virtual void set_inputfocus() {} virtual void pop() {} @@ -389,6 +391,7 @@ class XNav { void (* wl_bc_cancel)( void *), pwr_tStatus *status) { return 0;} virtual void bell( int time) {} + virtual int confirm_dialog( char *title, char *text) { return 0; } void start_trace( pwr_tObjid Objid, char *object_str); void start_trace_selected(); diff --git a/xtt/lib/xtt/src/xtt_xnav_command.cpp b/xtt/lib/xtt/src/xtt_xnav_command.cpp index 9dd4e08..5e9720f 100644 --- a/xtt/lib/xtt/src/xtt_xnav_command.cpp +++ b/xtt/lib/xtt/src/xtt_xnav_command.cpp @@ -7509,6 +7509,38 @@ static int xnav_messageinfo_func( return 1; } +static int xnav_confirmdialog_func( + void *filectx, + ccm_sArg *arg_list, + int arg_count, + int *return_decl, + ccm_tFloat *return_float, + ccm_tInt *return_int, + char *return_string) +{ + XNav *xnav; + ccm_sArg *arg_p2; + int sts; + + if ( arg_count != 2) + return CCM__ARGMISM; + + arg_p2 = arg_list->next; + + if ( arg_list->value_decl != CCM_DECL_STRING) + return CCM__ARGMISM; + if ( arg_p2->value_decl != CCM_DECL_STRING) + return CCM__ARGMISM; + + xnav_get_stored_xnav( &xnav); + sts = xnav->confirm_dialog( arg_list->value_string, arg_p2->value_string); + + *return_int = sts; + *return_decl = CCM_DECL_INT; + + return 1; +} + static int xnav_cutobjectname_func( void *filectx, ccm_sArg *arg_list, @@ -7678,6 +7710,8 @@ int XNav::readcmdfile( char *incommand) if ( EVEN(sts)) return sts; sts = ccm_register_function( "GetAttribute", xnav_getattribute_func); if ( EVEN(sts)) return sts; + sts = ccm_register_function( "ConfirmDialog", xnav_confirmdialog_func); + if ( EVEN(sts)) return sts; ccm_func_registred = 1; } -- 1.7.4.1