Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ You'll need the following dependencies:
* libgtkspell3-3-dev
* libgranite-dev >= 6.0.0
* libhandy-1-dev >= 0.90.0
* libportal-dev
* libpeas-dev
* libsoup2.4-dev
* libvala-0.34-dev (or higher)
Expand Down
9 changes: 9 additions & 0 deletions io.elementary.code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ modules:
url: https://github.com/universal-ctags/ctags.git
tag: p5.9.20201101.0

- name: libportal
buildsystem: meson
config-opts:
- '-Dgtk_doc=false'
sources:
- type: git
url: https://github.com/flatpak/libportal.git
tag: '0.4'

- name: code
buildsystem: meson
config-opts:
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ gee_dep = dependency('gee-0.8', version: '>=0.8.5')
gtk_dep = dependency('gtk+-3.0', version: '>=3.6.0')
granite_dep = dependency('granite', version: '>=6.0.0')
handy_dep = dependency('libhandy-1', version: '>=0.90.0')
libportal_dep = dependency ('libportal')
gtksourceview_dep = dependency('gtksourceview-4')
peas_dep = dependency('libpeas-1.0')
peasgtk_dep = dependency('libpeas-gtk-1.0')
Expand All @@ -51,6 +52,7 @@ dependencies = [
gtk_dep,
granite_dep,
handy_dep,
libportal_dep,
gtksourceview_dep,
peas_dep,
peasgtk_dep,
Expand Down
7 changes: 7 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ namespace Scratch {
public GLib.Settings settings;
public GLib.Settings service_settings;
public GLib.Settings privacy_settings;
public bool in_sandbox;

public class Application : Gtk.Application {
public string app_cmd_name { get { return _app_cmd_name; } }
public string data_home_folder_unsaved { get { return _data_home_folder_unsaved; } }
public string default_font { get; set; }
public Xdp.Portal portal;
private static string _app_cmd_name;
private static string _data_home_folder_unsaved;
private static bool create_new_tab = false;
Expand Down Expand Up @@ -67,6 +69,11 @@ namespace Scratch {
settings = new GLib.Settings (Constants.PROJECT_NAME + ".settings");
service_settings = new GLib.Settings (Constants.PROJECT_NAME + ".services");
privacy_settings = new GLib.Settings ("org.gnome.desktop.privacy");
in_sandbox = FileUtils.test ("/.flatpak-info", FileTest.EXISTS);

if (in_sandbox) {
portal = new Xdp.Portal ();
}

GLib.Intl.setlocale (LocaleCategory.ALL, "");
GLib.Intl.bindtextdomain (Constants.GETTEXT_PACKAGE, Constants.LOCALEDIR);
Expand Down
37 changes: 28 additions & 9 deletions src/FolderManager/FileItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,24 @@ namespace Scratch.FolderManager {
new_window.open_document (doc, true);
});

var files_appinfo = AppInfo.get_default_for_type ("inode/directory", true);
Gtk.MenuItem files_menuitem = null;

var files_item_icon = new Gtk.Image.from_gicon (files_appinfo.get_icon (), Gtk.IconSize.MENU);
files_item_icon.pixel_size = 16;
if (in_sandbox) {
files_menuitem = new Gtk.MenuItem.with_label (_("File Manager"));
files_menuitem.activate.connect (() => open_on_file_manager (file));
} else {
var files_appinfo = AppInfo.get_default_for_type ("inode/directory", true);

var files_item_grid = new Gtk.Grid ();
files_item_grid.add (files_item_icon);
files_item_grid.add (new Gtk.Label (files_appinfo.get_name ()));
var files_item_icon = new Gtk.Image.from_gicon (files_appinfo.get_icon (), Gtk.IconSize.MENU);
files_item_icon.pixel_size = 16;

var files_menuitem = new Gtk.MenuItem ();
files_menuitem.add (files_item_grid);
files_menuitem.activate.connect (() => launch_app_with_file (files_appinfo, file.file));
var files_item_grid = new Gtk.Grid ();
files_item_grid.add (files_item_icon);
files_item_grid.add (new Gtk.Label (files_appinfo.get_name ()));

files_menuitem = new Gtk.MenuItem ();
files_menuitem.add (files_item_grid);
}

var other_menuitem = new Gtk.MenuItem.with_label (_("Other Application…"));
other_menuitem.activate.connect (() => show_app_chooser (file));
Expand Down Expand Up @@ -135,5 +141,18 @@ namespace Scratch.FolderManager {

return menu;
}

public void open_on_file_manager (File file) {
var portal = ((Scratch.Application) GLib.Application.get_default ()).portal;
var parent = new Xdp.Gtk3.Parent (((Gtk.Application) GLib.Application.get_default ()).active_window);

portal.open_directory.begin (parent, file.file.get_uri (), Xdp.OpenUriFlags.NONE, null, (obj, res) => {
try {
portal.open_directory.end (res);
} catch (Error e) {
warning (e.message);
}
});
}
}
}
69 changes: 38 additions & 31 deletions src/FolderManager/FolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace Scratch.FolderManager {
};

var menu = new Gtk.Menu ();
menu.append (create_submenu_for_open_in (info, file_type));
menu.append (create_open_in_menuitem (info, file_type));
menu.append (contractor_item);
menu.append (new Gtk.SeparatorMenuItem ());
menu.append (create_submenu_for_new ());
Expand All @@ -122,49 +122,56 @@ namespace Scratch.FolderManager {
return menu;
}

protected Gtk.MenuItem create_submenu_for_open_in (GLib.FileInfo? info, string? file_type) {
var other_menuitem = new Gtk.MenuItem.with_label (_("Other Application…"));
other_menuitem.activate.connect (() => show_app_chooser (file));
protected Gtk.MenuItem create_open_in_menuitem (GLib.FileInfo? info, string? file_type) {
Gtk.MenuItem open_in_item = null;

file_type = file_type ?? "inode/directory";
if (in_sandbox) {
open_in_item = new Gtk.MenuItem.with_label (_("Open In…"));
open_in_item.activate.connect (() => show_app_chooser (file));
} else {
var other_menuitem = new Gtk.MenuItem.with_label (_("Other Application…"));
other_menuitem.activate.connect (() => show_app_chooser (file));

var open_in_menu = new Gtk.Menu ();
file_type = file_type ?? "inode/directory";

if (info != null) {
List<AppInfo> external_apps = GLib.AppInfo.get_all_for_type (file_type);
var open_in_menu = new Gtk.Menu ();

string this_id = GLib.Application.get_default ().application_id + ".desktop";
if (info != null) {
List<AppInfo> external_apps = GLib.AppInfo.get_all_for_type (file_type);

foreach (AppInfo app_info in external_apps) {
if (app_info.get_id () == this_id) {
continue;
}
string this_id = GLib.Application.get_default ().application_id + ".desktop";

foreach (AppInfo app_info in external_apps) {
if (app_info.get_id () == this_id) {
continue;
}

var menuitem_icon = new Gtk.Image.from_gicon (app_info.get_icon (), Gtk.IconSize.MENU);
menuitem_icon.pixel_size = 16;
var menuitem_icon = new Gtk.Image.from_gicon (app_info.get_icon (), Gtk.IconSize.MENU);
menuitem_icon.pixel_size = 16;

var menuitem_grid = new Gtk.Grid ();
menuitem_grid.add (menuitem_icon);
menuitem_grid.add (new Gtk.Label (app_info.get_name ()));
var menuitem_grid = new Gtk.Grid ();
menuitem_grid.add (menuitem_icon);
menuitem_grid.add (new Gtk.Label (app_info.get_name ()));

var item_app = new Gtk.MenuItem ();
item_app.add (menuitem_grid);
var item_app = new Gtk.MenuItem ();
item_app.add (menuitem_grid);

item_app.activate.connect (() => {
launch_app_with_file (app_info, file.file);
});
open_in_menu.add (item_app);
item_app.activate.connect (() => {
launch_app_with_file (app_info, file.file);
});
open_in_menu.add (item_app);
}
}
}

if (open_in_menu.get_children ().length () > 0) {
open_in_menu.add (new Gtk.SeparatorMenuItem ());
}
if (open_in_menu.get_children ().length () > 0) {
open_in_menu.add (new Gtk.SeparatorMenuItem ());
}

open_in_menu.add (other_menuitem);
open_in_menu.add (other_menuitem);

var open_in_item = new Gtk.MenuItem.with_label (_("Open In"));
open_in_item.submenu = open_in_menu;
open_in_item = new Gtk.MenuItem.with_label (_("Open In"));
open_in_item.submenu = open_in_menu;
}

return open_in_item;
}
Expand Down
31 changes: 22 additions & 9 deletions src/FolderManager/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,30 @@ namespace Scratch.FolderManager {
}

public void show_app_chooser (File file) {
var dialog = new Gtk.AppChooserDialog (new Gtk.Window (), Gtk.DialogFlags.MODAL, file.file);
dialog.deletable = false;

if (dialog.run () == Gtk.ResponseType.OK) {
var app_info = dialog.get_app_info ();
if (app_info != null) {
launch_app_with_file (app_info, file.file);
if (in_sandbox) {
var portal = ((Scratch.Application) GLib.Application.get_default ()).portal;
var parent = new Xdp.Gtk3.Parent (((Gtk.Application) GLib.Application.get_default ()).active_window);

portal.open_uri.begin (parent, file.file.get_uri (), Xdp.OpenUriFlags.ASK, null, (obj, res) => {
try {
portal.open_uri.end (res);
} catch (Error e) {
warning (e.message);
}
});
} else {
var dialog = new Gtk.AppChooserDialog (new Gtk.Window (), Gtk.DialogFlags.MODAL, file.file);
dialog.deletable = false;

if (dialog.run () == Gtk.ResponseType.OK) {
var app_info = dialog.get_app_info ();
if (app_info != null) {
launch_app_with_file (app_info, file.file);
}
}
}

dialog.destroy ();
dialog.destroy ();
}
}

public void launch_app_with_file (AppInfo app_info, GLib.File file) {
Expand Down
2 changes: 1 addition & 1 deletion src/FolderManager/ProjectFolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace Scratch.FolderManager {
}

var menu = new Gtk.Menu ();
menu.append (create_submenu_for_open_in (info, file_type));
menu.append (create_open_in_menuitem (info, file_type));
menu.append (new Gtk.SeparatorMenuItem ());
menu.append (create_submenu_for_new ());

Expand Down
Loading