Commit 223aa84b authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder
Browse files

Non-modal search and replace.

2001-02-24  Morten Welinder  <terra@diku.dk>

	* src/workbook-control-gui.c (cb_edit_search_replace_action): New
 	function for non-modal action.
	(cb_edit_search_replace): Supply action callback.


2001-02-24  Morten Welinder  <terra@diku.dk>

	* dialog-search-replace.c (dialog_search_replace): Rework to be
 	non-modal.
parent 85306f55
2001-02-24 Morten Welinder <terra@diku.dk>
* src/workbook-control-gui.c (cb_edit_search_replace_action): New
function for non-modal action.
(cb_edit_search_replace): Supply action callback.
2001-02-24 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-control-gui-priv.h :
......
2001-02-24 Morten Welinder <terra@diku.dk>
* src/workbook-control-gui.c (cb_edit_search_replace_action): New
function for non-modal action.
(cb_edit_search_replace): Supply action callback.
2001-02-24 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-control-gui-priv.h :
......
2001-02-24 Morten Welinder <terra@diku.dk>
* src/workbook-control-gui.c (cb_edit_search_replace_action): New
function for non-modal action.
(cb_edit_search_replace): Supply action callback.
2001-02-24 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-control-gui-priv.h :
......
2001-02-24 Morten Welinder <terra@diku.dk>
* src/workbook-control-gui.c (cb_edit_search_replace_action): New
function for non-modal action.
(cb_edit_search_replace): Supply action callback.
2001-02-24 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-control-gui-priv.h :
......
2001-02-24 Morten Welinder <terra@diku.dk>
* src/workbook-control-gui.c (cb_edit_search_replace_action): New
function for non-modal action.
(cb_edit_search_replace): Supply action callback.
2001-02-24 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-control-gui-priv.h :
......
2001-02-24 Morten Welinder <terra@diku.dk>
* dialog-search-replace.c (dialog_search_replace): Rework to be
non-modal.
2001-02-24 Almer S. Tigelaar <almer@gnome.org>
* search-replace.glade : Add spacing.
......
......@@ -13,6 +13,12 @@
#include "dialogs.h"
#include "search.h"
typedef struct {
WorkbookControlGUI *wbcg;
GladeXML *gui;
GnomeDialog *dialog;
SearchReplaceDialogCallback cb;
} DialogState;
static const char *error_group[] = {
"error_fail",
......@@ -63,90 +69,134 @@ get_text (GladeXML *gui, const char *name)
return g_strdup (gtk_entry_get_text (GTK_ENTRY (w)));
}
static void
ok_clicked (GtkWidget *widget, DialogState *dd)
{
GladeXML *gui = dd->gui;
GnomeDialog *dialog = dd->dialog;
WorkbookControlGUI *wbcg = dd->wbcg;
SearchReplaceDialogCallback cb = dd->cb;
SearchReplace *sr;
char *err;
int i;
/*
* Dialog. Returns a SearchReplace object that the users wants to search
* for, or NULL if the search is cancelled.
*/
SearchReplace *
dialog_search_replace (WorkbookControlGUI *wbcg)
sr = search_replace_new ();
sr->search_text = get_text (gui, "searchtext");
sr->replace_text = get_text (gui, "replacetext");
i = get_group_value (gui, search_type_group);
sr->is_regexp = (i == 1);
i = get_group_value (gui, scope_group);
sr->scope = (i == -1) ? SRS_sheet : (SearchReplaceScope)i;
sr->range_text = get_text (gui, "rangetext");
sr->query = is_checked (gui, "query");
sr->ignore_case = is_checked (gui, "ignore_case");
sr->preserve_case = is_checked (gui, "preserve_case");
sr->match_words = is_checked (gui, "match_words");
sr->replace_strings = is_checked (gui, "replace_string");
sr->replace_other_values = is_checked (gui, "replace_other");
sr->replace_expressions = is_checked (gui, "replace_expr");
sr->replace_comments = is_checked (gui, "replace_comments");
i = get_group_value (gui, error_group);
sr->error_behaviour = (i == -1) ? SRE_fail : (SearchReplaceError)i;
err = search_replace_verify (sr);
if (err) {
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR, err);
g_free (err);
search_replace_free (sr);
return;
} else if (!sr->replace_strings &&
!sr->replace_other_values &&
!sr->replace_expressions &&
!sr->replace_comments) {
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR,
_("You must select some cell types to search."));
search_replace_free (sr);
return;
}
gtk_widget_destroy (GTK_WIDGET (dialog));
dd = NULL; /* Destroyed */
cb (wbcg, sr);
search_replace_free (sr);
}
static void
cancel_clicked (GtkWidget *widget, DialogState *dd)
{
GnomeDialog *dialog = dd->dialog;
gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
dialog_destroy (GtkWidget *widget, DialogState *dd)
{
GladeXML *gui = dd->gui;
gtk_object_unref (GTK_OBJECT (gui));
memset (dd, 0, sizeof (*dd));
g_free (dd);
}
static void
non_model_dialog (WorkbookControlGUI *wbcg, GnomeDialog *dialog)
{
GtkWindow *toplevel = wb_control_gui_toplevel (wbcg);
if (GTK_WINDOW (dialog)->transient_parent != toplevel)
gnome_dialog_set_parent (dialog, toplevel);
gtk_widget_show (GTK_WIDGET (dialog));
}
void
dialog_search_replace (WorkbookControlGUI *wbcg,
SearchReplaceDialogCallback cb)
{
GladeXML *gui;
SearchReplace *sr;
GnomeDialog *dialog;
int bval;
DialogState *dd;
g_return_val_if_fail (wbcg != NULL, NULL);
g_return_if_fail (wbcg != NULL);
gui = gnumeric_glade_xml_new (wbcg, "search-replace.glade");
if (gui == NULL)
return NULL;
return;
dialog = GNOME_DIALOG (glade_xml_get_widget (gui, "search_replace_dialog"));
#if 0
gnome_dialog_set_default (dialog, BUTTON_CLOSE);
#endif
gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, TRUE, FALSE);
gtk_widget_show_all (dialog->vbox);
dd = g_new (DialogState, 1);
dd->wbcg = wbcg;
dd->gui = gui;
dd->cb = cb;
dd->dialog = dialog;
while (1) {
char *err;
bval = gnumeric_dialog_run (wbcg, dialog);
if (bval == 0) {
int i;
sr = search_replace_new ();
sr->search_text = get_text (gui, "searchtext");
sr->replace_text = get_text (gui, "replacetext");
i = get_group_value (gui, search_type_group);
sr->is_regexp = (i == 1);
i = get_group_value (gui, scope_group);
sr->scope = (i == -1) ? SRS_sheet : (SearchReplaceScope)i;
sr->range_text = get_text (gui, "rangetext");
sr->query = is_checked (gui, "query");
sr->ignore_case = is_checked (gui, "ignore_case");
sr->preserve_case = is_checked (gui, "preserve_case");
sr->match_words = is_checked (gui, "match_words");
sr->replace_strings = is_checked (gui, "replace_string");
sr->replace_other_values = is_checked (gui, "replace_other");
sr->replace_expressions = is_checked (gui, "replace_expr");
sr->replace_comments = is_checked (gui, "replace_comments");
i = get_group_value (gui, error_group);
sr->error_behaviour = (i == -1) ? SRE_fail : (SearchReplaceError)i;
} else {
sr = NULL;
}
if (sr && (err = search_replace_verify (sr))) {
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR, err);
g_free (err);
search_replace_free (sr);
} else if (sr &&
!sr->replace_strings &&
!sr->replace_other_values &&
!sr->replace_expressions &&
!sr->replace_comments) {
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR,
_("You must select some cell types to search."));
search_replace_free (sr);
continue;
} else
break;
}
gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, TRUE, FALSE);
if (bval != -1)
gnome_dialog_close (dialog);
gtk_signal_connect (GTK_OBJECT (glade_xml_get_widget (gui, "ok_button")),
"clicked",
GTK_SIGNAL_FUNC (ok_clicked),
dd);
gtk_signal_connect (GTK_OBJECT (glade_xml_get_widget (gui, "cancel_button")),
"clicked",
GTK_SIGNAL_FUNC (cancel_clicked),
dd);
gtk_signal_connect (GTK_OBJECT (dialog),
"destroy",
GTK_SIGNAL_FUNC (dialog_destroy),
dd);
gtk_object_unref (GTK_OBJECT (gui));
gtk_widget_show_all (dialog->vbox);
return sr;
non_model_dialog (wbcg, dialog);
}
......@@ -51,7 +51,10 @@ void dialog_sheet_order (WorkbookControlGUI *wbcg);
gboolean dialog_get_number (WorkbookControlGUI *wbcg,
const char *glade_file,
double *init_and_return_value);
SearchReplace *dialog_search_replace (WorkbookControlGUI *wbcg);
typedef gboolean (*SearchReplaceDialogCallback) (WorkbookControlGUI *wbcg, SearchReplace *sr);
void dialog_search_replace (WorkbookControlGUI *wbcg,
SearchReplaceDialogCallback cb);
FunctionDefinition *dialog_function_select (WorkbookControlGUI *wbcg);
......
......@@ -56,7 +56,7 @@
<widget>
<class>GtkButton</class>
<name>button5</name>
<name>ok_button</name>
<can_default>True</can_default>
<has_default>True</has_default>
<can_focus>True</can_focus>
......@@ -65,7 +65,7 @@
<widget>
<class>GtkButton</class>
<name>button6</name>
<name>cancel_button</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>
......@@ -540,7 +540,7 @@
<tooltip>Perform changes within expressions</tooltip>
<can_focus>True</can_focus>
<label>Expressions</label>
<active>False</active>
<active>True</active>
<draw_indicator>True</draw_indicator>
<child>
<left_attach>1</left_attach>
......
......@@ -1380,20 +1380,24 @@ cb_edit_search_replace_query (SearchReplaceQuery q, SearchReplace *sr, ...)
return res;
}
static void
cb_edit_search_replace (GtkWidget *unused, WorkbookControlGUI *wbcg)
static gboolean
cb_edit_search_replace_action (WorkbookControlGUI *wbcg,
SearchReplace *sr)
{
WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
Sheet *sheet = wb_control_cur_sheet (wbc);
SearchReplace *sr = dialog_search_replace (wbcg);
if (!sr) return;
sr->query_func = cb_edit_search_replace_query;
sr->user_data = wbcg;
cmd_search_replace (wbc, sheet, sr);
search_replace_free (sr);
return cmd_search_replace (wbc, sheet, sr);
}
static void
cb_edit_search_replace (GtkWidget *unused, WorkbookControlGUI *wbcg)
{
dialog_search_replace (wbcg, cb_edit_search_replace_action);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment