Exemple #1
0
        /// <summary>
        /// Raises the activated event when the Import menu item is invoked.
        /// </summary>
        /// <param name='sender'>
        /// The Gtk.MenuItem.
        /// </param>
        /// <param name='args'>
        /// Arguments.
        /// </param>

        void OnImportActivated(object sender, EventArgs args)
        {
            var fc = new Gtk.FileChooserDialog("Choose a file to import", null,
                                               Gtk.FileChooserAction.Open, "Cancel",
                                               Gtk.ResponseType.Cancel, "Import", Gtk.ResponseType.Accept);

            try {
                fc.SetCurrentFolder("/media/LocalD/SolidProject/Tools/DataMorphose/plugins/ImportExport/test/DemoDB/Text/");
                // then create a filter for files. For example .csvdb:
                // filter is not necessary if you wish to see all files in the dialog
                Gtk.FileFilter filter = new Gtk.FileFilter();
                filter.Name = "CSV database";
                filter.AddPattern("*.csvdb");
                fc.AddFilter(filter);
                if (fc.Run() == (int)Gtk.ResponseType.Accept)
                {
                    CSVImporter importer = new CSVImporter(/*firstRawIsHeader*/ true);
                    DataModel   model    = morphose.GetModel();
                    Database    db       = importer.importDBFromFiles(fc.Filename);
                    model.BeginUpdate();
                    model.DB = db;
                    model.EndUpdate();
                }
            } finally {
                fc.Destroy();
            }
        }