コード例 #1
0
ファイル: MainWindow.cs プロジェクト: spegelref/ScoobyRom
    // depends on gnuplot
    void OnCreateSVGFileActionActivated(object sender, System.EventArgs e)
    {
        if (data.RomLoaded == false)
        {
            return;
        }

        var table = CurrentTable;

        if (table == null)
        {
            return;
        }

        GnuPlot gnuPlot = GnuPlot.GetExistingGnuPlot(table);

        if (gnuPlot == null)
        {
            ErrorMsg("Error creating SVG export", "Need existing gnuplot window. Do a normal plot first.");
            return;
        }

        string filenameSuggested = string.IsNullOrEmpty(table.Title) ? "plot" : table.Title;

        filenameSuggested += ".svg";
        if (svgDirectory == null && data.Rom.Path != null)
        {
            svgDirectory = System.IO.Path.GetDirectoryName(data.Rom.Path);
        }

        var fc = new Gtk.FileChooserDialog("Export plot as SVG file", this, FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Save, ResponseType.Accept);

        try {
            FileFilter filter = new FileFilter();
            filter.Name = "SVG files";
            filter.AddPattern("*.svg");
            fc.AddFilter(filter);

            filter      = new FileFilter();
            filter.Name = "All files";
            filter.AddPattern("*");
            fc.AddFilter(filter);

            fc.DoOverwriteConfirmation = true;
            fc.SetCurrentFolder(svgDirectory);
            fc.CurrentName = filenameSuggested;
            if (fc.Run() == (int)ResponseType.Accept)
            {
                GnuPlot.CreateSVG(table, fc.Filename);
            }
            // remember used dir
            svgDirectory = System.IO.Path.GetDirectoryName(fc.Filename);
        } catch (GnuPlotException ex) {
            ErrorMsg("Error creating SVG file", ex.Message);
        } catch (System.IO.IOException ex) {
            ErrorMsg("IO Exception", ex.Message);
        } catch (Exception ex) {
            // Access to path denied...
            ErrorMsg("Error", ex.Message);
        } finally {
            // Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            if (fc != null)
            {
                fc.Destroy();
            }
        }
    }