diff --git a/moo/mooedit/plugins/fileselector/moofileselector.c b/moo/mooedit/plugins/fileselector/moofileselector.c index 64c82ba2..c18ebb98 100644 --- a/moo/mooedit/plugins/fileselector/moofileselector.c +++ b/moo/mooedit/plugins/fileselector/moofileselector.c @@ -30,10 +30,17 @@ #include "mooutils/mooactionfactory.h" #include "mooutils/moomarshals.h" #include "mooutils/mooi18n.h" -#include #include #include #include +#include +#include +#include +#include + +#ifdef MOO_USE_XDGMIME +#include +#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); } diff --git a/moo/mooutils/mooutils-fs.c b/moo/mooutils/mooutils-fs.c index c2fe1cf1..474474f6 100644 --- a/moo/mooutils/mooutils-fs.c +++ b/moo/mooutils/mooutils-fs.c @@ -40,10 +40,6 @@ #include #endif -#ifdef MOO_USE_XDGMIME -#include -#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 */ diff --git a/moo/mooutils/mooutils-fs.h b/moo/mooutils/mooutils-fs.h index 754bb083..f301c5ba 100644 --- a/moo/mooutils/mooutils-fs.h +++ b/moo/mooutils/mooutils-fs.h @@ -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 */