Skip to content

Commit

Permalink
Refactor contract methods in Utils so file_type is no longer used
Browse files Browse the repository at this point in the history
  • Loading branch information
colinkiama committed Jul 25, 2024
1 parent f1d903e commit 9081261
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
5 changes: 1 addition & 4 deletions src/FolderManager/FileItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions src/FolderManager/FolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
)
};

Expand All @@ -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];
Expand Down

0 comments on commit 9081261

Please sign in to comment.