From 62522db8527bc8054f1884d34600c57ec04dcb91 Mon Sep 17 00:00:00 2001 From: Bart Zaalberg Date: Fri, 6 Oct 2017 17:08:11 +0200 Subject: [PATCH] Refactored some code, changed some text, exracted some functions --- CMakeLists.txt | 1 + debian/changelog | 4 ++-- src/Application.vala | 6 +++--- src/Components/HeaderBar.vala | 35 +++----------------------------- src/FileWriter.vala | 38 +++++++++++++++++++++++++++++++++++ src/MainWindow.vala | 6 ------ 6 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 src/FileWriter.vala diff --git a/CMakeLists.txt b/CMakeLists.txt index acae27f..a277515 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ src/ListManager.vala src/Dialogs/Alert.vala src/Components/HeaderBar.vala + src/FileWriter.vala # tell what libraries to use when compiling PACKAGES diff --git a/debian/changelog b/debian/changelog index b38e043..a0fbaa8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,5 @@ -com.github.bartzaalberg.bookmark-manager (0.0.1) UNSTABLE; urgency=low +com.github.bartzaalberg.bookmark-manager (1.0.0) UNSTABLE; urgency=low * First release - -- Bart Zaalberg Wed, 04 Oct 2017 13:12:00 +0200 + -- Bart Zaalberg Wed, 06 Oct 2017 17:07:00 +0200 diff --git a/src/Application.vala b/src/Application.vala index 95c853f..47c4886 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -11,9 +11,9 @@ public class App:Granite.Application{ app_launcher = Constants.DESKTOP_NAME; build_version = Constants.VERSION; - app_icon = "com.github.bartzaalberg.repositories"; - main_url = "https://github.com/bartzaalberg/repositories"; - bug_url = "https://github.com/bartzaalberg/repositories/issues"; + app_icon = "com.github.bartzaalberg.php-tester"; + main_url = "https://github.com/bartzaalberg/php-tester"; + bug_url = "https://github.com/bartzaalberg/php-tester/issues"; } public override void activate() { diff --git a/src/Components/HeaderBar.vala b/src/Components/HeaderBar.vala index a656771..f4d15cd 100644 --- a/src/Components/HeaderBar.vala +++ b/src/Components/HeaderBar.vala @@ -9,7 +9,8 @@ public class HeaderBar : Gtk.HeaderBar { var start_button = new Gtk.Button.with_label ("Run Code"); start_button.margin_end = 12; start_button.clicked.connect (() => { - writeToFile(); + var fileWriter = new FileWriter(); + fileWriter.writeToFile(); string result; string error; @@ -23,7 +24,7 @@ public class HeaderBar : Gtk.HeaderBar { listManager.setResult(result); if(error != null && error != ""){ - listManager.setResult(error); + new Alert("PHP error",error); } } catch (SpawnError e) { @@ -39,35 +40,5 @@ public class HeaderBar : Gtk.HeaderBar { this.pack_start (button_box); } - - public void writeToFile(){ - var file = getCodeTestFile(); - - try { - if(file.query_exists() == true){ - - file.delete(null); - FileOutputStream fos = file.create (FileCreateFlags.REPLACE_DESTINATION, null); - DataOutputStream dos = new DataOutputStream (fos); - dos.put_string (listManager.getView().buffer.text, null); - } - } catch (Error e) { - new Alert ("An error Occurred", e.message); - } - } - - public File getCodeTestFile(){ - - var file = File.new_for_path ("phptest.php"); - if (!file.query_exists ()) { - try { - file.create (FileCreateFlags.REPLACE_DESTINATION, null); - getCodeTestFile(); - } catch (Error e) { - error ("%s", e.message); - } - } - return file; - } } } diff --git a/src/FileWriter.vala b/src/FileWriter.vala new file mode 100644 index 0000000..06728dd --- /dev/null +++ b/src/FileWriter.vala @@ -0,0 +1,38 @@ +using Granite.Widgets; + +namespace RepositoriesManager { +public class FileWriter : Object { + + ListManager listManager = ListManager.get_instance(); + + public void writeToFile(){ + var file = getCodeTestFile(); + + try { + if(file.query_exists() == true){ + + file.delete(null); + FileOutputStream fos = file.create (FileCreateFlags.REPLACE_DESTINATION, null); + DataOutputStream dos = new DataOutputStream (fos); + dos.put_string (listManager.getView().buffer.text, null); + } + } catch (Error e) { + new Alert ("An error Occurred", e.message); + } + } + + public File getCodeTestFile(){ + + var file = File.new_for_path ("phptest.php"); + if (!file.query_exists ()) { + try { + file.create (FileCreateFlags.REPLACE_DESTINATION, null); + getCodeTestFile(); + } catch (Error e) { + error ("%s", e.message); + } + } + return file; + } +} +} diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 5e47005..0ebc7f7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -15,12 +15,6 @@ public class MainWindow : Gtk.Window{ view = listManager.getView(); view.buffer.text = " { - listManager.setResult("vka"); - }); - Gtk.ScrolledWindow result_box = new Gtk.ScrolledWindow(null, null); result_box.set_border_width (10); result_box.set_size_request (200,200);