Esempio n. 1
0
void
editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
                             /*@out@ */ char **search_text, /*@out@ */ char **replace_text)
{
    size_t num_of_types;
    gchar **list_of_types;

    if ((search_default == NULL) || (*search_default == '\0'))
        search_default = INPUT_LAST_TEXT;

    list_of_types = mc_search_get_types_strings_array (&num_of_types);

    {
        quick_widget_t quick_widgets[] = {
            /* *INDENT-OFF* */
            QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above, search_default,
                                 MC_HISTORY_SHARED_SEARCH, search_text, NULL, FALSE, FALSE,
                                 INPUT_COMPLETE_NONE),
            QUICK_LABELED_INPUT (N_("Enter replacement string:"), input_label_above, replace_default,
                                 "replace", replace_text, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
            QUICK_SEPARATOR (TRUE),
            QUICK_START_COLUMNS,
                QUICK_RADIO (num_of_types, (const char **) list_of_types,
                             (int *) &edit_search_options.type, NULL),
            QUICK_NEXT_COLUMN,
                QUICK_CHECKBOX (N_("Cas&e sensitive"), &edit_search_options.case_sens, NULL),
                QUICK_CHECKBOX (N_("&Backwards"), &edit_search_options.backwards, NULL),
                QUICK_CHECKBOX (N_("In se&lection"), &edit_search_options.only_in_selection, NULL),
                QUICK_CHECKBOX (N_("&Whole words"), &edit_search_options.whole_words, NULL),
#ifdef HAVE_CHARSET
                QUICK_CHECKBOX (N_("&All charsets"), &edit_search_options.all_codepages, NULL),
#endif
            QUICK_STOP_COLUMNS,
            QUICK_BUTTONS_OK_CANCEL,
            QUICK_END
            /* *INDENT-ON* */
        };

        quick_dialog_t qdlg = {
            -1, -1, 58,
            N_("Replace"), "[Input Line Keys]",
            quick_widgets, NULL, NULL
        };

        if (quick_dialog (&qdlg) != B_CANCEL)
            edit->replace_mode = 0;
        else
        {
            *replace_text = NULL;
            *search_text = NULL;
        }
    }

    g_strfreev (list_of_types);
}
Esempio n. 2
0
void
editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
                             /*@out@ */ char **search_text, /*@out@ */ char **replace_text)
{
    if (*search_default == '\0')
        search_default = INPUT_LAST_TEXT;

    {
	size_t num_of_types;
	gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
	int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY;

	QuickWidget quick_widgets[] =
	{
	    /*  0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
	    /*  1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"),     B_ENTER,  NULL),
#ifdef HAVE_CHARSET
	    /*  2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("All charsets"), &edit->all_codepages),
#endif
	    /*  3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&Whole words"), &edit->whole_words),
	    /*  4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH,  9, REPLACE_DLG_HEIGHT, N_("In se&lection"), &edit->only_in_selection),
	    /*  5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH,  8, REPLACE_DLG_HEIGHT, N_("&Backwards"), &edit->replace_backwards),
	    /*  6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH,  7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"), &edit->replace_case),
	    /*  7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH,   7, REPLACE_DLG_HEIGHT,
				num_of_types, (const char **) list_of_types, (int *) &edit->search_type),
	    /*  8 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH,   4, REPLACE_DLG_HEIGHT, N_(" Enter replacement string:")),
	    /*  9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH,   5, REPLACE_DLG_HEIGHT,
				replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace", replace_text),
	    /* 10 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH,   2, REPLACE_DLG_HEIGHT, N_(" Enter search string:")),
	    /* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH,   3, REPLACE_DLG_HEIGHT,
				search_default, REPLACE_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text),
	    QUICK_END
	};

	QuickDialog Quick_input =
	{
	    REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_(" Replace "),
	    "[Input Line Keys]", quick_widgets, FALSE
	};

	if (quick_dialog (&Quick_input) != B_CANCEL) {
	    edit->replace_mode = 0;
	} else {
	    *replace_text = NULL;
	    *search_text = NULL;
	}

	g_strfreev (list_of_types);
    }
}
Esempio n. 3
0
gboolean
mcview_dialog_search (WView * view)
{
    char *exp = NULL;
    int qd_result;
    size_t num_of_types = 0;
    gchar **list_of_types;

    list_of_types = mc_search_get_types_strings_array (&num_of_types);

    {
        quick_widget_t quick_widgets[] = {
            /* *INDENT-OFF* */
            QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above,
                                 INPUT_LAST_TEXT, MC_HISTORY_SHARED_SEARCH, &exp,
                                 NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
            QUICK_SEPARATOR (TRUE),
            QUICK_START_COLUMNS,
                QUICK_RADIO (num_of_types, (const char **) list_of_types,
                             (int *) &mcview_search_options.type, NULL),
            QUICK_NEXT_COLUMN,
                QUICK_CHECKBOX (N_("Cas&e sensitive"), &mcview_search_options.case_sens, NULL),
                QUICK_CHECKBOX (N_("&Backwards"), &mcview_search_options.backwards, NULL),
                QUICK_CHECKBOX (N_("&Whole words"), &mcview_search_options.whole_words, NULL),
#ifdef HAVE_CHARSET
                QUICK_CHECKBOX (N_("&All charsets"), &mcview_search_options.all_codepages, NULL),
#endif
            QUICK_STOP_COLUMNS,
            QUICK_BUTTONS_OK_CANCEL,
            QUICK_END
            /* *INDENT-ON* */
        };

        quick_dialog_t qdlg = {
            -1, -1, 58,
            N_("Search"), "[Input Line Keys]",
            quick_widgets, NULL, NULL
        };

        qd_result = quick_dialog (&qdlg);
    }

    g_strfreev (list_of_types);

    if ((qd_result == B_CANCEL) || (exp == NULL) || (exp[0] == '\0'))
    {
        g_free (exp);
        return FALSE;
    }

#ifdef HAVE_CHARSET
    {
        GString *tmp;

        tmp = str_convert_to_input (exp);
        g_free (exp);
        exp = g_string_free (tmp, FALSE);
    }
#endif

    g_free (view->last_search_string);
    view->last_search_string = exp;
    mcview_nroff_seq_free (&view->search_nroff_seq);
    mc_search_free (view->search);

#ifdef HAVE_CHARSET
    view->search = mc_search_new (view->last_search_string, cp_source);
#else
    view->search = mc_search_new (view->last_search_string, NULL);
#endif
    view->search_nroff_seq = mcview_nroff_seq_new (view);
    if (view->search != NULL)
    {
        view->search->search_type = mcview_search_options.type;
#ifdef HAVE_CHARSET
        view->search->is_all_charsets = mcview_search_options.all_codepages;
#endif
        view->search->is_case_sensitive = mcview_search_options.case_sens;
        view->search->whole_words = mcview_search_options.whole_words;
        view->search->search_fn = mcview_search_cmd_callback;
        view->search->update_fn = mcview_search_update_cmd_callback;
    }

    return (view->search != NULL);
}
Esempio n. 4
0
gboolean
editcmd_dialog_search_show (WEdit * edit)
{
    char *search_text;
    size_t num_of_types;
    gchar **list_of_types;
    int dialog_result;

    list_of_types = mc_search_get_types_strings_array (&num_of_types);

    {
        quick_widget_t quick_widgets[] = {
            /* *INDENT-OFF* */
            QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above, INPUT_LAST_TEXT, 
                                 MC_HISTORY_SHARED_SEARCH, &search_text, NULL, FALSE, FALSE,
                                 INPUT_COMPLETE_NONE),
            QUICK_SEPARATOR (TRUE),
            QUICK_START_COLUMNS,
                QUICK_RADIO (num_of_types, (const char **) list_of_types,
                             (int *) &edit_search_options.type, NULL),
            QUICK_NEXT_COLUMN,
                QUICK_CHECKBOX (N_("Cas&e sensitive"), &edit_search_options.case_sens, NULL),
                QUICK_CHECKBOX (N_("&Backwards"), &edit_search_options.backwards, NULL),
                QUICK_CHECKBOX (N_("In se&lection"), &edit_search_options.only_in_selection, NULL),
                QUICK_CHECKBOX (N_("&Whole words"), &edit_search_options.whole_words, NULL),
#ifdef HAVE_CHARSET
                QUICK_CHECKBOX (N_("&All charsets"), &edit_search_options.all_codepages, NULL),
#endif
            QUICK_STOP_COLUMNS,
            QUICK_START_BUTTONS (TRUE, TRUE),
                QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
                QUICK_BUTTON (N_("&Find all"), B_USER, NULL, NULL),
                QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
            QUICK_END
            /* *INDENT-ON* */
        };

        quick_dialog_t qdlg = {
            -1, -1, 58,
            N_("Search"), "[Input Line Keys]",
            quick_widgets, NULL, NULL
        };

        dialog_result = quick_dialog (&qdlg);
    }

    g_strfreev (list_of_types);

    if ((dialog_result == B_CANCEL) || (search_text == NULL) || (search_text[0] == '\0'))
    {
        g_free (search_text);
        return FALSE;
    }

    if (dialog_result == B_USER)
        search_create_bookmark = TRUE;

