2 Directory hotlist -- for the Midnight Commander
4 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5 2003, 2004, 2005, 2006, 2007, 2008, 2011
6 The Free Software Foundation, Inc.
10 Janne Kukonlehto, 1995
11 Andrej Borsenkow, 1996
14 Janne did the original Hotlist code, Andrej made the groupable
15 hotlist; the move hotlist and revamped the file format and made
18 This file is part of the Midnight Commander.
20 The Midnight Commander is free software: you can redistribute it
21 and/or modify it under the terms of the GNU General Public License as
22 published by the Free Software Foundation, either version 3 of the License,
23 or (at your option) any later version.
25 The Midnight Commander is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
30 You should have received a copy of the GNU General Public License
31 along with this program. If not, see <http://www.gnu.org/licenses/>.
35 * \brief Source: directory hotlist
43 #include <sys/types.h>
47 #include "lib/global.h"
49 #include "lib/tty/tty.h" /* COLS */
50 #include "lib/tty/key.h" /* KEY_M_CTRL */
51 #include "lib/skin.h" /* colors */
52 #include "lib/mcconfig.h" /* Load/save directories hotlist */
53 #include "lib/fileloc.h"
54 #include "lib/strutil.h"
55 #include "lib/vfs/vfs.h"
57 #include "lib/widget.h"
59 #include "src/setup.h" /* For profile_bname */
60 #include "src/history.h"
62 #include "midnight.h" /* current_panel */
63 #include "command.h" /* cmdline */
67 /*** global variables ****************************************************************************/
69 int hotlist_has_dot_dot
= 1;
71 /*** file scope macro definitions ****************************************************************/
77 #define BY (LINES - 6)
79 #define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but))
81 #define B_ADD_CURRENT B_USER
82 #define B_REMOVE (B_USER + 1)
83 #define B_NEW_GROUP (B_USER + 2)
84 #define B_NEW_ENTRY (B_USER + 3)
85 #define B_UP_GROUP (B_USER + 4)
86 #define B_INSERT (B_USER + 5)
87 #define B_APPEND (B_USER + 6)
88 #define B_MOVE (B_USER + 7)
91 #define B_FREE_ALL_VFS (B_USER + 8)
92 #define B_REFRESH_VFS (B_USER + 9)
95 #define new_hotlist() g_new0(struct hotlist, 1)
97 #define CHECK_BUFFER \
101 i = strlen (current->label); \
102 if (i + 3 > buflen) { \
104 buflen = 1024 * (i/1024 + 1); \
105 buf = g_malloc (buflen); \
114 #define TKN_ENDGROUP 4
115 #define TKN_COMMENT 5
118 #define TKN_UNKNOWN 127
120 #define SKIP_TO_EOL \
123 while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
126 #define CHECK_TOKEN(_TKN_) \
127 tkn = hot_next_token (); \
130 hotlist_state.readonly = 1; \
131 hotlist_state.file_error = 1; \
132 while (tkn != TKN_EOL && tkn != TKN_EOF) \
133 tkn = hot_next_token (); \
137 /*** file scope type declarations ****************************************************************/
150 * these parameters are intended to be user configurable
152 int expanded
; /* expanded view of all groups at startup */
155 * these reflect run time state
158 int loaded
; /* hotlist is loaded */
159 int readonly
; /* hotlist readonly */
160 int file_error
; /* parse error while reading file */
161 int running
; /* we are running dlg (and have to
163 int moving
; /* we are in moving hotlist currently */
164 int modified
; /* hotlist was modified */
165 int type
; /* LIST_HOTLIST || LIST_VFSLIST */
168 /* Directory hotlist */
171 enum HotListType type
;
174 struct hotlist
*head
;
176 struct hotlist
*next
;
179 /*** file scope variables ************************************************************************/
181 static WListbox
*l_hotlist
;
182 static WListbox
*l_movelist
;
184 static Dlg_head
*hotlist_dlg
;
185 static Dlg_head
*movelist_dlg
;
187 static WLabel
*pname
, *pname_group
, *movelist_group
;
189 static struct _hotlist_but
191 int ret_cmd
, flags
, y
, x
;
194 widget_pos_flags_t pos_flags
;
198 { B_MOVE
, NORMAL_BUTTON
, 1, 42, N_("&Move"), LIST_HOTLIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
199 { B_REMOVE
, NORMAL_BUTTON
, 1, 30, N_("&Remove"),
200 LIST_HOTLIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
201 { B_APPEND
, NORMAL_BUTTON
, 1, 15, N_("&Append"),
202 LIST_MOVELIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
203 { B_INSERT
, NORMAL_BUTTON
, 1, 0, N_("&Insert"),
204 LIST_MOVELIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
205 { B_NEW_ENTRY
, NORMAL_BUTTON
, 1, 15, N_("New &entry"),
206 LIST_HOTLIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
207 { B_NEW_GROUP
, NORMAL_BUTTON
, 1, 0, N_("New &group"),
208 LIST_HOTLIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
209 { B_CANCEL
, NORMAL_BUTTON
, 0, 53, N_("&Cancel"),
210 LIST_HOTLIST
| LIST_VFSLIST
| LIST_MOVELIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
211 { B_UP_GROUP
, NORMAL_BUTTON
, 0, 42, N_("&Up"),
212 LIST_HOTLIST
| LIST_MOVELIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
213 { B_ADD_CURRENT
, NORMAL_BUTTON
, 0, 20, N_("&Add current"),
214 LIST_HOTLIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
216 { B_REFRESH_VFS
, NORMAL_BUTTON
, 0, 43, N_("&Refresh"),
217 LIST_VFSLIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
218 { B_FREE_ALL_VFS
, NORMAL_BUTTON
, 0, 20, N_("Fr&ee VFSs now"),
219 LIST_VFSLIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
},
221 { B_ENTER
, DEFPUSH_BUTTON
, 0, 0, N_("Change &to"),
222 LIST_HOTLIST
| LIST_VFSLIST
| LIST_MOVELIST
, WPOS_KEEP_LEFT
| WPOS_KEEP_BOTTOM
}
226 static struct hotlist
*hotlist
= NULL
;
228 static struct hotlist
*current_group
;
230 static GString
*tkn_buf
= NULL
;
232 static char *hotlist_file_name
;
233 static FILE *hotlist_file
;
234 static time_t hotlist_file_mtime
;
236 static int list_level
= 0;
238 /*** file scope functions ************************************************************************/
239 /* --------------------------------------------------------------------------------------------- */
241 static void init_movelist (int, struct hotlist
*);
242 static void add_new_group_cmd (void);
243 static void add_new_entry_cmd (void);
244 static void remove_from_hotlist (struct hotlist
*entry
);
245 static void load_hotlist (void);
246 static void add_dotdot_to_list (void);
248 /* --------------------------------------------------------------------------------------------- */
251 hotlist_refresh (Dlg_head
* dlg
)
253 /* TODO: use groupboxes here */
254 common_dialog_repaint (dlg
);
255 tty_setcolor (COLOR_NORMAL
);
256 draw_box (dlg
, 2, 5, dlg
->lines
- (hotlist_state
.moving
? 6 : 10), dlg
->cols
- (UX
* 2), TRUE
);
257 if (!hotlist_state
.moving
)
258 draw_box (dlg
, dlg
->lines
- 8, 5, 3, dlg
->cols
- (UX
* 2), TRUE
);
261 /* --------------------------------------------------------------------------------------------- */
262 /** If current->data is 0, then we are dealing with a VFS pathname */
265 update_path_name (void)
267 const char *text
= "";
269 WListbox
*list
= hotlist_state
.moving
? l_movelist
: l_hotlist
;
270 Dlg_head
*dlg
= list
->widget
.owner
;
272 if (list
->count
!= 0)
277 listbox_get_current (list
, &ctext
, &cdata
);
282 struct hotlist
*hlp
= (struct hotlist
*) cdata
;
284 if (hlp
->type
== HL_TYPE_ENTRY
|| hlp
->type
== HL_TYPE_DOTDOT
)
285 text
= hlp
->directory
;
286 else if (hlp
->type
== HL_TYPE_GROUP
)
287 text
= _("Subgroup - press ENTER to see list");
290 if (!hotlist_state
.moving
)
291 label_set_text (pname
, str_trunc (text
, dlg
->cols
- (UX
* 2 + 4)));
293 p
= g_strconcat (" ", current_group
->label
, " ", (char *) NULL
);
294 if (!hotlist_state
.moving
)
295 label_set_text (pname_group
, str_trunc (p
, dlg
->cols
- (UX
* 2 + 4)));
297 label_set_text (movelist_group
, str_trunc (p
, dlg
->cols
- (UX
* 2 + 4)));
303 /* --------------------------------------------------------------------------------------------- */
308 struct hotlist
*current
= current_group
->head
;
309 GString
*buff
= g_string_new ("");
313 switch (current
->type
)
318 g_string_truncate (buff
, 0);
319 g_string_append (buff
, "->");
320 g_string_append (buff
, current
->label
);
321 if (hotlist_state
.moving
)
322 listbox_add_item (l_movelist
, LISTBOX_APPEND_AT_END
, 0, buff
->str
, current
);
324 listbox_add_item (l_hotlist
, LISTBOX_APPEND_AT_END
, 0, buff
->str
, current
);
329 if (hotlist_state
.moving
)
330 listbox_add_item (l_movelist
, LISTBOX_APPEND_AT_END
, 0, current
->label
, current
);
332 listbox_add_item (l_hotlist
, LISTBOX_APPEND_AT_END
, 0, current
->label
, current
);
337 current
= current
->next
;
339 g_string_free (buff
, TRUE
);
342 /* --------------------------------------------------------------------------------------------- */
345 unlink_entry (struct hotlist
*entry
)
347 struct hotlist
*current
= current_group
->head
;
349 if (current
== entry
)
350 current_group
->head
= entry
->next
;
353 while (current
&& current
->next
!= entry
)
354 current
= current
->next
;
356 current
->next
= entry
->next
;
358 entry
->next
= entry
->up
= 0;
361 /* --------------------------------------------------------------------------------------------- */
365 add_name_to_list (const char *path
)
367 listbox_add_item (l_hotlist
, LISTBOX_APPEND_AT_END
, 0, path
, 0);
369 #endif /* !ENABLE_VFS */
371 /* --------------------------------------------------------------------------------------------- */
374 hotlist_button_callback (WButton
* button
, int action
)
382 struct hotlist
*saved
= current_group
;
383 struct hotlist
*item
= NULL
;
384 struct hotlist
*moveto_item
= NULL
;
385 struct hotlist
*moveto_group
= NULL
;
388 if (l_hotlist
->count
== 0)
389 return MSG_NOT_HANDLED
; /* empty group - nothing to do */
391 listbox_get_current (l_hotlist
, NULL
, (void **) &item
);
392 hotlist_state
.moving
= 1;
393 init_movelist (LIST_MOVELIST
, item
);
395 ret
= run_dlg (movelist_dlg
);
397 hotlist_state
.moving
= 0;
398 listbox_get_current (l_movelist
, NULL
, (void **) &moveto_item
);
399 moveto_group
= current_group
;
400 destroy_dlg (movelist_dlg
);
401 current_group
= saved
;
403 return MSG_NOT_HANDLED
;
404 if (moveto_item
== item
)
405 return MSG_NOT_HANDLED
; /* If we insert/append a before/after a
406 it hardly changes anything ;) */
408 listbox_remove_current (l_hotlist
);
409 item
->up
= moveto_group
;
410 if (!moveto_group
->head
)
411 moveto_group
->head
= item
;
412 else if (!moveto_item
)
413 { /* we have group with just comments */
414 struct hotlist
*p
= moveto_group
->head
;
421 else if (ret
== B_ENTER
|| ret
== B_APPEND
)
422 if (!moveto_item
->next
)
423 moveto_item
->next
= item
;
426 item
->next
= moveto_item
->next
;
427 moveto_item
->next
= item
;
429 else if (moveto_group
->head
== moveto_item
)
431 moveto_group
->head
= item
;
432 item
->next
= moveto_item
;
436 struct hotlist
*p
= moveto_group
->head
;
438 while (p
->next
!= moveto_item
)
440 item
->next
= p
->next
;
443 listbox_remove_list (l_hotlist
);
446 hotlist_state
.modified
= 1;
447 return MSG_NOT_HANDLED
;
451 struct hotlist
*entry
= NULL
;
452 listbox_get_current (l_hotlist
, NULL
, (void **) &entry
);
453 remove_from_hotlist (entry
);
455 return MSG_NOT_HANDLED
;
458 add_new_group_cmd ();
459 return MSG_NOT_HANDLED
;
463 return MSG_NOT_HANDLED
;
466 add_new_entry_cmd ();
467 return MSG_NOT_HANDLED
;
475 list
= hotlist_state
.moving
? l_movelist
: l_hotlist
;
476 listbox_get_current (list
, NULL
, &data
);
481 hlp
= (struct hotlist
*) data
;
483 if (hlp
->type
== HL_TYPE_ENTRY
)
485 if (hlp
->type
!= HL_TYPE_DOTDOT
)
487 listbox_remove_list (list
);
490 return MSG_NOT_HANDLED
;
492 /* Fall through - go up */
494 /* Fall through if list empty - just go up */
498 WListbox
*list
= hotlist_state
.moving
? l_movelist
: l_hotlist
;
499 listbox_remove_list (list
);
500 current_group
= current_group
->up
;
502 return MSG_NOT_HANDLED
;
511 listbox_remove_list (l_hotlist
);
512 listbox_add_item (l_hotlist
, LISTBOX_APPEND_AT_END
, 0, mc_config_get_home_dir (), 0);
513 vfs_fill_names (add_name_to_list
);
514 return MSG_NOT_HANDLED
;
515 #endif /* ENABLE_VFS */
522 /* --------------------------------------------------------------------------------------------- */
524 static inline cb_ret_t
525 hotlist_handle_key (Dlg_head
* h
, int key
)
529 case KEY_M_CTRL
| '\n':
535 if (hotlist_button_callback (NULL
, B_ENTER
))
537 h
->ret_value
= B_ENTER
;
543 if (hotlist_state
.type
!= LIST_VFSLIST
)
544 return !hotlist_button_callback (NULL
, B_UP_GROUP
);
546 return MSG_NOT_HANDLED
;
549 if (hotlist_state
.moving
)
550 return MSG_NOT_HANDLED
;
553 hotlist_button_callback (NULL
, B_REMOVE
);
560 if (!hotlist_state
.moving
)
564 listbox_get_current (l_hotlist
, NULL
, &ldata
);
568 struct hotlist
*hlp
= (struct hotlist
*) ldata
;
570 if (hlp
->type
== HL_TYPE_ENTRY
)
574 tmp
= g_strconcat ("cd ", hlp
->directory
, (char *) NULL
);
575 input_insert (cmdline
, tmp
, FALSE
);
577 h
->ret_value
= B_CANCEL
;
582 return MSG_HANDLED
; /* ignore key */
585 return MSG_NOT_HANDLED
;
589 /* --------------------------------------------------------------------------------------------- */
592 hotlist_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
600 case DLG_UNHANDLED_KEY
:
601 return hotlist_handle_key (h
, parm
);
604 if (hotlist_state
.moving
)
605 dlg_select_widget (l_movelist
);
607 dlg_select_widget (l_hotlist
);
608 /* always stay on hotlist */
612 tty_setcolor (MENU_ENTRY_COLOR
);
617 /* simply call dlg_set_size() with new size */
618 dlg_set_size (h
, LINES
- 2, COLS
- 6);
622 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
626 /* --------------------------------------------------------------------------------------------- */
629 l_call (WListbox
* list
)
631 Dlg_head
*dlg
= list
->widget
.owner
;
633 if (list
->count
!= 0)
637 listbox_get_current (list
, NULL
, &data
);
641 struct hotlist
*hlp
= (struct hotlist
*) data
;
642 if (hlp
->type
== HL_TYPE_ENTRY
)
644 dlg
->ret_value
= B_ENTER
;
650 hotlist_button_callback (NULL
, B_ENTER
);
651 hotlist_callback (dlg
, NULL
, DLG_POST_KEY
, '\n', NULL
);
657 dlg
->ret_value
= B_ENTER
;
663 hotlist_button_callback (NULL
, B_UP_GROUP
);
664 hotlist_callback (dlg
, NULL
, DLG_POST_KEY
, 'u', NULL
);
668 /* --------------------------------------------------------------------------------------------- */
670 * Expands all button names (once) and recalculates button positions.
671 * returns number of columns in the dialog box, which is 10 chars longer
674 * If common width of the window (i.e. in xterm) is less than returned
675 * width - sorry :) (anyway this did not handled in previous version too)
679 init_i18n_stuff (int list_type
, int cols
)
682 static const char *cancel_but
= N_("&Cancel");
685 static int hotlist_i18n_flag
= 0;
687 if (!hotlist_i18n_flag
)
689 i
= sizeof (hotlist_but
) / sizeof (hotlist_but
[0]);
691 hotlist_but
[i
].text
= _(hotlist_but
[i
].text
);
693 cancel_but
= _(cancel_but
);
694 hotlist_i18n_flag
= 1;
696 #endif /* ENABLE_NLS */
698 /* Dynamic resizing of buttonbars */
700 int len
[2], count
[2]; /* at most two lines of buttons */
703 i
= sizeof (hotlist_but
) / sizeof (hotlist_but
[0]);
704 len
[0] = len
[1] = count
[0] = count
[1] = 0;
706 /* Count len of buttonbars, assuming 2 extra space between buttons */
709 if (!(hotlist_but
[i
].type
& list_type
))
712 row
= hotlist_but
[i
].y
;
714 len
[row
] += str_term_width1 (hotlist_but
[i
].text
) + 5;
715 if (hotlist_but
[i
].flags
== DEFPUSH_BUTTON
)
721 cols
= max (cols
, max (len
[0], len
[1]));
723 /* arrange buttons */
725 cur_x
[0] = cur_x
[1] = 0;
726 i
= sizeof (hotlist_but
) / sizeof (hotlist_but
[0]);
729 if (!(hotlist_but
[i
].type
& list_type
))
732 row
= hotlist_but
[i
].y
;
734 if (hotlist_but
[i
].x
!= 0)
736 /* not first int the row */
737 if (!strcmp (hotlist_but
[i
].text
, cancel_but
))
738 hotlist_but
[i
].x
= cols
- str_term_width1 (hotlist_but
[i
].text
) - 13;
740 hotlist_but
[i
].x
= cur_x
[row
];
743 cur_x
[row
] += str_term_width1 (hotlist_but
[i
].text
) + 2
744 + (hotlist_but
[i
].flags
== DEFPUSH_BUTTON
? 5 : 3);
751 /* --------------------------------------------------------------------------------------------- */
754 init_hotlist (int list_type
)
757 const char *title
, *help_node
;
760 hotlist_cols
= init_i18n_stuff (list_type
, COLS
- 6);
764 hotlist_state
.expanded
=
765 mc_config_get_int (mc_main_config
, "HotlistConfig", "expanded_view_of_groups", 0);
767 if (list_type
== LIST_VFSLIST
)
769 title
= _("Active VFS directories");
770 help_node
= "[vfshot]"; /* FIXME - no such node */
774 title
= _("Directory hotlist");
775 help_node
= "[Hotlist]";
779 create_dlg (TRUE
, 0, 0, LINES
- 2, hotlist_cols
, dialog_colors
,
780 hotlist_callback
, help_node
, title
, DLG_CENTER
| DLG_REVERSE
);
782 for (i
= 0; i
< BUTTONS
; i
++)
784 if (hotlist_but
[i
].type
& list_type
)
785 add_widget_autopos (hotlist_dlg
,
786 button_new (BY
+ hotlist_but
[i
].y
,
787 BX
+ hotlist_but
[i
].x
,
788 hotlist_but
[i
].ret_cmd
,
789 hotlist_but
[i
].flags
,
791 hotlist_button_callback
), hotlist_but
[i
].pos_flags
);
794 /* We add the labels.
795 * pname will hold entry's pathname;
796 * pname_group will hold name of current group
798 pname
= label_new (UY
- 11 + LINES
, UX
+ 2, "");
799 add_widget_autopos (hotlist_dlg
, pname
, WPOS_KEEP_BOTTOM
| WPOS_KEEP_LEFT
);
800 if (!hotlist_state
.moving
)
802 char label_text
[BUF_TINY
];
804 g_snprintf (label_text
, sizeof (label_text
), " %s ", _("Directory path"));
805 add_widget_autopos (hotlist_dlg
,
806 label_new (UY
- 12 + LINES
, UX
+ 2,
807 label_text
), WPOS_KEEP_BOTTOM
| WPOS_KEEP_LEFT
);
809 /* This one holds the displayed pathname */
810 pname_group
= label_new (UY
, UX
+ 2, _("Directory label"));
811 add_widget (hotlist_dlg
, pname_group
);
813 /* get new listbox */
814 l_hotlist
= listbox_new (UY
+ 1, UX
+ 1, LINES
- 14, COLS
- 2 * UX
- 8, FALSE
, l_call
);
816 /* Fill the hotlist with the active VFS or the hotlist */
818 if (list_type
== LIST_VFSLIST
)
820 listbox_add_item (l_hotlist
, LISTBOX_APPEND_AT_END
, 0, mc_config_get_home_dir (), 0);
821 vfs_fill_names (add_name_to_list
);
824 #endif /* !ENABLE_VFS */
827 add_widget_autopos (hotlist_dlg
, l_hotlist
, WPOS_KEEP_ALL
);
828 /* add listbox to the dialogs */
831 /* --------------------------------------------------------------------------------------------- */
834 init_movelist (int list_type
, struct hotlist
*item
)
837 char *hdr
= g_strdup_printf (_("Moving %s"), item
->label
);
838 int movelist_cols
= init_i18n_stuff (list_type
, COLS
- 6);
843 create_dlg (TRUE
, 0, 0, LINES
- 6, movelist_cols
, dialog_colors
,
844 hotlist_callback
, "[Hotlist]", hdr
, DLG_CENTER
| DLG_REVERSE
);
847 for (i
= 0; i
< BUTTONS
; i
++)
849 if (hotlist_but
[i
].type
& list_type
)
850 add_widget (movelist_dlg
,
851 button_new (BY
- 4 + hotlist_but
[i
].y
,
852 BX
+ hotlist_but
[i
].x
,
853 hotlist_but
[i
].ret_cmd
,
854 hotlist_but
[i
].flags
,
855 hotlist_but
[i
].text
, hotlist_button_callback
));
858 /* We add the labels. We are interested in the last one,
859 * that one will hold the path name label
861 movelist_group
= label_new (UY
, UX
+ 2, _("Directory label"));
862 add_widget (movelist_dlg
, movelist_group
);
863 /* get new listbox */
865 listbox_new (UY
+ 1, UX
+ 1, movelist_dlg
->lines
- 8,
866 movelist_dlg
->cols
- 2 * UX
- 2, FALSE
, l_call
);
870 add_widget (movelist_dlg
, l_movelist
);
871 /* add listbox to the dialogs */
874 /* --------------------------------------------------------------------------------------------- */
876 * Destroy the list dialog.
877 * Don't confuse with done_hotlist() for the list in memory.
883 destroy_dlg (hotlist_dlg
);
886 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
890 /* --------------------------------------------------------------------------------------------- */
893 find_group_section (struct hotlist
*grp
)
895 return g_strconcat (grp
->directory
, ".Group", (char *) NULL
);
898 /* --------------------------------------------------------------------------------------------- */
900 static struct hotlist
*
901 add2hotlist (char *label
, char *directory
, enum HotListType type
, listbox_append_t pos
)
904 struct hotlist
*current
= NULL
;
907 * Hotlist is neither loaded nor loading.
908 * Must be called by "Ctrl-x a" before using hotlist.
913 listbox_get_current (l_hotlist
, NULL
, (void **) ¤t
);
915 /* Make sure `..' stays at the top of the list. */
916 if ((current
!= NULL
) && (current
->type
== HL_TYPE_DOTDOT
))
917 pos
= LISTBOX_APPEND_AFTER
;
919 new = new_hotlist ();
923 new->directory
= directory
;
924 new->up
= current_group
;
926 if (type
== HL_TYPE_GROUP
)
929 add_dotdot_to_list ();
930 current_group
= new->up
;
933 if (!current_group
->head
)
935 /* first element in group */
936 current_group
->head
= new;
938 else if (pos
== LISTBOX_APPEND_AFTER
)
940 new->next
= current
->next
;
943 else if (pos
== LISTBOX_APPEND_BEFORE
&& current
== current_group
->head
)
945 /* should be inserted before first item */
947 current_group
->head
= new;
949 else if (pos
== LISTBOX_APPEND_BEFORE
)
951 struct hotlist
*p
= current_group
->head
;
953 while (p
->next
!= current
)
960 { /* append at the end */
961 struct hotlist
*p
= current_group
->head
;
969 if (hotlist_state
.running
&& type
!= HL_TYPE_COMMENT
&& type
!= HL_TYPE_DOTDOT
)
971 if (type
== HL_TYPE_GROUP
)
973 char *lbl
= g_strconcat ("->", new->label
, (char *) NULL
);
975 listbox_add_item (l_hotlist
, pos
, 0, lbl
, new);
979 listbox_add_item (l_hotlist
, pos
, 0, new->label
, new);
980 listbox_select_entry (l_hotlist
, l_hotlist
->pos
);
986 /* --------------------------------------------------------------------------------------------- */
988 * Support routine for add_new_entry_input()/add_new_group_input()
989 * Change positions of buttons (first three widgets).
991 * This is just a quick hack. Accurate procedure must take care of
992 * internationalized label lengths and total buttonbar length...assume
993 * 64 is longer anyway.
998 add_widgets_i18n (QuickWidget
* qw
, int len
)
1000 int i
, l
[3], space
, cur_x
;
1002 for (i
= 0; i
< 3; i
++)
1004 qw
[i
].u
.button
.text
= _(qw
[i
].u
.button
.text
);
1005 l
[i
] = str_term_width1 (qw
[i
].u
.button
.text
) + 3;
1007 space
= (len
- 4 - l
[0] - l
[1] - l
[2]) / 4;
1009 for (cur_x
= 2 + space
, i
= 3; i
--; cur_x
+= l
[i
] + space
)
1011 qw
[i
].relative_x
= cur_x
;
1012 qw
[i
].x_divisions
= len
;
1015 #endif /* ENABLE_NLS */
1017 /* --------------------------------------------------------------------------------------------- */
1020 add_new_entry_input (const char *header
, const char *text1
, const char *text2
,
1021 const char *help
, char **r1
, char **r2
)
1023 #define RELATIVE_Y_BUTTONS 4
1024 #define RELATIVE_Y_LABEL_PTH 3
1025 #define RELATIVE_Y_INPUT_PTH 4
1027 QuickWidget quick_widgets
[] = {
1028 /* 0 */ QUICK_BUTTON (55, 80, RELATIVE_Y_BUTTONS
, 0, N_("&Cancel"), B_CANCEL
, NULL
),
1029 /* 1 */ QUICK_BUTTON (30, 80, RELATIVE_Y_BUTTONS
, 0, N_("&Insert"), B_INSERT
, NULL
),
1030 /* 2 */ QUICK_BUTTON (10, 80, RELATIVE_Y_BUTTONS
, 0, N_("&Append"), B_APPEND
, NULL
),
1031 /* 3 */ QUICK_INPUT (4, 80, RELATIVE_Y_INPUT_PTH
, 0, *r2
, 58, 2, "input-pth", r2
),
1032 /* 4 */ QUICK_LABEL (4, 80, 3, 0, text2
),
1033 /* 5 */ QUICK_INPUT (4, 80, 3, 0, *r1
, 58, 0, "input-lbl", r1
),
1034 /* 6 */ QUICK_LABEL (4, 80, 2, 0, text1
),
1044 static gboolean i18n_flag
= FALSE
;
1045 #endif /* ENABLE_NLS */
1047 len
= str_term_width1 (header
);
1048 str_msg_term_size (text1
, &lines1
, &cols1
);
1049 str_msg_term_size (text2
, &lines2
, &cols2
);
1050 len
= max (len
, cols1
);
1051 len
= max (max (len
, cols2
) + 4, 64);
1056 add_widgets_i18n (quick_widgets
, len
);
1059 #endif /* ENABLE_NLS */
1062 QuickDialog Quick_input
= {
1063 len
, lines1
+ lines2
+ 7, -1, -1, header
,
1064 help
, quick_widgets
, NULL
, FALSE
1067 for (i
= 0; i
< 7; i
++)
1068 quick_widgets
[i
].y_divisions
= Quick_input
.ylen
;
1070 quick_widgets
[0].relative_y
= RELATIVE_Y_BUTTONS
+ (lines1
+ lines2
);
1071 quick_widgets
[1].relative_y
= RELATIVE_Y_BUTTONS
+ (lines1
+ lines2
);
1072 quick_widgets
[2].relative_y
= RELATIVE_Y_BUTTONS
+ (lines1
+ lines2
);
1073 quick_widgets
[3].relative_y
= RELATIVE_Y_INPUT_PTH
+ (lines1
);
1074 quick_widgets
[4].relative_y
= RELATIVE_Y_LABEL_PTH
+ (lines1
);
1076 i
= quick_dialog (&Quick_input
);
1079 return (i
!= B_CANCEL
) ? i
: 0;
1081 #undef RELATIVE_Y_BUTTONS
1082 #undef RELATIVE_Y_LABEL_PTH
1083 #undef RELATIVE_Y_INPUT_PTH
1086 /* --------------------------------------------------------------------------------------------- */
1089 add_new_entry_cmd (void)
1091 char *title
, *url
, *to_free
;
1094 /* Take current directory as default value for input fields */
1095 to_free
= title
= url
= strip_password (g_strdup (current_panel
->cwd
), 1);
1097 ret
= add_new_entry_input (_("New hotlist entry"), _("Directory label:"),
1098 _("Directory path:"), "[Hotlist]", &title
, &url
);
1103 if (!title
|| !*title
|| !url
|| !*url
)
1110 if (ret
== B_ENTER
|| ret
== B_APPEND
)
1111 add2hotlist (title
, url
, HL_TYPE_ENTRY
, LISTBOX_APPEND_AFTER
);
1113 add2hotlist (title
, url
, HL_TYPE_ENTRY
, LISTBOX_APPEND_BEFORE
);
1115 hotlist_state
.modified
= 1;
1118 /* --------------------------------------------------------------------------------------------- */
1121 add_new_group_input (const char *header
, const char *label
, char **result
)
1123 QuickWidget quick_widgets
[] = {
1124 /* 0 */ QUICK_BUTTON (55, 80, 1, 0, N_("&Cancel"), B_CANCEL
, NULL
),
1125 /* 1 */ QUICK_BUTTON (30, 80, 1, 0, N_("&Insert"), B_INSERT
, NULL
),
1126 /* 2 */ QUICK_BUTTON (10, 80, 1, 0, N_("&Append"), B_APPEND
, NULL
),
1127 /* 3 */ QUICK_INPUT (4, 80, 0, 0, "", 58, 0, "input", result
),
1128 /* 4 */ QUICK_LABEL (4, 80, 2, 0, label
),
1138 static gboolean i18n_flag
= FALSE
;
1139 #endif /* ENABLE_NLS */
1141 len
= str_term_width1 (header
);
1142 str_msg_term_size (label
, &lines
, &cols
);
1143 len
= max (max (len
, cols
) + 4, 64);
1148 add_widgets_i18n (quick_widgets
, len
);
1151 #endif /* ENABLE_NLS */
1154 QuickDialog Quick_input
= {
1155 len
, lines
+ 6, -1, -1, header
,
1156 "[Hotlist]", quick_widgets
, NULL
, FALSE
1159 int relative_y
[] = { 1, 1, 1, 0, 2 }; /* the relative_x component from the
1160 quick_widgets variable above */
1162 for (i
= 0; i
< 5; i
++)
1163 quick_widgets
[i
].y_divisions
= Quick_input
.ylen
;
1165 for (i
= 0; i
< 4; i
++)
1166 quick_widgets
[i
].relative_y
= relative_y
[i
] + 2 + lines
;
1168 ret
= quick_dialog (&Quick_input
);
1171 return (ret
!= B_CANCEL
) ? ret
: 0;
1174 /* --------------------------------------------------------------------------------------------- */
1177 add_new_group_cmd (void)
1182 ret
= add_new_group_input (_("New hotlist group"), _("Name of new group:"), &label
);
1183 if (!ret
|| !label
|| !*label
)
1186 if (ret
== B_ENTER
|| ret
== B_APPEND
)
1187 add2hotlist (label
, 0, HL_TYPE_GROUP
, LISTBOX_APPEND_AFTER
);
1189 add2hotlist (label
, 0, HL_TYPE_GROUP
, LISTBOX_APPEND_BEFORE
);
1191 hotlist_state
.modified
= 1;
1194 /* --------------------------------------------------------------------------------------------- */
1197 remove_group (struct hotlist
*grp
)
1199 struct hotlist
*current
= grp
->head
;
1203 struct hotlist
*next
= current
->next
;
1205 if (current
->type
== HL_TYPE_GROUP
)
1206 remove_group (current
);
1208 g_free (current
->label
);
1209 g_free (current
->directory
);
1217 /* --------------------------------------------------------------------------------------------- */
1220 remove_from_hotlist (struct hotlist
*entry
)
1225 if (entry
->type
== HL_TYPE_DOTDOT
)
1228 if (confirm_directory_hotlist_delete
)
1233 title
= g_strconcat (_("Remove:"), " ", str_trunc (entry
->label
, 30), (char *) NULL
);
1237 result
= query_dialog (title
,
1238 _("Are you sure you want to remove this entry?"),
1239 D_ERROR
, 2, _("&Yes"), _("&No"));
1247 if (entry
->type
== HL_TYPE_GROUP
)
1249 struct hotlist
*head
= entry
->head
;
1251 if (head
!= NULL
&& (head
->type
!= HL_TYPE_DOTDOT
|| head
->next
!= NULL
))
1256 header
= g_strconcat (_("Remove:"), " ", str_trunc (entry
->label
, 30), (char *) NULL
);
1257 result
= query_dialog (header
, _("Group not empty.\nRemove it?"),
1258 D_ERROR
, 2, _("&Yes"), _("&No"));
1265 remove_group (entry
);
1268 unlink_entry (entry
);
1270 g_free (entry
->label
);
1271 g_free (entry
->directory
);
1273 /* now remove list entry from screen */
1274 listbox_remove_current (l_hotlist
);
1275 hotlist_state
.modified
= 1;
1278 /* --------------------------------------------------------------------------------------------- */
1281 load_group (struct hotlist
*grp
)
1283 gchar
**profile_keys
, **keys
;
1285 char *group_section
;
1286 struct hotlist
*current
= 0;
1288 group_section
= find_group_section (grp
);
1290 profile_keys
= keys
= mc_config_get_keys (mc_main_config
, group_section
, &len
);
1292 current_group
= grp
;
1294 while (*profile_keys
)
1296 add2hotlist (mc_config_get_string (mc_main_config
, group_section
, *profile_keys
, ""),
1297 g_strdup (*profile_keys
), HL_TYPE_GROUP
, LISTBOX_APPEND_AT_END
);
1300 g_free (group_section
);
1303 profile_keys
= keys
= mc_config_get_keys (mc_main_config
, grp
->directory
, &len
);
1305 while (*profile_keys
)
1307 add2hotlist (mc_config_get_string (mc_main_config
, group_section
, *profile_keys
, ""),
1308 g_strdup (*profile_keys
), HL_TYPE_ENTRY
, LISTBOX_APPEND_AT_END
);
1313 for (current
= grp
->head
; current
; current
= current
->next
)
1314 load_group (current
);
1317 /* --------------------------------------------------------------------------------------------- */
1320 hot_skip_blanks (void)
1324 while ((c
= getc (hotlist_file
)) != EOF
&& c
!= '\n' && g_ascii_isspace (c
))
1330 /* --------------------------------------------------------------------------------------------- */
1333 hot_next_token (void)
1339 if (tkn_buf
== NULL
)
1340 tkn_buf
= g_string_new ("");
1341 g_string_set_size (tkn_buf
, 0);
1344 c
= hot_skip_blanks ();
1354 while ((c
= getc (hotlist_file
)) != EOF
&& c
!= '\n')
1356 g_string_append_c (tkn_buf
, c
);
1361 while ((c
= getc (hotlist_file
)) != EOF
&& c
!= '"')
1365 c
= getc (hotlist_file
);
1368 g_string_free (tkn_buf
, TRUE
);
1372 g_string_append_c (tkn_buf
, c
== '\n' ? ' ' : c
);
1380 c
= getc (hotlist_file
);
1383 g_string_free (tkn_buf
, TRUE
);
1389 /* fall through; it is taken as normal character */
1394 g_string_append_c (tkn_buf
, g_ascii_toupper (c
));
1396 while ((c
= fgetc (hotlist_file
)) != EOF
&& (g_ascii_isalnum (c
) || !isascii (c
)));
1398 ungetc (c
, hotlist_file
);
1400 if (strncmp (tkn_buf
->str
, "GROUP", l
) == 0)
1402 else if (strncmp (tkn_buf
->str
, "ENTRY", l
) == 0)
1404 else if (strncmp (tkn_buf
->str
, "ENDGROUP", l
) == 0)
1406 else if (strncmp (tkn_buf
->str
, "URL", l
) == 0)
1415 /* --------------------------------------------------------------------------------------------- */
1418 hot_load_group (struct hotlist
*grp
)
1421 struct hotlist
*new_grp
;
1424 current_group
= grp
;
1426 while ((tkn
= hot_next_token ()) != TKN_ENDGROUP
)
1430 CHECK_TOKEN (TKN_STRING
);
1432 add2hotlist (g_strdup (tkn_buf
->str
), 0, HL_TYPE_GROUP
, LISTBOX_APPEND_AT_END
);
1434 hot_load_group (new_grp
);
1435 current_group
= grp
;
1440 CHECK_TOKEN (TKN_STRING
);
1441 label
= g_strdup (tkn_buf
->str
);
1442 CHECK_TOKEN (TKN_URL
);
1443 CHECK_TOKEN (TKN_STRING
);
1444 vpath
= vfs_path_from_str_flags (tkn_buf
->str
, VPF_USE_DEPRECATED_PARSER
);
1445 url
= vfs_path_to_str (vpath
);
1446 vfs_path_free (vpath
);
1447 add2hotlist (label
, url
, HL_TYPE_ENTRY
, LISTBOX_APPEND_AT_END
);
1452 label
= g_strdup (tkn_buf
->str
);
1453 add2hotlist (label
, 0, HL_TYPE_COMMENT
, LISTBOX_APPEND_AT_END
);
1456 hotlist_state
.readonly
= 1;
1457 hotlist_state
.file_error
= 1;
1461 /* skip empty lines */
1464 hotlist_state
.readonly
= 1;
1465 hotlist_state
.file_error
= 1;
1472 /* --------------------------------------------------------------------------------------------- */
1475 hot_load_file (struct hotlist
*grp
)
1478 struct hotlist
*new_grp
;
1481 current_group
= grp
;
1483 while ((tkn
= hot_next_token ()) != TKN_EOF
)
1487 CHECK_TOKEN (TKN_STRING
);
1489 add2hotlist (g_strdup (tkn_buf
->str
), 0, HL_TYPE_GROUP
, LISTBOX_APPEND_AT_END
);
1491 hot_load_group (new_grp
);
1492 current_group
= grp
;
1497 CHECK_TOKEN (TKN_STRING
);
1498 label
= g_strdup (tkn_buf
->str
);
1499 CHECK_TOKEN (TKN_URL
);
1500 CHECK_TOKEN (TKN_STRING
);
1501 vpath
= vfs_path_from_str_flags (tkn_buf
->str
, VPF_USE_DEPRECATED_PARSER
);
1502 url
= vfs_path_to_str (vpath
);
1503 vfs_path_free (vpath
);
1504 add2hotlist (label
, url
, HL_TYPE_ENTRY
, LISTBOX_APPEND_AT_END
);
1509 label
= g_strdup (tkn_buf
->str
);
1510 add2hotlist (label
, 0, HL_TYPE_COMMENT
, LISTBOX_APPEND_AT_END
);
1513 /* skip empty lines */
1516 hotlist_state
.readonly
= 1;
1517 hotlist_state
.file_error
= 1;
1523 /* --------------------------------------------------------------------------------------------- */
1526 clean_up_hotlist_groups (const char *section
)
1529 gchar
**profile_keys
, **keys
;
1532 grp_section
= g_strconcat (section
, ".Group", (char *) NULL
);
1533 if (mc_config_has_group (mc_main_config
, section
))
1534 mc_config_del_group (mc_main_config
, section
);
1536 if (mc_config_has_group (mc_main_config
, grp_section
))
1538 profile_keys
= keys
= mc_config_get_keys (mc_main_config
, grp_section
, &len
);
1540 while (*profile_keys
)
1542 clean_up_hotlist_groups (*profile_keys
);
1546 mc_config_del_group (mc_main_config
, grp_section
);
1548 g_free (grp_section
);
1551 /* --------------------------------------------------------------------------------------------- */
1556 int remove_old_list
= 0;
1557 struct stat stat_buf
;
1559 if (hotlist_state
.loaded
)
1561 stat (hotlist_file_name
, &stat_buf
);
1562 if (hotlist_file_mtime
< stat_buf
.st_mtime
)
1568 if (!hotlist_file_name
)
1569 hotlist_file_name
= mc_config_get_full_path (MC_HOTLIST_FILE
);
1571 hotlist
= new_hotlist ();
1572 hotlist
->type
= HL_TYPE_GROUP
;
1573 hotlist
->label
= g_strdup (_("Top level group"));
1574 hotlist
->up
= hotlist
;
1578 hotlist
->directory
= g_strdup ("Hotlist");
1580 hotlist_file
= fopen (hotlist_file_name
, "r");
1581 if (hotlist_file
== NULL
)
1585 load_group (hotlist
);
1586 hotlist_state
.loaded
= 1;
1588 * just to be sure we got copy
1590 hotlist_state
.modified
= 1;
1591 result
= save_hotlist ();
1592 hotlist_state
.modified
= 0;
1594 remove_old_list
= 1;
1596 message (D_ERROR
, _("Hotlist Load"),
1598 ("MC was unable to write %s file,\nyour old hotlist entries were not deleted"),
1599 MC_USERCONF_DIR PATH_SEP_STR MC_HOTLIST_FILE
);
1603 hot_load_file (hotlist
);
1604 fclose (hotlist_file
);
1605 hotlist_state
.loaded
= 1;
1608 if (remove_old_list
)
1610 GError
*error
= NULL
;
1611 clean_up_hotlist_groups ("Hotlist");
1612 if (!mc_config_save_file (mc_main_config
, &error
))
1613 setup_save_config_show_error (mc_main_config
->ini_path
, &error
);
1616 stat (hotlist_file_name
, &stat_buf
);
1617 hotlist_file_mtime
= stat_buf
.st_mtime
;
1618 current_group
= hotlist
;
1621 /* --------------------------------------------------------------------------------------------- */
1624 hot_save_group (struct hotlist
*grp
)
1626 struct hotlist
*current
= grp
->head
;
1632 for (i = 0; i < n; i++) \
1633 putc (' ', hotlist_file); \
1636 for (; current
; current
= current
->next
)
1637 switch (current
->type
)
1640 INDENT (list_level
);
1641 fputs ("GROUP \"", hotlist_file
);
1642 for (s
= current
->label
; *s
; s
++)
1644 if (*s
== '"' || *s
== '\\')
1645 putc ('\\', hotlist_file
);
1646 putc (*s
, hotlist_file
);
1648 fputs ("\"\n", hotlist_file
);
1650 hot_save_group (current
);
1652 INDENT (list_level
);
1653 fputs ("ENDGROUP\n", hotlist_file
);
1656 INDENT (list_level
);
1657 fputs ("ENTRY \"", hotlist_file
);
1658 for (s
= current
->label
; *s
; s
++)
1660 if (*s
== '"' || *s
== '\\')
1661 putc ('\\', hotlist_file
);
1662 putc (*s
, hotlist_file
);
1664 fputs ("\" URL \"", hotlist_file
);
1665 for (s
= current
->directory
; *s
; s
++)
1667 if (*s
== '"' || *s
== '\\')
1668 putc ('\\', hotlist_file
);
1669 putc (*s
, hotlist_file
);
1671 fputs ("\"\n", hotlist_file
);
1673 case HL_TYPE_COMMENT
:
1674 fprintf (hotlist_file
, "#%s\n", current
->label
);
1676 case HL_TYPE_DOTDOT
:
1682 /* --------------------------------------------------------------------------------------------- */
1685 add_dotdot_to_list (void)
1687 if (current_group
!= hotlist
)
1689 if (hotlist_has_dot_dot
!= 0)
1690 add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT
, LISTBOX_APPEND_AT_END
);
1694 /* --------------------------------------------------------------------------------------------- */
1695 /*** public functions ****************************************************************************/
1696 /* --------------------------------------------------------------------------------------------- */
1699 add2hotlist_cmd (void)
1701 char *lc_prompt
, *label
;
1702 const char *cp
= _("Label for \"%s\":");
1703 int l
= str_term_width1 (cp
);
1704 char *label_string
= g_strdup (current_panel
->cwd
);
1706 strip_password (label_string
, 1);
1708 lc_prompt
= g_strdup_printf (cp
, path_trunc (current_panel
->cwd
, COLS
- 2 * UX
- (l
+ 8)));
1709 label
= input_dialog (_("Add to hotlist"), lc_prompt
, MC_HISTORY_HOTLIST_ADD
, label_string
);
1712 if (!label
|| !*label
)
1714 g_free (label_string
);
1718 add2hotlist (label
, label_string
, HL_TYPE_ENTRY
, LISTBOX_APPEND_AT_END
);
1719 hotlist_state
.modified
= 1;
1722 /* --------------------------------------------------------------------------------------------- */
1725 hotlist_show (int vfs_or_hotlist
)
1727 char *target
= NULL
;
1729 hotlist_state
.type
= vfs_or_hotlist
;
1732 init_hotlist (vfs_or_hotlist
);
1734 /* display file info */
1735 tty_setcolor (SELECTED_COLOR
);
1737 hotlist_state
.running
= 1;
1738 run_dlg (hotlist_dlg
);
1739 hotlist_state
.running
= 0;
1742 switch (hotlist_dlg
->ret_value
)
1751 struct hotlist
*hlp
= NULL
;
1753 listbox_get_current (l_hotlist
, &text
, (void **) &hlp
);
1754 target
= g_strdup (hlp
!= NULL
? hlp
->directory
: text
);
1763 /* --------------------------------------------------------------------------------------------- */
1769 struct stat stat_buf
;
1771 if (!hotlist_state
.readonly
&& hotlist_state
.modified
&& hotlist_file_name
)
1773 mc_util_make_backup_if_possible (hotlist_file_name
, ".bak");
1775 hotlist_file
= fopen (hotlist_file_name
, "w");
1776 if (hotlist_file
!= NULL
)
1778 hot_save_group (hotlist
);
1779 fclose (hotlist_file
);
1780 stat (hotlist_file_name
, &stat_buf
);
1781 hotlist_file_mtime
= stat_buf
.st_mtime
;
1783 hotlist_state
.modified
= 0;
1786 mc_util_restore_from_backup_if_possible (hotlist_file_name
, ".bak");
1792 /* --------------------------------------------------------------------------------------------- */
1794 * Unload list from memory.
1795 * Don't confuse with hotlist_done() for GUI.
1803 remove_group (hotlist
);
1804 g_free (hotlist
->label
);
1805 g_free (hotlist
->directory
);
1810 hotlist_state
.loaded
= 0;
1812 g_free (hotlist_file_name
);
1813 hotlist_file_name
= 0;
1819 g_string_free (tkn_buf
, TRUE
);
1824 /* --------------------------------------------------------------------------------------------- */