Directory hotlist



Directory hotlist (C-\) has no way to add the current directory
to the beginning of the list, short of appending it and then moving it
to the top. A bit of a pain.

So I thought I'd have a go at the appropriate code modifications in
hotlist.c and hotlist.h. I added the option "Insert current &before"
so that now the 'a' key appends and the 'b' key inserts the current
directory before the selected one. At the top by default if you don't
move the cursor position.

No problem. It works exactly as I want, except for 1 odd thing: 

l_hotlist->pos for some strange reason keeps getting decremented 
so that the current cursor pos in the hotlist ends up being the item 
*before* the inserted item.

I traced this to lib/widget/listbox.c. In listbox_append_item() 
we have these lines:

    case LISTBOX_APPEND_BEFORE:
        l->list = g_list_insert_before (l->list, g_list_nth (l->list, l->pos), e);
        if (l->pos > 0)
            l->pos--;
        break; 

Why do we decrement l->pos here? This doesn't seem right, and it's the 
culprit in this anomaly. If anything it should be incremented so as
to keep the cursor on the same list item it was on before the insert. 

With l->pos decrementing like this repeated calls to listbox_append_item() 
from the middle of a list make the new items appear every 2nd item 
alternating, working towards the beginning of the list, skipping one 
each time. The only places LISTBOX_APPEND_BEFORE appears is in 
dialog-switch.c:void dialog_switch_list (void) and hotlist.c. 

Anyway, I commented those 2 lines out of listbox_append_item() 
and now my mod works as it should, the cursor being left on the 
newly inserted item, not the one before it.

Any ideas?



[code]

--- src/filemanager/hotlist.h~  2013-12-01 08:33:45.000000000 -0800
+++ src/filemanager/hotlist.h   2013-12-01 08:48:46.000000000 -0800
@@ -22,6 +22,7 @@ typedef enum

 /*** declarations of public functions ************************************************************/

+void insert2hotlist_cmd (void);
 void add2hotlist_cmd (void);
 char *hotlist_show (hotlist_t list_type);
 gboolean save_hotlist (void);
--- src/filemanager/hotlist.c~  2013-08-02 08:02:39.000000000 -0700
+++ src/filemanager/hotlist.c   2013-12-01 15:34:51.353531859 -0800
@@ -89,6 +89,7 @@
 #define B_FREE_ALL_VFS  (B_USER + 9)
 #define B_REFRESH_VFS   (B_USER + 10)
 #endif
+#define B_INSERT_BEFORE (B_USER + 11)

 #define TKN_GROUP   0
 #define TKN_ENTRY   1
@@ -185,9 +186,11 @@ static struct
     { B_REFRESH_VFS, NORMAL_BUTTON, 0, 43, 0, N_("&Refresh"),
             LIST_VFSLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM },
 #endif
-    { B_ADD_CURRENT, NORMAL_BUTTON, 0, 20, 0, N_("&Add current"),
+    { B_INSERT_BEFORE, NORMAL_BUTTON, 0, 20, 0, N_("Insert current &before"),
             LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM },
-    { B_UP_GROUP, NORMAL_BUTTON, 0, 42, 0, N_("&Up"),
+    { B_ADD_CURRENT, NORMAL_BUTTON, 0, 35, 0, N_("&Append current"),
+            LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM },
+    { B_UP_GROUP, NORMAL_BUTTON, 0, 57, 0, N_("&Up"),
             LIST_HOTLIST | LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM },
     { B_CANCEL, NORMAL_BUTTON, 0, 53, 0, N_("&Cancel"),
             LIST_HOTLIST | LIST_VFSLIST | LIST_MOVELIST, WPOS_KEEP_RIGHT | WPOS_KEEP_BOTTOM },
@@ -424,6 +427,10 @@ hotlist_button_callback (WButton * butto
         add_new_group_cmd ();
         return 0;

+    case B_INSERT_BEFORE:
+        insert2hotlist_cmd ();
+        return 0;
+
     case B_ADD_CURRENT:
         add2hotlist_cmd ();
         return 0;
@@ -1561,6 +1568,39 @@ add_dotdot_to_list (void)
 /* --------------------------------------------------------------------------------------------- */

 void
+insert2hotlist_cmd (void)
+{
+    char *lc_prompt;
+    const char *cp = N_("Label for \"%s\":");
+    int l;
+    char *label_string, *label;
+
+#ifdef ENABLE_NLS
+    cp = _(cp);
+#endif
+
+    l = str_term_width1 (cp);
+    label_string = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_PASSWORD);
+    lc_prompt = g_strdup_printf (cp, str_trunc (label_string, COLS - 2 * UX - (l + 8)));
+    label =
+        input_dialog (_("Insert to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string,
+                      INPUT_COMPLETE_NONE);
+    g_free (lc_prompt);
+
+    if (label == NULL || *label == '\0')
+    {
+        g_free (label_string);
+        g_free (label);
+    }
+    else
+    {
+        add2hotlist (label, label_string, HL_TYPE_ENTRY, LISTBOX_APPEND_BEFORE);
+        hotlist_state.modified = TRUE;
+    }
+}
+
+
+void
 add2hotlist_cmd (void)
 {
     char *lc_prompt;
--- lib/widget/listbox.c~       2013-12-01 15:26:56.053538768 -0800
+++ lib/widget/listbox.c        2013-12-01 11:20:28.000000000 -0800
@@ -336,8 +336,8 @@ listbox_append_item (WListbox * l, WLEnt

     case LISTBOX_APPEND_BEFORE:
         l->list = g_list_insert_before (l->list, g_list_nth (l->list, l->pos), e);
-        if (l->pos > 0)
-            l->pos--;
+//        if (l->pos > 0)
+//            l->pos--;
         break;

     case LISTBOX_APPEND_AFTER:

[/code]

-- 
Peace and Cheer


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]