#ifdef HAVE_CHARSET
    {
        GString *tmp;

        tmp = str_convert_to_input (search_text);
        if (tmp != NULL)
        {
            g_free (search_text);
            search_text = g_string_free (tmp, FALSE);
        }
    }
#endif

    g_free (edit->last_search_string);
    edit->last_search_string = search_text;
    mc_search_free (edit->search);

#ifdef HAVE_CHARSET
    edit->search = mc_search_new (edit->last_search_string, cp_source);
#else
    edit->search = mc_search_new (edit->last_search_string, NULL);
#endif
    if (edit->search != NULL)
    {
        edit->search->search_type = edit_search_options.type;
#ifdef HAVE_CHARSET
        edit->search->is_all_charsets = edit_search_options.all_codepages;
#endif
        edit->search->is_case_sensitive = edit_search_options.case_sens;
        edit->search->whole_words = edit_search_options.whole_words;
        edit->search->search_fn = edit_search_cmd_callback;
        edit->search->update_fn = edit_search_update_callback;
    }

    return (edit->search != NULL);
}
Esempio n. 5
0
File: dialogs.c Progetto: BrEacK/mc
gboolean
mcview_dialog_search (mcview_t * view)
{
    int SEARCH_DLG_MIN_HEIGHT = 12;
    int SEARCH_DLG_HEIGHT_SUPPLY = 3;
    int SEARCH_DLG_WIDTH = 58;

    char *exp = NULL;
    int qd_result;

    size_t num_of_types;
    gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
    int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;

    QuickWidget quick_widgets[] = {
        QUICK_BUTTON (6, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL,
                      NULL),
        QUICK_BUTTON (2, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
#ifdef HAVE_CHARSET
        QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT,
                        N_("&All charsets"), &mcview_search_options.all_codepages),
#endif
        QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT,
                        N_("&Whole words"), &mcview_search_options.whole_words),
        QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT,
                        N_("&Backwards"), &mcview_search_options.backwards),
        QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
                        N_("Cas&e sensitive"), &mcview_search_options.case_sens),
        QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
                     num_of_types, (const char **) list_of_types,
                     (int *) &mcview_search_options.type),
        QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
                     INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, &exp),
        QUICK_LABEL (3, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_("Enter search string:")),
        QUICK_END
    };

    QuickDialog Quick_input = {
        SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1,
        N_("Search"), "[Input Line Keys]",
        quick_widgets, NULL, NULL, FALSE
    };

    qd_result = quick_dialog (&Quick_input);
    g_strfreev (list_of_types);

    if ((qd_result == B_CANCEL) || (exp == NULL) || (exp[0] == '\0'))
    {
        g_free (exp);
        return FALSE;
    }

