From c3f5696cca382b61662d35b39be77d56f0fc0a92 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Fri, 29 Nov 2002 04:55:06 +0000 Subject: [PATCH] * tree.c: Make struct WTree opaque. Remove "done" flag - it's broken by design. (tree_selected_name): New function, return name of the currently selected entry. Use it where WTree is opaque. * boxes.c (tree_callback): Don't check for the "done" flag - it causes closing the dialog on any key after mouse selection. --- src/ChangeLog | 7 +++++++ src/boxes.c | 4 ++-- src/file.c | 6 +++--- src/main.c | 2 +- src/tree.c | 27 +++++++++++++++++++++++---- src/tree.h | 16 ++++------------ 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 23959b12e..8b85d9669 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2002-11-28 Pavel Roskin + * tree.c: Make struct WTree opaque. Remove "done" flag - it's + broken by design. + (tree_selected_name): New function, return name of the currently + selected entry. Use it where WTree is opaque. + * boxes.c (tree_callback): Don't check for the "done" flag - it + causes closing the dialog on any key after mouse selection. + * user.h: Don't include edit/edit-widget.h. * user.c: Include edit/edit-widget.h and edit/edit.h. diff --git a/src/boxes.c b/src/boxes.c index 1cbeb3305..c5effded4 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -643,7 +643,7 @@ tree_callback (struct Dlg_head *h, int id, int msg) case DLG_POST_KEY: /* The enter key will be processed by the tree widget */ - if (id == '\n' || ((WTree *)(h->current->widget))->done){ + if (id == '\n') { h->ret_value = B_ENTER; dlg_stop (h); } @@ -677,7 +677,7 @@ tree_box (char *current_dir) run_dlg (dlg); if (dlg->ret_value == B_ENTER) - val = g_strdup (mytree->selected_ptr->name); + val = g_strdup (tree_selected_name (mytree)); else val = 0; diff --git a/src/file.c b/src/file.c index 5cf20a814..7f4189362 100644 --- a/src/file.c +++ b/src/file.c @@ -1559,12 +1559,12 @@ panel_get_file (WPanel *panel, struct stat *stat_buf) { int i; - /* No problem with Gnome, as get_current_type never returns view_tree there */ if (get_current_type () == view_tree) { WTree *tree = (WTree *) get_panel_widget (get_current_index ()); + char *tree_name = tree_selected_name (tree); - mc_stat (tree->selected_ptr->name, stat_buf); - return tree->selected_ptr->name; + mc_stat (tree_name, stat_buf); + return tree_name; } if (panel->marked) { diff --git a/src/main.c b/src/main.c index 6bf65b497..dc49f2dcf 100644 --- a/src/main.c +++ b/src/main.c @@ -1332,7 +1332,7 @@ copy_prog_name (void) if (get_current_type () == view_tree) { WTree *tree = (WTree *) get_panel_widget (get_current_index ()); - tmp = tree->selected_ptr->name; + tmp = tree_selected_name (tree); } else tmp = selection (cpanel)->fname; diff --git a/src/tree.c b/src/tree.c index f127d25a4..4210565fe 100644 --- a/src/tree.c +++ b/src/tree.c @@ -56,6 +56,19 @@ extern int command_prompt; /* Specifies the display mode: 1d or 2d */ static int tree_navigation_flag; +struct WTree { + Widget widget; + TreeStore *store; + tree_entry *selected_ptr; /* The selected directory */ + char search_buffer[256]; /* Current search string */ + tree_entry **tree_shown; /* Entries currently on screen */ + int is_panel; /* panel or plain widget flag */ + int active; /* if it's currently selected */ + int searching; /* Are we on searching mode? */ + int topdiff; /* The difference between the topmost + shown and the selected */ +}; + /* Forwards */ static void save_tree (WTree *tree); static void tree_rescan_cmd (WTree *tree); @@ -862,12 +875,11 @@ move_nextp (WTree *tree) static void chdir_sel (WTree *tree) { - if (!tree->is_panel){ - tree->done = 1; + if (!tree->is_panel) { return; } change_panel (); - if (do_cd (tree->selected_ptr->name, cd_exact)){ + if (do_cd (tree->selected_ptr->name, cd_exact)) { paint_panel (cpanel); select_item (cpanel); } else { @@ -1069,7 +1081,6 @@ tree_new (int is_panel, int y, int x, int lines, int cols) tree->search_buffer[0] = 0; tree->topdiff = tree->widget.lines / 2; tree->searching = 0; - tree->done = 0; tree->active = 0; /* We do not want to keep the cursor */ @@ -1077,3 +1088,11 @@ tree_new (int is_panel, int y, int x, int lines, int cols) load_tree (tree); return tree; } + +/* Return name of the currently selected entry */ +char * +tree_selected_name (WTree *tree) +{ + return tree->selected_ptr->name; +} + diff --git a/src/tree.h b/src/tree.h index 1a66f5b29..d2a0049f5 100644 --- a/src/tree.h +++ b/src/tree.h @@ -4,23 +4,15 @@ #include "treestore.h" #include "dlg.h" -typedef struct { - Widget widget; - TreeStore *store; - tree_entry *selected_ptr; /* The selected directory */ - char search_buffer [256]; /* Current search string */ - int done; /* Flag: exit tree */ - tree_entry **tree_shown; /* Entries currently on screen */ - int is_panel; /* panel or plain widget flag */ - int active; /* if it's currently selected */ - int searching; /* Are we on searching mode? */ - int topdiff; /* The difference between the topmost shown and the selected */ -} WTree; + +struct WTree; +typedef struct WTree WTree; #define tlines(t) (t->is_panel ? t->widget.lines-2 - (show_mini_info ? 2 : 0) : t->widget.lines) int tree_init (char *current_dir, int lines); void tree_chdir (WTree *tree, char *dir); +char *tree_selected_name (WTree *tree); void sync_tree (char *pathname);