1998-02-27 04:54:42 +00:00
|
|
|
/* Directory panel listing format editor -- for the Midnight Commander
|
2007-09-25 15:33:35 +00:00
|
|
|
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005,
|
|
|
|
2006, 2007 Free Software Foundation, Inc.
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
Written by: 1994 Radek Doulik
|
|
|
|
1995 Janne Kukonlehto
|
|
|
|
|
|
|
|
This program 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 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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, write to the Free Software
|
2005-05-27 03:35:10 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-02-27 04:54:42 +00:00
|
|
|
*/
|
|
|
|
|
2009-02-06 16:46:15 +02:00
|
|
|
/** \file listmode.c
|
2009-02-05 20:28:18 +02:00
|
|
|
* \brief Source: directory panel listing format editor
|
|
|
|
*/
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
#include <config.h>
|
2000-09-26 22:38:13 +00:00
|
|
|
|
|
|
|
#ifdef LISTMODE_EDITOR
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
#include <stdio.h>
|
2005-02-08 09:04:03 +00:00
|
|
|
#include <string.h>
|
2009-02-05 23:40:32 +01:00
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2005-02-08 09:04:03 +00:00
|
|
|
#include <unistd.h>
|
2001-09-07 17:52:19 +00:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
#include "global.h"
|
2001-09-07 17:52:19 +00:00
|
|
|
#include "tty.h"
|
2009-05-24 13:39:14 +04:00
|
|
|
#include "key.h"
|
1998-02-27 04:54:42 +00:00
|
|
|
#include "color.h"
|
2003-10-24 23:20:30 +00:00
|
|
|
#include "dialog.h"
|
1998-02-27 04:54:42 +00:00
|
|
|
#include "widget.h"
|
|
|
|
#include "wtools.h"
|
|
|
|
|
|
|
|
/* Needed for the extern declarations of integer parameters */
|
|
|
|
#include "dir.h"
|
|
|
|
#include "panel.h" /* Needed for the externs */
|
|
|
|
#include "file.h"
|
2009-07-19 19:00:26 +04:00
|
|
|
#include "layout.h" /* repaint_screen() */
|
1998-02-27 04:54:42 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "listmode.h"
|
|
|
|
|
|
|
|
#define UX 5
|
|
|
|
#define UY 2
|
|
|
|
|
|
|
|
#define BX 5
|
|
|
|
#define BY 18
|
|
|
|
|
|
|
|
#define B_ADD B_USER
|
2003-09-10 21:33:12 +00:00
|
|
|
#define B_REMOVE (B_USER + 1)
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
static WListbox *l_listmode;
|
|
|
|
|
|
|
|
static WLabel *pname;
|
|
|
|
|
|
|
|
static char *listmode_section = "[Listing format edit]";
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
static char *s_genwidth[2] = { "Half width", "Full width" };
|
|
|
|
static WRadio *radio_genwidth;
|
|
|
|
static char *s_columns[2] = { "One column", "Two columns" };
|
|
|
|
static WRadio *radio_columns;
|
|
|
|
static char *s_justify[3] =
|
|
|
|
{ "Left justified", "Default justification", "Right justified" };
|
|
|
|
static WRadio *radio_justify;
|
|
|
|
static char *s_itemwidth[3] =
|
|
|
|
{ "Free width", "Fixed width", "Growable width" };
|
|
|
|
static WRadio *radio_itemwidth;
|
|
|
|
|
|
|
|
struct listmode_button {
|
1998-02-27 04:54:42 +00:00
|
|
|
int ret_cmd, flags, y, x;
|
|
|
|
char *text;
|
2003-09-01 08:18:54 +00:00
|
|
|
bcback callback;
|
1998-02-27 04:54:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define B_PLUS B_USER
|
2003-09-10 21:33:12 +00:00
|
|
|
#define B_MINUS (B_USER+1)
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
struct listmode_label {
|
1998-02-27 04:54:42 +00:00
|
|
|
int y, x;
|
|
|
|
char *text;
|
|
|
|
};
|
|
|
|
|
2003-09-01 08:18:54 +00:00
|
|
|
static char *
|
|
|
|
select_new_item (void)
|
|
|
|
{
|
2009-10-01 13:47:01 +03:00
|
|
|
char **possible_items;
|
|
|
|
char *ret = NULL;
|
2003-09-01 08:18:54 +00:00
|
|
|
int i;
|
|
|
|
Listbox *mylistbox;
|
|
|
|
|
2009-10-01 18:01:04 +03:00
|
|
|
possible_items = panel_get_user_possible_fields(NULL);
|
2009-10-01 13:47:01 +03:00
|
|
|
|
2003-09-01 08:18:54 +00:00
|
|
|
mylistbox =
|
2009-10-14 13:27:41 +04:00
|
|
|
create_listbox_window (20, 12, " Add listing format item ",
|
2003-09-01 08:18:54 +00:00
|
|
|
listmode_section);
|
|
|
|
for (i = 0; possible_items[i]; i++) {
|
|
|
|
listbox_add_item (mylistbox->list, 0, 0, possible_items[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = run_listbox (mylistbox);
|
|
|
|
if (i >= 0)
|
2009-10-01 13:47:01 +03:00
|
|
|
ret = g_strdup(possible_items[i]);
|
|
|
|
|
|
|
|
g_strfreev (possible_items);
|
|
|
|
return ret;
|
2003-09-01 08:18:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
static int
|
2003-09-01 02:07:02 +00:00
|
|
|
bplus_cback (int action)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
static int
|
2003-09-01 02:07:02 +00:00
|
|
|
bminus_cback (int action)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
static int
|
2003-09-01 08:18:54 +00:00
|
|
|
badd_cback (int action)
|
|
|
|
{
|
|
|
|
char *s = select_new_item ();
|
|
|
|
if (s) {
|
|
|
|
listbox_add_item (l_listmode, 0, 0, s, NULL);
|
2009-10-01 13:47:01 +03:00
|
|
|
g_free(s);
|
2003-09-01 08:18:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bremove_cback (int action)
|
|
|
|
{
|
|
|
|
listbox_remove_current (l_listmode, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
static Dlg_head *
|
|
|
|
init_listmode (char *oldlistformat)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *s;
|
|
|
|
int format_width = 0;
|
|
|
|
int format_columns = 0;
|
2002-09-02 06:06:49 +00:00
|
|
|
Dlg_head *listmode_dlg;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2003-09-07 23:06:27 +00:00
|
|
|
static struct listmode_label listmode_labels[] = {
|
2003-09-01 09:03:30 +00:00
|
|
|
{UY + 13, UX + 22, "Item width:"}
|
|
|
|
};
|
|
|
|
|
2003-09-07 23:06:27 +00:00
|
|
|
static struct listmode_button listmode_but[] = {
|
2003-09-01 09:03:30 +00:00
|
|
|
{B_CANCEL, NORMAL_BUTTON, BY, BX + 53, "&Cancel", NULL},
|
|
|
|
{B_ADD, NORMAL_BUTTON, BY, BX + 22, "&Add item", badd_cback},
|
|
|
|
{B_REMOVE, NORMAL_BUTTON, BY, BX + 10, "&Remove", bremove_cback},
|
|
|
|
{B_ENTER, DEFPUSH_BUTTON, BY, BX, "&OK", NULL},
|
|
|
|
{B_PLUS, NARROW_BUTTON, UY + 13, UX + 37, "&+", bplus_cback},
|
|
|
|
{B_MINUS, NARROW_BUTTON, UY + 13, UX + 34, "&-", bminus_cback},
|
|
|
|
};
|
|
|
|
|
1998-02-27 04:54:42 +00:00
|
|
|
do_refresh ();
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
listmode_dlg =
|
2003-09-07 23:06:27 +00:00
|
|
|
create_dlg (0, 0, 22, 74, dialog_colors, NULL, listmode_section,
|
2003-09-12 21:22:01 +00:00
|
|
|
"Listing format edit", DLG_CENTER | DLG_REVERSE);
|
2003-09-07 23:06:27 +00:00
|
|
|
|
|
|
|
add_widget (listmode_dlg,
|
2009-04-15 20:22:26 +04:00
|
|
|
groupbox_new (UY, UX, 4, 63, "General options"));
|
|
|
|
add_widget (listmode_dlg, groupbox_new (UY + 4, UX, 11, 18, "Items"));
|
2003-09-07 23:06:27 +00:00
|
|
|
add_widget (listmode_dlg,
|
2009-04-15 20:22:26 +04:00
|
|
|
groupbox_new (UY + 4, UX + 20, 11, 43, "Item options"));
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2003-09-07 23:06:27 +00:00
|
|
|
for (i = 0;
|
|
|
|
i < sizeof (listmode_but) / sizeof (struct listmode_button); i++)
|
2003-09-01 02:07:02 +00:00
|
|
|
add_widget (listmode_dlg,
|
2003-09-01 09:03:30 +00:00
|
|
|
button_new (listmode_but[i].y, listmode_but[i].x,
|
2003-09-01 02:07:02 +00:00
|
|
|
listmode_but[i].ret_cmd,
|
|
|
|
listmode_but[i].flags,
|
2003-09-01 08:18:54 +00:00
|
|
|
listmode_but[i].text,
|
|
|
|
listmode_but[i].callback));
|
1998-02-27 04:54:42 +00:00
|
|
|
|
|
|
|
/* We add the labels. */
|
2003-09-07 23:06:27 +00:00
|
|
|
for (i = 0;
|
|
|
|
i < sizeof (listmode_labels) / sizeof (struct listmode_label);
|
|
|
|
i++) {
|
2002-09-02 06:06:49 +00:00
|
|
|
pname =
|
|
|
|
label_new (listmode_labels[i].y, listmode_labels[i].x,
|
2003-09-01 05:10:49 +00:00
|
|
|
listmode_labels[i].text);
|
1998-02-27 04:54:42 +00:00
|
|
|
add_widget (listmode_dlg, pname);
|
|
|
|
}
|
|
|
|
|
2006-02-28 16:15:21 +00:00
|
|
|
radio_itemwidth = radio_new (UY + 9, UX + 22, 3, s_itemwidth);
|
1998-02-27 04:54:42 +00:00
|
|
|
add_widget (listmode_dlg, radio_itemwidth);
|
|
|
|
radio_itemwidth = 0;
|
2006-02-28 16:15:21 +00:00
|
|
|
radio_justify = radio_new (UY + 5, UX + 22, 3, s_justify);
|
1998-02-27 04:54:42 +00:00
|
|
|
add_widget (listmode_dlg, radio_justify);
|
|
|
|
radio_justify->sel = 1;
|
|
|
|
|
|
|
|
/* get new listbox */
|
2009-04-15 20:22:26 +04:00
|
|
|
l_listmode = listbox_new (UY + 5, UX + 1, 9, 16, NULL);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
if (strncmp (oldlistformat, "full ", 5) == 0) {
|
1998-02-27 04:54:42 +00:00
|
|
|
format_width = 1;
|
|
|
|
oldlistformat += 5;
|
|
|
|
}
|
2002-09-02 06:06:49 +00:00
|
|
|
if (strncmp (oldlistformat, "half ", 5) == 0) {
|
1998-02-27 04:54:42 +00:00
|
|
|
oldlistformat += 5;
|
|
|
|
}
|
2002-09-02 06:06:49 +00:00
|
|
|
if (strncmp (oldlistformat, "2 ", 2) == 0) {
|
1998-02-27 04:54:42 +00:00
|
|
|
format_columns = 1;
|
|
|
|
oldlistformat += 2;
|
|
|
|
}
|
2002-09-02 06:06:49 +00:00
|
|
|
if (strncmp (oldlistformat, "1 ", 2) == 0) {
|
1998-02-27 04:54:42 +00:00
|
|
|
oldlistformat += 2;
|
|
|
|
}
|
|
|
|
s = strtok (oldlistformat, ",");
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
while (s) {
|
1998-02-27 04:54:42 +00:00
|
|
|
listbox_add_item (l_listmode, 0, 0, s, NULL);
|
|
|
|
s = strtok (NULL, ",");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add listbox to the dialogs */
|
2001-04-06 21:48:11 +00:00
|
|
|
add_widget (listmode_dlg, l_listmode);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2006-02-28 16:15:21 +00:00
|
|
|
radio_columns = radio_new (UY + 1, UX + 32, 2, s_columns);
|
1998-02-27 04:54:42 +00:00
|
|
|
add_widget (listmode_dlg, radio_columns);
|
|
|
|
radio_columns->sel = format_columns;
|
2006-02-28 16:15:21 +00:00
|
|
|
radio_genwidth = radio_new (UY + 1, UX + 2, 2, s_genwidth);
|
1998-02-27 04:54:42 +00:00
|
|
|
add_widget (listmode_dlg, radio_genwidth);
|
|
|
|
radio_genwidth->sel = format_width;
|
2002-09-02 06:06:49 +00:00
|
|
|
|
|
|
|
return listmode_dlg;
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
static void
|
2003-09-01 08:18:54 +00:00
|
|
|
listmode_done (Dlg_head *h)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
2002-09-02 06:06:49 +00:00
|
|
|
destroy_dlg (h);
|
1998-02-27 04:54:42 +00:00
|
|
|
if (0)
|
1998-04-30 03:21:52 +00:00
|
|
|
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
1998-02-27 04:54:42 +00:00
|
|
|
repaint_screen ();
|
|
|
|
}
|
|
|
|
|
1998-12-02 21:27:27 +00:00
|
|
|
static char *
|
|
|
|
collect_new_format (void)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
char *newformat;
|
|
|
|
int i;
|
|
|
|
char *last;
|
|
|
|
char *text, *extra;
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 01:08:30 +00:00
|
|
|
newformat = g_malloc (1024);
|
1998-02-27 04:54:42 +00:00
|
|
|
if (radio_genwidth->sel)
|
|
|
|
strcpy (newformat, "full ");
|
|
|
|
else
|
|
|
|
strcpy (newformat, "half ");
|
|
|
|
if (radio_columns->sel)
|
|
|
|
strcat (newformat, "2 ");
|
|
|
|
last = NULL;
|
2002-09-02 06:06:49 +00:00
|
|
|
for (i = 0;; i++) {
|
1998-02-27 04:54:42 +00:00
|
|
|
listbox_select_by_number (l_listmode, i);
|
|
|
|
listbox_get_current (l_listmode, &text, &extra);
|
|
|
|
if (text == last)
|
|
|
|
break;
|
|
|
|
if (last != NULL)
|
|
|
|
strcat (newformat, ",");
|
|
|
|
strcat (newformat, text);
|
|
|
|
last = text;
|
|
|
|
}
|
|
|
|
return newformat;
|
|
|
|
}
|
|
|
|
|
2003-09-01 09:03:30 +00:00
|
|
|
/* Return new format or NULL if the user cancelled the dialog */
|
2002-09-02 06:06:49 +00:00
|
|
|
char *
|
|
|
|
listmode_edit (char *oldlistformat)
|
1998-02-27 04:54:42 +00:00
|
|
|
{
|
|
|
|
char *newformat = NULL;
|
|
|
|
char *s;
|
2002-09-02 06:06:49 +00:00
|
|
|
Dlg_head *listmode_dlg;
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2009-02-05 23:40:32 +01:00
|
|
|
s = g_strdup (oldlistformat);
|
2002-09-02 06:06:49 +00:00
|
|
|
listmode_dlg = init_listmode (s);
|
2009-02-05 23:27:37 +01:00
|
|
|
g_free (s);
|
1998-02-27 04:54:42 +00:00
|
|
|
|
2003-09-01 09:03:30 +00:00
|
|
|
if (run_dlg (listmode_dlg) == B_ENTER) {
|
2003-09-01 08:18:54 +00:00
|
|
|
newformat = collect_new_format ();
|
1998-02-27 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
listmode_done (listmode_dlg);
|
1998-02-27 04:54:42 +00:00
|
|
|
return newformat;
|
|
|
|
}
|
2009-04-24 01:47:22 +03:00
|
|
|
#else
|
|
|
|
void listmode__unused(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
CFLAGS="-ansi -pedantic -Wall -Wextra -Werror"
|
|
|
|
*/
|
|
|
|
}
|
2000-09-26 22:38:13 +00:00
|
|
|
|
2002-09-02 06:06:49 +00:00
|
|
|
#endif /* LISTMODE_EDITOR */
|