Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use open directory portal #762

Merged
merged 5 commits into from
Jun 7, 2024
Merged
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
8 changes: 4 additions & 4 deletions src/AppWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ public abstract class AppWindow : PageWindow {
}

private void show_file_uri (File file) throws Error {
AppInfo app_info = AppInfo.get_default_for_type ("inode/directory", true);
var file_list = new List<File> ();
file_list.append (file);
app_info.launch (file_list, get_window ().get_screen ().get_display ().get_app_launch_context ());
Xdp.Parent? parent = Xdp.parent_new_gtk (this);

var portal = new Xdp.Portal ();
portal.open_directory.begin (parent, file.get_uri (), NONE, null);
}

protected virtual Gtk.ActionGroup[] create_common_action_groups () {
Expand Down
80 changes: 0 additions & 80 deletions src/DesktopIntegration.vala

This file was deleted.

16 changes: 0 additions & 16 deletions src/Dialogs/Dialogs.vala
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,6 @@ public File? choose_dir (string? user_title = null) {
}
}

// Ticket #3023
// Attempt to replace the system error with something friendlier
// if we can't copy an image over for editing in an external tool.
public void open_external_editor_error_dialog (Error err, Photo photo) {
// Did we fail because we can't write to this directory?
if (err is IOError.PERMISSION_DENIED || err is FileError.PERM) {
// Yes - display an alternate error message here.
AppWindow.error_message (
_ ("Photos couldn't create a file for editing this photo because you do not have permission to write to %s.").printf (photo.get_master_file ().get_parent ().get_path ()));
} else {
// No - something else is wrong, display the error message
// the system gave us.
AppWindow.error_message (Resources.launch_editor_failed (err));
}
}

