Пример #1
0
		/// <param name="displayPrefix">
		/// A descriptive name for the format, such as "OpenRaster". This will be displayed
		/// in the file dialog's filter.
		/// </param>
		/// <param name="extensions">A list of supported file extensions (for example, "jpeg" and "JPEG").</param>
		/// <param name="importer">The importer for this file format, or null if importing is not supported.</param>
		/// <param name="exporter">The exporter for this file format, or null if exporting is not supported.</param>
		public FormatDescriptor (string displayPrefix, string[] extensions,
		                         IImageImporter importer, IImageExporter exporter)
		{
			if (extensions == null || (importer == null && exporter == null)) {
				throw new ArgumentNullException ("Format descriptor is initialized incorrectly");
			}
		
			this.Extensions = extensions;
			this.Importer = importer;
			this.Exporter = exporter;
			
			FileFilter ff = new FileFilter ();
			StringBuilder formatNames = new StringBuilder ();
			
			foreach (string ext in extensions) {
				if (formatNames.Length > 0)
					formatNames.Append (", ");
				
				string wildcard = string.Format ("*.{0}", ext);
				ff.AddPattern (wildcard);
				formatNames.Append (wildcard);
			}

			ff.Name = string.Format (Catalog.GetString ("{0} image ({1})"), displayPrefix, formatNames);
			this.Filter = ff;
		}
Пример #2
0
        private void Activated(object sender, EventArgs e)
        {
            var fcd = new Gtk.FileChooserDialog (Catalog.GetString ("Open Image File"), PintaCore.Chrome.MainWindow,
                                FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel,
                                Gtk.Stock.Open, Gtk.ResponseType.Ok);

            // Add image files filter
            FileFilter ff = new FileFilter ();
            ff.AddPixbufFormats ();
            ff.AddPattern ("*.ora");
            ff.Name = Catalog.GetString ("Image files");
            fcd.AddFilter (ff);

            FileFilter ff2 = new FileFilter ();
            ff2.Name = Catalog.GetString ("All files");
            ff2.AddPattern ("*.*");
            fcd.AddFilter (ff2);

            fcd.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel };
            fcd.SetCurrentFolder (PintaCore.System.LastDialogDirectory);
            fcd.SelectMultiple = true;

            int response = fcd.Run ();

            if (response == (int)Gtk.ResponseType.Ok) {
                PintaCore.System.LastDialogDirectory = fcd.CurrentFolder;

                foreach (var file in fcd.Filenames)
                    if (PintaCore.Workspace.OpenFile (file))
                        RecentManager.Default.AddFull (fcd.Uri, PintaCore.System.RecentData);
            }

            fcd.Destroy ();
        }
        protected void OnTargetNMMLFileButtonClicked(object sender, System.EventArgs e)
        {
            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog ("Target NMML file", this.Toplevel as Gtk.Window, FileChooserAction.Open,
                    "Cancel", ResponseType.Cancel,
                    "Select", ResponseType.Accept);

            Gtk.FileFilter filter = new Gtk.FileFilter ();
            filter.Name = "NMML files";
            filter.AddPattern ("*.nmml");
            fc.AddFilter (filter);

            if (mProject.TargetNMMLFile != "")
            {
                fc.SetFilename (mProject.TargetNMMLFile);
            }
            else
            {
                fc.SetFilename (mProject.BaseDirectory);
            }

            if (fc.Run () == (int)ResponseType.Accept)
            {
                string path = PathHelper.ToRelativePath (fc.Filename, mProject.BaseDirectory);

                TargetNMMLFileEntry.Text = path;
            }

            fc.Destroy ();
        }
Пример #4
0
        protected void OnButtonLoadPhotoClicked(object sender, EventArgs e)
        {
            FileChooserDialog Chooser = new FileChooserDialog ("Выберите фото для загрузки...",
                (Window)this.Toplevel,
                FileChooserAction.Open,
                "Отмена", ResponseType.Cancel,
                "Загрузить", ResponseType.Accept);

            FileFilter Filter = new FileFilter ();
            Filter.AddPixbufFormats ();
            Filter.Name = "Все изображения";
            Chooser.AddFilter (Filter);

            if ((ResponseType)Chooser.Run () == ResponseType.Accept) {
                Chooser.Hide ();
                logger.Info ("Загрузка фотографии...");

                FileStream fs = new FileStream (Chooser.Filename, FileMode.Open, FileAccess.Read);
                if (Chooser.Filename.ToLower ().EndsWith (".jpg")) {
                    using (MemoryStream ms = new MemoryStream ()) {
                        fs.CopyTo (ms);
                        ImageFile = ms.ToArray ();
                    }
                } else {
                    logger.Info ("Конвертация в jpg ...");
                    Gdk.Pixbuf image = new Gdk.Pixbuf (fs);
                    ImageFile = image.SaveToBuffer ("jpeg");
                }
                fs.Close ();
                buttonSavePhoto.Sensitive = true;
                logger.Info ("Ok");
            }
            Chooser.Destroy ();
        }
Пример #5
0
	/* Private methods */

	private void SetFilters () {

		/* Video files */
		FileFilter videoFilesFilter = new FileFilter();
		videoFilesFilter.Name = Catalog.GetString("All Video Files");
		videoFilesFilter.AddMimeType("video/*");
		videoFilesFilter.AddMimeType("application/vnd.rn-realmedia"); //support for real media files (currently includes rmvb)
		videoFilesFilter.AddMimeType("application/vnd.rn-realmedia-vbr"); //this should be the real mime type for rmvb files
		dialog.AddFilter(videoFilesFilter);

		/* Audio files */
		FileFilter audioFilesFilter = new FileFilter();
		audioFilesFilter.Name = Catalog.GetString("All Audio Files");
		audioFilesFilter.AddMimeType("audio/*");
		audioFilesFilter.AddMimeType("application/ogg");
		dialog.AddFilter(audioFilesFilter);


		/* All files */
		FileFilter allFilesFilter = new FileFilter();
		allFilesFilter.Name = Catalog.GetString("All Files");
		allFilesFilter.AddPattern("*");
		dialog.AddFilter(allFilesFilter);

		/* Set active filter */
		dialog.Filter = videoFilesFilter;
	}
Пример #6
0
		protected virtual void OpenClicked (object sender, System.EventArgs e)
		{
			FileChooserDialog dlg = new FileChooserDialog (
				GettextCatalog.GetString ("Select Executable"), null, FileChooserAction.Open,
				"gtk-cancel", ResponseType.Cancel,
				"gtk-open", ResponseType.Accept
			);
			dlg.SelectMultiple = false;
			dlg.LocalOnly = true;
			dlg.Modal = true;
			dlg.SetCurrentFolder (Environment.GetFolderPath (Environment.SpecialFolder.Personal));
			
			FileFilter filterExe = new FileFilter ();
			filterExe.AddPattern ("*.exe");
			filterExe.Name = GettextCatalog.GetString ("Executables");
			FileFilter filterAll = new FileFilter ();
			filterAll.AddPattern ("*");
			filterAll.Name = GettextCatalog.GetString ("All files");
			dlg.AddFilter (filterExe);
			dlg.AddFilter (filterAll);

			if (dlg.Run () == (int)ResponseType.Accept)
				entryExecutable.Text = dlg.Filename;
			dlg.Destroy ();
		}
Пример #7
0
        public override WindowResponse Show()
        {
            FileChooserAction fca = FileChooserAction.Open;
            switch(DialogType)
            {
                case FileDialogType.OpenFile:
                    fca = FileChooserAction.Open;
                    break;
                case FileDialogType.SelectFolder:
                    fca = FileChooserAction.SelectFolder;
                    break;
                case FileDialogType.SaveFile:
                    fca = FileChooserAction.Save;
                    break;
            }

            fc = new FileChooserDialog(Title, null, fca, Message.GetString("Cancel"), ResponseType.Cancel, Message.GetString("Select"), ResponseType.Ok);
            fc.SetCurrentFolder(InitialDirectory);
            foreach(FileTypeFilter filter in FileTypeFilters)
            {
                FileFilter ft = new FileFilter();
                ft.Name = filter.FilterName;
                foreach(string pat in filter.Filter) ft.AddPattern("*." + pat);
                fc.AddFilter(ft);
            }
            WindowResponse resp = GtkHelper.GetResponse((ResponseType)fc.Run());
            SelectedPath = fc.Filename;
            return resp;
        }
Пример #8
0
        protected override void OnActivated()
        {
            base.OnActivated();

            if(String.IsNullOrEmpty(MainClass.Workspace.FilePath)){
                MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("workspace_not_exist"), MainClass.Languages.Translate("please_create_workspace"), Gtk.MessageType.Error);
                md.ShowDialog();
                return;
            }

            Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog(MainClass.Languages.Translate("chose_project_import"), MainClass.MainWindow, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);

            if (!String.IsNullOrEmpty(MainClass.Settings.LastOpenedImportDir))
                fc.SetCurrentFolder(MainClass.Settings.LastOpenedImportDir);

            FileFilter filter = new FileFilter();
            filter.Name = "zip files";
            filter.AddMimeType("zip file");
            filter.AddPattern("*.zip");
            fc.AddFilter(filter);

            if (fc.Run() == (int)ResponseType.Accept) {

                MainClass.Settings.LastOpenedImportDir = System.IO.Path.GetDirectoryName(fc.Filename);

                MainClass.MainWindow.ImportProject(fc.Filename,true);
            }

            fc.Destroy();
        }
Пример #9
0
 protected void onAddClicked(object sender, System.EventArgs e)
 {
     String[] items = {};
     FileChooserDialog dialog =
         new FileChooserDialog("Open",
              null,
             FileChooserAction.Open,
             "Cancel",ResponseType.Cancel,
             "Open",ResponseType.Accept);
     dialog.SelectMultiple=true;
     FileFilter filter = new FileFilter();
     /*filter.AddPattern("*.jpg");
     filter.AddPattern("*.jpeg");
     filter.AddPattern("*.png");
     filter.AddPattern("*.svg");*/
     filter.AddMimeType("image/*");
     dialog.Filter = filter;
     if(dialog.Run()==(int)ResponseType.Accept)
     {
         items = dialog.Filenames;
     }
     dialog.Destroy();
     localfiles.LocalFiles.addItems(items);
     fillList();
 }
		private DatabaseSaveDialog(Window parent)
		{
			Glade.XML xml = new Glade.XML(null,"gui.glade","databaseSaveDialog",null);
			xml.Autoconnect(this);
			
			databaseSaveDialog.Icon = parent.Icon;
			
			// Conectamos las acciones de los botones del diálogo.
			databaseSaveDialog.AddActionWidget(btnSave,ResponseType.Ok);
			databaseSaveDialog.AddActionWidget(btnCancel,ResponseType.Cancel);			
			
			
			// Añadimos los archivos de filtros soportados
			FileFilter filter1=new FileFilter();
			filter1.Name="Archivo XML";
			filter1.AddPattern("*.xml");
			filter1.AddPattern("*.XML");
			
			FileFilter filter2=new FileFilter();
			filter2.Name="Base de datos de reconocimiento";
			filter2.AddPattern("*.jilfml");
			filter2.AddPattern("*.JILFML");
			
			FileFilter filter3=new FileFilter();
			filter3.Name="Todos los archivos";
			filter3.AddPattern("*.*");			
			
			databaseSaveDialog.AddFilter(filter2);		
			databaseSaveDialog.AddFilter(filter1);				
			databaseSaveDialog.AddFilter(filter3);	
		}
        public ImageFileChooserDialog () : base (Catalog.GetString("Select album cover image"), FileChooserAction.Open)
        {
            AddButton (Stock.Cancel, ResponseType.Cancel);
            AddButton (Stock.Open, ResponseType.Ok);

            DefaultResponse = ResponseType.Ok;

            FileFilter filter = new FileFilter ();
            filter.Name = Catalog.GetString ("All image files");
            filter.AddMimeType ("image/jpeg");
            filter.AddMimeType ("image/png");
            AddFilter (filter);
            Filter = filter;

            filter = new FileFilter ();
            filter.Name = Catalog.GetString ("JPEG image files");
            filter.AddMimeType ("image/jpeg");
            AddFilter (filter);

            filter = new FileFilter ();
            filter.Name = Catalog.GetString ("PNG image files");
            filter.AddMimeType ("image/png");
            AddFilter (filter);

            PreviewWidget = preview;
        }
		private bool ShowSelectDatabaseDialog (out string database)
		{
			FileChooserDialog dlg = new FileChooserDialog (
				AddinCatalog.GetString ("Open Database"), null, FileChooserAction.Open,
				"gtk-cancel", ResponseType.Cancel,
				"gtk-open", ResponseType.Accept
			);
			dlg.SelectMultiple = false;
			dlg.LocalOnly = true;
			dlg.Modal = true;
		
			FileFilter filter = new FileFilter ();
			filter.AddMimeType ("application/x-sqlite2");
			filter.AddMimeType ("application/x-sqlite3");
			filter.AddPattern ("*.db");
			filter.AddPattern ("*.sqlite");
			filter.Name = AddinCatalog.GetString ("SQLite databases");
			FileFilter filterAll = new FileFilter ();
			filterAll.AddPattern ("*");
			filterAll.Name = AddinCatalog.GetString ("All files");
			dlg.AddFilter (filter);
			dlg.AddFilter (filterAll);

			database = null;
			bool result = false;
			try {
				if (dlg.Run () == (int)ResponseType.Accept) {
					database = dlg.Filename;
					result = true;
				}
			} finally {
				dlg.Destroy ();					
			}
			return result;
		}
