Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Refactored some code, changed some text, exracted some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Zaalberg committed Oct 6, 2017
1 parent 275b35e commit 62522db
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 43 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <bartzaalberg@gmail.com> Wed, 04 Oct 2017 13:12:00 +0200
-- Bart Zaalberg <bartzaalberg@gmail.com> Wed, 06 Oct 2017 17:07:00 +0200
6 changes: 3 additions & 3 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
35 changes: 3 additions & 32 deletions src/Components/HeaderBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
}
}
38 changes: 38 additions & 0 deletions src/FileWriter.vala
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
6 changes: 0 additions & 6 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ public class MainWindow : Gtk.Window{
view = listManager.getView();
view.buffer.text = "<?php\n";

var new_button = new Gtk.Button.with_label ("change dinges");
new_button.margin_end = 12;
new_button.clicked.connect (() => {
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);
Expand Down

0 comments on commit 62522db

Please sign in to comment.