public Gtk.ResponseType export_error_dialog (File dest, bool photos_remaining) {
string message = _ ("Unable to export the following photo due to a file error.\n\n") +
dest.get_path ();
Expand Down
8 changes: 0 additions & 8 deletions src/Resources.vala
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,11 @@ public const string EDIT_COMMENT_LABEL = _("Edit Comment");
public const string ADJUST_DATE_TIME_MENU = _("_Adjust Date and Time…");
public const string ADJUST_DATE_TIME_LABEL = _("Adjust Date and Time");

public const string OPEN_WITH_MENU = _("_Open In");

public const string OPEN_WITH_RAW_MENU = _("_Open With RAW Editor…");

public const string FIND_LABEL = _("Find");

public const string FLAG_MENU = _("_Flag");
public const string UNFLAG_MENU = _("Un_flag");

public string launch_editor_failed (Error err) {
return _("Unable to launch editor: %s").printf (err.message);
}

public string add_tags_label (string[] names) {
if (names.length == 1)
return _("Add Tag \"%s\"").printf (HierarchicalTagUtilities.get_basename (names[0]));
Expand Down
136 changes: 5 additions & 131 deletions src/Views/CollectionPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public abstract class CollectionPage : MediaPage {
private CollectionSearchViewFilter search_filter = new CollectionSearchViewFilter ();
private Gtk.ToggleButton? enhance_button = null;
private Gtk.Menu item_context_menu;
private Gtk.Menu open_menu;
private Gtk.Menu open_raw_menu;
private Gtk.MenuItem open_raw_menu_item;
private Gtk.Menu contractor_menu;
private Gtk.Button rotate_button;
private Gtk.Button flip_button;
Expand Down Expand Up @@ -175,16 +172,9 @@ public abstract class CollectionPage : MediaPage {
adjust_datetime_action.bind_property ("sensitive", adjust_datetime_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
adjust_datetime_menu_item.activate.connect (() => adjust_datetime_action.activate ());

open_menu = new Gtk.Menu ();

var open_menu_item = new Gtk.MenuItem.with_mnemonic (Resources.OPEN_WITH_MENU);
open_menu_item.set_submenu (open_menu);

open_raw_menu_item = new Gtk.MenuItem.with_mnemonic (Resources.OPEN_WITH_RAW_MENU);
var open_raw_action = get_action ("OpenWithRaw");
open_raw_action.bind_property ("sensitive", open_raw_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
open_raw_menu = new Gtk.Menu ();
open_raw_menu_item.set_submenu (open_raw_menu);
var open_menu_item = new Gtk.MenuItem.with_label (_("Show in Files")) {
action_name = AppWindow.ACTION_PREFIX + AppWindow.ACTION_JUMP_TO_FILE
};

var new_event_menu_item = new Gtk.MenuItem.with_mnemonic (Resources.NEW_EVENT_MENU);
var new_event_action = get_action ("NewEvent");
Expand Down Expand Up @@ -233,7 +223,6 @@ public abstract class CollectionPage : MediaPage {
item_context_menu.add (duplicate_menu_item);
item_context_menu.add (new Gtk.SeparatorMenuItem ());
item_context_menu.add (open_menu_item);
item_context_menu.add (open_raw_menu_item);
item_context_menu.add (contractor_menu_item);
item_context_menu.add (new Gtk.SeparatorMenuItem ());
item_context_menu.add (copy_color_menu_item);
Expand All @@ -252,33 +241,11 @@ public abstract class CollectionPage : MediaPage {
item_context_menu.add (trash_menu_item);
item_context_menu.show_all ();

int n_items = 0;
var source = get_view ().get_selected_at (0).source;
if (source != null && source is Photo) {
unowned var photo_file_format = ((Photo)source).get_master_file_format ();
n_items = populate_external_app_menu (
open_menu,
photo_file_format.get_mime_types (),
false
);

open_menu_item.sensitive = n_items > 0;

var source = get_view ().get_selected_at (0).source;
if (source != null && source is Photo) {
var file = (((Photo) source).get_file ());
wallpaper_menuitem.action_target = new Variant.string (file.get_uri ());

if (photo_file_format == PhotoFileFormat.RAW) {
n_items = populate_external_app_menu (
open_raw_menu,
{},
true
);

open_raw_menu_item.sensitive = n_items > 0;
}
}

open_raw_menu_item.visible = get_action ("OpenWithRaw").sensitive;
}

populate_contractor_menu (contractor_menu);
Expand Down Expand Up @@ -336,81 +303,6 @@ public abstract class CollectionPage : MediaPage {
action.sensitive = sensitive;
}

private int populate_external_app_menu (Gtk.Menu menu, string[] mime_types, bool raw) {
SortedList<AppInfo> external_apps;
int n_items = 0;

foreach (Gtk.Widget item in menu.get_children ()) {
menu.remove (item);
}

if (!raw) {
var files_appinfo = AppInfo.get_default_for_type ("inode/directory", true);
var files_item_icon = new Gtk.Image.from_gicon (
files_appinfo.get_icon (), Gtk.IconSize.MENU
) {
pixel_size = 16
};
var menuitem_grid = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
menuitem_grid.add (files_item_icon);
menuitem_grid.add (new Gtk.Label (files_appinfo.get_name ()));

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

var jump_menu_action = AppWindow.get_instance ().lookup_action (AppWindow.ACTION_JUMP_TO_FILE);
jump_menu_action.bind_property ("enabled", jump_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
jump_menu_item.activate.connect (() => jump_menu_action.activate (null));

menu.add (jump_menu_item);
}

if (mime_types.length > 0) {
external_apps = DesktopIntegration.get_apps_for_mime_types (mime_types);
foreach (AppInfo app in external_apps) {
var menu_item_icon = new Gtk.Image.from_gicon (
app.get_icon (),
Gtk.IconSize.MENU
) {
pixel_size = 16
};
var menuitem_grid = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
menuitem_grid.add (menu_item_icon);
menuitem_grid.add (new Gtk.Label (app.get_name ()));

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

item_app.activate.connect (() => {
if (raw)
on_open_with_raw (app.get_commandline ());
else
on_open_with (app.get_commandline ());
});
menu.add (item_app);
n_items++;
}
}

menu.show_all ();
return n_items;
}

private void on_open_with (string app) {
if (get_view ().get_selected_count () != 1)
return;

Photo? photo = get_view ().get_selected_at (0).source as Photo;
try {
AppWindow.get_instance ().set_busy_cursor ();
photo.open_with_external_editor (app);
AppWindow.get_instance ().set_normal_cursor ();
} catch (Error err) {
AppWindow.get_instance ().set_normal_cursor ();
open_external_editor_error_dialog (err, photo);
}
}

// Default behaviour for "Copy" action from Collection (thumbnail) view.
public static void get_image_data_for_clipboard (Gtk.Clipboard cb,
Gtk.SelectionData sd,
Expand Down Expand Up @@ -468,24 +360,6 @@ public abstract class CollectionPage : MediaPage {
clipboard.set_with_owner (COPY_TARGETS, get_image_data_for_clipboard, clear_data_for_clipboard, this);
}

private void on_open_with_raw (string app) {
if (get_view ().get_selected_count () != 1)
return;

Photo photo = (Photo) get_view ().get_selected_at (0).source;
if (photo.get_master_file_format () != PhotoFileFormat.RAW)
return;

try {
AppWindow.get_instance ().set_busy_cursor ();
photo.open_with_raw_external_editor (app);
AppWindow.get_instance ().set_normal_cursor ();
} catch (Error err) {
AppWindow.get_instance ().set_normal_cursor ();
AppWindow.error_message (Resources.launch_editor_failed (err));
}
}

private bool selection_has_video () {
return MediaSourceCollection.has_video ((Gee.Collection<MediaSource>) get_view ().get_selected_sources ());
}
Expand Down
Loading