Пример #13
0
		/// <summary>
		/// Constructor de la clase LogSaveDialog. Crea y muestra el diálogo.
		/// </summary>
		public LogSaveDialog()
		{
			Glade.XML gxml = new Glade.XML (null,"gui.glade", "logSaveDialog", null);
            gxml.Autoconnect (this);
            
            FileFilter logFilter = new FileFilter();
            logFilter.Name = "Archivo de registro";
            logFilter.AddPattern("*.log");
            logFilter.AddPattern("*.LOG");
            
            FileFilter txtFilter = new FileFilter();
            txtFilter.Name = "Archivo de texto";
            txtFilter.AddPattern("*.txt");
            txtFilter.AddPattern("*.TXT");
            
            FileFilter allFilter = new FileFilter();
            allFilter.Name = "Todos los archivos";
            allFilter.AddPattern("*.*");          
            
            logSaveDialog.AddFilter(logFilter);
            logSaveDialog.AddFilter(txtFilter);
            logSaveDialog.AddFilter(allFilter);
            
            logSaveDialog.AddActionWidget(btnSave,ResponseType.Ok);
            logSaveDialog.AddActionWidget(btnCancel,ResponseType.Cancel); 
		}
Пример #14
0
	private void setupOpenDialog() {
		FileFilter filter;
		Glade.XML xml = getGlade("OpenDialog.glade");

		xml.Autoconnect(this);

		filter = new FileFilter();
		filter.Name = "All support files (*.fld, *.fld.gz, *.gat)";
		filter.AddPattern("*.fld");
		filter.AddPattern("*.fld.gz");
		filter.AddPattern("*.gat");
		openFileDialog.AddFilter(filter);

		filter = new FileFilter();
		filter.Name = "OpenKore Field Files (*.fld, *.fld.gz)";
		filter.AddPattern("*.fld");
		filter.AddPattern("*.fld.gz");
		openFileDialog.AddFilter(filter);

		filter = new FileFilter();
		filter.Name = "Ragnarok Online Ground Files (*.gat)";
		filter.AddPattern("*.gat");
		openFileDialog.AddFilter(filter);

		filter = new FileFilter();
		filter.Name = "All Files (*)";
		filter.AddPattern("*");
		openFileDialog.AddFilter(filter);

		openFileDialog.PreviewWidget = new FieldPreview();
		openFileDialog.UpdatePreview += OnUpdatePreview;
	}
Пример #15
0
        /// <summary>
        /// Adds the filters. Returns default extension
        /// </summary>
        /// <returns>The filters.</returns>
        /// <param name="dialog">Dialog.</param>
        private static string AddFilters(FileChooserDialog dialog) 
        {
            string defaultExtension = "teml";
            string cryptedFileExtension = "temlx";
            // Add experiment files filter
            FileFilter fileFilter = new FileFilter();
            fileFilter.AddPattern(string.Format("*.{0}", defaultExtension));
            fileFilter.Name = Mono.Unix.Catalog.GetString(string.Format("Experiment files (.{0})", defaultExtension));
            dialog.AddFilter(fileFilter);

            // Add experiment files filter
            //TLAB-67
        //here: we check if the file is crypted, if it's so we ask the user to insert a password. then we decrypt the file and check the 
            /// password. if the pwd is the same we contninue with the standard process, otherwise we raise and error
            FileFilter fileFilterCryptedFile = new FileFilter();
            fileFilterCryptedFile.AddPattern(string.Format("*.{0}", cryptedFileExtension));
            fileFilterCryptedFile.Name = Mono.Unix.Catalog.GetString(string.Format("Experiment files (.{0})", cryptedFileExtension));
            dialog.AddFilter(fileFilterCryptedFile);
            
            //add another option of All files
            FileFilter allFilesFilter = new FileFilter();
            allFilesFilter.Name = Mono.Unix.Catalog.GetString("All files");
            allFilesFilter.AddPattern("*.*");
            dialog.AddFilter(allFilesFilter);

            return defaultExtension;
        }
		public AssemblyReferencePanel (SelectReferenceDialog selectDialog)
		{
			this.selectDialog = selectDialog;
			
			chooser = new FileChooserWidget (FileChooserAction.Open, "");
			chooser.SetCurrentFolder (Environment.GetFolderPath (Environment.SpecialFolder.Personal));
			chooser.SelectMultiple = true;

			// this should only allow dll's and exe's
			FileFilter filter = new FileFilter ();
			filter.Name = GettextCatalog.GetString ("Assemblies");
			filter.AddPattern ("*.[Dd][Ll][Ll]");
			filter.AddPattern ("*.[Ee][Xx][Ee]");
			chooser.AddFilter (filter);
			chooser.FileActivated += new EventHandler (SelectReferenceDialog);

			PackStart (chooser, true, true, 0);
			
			PackStart (new Gtk.VSeparator(), false, false, 0);
			
			VBox box = new VBox ();
			Gtk.Button addButton = new Gtk.Button (Gtk.Stock.Add);
			addButton.Clicked += new EventHandler(SelectReferenceDialog);
			box.PackStart (addButton, false, false, 0);
			PackStart (box, false, false, 0);
			
			BorderWidth = 6;
			Spacing = 6;
			ShowAll();
		}
Пример #17
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();
            }
        }
Пример #18
0
        static void GetClip()
        {
            // TODO: Do not offer to save clip after selection and popup a clickable tooltip instead.
            FileChooserDialog fcd = new FileChooserDialog("PixClip - Save clip as...", null, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);
            FileFilter fltJpg = new FileFilter();
            fltJpg.AddMimeType("image/jpeg");
            fltJpg.Name = "JPEG image format";
            fcd.SetFilename("clip.jpg");
            fcd.SetCurrentFolder(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop));
            fcd.AddFilter(fltJpg);

            Console.WriteLine("main: selecting save target");
            if (fcd.Run() == (int) ResponseType.Accept) {
                // TODO: Add quality setting to options form.
                // http://library.gnome.org/devel/gdk-pixbuf/stable/gdk-pixbuf-file-saving.html
                string [] keys = {"quality"};
                string [] values = {"90"};
                pixClip.Savev(fcd.Filename, "jpeg", keys, values);
                Console.WriteLine("main: image saved");
            } else {
                Console.WriteLine("main: image save canceled");
            }
            fcd.Destroy();

            Clipboard clip = Gtk.Clipboard.Get(Atom.Intern("CLIPBOARD", false));
            clip.Image = pixClip;
            Console.WriteLine("main: image added to the clipboard");
        }
Пример #19
0
        public static byte[] GetTemplateFromDisk()
        {
            //Читаем файл документа
            FileChooserDialog Chooser = new FileChooserDialog ("Выберите шаблон документа...",
                null,
                FileChooserAction.Open,
                "Отмена", ResponseType.Cancel,
                "Выбрать", ResponseType.Accept);
            FileFilter Filter = new FileFilter ();
            Filter.Name = "ODT документы и OTT шаблоны";
            Filter.AddMimeType ("application/vnd.oasis.opendocument.text");
            Filter.AddMimeType ("application/vnd.oasis.opendocument.text-template");
            Filter.AddPattern ("*.odt");
            Filter.AddPattern ("*.ott");
            Chooser.AddFilter (Filter);

            Filter = new FileFilter ();
            Filter.Name = "Все файлы";
            Filter.AddPattern ("*.*");
            Chooser.AddFilter (Filter);

            byte[] file = null;

            if ((ResponseType)Chooser.Run () == ResponseType.Accept) {
                Chooser.Hide ();
                logger.Info ("Чтение файла...");

                file = File.ReadAllBytes(Chooser.Filename);

                logger.Info ("Ok");
            }
            Chooser.Destroy ();

            return file;
        }
Пример #20
0
        protected override void OnActivated()
        {
            base.OnActivated();

            Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog(MainClass.Languages.Translate("chose_workspace_open"), MainClass.MainWindow, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);

            FileFilter filter = new FileFilter();
            filter.Name = "Workspace files";
            filter.AddMimeType("Workspace file");
            filter.AddPattern("*.msw");
            fc.AddFilter(filter);

            if (!String.IsNullOrEmpty(MainClass.Settings.LastOpenedWorkspaceDir))
                fc.SetCurrentFolder(MainClass.Settings.LastOpenedWorkspaceDir);

            if (fc.Run() == (int)ResponseType.Accept) {

                MainClass.Settings.LastOpenedWorkspaceDir = System.IO.Path.GetDirectoryName(fc.Filename);

                //CloseActualWorkspace();
                Workspace.Workspace workspace = Workspace.Workspace.OpenWorkspace(fc.Filename);

                if (workspace != null){
                    //MainClass.Settings.RecentFiles.AddWorkspace(fc.Filename,fc.Filename);
                    MainClass.MainWindow.ReloadWorkspace(workspace,true,true);
                }

            }

            fc.Destroy();
        }
Пример #21
0
        private void HandleOpenAction()
        {
            CustomFileChooserDialog dlg =
                new CustomFileChooserDialog(this, "Open pack", FileChooserAction.Open);

            dlg.FileChooser.SelectMultiple = false;

            Packer.SupportedExtensions.ToList().ForEach(ext =>
            {
                using (Gtk.FileFilter filter = new Gtk.FileFilter())
                {
                    filter.Name = ext.ToUpper();
                    filter.AddPattern("*." + ext);
                    dlg.FileChooser.AddFilter(filter);
                }
            });

            dlg.Ok += (sender, e) =>
            {
                if (fileSystem != null)
                {
                    fileSystem.Close();
                }
                fileSystem = null;

                OpenPack(dlg.FileChooser.Filename);
                dlg.Destroy();
            };
            dlg.Cancel += (sender, e) => dlg.Destroy();
            dlg.Show();
        }
        void OpenFile(string title, string filterName, string filter)
        {
            var fc = new Gtk.FileChooserDialog(title,
                                               this, Gtk.FileChooserAction.Open, "Cancel", Gtk.ResponseType.Cancel,
                                               "Open", Gtk.ResponseType.Accept);

            var f = new Gtk.FileFilter();

            f.Name = filterName;
            f.AddPattern(filter);

            fc.AddFilter(f);

            if (fc.Run() == (int)Gtk.ResponseType.Accept)
            {
                if (filterName == ".keystore")
                {
                    entryCustomKeystore.Text = fc.Filename;
                }
                else if (filterName == "keytool")
                {
                    entryKeytool.Text = fc.Filename;
                }
            }
            fc.Destroy();
        }
        protected void OnSaveButtonClicked(object sender, EventArgs e)
        {
            try
            {
                FileChooserDialog fc = new FileChooserDialog("Save Filterset", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);

                FileFilter filter = new FileFilter();
                filter.Name = "DeSERt Filterset";
                filter.AddMimeType("Filterset/fis");
                filter.AddPattern("*.fis");
                fc.AddFilter(filter);
                fc.DoOverwriteConfirmation = true;
                fc.CurrentName = FiltersetnameEntry.Text.Replace(" ", "-");
                if (Directory.Exists(MySettings.LastFilterDir)) { fc.SetCurrentFolder(MySettings.LastFilterDir); }

                ResponseType res = (ResponseType)fc.Run();
                if (res == ResponseType.Ok || res == ResponseType.Close)
                {
                    string path;
                    if (!System.IO.Path.HasExtension(fc.Filename)) { path = fc.Filename + ".fis"; }
                    else { path = fc.Filename; }
                    MySettings.LastFilterDir = System.IO.Path.GetDirectoryName(fc.Filename);
                    MySettings.Save();
                    fst.Name = FiltersetnameEntry.Text;
                    Filterset.SaveFilterset(path, fst);
                    saved = true;
                }
                fc.Destroy();
                if (res == ResponseType.Close) { this.Destroy(); }
            }
            catch (Exception ex) { ErrorReport.ReportError("Save Button (Create Filterset)", ex); }
        }
