Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
- Added support for dependencies and packages
- Added remaining templates
- Improved library list view
  • Loading branch information
kjlaw89 committed Jun 4, 2018
1 parent 149d11a commit 7fb4d4e
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 64 deletions.
4 changes: 2 additions & 2 deletions app
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ case $1 in
;;
"run")
initialize
./com.github.kjlaw89.archetype
./com.github.kjlaw89.archetype "${@:2}"
;;
"test")
test
;;
"test-run")
test
./com.github.kjlaw89.archetype
./com.github.kjlaw89.archetype "${@:2}"
;;
"uninstall")
initialize
Expand Down
3 changes: 3 additions & 0 deletions data/com.github.kjlaw89.archetype.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
<gresource prefix="/com/github/kjlaw89/archetype/templates">
<file alias="granite" compressed="true">templates/granite.tar.gz</file>
<file alias="utility" compressed="true">templates/utility.tar.gz</file>
<file alias="widget" compressed="true">templates/widget.tar.gz</file>
<file alias="blank" compressed="true">templates/blank.tar.gz</file>
<file alias="terminal" compressed="true">templates/terminal.tar.gz</file>
</gresource>
</gresources>
Binary file added data/templates/blank.tar.gz
Binary file not shown.
Binary file modified data/templates/granite.tar.gz
Binary file not shown.
Binary file added data/templates/terminal.tar.gz
Binary file not shown.
Binary file modified data/templates/utility.tar.gz
Binary file not shown.
Binary file added data/templates/widget.tar.gz
Binary file not shown.
16 changes: 8 additions & 8 deletions src/configs/Constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ namespace App.Configs {
public abstract const string [] ABOUT_AUTHORS = { "KJ Lawrence <[email protected]>" };
public abstract const Gtk.License ABOUT_LICENSE_TYPE = Gtk.License.GPL_3_0;
public abstract const App.Widgets.Library [] LIBRARIES = {
{ "libgranite-dev", "Granite", "elementary extended GTK+", true },
{ "libgtk-3-dev", "GTK+", "Gnome UI Toolkit", true },
{ "libsqlite-3-dev", "SQLite", "Local database storage", false },
{ "libunity-dev", "Unity", "Ubuntu Unity integration library", false },
{ "libappindicator3-dev", "App Indictator", "Desktop indicator icons", false },
{ "libsoup2.4-dev", "Soup", "HTTP(s) Requests", false },
{ "libjson-glib-dev", "JSON", "JSON Encoding/Decoding", false },
{ "granite", "libgranite-dev", "Granite", "elementary extended GTK+", true },
{ "gtk+-3.0", "libgtk-3-dev", "GTK+", "Gnome UI Toolkit", true },
{ "sqlite3", "libsqlite-3-dev", "SQLite", "Local database storage", false },
{ "unity", "libunity-dev", "Unity", "Ubuntu Unity integration library", false },
{ "appindicator3-0.1", "libappindicator3-dev", "App Indictator", "Desktop indicator icons", false },
{ "libsoup-2.4", "libsoup2.4-dev", "Soup", "HTTP(s) Requests", false },
{ "json-glib-1.0", "libjson-glib-dev", "JSON", "JSON Encoding/Decoding", false },
};
}
}
}
104 changes: 77 additions & 27 deletions src/models/Template.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace App.Models {
public bool git { get; set; default = false;}
public string libraries { get; set; }
public string license { get; set; }
public string packages { get; set; }
public string punchline { get; set; }
public string template { get; set; }
public string title { get; set; }
Expand Down Expand Up @@ -67,6 +68,7 @@ namespace App.Models {
this.git = view.git_switch.active;
this.libraries = view.libraries_list ();
this.license = view.license_combo.active_id;
this.packages = view.packages_list ();
this.punchline = view.punchline_entry.text;
this.template = view.template_combo.active_id;
this.title = view.title_entry.text;
Expand All @@ -75,8 +77,9 @@ namespace App.Models {
this.rdnn_path = "/" + rdnn.replace (".", "/") +"/";
this.website = view.website_entry.text;

// Add defaults to libraries
this.libraries = "meson, valac, debhelper, " + this.libraries;
// Add defaults to libraries (used in meson dependencies) and packages (use for apt dev packages)
this.libraries = "gobject-2.0, glib-2.0, " + this.libraries;
this.packages = "meson, valac, debhelper, " + this.packages;

// Get colors
headerbar_color = view.headerbar_color.hex ();
Expand Down Expand Up @@ -181,8 +184,9 @@ namespace App.Models {
* {{ repo-url }} - still need to get
* {{ website-url }} - still need to get
* {{ exe-name }} - replace with executable
* {{ libraries-control }} - replace with libraries (formatted for debian control file)
* {{ libraries-readme }} - replace with libraries formatted for README.md
* {{ libraries-control }} - replace with packages (formatted for debian control file)
* {{ libraries-readme }} - replace with packages formatted for README.md
* {{ libraries-meson }} - replace with libraries formatted for meson
* {{ screenshot-url }} - replace with nothing for now (no good way to get this)
* {{ app-center-bg }} - need to get
* {{ app-center-text }} - need to get
Expand All @@ -209,7 +213,8 @@ namespace App.Models {
}
}
catch (Error e) {
error ("Unable to get license " + e.message);
warning ("Unable to get license " + e.message);
return false;
}

var license_preamble_file = File.new_for_uri ("resource:///com/github/kjlaw89/archetype/licenses/"+ this.license +"-preamble");
Expand All @@ -222,7 +227,8 @@ namespace App.Models {
}
}
catch (Error e) {
error ("Unable to get license preamble " + e.message);
warning ("Unable to get license preamble " + e.message);
return false;
}

var dt = new DateTime.now_local ();
Expand All @@ -239,8 +245,9 @@ namespace App.Models {
replace_in_files (export_path, "{{ author }}", author);
replace_in_files (export_path, "{{ author-email }}", author_email);
replace_in_files (export_path, "{{ rdnn-path }}", rdnn_path);
replace_in_files (export_path, "{{ libraries-control }}", format_libraries_control (libraries));
replace_in_files (export_path, "{{ libraries-readme }}", format_libraries_readme (libraries));
replace_in_files (export_path, "{{ libraries-control }}", format_libraries_control (packages));
replace_in_files (export_path, "{{ libraries-readme }}", format_libraries_readme (packages));
replace_in_files (export_path, "{{ libraries-meson }}", format_libraries_meson (libraries));
replace_in_files (export_path, "{{ categories }}", "");
replace_in_files (export_path, "{{ keywords }}", "");
replace_in_files (export_path, "{{ terminal_mode }}", (template == "terminal" ? "true" : "false"));
Expand All @@ -254,7 +261,7 @@ namespace App.Models {
replace_in_files (export_path, "{{ resizable }}", (template == "utility" || template =="widget") ? "false" : "true");
replace_in_files (export_path, "/* {{ styles }} */", generate_styles ());
replace_in_files (export_path, "/* {{ dark-mode }} */", dark_mode ? "Gtk.Settings.get_default ().set (\"gtk-application-prefer-dark-theme\", true);" : "");
replace_in_files (export_path, "/* {{ headerbar-style-code }} */", (template == "utility" || template =="widget") ? "get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);" : "");
replace_in_files (export_path, "/* {{ headerbar-style-code }} */", (template == "utility") ? "get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);" : "");
replace_in_files (export_path, "/* {{ window-style-code }} */", generate_window_styles ());
replace_in_files (export_path, "com.generic.rdnn", rdnn);
replace_in_filenames (export_path, "com.generic.rdnn", rdnn);
Expand All @@ -269,11 +276,15 @@ namespace App.Models {

try {
if (!source_dir.move (dest_dir, FileCopyFlags.NONE)) {
error ("Unable to move temp directory to " + directory);
warning ("Unable to move temp directory to " + directory);
clean (rdnn);
return false;
}
}
catch (Error e) {
error ("Unable to move temp directory to "+ directory +" - "+ e.message);
warning ("Unable to move temp directory to "+ directory +" - "+ e.message);
clean (rdnn);
return false;
}


Expand Down Expand Up @@ -344,8 +355,14 @@ namespace App.Models {
var file_split = f.split (":");
var file = File.new_for_path (file_split[0]);
var new_name = file.get_basename ().replace (search, replace);
file.set_display_name (new_name);
modified++;

try {
file.set_display_name (new_name);
modified++;
}
catch (Error e) {
warning ("Unable to rename file "+ file_split[0] +" - "+ e.message);
}
}

return modified;
Expand All @@ -371,14 +388,19 @@ namespace App.Models {
}

private void initialize_git (string path) {
string[] init_args = { "git", "init" };
Process.spawn_sync (path, init_args, Environ.get (), SpawnFlags.SEARCH_PATH, null);
try {
string[] init_args = { "git", "init" };
Process.spawn_sync (path, init_args, Environ.get (), SpawnFlags.SEARCH_PATH, null);

string[] add_args = { "git", "add", "." };
Process.spawn_sync (path, add_args, Environ.get (), SpawnFlags.SEARCH_PATH, null);
string[] add_args = { "git", "add", "." };
Process.spawn_sync (path, add_args, Environ.get (), SpawnFlags.SEARCH_PATH, null);

string[] commit_args = { "git", "commit", "-m", "Initial commit for " + title };
Process.spawn_sync (path, commit_args, Environ.get (), SpawnFlags.SEARCH_PATH, null);
string[] commit_args = { "git", "commit", "-m", "Initial commit for " + title };
Process.spawn_sync (path, commit_args, Environ.get (), SpawnFlags.SEARCH_PATH, null);
}
catch (Error e) {
warning ("Unable to initialize GIT " + e.message);
}
}

private string format_libraries_control (string libraries) {
Expand Down Expand Up @@ -419,6 +441,30 @@ namespace App.Models {
return output;
}

private string format_libraries_meson (string libraries) {
var output = "";

var i = 0;
var libs = libraries.split (",");
foreach (var l in libs) {
var library = l.strip ();

if (i == 0) {
output = "dependency('"+ library +"'),\n";
}
else if (i == libs.length - 1) {
output += " dependency('"+ library +"')";
}
else {
output += " dependency('"+ library +"'),\n";
}

i++;
}

return output;
}

private string format_license_type (string license) {
switch (license) {
case "agpl-3.0":
Expand Down Expand Up @@ -469,15 +515,15 @@ namespace App.Models {
output += "/* @define-color colorAccent {{ accent-color }}; */\n";
}

// A utility should have the headerbar and body be the same color
// A widget should have the headerbar and body be the same color
// Use the font color specified for the headerbar for the primary font color
if (template == "utility") {
if (headerbar_color != null && headerbar_text_color != null) {
output += "AppWindow { background-color: %s; color: %s; }\n".printf (headerbar_color, headerbar_text_color);
}
else {
output += "/* AppWindow { background-color: {{ color-primary }}; color: {{ text-color-primary }}; } */n";
}
if (template == "widget") {
output += "@define-color bg_highlight_color shade (@colorPrimary, 1.4);\n\n";
output += ".titlebar, .background {\n";
output += " background-color: @colorPrimary; color: @textColorPrimary;\n";
output += " icon-shadow: 0 1px 1px shade (@textColorPrimaryShadow, 0.82)\n";
output += " text-shadow: 0 1px 1px shade (@textColorPrimaryShadow, 0.82);\n";
output += "}\n";
}

return output;
Expand All @@ -488,6 +534,10 @@ namespace App.Models {

switch (template) {
case "widget":
output += "get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);\n";
output += " set_keep_below (true);\n";
output += " stick ();";
break;
case "utility":
output += "get_style_context ().add_class (\"rounded\");";
break;
Expand Down
46 changes: 25 additions & 21 deletions src/views/AppView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ namespace App.Views {
public Gtk.Button next_button { get; private set; }
public Gtk.ComboBoxText license_combo { get; private set; }
public Gtk.Button license_lookup_button { get; private set; }
public Gtk.Button libraries_button { get; private set; }
public Gtk.ListBox libraries_listbox { get; private set; }
public Gtk.Popover libraries_popover { get; private set; }
public Gtk.Label libraries_values_label { get; private set; }
public Gtk.Entry libraries_values_entry { get; private set; }
public Gtk.Entry punchline_entry { get; private set; }
public Gtk.Entry repo_entry { get; private set; }
public Gtk.Stack stack_view { get; private set; }
Expand Down Expand Up @@ -322,8 +321,20 @@ namespace App.Views {
}

var output = string.joinv (", ", list.data);
libraries_values_entry.text = output;
return output;
}

libraries_values_label.label = output;
public string packages_list () {
var list = new Array<string?> ();
foreach (var widget in libraries_listbox.get_children ()) {
LibraryRow row = (LibraryRow)widget;
if (row.active) {
list.append_val (row.library.package);
}
}

var output = string.joinv (", ", list.data);
return output;
}

Expand Down Expand Up @@ -700,28 +711,21 @@ namespace App.Views {
libraries_label.valign = Gtk.Align.START;
libraries_label.margin_top = 4;

libraries_values_label = new Gtk.Label (null);
libraries_values_label.selectable = true;
libraries_values_label.halign = Gtk.Align.START;
libraries_values_label.margin_left = 12;
libraries_values_label.margin_right = 12;

var libraries_scrolled = new Gtk.ScrolledWindow (null, null);
libraries_scrolled.get_style_context ().add_class ("libraries_scrolled");
libraries_values_entry = new Gtk.Entry ();
libraries_values_entry.sensitive = true;
libraries_values_entry.secondary_icon_name = "tag-new";
libraries_values_entry.secondary_icon_tooltip_text = _("Modify selected libraries");

var libraries_viewport = new Gtk.Viewport (null, null);
libraries_viewport.add (libraries_values_label);
libraries_scrolled.add (libraries_viewport);
libraries_values_entry.key_press_event.connect ((event) => {
return true;
});

libraries_button = new Gtk.Button.from_icon_name ("tag-new", Gtk.IconSize.SMALL_TOOLBAR);
libraries_button.halign = Gtk.Align.START;
libraries_button.clicked.connect (() => {
libraries_values_entry.icon_release.connect ((pos, event) => {
show_libraries_list ();
});

grid.attach (libraries_label, 0, 2, 1, 1);
grid.attach (libraries_scrolled, 1, 2, 1, 1);
grid.attach (libraries_button, 2, 2, 1, 1);
grid.attach (libraries_values_entry, 1, 2, 3, 1);

// Repo entry
repo_entry = new Gtk.Entry ();
Expand Down Expand Up @@ -781,8 +785,8 @@ namespace App.Views {
libraries_scrolled.height_request = 250;
libraries_scrolled.add (libraries_viewport);

libraries_popover = new Gtk.Popover (libraries_button);
libraries_popover.position = Gtk.PositionType.BOTTOM;
libraries_popover = new Gtk.Popover (libraries_label);
libraries_popover.position = Gtk.PositionType.RIGHT;
libraries_popover.add (libraries_scrolled);
libraries_popover.closed.connect (() => {
this.libraries_list ();
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/LibraryRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ namespace App.Widgets {

public struct Library {
public string library;
public string package;
public string name;
public string description;
public bool is_default;
}
}
}
13 changes: 8 additions & 5 deletions tests/test.vala
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,16 @@ namespace App.Tests {

Test.add_data_func ("/app/form/libraries_list", () => {
var view = new App.Views.AppView ();
Assert.string_compare ("libgranite-dev, libgtk-3-dev", view.libraries_list ());
Assert.string_compare ("granite, gtk+-3.0", view.libraries_list ());
Assert.string_compare ("libgranite-dev, libgtk-3-dev", view.packages_list ());

view.toggle_library ("libunity-dev", true);
Assert.string_compare ("libgranite-dev, libgtk-3-dev, libunity-dev", view.libraries_list ());
view.toggle_library ("unity", true);
Assert.string_compare ("granite, gtk+-3.0, unity", view.libraries_list ());
Assert.string_compare ("libgranite-dev, libgtk-3-dev, libunity-dev", view.packages_list ());

view.toggle_library ("libgranite-dev", false);
Assert.string_compare ("libgtk-3-dev, libunity-dev", view.libraries_list ());
view.toggle_library ("granite", false);
Assert.string_compare ("gtk+-3.0, unity", view.libraries_list ());
Assert.string_compare ("libgtk-3-dev, libunity-dev", view.packages_list ());
});

Test.add_data_func ("/template/setup", () => {
Expand Down

0 comments on commit 7fb4d4e

Please sign in to comment.