[gedit/gnome-3-8] Bug 698292 - Do not include non-text files in quick open



commit 6550abee5af9624cc18cbdeb168c49a64abf4e0c
Author: Garrett Regier <garrettregier gmail com>
Date:   Mon Jun 17 00:02:32 2013 -0700

    Bug 698292 - Do not include non-text files in quick open

 plugins/quickopen/quickopen/popup.py |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/plugins/quickopen/quickopen/popup.py b/plugins/quickopen/quickopen/popup.py
index 484f512..f0c2669 100644
--- a/plugins/quickopen/quickopen/popup.py
+++ b/plugins/quickopen/quickopen/popup.py
@@ -18,6 +18,7 @@
 #  Boston, MA 02111-1307, USA.
 
 import os
+import platform
 import functools
 import fnmatch
 from gi.repository import Gio, GObject, Pango, Gtk, Gdk, Gedit
@@ -145,6 +146,26 @@ class Popup(Gtk.Dialog):
 
         return pixbuf
 
+    def _is_text(self, entry):
+        content_type = entry.get_content_type()
+
+        if content_type is None or Gio.content_type_is_unknown(content_type):
+            return True
+
+        if platform.system() != 'Windows':
+            if Gio.content_type_is_a(content_type, 'text/plain'):
+                return True
+        else:
+            if Gio.content_type_is_a(content_type, 'text'):
+                return True
+
+            # This covers a rare case in which on Windows the PerceivedType
+            # is not set to "text" but the Content Type is set to text/plain
+            if Gio.content_type_get_mime_type(content_type) == 'text/plain':
+                return True
+
+        return False
+
     def _list_dir(self, gfile):
         entries = []
 
@@ -168,9 +189,15 @@ class Popup(Gtk.Dialog):
         children = []
 
         for entry in entries:
+            file_type = entry[1].get_file_type()
+
+            if file_type == Gio.FileType.REGULAR:
+                if not self._is_text(entry[1]):
+                    continue
+
             children.append((entry[0],
                              entry[1].get_name(),
-                             entry[1].get_file_type(),
+                             file_type,
                              entry[1].get_icon()))
 
         return children


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]