Пример #24
0
 public static FileFilter FileTypesToGtkFilter(params FileTypes[] types)
 {
     FileFilter filter = new FileFilter();
     for (int i = 0; i < types.Length; i++)
     {
         FileTypes type = types[i];
         switch (type)
         {
             case FileTypes.Images:
                 filter.AddPattern("*.jpg");
                 filter.AddPattern("*.png");
                 filter.AddPattern("*.bmp");
                 filter.Name += "Images ";
                 break;
             case FileTypes.JPG:
                 filter.AddPattern("*.jpg");
                 filter.Name += "Jpg ";
                 break;
             case FileTypes.PNG:
                 filter.AddPattern("*.png");
                 filter.Name += "Png ";
                 break;
             case FileTypes.BMP:
                 filter.AddPattern("*.bmp");
                 filter.Name += "Bmp ";
                 break;
         }
     }
     return filter;
 }
Пример #25
0
		#pragma warning restore 0169
		
		private FileFilter CreateAssemblyFilter () {
			FileFilter fileFilter = new FileFilter ();
			fileFilter.Name = "Assemblies";
			fileFilter.AddPattern ("*.dll");
			fileFilter.AddPattern ("*.exe");
			return fileFilter;
		}
Пример #26
0
        public void AddFilter(string name, string pattern)
        {
            var filter = new FileFilter();
            filter.Name = name;
            filter.AddPattern(pattern);

            dialog.AddFilter(filter);
        }
Пример #27
0
        protected override void OnActivated()
        {
            base.OnActivated();

            if(String.IsNullOrEmpty(MainClass.Workspace.FilePath)){
                MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("workspace_not_exist"), MainClass.Languages.Translate("please_create_workspace"), Gtk.MessageType.Error);
                md.ShowDialog();
                return;
            }

            Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog(MainClass.Languages.Translate("save_project_export"), MainClass.MainWindow, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);

            if (!String.IsNullOrEmpty(MainClass.Settings.LastOpenedExportDir))
                fc.SetCurrentFolder(MainClass.Settings.LastOpenedExportDir);

            FileFilter filter = new FileFilter();
            filter.Name = "zip files";
            filter.AddMimeType("zip file");
            filter.AddPattern("*.zip");
            fc.AddFilter(filter);

            string appname = "";
            int typ = -1;
            Gtk.TreeIter ti = new Gtk.TreeIter();
            MainClass.MainWindow.WorkspaceTree.GetSelectedFile(out appname, out typ, out ti);

            if (String.IsNullOrEmpty(appname)){
                return;
            }

            Project p = MainClass.Workspace.FindProject_byApp(appname, true);

            if(p== null){
                return;
            }

            fc.CurrentName =p.ProjectName+"_"+p.AppFile.Version.Replace(".","_") ;
            //fc.SetFilename(p.ProjectName);

            if (fc.Run() != (int)ResponseType.Accept) {
                fc.Destroy();
                return;
            }

            string name =fc.Filename;

            string ext = System.IO.Path.GetExtension(name);

            if(ext.ToLower() != ".zip"){
                name = name+".zip";
            }

            if(p!= null){
                p.Export(name,true);
                MainClass.Settings.LastOpenedExportDir = System.IO.Path.GetDirectoryName(fc.Filename);
            }
            fc.Destroy();
        }
Пример #28
0
        protected void OnOpen(object sender, EventArgs e)
        {
            Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog("Open Document",
                                                                     (Gtk.Window) this.Toplevel,
                                                                     Gtk.FileChooserAction.Open);

            dialog.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
            dialog.AddButton(Gtk.Stock.Open, Gtk.ResponseType.Accept);

            dialog.DefaultResponse = Gtk.ResponseType.Cancel;
            dialog.LocalOnly       = true;

            Gtk.FileFilter filter = new Gtk.FileFilter();
            filter.Name = "doc/pdf";
            filter.AddMimeType("application/pdf");
            filter.AddMimeType("application/ps");
            filter.AddMimeType("application/eps");
            filter.AddMimeType("application/pcl");
            filter.AddMimeType("application/xps");
            filter.AddMimeType("application/oxps");
            filter.AddPattern("*.pdf");
            filter.AddPattern("*.ps");
            filter.AddPattern("*.eps");
            filter.AddPattern("*.bin");
            filter.AddPattern("*.xps");
            filter.AddPattern("*.oxps");
            dialog.Filter = filter;
            int response = dialog.Run();

            if (response != (int)Gtk.ResponseType.Accept)
            {
                dialog.Destroy();
                return;
            }

            if (m_file_open)
            {
                /* launch a new process */
                string path = System.Reflection.Assembly.GetExecutingAssembly().Location;

                Process p = new Process();
                try
                {
                    String name = dialog.Filename;
                    Process.Start(path, name);
                }
                catch (Exception except)
                {
                    Console.WriteLine("Problem opening file: " + except.Message);
                }
                dialog.Destroy();
                return;
            }

            m_currfile = dialog.Filename;
            dialog.Destroy();
            ProcessFile();
        }
Пример #29
0
 public static FileFilter GetFileFilter()
 {
     FileFilter filter = new FileFilter();
     filter.Name = "Images";
     filter.AddPattern("*.png");
     filter.AddPattern("*.jpg");
     filter.AddPattern("*.jpeg");
     return filter;
 }
Пример #30
0
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            Build ();

            Gtk.FileFilter fileFilter = new Gtk.FileFilter();
            fileFilter.AddPattern("blue.dll");
            ChooseFile.Filter = fileFilter;
        }
Пример #31
0
    protected void OnImportImage(object o, EventArgs e)
    {
        FileChooserDialog fileChooser = new FileChooserDialog("Select ImageFile", MainWindow, FileChooserAction.Open, new object[] {});

        fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
        fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
        fileChooser.DefaultResponse = Gtk.ResponseType.Ok;
        Gtk.FileFilter all = new Gtk.FileFilter();
        all.Name = "All Files";
        all.AddPattern("*");
        fileChooser.AddFilter(all);
        int result = fileChooser.Run();

        fileChooser.Hide();

        if (result != (int)ResponseType.Ok)
        {
            return;
        }

        string file = fileChooser.Filename;
        string trim = tilesetdir + "/";

        if (!file.StartsWith(trim))
        {
            Console.WriteLine(
                "Imported file must be located inside tileset directory");
            return;
        }

        ChangeImage(file.TrimStart(trim.ToCharArray()));

        int startid = tileset.Tiles.Count;

        for (int y = 0; y < TilesY; ++y)
        {
            for (int x = 0; x < TilesX; ++x)
            {
                int  i    = y * TilesX + x;
                Tile tile = new Tile();
                tile.ID = startid + i;
                ImageRegion region = new ImageRegion();
                region.ImageFile = currentimage;
                region.Region    = new System.Drawing.Rectangle(x * TileSet.TILE_WIDTH, y * TileSet.TILE_HEIGHT, TileSet.TILE_WIDTH, TileSet.TILE_HEIGHT);
                tile.Images.Add(region);
                if (Tiles[i] != null)
                {
                    Console.WriteLine(
                        "Warning Tile in this region already existed...");
                }
                Tiles[i] = tile;
                tileset.Tiles.Add(tile);
            }
        }

        FillTileList();
    }
Пример #32
0
 public CopyMoveDialog()
 {
     this.Build ();
     FileFilter filter = new FileFilter ();
     filter.Name = "OCM Databases";
     filter.AddPattern ("*.ocm");
     chooser.AddFilter (filter);
     chooser.SelectionChanged += HandleChooserSelectionChanged;
     buttonOk.Sensitive = false;
 }
Пример #33
0
        protected virtual void OnButtonInstallFromFileClicked(object sender, System.EventArgs e)
        {
            string[] files;
            Gtk.FileChooserDialog dlg = new Gtk.FileChooserDialog(Catalog.GetString("Install Add-in Package"), this, FileChooserAction.Open);
            try
            {
                if (lastFolder != null)
                {
                    dlg.SetCurrentFolder(lastFolder);
                }
                else
                {
                    dlg.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                }
                dlg.SelectMultiple = true;

                Gtk.FileFilter f = new Gtk.FileFilter();
                f.AddPattern("*.mpack");
                f.Name = Catalog.GetString("Add-in packages");
                dlg.AddFilter(f);

                f = new Gtk.FileFilter();
                f.AddPattern("*");
                f.Name = Catalog.GetString("All files");
                dlg.AddFilter(f);

                dlg.AddButton(Gtk.Stock.Cancel, ResponseType.Cancel);
                dlg.AddButton(Gtk.Stock.Open, ResponseType.Ok);
                if (dlg.Run() != (int)Gtk.ResponseType.Ok)
                {
                    return;
                }
                files      = dlg.Filenames;
                lastFolder = dlg.CurrentFolder;
            }
            finally
            {
                dlg.Destroy();
            }

            InstallDialog idlg = new InstallDialog(this, service);

            try
            {
                idlg.InitForInstall(files);
                if (idlg.Run() == (int)Gtk.ResponseType.Ok)
                {
                    LoadAll();
                }
            }
            finally
            {
                idlg.Destroy();
            }
        }
Пример #34
0
        protected void OnImportCommandsButtonPress(object sender, EventArgs e)
        {
            Gtk.FileChooserDialog fileChooser = new Gtk.FileChooserDialog
                                                    ("Choose files"
                                                    , this
                                                    , FileChooserAction.Open
                                                    , "Select"
                                                    , ResponseType.Accept
                                                    , "Cancel"
                                                    , ResponseType.Close);

            Gtk.FileFilter xmlFileFilter = new Gtk.FileFilter();
            xmlFileFilter.AddPattern("*.xml");
            fileChooser.AddFilter(xmlFileFilter);

            int response = fileChooser.Run();

            if (response == Utils.static_cast <int>(ResponseType.Close))
            {
                UIUtils.ShutDownWindow(ref fileChooser);
            }
            else if (response == Utils.static_cast <int>(ResponseType.Accept))
            {
                string fullPath = fileChooser.Filename;
                UIUtils.ShutDownWindow(ref fileChooser);

                GameConfigDescriptorLoader loader = new GameConfigDescriptorLoader(fullPath);
                FileOperationResult        fileOperationResult = loader.Load();

                if (fileOperationResult.IsSuccess())
                {
                    GameConfigDB sourceConfigDB = loader.GetConfig();

                    UITabPage    currentTabPage = GetCurrentTabPage();
                    GameConfigDB targetConfigDB = currentTabPage.GetGameConfig();

                    foreach (GameConfigSectionDescriptor sectionDescriptor in sourceConfigDB.GetSections())
                    {
                        targetConfigDB.AddSection(sectionDescriptor);
                        currentTabPage.AddNewSection(sectionDescriptor);
                    }

                    currentTabPage.RefreshCanvas();
                }
                else
                {
                    UIUtils.ShutDownWindowSafe(ref _windowPrompt);
                    _windowPrompt = new WindowPrompt(fileOperationResult.GetResult());
                    _windowPrompt.OnAcceptEvent += OnAlertAccept;
                    _windowPrompt.SetCancelVisible(false);
                    _windowPrompt.Show();
                    MainApp.GetInstance().MoveWindowToMousePos(_windowPrompt);
                }
            }
        }
Пример #35
0
 public ImportDialog()
 {
     this.Build ();
     FileFilter filter = new FileFilter ();
     filter.Name = "Waypoint Files";
     filter.AddPattern ("*.gpx");
     filter.AddPattern ("*.loc");
     filter.AddPattern ("*.zip");
     fileWidget.AddFilter (filter);
     UpdateBookMarkCombo();
 }
