refactor: use GtkFileChooserNative for file dialogs

GtkFileChooserNative uses the platform's APIs, and thus the Portal API.

This is important since we want to integrate this well with Flatpak.

See:
https://docs.flatpak.org/en/latest/portals-gtk.html
pull/19/head
Nefo Fortressia 2021-12-14 06:00:48 +07:00
parent 0de1d86494
commit cfe8c4dbe4
Signed by: fortressia
GPG Key ID: 6D7972CC76174995
2 changed files with 12 additions and 18 deletions

View File

@ -8,7 +8,7 @@ use crate::components::editor::EchidnaCoreEditor;
use gio::Cancellable;
use glib::{clone, Priority};
use gtk::{
prelude::*, subclass::prelude::*, FileChooserAction, FileChooserDialog, Label, ResponseType,
prelude::*, subclass::prelude::*, FileChooserAction, FileChooserNative, Label, ResponseType,
};
use sourceview::{prelude::*, Buffer, File, FileSaver};
@ -36,14 +36,12 @@ impl FileImplementedEditor for super::EchidnaWindow {
Perhaps some of the last points should not be implemented in this function but rather in another function that keeps track of every files.
*/
fn action_open_file(&self) {
let dialog: FileChooserDialog = FileChooserDialog::new(
let dialog = FileChooserNative::new(
Some("Open a file"),
Some(self),
FileChooserAction::Open,
&[
("Cancel", ResponseType::Cancel),
("Open", ResponseType::Accept),
],
Some("Open"),
Some("Cancel"),
);
dialog.set_visible(true);
@ -81,14 +79,12 @@ impl FileImplementedEditor for super::EchidnaWindow {
}
fn action_save_file_as(&self) {
let dialog = FileChooserDialog::new(
let dialog = FileChooserNative::new(
Some("Save File As"),
Some(self),
FileChooserAction::Save,
&[
("Cancel", ResponseType::Cancel),
("Save", ResponseType::Accept),
],
Some("Open"),
Some("Cancel"),
);
dialog.set_current_name("untitled");

View File

@ -9,7 +9,7 @@ use glib::clone;
use glib::subclass::types::ObjectSubclassExt;
use glib::types::Type;
use gtk::prelude::*;
use gtk::{ApplicationWindow, FileChooserAction, FileChooserDialog, ResponseType, TreeStore};
use gtk::{ApplicationWindow, FileChooserAction, FileChooserNative, ResponseType, TreeStore};
use relative_path::RelativePath;
use serde::{Deserialize, Serialize};
use std::path::Path;
@ -46,14 +46,12 @@ impl WorkspaceImplementedEditor for EchidnaEditor {
_action: &SimpleAction,
_variant: Option<&glib::Variant>,
) {
let dialog: FileChooserDialog = FileChooserDialog::new(
let dialog = FileChooserNative::new(
Some("Open a file"),
Some(&window),
FileChooserAction::Open,
&[
("Cancel", ResponseType::Cancel),
("Open", ResponseType::Accept),
],
Some("Open"),
Some("Cancel"),
);
dialog.set_visible(true);
dialog.connect_response(clone!(@weak window, @weak app =>
@ -78,7 +76,7 @@ impl WorkspaceImplementedEditor for EchidnaEditor {
*
* Basically, this is just the same as Open Folder, but it's many folders.
*
* - Open a FileChooserDialog, set to only view .code-workspace files.
* - Open a FileChooserNative, set to only view .code-workspace files.
* - If the user pressed cancel, destroy the dialog. If the user opened a .code-workspace file:
* - Get the workspace file, load and parse its content, .code-workspace files are in JSON with comments. But JSON only should be fine, for now.
* - Iterate over folders listed in the workspace file.