1998-12-16 05:51:44 +03:00
|
|
|
#include <config.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "x.h"
|
1999-01-27 04:14:57 +03:00
|
|
|
#include "global.h"
|
1998-12-16 05:51:44 +03:00
|
|
|
#include "dir.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "panel.h"
|
|
|
|
#define WANT_WIDGETS /* bleah */
|
|
|
|
#include "main.h"
|
|
|
|
#include "color.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "layout.h" /* get_panel_widget */
|
|
|
|
#include "ext.h" /* regex_command */
|
|
|
|
#include "cmd.h" /* copy_cmd, ren_cmd, delete_cmd, ... */
|
|
|
|
#include "gscreen.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "dialog.h"
|
|
|
|
#include "../vfs/vfs.h"
|
|
|
|
|
|
|
|
static void
|
1999-02-26 10:17:51 +03:00
|
|
|
gmc_execute (const char *fname, const char *buf, int needs_terminal)
|
1998-12-16 05:51:44 +03:00
|
|
|
{
|
1999-02-26 10:17:51 +03:00
|
|
|
exec_extension (fname, buf, NULL, NULL, 0, needs_terminal);
|
1998-12-16 05:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-12-30 06:24:46 +03:00
|
|
|
gmc_open_filename (char *fname, GList *args)
|
1998-12-16 05:51:44 +03:00
|
|
|
{
|
1999-02-11 08:52:55 +03:00
|
|
|
const char *mime_type;
|
|
|
|
const char *cmd;
|
1998-12-16 05:51:44 +03:00
|
|
|
char *buf;
|
|
|
|
int size;
|
1999-02-26 10:17:51 +03:00
|
|
|
int needs_terminal = 0;
|
1998-12-16 05:51:44 +03:00
|
|
|
|
1999-02-26 10:17:51 +03:00
|
|
|
mime_type = gnome_mime_type_or_default (fname, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We accept needs_terminal as -1, which means our caller
|
|
|
|
* did not want to do the work
|
|
|
|
*/
|
|
|
|
if (gnome_metadata_get (fname, "flags", &size, &buf) == 0){
|
|
|
|
needs_terminal = (strstr (buf, "needsterminal") != 0);
|
|
|
|
g_free (buf);
|
|
|
|
} else if (mime_type){
|
|
|
|
const char *flags;
|
|
|
|
|
|
|
|
flags = gnome_mime_type_or_default (mime_type, "flags");
|
|
|
|
needs_terminal = (strstr (flags, "needsterminal") != 0);
|
|
|
|
}
|
|
|
|
|
1998-12-30 06:24:46 +03:00
|
|
|
if (gnome_metadata_get (fname, "fm-open", &size, &buf) == 0){
|
1999-02-26 10:17:51 +03:00
|
|
|
gmc_execute (fname, buf, needs_terminal);
|
1999-01-06 07:03:15 +03:00
|
|
|
g_free (buf);
|
1998-12-16 05:51:44 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-12-30 06:24:46 +03:00
|
|
|
if (gnome_metadata_get (fname, "open", &size, &buf) == 0){
|
1999-02-26 10:17:51 +03:00
|
|
|
gmc_execute (fname, buf, needs_terminal);
|
1999-01-06 07:03:15 +03:00
|
|
|
g_free (buf);
|
1998-12-16 05:51:44 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mime_type)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
cmd = gnome_mime_get_value (mime_type, "fm-open");
|
|
|
|
|
|
|
|
if (cmd){
|
1999-02-26 10:17:51 +03:00
|
|
|
gmc_execute (fname, cmd, needs_terminal);
|
1998-12-16 05:51:44 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = gnome_mime_get_value (mime_type, "open");
|
|
|
|
if (cmd){
|
1999-02-26 10:17:51 +03:00
|
|
|
gmc_execute (fname, cmd, needs_terminal);
|
1998-12-16 05:51:44 +03:00
|
|
|
return 1;
|
|
|
|
}
|
1999-02-11 08:52:55 +03:00
|
|
|
|
|
|
|
if (strcmp (mime_type, "application/x-gnome-app-info") == 0){
|
|
|
|
GnomeDesktopEntry *entry;
|
|
|
|
|
|
|
|
entry = gnome_desktop_entry_load (fname);
|
|
|
|
if (entry){
|
|
|
|
gnome_desktop_entry_launch (entry);
|
|
|
|
gnome_desktop_entry_free (entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-16 05:51:44 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-02-12 05:42:42 +03:00
|
|
|
int
|
|
|
|
gmc_edit_filename (char *fname)
|
|
|
|
{
|
|
|
|
const char *mime_type;
|
|
|
|
const char *cmd;
|
|
|
|
char *buf;
|
|
|
|
int size;
|
1999-02-16 00:19:03 +03:00
|
|
|
char *editor, *type;
|
|
|
|
int on_terminal;
|
1999-02-12 05:42:42 +03:00
|
|
|
|
|
|
|
if (gnome_metadata_get (fname, "edit", &size, &buf) == 0){
|
1999-02-26 10:17:51 +03:00
|
|
|
gmc_execute (fname, buf, 0);
|
1999-02-12 05:42:42 +03:00
|
|
|
g_free (buf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mime_type = gnome_mime_type_or_default (fname, NULL);
|
1999-02-16 00:19:03 +03:00
|
|
|
if (mime_type){
|
|
|
|
cmd = gnome_mime_get_value (mime_type, "edit");
|
1999-02-12 05:42:42 +03:00
|
|
|
|
1999-02-16 00:19:03 +03:00
|
|
|
if (cmd){
|
1999-02-26 10:17:51 +03:00
|
|
|
gmc_execute (fname, cmd, 0);
|
1999-02-16 00:19:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
1999-02-12 05:42:42 +03:00
|
|
|
|
1999-02-16 00:19:03 +03:00
|
|
|
gnome_config_push_prefix( "/editor/Editor/");
|
|
|
|
type = gnome_config_get_string ("EDITOR_TYPE=executable");
|
|
|
|
|
|
|
|
if (strcmp (type, "mc-internal") == 0){
|
|
|
|
g_free (type);
|
|
|
|
do_edit (fname);
|
1999-02-12 05:42:42 +03:00
|
|
|
return 1;
|
|
|
|
}
|
1999-02-16 00:19:03 +03:00
|
|
|
g_free (type);
|
|
|
|
|
|
|
|
editor = gnome_config_get_string ("EDITOR=emacs");
|
|
|
|
on_terminal = gnome_config_get_bool ("NEEDS_TERM=false");
|
|
|
|
|
|
|
|
if (on_terminal){
|
|
|
|
char *quoted = name_quote (fname, 0);
|
|
|
|
char *editor_cmd = g_strconcat (editor, " ", quoted, NULL);
|
|
|
|
|
|
|
|
gnome_open_terminal_with_cmd (editor_cmd);
|
|
|
|
g_free (quoted);
|
|
|
|
g_free (editor_cmd);
|
|
|
|
} else {
|
|
|
|
char *cmd = g_strconcat (editor, " %s", NULL);
|
|
|
|
|
1999-02-26 10:17:51 +03:00
|
|
|
gmc_execute (fname, cmd, 0);
|
1999-02-16 00:19:03 +03:00
|
|
|
g_free (cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (editor);
|
1999-02-12 05:42:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-30 06:24:46 +03:00
|
|
|
int
|
|
|
|
gmc_open (file_entry *fe)
|
|
|
|
{
|
|
|
|
return gmc_open_filename (fe->fname, NULL);
|
|
|
|
}
|
|
|
|
|
1998-12-16 05:51:44 +03:00
|
|
|
static void
|
1999-02-16 00:19:03 +03:00
|
|
|
gmc_run_view (const char *filename, const char *buf)
|
1998-12-16 05:51:44 +03:00
|
|
|
{
|
1999-02-26 10:17:51 +03:00
|
|
|
exec_extension (filename, buf, NULL, NULL, 0, 0);
|
1998-12-16 05:51:44 +03:00
|
|
|
}
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
int
|
1998-12-16 05:51:44 +03:00
|
|
|
gmc_view (char *filename, int start_line)
|
|
|
|
{
|
1999-02-11 08:52:55 +03:00
|
|
|
const char *mime_type, *cmd;
|
1998-12-16 05:51:44 +03:00
|
|
|
char *buf;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (gnome_metadata_get (filename, "fm-view", &size, &buf) == 0){
|
|
|
|
gmc_run_view (filename, buf);
|
1999-01-06 07:03:15 +03:00
|
|
|
g_free (buf);
|
1998-12-16 05:51:44 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gnome_metadata_get (filename, "view", &size, &buf) == 0){
|
|
|
|
gmc_run_view (filename, buf);
|
1999-01-06 07:03:15 +03:00
|
|
|
g_free (buf);
|
1998-12-16 05:51:44 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mime_type = gnome_mime_type_or_default (filename, NULL);
|
|
|
|
if (!mime_type)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
cmd = gnome_mime_get_value (mime_type, "fm-view");
|
|
|
|
|
|
|
|
if (cmd){
|
|
|
|
gmc_run_view (filename, cmd);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = gnome_mime_get_value (mime_type, "view");
|
|
|
|
if (cmd){
|
|
|
|
gmc_run_view (filename, cmd);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|