Пример #36
0
        public bool OpenFileDialog(OpenFileDialogParams openParams, Action <OpenFileDialogParams> callback)
        {
            WinformsSystemWindow.ShowingSystemDialog = true;
            Gtk.Application.Init();

            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog(openParams.Title,
                                          null,
                                          FileChooserAction.Open,
                                          "Cancel", ResponseType.Cancel,
                                          "Open", ResponseType.Accept);

            if (openParams.InitialDirectory != null)
            {
                fc.SetCurrentFolder(openParams.InitialDirectory);
            }
            fc.SelectMultiple = openParams.MultiSelect;

            Gtk.FileFilter filter = new Gtk.FileFilter();
            filter.Name = openParams.Filter.Split('|')[0];
            string[] extensions = openParams.Filter.Split('|') [1].Split(';');
            foreach (string e in extensions)
            {
                filter.AddPattern(e.ToLower());
                filter.AddPattern(e.ToUpper());
            }
            fc.AddFilter(filter);

            // fc.Show();
            // fc.Present();
            fc.KeepAbove = true;

            if (fc.Run() == (int)ResponseType.Accept)
            {
                this.LastDirectoryUsed = Path.GetDirectoryName(fc.Filename);
                openParams.FileNames   = fc.Filenames;
                openParams.FileName    = fc.Filename;
                UiThread.RunOnIdle(() =>
                {
                    callback(openParams);
                });
            }

            fc.Destroy();
            while (Gtk.Application.EventsPending())
            {
                Gtk.Main.Iteration();
            }

            WinformsSystemWindow.ShowingSystemDialog = false;

            return(true);
        }
Пример #37
0
 /// <summary>
 /// add a new filepattern to the filechooserbutton (e.g. *.xml)
 /// </summary>
 /// <param name='pattern'>
 /// Pattern.
 /// </param>
 public void AddPattern(String pattern)
 {
     if (CurrentFilter == null)
     {
         CurrentFilter = new Gtk.FileFilter();
         CurrentFilter.AddPattern(pattern);
         Chooser.Filter = CurrentFilter;
     }
     else
     {
         CurrentFilter.AddPattern(pattern);
     }
 }
        public override bool OpenFileDialog(OpenFileDialogParams openParams, Action <OpenFileDialogParams> callback)
        {
            WidgetForWindowsFormsAbstract.MainWindowsFormsWindow.ShowingSystemDialog = true;

            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog(openParams.Title,
                                          null,
                                          FileChooserAction.Open,
                                          "Cancel", ResponseType.Cancel,
                                          "Open", ResponseType.Accept);

            fc.SetCurrentFolder(openParams.InitialDirectory);
            fc.SelectMultiple = openParams.MultiSelect;

            Gtk.FileFilter filter = new Gtk.FileFilter();
            filter.Name = openParams.Filter.Split('|')[0];
            string[] extensions = openParams.Filter.Split('|') [1].Split(';');
            foreach (string e in extensions)
            {
                filter.AddPattern(e.ToLower());
                filter.AddPattern(e.ToUpper());
            }
            fc.AddFilter(filter);

            Gtk.Application.Init();

            if (fc.Run() == (int)ResponseType.Accept)
            {
                openParams.FileNames = fc.Filenames;
                openParams.FileName  = fc.Filename;
                UiThread.RunOnIdle((state) =>
                {
                    OpenFileDialogParams openParamsIn = state as OpenFileDialogParams;
                    if (openParamsIn != null)
                    {
                        callback(openParamsIn);
                    }
                }, openParams);
            }

            fc.Destroy();
            while (Gtk.Application.EventsPending())
            {
                Gtk.Main.Iteration();
            }

            WidgetForWindowsFormsAbstract.MainWindowsFormsWindow.ShowingSystemDialog = false;

            return(true);
        }
Пример #39
0
 private void OpenFileFromMenu(object sender, EventArgs a)
 {
     Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog("Open File", null, FileChooserAction.Open, "Open", Gtk.ResponseType.Accept, "Cancel", Gtk.ResponseType.Cancel);
     dialog.SelectMultiple = true;
     Gtk.FileFilter filter = new Gtk.FileFilter();
     filter.Name = "ogg File";
     filter.AddPattern("*.ogg");
     dialog.AddFilter(filter);
     if (dialog.Run() == (int)ResponseType.Accept)
     {
         AddSongs(dialog.Filenames);
     }
     dialog.Destroy();
 }
Пример #40
0
        public bool SaveFileDialog(SaveFileDialogParams saveParams, Action <SaveFileDialogParams> callback)
        {
            WinformsSystemWindow.ShowingSystemDialog = true;
            Gtk.Application.Init();

            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog(saveParams.Title,
                                          null,
                                          FileChooserAction.Save,
                                          "Cancel", ResponseType.Cancel,
                                          "Save", ResponseType.Accept);

            Gtk.FileFilter filter = new Gtk.FileFilter();
            filter.Name = saveParams.Filter.Split('|')[0];
            string[] extensions = saveParams.Filter.Split('|')[1].Split(';');
            foreach (string e in extensions)
            {
                filter.AddPattern(e.ToLower());
            }
            fc.AddFilter(filter);

            //Set default filename and add file extension
            fc.CurrentName = saveParams.FileName + extensions[0].TrimStart('*');
            if (saveParams.InitialDirectory != null)
            {
                fc.SetCurrentFolder(saveParams.InitialDirectory);
            }

            fc.KeepAbove = true;

            if (fc.Run() == (int)ResponseType.Accept)
            {
                this.LastDirectoryUsed = Path.GetDirectoryName(fc.Filename);
                saveParams.FileName    = fc.Filename;
                UiThread.RunOnIdle(() =>
                {
                    callback(saveParams);
                });
            }

            fc.Destroy();
            while (Gtk.Application.EventsPending())
            {
                Gtk.Main.Iteration();
            }

            WinformsSystemWindow.ShowingSystemDialog = false;

            return(true);
        }
Пример #41
0
 private static void AddFilters(FileChooserDialog dialog) 
 {
     // Add experiment files filter
     FileFilter fileFilter = new FileFilter();
     fileFilter.AddPattern("*.teml");
     fileFilter.Name = Mono.Unix.Catalog.GetString("Experiment files (.teml)");
     dialog.AddFilter(fileFilter);
     
     //add another option of All files
     FileFilter allFilesFilter = new FileFilter();
     allFilesFilter.Name = Mono.Unix.Catalog.GetString("All files");
     allFilesFilter.AddPattern("*.*");
     dialog.AddFilter(allFilesFilter);
 }
        public MainWindow2()
            : base(Gtk.WindowType.Toplevel)
        {
            this.Build();

            m_app = new App();

            m_app.Should += delegate(Act action) {
                switch (action) {
                    case Act.AnalyzeHorizontal: return IsHorizontalActive;
                    case Act.AnalyzeVertical: return IsVerticalActive;
                    case Act.AnalyzeIslands: return IsIslandsActive;
                    case Act.Analyze: return true;
                    case Act.Clean: return IsCleanActive;
                    case Act.RemoveBackground: return IsRemoveBackgroundActive;
                    case Act.RefreshIslandsOutputAction: return true;
                    case Act.Process: return true;
                }

            #if DEBUG
                throw new NotImplementedException(action.ToString());
            #else
                return false;
            #endif
            };

            m_app.UpdateInterface += delegate(object sender, UIEventArgs e) {
                var app = m_app;
                switch (e.UI) {
                    case UI.Output: textviewOutput.Buffer.Text = app.Output; return;
                    case UI.ErrorMessage: ShowError(app.ErrorMessage); return;
                    case UI.Filename: return;
                    case UI.IslandEditor: islandeditor1.App = m_app; islandeditor1.QueueDraw(); return;
                    case UI.CompletedTask: ShowCompleted(app.Task); return;
                }

            #if DEBUG
                throw new NotImplementedException(e.UI.ToString());
            #endif
            };

            comboboxMode.Active = 0;
            comboboxProcess.Active = 0;
            islandeditor1.App = m_app;

            var filter = new FileFilter();
            filter.AddPattern("*.png");
            filter.AddPattern("*.PNG");
            filechooserbuttonOpen.AddFilter(filter);
        }
Пример #43
0
        /// <summary>
        /// Choose file to save contacts.
        /// </summary>
        private string ChooseFileToSave(string dialogTitle)
        {
            string fileToSave = "";

            // New dialog to save sim contacts on file
            Gtk.FileChooserDialog FileBox = new Gtk.FileChooserDialog(dialogTitle,
                                                                      MainWindow,
                                                                      FileChooserAction.Save,
                                                                      GlobalObjUI.LMan.GetString("cancellbl"), Gtk.ResponseType.Cancel,
                                                                      GlobalObjUI.LMan.GetString("savelbl"), Gtk.ResponseType.Accept);

            // Filter for using only monosim files
            Gtk.FileFilter myFilter = new Gtk.FileFilter();
            myFilter.AddPattern("*.monosim");
            myFilter.Name = "monosim files";
            FileBox.AddFilter(myFilter);

            // Manage result of dialog box
            FileBox.Icon = Gdk.Pixbuf.LoadFromResource("monosim.png");
            int retFileBox = FileBox.Run();

            if ((ResponseType)retFileBox == Gtk.ResponseType.Accept)
            {
                // path of a right file returned
                fileToSave = FileBox.Filename;

                string chkfile = fileToSave.PadLeft(9).ToLower();
                if (chkfile.Substring(chkfile.Length - 8) != ".monosim")
                {
                    fileToSave += ".monosim";
                }

                FileBox.Destroy();
                FileBox.Dispose();
            }
            else
            {
                // nothing returned
                FileBox.Destroy();
                FileBox.Dispose();
                return("");
            }

            return(fileToSave);
        }
Пример #44
0
        /// <summary>
        /// Open command file
        /// </summary>
        private void OpenCommandFile()
        {
            // New dialog for select command file
            Gtk.FileChooserDialog FileBox =
                new Gtk.FileChooserDialog(GlobalObj.LMan.GetString("selectfile"),
                                          MainWindow,
                                          FileChooserAction.Open,
                                          GlobalObj.LMan.GetString("cancellbl"),
                                          Gtk.ResponseType.Cancel,
                                          GlobalObj.LMan.GetString("openlbl"),
                                          Gtk.ResponseType.Accept);

            // Filter to use only comex files
            Gtk.FileFilter myFilter = new Gtk.FileFilter();
            myFilter.AddPattern("*.comex");
            myFilter.Name = "comex project files (*.comex)";
            FileBox.AddFilter(myFilter);

            // Manage result of dialog box
            FileBox.Icon = Gdk.Pixbuf.LoadFromResource("comex_256.png");
            int retFileBox = FileBox.Run();

            if ((ResponseType)retFileBox == Gtk.ResponseType.Accept)
            {
                // path of a right file returned
                commandFilePath = FileBox.Filename;
                commandFileName = System.IO.Path.GetFileNameWithoutExtension(commandFilePath);
                log.Debug("file selected: " + commandFilePath);

                UpdateGuiForCommandFile();



                FileBox.Destroy();
                FileBox.Dispose();
            }
            else
            {
                // nothing returned
                FileBox.Destroy();
                FileBox.Dispose();
                return;
            }
        }
Пример #45
0
        private void HandleAddFilesAction()
        {
            if (fileSystem == null)
            {
                return;
            }

            CustomFileChooserDialog dlg =
                new CustomFileChooserDialog(this, "Add files to pack", FileChooserAction.Open);

            dlg.FileChooser.SelectMultiple = true;

            using (Gtk.FileFilter filter = new Gtk.FileFilter())
            {
                filter.Name = "All";
                filter.AddPattern("*.*");
                dlg.FileChooser.AddFilter(filter);
            }

            dlg.Ok += (sender, e) =>
            {
                packTreeView.Selection.UnselectAll();

                waitWindow = new WaitWindow(this, "Adding", "");
                waitWindow.Show();

                ThreadNotify done = new ThreadNotify(new ReadyEvent(() =>
                {
                    dlg.Destroy();
                    waitWindow.Destroy();
                    waitWindow = null;
                }));

                new Thread(new ThreadStart(() =>
                {
                    dlg.FileChooser.Filenames.ToList().ForEach(
                        file => AppendFile(currentFolder, file));
                    done.WakeupMain();
                })).Start();
            };
            dlg.Cancel += (sender, e) => dlg.Destroy();
            dlg.Show();
        }
