Added events for Treeview

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2014-04-22 17:45:50 +03:00
parent 953ef5a4a9
commit 5d8d42c239
13 changed files with 781 additions and 495 deletions

View File

@ -11,6 +11,7 @@
#define MCEVENT_GROUP_DIFFVIEWER "DiffViewer" #define MCEVENT_GROUP_DIFFVIEWER "DiffViewer"
#define MCEVENT_GROUP_EDITOR "Editor" #define MCEVENT_GROUP_EDITOR "Editor"
#define MCEVENT_GROUP_FILEMANAGER "FileManager" #define MCEVENT_GROUP_FILEMANAGER "FileManager"
#define MCEVENT_GROUP_TREEVIEW "FileManager:Tree"
#define MCEVENT_GROUP_VIEWER "Viewer" #define MCEVENT_GROUP_VIEWER "Viewer"
/* Events */ /* Events */

View File

@ -9,6 +9,7 @@ libmcfilemanager_la_SOURCES = \
cmd.c cmd.h \ cmd.c cmd.h \
command.c command.h \ command.c command.h \
dir.c dir.h \ dir.c dir.h \
event.c event.h \
ext.c ext.h \ ext.c ext.h \
file.c file.h \ file.c file.h \
filegui.c filegui.h \ filegui.c filegui.h \

View File

@ -387,35 +387,6 @@ sel_charset_button (WButton * button, int action)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static cb_ret_t
tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
WDialog *h = DIALOG (w);
switch (msg)
{
case MSG_RESIZE:
{
Widget *bar;
/* simply call dlg_set_size() with new size */
dlg_set_size (h, LINES - 9, COLS - 20);
bar = WIDGET (find_buttonbar (h));
bar->x = 0;
bar->y = LINES - 1;
return MSG_HANDLED;
}
case MSG_ACTION:
return send_message (find_tree (h), NULL, MSG_ACTION, parm, NULL);
default:
return dlg_default_callback (w, sender, msg, parm, data);
}
}
/* --------------------------------------------------------------------------------------------- */
#if defined(ENABLE_VFS) && defined (ENABLE_VFS_FTP) #if defined(ENABLE_VFS) && defined (ENABLE_VFS_FTP)
static cb_ret_t static cb_ret_t
confvfs_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) confvfs_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
@ -1032,45 +1003,6 @@ display_bits_box (void)
} }
#endif /* HAVE_CHARSET */ #endif /* HAVE_CHARSET */
/* --------------------------------------------------------------------------------------------- */
/** Show tree in a box, not on a panel */
char *
tree_box (const char *current_dir)
{
WTree *mytree;
WDialog *dlg;
Widget *wd;
char *val = NULL;
WButtonBar *bar;
(void) current_dir;
/* Create the components */
dlg = dlg_create (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors, tree_callback, NULL,
"[Directory Tree]", _("Directory tree"), DLG_CENTER);
wd = WIDGET (dlg);
mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
add_widget_autopos (dlg, mytree, WPOS_KEEP_ALL, NULL);
add_widget_autopos (dlg, hline_new (wd->lines - 4, 1, -1), WPOS_KEEP_BOTTOM, NULL);
bar = buttonbar_new (TRUE);
add_widget (dlg, bar);
/* restore ButtonBar coordinates after add_widget() */
WIDGET (bar)->x = 0;
WIDGET (bar)->y = LINES - 1;
if (dlg_run (dlg) == B_ENTER)
{
const vfs_path_t *selected_name;
selected_name = tree_selected_name (mytree);
val = g_strdup (vfs_path_as_str (selected_name));
}
dlg_destroy (dlg);
return val;
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
#ifdef ENABLE_VFS #ifdef ENABLE_VFS

View File

@ -30,7 +30,6 @@ void jobs_cmd (void);
char *cd_dialog (void); char *cd_dialog (void);
void symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath, void symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
char **ret_existing, char **ret_new); char **ret_existing, char **ret_new);
char *tree_box (const char *current_dir);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/
#endif /* MC__BOXES_H */ #endif /* MC__BOXES_H */

View File

