Removed _moo_file_is_text(); made file selector not try to open executables

This commit is contained in:
Yevgen Muntyan 2007-03-13 01:28:27 -05:00
parent 98f8ace143
commit a621681e7f
3 changed files with 32 additions and 42 deletions

View File

@ -30,10 +30,17 @@
#include "mooutils/mooactionfactory.h"
#include "mooutils/moomarshals.h"
#include "mooutils/mooi18n.h"
#include <string.h>
#include <gmodule.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glib/gstdio.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#ifdef MOO_USE_XDGMIME
#include <mooutils/xdgmime/xdgmime.h>
#endif
#ifndef MOO_VERSION
#define MOO_VERSION NULL
@ -278,12 +285,34 @@ static void
moo_file_selector_activate (MooFileView *fileview,
const char *path)
{
struct stat statbuf;
MooFileSelector *filesel = MOO_FILE_SELECTOR (fileview);
gboolean is_text = TRUE, is_exe = FALSE;
if (_moo_file_is_text (path))
g_return_if_fail (path != NULL);
errno = 0;
if (g_stat (path, &statbuf) != 0)
{
int err = errno;
g_warning ("%s: error in stat(%s): %s", G_STRLOC, path, g_strerror (err));
return;
}
#ifdef MOO_USE_XDGMIME
{
const char *mime_type = xdg_mime_get_mime_type_for_file (path, &statbuf);
is_text = !strcmp (mime_type, "application/octet-stream") ||
xdg_mime_mime_type_subclass (mime_type, "text/*");
is_exe = !strcmp (mime_type, "application/x-executable");
}
#endif
if (is_text)
moo_editor_open_file (moo_edit_window_get_editor (filesel->window),
filesel->window, GTK_WIDGET (filesel), path, NULL);
else
else if (!is_exe)
_moo_open_file (path);
}

View File

@ -40,10 +40,6 @@
#include <unistd.h>
#endif
#ifdef MOO_USE_XDGMIME
#include <mooutils/xdgmime/xdgmime.h>
#endif
#define BROKEN_NAME "<" "????" ">"
@ -480,39 +476,6 @@ _moo_normalize_file_path (const char *filename)
}
gboolean
_moo_file_is_text (const char *path)
{
struct stat buf;
g_return_val_if_fail (path != NULL, FALSE);
errno = 0;
if (g_stat (path, &buf) != 0)
{
int err = errno;
g_warning ("%s: error in stat(%s): %s", G_STRLOC, path, g_strerror (err));
return FALSE;
}
#ifdef MOO_USE_XDGMIME
{
const char *mime;
mime = xdg_mime_get_mime_type_for_file (path, &buf);
if (!strcmp (mime, XDG_MIME_TYPE_UNKNOWN) || xdg_mime_mime_type_subclass (mime, "text/*"))
return TRUE;
return FALSE;
}
#endif
return TRUE;
}
/**********************************************************************/
/* MSLU for poor
*/

View File

@ -68,8 +68,6 @@ char *moo_filename_from_locale (const char *file);
char *_moo_normalize_file_path (const char *filename);
gboolean _moo_file_is_text (const char *path);
/*
* C library and WinAPI functions wrappers analogous to glib/gstdio.h
*/