Пример #46
0
    public void OnOpenActivate(object o, EventArgs args)
    {
        string filename = null;

        //FileSelection openFileDialog = new FileSelection ("Open File");
        Gtk.FileFilter txtFileFilter = new Gtk.FileFilter();
        txtFileFilter.AddPattern("*.txt");
        txtFileFilter.Name = "Plain Text";
        Gtk.FileChooserDialog openFileDialog = new Gtk.FileChooserDialog("Open file", mindFire, FileChooserAction.Open, Stock.Cancel, ResponseType.Cancel, Stock.Open, ResponseType.Ok);
        //openFileDialog.Complete ("*.txt");
        //openFileDialog.HideFileopButtons ();
        openFileDialog.AddFilter(txtFileFilter);
        openFileDialog.Run();
        filename = openFileDialog.Filename;
        if (File.Exists(filename))
        {
            // Check mimetype
            OpenFile(filename);
        }
        openFileDialog.Destroy();
    }
Пример #47
0
    private void file_dialog()
    {
        Gtk.FileChooserDialog filechooser =
            new Gtk.FileChooserDialog("Pick the sh.tex",
                                      this,
                                      FileChooserAction.Open,
                                      "Cancel", ResponseType.Cancel,
                                      "Open", ResponseType.Accept);

        Gtk.FileFilter filter = new Gtk.FileFilter();
        filter.Name = "tex";
        filter.AddPattern("sh.tex");
        filechooser.Filter = filter;

        if (filechooser.Run() == (int)ResponseType.Accept)
        {
            filepath = filechooser.Filename;
            load_file();
        }

        filechooser.Destroy();
    }
Пример #48
0
    protected void OnOpen(object o, EventArgs e)
    {
        FileChooserDialog fileChooser = new FileChooserDialog("Select TileSet", MainWindow, FileChooserAction.Open, new object[] {});

        fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
        fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
        fileChooser.DefaultResponse = Gtk.ResponseType.Ok;
        Gtk.FileFilter filter;
        filter      = new Gtk.FileFilter();
        filter.Name = "Supertux tilesets";
        filter.AddPattern("*.strf");
        filter.AddPattern("*.stgt");
        fileChooser.AddFilter(filter);
        filter      = new Gtk.FileFilter();
        filter.Name = "Supertux 0.1.x tilesets";
        filter.AddPattern("*.stgt");
        fileChooser.AddFilter(filter);
        filter      = new Gtk.FileFilter();
        filter.Name = "Supertux 0.3.x tilesets";
        filter.AddPattern("*.strf");
        fileChooser.AddFilter(filter);
        Gtk.FileFilter all = new Gtk.FileFilter();
        all.Name = "All Files";
        all.AddPattern("*");
        fileChooser.AddFilter(all);
        int result = fileChooser.Run();

        fileChooser.Hide();

        if (result != (int)ResponseType.Ok)
        {
            return;
        }

        LoadTileSet(fileChooser.Filename);
    }
        protected void OnTargetNMMLFileButtonClicked(object sender, System.EventArgs e)
        {
            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog("Target NMML file", this.Toplevel as Gtk.Window, FileChooserAction.Open,
                                          "Cancel", ResponseType.Cancel,
                                          "Select", ResponseType.Accept);

            Gtk.FileFilter filterNMML = new Gtk.FileFilter();
            filterNMML.Name = "NMML Files";
            filterNMML.AddPattern("*.nmml");

            Gtk.FileFilter filterAll = new Gtk.FileFilter();
            filterAll.Name = "All Files";
            filterAll.AddPattern("*");

            fc.AddFilter(filterNMML);
            fc.AddFilter(filterAll);

            if (mProject.TargetNMMLFile != "")
            {
                fc.SetFilename(mProject.TargetNMMLFile);
            }
            else
            {
                fc.SetFilename(mProject.BaseDirectory);
            }

            if (fc.Run() == (int)ResponseType.Accept)
            {
                string path = PathHelper.ToRelativePath(fc.Filename, mProject.BaseDirectory);

                TargetNMMLFileEntry.Text = path;
            }

            fc.Destroy();
        }
Пример #50
0
        protected void OnPdfActionActivated(object sender, System.EventArgs e)
        {
            // *********************************
            object[] param = new object[4];
            param[0] = "Cancel";
            param[1] = Gtk.ResponseType.Cancel;
            param[2] = "Save";
            param[3] = Gtk.ResponseType.Accept;

            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog("Save File As",
                                          null,
                                          Gtk.FileChooserAction.Save,
                                          param);

            fc.CurrentName = DefaultExportFileName ?? report.Name;

            Gtk.FileFilter pdfFilter = new Gtk.FileFilter();
            pdfFilter.Name = "PDF";

            Gtk.FileFilter csvFilter = new Gtk.FileFilter();
            csvFilter.Name = "CSV";

            Gtk.FileFilter asphtmlFilter = new Gtk.FileFilter();
            asphtmlFilter.Name = "ASP HTML";

            Gtk.FileFilter excel2007 = new Gtk.FileFilter();
            excel2007.Name = "Excel 2007";

            Gtk.FileFilter htmlFilter = new Gtk.FileFilter();
            htmlFilter.Name = "HTML";

            Gtk.FileFilter mhtmlFilter = new Gtk.FileFilter();
            mhtmlFilter.Name = "MHTML";

            Gtk.FileFilter rtfFilter = new Gtk.FileFilter();
            rtfFilter.Name = "RTF";

            Gtk.FileFilter xmlFilter = new Gtk.FileFilter();
            xmlFilter.Name = "XML";

            fc.AddFilter(pdfFilter);
            fc.AddFilter(csvFilter);
            fc.AddFilter(asphtmlFilter);
            fc.AddFilter(excel2007);
            fc.AddFilter(htmlFilter);
            fc.AddFilter(mhtmlFilter);
            fc.AddFilter(xmlFilter);

            if (fc.Run() == (int)Gtk.ResponseType.Accept)
            {
                try
                {
                    // Must use the RunGetData before each export or there is no data.
                    report.RunGetData(this.Parameters);

                    string filename = fc.Filename;
                    OutputPresentationType exportType = OutputPresentationType.PDF;
                    if (fc.Filter.Name == "CSV")
                    {
                        exportType = OutputPresentationType.CSV;
                        if (filename.ToLower().Trim().EndsWith(".csv") == false)
                        {
                            filename = filename + ".csv";
                        }
                    }
                    else if (fc.Filter.Name == "PDF")
                    {
                        exportType = OutputPresentationType.PDF;
                        if (filename.ToLower().Trim().EndsWith(".pdf") == false)
                        {
                            filename = filename + ".pdf";
                        }
                    }
                    else if (fc.Filter.Name == "ASP HTML")
                    {
                        exportType = OutputPresentationType.ASPHTML;
                        if (filename.ToLower().Trim().EndsWith(".asphtml") == false)
                        {
                            filename = filename + ".asphtml";
                        }
                    }
                    else if (fc.Filter.Name == "Excel 2007")
                    {
                        exportType = OutputPresentationType.Excel;
                        if (filename.ToLower().Trim().EndsWith(".xlsx") == false)
                        {
                            filename = filename + ".xlsx";
                        }
                    }
                    else if (fc.Filter.Name == "HTML")
                    {
                        exportType = OutputPresentationType.HTML;
                        if (filename.ToLower().Trim().EndsWith(".html") == false)
                        {
                            filename = filename + ".html";
                        }
                    }
                    else if (fc.Filter.Name == "MHTML")
                    {
                        exportType = OutputPresentationType.MHTML;
                        if (filename.ToLower().Trim().EndsWith(".mhtml") == false)
                        {
                            filename = filename + ".mhtml";
                        }
                    }
                    else if (fc.Filter.Name == "XML")
                    {
                        exportType = OutputPresentationType.XML;
                        if (filename.ToLower().Trim().EndsWith(".xml") == false)
                        {
                            filename = filename + ".xml";
                        }
                    }

                    ExportReport(report, filename, exportType);
                }
                catch (Exception ex)
                {
                    Gtk.MessageDialog m = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Info,
                                                                Gtk.ButtonsType.Ok, false,
                                                                "Error Saving Copy of PDF." + System.Environment.NewLine + ex.Message);

                    m.Run();
                    m.Destroy();
                }
            }
            //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            fc.Destroy();
        }
Пример #51
0
        protected void OnPdfActionActivated(object sender, System.EventArgs e)
        {
            // *********************************
            object[] param = new object[4];
            param[0] = "Cancel";
            param[1] = Gtk.ResponseType.Cancel;
            param[2] = "Save";
            param[3] = Gtk.ResponseType.Accept;

            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog("Save File As",
                                          null,
                                          Gtk.FileChooserAction.Save,
                                          param);

            fc.CurrentName = DefaultExportFileName ?? report.Name;

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.PDF))
            {
                Gtk.FileFilter pdfFilter = new Gtk.FileFilter {
                    Name = "PDF"
                };
                fc.AddFilter(pdfFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.CSV))
            {
                Gtk.FileFilter csvFilter = new Gtk.FileFilter {
                    Name = "CSV"
                };
                fc.AddFilter(csvFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.ExcelTableOnly))
            {
                Gtk.FileFilter excel2007Data = new Gtk.FileFilter {
                    Name = "Excel no formatting (Fast)"
                };
                fc.AddFilter(excel2007Data);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.Excel2007))
            {
                Gtk.FileFilter excel2007 = new Gtk.FileFilter {
                    Name = "Excel with formatting (Slow)"
                };
                fc.AddFilter(excel2007);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.TIF))
            {
                Gtk.FileFilter tiffFilter = new Gtk.FileFilter {
                    Name = "TIFF"
                };
                fc.AddFilter(tiffFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.ASPHTML))
            {
                Gtk.FileFilter asphtmlFilter = new Gtk.FileFilter {
                    Name = "ASP HTML"
                };
                fc.AddFilter(asphtmlFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.HTML))
            {
                Gtk.FileFilter htmlFilter = new Gtk.FileFilter {
                    Name = "HTML"
                };
                fc.AddFilter(htmlFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.MHTML))
            {
                Gtk.FileFilter mhtmlFilter = new Gtk.FileFilter {
                    Name = "MHTML"
                };
                fc.AddFilter(mhtmlFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.XML))
            {
                Gtk.FileFilter xmlFilter = new Gtk.FileFilter {
                    Name = "XML"
                };
                fc.AddFilter(xmlFilter);
            }

            if (!fc.Filters.Any())
            {
                Gtk.MessageDialog m = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Info,
                                                            Gtk.ButtonsType.Ok, false,
                                                            "Export in all document formats is prohibited");

                m.WindowPosition = WindowPosition.Center;
                m.Run();
                m.Destroy();
                return;
            }

            if (fc.Run() == (int)Gtk.ResponseType.Accept)
            {
                try
                {
                    // Must use the RunGetData before each export or there is no data.
                    report.RunGetData(this.Parameters);

                    string filename = fc.Filename;
                    OutputPresentationType exportType = OutputPresentationType.PDF;
                    if (fc.Filter.Name == "CSV")
                    {
                        exportType = OutputPresentationType.CSV;
                        if (filename.ToLower().Trim().EndsWith(".csv") == false)
                        {
                            filename = filename + ".csv";
                        }
                    }
                    else if (fc.Filter.Name == "PDF")
                    {
                        exportType = OutputPresentationType.PDF;
                        if (filename.ToLower().Trim().EndsWith(".pdf") == false)
                        {
                            filename = filename + ".pdf";
                        }
                    }
                    else if (fc.Filter.Name == "Excel 2007 Data")
                    {
                        exportType = OutputPresentationType.ExcelTableOnly;
                        if (filename.ToLower().Trim().EndsWith(".xlsx") == false)
                        {
                            filename = filename + ".xlsx";
                        }
                    }
                    else if (fc.Filter.Name == "Excel 2007")
                    {
                        exportType = OutputPresentationType.Excel2007;
                        if (filename.ToLower().Trim().EndsWith(".xlsx") == false)
                        {
                            filename = filename + ".xlsx";
                        }
                    }
                    else if (fc.Filter.Name == "TIFF")
                    {
                        exportType = OutputPresentationType.TIF;
                        if (filename.ToLower().Trim().EndsWith(".tif") == false)
                        {
                            filename = filename + ".tif";
                        }
                    }
                    else if (fc.Filter.Name == "ASP HTML")
                    {
                        exportType = OutputPresentationType.ASPHTML;
                        if (filename.ToLower().Trim().EndsWith(".asphtml") == false)
                        {
                            filename = filename + ".asphtml";
                        }
                    }
                    else if (fc.Filter.Name == "HTML")
                    {
                        exportType = OutputPresentationType.HTML;
                        if (filename.ToLower().Trim().EndsWith(".html") == false)
                        {
                            filename = filename + ".html";
                        }
                    }
                    else if (fc.Filter.Name == "MHTML")
                    {
                        exportType = OutputPresentationType.MHTML;
                        if (filename.ToLower().Trim().EndsWith(".mhtml") == false)
                        {
                            filename = filename + ".mhtml";
                        }
                    }
                    else if (fc.Filter.Name == "XML")
                    {
                        exportType = OutputPresentationType.XML;
                        if (filename.ToLower().Trim().EndsWith(".xml") == false)
                        {
                            filename = filename + ".xml";
                        }
                    }

                    ExportReport(report, filename, exportType);
                }
                catch (Exception ex)
                {
                    Gtk.MessageDialog m = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Info,
                                                                Gtk.ButtonsType.Ok, false,
                                                                "Error Saving Copy of PDF." + System.Environment.NewLine + ex.Message);

                    m.Run();
                    m.Destroy();
                }
            }
            //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            fc.Destroy();
        }
