2 Copyright (C) 1995 The Free Software Foundation
4 Written by: 1995 Janne Kukonlehto
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <sys/types.h>
33 #include "tty.h" /* attrset() */
38 #include "wtools.h" /* For common_dialog_repaint() */
39 #include "setup.h" /* For profile_bname */
40 #include "profile.h" /* Load/save directories panelize */
42 #include "panel.h" /* current_panel */
43 #include "main.h" /* repaint_screen */
55 #define B_REMOVE (B_USER + 1)
57 static WListbox
*l_panelize
;
58 static Dlg_head
*panelize_dlg
;
59 static int last_listitem
;
63 int ret_cmd
, flags
, y
, x
;
65 } panelize_but
[BUTTONS
] = {
66 { B_CANCEL
, NORMAL_BUTTON
, 0, 53, N_("&Cancel") },
67 { B_ADD
, NORMAL_BUTTON
, 0, 28, N_("&Add new") },
68 { B_REMOVE
, NORMAL_BUTTON
, 0, 16, N_("&Remove") },
69 { B_ENTER
, DEFPUSH_BUTTON
, 0, 0, N_("Pane&lize") },
72 static char *panelize_section
= "Panelize";
73 static void do_external_panelize (char *command
);
75 /* Directory panelize */
76 static struct panelize
{
79 struct panelize
*next
;
85 if (l_panelize
->pos
!= last_listitem
) {
86 last_listitem
= l_panelize
->pos
;
88 ((struct panelize
*) l_panelize
->current
->data
)->command
);
90 update_input (pname
, 1);
95 panelize_callback (Dlg_head
*h
, dlg_msg_t msg
, int parm
)
99 common_dialog_repaint (h
);
100 attrset (COLOR_NORMAL
);
101 draw_box (h
, UY
, UX
, h
->lines
- 10, h
->cols
- 10);
107 attrset (MENU_ENTRY_COLOR
);
112 return default_dlg_callback (h
, msg
, parm
);
119 int i
, panelize_cols
= COLS
- 6;
120 struct panelize
*current
= panelize
;
123 static int i18n_flag
= 0;
124 static int maxlen
= 0;
127 i
= sizeof (panelize_but
) / sizeof (panelize_but
[0]);
129 panelize_but
[i
].text
= _(panelize_but
[i
].text
);
130 maxlen
+= strlen (panelize_but
[i
].text
) + 5;
136 panelize_cols
= max (panelize_cols
, maxlen
);
139 panelize_but
[3].x
+ strlen (panelize_but
[3].text
) + 7;
141 panelize_but
[2].x
+ strlen (panelize_but
[2].text
) + 5;
143 panelize_cols
- strlen (panelize_but
[0].text
) - 8 - BX
;
145 #endif /* ENABLE_NLS */
152 create_dlg (0, 0, 22, panelize_cols
, dialog_colors
,
153 panelize_callback
, "[External panelize]",
154 _("External panelize"), DLG_CENTER
| DLG_REVERSE
);
156 for (i
= 0; i
< BUTTONS
; i
++)
157 add_widget (panelize_dlg
,
158 button_new (BY
+ panelize_but
[i
].y
,
159 BX
+ panelize_but
[i
].x
,
160 panelize_but
[i
].ret_cmd
,
161 panelize_but
[i
].flags
,
162 panelize_but
[i
].text
, 0));
165 input_new (UY
+ 14, UX
, INPUT_COLOR
, panelize_dlg
->cols
- 10, "",
167 add_widget (panelize_dlg
, pname
);
169 add_widget (panelize_dlg
, label_new (UY
+ 13, UX
, _("Command")));
171 /* get new listbox */
173 listbox_new (UY
+ 1, UX
+ 1, panelize_dlg
->cols
- 12, 10, NULL
);
176 listbox_add_item (l_panelize
, 0, 0, current
->label
, current
);
177 current
= current
->next
;
180 /* add listbox to the dialogs */
181 add_widget (panelize_dlg
, l_panelize
);
183 listbox_select_entry (l_panelize
,
184 listbox_search_text (l_panelize
,
185 _("Other command")));
188 static void panelize_done (void)
190 destroy_dlg (panelize_dlg
);
194 static void add2panelize (char *label
, char *command
)
196 struct panelize
*current
, *old
;
200 while (current
&& strcmp (current
->label
, label
) <= 0){
202 current
= current
->next
;
206 panelize
= g_new (struct panelize
, 1);
207 panelize
->label
= label
;
208 panelize
->command
= command
;
209 panelize
->next
= current
;
211 struct panelize
*new;
212 new = g_new (struct panelize
, 1);
214 new->command
= command
;
221 add2panelize_cmd (void)
225 if (pname
->buffer
&& (*pname
->buffer
)) {
226 label
= input_dialog (_(" Add to external panelize "),
227 _(" Enter command label: "),
236 add2panelize (label
, g_strdup (pname
->buffer
));
240 static void remove_from_panelize (struct panelize
*entry
)
242 if (strcmp (entry
->label
, _("Other command")) != 0) {
243 if (entry
== panelize
) {
244 panelize
= panelize
->next
;
246 struct panelize
*current
= panelize
;
247 while (current
&& current
->next
!= entry
)
248 current
= current
->next
;
250 current
->next
= entry
->next
;
254 g_free (entry
->label
);
255 g_free (entry
->command
);
261 external_panelize (void)
265 if (!vfs_current_is_local ()){
266 message (1, MSG_ERROR
,
267 _(" Cannot run external panelize in a non-local directory "));
273 /* display file info */
274 attrset (SELECTED_COLOR
);
276 run_dlg (panelize_dlg
);
278 switch (panelize_dlg
->ret_value
) {
287 remove_from_panelize (l_panelize
->current
->data
);
291 target
= pname
->buffer
;
292 if (target
!= NULL
&& *target
) {
293 char *cmd
= g_strdup (target
);
294 destroy_dlg (panelize_dlg
);
295 do_external_panelize (cmd
);
306 void load_panelize (void)
311 profile_keys
= profile_init_iterator (panelize_section
, profile_name
);
313 add2panelize (g_strdup (_("Other command")), g_strdup (""));
316 add2panelize (g_strdup (_("Find rejects after patching")), g_strdup ("find . -name \\*.rej -print"));
317 add2panelize (g_strdup (_("Find *.orig after patching")), g_strdup ("find . -name \\*.orig -print"));
318 add2panelize (g_strdup (_("Find SUID and SGID programs")), g_strdup ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
322 while (profile_keys
){
323 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
324 add2panelize (g_strdup (key
), g_strdup (value
));
328 void save_panelize (void)
330 struct panelize
*current
= panelize
;
332 profile_clean_section (panelize_section
, profile_name
);
333 for (;current
; current
= current
->next
){
334 if (strcmp (current
->label
, _("Other command")))
335 WritePrivateProfileString (panelize_section
,
343 void done_panelize (void)
345 struct panelize
*current
= panelize
;
346 struct panelize
*next
;
348 for (; current
; current
= next
){
349 next
= current
->next
;
350 g_free (current
->label
);
351 g_free (current
->command
);
356 static void do_external_panelize (char *command
)
358 int status
, link_to_dir
, stale_link
;
361 dir_list
*list
= ¤t_panel
->dir
;
362 char line
[MC_MAXPATHLEN
];
367 external
= popen (command
, "r");
369 close_error_pipe (1, _("Cannot invoke command."));
372 /* Clear the counters and the directory list */
373 panel_clean_dir (current_panel
);
377 if (fgets (line
, MC_MAXPATHLEN
, external
) == NULL
) {
378 if (ferror(external
) && errno
== EINTR
)
383 if (line
[strlen(line
)-1] == '\n')
384 line
[strlen(line
)-1] = 0;
385 if (strlen(line
) < 1)
387 if (line
[0] == '.' && line
[1] == PATH_SEP
)
391 status
= handle_path (list
, name
, &st
, next_free
, &link_to_dir
,
397 list
->list
[next_free
].fnamelen
= strlen (name
);
398 list
->list
[next_free
].fname
= g_strdup (name
);
399 file_mark (current_panel
, next_free
, 0);
400 list
->list
[next_free
].f
.link_to_dir
= link_to_dir
;
401 list
->list
[next_free
].f
.stale_link
= stale_link
;
402 list
->list
[next_free
].f
.dir_size_computed
= 0;
403 list
->list
[next_free
].st
= st
;
405 if (!(next_free
& 32))
409 current_panel
->is_panelized
= 1;
411 current_panel
->count
= next_free
;
412 if (list
->list
[0].fname
[0] == PATH_SEP
){
413 strcpy (current_panel
->cwd
, PATH_SEP_STR
);
414 chdir (PATH_SEP_STR
);
417 current_panel
->count
= set_zero_dir (list
);
419 if (pclose (external
) < 0)
420 message (0, _("External panelize"), _("Pipe close failed"));
421 close_error_pipe (0, 0);
422 try_to_select (current_panel
, NULL
);
423 panel_re_sort (current_panel
);