diff --git a/src/Application.vala b/src/Application.vala index 6c10029..63f4858 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -168,7 +168,26 @@ public class Application : Gtk.Application { } public void on_open_document () { - var open_dialog = new Gtk.FileDialog (); + var all_files_filter = new Gtk.FileFilter () { + name = _("All files"), + }; + all_files_filter.add_pattern ("*"); + + var text_files_filter = new Gtk.FileFilter () { + name = _("Text files"), + }; + text_files_filter.add_mime_type ("text/plain"); + + var filter_model = new ListStore (typeof (Gtk.FileFilter)); + filter_model.append (all_files_filter); + filter_model.append (text_files_filter); + + var open_dialog = new Gtk.FileDialog () { + default_filter = text_files_filter, + filters = filter_model, + title = _("Open"), + }; + open_dialog.open.begin (this.active_window, null, (obj, res) => { try { var file = open_dialog.open.end (res); diff --git a/src/Window.vala b/src/Window.vala index 1e63147..60e1481 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -145,7 +145,24 @@ public class AppWindow : Gtk.Window { File oldfile = this.file; bool is_unsaved_doc = (Application.data_dir_path in this.file.get_path ()); + var all_files_filter = new Gtk.FileFilter () { + name = _("All files"), + }; + all_files_filter.add_pattern ("*"); + + var text_files_filter = new Gtk.FileFilter () { + name = _("Text files"), + }; + text_files_filter.add_mime_type ("text/plain"); + + var filter_model = new ListStore (typeof (Gtk.FileFilter)); + filter_model.append (all_files_filter); + filter_model.append (text_files_filter); + var save_dialog = new Gtk.FileDialog () { + default_filter = text_files_filter, + filters = filter_model, + title = _("Save as"), initial_name = (is_unsaved_doc ? file_name + ".txt" : file_name) };