public void SaveConfig(string filename, PrettyPrinterOptions options)
 {
     try
     {
         if (!File.Exists(filename))
         {
             string path = Path.GetDirectoryName(filename);
             if (!Directory.Exists(path))
             {
                 Directory.CreateDirectory(path);
             }
         }
         using (StreamWriter sw = new StreamWriter(filename))
         {
             XmlSerializer xs = new XmlSerializer(typeof(PrettyPrinterOptions));
             xs.Serialize(sw, options);
             sw.Close();
         }
     }
     catch (Exception e)
     {
         Console.Error.WriteLine("Couldn't save configuration file {0}.\nCause: {1}",
                                 filename, e);
     }
 }
示例#2
0
        public static string Print(JsonElement element, PrettyPrinterOptions options = null)
        {
            if (options == null)
            {
                options = PrettyPrinterOptions.Default;
            }
            var doc      = PrintImpl(element, options.Indentation);
            var renderer = new Renderer(options.MaxColumn);

            return(renderer.Render(doc));
        }
    public GASNViewerApp(string[] args)
    {
        Application.Init();
        Glade.XML xml = new Glade.XML(null, "gui.glade", "gasnview", null);
        xml.Autoconnect(this);

        options = LoadConfig(config);
        UpdateOptions();

        // load cache
        PrettyPrinter.Cache.Load(cache);

        // UI preparation
        fileexportimage.Pixbuf = new Pixbuf(null, "export.png");
        file_export.Image      = new Gtk.Image(new Pixbuf(null, "export-16.png"));
        textview1.Editable     = false;
        textview1.GrabFocus();
        Font                = options.FontName;
        findfwd             = textview1.Buffer.StartIter;
        findbck             = textview1.Buffer.EndIter;
        findstart           = -1;
        findend             = -1;
        highlight_on        = new Pixbuf(null, "text_hilight-16.png");
        highlight_off       = new Pixbuf(null, "text_lolight-16.png");
        findhighlight       = false;
        findnormalbasecolor = findentry.Style.Base(StateType.Normal);
        try
        {
            // GTK# bug - entry point was missing in early 1.0.x versions
            findnormaltextcolor = findentry.Style.Text(StateType.Normal);
        }
        catch (EntryPointNotFoundException)
        {
            findnormaltextcolor = new Gdk.Color(0x00, 0x00, 0x00);
        }
        finderrorbasecolor = new Gdk.Color(0xff, 0x00, 0x00);
        finderrortextcolor = new Gdk.Color(0xff, 0xff, 0xff);

        highlight = new TextTag("highlight");
        highlight.BackgroundGdk = new Gdk.Color(0xff, 0xff, 0x00);
        textview1.Buffer.TagTable.Add(highlight);
        encapsulated = new TextTag("encapsulated");
        encapsulated.ForegroundGdk = new Gdk.Color(0x00, 0x00, 0xff);
        textview1.Buffer.TagTable.Add(encapsulated);
        Highlight(false);

        // load any specified file and execute application
        if (args.Length > 0)
        {
            FileLoad(args[0]);
        }
        Application.Run();
    }
示例#4
0
    public PrettyPrinterOptions LoadConfig(string filename)
    {
        try {
            if (File.Exists(filename))
            {
                using (StreamReader sr = new StreamReader(filename)) {
                    PrettyPrinterOptions options;
                    XmlSerializer        xs = new XmlSerializer(typeof(PrettyPrinterOptions));
                    options = (PrettyPrinterOptions)xs.Deserialize(sr);
                    sr.Close();
                    return(options);
                }
            }
        }
        catch (Exception exception1) {
            Console.Error.WriteLine("Couldn't load configuration file {0}.\nCause: {1}", filename, exception1);
        }

        return(PrettyPrinterOptions.GetDefaults());
    }
示例#5
0
 public static string Print(JsonDocument document, PrettyPrinterOptions options = null)
 {
     return(Print(document.RootElement, options));
 }