#ifdef HAVE_CHARSET
    {
        GString *tmp = str_convert_to_input (exp);

        if (tmp)
        {
            g_free (exp);
            exp = g_string_free (tmp, FALSE);
        }
    }
#endif

    g_free (view->last_search_string);
    view->last_search_string = exp;
    mcview_nroff_seq_free (&view->search_nroff_seq);
    mc_search_free (view->search);

    view->search = mc_search_new (view->last_search_string, -1);
    view->search_nroff_seq = mcview_nroff_seq_new (view);
    if (view->search != NULL)
    {
        view->search->search_type = mcview_search_options.type;
        view->search->is_all_charsets = mcview_search_options.all_codepages;
        view->search->is_case_sensitive = mcview_search_options.case_sens;
        view->search->whole_words = mcview_search_options.whole_words;
        view->search->search_fn = mcview_search_cmd_callback;
        view->search->update_fn = mcview_search_update_cmd_callback;
    }

    return (view->search != NULL);
}
Esempio n. 6
0
void
editcmd_dialog_search_show (WEdit * edit, char **search_text)
{
    if (*search_text == '\0')
        *search_text = INPUT_LAST_TEXT;

    {
	size_t num_of_types;
	gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
	int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
	size_t i;

	int dialog_result;

	QuickWidget quick_widgets[] =
	{
	    /* 0 */
	    QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
	    /* 1 */
	    QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL),
	    /* 2 */
	    QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"),     B_ENTER,  NULL),
#ifdef HAVE_CHARSET
	    /* 3 */
	    QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"), &edit->all_codepages),
#endif
	    /* 4 */
	    QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"), &edit->whole_words),
	    /* 5 */
	    QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"), &edit->only_in_selection),
	    /* 6 */
	    QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"), &edit->replace_backwards),
	    /* 7 */
	    QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), &edit->replace_case),
	    /* 8 */
	    QUICK_RADIO ( 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
				    num_of_types, (const char **) list_of_types, (int *) &edit->search_type),
	    /* 9 */
	    QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
				    *search_text, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text),
	    /* 10 */
	    QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")),
	    QUICK_END
	};

