bool tree_input;
};
+static struct regedit *regedit_main = NULL;
+
/* load all available hives */
static struct tree_node *load_hives(TALLOC_CTX *mem_ctx,
struct registry_context *ctx)
if (subkey) {
msg = "Enter name of new subkey";
}
- dialog_input(regedit, &name, "New Key", regedit->main_window, msg);
+ dialog_input(regedit, &name, "New Key", msg);
if (name) {
WERROR rv;
struct registry_key *new_key;
tree_view_update(regedit->keys, list);
} else {
dialog_notice(regedit, DIA_ALERT, "New Key",
- regedit->main_window,
"Failed to create key.");
}
talloc_free(name);
}
sel = dialog_notice(regedit, DIA_CONFIRM,
"Delete Key",
- regedit->main_window,
"Really delete key \"%s\"?",
node->name);
if (sel == DIALOG_OK) {
value_list_load(regedit->vl, node->key);
} else {
dialog_notice(regedit, DIA_ALERT, "Delete Key",
- regedit->main_window,
"Failed to delete key.");
}
}
struct tree_node *node;
node = item_userptr(current_item(regedit->keys->menu));
dialog_edit_value(regedit, node->key, vitem->type,
- vitem, regedit->main_window);
+ vitem);
value_list_load(regedit->vl, node->key);
}
break;
int new_type;
int sel;
- sel = dialog_select_type(regedit, &new_type,
- regedit->main_window);
+ sel = dialog_select_type(regedit, &new_type);
if (sel == DIALOG_OK) {
struct tree_node *node;
node = item_userptr(current_item(regedit->keys->menu));
- dialog_edit_value(regedit, node->key, new_type, NULL,
- regedit->main_window);
+ dialog_edit_value(regedit, node->key, new_type, NULL);
value_list_load(regedit->vl, node->key);
}
break;
sel = dialog_notice(regedit, DIA_CONFIRM,
"Delete Value",
- regedit->main_window,
"Really delete value \"%s\"?",
vitem->value_name);
if (sel == DIALOG_OK) {
}
}
-/* test navigating available hives */
-static void display_test_window(TALLOC_CTX *mem_ctx,
- struct registry_context *ctx)
+int regedit_getch(void)
+{
+ int c;
+
+ SMB_ASSERT(regedit_main);
+
+ c = getch();
+
+ if (c == KEY_RESIZE) {
+ tree_view_resize(regedit_main->keys, KEY_HEIGHT, KEY_WIDTH,
+ KEY_START_Y, KEY_START_X);
+ value_list_resize(regedit_main->vl, VAL_HEIGHT, VAL_WIDTH,
+ VAL_START_Y, VAL_START_X);
+ print_heading(regedit_main);
+ }
+
+ return c;
+}
+
+static void display_window(TALLOC_CTX *mem_ctx, struct registry_context *ctx)
{
struct regedit *regedit;
struct tree_node *root;
regedit = talloc_zero(mem_ctx, struct regedit);
SMB_ASSERT(regedit != NULL);
+ regedit_main = regedit;
regedit->main_window = stdscr;
keypad(regedit->main_window, TRUE);
update_panels();
doupdate();
- while ((c = wgetch(regedit->main_window)) != 'q') {
- if (c == KEY_RESIZE) {
- tree_view_resize(regedit->keys, KEY_HEIGHT, KEY_WIDTH,
- KEY_START_Y, KEY_START_X);
- value_list_resize(regedit->vl, VAL_HEIGHT, VAL_WIDTH,
- VAL_START_Y, VAL_START_X);
- print_heading(regedit);
+ while (1) {
+ c = regedit_getch();
+ if (c == 'q' || c == 'Q') {
+ break;
}
handle_main_input(regedit, c);
update_panels();
return 1;
}
- display_test_window(frame, ctx);
+ display_window(frame, ctx);
//talloc_report_full(frame, stdout);
*/
#include "includes.h"
+#include "regedit.h"
#include "regedit_dialog.h"
#include "regedit_valuelist.h"
#include "regedit_hexedit.h"
}
-static void center_dialog_above_window(WINDOW *below, int *nlines, int *ncols,
+static void center_dialog_above_window(int *nlines, int *ncols,
int *y, int *x)
{
- int maxy, maxx;
int centery, centerx;
- getmaxyx(below, maxy, maxx);
-
- centery = maxy / 2;
- centerx = maxx / 2;
+ centery = LINES / 2;
+ centerx = COLS / 2;
*y = 0;
*x = 0;
- if (*nlines > maxy) {
- *nlines = maxy;
+ if (*nlines > LINES) {
+ *nlines = LINES;
}
- if (*ncols > maxx) {
- *ncols = maxx;
+ if (*ncols > COLS) {
+ *ncols = COLS;
}
- if (*nlines < centery) {
+ if (*nlines/2 < centery) {
*y = centery - *nlines / 2;
}
- if (*ncols < centerx) {
+ if (*ncols/2 < centerx) {
*x = centerx - *ncols / 2;
}
}
+static int dialog_getch(struct dialog *dia)
+{
+ int c;
+
+ c = regedit_getch();
+
+ if (c == KEY_RESIZE) {
+ int nlines, ncols, y, x;
+
+ getmaxyx(dia->window, nlines, ncols);
+ getbegyx(dia->window, y, x);
+ if (dia->centered) {
+ center_dialog_above_window(&nlines, &ncols, &y, &x);
+ } else {
+ if (nlines + y > LINES) {
+ if (nlines > LINES) {
+ y = 0;
+ } else {
+ y = LINES - nlines;
+ }
+ }
+ if (ncols + x > COLS) {
+ if (ncols > COLS) {
+ x = 0;
+ } else {
+ x = COLS - ncols;
+ }
+ }
+ }
+ move_panel(dia->panel, y, x);
+ doupdate();
+ }
+
+ return c;
+}
+
struct dialog *dialog_center_new(TALLOC_CTX *ctx, const char *title, int nlines,
- int ncols, WINDOW *below)
+ int ncols)
{
+ struct dialog *dia;
int y, x;
- center_dialog_above_window(below, &nlines, &ncols, &y, &x);
+ center_dialog_above_window(&nlines, &ncols, &y, &x);
- return dialog_new(ctx, title, nlines, ncols, y, x);
+ dia = dialog_new(ctx, title, nlines, ncols, y, x);
+ if (dia) {
+ dia->centered = true;
+ }
+
+ return dia;
}
struct dialog *dialog_choice_new(TALLOC_CTX *ctx, const char *title,
struct dialog *dialog_choice_center_new(TALLOC_CTX *ctx, const char *title,
const char **choices, int nlines,
- int ncols, WINDOW *below)
+ int ncols)
{
int y, x;
+ struct dialog *dia;
+ center_dialog_above_window(&nlines, &ncols, &y, &x);
- center_dialog_above_window(below, &nlines, &ncols, &y, &x);
+ dia = dialog_choice_new(ctx, title, choices, nlines, ncols, y, x);
+ if (dia) {
+ dia->centered = true;
+ }
- return dialog_choice_new(ctx, title, choices, nlines, ncols, y, x);
+ return dia;
}
static int handle_menu_input(MENU *menu, int c)
int c;
int selection = -1;
- keypad(dia->window, true);
update_panels();
doupdate();
while (selection == -1) {
- c = wgetch(dia->window);
+ c = dialog_getch(dia);
selection = handle_menu_input(dia->choices, c);
update_panels();
doupdate();
}
static struct dialog *dialog_msg_new(TALLOC_CTX *ctx, const char *title,
- const char **choices, WINDOW *below,
- int nlines, const char *msg, va_list ap)
+ const char **choices, int nlines,
+ const char *msg, va_list ap)
{
struct dialog *dia;
char *str;
if (width < MIN_WIDTH) {
width = MIN_WIDTH;
}
- dia = dialog_choice_center_new(ctx, title, choices, nlines, width, below);
+ dia = dialog_choice_center_new(ctx, title, choices, nlines, width);
if (dia == NULL) {
return NULL;
}
}
int dialog_input(TALLOC_CTX *ctx, char **output, const char *title,
- WINDOW *below, const char *msg, ...)
+ const char *msg, ...)
{
va_list ap;
struct dialog *dia;
bool input_section = true;
va_start(ap, msg);
- dia = dialog_msg_new(ctx, title, choices, below, 7, msg, ap);
+ dia = dialog_msg_new(ctx, title, choices, 7, msg, ap);
va_end(ap);
if (dia == NULL) {
return -1;
post_form(input);
*output = NULL;
- keypad(dia->window, true);
update_panels();
doupdate();
while (rv == -1) {
- int c = wgetch(dia->window);
+ int c = dialog_getch(dia);
if (c == '\t' || c == KEY_BTAB) {
if (input_section) {
input_section = true;
set_current_field(input, field[0]);
}
- continue;
- }
-
- if (input_section) {
+ } else if (input_section) {
handle_form_input(input, c);
} else {
rv = handle_menu_input(dia->choices, c);
*output = string_trim(ctx, buf);
}
}
+ update_panels();
+ doupdate();
}
finish:
}
int dialog_notice(TALLOC_CTX *ctx, enum dialog_type type,
- const char *title, WINDOW *below,
- const char *msg, ...)
+ const char *title, const char *msg, ...)
{
va_list ap;
struct dialog *dia;
}
va_start(ap, msg);
- dia = dialog_msg_new(ctx, title, choices, below, 5, msg, ap);
+ dia = dialog_msg_new(ctx, title, choices, 5, msg, ap);
va_end(ap);
if (dia == NULL) {
return -1;
set_current_field(edit->input, edit->field[0]);
break;
}
+ update_panels();
+ doupdate();
}
static void section_up(struct edit_dialog *edit)
}
break;
}
+ update_panels();
+ doupdate();
}
static void handle_hexedit_input(struct hexedit *buf, int c)
}
WERROR dialog_edit_value(TALLOC_CTX *ctx, struct registry_key *key, uint32_t type,
- const struct value_item *vitem, WINDOW *below)
+ const struct value_item *vitem)
{
struct edit_dialog *edit;
const char *choices[] = {
}
ncols = 50;
edit->dia = dialog_choice_center_new(edit, title, choices, nlines,
- ncols, below);
+ ncols);
talloc_free(title);
if (edit->dia == NULL) {
goto finish;
mvwprintw(edit->dia->sub_window, 0, 0, "Name");
mvwprintw(edit->dia->sub_window, 3, 0, "Data");
- keypad(edit->dia->window, true);
update_panels();
doupdate();
edit->section = IN_NAME;
while (1) {
- int c = wgetch(edit->dia->window);
+ int c = dialog_getch(edit->dia);
if (c == '\t') {
section_down(edit);
continue;
rv = set_value(edit, key, type, vitem == NULL);
if (W_ERROR_EQUAL(rv, WERR_FILE_EXISTS)) {
dialog_notice(edit, DIA_ALERT,
- "Value exists", below,
+ "Value exists",
"Value name already exists.");
selection = -1;
} else {
char *n;
size_t newlen = 0;
- dialog_input(edit, &n, "Resize buffer", below,
+ dialog_input(edit, &n, "Resize buffer",
"Enter new size");
if (n) {
newlen = strtoul(n, NULL, 10);
return rv;
}
-int dialog_select_type(TALLOC_CTX *ctx, int *type, WINDOW *below)
+int dialog_select_type(TALLOC_CTX *ctx, int *type)
{
struct dialog *dia;
const char *choices[] = {
int sel = -1;
size_t i;
- dia = dialog_choice_center_new(ctx, "New Value", choices, 10, 20,
- below);
+ dia = dialog_choice_center_new(ctx, "New Value", choices, 10, 20);
if (dia == NULL) {
return -1;
}
set_menu_mark(list, "* ");
post_menu(list);
- keypad(dia->window, true);
update_panels();
doupdate();
while (sel == -1) {
ITEM *it;
- int c = wgetch(dia->window);
+ int c = dialog_getch(dia);
switch (c) {
case KEY_UP:
sel = (int)(uintptr_t)item_userptr(it);
break;
}
+
+ update_panels();
+ doupdate();
}
finish:
PANEL *panel;
MENU *choices;
ITEM **choice_items;
+ bool centered;
};
struct dialog *dialog_new(TALLOC_CTX *ctx, const char *title, int nlines,
int ncols, int y, int x);
struct dialog *dialog_center_new(TALLOC_CTX *ctx, const char *title, int nlines,
- int ncols, WINDOW *below);
+ int ncols);
struct dialog *dialog_choice_new(TALLOC_CTX *ctx, const char *title,
const char **choices, int nlines, int ncols,
struct dialog *dialog_choice_center_new(TALLOC_CTX *ctx, const char *title,
const char **choices, int nlines,
- int ncols, WINDOW *below);
+ int ncols);
enum dialog_type {
DIA_ALERT,
};
int dialog_notice(TALLOC_CTX *ctx, enum dialog_type type,
- const char *title, WINDOW *below,
- const char *msg, ...);
+ const char *title, const char *msg, ...);
int dialog_input(TALLOC_CTX *ctx, char **output, const char *title,
- WINDOW *below, const char *msg, ...);
+ const char *msg, ...);
struct registry_key;
struct value_item;
WERROR dialog_edit_value(TALLOC_CTX *ctx, struct registry_key *key, uint32_t type,
- const struct value_item *vitem, WINDOW *below);
+ const struct value_item *vitem);
-int dialog_select_type(TALLOC_CTX *ctx, int *type, WINDOW *below);
+int dialog_select_type(TALLOC_CTX *ctx, int *type);
#endif