From 9081261d04e1077bb60a9e038b983839ead26647 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Thu, 25 Jul 2024 09:19:56 +0100 Subject: [PATCH] Refactor contract methods in Utils so file_type is no longer used --- src/FolderManager/FileItem.vala | 5 +---- src/FolderManager/FileView.vala | 7 +------ src/FolderManager/FolderItem.vala | 5 +---- src/Utils.vala | 10 +++++----- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/FolderManager/FileItem.vala b/src/FolderManager/FileItem.vala index 7cc8f8642..d933081f0 100644 --- a/src/FolderManager/FileItem.vala +++ b/src/FolderManager/FileItem.vala @@ -70,10 +70,7 @@ namespace Scratch.FolderManager { open_in_item.submenu = open_in_menu; var contractor_item = new Gtk.MenuItem.with_label (_("Other Actions")); - contractor_item.submenu = Utils.create_contract_items_for_file ( - file.file, - file_type - ); + contractor_item.submenu = Utils.create_contract_items_for_file (file.file); var rename_item = new Gtk.MenuItem.with_label (_("Rename")) { action_name = FileView.ACTION_PREFIX + FileView.ACTION_RENAME_FILE, diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index 034780f8f..94e037427 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -467,12 +467,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane return; } - var file_type = params[2]; - if (file_type == null || file_type == "") { - return; - } - - Utils.execute_contract_with_file_path (path, contract_name, file_type); + Utils.execute_contract_with_file_path (path, contract_name); } private void action_rename_file (SimpleAction action, Variant? param) { diff --git a/src/FolderManager/FolderItem.vala b/src/FolderManager/FolderItem.vala index 2ee9a38d4..af1723515 100644 --- a/src/FolderManager/FolderItem.vala +++ b/src/FolderManager/FolderItem.vala @@ -104,10 +104,7 @@ namespace Scratch.FolderManager { var file_type = info.get_content_type (); var contractor_item = new Gtk.MenuItem.with_label (_("Other Actions")); - contractor_item.submenu = Utils.create_contract_items_for_file ( - file.file, - file_type - ); + contractor_item.submenu = Utils.create_contract_items_for_file (file.file); var rename_menu_item = new Gtk.MenuItem.with_label (_("Rename")) { action_name = FileView.ACTION_PREFIX + FileView.ACTION_RENAME_FOLDER, diff --git a/src/Utils.vala b/src/Utils.vala index 5cf97294d..c80d979e0 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -232,11 +232,11 @@ namespace Scratch.Utils { } } - public Gtk.Menu create_contract_items_for_file (GLib.File file, string file_type) { + public Gtk.Menu create_contract_items_for_file (GLib.File file) { var menu = new Gtk.Menu (); try { - var contracts = Granite.Services.ContractorProxy.get_contracts_by_mime (file_type); + var contracts = Granite.Services.ContractorProxy.get_contracts_for_file (file); foreach (var contract in contracts) { string contract_name = contract.get_display_name (); var menu_item = new Gtk.MenuItem.with_label (contract_name) { @@ -244,7 +244,7 @@ namespace Scratch.Utils { + Scratch.FolderManager.FileView.ACTION_EXECUTE_CONTRACT_WITH_FILE_PATH, action_target = new GLib.Variant.array ( GLib.VariantType.STRING, - { file.get_path (), contract_name, file_type } + { file.get_path (), contract_name } ) }; @@ -257,11 +257,11 @@ namespace Scratch.Utils { return menu; } - public void execute_contract_with_file_path (string path, string contract_name, string file_type) { + public void execute_contract_with_file_path (string path, string contract_name) { var file = GLib.File.new_for_path (path); try { - var contracts = Granite.Services.ContractorProxy.get_contracts_by_mime (file_type); + var contracts = Granite.Services.ContractorProxy.get_contracts_for_file (file); int length = contracts.size; for (int i = 0; i < length; i++) { var contract = contracts[i];