[yast-commit] r40654 - in /trunk/gtk: ChangeLog package/yast2-gtk.changes src/YGDialog.cc src/YGDialog.h src/YGPackageSelector.cc src/YGUI.h
Author: michael_meeks Date: Fri Aug 31 16:33:37 2007 New Revision: 40654 URL: http://svn.opensuse.org/viewcvs/yast?rev=40654&view=rev Log: 2007-08-26 Michael Meeks <michael.meeks@novell.com> * src/YGPackageSelector.cc (does_package_match_one): don't fetch the obj unless we need to - hugely accelerates search. * src/YGPackageSelector.cc (PackageSelector): use search_activate_cb for 'activate' on the entry, so we don't wait 1 second when the user hits 'enter' ;-) 2007-08-25 Michael Meeks <michael.meeks@novell.com> * src/YGPackageSelector.cc: merge two gtk_tree_model_gets. (checkDelete): use this to get user confirmation on exit if there are unsaved changes etc. n#300390 * src/YGDialog.cc (close_window_cb, setDeleteCallback): add ability to set a custom dlete callback. (currentYGDialog): expose as YGDialog. * src/YGDialog.h: add: needed in YGPackageSelector. Added: trunk/gtk/src/YGDialog.h Modified: trunk/gtk/ChangeLog trunk/gtk/package/yast2-gtk.changes trunk/gtk/src/YGDialog.cc trunk/gtk/src/YGPackageSelector.cc trunk/gtk/src/YGUI.h Modified: trunk/gtk/ChangeLog URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/ChangeLog?rev=40654&r1=40653&r2=40654&view=diff ============================================================================== --- trunk/gtk/ChangeLog (original) +++ trunk/gtk/ChangeLog Fri Aug 31 16:33:37 2007 @@ -1,3 +1,25 @@ +2007-08-26 Michael Meeks <michael.meeks@novell.com> + + * src/YGPackageSelector.cc (does_package_match_one): + don't fetch the obj unless we need to - hugely accelerates + search. + + * src/YGPackageSelector.cc (PackageSelector): use + search_activate_cb for 'activate' on the entry, so we + don't wait 1 second when the user hits 'enter' ;-) + +2007-08-25 Michael Meeks <michael.meeks@novell.com> + + * src/YGPackageSelector.cc: merge two gtk_tree_model_gets. + (checkDelete): use this to get user confirmation on exit if + there are unsaved changes etc. n#300390 + + * src/YGDialog.cc (close_window_cb, setDeleteCallback): add + ability to set a custom dlete callback. + (currentYGDialog): expose as YGDialog. + + * src/YGDialog.h: add: needed in YGPackageSelector. + 2007-08-22 Michael Meeks <michael.meeks@novell.com> * src/YGProgressBar.cc (YGProgressBar): implement pulse Modified: trunk/gtk/package/yast2-gtk.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/package/yast2-gtk.changes?rev=40654&r1=40653&r2=40654&view=diff ============================================================================== --- trunk/gtk/package/yast2-gtk.changes (original) +++ trunk/gtk/package/yast2-gtk.changes Fri Aug 31 16:33:37 2007 @@ -1,4 +1,14 @@ ------------------------------------------------------------------- +Wed Aug 26 15:32:01 BST 2007 - mmichael@suse.de + +- n#300390: warn if cancelling a non-submitted transaction. + +------------------------------------------------------------------- +Wed Aug 8 15:32:01 BST 2007 - mmichael@suse.de + +- #296945: pulse progress bar impl. + +------------------------------------------------------------------- Fri Aug 10 18:01:20 CEST 2007 - mvidner@suse.cz - Finished integrating Feature #120292, UI as a namespace callable Modified: trunk/gtk/src/YGDialog.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGDialog.cc?rev=40654&r1=40653&r2=40654&view=diff ============================================================================== --- trunk/gtk/src/YGDialog.cc (original) +++ trunk/gtk/src/YGDialog.cc Fri Aug 31 16:33:37 2007 @@ -5,7 +5,7 @@ #include <config.h> #include <ycp/y2log.h> #include <YGUI.h> -#include "YGWidget.h" +#include "YGDialog.h" #include <gdk/gdkkeysyms.h> #include <math.h> // easter @@ -21,283 +21,266 @@ class YGWindow; static YGWindow *main_window = NULL; -class YGWindow +YGWindow::~YGWindow() { - GtkWidget *m_widget; - int m_refcount; - // we keep a pointer of the child just for debugging - // (ie. dump yast tree) - YWidget *m_child; - -public: - YGWindow (bool main_window) - { - m_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_object_ref (G_OBJECT (m_widget)); - gtk_object_sink (GTK_OBJECT (m_widget)); - - m_refcount = 0; - if (main_window) - ::main_window = this; - m_child = NULL; - - { - GtkWindow *parent = YGUI::ui()->currentWindow(); - GtkWindow *window = GTK_WINDOW (m_widget); - - if (parent) { - // if there is a parent, this would be a dialog - gtk_window_set_transient_for (window, parent); - gtk_window_set_title (window, ""); - - gtk_window_set_modal (window, TRUE); - gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DIALOG); - } - else { - gtk_window_set_title (window, "YaST"); - if (YGUI::ui()->unsetBorder()) - gtk_window_set_decorated (window, FALSE); - } - - if (main_window) { - int w = YGUI::ui()->getDefaultSize (YD_HORIZ), - h = YGUI::ui()->getDefaultSize (YD_VERT); - gtk_window_set_default_size (window, w, h); - } - - gtk_window_set_role (window, "yast-gtk"); - if (!YGUI::ui()->hasWM()) - g_signal_connect (G_OBJECT (m_widget), "expose-event", - G_CALLBACK (draw_border_cb), this); - } - - g_signal_connect (G_OBJECT (m_widget), "delete_event", - G_CALLBACK (close_window_cb), this); - g_signal_connect_after (G_OBJECT (m_widget), "key-press-event", - G_CALLBACK (key_pressed_cb), this); - } - - ~YGWindow() - { - IMPL + IMPL setChild (NULL); - gtk_widget_destroy (m_widget); - g_object_unref (G_OBJECT (m_widget)); - } + gtk_widget_destroy (m_widget); + g_object_unref (G_OBJECT (m_widget)); +} - void setChild (YWidget *new_child) - { - IMPL +void YGWindow::setChild (YWidget *new_child) +{ + IMPL GtkWidget *child = gtk_bin_get_child (GTK_BIN (m_widget)); - if (child) - gtk_container_remove (GTK_CONTAINER (m_widget), child); - if (new_child) { - child = YGWidget::get (new_child)->getLayout(); - gtk_container_add (GTK_CONTAINER (m_widget), child); - } - m_child = new_child; - } - - // YGDialog should not destroy its YGWindow. Instead, they should use this - // simple ref-count mechanism to ensure there is no other window open. - static void ref (YGWindow *window) - { window->m_refcount++; } - static void unref (YGWindow *window) - { - if (--window->m_refcount == 0) { - bool is_main_window = (window == main_window); - delete window; - if (is_main_window) - main_window = NULL; - } - } - - // Y(G)Widget-like methods - GtkWidget *getWidget() - { return m_widget; } - - static gboolean close_window_cb (GtkWidget *widget, GdkEvent *event, - YGWindow *pThis) - { - IMPL - YGUI::ui()->sendEvent (new YCancelEvent()); - return TRUE; - } + if (child) + gtk_container_remove (GTK_CONTAINER (m_widget), child); + if (new_child) { + child = YGWidget::get (new_child)->getLayout(); + gtk_container_add (GTK_CONTAINER (m_widget), child); + } + m_child = new_child; +} - static gboolean key_pressed_cb (GtkWidget *widget, GdkEventKey *event, - YGWindow *pThis) - { - IMPL - // if not main dialog, close it on escape - if (event->keyval == GDK_Escape && - /* not main window */ main_window != pThis) - return close_window_cb (widget, NULL, pThis); - - if ((event->state & GDK_CONTROL_MASK) && (event->state & GDK_SHIFT_MASK) - && (event->state & GDK_MOD1_MASK)) { - y2milestone ("Caught YaST2 magic key combination"); - switch (event->keyval) { - case GDK_S: - YGUI::ui()->makeScreenShot(""); - return TRUE; - case GDK_M: - YGUI::ui()->toggleRecordMacro(); - return TRUE; - case GDK_P: - YGUI::ui()->askPlayMacro(); - return TRUE; - case GDK_D: - YGUI::ui()->sendEvent (new YDebugEvent()); - return TRUE; - case GDK_X: - y2milestone ("Starting xterm"); - system ("/usr/bin/xterm &"); - return TRUE; - case GDK_T: - dumpYastTree (pThis->m_child, GTK_WINDOW (pThis->getWidget())); - return TRUE; - case GDK_E: // easter egg - static guint explode_timeout = 0; - if (explode_timeout == 0) - explode_timeout = g_timeout_add (10000, - expode_window_timeout_cb, NULL); - else { - g_source_remove (explode_timeout); - explode_timeout = 0; - } - return TRUE; - default: - return FALSE; - } - } - return FALSE; - } +void YGWindow::ref (YGWindow *window) +{ + window->m_refcount++; +} +void YGWindow::unref (YGWindow *window) +{ + if (--window->m_refcount == 0) { + bool is_main_window = (window == main_window); + delete window; + if (is_main_window) + main_window = NULL; + } +} - static gboolean draw_border_cb (GtkWidget *widget, GdkEventExpose *event, +static gboolean draw_border_cb (GtkWidget *widget, GdkEventExpose *event, YGWindow *pThis) - { - IMPL - // to avoid background from overlapping, we emit the expose to the containee - // ourselves - gtk_container_propagate_expose (GTK_CONTAINER (widget), - gtk_bin_get_child (GTK_BIN (widget)), - event); - - GtkAllocation *alloc = &widget->allocation; - gtk_draw_shadow (gtk_widget_get_style (widget), widget->window, - GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_OUT, - alloc->x, alloc->y, alloc->width, alloc->height); - return TRUE; - } +{ + IMPL + // to avoid background from overlapping, we emit the expose to the containee + // ourselves + gtk_container_propagate_expose (GTK_CONTAINER (widget), + gtk_bin_get_child (GTK_BIN (widget)), + event); + + GtkAllocation *alloc = &widget->allocation; + gtk_draw_shadow (gtk_widget_get_style (widget), widget->window, + GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_OUT, + alloc->x, alloc->y, alloc->width, alloc->height); + return TRUE; +} - static gboolean expode_window_timeout_cb (gpointer data) - { - GtkWindow *window = YGUI::ui()->currentWindow(); - if (!window) - return FALSE; - srand (time (NULL)); - gint x, y; - gtk_window_get_position (window, &x, &y); +static gboolean expode_window_timeout_cb (gpointer data) +{ + GtkWindow *window = YGUI::ui()->currentWindow(); + if (!window) + return FALSE; + srand (time (NULL)); + gint x, y; + gtk_window_get_position (window, &x, &y); #if 0 - // OVAL MOVE - for (int i = 180; i < 360+180; i++) { - gtk_window_move (window, x+(int)(sin((i*G_PI)/180)*50), - y+(int)(cos((i*G_PI)/180)*50)+50); - while (gtk_events_pending()) - gtk_main_iteration(); - usleep (25); - } + // OVAL MOVE + for (int i = 180; i < 360+180; i++) { + gtk_window_move (window, x+(int)(sin((i*G_PI)/180)*50), + y+(int)(cos((i*G_PI)/180)*50)+50); + while (gtk_events_pending()) + gtk_main_iteration(); + usleep (25); + } #else - // EXPLOSION - for (int i = 0; i < 40; i++) { - gtk_window_move (window, x+(int)((((float)(rand())/RAND_MAX)*40)-20), - y+(int)((((float)(rand())/RAND_MAX)*40)-20)); - while (gtk_events_pending()) - gtk_main_iteration(); - usleep (200); - } + // EXPLOSION + for (int i = 0; i < 40; i++) { + gtk_window_move (window, x+(int)((((float)(rand())/RAND_MAX)*40)-20), + y+(int)((((float)(rand())/RAND_MAX)*40)-20)); + while (gtk_events_pending()) + gtk_main_iteration(); + usleep (200); + } #endif - gtk_window_move (window, x, y); - return TRUE; - } -}; - -#include "YDialog.h" + gtk_window_move (window, x, y); + return TRUE; +} -class YGDialog : public YDialog, public YGWidget +gboolean YGWindow::close_window_cb (GtkWidget *widget, GdkEvent *event, + YGWindow *pThis) { - int m_padding; - GtkWidget *m_containee; - - YGWindow *m_window; - -public: - YGDialog (YWidgetOpt &opt) - : YDialog (opt), - YGWidget (this, NULL, FALSE, GTK_TYPE_HBOX, NULL) - { - setBorder (0); - m_padding = 0; - m_containee = gtk_event_box_new(); - if (hasDefaultSize() && main_window) - m_window = main_window; - else - m_window = new YGWindow (hasDefaultSize()); - YGWindow::ref (m_window); + IMPL + return !pThis->checkDelete(); +} - if (hasWarnColor() || hasInfoColor()) { - // emulate a warning / info dialog - GtkWidget *icon = gtk_image_new_from_stock - (hasWarnColor() ? GTK_STOCK_DIALOG_WARNING : GTK_STOCK_DIALOG_INFO, - GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (icon), 0.5, 0); - gtk_misc_set_padding (GTK_MISC (icon), 0, 12); - - gtk_box_pack_start (GTK_BOX (getWidget()), icon, FALSE, FALSE, 12); - gtk_box_pack_start (GTK_BOX (getWidget()), m_containee, TRUE, TRUE, 0); - - GtkRequisition req; - gtk_widget_size_request (icon, &req); - m_padding = req.width + 24; - } - else - gtk_box_pack_start (GTK_BOX (getWidget()), m_containee, TRUE, TRUE, 0); - gtk_widget_show_all (getWidget()); +bool YGWindow::checkDelete() +{ + fprintf (stderr, "YGDialog close event ...\n"); + if (!m_canDelete) { + YGUI::ui()->sendEvent (new YCancelEvent()); + return TRUE; + } + return m_canDelete (m_closure); +} - // NOTE: we need to add this containter to the window right here, else - // weird stuff happens (like if we set a pango font description to a - // GtkLabel, size request would output the size without that description - // set...) - m_window->setChild (this); - } +static gboolean key_pressed_cb (GtkWidget *widget, GdkEventKey *event, + YGWindow *pThis) +{ + IMPL + // if not main dialog, close it on escape + if (event->keyval == GDK_Escape && + /* not main window */ main_window != pThis) + return pThis->checkDelete(); + + if ((event->state & GDK_CONTROL_MASK) && (event->state & GDK_SHIFT_MASK) + && (event->state & GDK_MOD1_MASK)) { + y2milestone ("Caught YaST2 magic key combination"); + switch (event->keyval) { + case GDK_S: + YGUI::ui()->makeScreenShot(""); + return TRUE; + case GDK_M: + YGUI::ui()->toggleRecordMacro(); + return TRUE; + case GDK_P: + YGUI::ui()->askPlayMacro(); + return TRUE; + case GDK_D: + YGUI::ui()->sendEvent (new YDebugEvent()); + return TRUE; + case GDK_X: + y2milestone ("Starting xterm"); + system ("/usr/bin/xterm &"); + return TRUE; + case GDK_T: + dumpYastTree (pThis->getChild(), GTK_WINDOW (pThis->getWidget())); + return TRUE; + case GDK_E: // easter egg + static guint explode_timeout = 0; + if (explode_timeout == 0) + explode_timeout = g_timeout_add (10000, + expode_window_timeout_cb, NULL); + else { + g_source_remove (explode_timeout); + explode_timeout = 0; + } + return TRUE; + default: + return FALSE; + } + } + return FALSE; +} - virtual ~YGDialog() - { - YGWindow::unref (m_window); - } +YGWindow::YGWindow (bool main_window) +{ + m_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_object_ref (G_OBJECT (m_widget)); + gtk_object_sink (GTK_OBJECT (m_widget)); + + m_refcount = 0; + if (main_window) + ::main_window = this; + m_child = NULL; + m_canDelete = NULL; + + { + GtkWindow *parent = YGUI::ui()->currentWindow(); + GtkWindow *window = GTK_WINDOW (m_widget); + + if (parent) { + // if there is a parent, this would be a dialog + gtk_window_set_transient_for (window, parent); + gtk_window_set_title (window, ""); + + gtk_window_set_modal (window, TRUE); + gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DIALOG); + } + else { + gtk_window_set_title (window, "YaST"); + if (YGUI::ui()->unsetBorder()) + gtk_window_set_decorated (window, FALSE); + } + + if (main_window) { + int w = YGUI::ui()->getDefaultSize (YD_HORIZ), + h = YGUI::ui()->getDefaultSize (YD_VERT); + gtk_window_set_default_size (window, w, h); + } + + gtk_window_set_role (window, "yast-gtk"); + if (!YGUI::ui()->hasWM()) + g_signal_connect (G_OBJECT (m_widget), "expose-event", + G_CALLBACK (draw_border_cb), this); + } + + g_signal_connect (G_OBJECT (m_widget), "delete_event", + G_CALLBACK (close_window_cb), this); + g_signal_connect_after (G_OBJECT (m_widget), "key-press-event", + G_CALLBACK (key_pressed_cb), this); +} - void showWindow() - { - IMPL - m_window->setChild (this); - gtk_widget_show (m_window->getWidget()); - } +void YGWindow::setDeleteCallback (YGWindowDeleteFn canDelete, void *closure) +{ + m_canDelete = canDelete; + m_closure = closure; +} - void hideWindow() - { - IMPL - m_window->setChild (NULL); - gtk_widget_hide (m_window->getWidget()); - } +YGDialog::YGDialog (YWidgetOpt &opt) + : YDialog (opt), + YGWidget (this, NULL, FALSE, GTK_TYPE_HBOX, NULL) +{ + setBorder (0); + m_padding = 0; + m_containee = gtk_event_box_new(); + if (hasDefaultSize() && main_window) + m_window = main_window; + else + m_window = new YGWindow (hasDefaultSize()); + YGWindow::ref (m_window); + + if (hasWarnColor() || hasInfoColor()) { + // emulate a warning / info dialog + GtkWidget *icon = gtk_image_new_from_stock + (hasWarnColor() ? GTK_STOCK_DIALOG_WARNING : GTK_STOCK_DIALOG_INFO, + GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment (GTK_MISC (icon), 0.5, 0); + gtk_misc_set_padding (GTK_MISC (icon), 0, 12); + + gtk_box_pack_start (GTK_BOX (getWidget()), icon, FALSE, FALSE, 12); + gtk_box_pack_start (GTK_BOX (getWidget()), m_containee, TRUE, TRUE, 0); + + GtkRequisition req; + gtk_widget_size_request (icon, &req); + m_padding = req.width + 24; + } + else + gtk_box_pack_start (GTK_BOX (getWidget()), m_containee, TRUE, TRUE, 0); + gtk_widget_show_all (getWidget()); + + // NOTE: we need to add this containter to the window right here, else + // weird stuff happens (like if we set a pango font description to a + // GtkLabel, size request would output the size without that description + // set...) + m_window->setChild (this); +} - GtkWindow *getWindow() - { return GTK_WINDOW (m_window->getWidget()); } +YGDialog::~YGDialog() +{ + YGWindow::unref (m_window); +} - YGWIDGET_IMPL_COMMON +void YGDialog::showWindow() +{ + IMPL + m_window->setChild (this); + gtk_widget_show (m_window->getWidget()); +} - YGWIDGET_IMPL_CHILD_ADDED (m_containee) - YGWIDGET_IMPL_CHILD_REMOVED (m_containee) -}; +void YGDialog::hideWindow() +{ + IMPL + m_window->setChild (NULL); + gtk_widget_hide (m_window->getWidget()); +} YDialog * YGUI::createDialog (YWidgetOpt &opt) @@ -341,7 +324,17 @@ { YDialog *ydialog = YGUI::ui()->currentDialog(); if (ydialog) - return ((YGDialog *) ydialog)->getWindow(); + return static_cast<YGDialog *>(ydialog)->getWindow(); + else + return NULL; +} + +YGDialog * +YGUI::currentYGDialog() +{ + YDialog *ydialog = YGUI::ui()->currentDialog(); + if (ydialog) + return static_cast<YGDialog *>(ydialog); else return NULL; } Added: trunk/gtk/src/YGDialog.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGDialog.h?rev=40654&view=auto ============================================================================== --- trunk/gtk/src/YGDialog.h (added) +++ trunk/gtk/src/YGDialog.h Fri Aug 31 16:33:37 2007 @@ -0,0 +1,59 @@ +#ifndef YGDIALOG_H +#define YGDIALOG_H + +#include "YGWidget.h" +#include "YDialog.h" + +typedef bool (*YGWindowDeleteFn) (void *closure); + +class YGWindow +{ + GtkWidget *m_widget; + int m_refcount; + // we keep a pointer of the child just for debugging + // (ie. dump yast tree) + YWidget *m_child; + YGWindowDeleteFn m_canDelete; + void *m_closure; + +private: + static gboolean close_window_cb (GtkWidget *widget, GdkEvent *event, + YGWindow *pThis); +public: + YGWindow (bool main_window); + ~YGWindow(); + void setChild (YWidget *new_child); + static void ref (YGWindow *window); + static void unref (YGWindow *window); + void setDeleteCallback (YGWindowDeleteFn canDelete, void *closure); + bool checkDelete(); + + // Y(G)Widget-like methods + GtkWidget *getWidget() { return m_widget; } + YWidget *getChild() { return m_child; } +}; + +class YGDialog : public YDialog, public YGWidget +{ + int m_padding; + GtkWidget *m_containee; + + YGWindow *m_window; + +public: + YGDialog (YWidgetOpt &opt); + virtual ~YGDialog(); + void showWindow(); + void hideWindow(); + GtkWindow *getWindow() { return GTK_WINDOW (m_window->getWidget()); } + + void setDeleteCallback (bool (*canDelete) (void *closure), void *closure) + { m_window->setDeleteCallback (canDelete, closure); } + + YGWIDGET_IMPL_COMMON + + YGWIDGET_IMPL_CHILD_ADDED (m_containee) + YGWIDGET_IMPL_CHILD_REMOVED (m_containee) +}; + +#endif // YGDIALOG_H Modified: trunk/gtk/src/YGPackageSelector.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGPackageSelector.cc?rev=40654&r1=40653&r2=40654&view=diff ============================================================================== --- trunk/gtk/src/YGPackageSelector.cc (original) +++ trunk/gtk/src/YGPackageSelector.cc Fri Aug 31 16:33:37 2007 @@ -11,7 +11,7 @@ #include <YGUI.h> #include "YGUtils.h" #include "YGi18n.h" -#include "YGWidget.h" +#include "YGDialog.h" #include "YPackageSelector.h" #include "ygtkrichtext.h" #include "ygtkwizard.h" @@ -1140,7 +1140,7 @@ gtk_box_pack_start (GTK_BOX (search_hbox), m_search_entry, TRUE, TRUE, 4); search_timeout_id = 0; g_signal_connect (G_OBJECT (m_search_entry), "activate", // when Enter - G_CALLBACK (search_request_cb), this); // is pressed + G_CALLBACK (search_activate_cb), this); // is pressed g_signal_connect_after (G_OBJECT (m_search_entry), "changed", G_CALLBACK (search_request_cb), this); ygtk_find_entry_attach_menu (YGTK_FIND_ENTRY (m_search_entry), @@ -1773,9 +1773,59 @@ pThis->search_timeout_id = g_timeout_add (1000, search_cb, pThis); } + struct FindClosure { + bool found; + GtkTreeView *view; + PackageSelector *pThis; + }; + static gboolean find_exact_match (GtkTreeModel *model, GtkTreePath *path, + GtkTreeIter *iter, gpointer data) + { + FindClosure *cl = (FindClosure *) data; + + ZyppSelectablePtr sel = NULL; + + gtk_tree_model_get (model, iter, 0, &sel, -1); + + if (!sel) + return FALSE; + + if (sel->name() == *cl->pThis->m_search_queries.begin()) { + fprintf (stderr, "bingo !\n"); + + cl->found = true; + gtk_tree_selection_select_iter + (gtk_tree_view_get_selection (cl->view), iter); + package_clicked_cb (gtk_tree_view_get_selection (cl->view), cl->pThis); + return TRUE; + } + return FALSE; + } + + void highlight_exact_matches () + { + if (m_search_queries.empty() || !name_opt) + return; + + FindClosure cl; + cl.found = false; + cl.pThis = this; + cl.view = GTK_TREE_VIEW (m_installed_view); + + gtk_tree_model_foreach (gtk_tree_view_get_model (cl.view), + find_exact_match, &cl); + + if (!cl.found) { + cl.view = GTK_TREE_VIEW (m_available_view); + gtk_tree_model_foreach (gtk_tree_view_get_model (cl.view), + find_exact_match, &cl); + } + } + static gboolean search_cb (gpointer data) { IMPL + fprintf (stderr, "search start...\n"); PackageSelector *pThis = (PackageSelector *) data; pThis->search_timeout_id = 0; @@ -1793,6 +1843,10 @@ gtk_tree_view_get_model (GTK_TREE_VIEW (pThis->m_installed_view)); gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (available_model)); gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (installed_model)); + + pThis->highlight_exact_matches (); + + fprintf (stderr, "search done...\n"); return FALSE; } @@ -1824,14 +1878,17 @@ PackageSelector *pThis, int visible_col) { gboolean visible, has_children; - gtk_tree_model_get (model, iter, visible_col, &visible, 8, &has_children, -1); + ZyppSelectablePtr selectable; + + gtk_tree_model_get (model, iter, visible_col, &visible, 8, &has_children, + 0, &selectable, -1); + +// fprintf (stderr, "is visible '%s'\n", selectable ? selectable->name().c_str() : "<noname>"); if (has_children) visible = TRUE; - else if (visible && !pThis->m_search_queries.empty()) { - ZyppSelectablePtr selectable; - gtk_tree_model_get (model, iter, 0, &selectable, -1); + else if (visible && !pThis->m_search_queries.empty()) visible = pThis->does_package_match (selectable); - } + return visible; } @@ -1845,10 +1902,14 @@ bool does_package_match_one (ZyppSelectablePtr sel, string key) { - ZyppObject obj = sel->theObj(); + ZyppObject obj = NULL; if (name_opt && YGUtils::contains (sel->name(), key)) return TRUE; + + if (summary_opt || descr_opt || provides_opt || requires_opt) + obj = sel->theObj(); + if (summary_opt && YGUtils::contains (obj->summary(), key)) return TRUE; if (descr_opt && YGUtils::contains (obj->description(), key)) @@ -2206,6 +2267,38 @@ { PackageSelector *m_package_selector; + static bool confirm_cb (void *pThis) + { + return ((YGPackageSelector *)pThis)->checkDelete(); + } + + bool checkDelete() + { + GtkWidget *dialog; + + bool changed = + zyppPool().diffState<zypp::Package >() || + zyppPool().diffState<zypp::Pattern >() || + zyppPool().diffState<zypp::Selection>() || + zyppPool().diffState<zypp::Language >() || + zyppPool().diffState<zypp::Patch >(); + + if (!changed) + return true; + + dialog = gtk_message_dialog_new_with_markup + (YGUI::ui()->currentWindow(), + GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK_CANCEL, + _("<b>Abandon all changes ?</b>")); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), + GTK_RESPONSE_CANCEL); + bool ok = gtk_dialog_run (GTK_DIALOG (dialog)) == + GTK_RESPONSE_OK; + gtk_widget_destroy (dialog); + return ok; + } + public: YGPackageSelector (const YWidgetOpt &opt, YGWidget *parent) : YPackageSelector (opt), @@ -2213,9 +2306,13 @@ { setBorder (0); - GtkWindow *window = YGUI::ui()->currentWindow(); + YGDialog *dialog = YGUI::ui()->currentYGDialog(); + + GtkWindow *window = GTK_WINDOW (dialog->getWindow()); gtk_window_resize (window, 680, 580); + dialog->setDeleteCallback (confirm_cb, this); + YGtkWizard *wizard = YGTK_WIZARD (getWidget()); ygtk_wizard_set_header_icon (wizard, window, @@ -2270,7 +2367,8 @@ } else if (!strcmp (action, "cancel")) { y2milestone ("Closing PackageSelector with 'cancel'"); - YGUI::ui()->sendEvent (new YCancelEvent()); + if (pThis->checkDelete()) + YGUI::ui()->sendEvent (new YCancelEvent()); } } @@ -2459,7 +2557,6 @@ const YCPString &subwidget) { // same as Qt's - // TODO: check what this is supposed to do (something for ncurses maybe?) y2error ("The GTK+ UI does not support PkgSpecial subwidgets!"); return 0; } Modified: trunk/gtk/src/YGUI.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUI.h?rev=40654&r1=40653&r2=40654&view=diff ============================================================================== --- trunk/gtk/src/YGUI.h (original) +++ trunk/gtk/src/YGUI.h Fri Aug 31 16:33:37 2007 @@ -39,6 +39,8 @@ # define YAST2_YGUI_CHECKBOX_FRAME 0 #endif +class YGDialog; + class YGUI: public YUI { public: @@ -139,6 +141,19 @@ const YCPString &subwidget); virtual YCPValue runPkgSelection (YWidget *packageSelector); +/* + // FIXME: do we need to implement these new bits ? + + // New package selector bits ... + bool hasPatternSelector(); + YWidget * createPatternSelector ( YWidget * parent, + YWidgetOpt & opt ); + + bool hasSimplePatchSelector(); + YWidget * createSimplePatchSelector( YWidget * parent, + YWidgetOpt & opt ); +*/ + // Optional widgets virtual YWidget *createDummySpecialWidget (YWidget *parent, YWidgetOpt &opt) IMPL_NULL; @@ -235,6 +250,7 @@ // convience function to be used rather than currentDialog() // NULL if there is no dialog at the moment. GtkWindow *currentWindow(); + YGDialog *currentYGDialog(); virtual void busyCursor(); virtual void normalCursor(); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
michael_meeks@svn.opensuse.org