#ifdef HAVE_CHARSET
	size_t last_checkbox = 7;
#else
	size_t last_checkbox = 6;
#endif

	QuickDialog Quick_input =
	{
	    SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"),
	    "[Input Line Keys]", quick_widgets, TRUE
	};

#ifdef ENABLE_NLS
	char **list_of_types_nls;

	/* header title */
	Quick_input.title = _(Quick_input.title);
	/* buttons */
	for (i = 0; i < 3; i++)
	    quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
	/* checkboxes */
	for (i = 3; i <= last_checkbox; i++)
	    quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
	/* label */
	quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text);

	/* radiobuttons */
	/* create copy of radio items to avoid memory leak */
	list_of_types_nls = g_new0 (char *, num_of_types + 1);
	for (i = 0; i < num_of_types; i++)
	    list_of_types_nls[i] = g_strdup (_(list_of_types[i]));
	g_strfreev (list_of_types);
	list_of_types = list_of_types_nls;
	quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types;
#endif

	/* calculate widget coordinates */
	{
	    int len = 0;
	    int dlg_width;
	    gchar **radio = list_of_types;
	    int b0_len, b1_len, b2_len;
	    const int button_gap = 2;

	    /* length of radiobuttons */
            while (*radio != NULL) {
		len = max (len, str_term_width1 (*radio));
		radio++;
	    }
	    /* length of checkboxes */
	    for (i = 3; i <= last_checkbox; i++)
		len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);

	    /* preliminary dialog width */
	    dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4;

	    /* length of buttons */
	    b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
	    b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
	    b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */
	    len = b0_len + b1_len + b2_len + button_gap * 2;

	    /* dialog width */
	    Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6));

	    /* correct widget coordinates */
	    for (i = 0; i < sizeof (quick_widgets)/sizeof (quick_widgets[0]); i++)
		quick_widgets[i].x_divisions = Quick_input.xlen;

	    /* checkbox positions */
	    for (i = 3; i <= last_checkbox; i++)
		quick_widgets[i].relative_x = Quick_input.xlen/2 + 2;
	    /* input length */
	    quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6;
	    /* button positions */
	    quick_widgets[2].relative_x = Quick_input.xlen/2 - len/2;
	    quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap;
	    quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
	}

	dialog_result = quick_dialog (&Quick_input);

	g_strfreev (list_of_types);

	if (dialog_result == B_CANCEL)
	    *search_text = NULL;
	else if (dialog_result == B_USER)
	    search_create_bookmark = 1;
    }
}