Merge lp:~jeremywootten/pantheon-files/fix-1669996-execute-edit-script-choice into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Rejected
Rejected by: Danielle Foré
Proposed branch: lp:~jeremywootten/pantheon-files/fix-1669996-execute-edit-script-choice
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 137 lines (+91/-2)
4 files modified
libcore/gof-file.c (+1/-1)
src/CMakeLists.txt (+2/-0)
src/Dialogs/ConfirmExecuteDialog.vala (+79/-0)
src/View/AbstractDirectoryView.vala (+9/-1)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-1669996-execute-edit-script-choice
Reviewer Review Type Date Requested Status
Danielle Foré Disapprove
Review via email: mp+319640@code.launchpad.net

Commit message

Confirm execution of script or other executable when clicked on.

Description of the change

This branch shows a dialog if an executable script (or x-application) is clicked on, asking to confirm execution of the file and, if a default application is available, giving the option to open it with the default application instead.

The dialog does not appear if "Run" is deliberately chosen from the context menu.

To post a comment you must log in.
Revision history for this message
David Hewitt (davidmhewitt) wrote :

Code looks good, haven't tested yet. One minor comment about the wording. Does it make more sense to say "This file may be run as a program..." or maybe even "application" instead of "program" instead of "This file may be executed as a program"?

I feel as though run would be more widely understood than execute.

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

The wording is provisional and needs UX team approval really. I do not think "application" is necessarily correct - the file is likely to be a script which is not an application in the normal sense. Indeed, strictly speaking, it is not definitely a program is it? - it is a file with the attribute of being executable. I used the plainer word "Run" in the main message and the more technical word "execute" in the detailed message, but I am open to using the same word everywhere.

Revision history for this message
Danielle Foré (danrabbit) wrote :

I'm kind of -1 on this branch. Throwing a dialog doesn't make it faster for people who want to run the script. It's still two clicks, but now there's an annoying dialog in the way whenever I want to edit a script. And I'm a bit of the position that I'm going to be executing scripts from Terminal anyways because I want the output.

review: Disapprove

Unmerged revisions

2522. By Jeremy Wootten

