///<summary>Handle list selection changed event</summary>
        public void OnLayoutListSelectionChanged(object o, EventArgs args)
        {
            TreeSelection sel = (TreeSelection)o;
            TreeModel     tm;
            TreeIter      ti;

            if (sel.GetSelected(out tm, out ti))
            {
                string val = (string)tm.GetValue(ti, (int)LayoutColumn.Path);

                // if there is not path, it means user clicked on a header row
                if (val == string.Empty)
                {
                    if (selectedLayout != null)
                    {
                        sel.SelectIter(selectedLayoutIter);
                    }
                    else
                    {
                        sel.UnselectIter(ti);
                    }
                    return;
                }

                // try to load layout from file
                try {
                    dataPreview.Display.Layout = new Layout(val);
                    selectedLayoutIter         = ti;
                    selectedLayout             = val;
                }
                catch (System.Xml.XmlException ex) {
                    string     msg = string.Format(Catalog.GetString("Error parsing layout file '{0}'"), val);
                    ErrorAlert ea  = new ErrorAlert(msg, ex.Message, this);
                    ea.Run();
                    ea.Destroy();
                    if (selectedLayout != null)
                    {
                        sel.SelectIter(selectedLayoutIter);
                    }
                    else
                    {
                        sel.UnselectIter(ti);
                    }
                }
                finally {
                    dataPreview.Display.Redraw();
                }
            }
        }
Exemple #2
0
        void OnDialogResponse(object o, Gtk.ResponseArgs args)
        {
            lock (LockObj) {
                if (args.ResponseId == ResponseType.Ok && dataBook != null && dataBook.NPages > 0)
                {
                    DataView dv = ((DataViewDisplay)dataBook.CurrentPageWidget).View;

                    IExportBuilder builder = null;
                    TreeIter       iter;
                    ExportAsCombo.GetActiveIter(out iter);
                    ExportPlugin plugin = (ExportPlugin)ExportAsCombo.Model.GetValue(iter, 1);


                    Util.Range range;

                    try {
                        range = GetCurrentRange(dv);
                    }
                    catch (FormatException ex) {
                        ErrorAlert ea = new ErrorAlert(Catalog.GetString("Error in custom range"), ex.Message, mainWindow);
                        ea.Run();
                        ea.Destroy();
                        return;
                    }

                    Util.Range bufferRange;
                    if (dv.Buffer.Size == 0)
                    {
                        bufferRange = new Util.Range();
                    }
                    else
                    {
                        bufferRange = new Util.Range(0, dv.Buffer.Size - 1);
                    }

                    if (!bufferRange.Contains(range.Start) || !bufferRange.Contains(range.End))
                    {
                        ErrorAlert ea = new ErrorAlert(Catalog.GetString("Error in range"), Catalog.GetString("Range is out of file's limits"), mainWindow);
                        ea.Run();
                        ea.Destroy();
                        return;
                    }

                    Stream stream = null;
                    try {
                        stream  = new FileStream(ExportFileEntry.Text, FileMode.Create, FileAccess.Write);
                        builder = plugin.CreateBuilder(stream);

                        InterpretedPatternExporter exporter = new InterpretedPatternExporter(builder);
                        exporter.Pattern = ExportPatternComboEntry.Entry.Text;

                        cancelClicked = false;
                        BeginExport(exporter, dv.Buffer, range.Start, range.End);
                    }
                    catch (Exception ex) {
                        if (stream != null)
                        {
                            stream.Close();
                        }

                        ErrorAlert ea = new ErrorAlert(Catalog.GetString("Error saving to file"), ex.Message, mainWindow);
                        ea.Run();
                        ea.Destroy();
                        return;
                    }
                }
                else if (args.ResponseId == ResponseType.Close)
                {
                    this.Hide();
                }
            }
        }