Ejemplo n.º 1
0
int
dialog_switch_process_pending (void)
{
    int ret = 0;

    while (dialog_switch_pending)
    {
        Dlg_head *h = (Dlg_head *) mc_current->data;

        dialog_switch_pending = FALSE;
        h->state = DLG_SUSPENDED;
        ret = run_dlg (h);
        if (h->state == DLG_CLOSED)
        {
            destroy_dlg (h);

            /* return to panels */
            if (mc_global.mc_run_mode == MC_RUN_FULL)
            {
                mc_current = g_list_find (mc_dialogs, midnight_dlg);
                mc_event_raise (MCEVENT_GROUP_FILEMANAGER, "update_panels", NULL);
            }
        }
    }

    repaint_screen ();

    return ret;
}
Ejemplo n.º 2
0
/**
  * Write history to the ${XDG_CACHE_HOME}/mc/history file
  */
void
dlg_save_history (WDialog * h)
{
    char *profile;
    int i;

    if (num_history_items_recorded == 0)        /* this is how to disable */
        return;

    profile = mc_config_get_full_path (MC_HISTORY_FILE);
    i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
    if (i != -1)
        close (i);

    /* Make sure the history is only readable by the user */
    if (chmod (profile, S_IRUSR | S_IWUSR) != -1 || errno == ENOENT)
    {
        ev_history_load_save_t event_data;

        event_data.cfg = mc_config_init (profile, FALSE);
        event_data.receiver = NULL;

        /* get all histories in dialog */
        mc_event_raise (h->event_group, MCEVENT_HISTORY_SAVE, &event_data);

        mc_config_save_file (event_data.cfg, NULL);
        mc_config_deinit (event_data.cfg);
    }

    g_free (profile);
}
Ejemplo n.º 3
0
void
help_cmd (void)
{
    ev_help_t event_data = { NULL, NULL };

    if (current_panel->searching)
        event_data.node = "[Quick search]";
    else
        event_data.node = "[main]";

    mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
Ejemplo n.º 4
0
Archivo: wtools.c Proyecto: ryanlee/mc
static char *
wtools_parent_call_string (void *routine, int argc, ...)
{
    ev_background_parent_call_t event_data;

    event_data.routine = routine;
    event_data.argc = argc;
    va_start (event_data.ap, argc);
    mc_event_raise (MCEVENT_GROUP_CORE, "background_parent_call_string", (gpointer) & event_data);
    va_end (event_data.ap);
    return event_data.ret.s;
}
Ejemplo n.º 5
0
Archivo: wtools.c Proyecto: ryanlee/mc
static int
wtools_parent_call (void *routine, gpointer ctx, int argc, ...)
{
    ev_background_parent_call_t event_data;

    event_data.routine = routine;
    event_data.ctx = ctx;
    event_data.argc = argc;
    va_start (event_data.ap, argc);
    mc_event_raise (MCEVENT_GROUP_CORE, "background_parent_call", (gpointer) & event_data);
    va_end (event_data.ap);
    return event_data.ret.i;
}
Ejemplo n.º 6
0
/**
  * Read histories from the ${XDG_CACHE_HOME}/mc/history file
  */
static void
dlg_read_history (WDialog * h)
{
    char *profile;
    ev_history_load_save_t event_data;

    if (num_history_items_recorded == 0)        /* this is how to disable */
        return;

    profile = mc_config_get_full_path (MC_HISTORY_FILE);
    event_data.cfg = mc_config_init (profile, TRUE);
    event_data.receiver = NULL;

    /* create all histories in dialog */
    mc_event_raise (h->event_group, MCEVENT_HISTORY_LOAD, &event_data);

    mc_config_deinit (event_data.cfg);
    g_free (profile);
}
Ejemplo n.º 7
0
static int
menubar_handle_key (WMenuBar * menubar, int key)
{
    /* Lowercase */
    if (isascii (key))
        key = g_ascii_tolower (key);

    if (is_abort_char (key))
    {
        menubar_finish (menubar);
        return 1;
    }

    /* menubar help or menubar navigation */
    switch (key)
    {
    case KEY_F (1):
        {
            ev_help_t event_data = { NULL, NULL };

            if (menubar->is_dropped)
                event_data.node =
                    MENU (g_list_nth_data (menubar->menu, menubar->selected))->help_node;
            else
                event_data.node = "[Menu Bar]";

            mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
            menubar_draw (menubar);
            return 1;
        }

    case KEY_LEFT:
    case XCTRL ('b'):
        menubar_left (menubar);
        return 1;

    case KEY_RIGHT:
    case XCTRL ('f'):
        menubar_right (menubar);
        return 1;

    default:
        break;
    }

    if (!menubar->is_dropped)
    {
        GList *i;

        /* drop menu by hotkey */
        for (i = menubar->menu; i != NULL; i = g_list_next (i))
        {
            menu_t *menu = MENU (i->data);

            if ((menu->text.hotkey != NULL) && (key == g_ascii_tolower (menu->text.hotkey[0])))
            {
                menubar_drop (menubar, g_list_position (menubar->menu, i));
                return 1;
            }
        }

        /* drop menu by Enter or Dowwn key */
        if (key == KEY_ENTER || key == XCTRL ('n') || key == KEY_DOWN || key == '\n')
            menubar_drop (menubar, menubar->selected);

        return 1;
    }

    {
        menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
        GList *i;

        /* execute menu command by hotkey */
        for (i = menu->entries; i != NULL; i = g_list_next (i))
        {
            const menu_entry_t *entry = MENUENTRY (i->data);

            if ((entry != NULL) && (entry->command != CK_IgnoreKey)
                && (entry->text.hotkey != NULL) && (key == g_ascii_tolower (entry->text.hotkey[0])))
            {
                menu->selected = g_list_position (menu->entries, i);
                menubar_execute (menubar);
                return 1;
            }
        }

        /* menu execute by Enter or menu navigation */
        switch (key)
        {
        case KEY_ENTER:
        case '\n':
            menubar_execute (menubar);
            return 1;

        case KEY_HOME:
        case ALT ('<'):
            menubar_first (menubar);
            break;

        case KEY_END:
        case ALT ('>'):
            menubar_last (menubar);
            break;

        case KEY_DOWN:
        case XCTRL ('n'):
            menubar_down (menubar);
            break;

        case KEY_UP:
        case XCTRL ('p'):
            menubar_up (menubar);
            break;

        default:
            break;
        }
    }

    return 0;
}
Ejemplo n.º 8
0
static cb_ret_t
dlg_execute_cmd (WDialog * h, unsigned long command)
{
    cb_ret_t ret = MSG_HANDLED;
    switch (command)
    {
    case CK_Ok:
        h->ret_value = B_ENTER;
        dlg_stop (h);
        break;
    case CK_Cancel:
        h->ret_value = B_CANCEL;
        dlg_stop (h);
        break;

    case CK_Up:
    case CK_Left:
        dlg_one_up (h);
        break;
    case CK_Down:
    case CK_Right:
        dlg_one_down (h);
        break;

    case CK_Help:
        {
            ev_help_t event_data = { NULL, h->help_ctx };
            mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
        }
        break;

    case CK_Suspend:
        mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
        refresh_cmd ();
        break;
    case CK_Refresh:
        refresh_cmd ();
        break;

    case CK_ScreenList:
        if (!h->modal)
            dialog_switch_list ();
        else
            ret = MSG_NOT_HANDLED;
        break;
    case CK_ScreenNext:
        if (!h->modal)
            dialog_switch_next ();
        else
            ret = MSG_NOT_HANDLED;
        break;
    case CK_ScreenPrev:
        if (!h->modal)
            dialog_switch_prev ();
        else
            ret = MSG_NOT_HANDLED;
        break;

    default:
        ret = MSG_NOT_HANDLED;
    }

    return ret;
}
Ejemplo n.º 9
0
static void
edit_help (void)
{
    ev_help_t event_data = { NULL, "[Internal File Editor]" };
    mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
Ejemplo n.º 10
0
static cb_ret_t
tree_execute_cmd (WTree * tree, long command)
{
    cb_ret_t res = MSG_HANDLED;

    if (command != CK_Search)
        tree->searching = 0;

    switch (command)
    {
    case CK_Help:
        {
            ev_help_t event_data = { NULL, "[Directory Tree]" };
            mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
        }
        break;
    case CK_Forget:
        tree_forget (tree);
        break;
    case CK_ToggleNavigation:
        tree_toggle_navig (tree);
        break;
    case CK_Copy:
        tree_copy (tree, "");
        break;
    case CK_Move:
        tree_move (tree, "");
        break;
    case CK_Up:
        tree_move_up (tree);
        break;
    case CK_Down:
        tree_move_down (tree);
        break;
    case CK_Top:
        tree_move_home (tree);
        break;
    case CK_Bottom:
        tree_move_end (tree);
        break;
    case CK_PageUp:
        tree_move_pgup (tree);
        break;
    case CK_PageDown:
        tree_move_pgdn (tree);
        break;
    case CK_Enter:
        tree_chdir_sel (tree);
        break;
    case CK_Reread:
        tree_rescan (tree);
        break;
    case CK_Search:
        tree_start_search (tree);
        break;
    case CK_Delete:
        tree_rmdir (tree);
        break;
    case CK_Quit:
        if (!tree->is_panel)
            dlg_stop (WIDGET (tree)->owner);
        return res;
    default:
        res = MSG_NOT_HANDLED;
    }

    show_tree (tree);

    return res;
}
Ejemplo n.º 11
0
Archivo: layout.c Proyecto: m32/mc
void
set_display_type (int num, panel_view_mode_t type)
{
    int x = 0, y = 0, cols = 0, lines = 0;
    unsigned int the_other = 0; /* Index to the other panel */
    const char *file_name = NULL;       /* For Quick view */
    Widget *new_widget = NULL, *old_widget = NULL;
    panel_view_mode_t old_type = view_listing;
    WPanel *the_other_panel = NULL;

    if (num >= MAX_VIEWS)
    {
        fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS);
        abort ();
    }
    /* Check that we will have a WPanel * at least */
    if (type != view_listing)
    {
        the_other = num == 0 ? 1 : 0;

        if (panels[the_other].type != view_listing)
            return;
    }

    /* Get rid of it */
    if (panels[num].widget != NULL)
    {
        Widget *w = panels[num].widget;
        WPanel *panel = PANEL (w);

        x = w->x;
        y = w->y;
        cols = w->cols;
        lines = w->lines;
        old_widget = w;
        old_type = panels[num].type;

        if (old_type == view_listing && panel->frame_size == frame_full && type != view_listing)
        {
            if (panels_layout.horizontal_split)
            {
                cols = COLS;
                x = 0;
            }
            else
            {
                cols = COLS - panels_layout.left_panel_size;
                if (num == 1)
                    x = panels_layout.left_panel_size;
            }
        }
    }

    /* Restoring saved path from panels.ini for nonlist panel */
    /* when it's first creation (for example view_info) */
    if (old_widget == NULL && type != view_listing)
    {
        char *panel_dir;

        panel_dir = _vfs_get_cwd ();
        panels[num].last_saved_dir = g_strdup (panel_dir);
        g_free (panel_dir);
    }

    switch (type)
    {
    case view_nothing:
    case view_listing:
        new_widget = restore_into_right_dir_panel (num, old_widget);
        widget_set_size (new_widget, y, x, lines, cols);
        break;

    case view_info:
        new_widget = WIDGET (info_new (y, x, lines, cols));
        break;

    case view_tree:
        new_widget = WIDGET (tree_new (y, x, lines, cols, TRUE));
        break;

    case view_quick:
        new_widget = WIDGET (mcview_new (y, x, lines, cols, TRUE));
        the_other_panel = PANEL (panels[the_other].widget);
        if (the_other_panel != NULL)
            file_name = the_other_panel->dir.list[the_other_panel->selected].fname;
        else
            file_name = "";

        mcview_load ((struct mcview_struct *) new_widget, 0, file_name, 0, 0, 0);
        break;

    default:
        break;
    }

    if (type != view_listing)
        /* Must save dir, for restoring after change type to */
        /* view_listing */
        save_panel_dir (num);

    panels[num].type = type;
    panels[num].widget = new_widget;

    /* We use replace to keep the circular list of the dialog in the */
    /* same state.  Maybe we could just kill it and then replace it  */
    if ((midnight_dlg != NULL) && (old_widget != NULL))
    {
        if (old_type == view_listing)
        {
            /* save and write directory history of panel
             * ... and other histories of midnight_dlg  */
            dlg_save_history (midnight_dlg);
        }

        widget_replace (old_widget, new_widget);
    }

    if (type == view_listing)
    {
        WPanel *panel = PANEL (new_widget);

        /* if existing panel changed type to view_listing, then load history */
        if (old_widget != NULL)
        {
            ev_history_load_save_t event_data = { NULL, new_widget };

            mc_event_raise (midnight_dlg->event_group, MCEVENT_HISTORY_LOAD, &event_data);
        }

        if (num == 0)
            left_panel = panel;
        else
            right_panel = panel;

        /* forced update format after set new sizes */
        set_panel_formats (panel);
    }

    if (type == view_tree)
        the_tree = (WTree *) new_widget;

    /* Prevent current_panel's value from becoming invalid.
     * It's just a quick hack to prevent segfaults. Comment out and
     * try following:
     * - select left panel
     * - invoke menue left/tree
     * - as long as you stay in the left panel almost everything that uses
     *   current_panel causes segfault, e.g. C-Enter, C-x c, ...
     */
    if ((type != view_listing) && (current_panel == PANEL (old_widget)))
        current_panel = num == 0 ? right_panel : left_panel;

    g_free (old_widget);
}
Ejemplo n.º 12
0
static cb_ret_t
dlg_execute_cmd (WDialog * h, long command)
{
    cb_ret_t ret = MSG_HANDLED;

    if (send_message (h, NULL, MSG_ACTION, command, NULL) == MSG_HANDLED)
        return MSG_HANDLED;

    switch (command)
    {
    case CK_Ok:
        h->ret_value = B_ENTER;
        dlg_stop (h);
        break;
    case CK_Cancel:
        h->ret_value = B_CANCEL;
        dlg_stop (h);
        break;

    case CK_Up:
    case CK_Left:
        dlg_select_prev_widget (h);
        break;
    case CK_Down:
    case CK_Right:
        dlg_select_next_widget (h);
        break;

    case CK_Help:
        {
            ev_help_t event_data = { NULL, h->help_ctx };
            mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
        }
        break;

    case CK_Suspend:
        mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
        refresh_cmd ();
        break;
    case CK_Refresh:
        refresh_cmd ();
        break;

    case CK_ScreenList:
        if (!widget_get_state (WIDGET (h), WST_MODAL))
            dialog_switch_list ();
        else
            ret = MSG_NOT_HANDLED;
        break;
    case CK_ScreenNext:
        if (!widget_get_state (WIDGET (h), WST_MODAL))
            dialog_switch_next ();
        else
            ret = MSG_NOT_HANDLED;
        break;
    case CK_ScreenPrev:
        if (!widget_get_state (WIDGET (h), WST_MODAL))
            dialog_switch_prev ();
        else
            ret = MSG_NOT_HANDLED;
        break;

    default:
        ret = MSG_NOT_HANDLED;
    }

    return ret;
}