Implement ConfirmExecuteDialog

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libcore/gof-file.c'
2--- libcore/gof-file.c 2017-02-26 04:50:36 +0000
3+++ libcore/gof-file.c 2017-03-11 18:39:16 +0000
4@@ -1477,7 +1477,7 @@
5 /* check for .exe, .bar or .com */
6 can_execute = g_content_type_can_be_executable (content_type);
7 #else
8- /* check if the content type is save to execute, we don't use
9+ /* check if the content type is safe to execute, we don't use
10 * g_content_type_can_be_executable() for unix because it also returns
11 * true for "text/plain" and we don't want that */
12 if (g_content_type_is_a (content_type, "application/x-executable")
13
14=== modified file 'src/CMakeLists.txt'
15--- src/CMakeLists.txt 2017-02-01 14:42:37 +0000
16+++ src/CMakeLists.txt 2017-03-11 18:39:16 +0000
17@@ -81,6 +81,7 @@
18 Thumbnailer.vala
19 Dialogs/AbstractPropertiesDialog.vala
20 Dialogs/ChooseAppDialog.vala
21+ Dialogs/ConfirmExecuteDialog.vala
22 Dialogs/PropertiesWindow.vala
23 Dialogs/VolumePropertiesWindow.vala
24 Utils/MimeActions.vala
25@@ -147,6 +148,7 @@
26 Thumbnailer.vala
27 Dialogs/AbstractPropertiesDialog.vala
28 Dialogs/ChooseAppDialog.vala
29+ Dialogs/ConfirmExecuteDialog.vala
30 Dialogs/PropertiesWindow.vala
31 Dialogs/VolumePropertiesWindow.vala
32 Utils/MimeActions.vala
33
34=== added file 'src/Dialogs/ConfirmExecuteDialog.vala'
35--- src/Dialogs/ConfirmExecuteDialog.vala 1970-01-01 00:00:00 +0000
36+++ src/Dialogs/ConfirmExecuteDialog.vala 2017-03-11 18:39:16 +0000
37@@ -0,0 +1,79 @@
38+/*
39+* Copyright (c) 2017 elementary LLC (http://launchpad.net/pantheon-files)
40+*
41+* This program is free software; you can redistribute it and/or
42+* modify it under the terms of the GNU General Public
43+* License as published by the Free Software Foundation, Inc.,; either
44+* version 3 of the License, or (at your option) any later version.
45+*
46+* This program is distributed in the hope that it will be useful,
47+* but WITHOUT ANY WARRANTY; without even the implied warranty of
48+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
49+* General Public License for more details.
50+*
51+* You should have received a copy of the GNU General Public
52+* License along with this program; if not, write to the
53+* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
54+* Boston, MA 02110-1335 USA.
55+*
56+* Authored by: Jeremy Wootten <jeremy@elementaryos.org>
57+*/
58+
59+public class PF.ConfirmExecuteDialog : Object {
60+ public enum Response {
61+ CANCEL,
62+ EXECUTE,
63+ OPEN
64+ }
65+
66+ private Gtk.MessageDialog dialog;
67+ public GOF.File file {get; construct;}
68+ public GLib.AppInfo? default_app {get; construct;}
69+ public Gtk.Window? parent {get; construct;}
70+
71+ public ConfirmExecuteDialog (GOF.File _file, GLib.AppInfo? _default_app, Gtk.Window? _parent) {
72+ Object (file: _file,
73+ default_app: _default_app,
74+ parent: _parent
75+ );
76+ }
77+
78+ construct {
79+ string primary_text, secondary_text;
80+
81+ if (default_app != null) {
82+ primary_text = _("Run or Open this File?").printf (file.basename);
83+ secondary_text = _("This file may be executed as a program or opened with the default application (%s).\n\nOnly execute files that you know to be safe").printf (default_app.get_name ());
84+ } else {
85+ primary_text = _("Run this File?").printf (file.basename);
86+ secondary_text = _("This file may be executed as a program.\n\nOnly execute files that you know to be safe").printf (default_app.get_name ());
87+ }
88+
89+ dialog = new Gtk.MessageDialog (parent,
90+ Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
91+ Gtk.MessageType.QUESTION,
92+ Gtk.ButtonsType.NONE,
93+ primary_text);
94+
95+ dialog.secondary_text = secondary_text;
96+
97+ dialog.add_button (_("Execute"), Response.EXECUTE);
98+ dialog.add_button (_("Cancel"), Response.CANCEL);
99+
100+ /* Set safer option to be the default */
101+ if (default_app != null) {
102+ dialog.add_button (_("Open"), Response.OPEN);
103+ dialog.set_default_response (Response.OPEN);
104+ } else {
105+ dialog.set_default_response (Response.CANCEL);
106+ }
107+
108+ dialog.show_all ();
109+ }
110+
111+ public Response run () {
112+ var res = dialog.run ();
113+ dialog.destroy ();
114+ return (Response)res;
115+ }
116+}
117
118=== modified file 'src/View/AbstractDirectoryView.vala'
119--- src/View/AbstractDirectoryView.vala 2017-02-15 18:54:50 +0000
120+++ src/View/AbstractDirectoryView.vala 2017-03-11 18:39:16 +0000
121@@ -795,7 +795,15 @@
122 if (file.is_root_network_folder ()) {
123 load_location (location);
124 } else if (file.is_executable ()) {
125- file.execute (screen, null, null);
126+ var dialog = new PF.ConfirmExecuteDialog (file, default_app, window);
127+ switch (dialog.run ()) { /* dialog destroys itself */
128+ case PF.ConfirmExecuteDialog.Response.EXECUTE:
129+ file.execute (screen, null, null);
130+ break;
131+ case PF.ConfirmExecuteDialog.Response.OPEN:
132+ open_file (file, screen, default_app);
133+ break;
134+ }
135 } else {
136 open_file (file, screen, default_app);
137 }

Subscribers

People subscribed via source and target branches

to all changes: