regedit: flesh out search dialog and simplify search opts
authorChris Davis <cd.rattan@gmail.com>
Thu, 31 Jul 2014 05:04:50 +0000 (22:04 -0700)
committerMichael Adam <obnox@samba.org>
Wed, 1 Oct 2014 12:32:09 +0000 (14:32 +0200)
Signed-off-by: Chris Davis <cd.rattan@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/utils/regedit.c
source3/utils/regedit.h
source3/utils/regedit_dialog.c

index 3ff833ac2088a3d2258488334b7ac9f310a446ba..c1b94ac9d5a8d97d664dda1643537dc6dbee88da 100644 (file)
@@ -537,18 +537,15 @@ static void handle_main_input(struct regedit *regedit, int c)
                struct regedit_search_opts *opts;
 
                opts = &regedit->active_search;
-               if (opts->query) {
-                       talloc_free(discard_const(opts->query));
-               }
                rv = dialog_search_input(regedit, opts);
                if (rv == DIALOG_OK) {
                        SMB_ASSERT(opts->query != NULL);
-                       opts->match = find_substring;
+                       opts->match = find_substring_nocase;
                        opts->node = regedit->keys->root;
-                       if (opts->search_nocase) {
-                               opts->match = find_substring_nocase;
+                       if (opts->search_case) {
+                               opts->match = find_substring;
                        }
-                       if (opts->search_relative) {
+                       if (!opts->search_recursive) {
                                opts->node =
                                     tree_view_get_current_node(regedit->keys);
                        }
index 688bc72456b3d5edf633c95e24af17f539c3f958..c99aebab97fef348924d6ddd7c32af808d37a34b 100644 (file)
@@ -65,11 +65,10 @@ struct regedit_search_opts {
        const char *query;
        regedit_search_match_fn_t match;
        struct tree_node *node;
-       unsigned int search_key:1;
-       unsigned int search_value:1;
-       unsigned int search_recursive:1;
-       unsigned int search_relative:1;
-       unsigned int search_nocase:1;
+       bool search_key;
+       bool search_value;
+       bool search_recursive;
+       bool search_case;
 };
 
 #define PAIR_YELLOW_CYAN 1
index 3c57773728082c2ec8b4d334c35dd2c1d16555ae..20d765102ac2263a4f7d9739615372831e01f6b3 100644 (file)
@@ -2062,16 +2062,88 @@ int dialog_select_type(TALLOC_CTX *ctx, int *type)
        return action;
 }
 
+struct search_req {
+       TALLOC_CTX *ctx;
+       struct regedit_search_opts *opts;
+};
+
+static bool search_on_submit(struct dialog *dia, struct dialog_section *section,
+                            void *arg)
+{
+       struct search_req *search = arg;
+       struct dialog_section *query;
+
+       query = dialog_find_section(dia, "query");
+       SMB_ASSERT(query != NULL);
+
+       if (!search->opts->search_key && !search->opts->search_value) {
+               dialog_notice(dia, DIA_ALERT, "Error",
+                             "Must search a key and/or a value");
+               return false;
+       }
+
+       talloc_free(discard_const(search->opts->query));
+       search->opts->query = dialog_section_text_field_get(search->ctx, query);
+       SMB_ASSERT(search->opts->query != NULL);
+       if (search->opts->query[0] == '\0') {
+               dialog_notice(dia, DIA_ALERT, "Error",
+                             "Query must not be blank.");
+               return false;
+       }
+
+       return true;
+}
+
 int dialog_search_input(TALLOC_CTX *ctx, struct regedit_search_opts *opts)
 {
-       int rv;
-       // TODO
+       WERROR err;
+       enum dialog_action action;
+       struct dialog *dia;
+       struct dialog_section *section, *query;
+       struct search_req search;
+       struct button_spec spec[] = {
+               {.label = "Search", .action = DIALOG_OK},
+               {.label = "Cancel", .action = DIALOG_CANCEL},
+               { 0 }
+       };
+       struct option_spec search_opts[] = {
+               {.label = "Search Keys", .state = &opts->search_key},
+               {.label = "Search Values", .state = &opts->search_value},
+               {.label = "Recursive", .state = &opts->search_recursive},
+               {.label = "Case Sensitive", .state = &opts->search_case},
+               { 0 }
+       };
+
+       if (!opts->search_key && !opts->search_value) {
+               opts->search_key = true;
+       }
+
+       search.ctx = ctx;
+       search.opts = opts;
+       dia = dialog_new(ctx, PAIR_BLACK_CYAN, "Search", -1, -1);
+       dialog_set_submit_cb(dia, search_on_submit, &search);
+       section = dialog_section_label_new(dia, "Query");
+       dialog_append_section(dia, section);
+       query = dialog_section_text_field_new(dia, 1, -1);
+       dialog_section_set_name(query, "query");
+       dialog_append_section(dia, query);
+       section = dialog_section_hsep_new(dia, 0);
+       dialog_append_section(dia, section);
+       section = dialog_section_options_new(dia, search_opts, 2, false);
+       dialog_append_section(dia, section);
+       section = dialog_section_hsep_new(dia, 0);
+       dialog_append_section(dia, section);
+       section = dialog_section_buttons_new(dia, spec);
+       dialog_section_set_justify(section, SECTION_JUSTIFY_CENTER);
+       dialog_append_section(dia, section);
 
-       opts->search_key = 1;
-       opts->search_recursive = 1;
-       opts->search_nocase = 1;
+       dialog_create(dia);
+       if (opts->query) {
+               dialog_section_text_field_set(query, opts->query);
+       }
 
-       rv = dialog_input(ctx, &opts->query, "Search", "Query");
+       dialog_modal_loop(dia, &err, &action);
+       talloc_free(dia);
 
-       return rv;
+       return action;
 }