Skip to content

Commit

Permalink
Move open_external to the View
Browse files Browse the repository at this point in the history
  • Loading branch information
ryonakano committed Sep 28, 2024
1 parent bdf21c7 commit 0775766
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
25 changes: 0 additions & 25 deletions src/Model/DesktopFile.vala
Original file line number Diff line number Diff line change
Expand Up @@ -416,29 +416,4 @@ public class Model.DesktopFile : Object {

return ret;
}

/**
* Open the desktop file associated with this in an external editor.
*
* @param parent the parent GtkWindow
* @return true if successfully opened this, false otherwise
* @throws Error failed to open this externally
*/
public async bool open_external (Gtk.Window? parent) throws Error {
var file = File.new_for_path (path);

var file_launcher = new Gtk.FileLauncher (file) {
always_ask = true
};

bool ret = false;
try {
ret = yield file_launcher.launch (parent, null);
} catch (Error err) {
warning ("Failed to open file externally. path=%s: %s", path, err.message);
throw err;
}

return ret;
}
}
22 changes: 20 additions & 2 deletions src/View/EditView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ public class View.EditView : Adw.NavigationPage {
});

open_text_editor_button.clicked.connect (() => {
desktop_file.open_external.begin ((Gtk.Window) get_root (), (obj, res) => {
open_external.begin (desktop_file.path, (obj, res) => {
bool ret;

try {
ret = desktop_file.open_external.end (res);
ret = open_external.end (res);
} catch (Error err) {
// The calling method is responsible for showing the error log.

Expand Down Expand Up @@ -494,4 +494,22 @@ public class View.EditView : Adw.NavigationPage {
private void set_save_button_sensitivity () {
save_button.sensitive = (name_entry.text.length > 0 && exec_entry.text.length > 0);
}

private async bool open_external (string path) throws Error {
var file = File.new_for_path (path);

var file_launcher = new Gtk.FileLauncher (file) {
always_ask = true
};

bool ret = false;
try {
ret = yield file_launcher.launch ((Gtk.Window) get_root (), null);
} catch (Error err) {
warning ("Failed to open file externally. path=%s: %s", path, err.message);
throw err;
}

return ret;
}
}

0 comments on commit 0775766

Please sign in to comment.