2 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007 Free Software Foundation, Inc.
5 Written by: 1995 Janne Kukonlehto
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <sys/types.h>
34 #include "tty.h" /* attrset() */
39 #include "wtools.h" /* For common_dialog_repaint() */
40 #include "setup.h" /* For profile_bname */
41 #include "profile.h" /* Load/save directories panelize */
43 #include "panel.h" /* current_panel */
44 #include "main.h" /* repaint_screen */
57 #define B_REMOVE (B_USER + 1)
59 static WListbox
*l_panelize
;
60 static Dlg_head
*panelize_dlg
;
61 static int last_listitem
;
65 int ret_cmd
, flags
, y
, x
;
67 } panelize_but
[BUTTONS
] = {
68 { B_CANCEL
, NORMAL_BUTTON
, 0, 53, N_("&Cancel") },
69 { B_ADD
, NORMAL_BUTTON
, 0, 28, N_("&Add new") },
70 { B_REMOVE
, NORMAL_BUTTON
, 0, 16, N_("&Remove") },
71 { B_ENTER
, DEFPUSH_BUTTON
, 0, 0, N_("Pane&lize") },
74 static const char *panelize_section
= "Panelize";
75 static void do_external_panelize (char *command
);
77 /* Directory panelize */
78 static struct panelize
{
81 struct panelize
*next
;
87 if (l_panelize
->pos
!= last_listitem
) {
88 last_listitem
= l_panelize
->pos
;
90 ((struct panelize
*) l_panelize
->current
->data
)->command
);
92 update_input (pname
, 1);
97 panelize_callback (Dlg_head
*h
, dlg_msg_t msg
, int parm
)
101 common_dialog_repaint (h
);
102 attrset (COLOR_NORMAL
);
103 draw_box (h
, UY
, UX
, h
->lines
- 10, h
->cols
- 10);
109 attrset (MENU_ENTRY_COLOR
);
114 return default_dlg_callback (h
, msg
, parm
);
121 int i
, panelize_cols
= COLS
- 6;
122 struct panelize
*current
= panelize
;
125 static int i18n_flag
= 0;
126 static int maxlen
= 0;
129 i
= sizeof (panelize_but
) / sizeof (panelize_but
[0]);
131 panelize_but
[i
].text
= _(panelize_but
[i
].text
);
132 maxlen
+= strlen (panelize_but
[i
].text
) + 5;
138 panelize_cols
= max (panelize_cols
, maxlen
);
141 panelize_but
[3].x
+ strlen (panelize_but
[3].text
) + 7;
143 panelize_but
[2].x
+ strlen (panelize_but
[2].text
) + 5;
145 panelize_cols
- strlen (panelize_but
[0].text
) - 8 - BX
;
147 #endif /* ENABLE_NLS */
154 create_dlg (0, 0, 22, panelize_cols
, dialog_colors
,
155 panelize_callback
, "[External panelize]",
156 _("External panelize"), DLG_CENTER
| DLG_REVERSE
);
158 for (i
= 0; i
< BUTTONS
; i
++)
159 add_widget (panelize_dlg
,
160 button_new (BY
+ panelize_but
[i
].y
,
161 BX
+ panelize_but
[i
].x
,
162 panelize_but
[i
].ret_cmd
,
163 panelize_but
[i
].flags
,
164 panelize_but
[i
].text
, 0));
167 input_new (UY
+ 14, UX
, INPUT_COLOR
, panelize_dlg
->cols
- 10, "",
169 add_widget (panelize_dlg
, pname
);
171 add_widget (panelize_dlg
, label_new (UY
+ 13, UX
, _("Command")));
173 /* get new listbox */
175 listbox_new (UY
+ 1, UX
+ 1, panelize_dlg
->cols
- 12, 10, NULL
);
178 listbox_add_item (l_panelize
, 0, 0, current
->label
, current
);
179 current
= current
->next
;
182 /* add listbox to the dialogs */
183 add_widget (panelize_dlg
, l_panelize
);
185 listbox_select_entry (l_panelize
,
186 listbox_search_text (l_panelize
,
187 _("Other command")));
190 static void panelize_done (void)
192 destroy_dlg (panelize_dlg
);
196 static void add2panelize (char *label
, char *command
)
198 struct panelize
*current
, *old
;
202 while (current
&& strcmp (current
->label
, label
) <= 0){
204 current
= current
->next
;
208 panelize
= g_new (struct panelize
, 1);
209 panelize
->label
= label
;
210 panelize
->command
= command
;
211 panelize
->next
= current
;
213 struct panelize
*new;
214 new = g_new (struct panelize
, 1);
216 new->command
= command
;
223 add2panelize_cmd (void)
227 if (pname
->buffer
&& (*pname
->buffer
)) {
228 label
= input_dialog (_(" Add to external panelize "),
229 _(" Enter command label: "),
230 MC_HISTORY_FM_PANELIZE_ADD
,
239 add2panelize (label
, g_strdup (pname
->buffer
));
243 static void remove_from_panelize (struct panelize
*entry
)
245 if (strcmp (entry
->label
, _("Other command")) != 0) {
246 if (entry
== panelize
) {
247 panelize
= panelize
->next
;
249 struct panelize
*current
= panelize
;
250 while (current
&& current
->next
!= entry
)
251 current
= current
->next
;
253 current
->next
= entry
->next
;
257 g_free (entry
->label
);
258 g_free (entry
->command
);
264 external_panelize (void)
268 if (!vfs_current_is_local ()){
269 message (1, MSG_ERROR
,
270 _(" Cannot run external panelize in a non-local directory "));
276 /* display file info */
277 attrset (SELECTED_COLOR
);
279 run_dlg (panelize_dlg
);
281 switch (panelize_dlg
->ret_value
) {
290 remove_from_panelize (l_panelize
->current
->data
);
294 target
= pname
->buffer
;
295 if (target
!= NULL
&& *target
) {
296 char *cmd
= g_strdup (target
);
297 destroy_dlg (panelize_dlg
);
298 do_external_panelize (cmd
);
309 void load_panelize (void)
314 profile_keys
= profile_init_iterator (panelize_section
, profile_name
);
316 add2panelize (g_strdup (_("Other command")), g_strdup (""));
319 add2panelize (g_strdup (_("Find rejects after patching")), g_strdup ("find . -name \\*.rej -print"));
320 add2panelize (g_strdup (_("Find *.orig after patching")), g_strdup ("find . -name \\*.orig -print"));
321 add2panelize (g_strdup (_("Find SUID and SGID programs")), g_strdup ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
325 while (profile_keys
){
326 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
327 add2panelize (g_strdup (key
), g_strdup (value
));
331 void save_panelize (void)
333 struct panelize
*current
= panelize
;
335 profile_clean_section (panelize_section
, profile_name
);
336 for (;current
; current
= current
->next
){
337 if (strcmp (current
->label
, _("Other command")))
338 WritePrivateProfileString (panelize_section
,
346 void done_panelize (void)
348 struct panelize
*current
= panelize
;
349 struct panelize
*next
;
351 for (; current
; current
= next
){
352 next
= current
->next
;
353 g_free (current
->label
);
354 g_free (current
->command
);
359 static void do_external_panelize (char *command
)
361 int status
, link_to_dir
, stale_link
;
364 dir_list
*list
= ¤t_panel
->dir
;
365 char line
[MC_MAXPATHLEN
];
370 external
= popen (command
, "r");
372 close_error_pipe (1, _("Cannot invoke command."));
375 /* Clear the counters and the directory list */
376 panel_clean_dir (current_panel
);
380 if (fgets (line
, MC_MAXPATHLEN
, external
) == NULL
) {
381 if (ferror(external
) && errno
== EINTR
)
386 if (line
[strlen(line
)-1] == '\n')
387 line
[strlen(line
)-1] = 0;
388 if (strlen(line
) < 1)
390 if (line
[0] == '.' && line
[1] == PATH_SEP
)
394 status
= handle_path (list
, name
, &st
, next_free
, &link_to_dir
,
400 list
->list
[next_free
].fnamelen
= strlen (name
);
401 list
->list
[next_free
].fname
= g_strdup (name
);
402 file_mark (current_panel
, next_free
, 0);
403 list
->list
[next_free
].f
.link_to_dir
= link_to_dir
;
404 list
->list
[next_free
].f
.stale_link
= stale_link
;
405 list
->list
[next_free
].f
.dir_size_computed
= 0;
406 list
->list
[next_free
].st
= st
;
408 if (!(next_free
& 32))
412 current_panel
->is_panelized
= 1;
414 current_panel
->count
= next_free
;
415 if (list
->list
[0].fname
[0] == PATH_SEP
){
416 strcpy (current_panel
->cwd
, PATH_SEP_STR
);
417 chdir (PATH_SEP_STR
);
420 current_panel
->count
= set_zero_dir (list
);
422 if (pclose (external
) < 0)
423 message (0, _("External panelize"), _("Pipe close failed"));
424 close_error_pipe (0, 0);
425 try_to_select (current_panel
, NULL
);
426 panel_re_sort (current_panel
);