Пример #52
0
        protected void OnPdfActionActivated(object sender, System.EventArgs e)
        {
            // *********************************
            object[] param = new object[4];
            param[0] = Strings.ButtonCancel_Text;
            param[1] = Gtk.ResponseType.Cancel;
            param[2] = Strings.ButtonSave_Text;
            param[3] = Gtk.ResponseType.Accept;

            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog(Strings.FileChooser_SaveFileTo_Title,
                                          null,
                                          Gtk.FileChooserAction.Save,
                                          param);

            fc.CurrentName = DefaultExportFileName ?? report.Name;

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.PDF))
            {
                Gtk.FileFilter pdfFilter = new Gtk.FileFilter {
                    Name = "PDF"
                };
                var extensionPDF = ".pdf";
                pdfFilter.AddPattern($"*{extensionPDF}");
                fc.AddFilter(pdfFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.CSV))
            {
                Gtk.FileFilter csvFilter = new Gtk.FileFilter {
                    Name = "CSV"
                };
                var extensionCSV = ".csv";
                csvFilter.AddPattern($"*{extensionCSV}");
                fc.AddFilter(csvFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.ExcelTableOnly))
            {
                Gtk.FileFilter excel2007Data = new Gtk.FileFilter {
                    Name = "Excel no formatting (Fast)"
                };
                var extensionXLSX = ".xlsx";
                excel2007Data.AddPattern($"*{extensionXLSX}");
                fc.AddFilter(excel2007Data);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.Excel2007))
            {
                Gtk.FileFilter excel2007 = new Gtk.FileFilter {
                    Name = "Excel with formatting (Slow)"
                };
                var extensionXLSX = ".xlsx";
                excel2007.AddPattern($"*{extensionXLSX}");
                fc.AddFilter(excel2007);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.TIF))
            {
                Gtk.FileFilter tiffFilter = new Gtk.FileFilter {
                    Name = "TIFF"
                };
                var extensionTIFF = ".tiff";
                tiffFilter.AddPattern($"*{extensionTIFF}");
                fc.AddFilter(tiffFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.ASPHTML))
            {
                Gtk.FileFilter asphtmlFilter = new Gtk.FileFilter {
                    Name = "ASP HTML"
                };
                var extensionASPHTML = ".asphtml";
                asphtmlFilter.AddPattern($"*{extensionASPHTML}");
                fc.AddFilter(asphtmlFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.HTML))
            {
                Gtk.FileFilter htmlFilter = new Gtk.FileFilter {
                    Name = "HTML"
                };
                var extensionHTML = ".html";
                htmlFilter.AddPattern($"*{extensionHTML}");
                fc.AddFilter(htmlFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.MHTML))
            {
                Gtk.FileFilter mhtmlFilter = new Gtk.FileFilter {
                    Name = "MHTML"
                };
                var extensionMHTML = ".mhtml";
                mhtmlFilter.AddPattern($"*{extensionMHTML}");
                fc.AddFilter(mhtmlFilter);
            }

            if (!restrictedOutputPresentationTypes.Contains(OutputPresentationType.XML))
            {
                Gtk.FileFilter xmlFilter = new Gtk.FileFilter {
                    Name = "XML"
                };
                var extensionXML = ".xml";
                xmlFilter.AddPattern($"*{extensionXML}");
                fc.AddFilter(xmlFilter);
            }

            if (!fc.Filters.Any())
            {
                Gtk.MessageDialog m = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Info,
                                                            Gtk.ButtonsType.Ok, false,
                                                            "Export in all document formats is prohibited");

                m.WindowPosition = WindowPosition.Center;
                m.Run();
                m.Destroy();
                return;
            }

            if (fc.Run() == (int)Gtk.ResponseType.Accept)
            {
                try
                {
                    string searchPattern = "*";

                    string filename = fc.Filename;
                    OutputPresentationType exportType = OutputPresentationType.PDF;
                    if (fc.Filter.Name == "CSV")
                    {
                        exportType = OutputPresentationType.CSV;
                        if (filename.ToLower().Trim().EndsWith(".csv") == false)
                        {
                            filename      = filename + ".csv";
                            searchPattern = "*.csv";
                        }
                    }
                    else if (fc.Filter.Name == "PDF")
                    {
                        exportType = OutputPresentationType.PDF;
                        if (filename.ToLower().Trim().EndsWith(".pdf") == false)
                        {
                            filename      = filename + ".pdf";
                            searchPattern = "*.pdf";
                        }
                    }
                    else if (fc.Filter.Name == "Excel 2007 Data")
                    {
                        exportType = OutputPresentationType.ExcelTableOnly;
                        if (filename.ToLower().Trim().EndsWith(".xlsx") == false)
                        {
                            filename      = filename + ".xlsx";
                            searchPattern = "*.xlsx";
                        }
                    }
                    else if (fc.Filter.Name == "Excel 2007")
                    {
                        exportType = OutputPresentationType.Excel2007;
                        if (filename.ToLower().Trim().EndsWith(".xlsx") == false)
                        {
                            filename      = filename + ".xlsx";
                            searchPattern = "*.xlsx";
                        }
                    }
                    else if (fc.Filter.Name == "TIFF")
                    {
                        exportType = OutputPresentationType.TIF;
                        if (filename.ToLower().Trim().EndsWith(".tif") == false)
                        {
                            filename      = filename + ".tif";
                            searchPattern = "*.tif";
                        }
                    }
                    else if (fc.Filter.Name == "ASP HTML")
                    {
                        exportType = OutputPresentationType.ASPHTML;
                        if (filename.ToLower().Trim().EndsWith(".asphtml") == false)
                        {
                            filename      = filename + ".asphtml";
                            searchPattern = "*.asphtml";
                        }
                    }
                    else if (fc.Filter.Name == "HTML")
                    {
                        exportType = OutputPresentationType.HTML;
                        if (filename.ToLower().Trim().EndsWith(".html") == false)
                        {
                            filename      = filename + ".html";
                            searchPattern = "*.html";
                        }
                    }
                    else if (fc.Filter.Name == "MHTML")
                    {
                        exportType = OutputPresentationType.MHTML;
                        if (filename.ToLower().Trim().EndsWith(".mhtml") == false)
                        {
                            filename      = filename + ".mhtml";
                            searchPattern = "*.mhtml";
                        }
                    }
                    else if (fc.Filter.Name == "XML")
                    {
                        exportType = OutputPresentationType.XML;
                        if (filename.ToLower().Trim().EndsWith(".xml") == false)
                        {
                            filename      = filename + ".xml";
                            searchPattern = "*.xml";
                        }
                    }


                    string directory = filename.Remove(filename.LastIndexOf(@"\") + 1);

                    var files = Directory.GetFiles(directory, searchPattern);

                    //Check for files with same name in directory
                    if (files.Any())
                    {
                        for (int i = 0; i < files.Length; i++)
                        {
                            if (files[i] == filename)
                            {
                                //If found files with the same name in directory
                                MessageDialog m = new Gtk.MessageDialog(null, DialogFlags.Modal, MessageType.Question,
                                                                        Gtk.ButtonsType.YesNo, false,
                                                                        Strings.SaveToFile_CheckIf_SameFilesInDir);

                                m.SetPosition(WindowPosition.Center);
                                ResponseType result = (ResponseType)m.Run();
                                m.Destroy();
                                if (result == ResponseType.Yes)
                                {
                                    // Must use the RunGetData before each export or there is no data.
                                    report.RunGetData(this.Parameters);
                                    ExportReport(report, filename, exportType);
                                    break;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            if (i + 1 == files.Length && files[i] != filename)
                            {
                                //If no files with the same name found in directory
                                // Must use the RunGetData before each export or there is no data.
                                report.RunGetData(this.Parameters);
                                ExportReport(report, filename, exportType);
                                break;
                            }
                        }
                    }
                    else
                    {
                        //If no files found in directory
                        // Must use the RunGetData before each export or there is no data.
                        report.RunGetData(this.Parameters);
                        ExportReport(report, filename, exportType);
                    }
                }
                catch (Exception ex)
                {
                    Gtk.MessageDialog m = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Info,
                                                                Gtk.ButtonsType.Ok, false,
                                                                "Error Saving Copy of PDF." + System.Environment.NewLine + ex.Message);

                    m.Run();
                    m.Destroy();
                }
            }
            //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            fc.Destroy();
        }
Пример #53
0
        protected void OnButtonOkClicked(object sender, EventArgs e)
        {
            #region Выбираем файл
            var fileChooser = new Gtk.FileChooserDialog(
                "Сохранить как...",
                (Window)this.Toplevel,
                Gtk.FileChooserAction.Save,
                "Отмена", ResponseType.Cancel,
                "Сохранить", ResponseType.Accept);

            Gtk.FileFilter excel2007 = new Gtk.FileFilter();
            excel2007.AddPattern("*.xlsx");
            excel2007.Name = ".xlsx (Excel 2007)";

            //Gtk.FileFilter excel2003 = new Gtk.FileFilter();
            //excel2003.AddPattern("*.xls");
            //excel2003.Name = ".xls (Excel 2003)";

            fileChooser.AddFilter(excel2007);
            //fileChooser.AddFilter(excel2003);

            string filename;
            bool   result = fileChooser.Run() == (int)ResponseType.Accept;
            filename = fileChooser.Filename;
            fileChooser.Destroy();
            if (!result)
            {
                return;
            }

            #endregion
            #region Загружаем заказы

            buttonOk.Sensitive            = buttonCancel.Sensitive = false;
            progressbar1.Text             = "Загрузка списка заказов...";
            progressbar1.Adjustment.Upper = 1;
            GtkHelper.WaitRedraw();

            if (!filename.EndsWith(".xlsx"))             //&& !filename.EndsWith(".xls"))
            {
                filename += ".xlsx";
            }

            var orders = WorkOrderRepository.GetOrders(UoW, daterange.StartDateOrNull, daterange.EndDateOrNull);
            logger.Info($"Загружено {orders.Count} заказов.");
            progressbar1.Adjustment.Upper = orders.Count + 2;

            progressbar1.Text = "Формирование файла...";
            GtkHelper.WaitRedraw();

            #endregion
            #region Базовые настройки

            var workbook = new XSSFWorkbook();
            var sheet    = workbook.CreateSheet("Заказы");

            //Заголовок
            var headerStyle = workbook.CreateCellStyle();
            var headerFont  = workbook.CreateFont();
            headerFont.FontName           = "Calibri";
            headerFont.FontHeightInPoints = 11;
            headerFont.IsBold             = true;
            headerStyle.SetFont(headerFont);

            var newDataFormat = workbook.CreateDataFormat();
            var dateCellStyle = workbook.CreateCellStyle();
            dateCellStyle.DataFormat = newDataFormat.GetFormat("dd.MM.yyyy");

            //Ширина измеряется в количестве симвовлов * 256
            sheet.SetColumnWidth(0, 7 * 256);
            sheet.SetColumnWidth(1, 14 * 256);
            sheet.SetColumnWidth(2, 16 * 256);
            sheet.SetColumnWidth(3, 5 * 256);
            sheet.SetColumnWidth(4, 20 * 256);
            sheet.SetColumnWidth(5, 11 * 256);
            sheet.SetColumnWidth(6, 14 * 256);
            sheet.SetColumnWidth(7, 15 * 256);
            sheet.SetColumnWidth(8, 6 * 256);
            sheet.SetColumnWidth(9, 20 * 256);
            sheet.SetColumnWidth(10, 12 * 256);
            sheet.SetColumnWidth(11, 15 * 256);
            sheet.SetColumnWidth(12, 10 * 256);

            #endregion
            #region параметры экспорта

            string[] columnTiles = new string[] {
                "Номер",
                "Марка",
                "Модель",
                "Год",
                "Еврокод",
                "Производитель",
                "Склад",
                "Телефон",
                "Сумма работ",
                "Коментарий",
                "Состояние заказа",
                "Вид работ",
                "Дата работы"
            };

            Action <WorkOrder, ICell>[] SetValuesFuncs = new Action <WorkOrder, ICell>[]
            {
                (o, c) => c.SetCellValue(o.Id),
                (o, c) => c.SetCellValue(o.CarModel?.Brand?.Name),
                (o, c) => c.SetCellValue(o.CarModel?.Name),
                (o, c) => c.SetCellValue(o.CarYearText),
                (o, c) => c.SetCellValue(o.Eurocode),
                (o, c) => c.SetCellValue(o.Manufacturer?.Name),
                (o, c) => c.SetCellValue(o.Stock?.Name),
                (o, c) => c.SetCellValue(o.Phone),
                (o, c) => c.SetCellValue((double)o.Pays.Sum(x => x.Cost)),
                (o, c) => c.SetCellValue(o.Comment),
                (o, c) => c.SetCellValue(o.OrderState?.Name),
                (o, c) => c.SetCellValue(o.OrderTypeClass?.Name),
                (o, c) => {
                    c.SetCellValue(o.Date);
                    c.CellStyle = dateCellStyle;
                },
            };

            #endregion

            var headerRow = sheet.CreateRow(0);
            for (var i = 0; i < columnTiles.Length; i++)
            {
                var cell = headerRow.CreateCell(i);
                cell.SetCellValue(columnTiles[i]);
                cell.CellStyle = headerStyle;
            }

            for (var row = 1; row <= orders.Count; row++)
            {
                progressbar1.Text = $"Заказ {row} из {orders.Count}";
                progressbar1.Adjustment.Value++;
                GtkHelper.WaitRedraw();

                var dataRow = sheet.CreateRow(row);
                for (var i = 0; i < columnTiles.Length; i++)
                {
                    var cell = dataRow.CreateCell(i);
                    SetValuesFuncs[i](orders[row - 1], cell);
                }
            }

            if (updatePhoneFormat)
            {
                PhoneUpdate(workbook, orders);
            }

            progressbar1.Text = "Записываем фаил...";
            progressbar1.Adjustment.Value++;
            GtkHelper.WaitRedraw();

            try
            {
                using (FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write))
                {
                    workbook.Write(file);
                }
            }
            catch (IOException ex)
            {
                if (ex.HResult == -2147024864)
                {
                    MessageDialogHelper.RunErrorDialog("Указанный файл уже открыт в другом приложении. Оно заблокировало доступ к файлу.");
                    return;
                }
                throw ex;
            }
            progressbar1.Text = "Готово";
            progressbar1.Adjustment.Value++;
            GtkHelper.WaitRedraw();

            if (checkOpenAfterSave.Active)
            {
                progressbar1.Text = "Открываем Excel";
                GtkHelper.WaitRedraw();
                logger.Info("Открываем во внешем приложении...");
                System.Diagnostics.Process.Start(filename);
            }
            logger.Info("Ок");
            Respond(ResponseType.Ok);
        }
Пример #54
0
        private void HandleExtractAction()
        {
            if (fileSystem == null)
            {
                return;
            }

            int selectedCount = packTreeView.Selection.CountSelectedRows();

            if (selectedCount == 0)
            {
                return;
            }

            List <TreeIter> selectedInFolder = packTreeView.GetSelected().ToList();

            Packer.Item firstItem = folderStore.GetValue(selectedInFolder.First(), 2) as Packer.Item;

            if (selectedCount == 1 && !firstItem.IsFolder)
            {
                TreeIter iterInPack = FindInPack(firstItem);

                CustomFileChooserDialog dlg = new CustomFileChooserDialog(this, "Extract file from pack", FileChooserAction.Save);
                dlg.FileChooser.CurrentName = firstItem.Name;

                using (Gtk.FileFilter filter = new Gtk.FileFilter())
                {
                    filter.Name = "All";
                    filter.AddPattern("*.*");
                    dlg.FileChooser.AddFilter(filter);
                }

                dlg.Ok += (sender, e) =>
                {
                    ExtractFile(iterInPack, dlg.FileChooser.Filename);
                    dlg.Destroy();
                };
                dlg.Cancel += (sender, e) => dlg.Destroy();
                dlg.Show();
            }
            else
            {
                CustomFileChooserDialog dlg = new CustomFileChooserDialog(
                    this, "Extract from pack", FileChooserAction.SelectFolder);

                dlg.Ok += (sender, e) =>
                {
                    selectedInFolder.ForEach(iter =>
                    {
                        Packer.Item item    = folderStore.GetValue(iter, 2) as Packer.Item;
                        TreeIter iterInPack = FindInPack(item);

                        if (item.IsFolder)
                        {
                            ExtractFolder(iterInPack, dlg.FileChooser.Filename);
                        }
                        else
                        {
                            ExtractFile(iterInPack, dlg.FileChooser.Filename +
                                        System.IO.Path.DirectorySeparatorChar + item.Name);
                        }
                    });

                    dlg.Destroy();
                };
                dlg.Cancel += (sender, e) => dlg.Destroy();
                dlg.Show();
            }
        }
Пример #55
0
        /* GS Result*/
        public void GSResult(gsParamState_t gs_result)
        {
            TempFile tempfile = null;

            if (gs_result.outputfile != null)
            {
                tempfile = new TempFile(gs_result.outputfile);
            }

            if (gs_result.result == GS_Result_t.gsCANCELLED)
            {
                if (tempfile != null)
                {
                    try
                    {
                        tempfile.DeleteFile();
                    }
                    catch
                    {
                        ShowMessage(NotifyType_t.MESS_STATUS, "Problem Deleting Temp File");
                    }
                }
                return;
            }
            if (gs_result.result == GS_Result_t.gsFAILED)
            {
                ShowMessage(NotifyType_t.MESS_STATUS, "GS Failed Conversion");
                if (tempfile != null)
                {
                    try
                    {
                        tempfile.DeleteFile();
                    }
                    catch
                    {
                        ShowMessage(NotifyType_t.MESS_STATUS, "Problem Deleting Temp File");
                    }
                }
                return;
            }

            switch (gs_result.task)
            {
            case GS_Task_t.PS_DISTILL:
                m_origfile = gs_result.inputfile;

                Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog("Save Document",
                                                                         (Gtk.Window) this.Toplevel,
                                                                         Gtk.FileChooserAction.Save);
                dialog.LocalOnly = true;
                dialog.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
                dialog.AddButton(Gtk.Stock.Save, Gtk.ResponseType.Yes);
                dialog.SetFilename(System.IO.Path.GetFileNameWithoutExtension(m_origfile) + ".pdf");

                Gtk.FileFilter filter = new Gtk.FileFilter();
                filter.Name = "doc/pdf";
                filter.AddMimeType("application/pdf");
                filter.AddPattern("*.pdf");
                dialog.Filter = filter;

                int response = dialog.Run();
                if (response == (int)Gtk.ResponseType.Yes)
                {
                    m_currfile = dialog.Filename;
                    try
                    {
                        if (System.IO.File.Exists(m_currfile))
                        {
                            System.IO.File.Delete(m_currfile);
                        }

                        var res = System.IO.File.Exists(tempfile.Filename);
                        System.IO.File.Copy(tempfile.Filename, dialog.Filename);
                    }
                    catch (Exception except)
                    {
                        ShowMessage(NotifyType_t.MESS_ERROR, "Exception Saving Distilled Result:" + except.Message);
                    }
                }

                dialog.Destroy();
                tempfile.DeleteFile();
                break;
            }
        }
Пример #56
0
    private Application(string[] args)
    {
        selection = new Selection();

        Glade.XML.CustomHandler = GladeCustomWidgetHandler;
        Glade.XML gxml = new Glade.XML("editor.glade", "MainWindow");
        gxml.Autoconnect(this);

        if (MainWindow == null)
        {
            throw new Exception("Couldn't resolve all widgets");
        }

        Tileset.LoadEditorImages = true;

        // Initialize status bar for PrintStatus()
        printStatusContextID = sbMain.GetContextId("PrintStatus");
        printStatusMessageID = sbMain.Push(printStatusContextID, "Welcome to Tuxjunior-Editor.");

        MainWindow.DeleteEvent += OnDelete;

        MainWindow.SetSizeRequest(900, 675);
        MainWindowTitlePrefix = MainWindow.Title;
        UpdateTitlebar();
        UpdateRecentDocuments();
        MainWindow.Icon = EditorStock.WindowIcon;
        //HACK: not a typo, EditorStock adds icons to the stock only when called 2x or more..
        MainWindow.Icon = EditorStock.WindowIcon;
        MainWindow.ShowAll();

        // Tool "Select" is selected by default - call its event handler
        OnToolSelect(null, null);

        fileChooser = new FileChooserDialog("Choose a Level", MainWindow, FileChooserAction.Open, new object[] {});
        if (Settings.Instance.LastDirectoryName == null)
        {
            if (Settings.Instance.TuxjuniorData != null)
            {
                Settings.Instance.LastDirectoryName = Settings.Instance.TuxjuniorData + "levels" + System.IO.Path.DirectorySeparatorChar;
            }
            else
            {
                Settings.Instance.LastDirectoryName = Environment.ExpandEnvironmentVariables("%HOME%");
            }
        }
        fileChooser.SetCurrentFolder(Settings.Instance.LastDirectoryName);
        fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
        fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
        fileChooser.DefaultResponse = Gtk.ResponseType.Ok;
        Gtk.FileFilter filter = new Gtk.FileFilter();
        filter.Name = "Tuxjunior Levels and Worldmaps";
        filter.AddPattern("*.stl");
        filter.AddPattern("*.stwm");
        fileChooser.AddFilter(filter);
        Gtk.FileFilter levelfilter = new Gtk.FileFilter();
        levelfilter.Name = "Tuxjunior Levels";
        levelfilter.AddPattern("*.stl");
        fileChooser.AddFilter(levelfilter);
        Gtk.FileFilter worldmapfilter = new Gtk.FileFilter();
        worldmapfilter.Name = "Tuxjunior Worldmaps";
        worldmapfilter.AddPattern("*.stwm");
        fileChooser.AddFilter(worldmapfilter);
        Gtk.FileFilter brushfilter = new Gtk.FileFilter();
        brushfilter.Name = "Tuxjunior-Editor Brushes";
        brushfilter.AddPattern("*.csv");
        fileChooser.AddFilter(brushfilter);
        Gtk.FileFilter all = new Gtk.FileFilter();
        all.Name = "All Files";
        all.AddPattern("*");
        fileChooser.AddFilter(all);
        if (Settings.Instance.TuxjuniorData != null)
        {
            try {
                fileChooser.AddShortcutFolder(Settings.Instance.TuxjuniorData + System.IO.Path.DirectorySeparatorChar + "levels");
            } catch (Exception e) {
                LogManager.Log(LogLevel.Warning, "Couldn't add tuxjunior level directory to File Chooser: " + e.Message);
            }
        }

        if (args.Length > 0)
        {
            Load(args[0]);
        }

        UndoManager.OnAddCommand += OnUndoManager;
        UndoManager.OnRedo       += OnUndoManager;
        UndoManager.OnUndo       += OnUndoManager;

        PrintStatus("Welcome to Tuxjunior-Editor.");
    }
Пример #57
0
        private void HandleSaveAction()
        {
            if (fileSystem == null)
            {
                return;
            }

            CustomFileChooserDialog dlg =
                new CustomFileChooserDialog(this, "Save pack", FileChooserAction.Save);

            dlg.FileChooser.SelectMultiple = false;

            using (Gtk.FileFilter filter = new Gtk.FileFilter())
            {
                filter.Name = fileSystem.Extension.ToUpper();
                filter.AddPattern("*." + fileSystem.Extension.ToLower());
                dlg.FileChooser.AddFilter(filter);
            }

            using (Gtk.FileFilter filter = new Gtk.FileFilter())
            {
                filter.Name = "All";
                filter.AddPattern("*.*");
                dlg.FileChooser.AddFilter(filter);
            }

            dlg.Ok += (sender, e) =>
            {
                string filename = dlg.FileChooser.Filename;

                waitWindow = new WaitWindow(this, "Saving", filename);
                waitWindow.Show();

                ThreadNotify done = new ThreadNotify(new ReadyEvent(() =>
                {
                    waitWindow.Destroy();
                    waitWindow = null;
                }));

                ThreadNotify error = new ThreadNotify(new ReadyEvent(() =>
                {
                    waitWindow.Destroy();
                    waitWindow = null;

                    CustomMessageDialog msg =
                        new CustomMessageDialog(this, MessageType.Error, fileSystem.LastError);
                    msg.Run();
                    msg.Destroy();
                }));

                new Thread(new ThreadStart(() =>
                {
                    if (fileSystem.Save(filename))
                    {
                        done.WakeupMain();
                    }
                    else
                    {
                        error.WakeupMain();
                    }
                })).Start();

                dlg.Destroy();
            };
            dlg.Cancel += (sender, e) => dlg.Destroy();
            dlg.Show();
        }
Пример #58
0
    private Application(Options opts)
    {
        selection = new TileSelection();

        Glade.XML.CustomHandler = GladeCustomWidgetHandler;
        Glade.XML gxml = new Glade.XML("editor.glade", "MainWindow");
        gxml.Autoconnect(this);

        if (MainWindow == null)
        {
            throw new Exception("Couldn't resolve all widgets");
        }

        ((GameObjectListWidget)ToolGObjectsProps).SetGtkFrame(fGObjects);

        Tileset.LoadEditorImages = true;

        // Initialize status bar for PrintStatus()
        printStatusContextID = sbMain.GetContextId("PrintStatus");
        printStatusMessageID = sbMain.Push(printStatusContextID, "Welcome to Supertux-Editor.");

        MainWindow.DeleteEvent += OnDelete;

        MainWindow.SetSizeRequest(900, 675);
        MainWindowTitlePrefix = MainWindow.Title;
        UpdateTitlebar();
        UpdateRecentDocuments();
        MainWindow.Icon = EditorStock.WindowIcon;
        //HACK: not a typo, EditorStock adds icons to the stock only when called 2x or more..
        MainWindow.Icon = EditorStock.WindowIcon;
        MainWindow.ShowAll();

        // Manually set icons for Tools, automatic stock initialization is broken on some systems
        ToolSelect.StockId       = EditorStock.ToolSelect;
        ToolTiles.StockId        = EditorStock.ToolTiles;
        ToolObjects.StockId      = EditorStock.ToolObjects;
        ToolBrush.StockId        = EditorStock.ToolBrush;
        ToolFill.StockId         = EditorStock.ToolFill;
        ToolReplace.StockId      = EditorStock.ToolReplace;
        ToolPath.StockId         = EditorStock.ToolPath;
        ToolButtonCamera.StockId = EditorStock.Camera;

        // Hide some extra widgets (because MainWindow.ShowAll(); showed them all)
        fGObjects.Visible = false;
        if (Settings.Instance.ToolboxOnRight)
        {
            aTools.Reparent(fToolsRight);
            fToolsLeft.Hide();
        }
        else
        {
            aTools.Reparent(fToolsLeft);
            fToolsRight.Hide();
        }


        // Tool "Select" is selected by default - call its event handler
        OnToolSelect(null, null);

        //Setup drag destination for "files"
        Gtk.Drag.DestSet(MainWindow, Gtk.DestDefaults.All, target_table,
                         Gdk.DragAction.Default |
                         Gdk.DragAction.Copy |
                         Gdk.DragAction.Move |
                         Gdk.DragAction.Link |
                         Gdk.DragAction.Private |
                         Gdk.DragAction.Ask);
        MainWindow.DragDataReceived += OnDragDataReceived;

        fileChooser = new Gtk.FileChooserDialog("Choose a Level", MainWindow, Gtk.FileChooserAction.Open, new object[] {});
        if (!Directory.Exists(Settings.Instance.LastDirectoryName))             //noexistent (or null) LastDirectoryName, resetting to default
        {
            if (Settings.Instance.SupertuxData != null)
            {
                Settings.Instance.LastDirectoryName = System.IO.Path.Combine(Settings.Instance.SupertuxData, "levels") + System.IO.Path.DirectorySeparatorChar;
            }
            else
            {
                Settings.Instance.LastDirectoryName = Environment.ExpandEnvironmentVariables("%HOME%");
            }
        }
        fileChooser.SetCurrentFolder(Settings.Instance.LastDirectoryName);
        fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
        fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
        fileChooser.DefaultResponse = Gtk.ResponseType.Ok;
        Gtk.FileFilter filter = new Gtk.FileFilter();
        filter.Name = "Supertux Levels and Worldmaps";
        filter.AddPattern("*.stl");
        filter.AddPattern("*.stwm");
        fileChooser.AddFilter(filter);
        Gtk.FileFilter levelfilter = new Gtk.FileFilter();
        levelfilter.Name = "Supertux Levels";
        levelfilter.AddPattern("*.stl");
        fileChooser.AddFilter(levelfilter);
        Gtk.FileFilter worldmapfilter = new Gtk.FileFilter();
        worldmapfilter.Name = "Supertux Worldmaps";
        worldmapfilter.AddPattern("*.stwm");
        fileChooser.AddFilter(worldmapfilter);
        Gtk.FileFilter brushfilter = new Gtk.FileFilter();
        brushfilter.Name = "Supertux-Editor Brushes";
        brushfilter.AddPattern("*.csv");
        fileChooser.AddFilter(brushfilter);
        Gtk.FileFilter all = new Gtk.FileFilter();
        all.Name = "All Files";
        all.AddPattern("*");
        fileChooser.AddFilter(all);
        if (Settings.Instance.SupertuxData != null)
        {
            try {
                fileChooser.AddShortcutFolder(System.IO.Path.Combine(Settings.Instance.SupertuxData, "levels"));
            } catch (Exception e) {
                LogManager.Log(LogLevel.Warning, "Couldn't add supertux level directory to File Chooser: " + e.Message);
            }
        }

        if (opts.FileNames.Count > 0)
        {
            Load(opts.FileNames[0]);
        }

        UndoManager.OnAddCommand += OnUndoManager;
        UndoManager.OnRedo       += OnUndoManager;
        UndoManager.OnUndo       += OnUndoManager;

        editorApplication = this;

        PrintStatus("Welcome to Supertux-Editor.");
    }
        protected void cmdAdd_Clicked(object sender, EventArgs e)
        {
            FileChooserDialog cdlOpen = new FileChooserDialog("Add Alert Window Styles", this, FileChooserAction.Open, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Ok);

            Gtk.FileFilter fTGZ = new Gtk.FileFilter();
            fTGZ.AddPattern("*.tar");
            fTGZ.AddPattern("*.tgz");
            fTGZ.AddPattern("*.tar.gz");
            fTGZ.Name = "Window Styles";
            cdlOpen.AddFilter(fTGZ);
            cdlOpen.SelectMultiple = true;
            cdlOpen.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            ResponseType ret = (ResponseType)cdlOpen.Run();

            string[]   sRet = cdlOpen.Filenames;
            FileFilter fRet = cdlOpen.Filter;

            cdlOpen.Destroy();
            if (ret == ResponseType.Ok)
            {
                if (fRet == fTGZ)
                {
                    foreach (string StylePath in sRet)
                    {
                        string sTitle = System.IO.Path.GetFileNameWithoutExtension(StylePath);
                        string sExt   = System.IO.Path.GetExtension(StylePath).ToLower();
                        while (!string.IsNullOrEmpty(System.IO.Path.GetExtension(sTitle)))
                        {
                            sExt   = System.IO.Path.GetExtension(sTitle).ToLower() + sExt;
                            sTitle = System.IO.Path.GetFileNameWithoutExtension(sTitle);
                        }
                        if (sExt == ".tgz" | sExt == ".tar.gz" | sExt == ".tar")
                        {
                            File.Copy(StylePath, System.IO.Path.Combine(modFunctions.AppData, sTitle + sExt), true);
                            TreeIter iter;
                            lstStyles.Model.GetIterFirst(out iter);
                            bool Add = true;
                            do
                            {
                                GLib.Value val = new GLib.Value();
                                lstStyles.Model.GetValue(iter, 0, ref val);
                                if ((string)val.Val == sTitle)
                                {
                                    Add = false;
                                    break;
                                }
                            } while (lstStyles.Model.IterNext(ref iter));
                            if (Add)
                            {
                                lstStyles.AddItem(sTitle);
                            }
                            if (sRet.Length == 1)
                            {
                                TreeIter iterSel;
                                lstStyles.Model.GetIterFirst(out iterSel);
                                do
                                {
                                    GLib.Value val = new GLib.Value();
                                    lstStyles.Model.GetValue(iterSel, 0, ref val);
                                    if ((string)val.Val == sTitle)
                                    {
                                        lstStyles.Selection.SelectIter(iterSel);
                                        break;
                                    }
                                } while (lstStyles.Model.IterNext(ref iterSel));
                            }
                        }
                    }
                }
            }
        }
Пример #60
0
        private void OpenContactsFile()
        {
            GlobalObjUI.ContactsFilePath = "";

            // New dialog for select contacts file
            Gtk.FileChooserDialog FileBox = new Gtk.FileChooserDialog(GlobalObjUI.LMan.GetString("openfileact"),
                                                                      MainWindow,
                                                                      FileChooserAction.Open,
                                                                      GlobalObjUI.LMan.GetString("cancellbl"), Gtk.ResponseType.Cancel,
                                                                      GlobalObjUI.LMan.GetString("openlbl"), Gtk.ResponseType.Accept);

            // Filter for using only monosim files
            Gtk.FileFilter myFilter = new Gtk.FileFilter();
            myFilter.AddPattern("*.monosim");
            myFilter.Name = "monosim files";
            FileBox.AddFilter(myFilter);

            // Manage result of dialog box
            FileBox.Icon = Gdk.Pixbuf.LoadFromResource("monosim.png");
            int retFileBox = FileBox.Run();

            if ((ResponseType)retFileBox == Gtk.ResponseType.Accept)
            {
                // path of a right file returned
                GlobalObjUI.ContactsFilePath = FileBox.Filename;

                FileBox.Destroy();
                FileBox.Dispose();
            }
            else
            {
                // nothing returned
                FileBox.Destroy();
                FileBox.Dispose();
                return;
            }


            // Update gui
            UpdateFileControls(false);
            lstFileContacts.Clear();
            MainClass.GtkWait();

            try
            {
                GlobalObjUI.FileContacts = new Contacts();
                StreamReader sr       = new StreamReader(GlobalObjUI.ContactsFilePath);
                string       descRow  = sr.ReadLine();
                string       phoneRow = "";
                while (!sr.EndOfStream)
                {
                    phoneRow = sr.ReadLine();
                    // check for right values
                    if (descRow.Trim() != "" && phoneRow.Trim() != "")
                    {
                        GlobalObjUI.FileContacts.SimContacts.Add(new Contact(descRow, phoneRow));
                    }

                    // read new contact description
                    descRow = sr.ReadLine();
                }
                sr.Close();
                sr.Dispose();
                sr = null;
            }
            catch (Exception Ex)
            {
                log.Error("MainWindowClass::OpenContactsFile: " + Ex.Message + "\r\n" + Ex.StackTrace);
                MainClass.ShowMessage(MainWindow, "ERROR", Ex.Message, MessageType.Error);
                return;
            }

            // loop to append data readed from file
            foreach (Contact cnt in GlobalObjUI.FileContacts.SimContacts)
            {
                lstFileContacts.AppendValues(new string[] { cnt.Description, cnt.PhoneNumber });
            }

            UpdateFileControls(true);
        }