@ -86,7 +86,7 @@
#include "filenot.h" #include "filenot.h"
#include "hotlist.h" /* hotlist_show() */ #include "hotlist.h" /* hotlist_show() */
#include "panel.h" /* WPanel */ #include "panel.h" /* WPanel */
#include "tree.h" /* tree_chdir() */ #include "tree.h" /* mc_tree_chdir_t */
#include "midnight.h" /* change_panel() */ #include "midnight.h" /* change_panel() */
#include "usermenu.h" /* MC_GLOBAL_MENU */ #include "usermenu.h" /* MC_GLOBAL_MENU */
#include "command.h" /* cmdline */ #include "command.h" /* cmdline */
@ -1110,7 +1110,13 @@ hotlist_cmd (void)
return; return;
if (get_current_type () == view_tree) if (get_current_type () == view_tree)
tree_chdir (the_tree, target); {
mc_tree_chdir_t chdir_info = {
.tree = the_tree,
.dir = target
};
mc_event_raise (MCEVENT_GROUP_TREEVIEW, "chdir", &chdir_info, NULL, NULL);
}
else else
{ {
vfs_path_t *deprecated_vpath; vfs_path_t *deprecated_vpath;

View File

@ -399,10 +399,12 @@ do_cd_command (char *orig_cmd)
if (get_current_type () == view_tree) if (get_current_type () == view_tree)
{ {
mc_tree_chdir_t chdir_info = {
.tree = the_tree
};
if (cmd[0] == 0) if (cmd[0] == 0)
{ chdir_info.dir = g_strdup (mc_config_get_home_dir ());
sync_tree (mc_config_get_home_dir ());
}
else if (DIR_IS_DOTDOT (cmd + operand_pos)) else if (DIR_IS_DOTDOT (cmd + operand_pos))
{ {
if (vfs_path_elements_count (current_panel->cwd_vpath) != 1 || if (vfs_path_elements_count (current_panel->cwd_vpath) != 1 ||
@ -414,18 +416,20 @@ do_cd_command (char *orig_cmd)
vfs_path_vtokens_get (tmp_vpath, 0, vfs_path_tokens_count (tmp_vpath) - 1); vfs_path_vtokens_get (tmp_vpath, 0, vfs_path_tokens_count (tmp_vpath) - 1);
vfs_path_free (tmp_vpath); vfs_path_free (tmp_vpath);
} }
sync_tree (vfs_path_as_str (current_panel->cwd_vpath)); chdir_info.dir = g_strdup (vfs_path_as_str (current_panel->cwd_vpath));
} }
else if (IS_PATH_SEP (cmd[operand_pos])) else if (IS_PATH_SEP (cmd[operand_pos]))
sync_tree (cmd + operand_pos); chdir_info.dir = g_strdup (cmd + operand_pos);
else else
{ {
vfs_path_t *new_vpath; vfs_path_t *new_vpath;
new_vpath = vfs_path_append_new (current_panel->cwd_vpath, cmd + operand_pos, NULL); new_vpath = vfs_path_append_new (current_panel->cwd_vpath, cmd + operand_pos, NULL);
sync_tree (vfs_path_as_str (new_vpath)); chdir_info.dir = g_strdup (vfs_path_as_str (new_vpath));
vfs_path_free (new_vpath); vfs_path_free (new_vpath);
} }
mc_event_raise (MCEVENT_GROUP_TREEVIEW, "chdir", &chdir_info, NULL, NULL);
g_free (chdir_info.dir);
} }
else else
{ {

90
src/filemanager/event.c Normal file
View File

@ -0,0 +1,90 @@
/*
Editor's events definitions.
Copyright (C) 2012-2014
Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2014
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "lib/global.h"
#include "lib/event.h"
#include "event.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
mc_filemanager_init_events (GError ** error)
{
/* *INDENT-OFF* */
event_init_group_t treeview_group_events[] =
{
{"help", mc_tree_cmd_help, NULL},
{"forget", mc_tree_cmd_forget, NULL},
{"navigation_mode_toggle", mc_tree_cmd_navigation_mode_toggle, NULL},
{"copy", mc_tree_cmd_copy, NULL},
{"move", mc_tree_cmd_move, NULL},
{"goto_up", mc_tree_cmd_goto_up, NULL},
{"goto_down", mc_tree_cmd_goto_down, NULL},
{"goto_home", mc_tree_cmd_goto_home, NULL},
{"goto_end", mc_tree_cmd_goto_end, NULL},
{"goto_page_up", mc_tree_cmd_goto_page_up, NULL},
{"goto_page_down", mc_tree_cmd_goto_page_down, NULL},
{"goto_left", mc_tree_cmd_goto_left, NULL},
{"goto_right", mc_tree_cmd_goto_right, NULL},
{"enter", mc_tree_cmd_enter, NULL},
{"rescan", mc_tree_cmd_rescan, NULL},
{"search_begin", mc_tree_cmd_search_begin, NULL},
{"rmdir", mc_tree_cmd_rmdir, NULL},
{"chdir", mc_tree_cmd_chdir, NULL},
{"show_box", mc_tree_cmd_show_box, NULL},
{NULL, NULL, NULL}
};
/* *INDENT-ON* */
/* *INDENT-OFF* */
event_init_t standard_events[] =
{
{MCEVENT_GROUP_TREEVIEW, treeview_group_events},
{NULL, NULL}
};
/* *INDENT-ON* */
mc_event_mass_add (standard_events, error);
}
/* --------------------------------------------------------------------------------------------- */

42
src/filemanager/event.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef MC__FILEMANAGER_EVENT_H
#define MC__FILEMANAGER_EVENT_H
#include "lib/event.h"
/*** typedefs(not structures) and defined constants **********************************************/
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
void mc_filemanager_init_events (GError ** error);
gboolean mc_tree_cmd_help (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_forget (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_navigation_mode_toggle (event_info_t * event_info, gpointer data,
GError ** error);
gboolean mc_tree_cmd_copy (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_move (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_goto_up (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_goto_down (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_goto_home (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_goto_end (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_goto_page_up (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_goto_page_down (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_goto_left (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_goto_right (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_enter (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_rescan (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_search_begin (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_rmdir (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_chdir (event_info_t * event_info, gpointer data, GError ** error);
gboolean mc_tree_cmd_show_box (event_info_t * event_info, gpointer data, GError ** error);
/*** inline functions ****************************************************************************/
#endif /* MC__FILEMANAGER_EVENT_H */

View File

@ -41,6 +41,8 @@
#include "lib/global.h" #include "lib/global.h"
#include "lib/event.h"
#include "lib/tty/tty.h" #include "lib/tty/tty.h"
#include "lib/tty/key.h" #include "lib/tty/key.h"
#include "lib/skin.h" #include "lib/skin.h"
@ -702,21 +704,23 @@ find_parameters (char **start_dir, ssize_t * start_dir_len,
case B_TREE: case B_TREE:
{ {
char *temp_dir; event_return_t ret;
temp_dir = in_start->buffer;
if (*temp_dir == '\0' || DIR_IS_DOT (temp_dir))
temp_dir = g_strdup (vfs_path_as_str (current_panel->cwd_vpath));
else
temp_dir = g_strdup (temp_dir);
if (in_start_dir != INPUT_LAST_TEXT) if (in_start_dir != INPUT_LAST_TEXT)
g_free (in_start_dir); g_free (in_start_dir);
in_start_dir = tree_box (temp_dir);
if (in_start_dir == NULL) mc_event_raise (MCEVENT_GROUP_TREEVIEW, "show_box", NULL, &ret, NULL);
in_start_dir = temp_dir;
if (ret.s == NULL)
{
in_start_dir = in_start->buffer;
if (*in_start_dir == '\0' || DIR_IS_DOT (in_start_dir))
in_start_dir = g_strdup (vfs_path_as_str (current_panel->cwd_vpath));
else
in_start_dir = g_strdup (in_start_dir);
}
else else
g_free (temp_dir); in_start_dir = ret.s;
input_assign_text (in_start, in_start_dir); input_assign_text (in_start, in_start_dir);

View File

@ -87,6 +87,7 @@
#include "src/consaver/cons.saver.h" /* show_console_contents */ #include "src/consaver/cons.saver.h" /* show_console_contents */
#include "event.h"
#include "midnight.h" #include "midnight.h"
/* TODO: merge content of layout.c here */ /* TODO: merge content of layout.c here */
@ -152,17 +153,18 @@ stop_dialogs (void)
static void static void
treebox_cmd (void) treebox_cmd (void)
{ {
char *sel_dir; event_return_t ret;
sel_dir = tree_box (selection (current_panel)->fname); mc_event_raise (MCEVENT_GROUP_TREEVIEW, "show_box", NULL, &ret, NULL);
if (sel_dir != NULL)
if (ret.s != NULL)
{ {
vfs_path_t *sel_vdir; vfs_path_t *sel_vdir;
sel_vdir = vfs_path_from_str (sel_dir); sel_vdir = vfs_path_from_str (ret.s);
do_cd (sel_vdir, cd_exact); do_cd (sel_vdir, cd_exact);
vfs_path_free (sel_vdir); vfs_path_free (sel_vdir);
g_free (sel_dir); g_free (ret.s);
} }
} }
@ -496,7 +498,6 @@ check_current_panel_timestamp (event_info_t * event_info, gpointer data, GError
{ {
ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data; ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
(void) event_info;
(void) error; (void) error;
event_info->ret->b = event_info->ret->b =
@ -513,7 +514,6 @@ check_other_panel_timestamp (event_info_t * event_info, gpointer data, GError **
{ {
ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data; ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data;
(void) event_info;
(void) error; (void) error;
event_info->ret->b = event_info->ret->b =
@ -1768,6 +1768,7 @@ do_nc (GError ** error)
setup_mc (); setup_mc ();
mc_filehighlight = mc_fhl_new (TRUE); mc_filehighlight = mc_fhl_new (TRUE);
mc_filemanager_init_events (error);
create_panels_and_run_mc (); create_panels_and_run_mc ();
mc_fhl_free (&mc_filehighlight); mc_fhl_free (&mc_filehighlight);

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,12 @@
typedef struct WTree WTree; typedef struct WTree WTree;
typedef struct
{
WTree *tree;
char *dir;
} mc_tree_chdir_t;
/*** global variables defined in .c file *********************************************************/ /*** global variables defined in .c file *********************************************************/
extern WTree *the_tree; extern WTree *the_tree;
@ -26,12 +32,7 @@ struct WDialog;
WTree *tree_new (int y, int x, int lines, int cols, gboolean is_panel); WTree *tree_new (int y, int x, int lines, int cols, gboolean is_panel);
void tree_chdir (WTree * tree, const char *dir);
vfs_path_t *tree_selected_name (const WTree * tree); vfs_path_t *tree_selected_name (const WTree * tree);
void sync_tree (const char *pathname);
WTree *find_tree (struct WDialog *h);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/
#endif /* MC__TREE_H */ #endif /* MC__TREE_H */

View File

@ -100,12 +100,6 @@ shell_execute (const char *command, int flags)
(void) flags; (void) flags;
} }
void
sync_tree (const char *pathname)
{
(void) pathname;
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void