From 65f17941ad0e2d91cd5c4e9e290c45c8cb61ac0e Mon Sep 17 00:00:00 2001 From: Bart Zaalberg Date: Mon, 16 Oct 2017 10:37:06 +0200 Subject: [PATCH] Added run shortcut (ctrl + r) --- ...github.bartzaalberg.php-tester.appdata.xml | 1 + debian/changelog | 6 +++++ src/Components/HeaderBar.vala | 21 +----------------- src/FileManager.vala | 22 +++++++++++++++++++ src/MainWindow.vala | 13 +++++++++++ 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/data/com.github.bartzaalberg.php-tester.appdata.xml b/data/com.github.bartzaalberg.php-tester.appdata.xml index 2cc93e1..9e3cba0 100644 --- a/data/com.github.bartzaalberg.php-tester.appdata.xml +++ b/data/com.github.bartzaalberg.php-tester.appdata.xml @@ -11,6 +11,7 @@ diff --git a/debian/changelog b/debian/changelog index 46efd8d..6d1e5e4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +com.github.bartzaalberg.php-tester (1.1.4) UNSTABLE; urgency=low + + * Added run shortcut (ctrl + r) + + -- Bart Zaalberg Mon, 16 Oct 2017 10:36:00 +0200 + com.github.bartzaalberg.php-tester (1.1.3) UNSTABLE; urgency=low * Added a button to copy the text diff --git a/src/Components/HeaderBar.vala b/src/Components/HeaderBar.vala index bd66c30..746d3d9 100644 --- a/src/Components/HeaderBar.vala +++ b/src/Components/HeaderBar.vala @@ -13,26 +13,7 @@ public class HeaderBar : Gtk.HeaderBar { var start_button = new Gtk.Button.with_label ("Run"); start_button.margin_end = 12; start_button.clicked.connect (() => { - fileManager.writeToFile(); - - string result; - string error; - int status; - - try { - Process.spawn_command_line_sync ("php phptest.php", - out result, - out error, - out status); - - sourceViewManager.setResult(result); - if(error != null && error != ""){ - new Alert("PHP error",error); - } - - } catch (SpawnError e) { - new Alert("An error occured", e.message); - } + fileManager.runCode(); }); var copy_button = new Gtk.Button.with_label ("Copy"); diff --git a/src/FileManager.vala b/src/FileManager.vala index 928bcc7..c741acb 100644 --- a/src/FileManager.vala +++ b/src/FileManager.vala @@ -48,5 +48,27 @@ public class FileManager : Object { } return file; } + + public void runCode(){ + writeToFile(); + string result; + string error; + int status; + + try { + Process.spawn_command_line_sync ("php phptest.php", + out result, + out error, + out status); + + sourceViewManager.setResult(result); + if(error != null && error != ""){ + new Alert("PHP error",error); + } + + } catch (SpawnError e) { + new Alert("An error occured", e.message); + } + } } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 62b0650..18960bd 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -4,6 +4,7 @@ namespace RepositoriesManager { public class MainWindow : Gtk.Window{ private SourceViewManager sourceViewManager = SourceViewManager.get_instance(); + private FileManager fileManager = FileManager.get_instance(); Gtk.TextView view; Gtk.Label resultLabel; @@ -29,6 +30,18 @@ public class MainWindow : Gtk.Window{ pane.pack2 (result_box, false, false); add (pane); + + key_press_event.connect ((e) => { + switch (e.keyval) { + case Gdk.Key.r: + if ((e.state & Gdk.ModifierType.CONTROL_MASK) != 0) { + fileManager.runCode(); + } + break; + } + + return false; + }); } } }