Skip to content

Commit

Permalink
Format selection buxfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaroslav Staněk (Datalife) committed Jul 14, 2022
1 parent 60426ca commit a23cf18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
15 changes: 11 additions & 4 deletions src/Prettify.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ using App.Configs;
namespace App{
public class Prettify : GLib.Object{

public TypeOfFile type_of_file { get; set;}

public Prettify(){
}

public string prettify(string text, int indent){
switch (this.type_of_file) {
switch (this.get_type_of_file()) {
case TypeOfFile.JSON:
return this.prettify_json(text, indent);
case TypeOfFile.XML:
Expand Down Expand Up @@ -46,10 +45,18 @@ namespace App{
}

public void prettify_action(Gtk.SourceView input, Gtk.SourceView output, int indent){
string prettified_text = this.prettify(input.buffer.text, indent);
output.buffer.text = prettified_text;
output.buffer.text = this.prettify(input.buffer.text, indent);
Application.settings.set_string ("input-text", input.buffer.text);
Application.settings.set_string ("output-text", output.buffer.text);
}

public TypeOfFile get_type_of_file(){
return (TypeOfFile)Application.settings.get_enum("selected-format");
}

public void set_type_of_file(TypeOfFile tof){
Application.settings.set_enum("selected-format", tof);
}

}
}
13 changes: 2 additions & 11 deletions src/widgets/ControlPanel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace App.Widgets{
public Gtk.Button prettify_button { get; private set;}
public Gtk.ComboBoxText format_combobox { get; private set;}
public Gtk.ComboBoxText color_scheme_combobox { get; private set;}
public Gtk.Button format_json {get; private set;}
public Gtk.Button format_xml {get; private set;}
public Gtk.Button copy_to_clipboard {get; private set;}
public Gtk.Button reset_button {get; private set;}
public Gtk.SpinButton indent_num {get; private set;}
Expand All @@ -20,9 +18,6 @@ namespace App.Widgets{
private App.Prettify prettify {get; private set;}

public ControlPanel(App.Controllers.AppController app) {
// var icon = new Gtk.Button.from_icon_name ("object-inverse", Gtk.IconSize.BUTTON);
// var item = new Gtk.ToolButton (icon, "test");
// this.insert (item, 0);

//Initialization of properties of "this"
init_control_panel(app);
Expand All @@ -46,10 +41,9 @@ namespace App.Widgets{
this.format_combobox.valign = Gtk.Align.CENTER;
this.format_combobox.append_text (_("JSON"));
this.format_combobox.append_text (_("XML"));
this.format_combobox.active = Application.settings.get_enum ("selected-format");
this.format_combobox.active = this.prettify.get_type_of_file();
this.format_combobox.changed.connect (() => {
prettify.type_of_file = (TypeOfFile)this.format_combobox.active;
Application.settings.set_enum ("selected-format", prettify.type_of_file);
this.prettify.set_type_of_file((TypeOfFile)this.format_combobox.active);
if(auto_prettify.active) this.app.app_view.run_prettify();
});

Expand Down Expand Up @@ -137,8 +131,5 @@ namespace App.Widgets{
this.pack_start(sep);
}




}
}

0 comments on commit a23cf18

Please sign in to comment.