Skip to content

Commit 2f86c0c

Browse files
committed
Support multiple files
Fixes: #12
1 parent e34a4dc commit 2f86c0c

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

data/com.github.peteruithoven.resizer.contract

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Name=Resize image
33
Description=Resize image
44
MimeType=image
55
Icon=com.github.peteruithoven.resizer
6-
Exec=com.github.peteruithoven.resizer %f
6+
Exec=com.github.peteruithoven.resizer %F

src/Application.vala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ namespace Resizer {
4141
}
4242

4343
public override void open (File[] files, string hint) {
44-
// TODO: throw error when multiple files or handle multiple files
45-
foreach (var file in files) {
46-
Resizer.file = file;
47-
}
44+
Resizer.files = files;
4845
activate();
4946
}
5047

src/Resizer.vala

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,25 @@ namespace Resizer {
2323
public class Resizer : Object {
2424
public static int maxWidth = 1000;
2525
public static int maxHeight = 1000;
26-
public static File file;
26+
public static File[] files;
2727

2828
public static void create_resized_image() {
29-
var input_name = file.get_path ();
30-
var output_name = get_output_name (input_name, maxWidth, maxHeight);
29+
foreach (var file in files) {
30+
stdout.printf ("resizing: %s\n", file.get_path ());
3131

32-
try {
33-
string[] command = get_command(input_name, output_name, maxWidth, maxHeight);
34-
new Subprocess.newv (command, SubprocessFlags.STDERR_PIPE);
35-
// Subprocess subprocess = new Subprocess.newv (command, SubprocessFlags.STDERR_PIPE);
36-
// if (subprocess.wait_check ()) {
37-
// stdout.printf ("Success!\n");
38-
// }
39-
} catch (Error e) {
40-
stderr.printf ("Error during resize: %s", e.message);
32+
var input_name = file.get_path ();
33+
var output_name = get_output_name (input_name, maxWidth, maxHeight);
34+
35+
try {
36+
string[] command = get_command(input_name, output_name, maxWidth, maxHeight);
37+
new Subprocess.newv (command, SubprocessFlags.STDERR_PIPE);
38+
// Subprocess subprocess = new Subprocess.newv (command, SubprocessFlags.STDERR_PIPE);
39+
// if (subprocess.wait_check ()) {
40+
// stdout.printf ("Success!\n");
41+
// }
42+
} catch (Error e) {
43+
stderr.printf ("Error during resize: %s", e.message);
44+
}
4145
}
4246
}
4347
public static string get_output_name(string input, int width, int height) {

0 commit comments

Comments
 (0)