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

[GTK4 Prep] Move External App Actions Logic To Utils #1455

Merged
merged 11 commits into from
Jul 25, 2024
Prev Previous commit
Refactor contract methods in Utils so file_type is no longer used
  • Loading branch information
colinkiama committed Jul 25, 2024
commit 9081261d04e1077bb60a9e038b983839ead26647
5 changes: 1 addition & 4 deletions src/FolderManager/FileItem.vala
Original file line number Diff line number Diff line change
@@ -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,
7 changes: 1 addition & 6 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
@@ -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) {
5 changes: 1 addition & 4 deletions src/FolderManager/FolderItem.vala
Original file line number Diff line number Diff line change
@@ -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,
10 changes: 5 additions & 5 deletions src/Utils.vala
Original file line number Diff line number Diff line change
@@ -232,19 +232,19 @@ 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) {
action_name = Scratch.FolderManager.FileView.ACTION_PREFIX
+ 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];