Пример #1
0
        /// <summary>
        /// On click "..." button - select file
        /// </summary>
        protected virtual void OnBtnSelectFileClicked(object sender, System.EventArgs e)
        {
            Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog(
                AddinManager.CurrentLocalizer.GetString("Choose the file to open"), new Dialog(),
                Gtk.FileChooserAction.Open,
                AddinManager.CurrentLocalizer.GetString("Cancel"), ResponseType.Cancel,
                AddinManager.CurrentLocalizer.GetString("Open"), ResponseType.Accept);

            if (!string.IsNullOrEmpty(this.eCommand.Text))
            {
                fc.SetFilename(this.eCommand.Text);
            }

            if (fc.Run() == (int)ResponseType.Accept)
            {
                // check
                UnixFileInfo info = new UnixFileInfo(fc.Filename);
                if ((info.FileAccessPermissions & FileAccessPermissions.UserExecute)
                    != FileAccessPermissions.UserExecute)
                {
                    MessageDialog md = new MessageDialog(new Dialog(),
                                                         DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close,
                                                         AddinManager.CurrentLocalizer.GetString("Selected invalid file!\nShould be executable."));
                    md.Run();
                    md.Destroy();
                }
                else
                {
                    this.eCommand.Text = fc.Filename;
                }
            }

            fc.Destroy();
        }
Пример #2
0
        /// <summary>
        /// On click "..." button - select file
        /// </summary>
        protected virtual void OnBtnSelectFileClicked(object sender, System.EventArgs e)
        {
            Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog (
                    AddinManager.CurrentLocalizer.GetString ("Choose the file to open"), new Dialog(),
                    Gtk.FileChooserAction.Open,
                    AddinManager.CurrentLocalizer.GetString ("Cancel"), ResponseType.Cancel,
                    AddinManager.CurrentLocalizer.GetString ("Open"), ResponseType.Accept);

            if (!string.IsNullOrEmpty (this.eCommand.Text)) {
                fc.SetFilename(this.eCommand.Text);
            }

            if (fc.Run() == (int) ResponseType.Accept) {
                // check
                UnixFileInfo info = new UnixFileInfo (fc.Filename);
                if ((info.FileAccessPermissions & FileAccessPermissions.UserExecute)
                        != FileAccessPermissions.UserExecute) {

                    MessageDialog md = new MessageDialog (new Dialog(),
                            DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close,
                            AddinManager.CurrentLocalizer.GetString ("Selected invalid file!\nShould be executable."));
                    md.Run ();
                    md.Destroy();
                } else {
                    this.eCommand.Text = fc.Filename;
                }
            }

            fc.Destroy();
        }
Пример #3
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");
        }
Пример #4
0
    protected void on_SaveSongFileAs(object sender, EventArgs e)
    {
        Gtk.FileChooserDialog filechooser =
            new Gtk.FileChooserDialog("Save the song file",
                                      this,
                                      FileChooserAction.Save,
                                      "Cancel", ResponseType.Cancel,
                                      "Save As", ResponseType.Accept);

        FileFilter filter = new FileFilter();

        filter.AddPattern("*.pro");

        filechooser.Filter = filter;

        if (!string.IsNullOrEmpty(_currentSong.FilePath))
        {
            filechooser.SetFilename(_currentSong.FilePath);
        }
        else
        {
            string title = _currentSong.Title.Trim();
            title = title.Replace("/", "-");
            title = title.Replace("\\", "-");
            title = title.Replace(".", "");
            filechooser.CurrentName = title;
        }


        string folder = _appSettings.DefaultFolder;

        if (!string.IsNullOrEmpty(folder) &&
            System.IO.Directory.Exists(folder))
        {
            filechooser.SetCurrentFolder(folder);
        }


        if (filechooser.Run() == (int)ResponseType.Accept)
        {
            string fileName = filechooser.Filename;
            fileName = fileName + ".pro";

            _currentSong.FilePath = fileName;
            FileOperations.SaveSongFile(_currentSong);

            CheckStatuses();
        }

        filechooser.Destroy();
    }
		protected void OnTargetHXMLFileButtonClicked (object sender, System.EventArgs e)
		{
			Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog ("Target HXML file", this.Toplevel as Gtk.Window, FileChooserAction.Open,
                    "Cancel", ResponseType.Cancel,
                    "Select", ResponseType.Accept);
			
			Gtk.FileFilter filterHXML = new Gtk.FileFilter ();
			filterHXML.Name = "HXML Files";
			filterHXML.AddPattern ("*.nmml");
			
			Gtk.FileFilter filterAll = new Gtk.FileFilter ();
			filterAll.Name = "All Files";
			filterAll.AddPattern ("*");
			
			fc.AddFilter (filterHXML);
			fc.AddFilter (filterAll);
			
			if (mProject.TargetHXMLFile != "")
			{
				fc.SetFilename (mProject.TargetHXMLFile);
			}
			else
			{
				fc.SetFilename (mProject.BaseDirectory);
			}

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

			fc.Destroy ();
		}
Пример #6
0
 protected void OnButtonFileChooserClicked(object sender, EventArgs e)
 {
     FileChooserDialog fc =
         new FileChooserDialog ("Укажите файл резервной копии",
             this,
             FileChooserAction.Save,
             "Отмена", ResponseType.Cancel,
             "Сохранить", ResponseType.Accept);
     fc.SetFilename (entryFileName.Text);
     fc.Show ();
     if (fc.Run () == (int)ResponseType.Accept) {
         entryFileName.Text = fc.Filename;
     }
     fc.Destroy ();
 }
Пример #7
0
        protected virtual void OnWPlayerPathButtonClicked(object sender, System.EventArgs e)
        {
            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog("Standalone Player Path", this.Toplevel as Gtk.Window, FileChooserAction.Open,
                    "Cancel", ResponseType.Cancel,
                    "Select", ResponseType.Accept);
            if (!String.IsNullOrEmpty(wSdkPathEntry.Text))
                fc.SetFilename(wPlayerPathEntry.Text);

            if (fc.Run() == (int)ResponseType.Accept) {
                wPlayerPathEntry.Text = fc.Filename;
            }

            fc.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 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();
        }
Пример #9
0
    void OnExportAsRRActionActivated(object sender, System.EventArgs e)
    {
        SelectedChoice choice;
        var            responseType = DisplaySelectDataDialog(out choice);

        if (responseType == ResponseType.Cancel)
        {
            return;
        }

        string pathSuggested = ScoobyRom.Data.PathWithNewExtension(data.Rom.Path, ".RR.xml");
        var    fc            = new Gtk.FileChooserDialog("Export as RomRaider definition file", this,
                                                         FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Save, ResponseType.Accept);

        try {
            FileFilter filter = new FileFilter();
            filter.Name = "XML files";
            filter.AddPattern("*.xml");
            // would show other XML files like .svg (on Linux at least): filter.AddMimeType ("text/xml");
            fc.AddFilter(filter);

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

            fc.DoOverwriteConfirmation = true;
            fc.SetFilename(pathSuggested);
            // in addition this is necessary to populate filename when target file does not exist yet:
            fc.CurrentName = System.IO.Path.GetFileName(pathSuggested);

            if (fc.Run() == (int)ResponseType.Accept)
            {
                data.SaveAsRomRaiderXml(fc.Filename, choice);
            }
        } catch (Exception ex) {
            ErrorMsg("Error writing file", ex.Message);
        } finally {
            // Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            if (fc != null)
            {
                fc.Destroy();
            }
        }
    }
Пример #10
0
    void OnExportAsXDFActionActivated(object sender, EventArgs e)
    {
        SelectedChoice choice;
        var            responseType = DisplaySelectDataDialog(out choice);

        if (responseType == ResponseType.Cancel)
        {
            return;
        }

        string pathSuggested = ScoobyRom.Data.PathWithNewExtension(data.Rom.Path, ".xdf");
        var    fc            = new Gtk.FileChooserDialog("Export as TunerPro XDF file", this,
                                                         FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Save, ResponseType.Accept);

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

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

            fc.DoOverwriteConfirmation = true;
            fc.SetFilename(pathSuggested);
            fc.CurrentName = System.IO.Path.GetFileName(pathSuggested);

            if (fc.Run() == (int)ResponseType.Accept)
            {
                data.SaveAsTunerProXdf(fc.Filename, choice);
            }
        } catch (Exception ex) {
            ErrorMsg("Error writing file", ex.Message);
        } finally {
            if (fc != null)
            {
                fc.Destroy();
            }
        }
    }
    private void OnChoose(object o, EventArgs args)
    {
        FileChooserDialog dialog = new FileChooserDialog("Choose resource", null, FileChooserAction.Open, new object[] {});
        dialog.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
        dialog.AddButton(Gtk.Stock.Open, Gtk.ResponseType.Ok);
        dialog.DefaultResponse = Gtk.ResponseType.Ok;

        dialog.Action = FileChooserAction.Open;
        dialog.SetFilename(Settings.Instance.SupertuxData + entry.Text);
        int result = dialog.Run();
        if(result != (int) ResponseType.Ok) {
            dialog.Destroy();
            return;
        }

        if(dialog.Filename.StartsWith(Settings.Instance.SupertuxData))
            entry.Text = dialog.Filename.Substring(Settings.Instance.SupertuxData.Length,
                                                   dialog.Filename.Length - Settings.Instance.SupertuxData.Length);
        else
            entry.Text = System.IO.Path.GetFileName(dialog.Filename);
        // Fixes backslashes on windows:
        entry.Text = entry.Text.Replace("\\", "/");
        dialog.Destroy();
    }
Пример #12
0
        private void HandlePintaCoreActionsFileSaveAsActivated(object sender, EventArgs e)
        {
            var fcd = new FileChooserDialog (Mono.Unix.Catalog.GetString ("Save Image File"),
                                                                   PintaCore.Chrome.MainWindow,
                                                                   FileChooserAction.Save,
                                                                   Gtk.Stock.Cancel,
                                                                   Gtk.ResponseType.Cancel,
                                                                   Gtk.Stock.Save, Gtk.ResponseType.Ok);

            fcd.DoOverwriteConfirmation = true;
            fcd.SetCurrentFolder (lastDialogDir);
            fcd.AlternativeButtonOrder = new int[] { (int) ResponseType.Ok, (int) ResponseType.Cancel };
            bool hasFile = PintaCore.Workspace.ActiveDocument.HasFile;
            string currentExt = null;

            if (hasFile) {
                fcd.SetFilename (PintaCore.Workspace.ActiveDocument.Pathname);
                currentExt = Path.GetExtension(PintaCore.Workspace.Filename.ToLowerInvariant ());
            }

            Dictionary<FileFilter, FormatDescriptor> filetypes = new Dictionary<FileFilter, FormatDescriptor> ();

            // Add all the formats we support to the save dialog
            foreach (var format in formats) {
                if (!format.IsReadOnly ()) {
                    fcd.AddFilter (format.Filter);
                    filetypes.Add (format.Filter, format);

                    if ((hasFile && formatsByExt[currentExt] == format) || (!hasFile && format.Name == "jpeg")) {
                        fcd.Filter = format.Filter;
                    }
                }
            }

            // Replace GTK's ConfirmOverwrite with our own, for UI consistency
            fcd.ConfirmOverwrite += (eventSender, eventArgs) => {
                if (this.ConfirmOverwrite (fcd, fcd.Filename)) {
                    eventArgs.RetVal = FileChooserConfirmation.AcceptFilename;
                } else {
                    eventArgs.RetVal = FileChooserConfirmation.SelectAgain;
                }
            };

            while (fcd.Run () == (int) Gtk.ResponseType.Ok) {
                FormatDescriptor format = filetypes[fcd.Filter];
                string file = fcd.Filename;

                if (string.IsNullOrEmpty (System.IO.Path.GetExtension (file))) {
                    // No extension; add one from the format descriptor.
                    file = string.Format ("{0}.{1}", file, format.Extensions[0]);
                    fcd.CurrentName = System.IO.Path.GetFileName (file);

                    // We also need to display an overwrite confirmation message manually,
                    // because MessageDialog won't do this for us in this case.
                    if (File.Exists (file) && !ConfirmOverwrite (fcd, file)) {
                        continue;
                    }
                }

                lastDialogDir = fcd.CurrentFolder;
                SaveFile (file, format);
                AddRecentFileUri (fcd.Uri);

                PintaCore.Workspace.ActiveDocument.HasFile = true;
                PintaCore.Workspace.ActiveDocument.Pathname = file;
                break;
            }

            fcd.Destroy ();
        }
Пример #13
0
		protected virtual FileChooserDialog CreateFileChooserDialog()
		{
			// TODO: set parent
			var dlg = new FileChooserDialog(Title, null, Action);
			dlg.Response += HandleDlgResponse;

			if (ShowHelp)
				dlg.AddButton(FileDialogStrings.Help, ResponseType.Help);
			dlg.AddButton(FileDialogStrings.Cancel, ResponseType.Cancel);
			dlg.AddButton(AcceptButtonText, ResponseType.Accept);

			dlg.LocalOnly = true;
			dlg.SelectMultiple = Multiselect;
			if (!string.IsNullOrEmpty(InitialDirectory))
				dlg.SetCurrentFolder(InitialDirectory);
			if (!string.IsNullOrEmpty(FileName))
				dlg.SetFilename(FileName);

			ApplyFilter(dlg);

			return dlg;
		}
Пример #14
0
        // END HERZUM SPRINT 3: TLAB-86

        private bool chooseTpkgPath(out string path){
            bool result = false;
            var fileChooserDialog = new FileChooserDialog (Mono.Unix.Catalog.GetString ("Choose package name"),
                                                           null,
                                                           FileChooserAction.Save,
                                                           Gtk.Stock.Cancel,
                                                           Gtk.ResponseType.Cancel,
                                                           Gtk.Stock.Save, Gtk.ResponseType.Ok);

            fileChooserDialog.DoOverwriteConfirmation = true;
            fileChooserDialog.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel };
            fileChooserDialog.SelectMultiple = false;

            AddFilters(fileChooserDialog);
            String currentPath = changePathToTpkg(m_applicationViewModel.Experiment.ExperimentInfo.FilePath);
            fileChooserDialog.SetFilename(currentPath);
            fileChooserDialog.SetCurrentFolder (currentPath);

            int response = fileChooserDialog.Run();

            string filename = null;

            if(response == (int)Gtk.ResponseType.Ok) 
            {
                filename = fileChooserDialog.Filename;
            }

            fileChooserDialog.Destroy();
            result = true;
            path = addTpkgExtIfNeeded(filename);

            return result;
        }
Пример #15
0
        static void saveButton_Clicked(object sender, EventArgs e)
        {
            FileChooserDialog fcd = new FileChooserDialog ("Save page as...", (Window)((Widget)sender).Toplevel, FileChooserAction.Save);
            fcd.AddButton (Stock.Cancel, ResponseType.Cancel);
            fcd.AddButton (Stock.Save, ResponseType.Ok);
            fcd.DefaultResponse = ResponseType.Ok;
            fcd.Filter = new FileFilter();
            fcd.Filter.AddPattern ("*.aspx");
            fcd.SelectMultiple = false;
            fcd.SetFilename (((System.Web.UI.Control)host.RootComponent).ID + ".aspx");

            ResponseType response = (ResponseType) fcd.Run();
            fcd.Hide();

            if (response == ResponseType.Ok && fcd.Filename != null)
                using (FileStream fileStream = new FileStream (fcd.Filename, FileMode.Create))
                {
                    if (fileStream == null)
                        return;
                    host.SaveDocument (fileStream);
                }
            fcd.Destroy ();
        }
Пример #16
0
        internal static string ShowSaveAsDialog(Window parentWindow, string currentFilename = null) 
        {
            var fileChooserDialog = new FileChooserDialog (Mono.Unix.Catalog.GetString ("Save Experiment File"),
                                             parentWindow,
                                             FileChooserAction.Save,
                                             Gtk.Stock.Cancel,
                                             Gtk.ResponseType.Cancel,
                                             Gtk.Stock.Save, Gtk.ResponseType.Ok);
            
            fileChooserDialog.DoOverwriteConfirmation = true;
            fileChooserDialog.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel };
            fileChooserDialog.SelectMultiple = false;

            if (String.IsNullOrEmpty(currentFilename) == false)
            {
                fileChooserDialog.SetFilename(currentFilename);
            }

            AddFilters(fileChooserDialog);

            int response = fileChooserDialog.Run();
            
            string filename = null;
            if(response == (int)Gtk.ResponseType.Ok) 
            {
                filename = fileChooserDialog.Filename;
            }
            
            fileChooserDialog.Destroy();
            
            return filename;
        }
        protected virtual void OnWMainSourceButtonClicked(object sender, System.EventArgs e)
        {
            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog("Main source file", this.Toplevel as Gtk.Window, FileChooserAction.Open,
                    "Cancel", ResponseType.Cancel,
                    "Select", ResponseType.Accept);
            fc.SetFilename(mProject.MainSource);

            if (fc.Run() == (int)ResponseType.Accept) {
                wMainSourceEntry.Text = fc.Filename;

                string ext = System.IO.Path.GetExtension(fc.Filename.ToLower());
                switch (ext)
                {
                    case ".mxml": wLanguageCombo.Active = 0; break;
                    case ".as": wLanguageCombo.Active = 1; break;
                }
            }

            fc.Destroy();
        }
Пример #18
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;
            }
        }
Пример #19
0
        internal static string ShowSaveAsDialog(Window parentWindow, string currentFilename = null) 
        {
            var fileChooserDialog = new FileChooserDialog (Mono.Unix.Catalog.GetString ("Save Experiment File"),
                                             parentWindow,
                                             FileChooserAction.Save,
                                             Gtk.Stock.Cancel,
                                             Gtk.ResponseType.Cancel,
                                             Gtk.Stock.Save, Gtk.ResponseType.Ok);
            
            fileChooserDialog.DoOverwriteConfirmation = true;
            fileChooserDialog.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel };
            fileChooserDialog.SelectMultiple = false;

            if (String.IsNullOrEmpty(currentFilename) == false)
            {
                fileChooserDialog.SetFilename(currentFilename);
            }

            string defaultExtension = AddFilters(fileChooserDialog);

            while (fileChooserDialog.Run() == (int)Gtk.ResponseType.Ok) 
            {
                string filename = fileChooserDialog.Filename;
                if (string.IsNullOrEmpty(Path.GetExtension(filename))) 
                {
                    // No extension; add one from the format descriptor.
                    filename = string.Format ("{0}.{1}", filename, defaultExtension);
                    fileChooserDialog.CurrentName = Path.GetFileName (filename);

                    // We also need to display an overwrite confirmation message manually,
                    // because MessageDialog won't do this for us in this case.
                    if (File.Exists (filename) && !ConfirmOverwrite (fileChooserDialog, filename))
                    {
                        continue;
                    }
                }

                fileChooserDialog.Destroy();
                return filename;
            }

            //if file was not selected return null
            fileChooserDialog.Destroy();
            return null;
        }
Пример #20
0
        /// <summary>Handles the Click event of the button1 control.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void OnButton1Click(object sender, EventArgs e)
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Choose a weather file to open", null, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);

            FileFilter fileFilter = new FileFilter();
            fileFilter.Name = "APSIM Weather file (*.met)";
            fileFilter.AddPattern("*.met");
            fileChooser.AddFilter(fileFilter);

            FileFilter excelFilter = new FileFilter();
            excelFilter.Name = "Excel file (*.xlsx)";
            excelFilter.AddPattern("*.xlsx");
            fileChooser.AddFilter(excelFilter);

            FileFilter allFilter = new FileFilter();
            allFilter.Name = "All files";
            allFilter.AddPattern("*");
            fileChooser.AddFilter(allFilter);

            fileChooser.SetFilename(labelFileName.Text);

            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                Filename = fileChooser.Filename;
                fileChooser.Destroy();
                if (BrowseClicked != null)
                {
                    BrowseClicked.Invoke(Filename);    //reload the grid with data
                    notebook1.CurrentPage = 0;
                }

             }
             else
                fileChooser.Destroy();
        }
Пример #21
0
    private void FireUpFileChooserForDownloading()
    {
        if (uploadbutton.Active) return;
          FileChooserDialog chooser = new FileChooserDialog(
          "Select a folder", null, FileChooserAction.SelectFolder,
          Stock.Open, ResponseType.Ok, Stock.Cancel, ResponseType.Cancel);

          chooser.SetIconFromFile(DeskFlickrUI.ICON_PATH);
          chooser.SetFilename(PersistentInformation.GetInstance().DownloadFoldername);
          ResponseType choice = (ResponseType) chooser.Run();
          string foldername = "";
          if (choice == ResponseType.Ok) {
           foldername = chooser.Filename;
           // Set the default path to be opened next time file chooser runs.
           PersistentInformation.GetInstance().DownloadFoldername = foldername;
          }
          chooser.Destroy();
          if (foldername.Equals("")) return;

          // Selected folder for downloading.
          ArrayList photoids = new ArrayList();
          ArrayList selectedphotos = new ArrayList();
          bool refreshview = false;
          if (treeview2.Selection.GetSelectedRows().Length > 0) {
            foreach (TreePath path in treeview2.Selection.GetSelectedRows()) {
              Photo p = new Photo(GetPhoto(path));
              TreePath childpath = filter.ConvertPathToChildPath(path);
              SelectedPhoto sel = new SelectedPhoto(p, childpath.ToString());
              selectedphotos.Add(sel);
              photoids.Add(p.Id);
            }
          }
        else if (treeview1.Selection.GetSelectedRows().Length > 0) {
          // Going through the complex way of figuring out photos for the
          // different tab modes. Easier way would be to just copy contents
          // of _photos, as it already takes care of left tree selection. However,
          // when the view is locked to 'downloads', _photos wouldn't be updated.
          // Hence the need to figure out photoids.
            TreePath path = treeview1.Selection.GetSelectedRows()[0];
            if (selectedtab == 0) { // albums
              Album album = new Album((Album) _albums[path.Indices[0]]);
              photoids = PersistentInformation.GetInstance().GetPhotoIdsForAlbum(album.SetId);
              //foldername = String.Format("{0}/{1}", foldername, album.Title);
          		  } else if (selectedtab == 1) { // tags
          		    string tag = (string) _tags[path.Indices[0]];
          		    photoids = PersistentInformation.GetInstance().GetPhotoIdsForTag(tag);
          		    //foldername = String.Format("{0}/{1}", foldername, tag);
          		  } else if (selectedtab == 2) {
          		    PersistentInformation.Entry poolentry =
          		        (PersistentInformation.Entry) _pools[path.Indices[0]];
          		    string poolid = poolentry.entry1;
          		    //string pooltitle = poolentry.entry2;
          		    photoids = PersistentInformation.GetInstance().GetPhotoidsForPool(poolid);
          		    //foldername = String.Format("{0}/{1}", foldername, pooltitle);
          		  } else if (selectedtab == 3) {
          		    PersistentInformation.Entry blog =
          		        (PersistentInformation.Entry) _blogs[path.Indices[0]];
          		    foreach (BlogEntry blogentry in
          		        PersistentInformation.GetInstance().GetEntriesForBlog(blog.entry1)) {
          		      photoids.Add(blogentry.Photoid);
          		    }
          		    //foldername = String.Format("{0}/{1}", foldername, blog.entry2);
          		  }
          		  refreshview = true;
          }
          Utils.EnsureDirectoryExists(foldername);
          foreach (string id in photoids) {
            if (PersistentInformation.GetInstance().IsDownloadEntryExists(id)) {
              PersistentInformation.GetInstance().DeleteEntryFromDownload(id);
            }
            PersistentInformation.GetInstance().InsertEntryToDownload(id, foldername);
          }
          UpdateToolBarButtons();
          if (downloadbutton.Active) RefreshDownloadPhotos();
          else if (refreshview) RefreshLeftTreeView();
          else UpdatePhotos(selectedphotos);
    }
Пример #22
0
        // This is actually both for "Save As" and saving a file that never
        // been saved before.  Either way, we need to prompt for a filename.
        private bool SaveFileAs(Document document)
        {
            var fcd = new FileChooserDialog (Mono.Unix.Catalog.GetString ("Save Image File"),
                                           PintaCore.Chrome.MainWindow,
                                           FileChooserAction.Save,
                                           Gtk.Stock.Cancel,
                                           Gtk.ResponseType.Cancel,
                                           Gtk.Stock.Save, Gtk.ResponseType.Ok);

            fcd.DoOverwriteConfirmation = true;
            fcd.SetCurrentFolder (lastDialogDir);
            fcd.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel };

            bool hasFile = document.HasFile;

            if (hasFile)
                fcd.SetFilename (document.PathAndFileName);

            Dictionary<FileFilter, FormatDescriptor> filetypes = new Dictionary<FileFilter, FormatDescriptor> ();

            // Add all the formats we support to the save dialog
            foreach (var format in PintaCore.System.ImageFormats.Formats) {
                if (!format.IsReadOnly ()) {
                    fcd.AddFilter (format.Filter);
                    filetypes.Add (format.Filter, format);
                }
            }

            // If we already have a format, set it to the default.
            // If not, default to jpeg
            if (hasFile)
                fcd.Filter = PintaCore.System.ImageFormats.GetFormatByFile (document.Filename).Filter;
            else
                fcd.Filter = PintaCore.System.ImageFormats.GetDefaultFormat ().Filter;

            // Replace GTK's ConfirmOverwrite with our own, for UI consistency
            fcd.ConfirmOverwrite += (eventSender, eventArgs) => {
                if (this.ConfirmOverwrite (fcd, fcd.Filename))
                    eventArgs.RetVal = FileChooserConfirmation.AcceptFilename;
                else
                    eventArgs.RetVal = FileChooserConfirmation.SelectAgain;
            };

            while (fcd.Run () == (int)Gtk.ResponseType.Ok) {
                FormatDescriptor format = filetypes[fcd.Filter];
                string file = fcd.Filename;

                if (string.IsNullOrEmpty (Path.GetExtension (file))) {
                    // No extension; add one from the format descriptor.
                    file = string.Format ("{0}.{1}", file, format.Extensions[0]);
                    fcd.CurrentName = Path.GetFileName (file);

                    // We also need to display an overwrite confirmation message manually,
                    // because MessageDialog won't do this for us in this case.
                    if (File.Exists (file) && !ConfirmOverwrite (fcd, file))
                        continue;
                }

                // Always follow the extension rather than the file type drop down
                // ie: if the user chooses to save a "jpeg" as "foo.png", we are going
                // to assume they just didn't update the dropdown and really want png
                var format_type = PintaCore.System.ImageFormats.GetFormatByFile (file);

                if (format_type != null)
                    format = format_type;

                lastDialogDir = fcd.CurrentFolder;
                SaveFile (document, file, format);
                RecentManager.Default.AddFull (fcd.Uri, recentData);
                PintaCore.System.ImageFormats.SetDefaultFormat (Path.GetExtension (file));

                document.HasFile = true;
                document.PathAndFileName = file;

                fcd.Destroy ();
                return true;
            }

            fcd.Destroy ();
            return false;
        }
Пример #23
0
        string FileChooser(string title, string defaultName,
			string defaultFolder, string filterName, string extensionFilter,
			FileChooserAction action)
        {
            FileChooserDialog fChooser;
            FileFilter filter;
            string button, path;

            if (action == FileChooserAction.Save)
                button = "gtk-save";
            else
                button = "gtk-open";

            fChooser = new FileChooserDialog(title, mainWindow as Gtk.Window, action,
                "gtk-cancel",ResponseType.Cancel, button, ResponseType.Accept);

            if (defaultFolder != null)
                fChooser.SetCurrentFolder(defaultFolder);
            if (defaultName != null)
                fChooser.SetFilename(defaultName);
            if (filterName != null) {
                filter = new FileFilter();
                filter.Name = filterName;
                filter.AddPattern(extensionFilter);
                fChooser.AddFilter(filter);
            }

            if (fChooser.Run() != (int)ResponseType.Accept)
                path = null;
            else
                path = fChooser.Filename;

            fChooser.Destroy();
            return path;
        }
Пример #24
0
    void OnExportAsRRActionActivated(object sender, System.EventArgs e)
    {
        SelectedChoice choice;
        var responseType = DisplaySelectDataDialog (out choice);
        if (responseType == ResponseType.Cancel)
            return;

        string pathSuggested = ScoobyRom.Data.PathWithNewExtension (data.Rom.Path, ".RR.xml");
        var fc = new Gtk.FileChooserDialog ("Export as RomRaider definition file", this,
                     FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Save, ResponseType.Accept);
        try {
            FileFilter filter = new FileFilter ();
            filter.Name = "XML files";
            filter.AddPattern ("*.xml");
            // would show other XML files like .svg (on Linux at least): filter.AddMimeType ("text/xml");
            fc.AddFilter (filter);

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

            fc.DoOverwriteConfirmation = true;
            fc.SetFilename (pathSuggested);
            // in addition this is necessary to populate filename when target file does not exist yet:
            fc.CurrentName = System.IO.Path.GetFileName (pathSuggested);

            if (fc.Run () == (int)ResponseType.Accept) {
                data.SaveAsRomRaiderXml (fc.Filename, choice);
            }
        } catch (Exception ex) {
            ErrorMsg ("Error writing file", ex.Message);
        } finally {
            // Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            if (fc != null)
                fc.Destroy ();
        }
    }
Пример #25
0
    public string ChoosePath()
    {
        string path = null;

        FileChooserDialog file_chooser =
            new FileChooserDialog (Catalog.GetString ("Import"), this.Dialog,
                    FileChooserAction.SelectFolder,
                    Stock.Cancel, ResponseType.Cancel,
                    Stock.Open, ResponseType.Ok);

        file_chooser.SelectMultiple = false;

        if (ImportPath != null)
            file_chooser.SetFilename (ImportPath);
        else
            file_chooser.SetFilename (FSpot.Global.HomeDirectory);

        int response = file_chooser.Run ();

        if ((ResponseType) response == ResponseType.Ok) {
            path = file_chooser.Filename;
        }

        file_chooser.Destroy ();
        return path;
    }
Пример #26
0
    /*
     * public void LoadCEStage(string filename, bool findRawForCEStage)
     * {
     *      try
     *      {
     *              mStage.LoadStage(filename);
     *
     *              string raw_filename; int prescale = 2;
     *              if (mStage.Prescale != 0) prescale = mStage.Prescale;
     *
     *              if (findRawForCEStage && MainClass.FindRawsForCestageAndAskToOpen(filename, out raw_filename, ref prescale))
     *              {
     *                      mStage.AskLoadImage(raw_filename, prescale);
     *              }
     *      }
     *      catch (StageDeserializationException sdex)
     *      {
     *              Gtk.MessageDialog md = new Gtk.MessageDialog(
     *                      this, DialogFlags.Modal,
     *                      MessageType.Error, ButtonsType.Ok,
     *                      false, "Can't load stage from the file \"{0}\".\n{1}", filename, sdex.Message);
     *
     *              md.Title = MainClass.APP_NAME;
     *
     *              md.Run();
     *              md.Destroy();
     *      }
     * }
     */
    public bool ShowLoadImageDialog()
    {
        if (mStage.TheUIState == UIState.Loading)
        {
            Gtk.MessageDialog md = new Gtk.MessageDialog(this, DialogFlags.Modal,
                                                         MessageType.Error, ButtonsType.Ok,
                                                         "Loading is in progress");
            md.Title = MainClass.APP_NAME;
            md.Run();
            md.Destroy();
        }
        else
        {
            Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Open RAW image",
                                                                  this,
                                                                  FileChooserAction.Open,
                                                                  "Cancel", ResponseType.Cancel,
                                                                  "Open", ResponseType.Accept);

            // Filter for RAWs
            FileFilter ff = new FileFilter();

            ff.AddCustom(FileFilterFlags.Filename, delegate(Gtk.FileFilterInfo ffi) {
                return(RawLoader.IsRaw(ffi.Filename));
            });
            ff.Name = "RAW image";

            fcd.AddFilter(ff);

            // Setting current folder to stage file folder or to RAW file folder
            if (mStage.StageFileName != null && mStage.StageFileName != "" &&
                !fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.StageFileName)))
            {
                fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.RawFileName));
            }



            // Adding preview widget

            ReceiptSelectorWidget rsw = new ReceiptSelectorWidget();
            RawPreviewWidget      rpw = new RawPreviewWidget();

            // Adding options widget

            PreScaleSelectorWidget pssw = new PreScaleSelectorWidget();
            pssw.Value = 2;
            if (mStage.Prescale != 0)
            {
                pssw.Value = mStage.Prescale;
            }

            VBox preview_box = new VBox(false, 4);
            preview_box.PackStart(rpw, true, true, 0);
            preview_box.ShowAll();
            fcd.PreviewWidget = preview_box;

            HBox options_box = new HBox(false, 20);
            options_box.PackStart(rsw, true, true, 0);
            options_box.PackEnd(pssw, false, true, 0);
            fcd.ExtraWidget = options_box;
            options_box.ShowAll();

            // Adding events

            fcd.UpdatePreview += delegate {
                rpw.Filename = fcd.Filename;
            };
            fcd.SelectionChanged += delegate {
                rpw.Filename    = fcd.Filename;
                rsw.RawFileName = fcd.Filename;
            };
            rpw.FileIsGoodChanged += delegate {
                options_box.Sensitive   = rpw.FileIsGood;
                fcd.PreviewWidgetActive = rpw.FileIsGood;
            };


            if (mStage.RawFileName != null)
            {
                fcd.SetFilename(mStage.RawFileName);
                rpw.Filename            = mStage.RawFileName;
                rsw.RawFileName         = mStage.RawFileName;
                fcd.PreviewWidgetActive = rpw.FileIsGood;
                options_box.Sensitive   = rpw.FileIsGood;
            }

            string filename = ""; int prescale = 2;
            bool   ok = false;

            if (fcd.Run() == (int)Gtk.ResponseType.Accept)
            {
                ok       = true;
                filename = fcd.Filename;
                prescale = pssw.Value;
            }

            fcd.Destroy();

            if (ok)
            {
                if (mStage.RawFileName != filename)
                {
                    mStage.AskLoadImage(filename, prescale);
                }
                mStage.LoadStage(rsw.SelectedReceiptFileName);
                return(true);
            }
        }
        return(false);
    }
Пример #27
0
		/// <summary>
		/// Opens a file dialog with the given settings.
		/// </summary>
		public bool FileDialog(FileDialogDef def)
		{
			// decide which action to use
			gtk.FileChooserAction action = gtk.FileChooserAction.Save;
			string accept = "";
			if (def.Type == FileDialogType.Open)
			{
				action = gtk.FileChooserAction.Open;
				accept = "Open";
			}
			else if (def.Type == FileDialogType.SaveAs)
			{
				action = gtk.FileChooserAction.Save;
				accept = "Save";
			}
			
			var dialog = new gtk.FileChooserDialog(def.Title, 
							this.Toplevel as gtk.Window, action,
							"Cancel", gtk.ResponseType.Cancel,
                            accept, gtk.ResponseType.Accept);
			if (def.FileName != null)
				dialog.SetFilename(def.FileName);
			
			// assemble the filters
			foreach (var ext in def.Extensions)
			{
				var filter = new gtk.FileFilter();
				var pattern = "*." + ext;
				filter.AddPattern(pattern);
				filter.Name = def.GetDescription(ext) + " (" + pattern + ")";
				dialog.AddFilter(filter);
			}
			
			var ret = dialog.Run() == (int)gtk.ResponseType.Accept;
			def.FileName = dialog.Filename;
			dialog.Destroy();
			return ret;
		}
Пример #28
0
    /*
    public void LoadCEStage(string filename, bool findRawForCEStage)
    {
        try
        {
            mStage.LoadStage(filename);

            string raw_filename; int prescale = 2;
            if (mStage.Prescale != 0) prescale = mStage.Prescale;

            if (findRawForCEStage && MainClass.FindRawsForCestageAndAskToOpen(filename, out raw_filename, ref prescale))
            {
                mStage.AskLoadImage(raw_filename, prescale);
            }
        }
        catch (StageDeserializationException sdex)
        {
            Gtk.MessageDialog md = new Gtk.MessageDialog(
                this, DialogFlags.Modal,
                MessageType.Error, ButtonsType.Ok,
                false, "Can't load stage from the file \"{0}\".\n{1}", filename, sdex.Message);

            md.Title = MainClass.APP_NAME;

            md.Run();
            md.Destroy();
        }
    }
    */
    public bool ShowLoadImageDialog()
    {
        if (mStage.TheUIState == UIState.Loading)
        {
            Gtk.MessageDialog md = new Gtk.MessageDialog(this, DialogFlags.Modal,
                                                         MessageType.Error, ButtonsType.Ok,
                                                         "Loading is in progress");
            md.Title = MainClass.APP_NAME;
            md.Run();
            md.Destroy();
        }
        else
        {
            Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Open RAW image",
                                                                  this,
                                                                  FileChooserAction.Open,
                                                                  "Cancel", ResponseType.Cancel,
                                                                  "Open", ResponseType.Accept);

            // Filter for RAWs
            FileFilter ff = new FileFilter();

            ff.AddCustom(FileFilterFlags.Filename, delegate (Gtk.FileFilterInfo ffi) {
                return RawLoader.IsRaw(ffi.Filename);
            });
            ff.Name = "RAW image";

            fcd.AddFilter(ff);

            // Setting current folder to stage file folder or to RAW file folder
            if (mStage.StageFileName != null && mStage.StageFileName != ""
                    && !fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.StageFileName)))
                fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.RawFileName));

            // Adding preview widget

            ReceiptSelectorWidget rsw = new ReceiptSelectorWidget();
            RawPreviewWidget rpw = new RawPreviewWidget();

            // Adding options widget

            PreScaleSelectorWidget pssw = new PreScaleSelectorWidget();
            pssw.Value = 2;
            if (mStage.Prescale != 0) pssw.Value = mStage.Prescale;

            VBox preview_box = new VBox(false, 4);
            preview_box.PackStart(rpw, true, true, 0);
            preview_box.ShowAll();
            fcd.PreviewWidget = preview_box;

            HBox options_box = new HBox(false, 20);
            options_box.PackStart(rsw, true, true, 0);
            options_box.PackEnd(pssw, false, true, 0);
            fcd.ExtraWidget = options_box;
            options_box.ShowAll();

            // Adding events

            fcd.UpdatePreview += delegate {
                rpw.Filename = fcd.Filename;
            };
            fcd.SelectionChanged += delegate {
                rpw.Filename = fcd.Filename;
                rsw.RawFileName = fcd.Filename;
            };
            rpw.FileIsGoodChanged += delegate {
                options_box.Sensitive = rpw.FileIsGood;
                fcd.PreviewWidgetActive = rpw.FileIsGood;
            };

            if (mStage.RawFileName != null)
            {
                fcd.SetFilename(mStage.RawFileName);
                rpw.Filename = mStage.RawFileName;
                rsw.RawFileName = mStage.RawFileName;
                fcd.PreviewWidgetActive = rpw.FileIsGood;
                options_box.Sensitive = rpw.FileIsGood;
            }

            string filename = ""; int prescale = 2;
            bool ok = false;

            if (fcd.Run() == (int)Gtk.ResponseType.Accept)
            {
                ok = true;
                filename = fcd.Filename;
                prescale = pssw.Value;
            }

            fcd.Destroy();

            if (ok)
            {
                if (mStage.RawFileName != filename)
                {
                    mStage.AskLoadImage(filename, prescale);
                }
                mStage.LoadStage(rsw.SelectedReceiptFileName);
                return true;
            }
        }
        return false;
    }
Пример #29
0
    protected void OnSaveActionActivated(object sender, EventArgs e)
    {
        if (gameInfoList == null)
        {
            Gtk.MessageDialog dialog = new Gtk.MessageDialog(this,
                                           Gtk.DialogFlags.DestroyWithParent,
                                           Gtk.MessageType.Error,
                                           Gtk.ButtonsType.Ok,
                                           "No info entry to save !!");

            dialog.Run();
            dialog.Destroy();
            return;
        }

        FileChooserDialog openD = new FileChooserDialog("Save text file",
                                      this, FileChooserAction.Save,
                                      Stock.Cancel, ResponseType.Cancel,
                                      Stock.Save, ResponseType.Accept);
        FileFilter filter = new FileFilter();
        filter.Name = "Text file (*.txt)";
        filter.AddMimeType("Text");
        filter.AddPattern("*.txt");
        openD.AddFilter(filter);
        openD.SetFilename(filechooserwidget2.Filename.Replace(".nes", ".txt"));
        if (openD.Run() == (int)ResponseType.Accept)
        {
            File.WriteAllLines(openD.Filename, gameInfoLines.ToArray(), System.Text.Encoding.UTF8);
            try
            {
                Process.Start(openD.Filename);
            }
            catch
            {
            }
        }
        openD.Destroy();
    }
Пример #30
0
        protected virtual void OnButtonBrowseClicked(object sender, System.EventArgs e)
        {
            FileChooserDialog dlg = new FileChooserDialog ("Select Folder", this, FileChooserAction.SelectFolder);
            try {
                dlg.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
                dlg.AddButton (Gtk.Stock.Open, Gtk.ResponseType.Ok);

                dlg.SetFilename (Environment.GetFolderPath (Environment.SpecialFolder.Personal));
                if (dlg.Run () == (int) ResponseType.Ok) {
                    pathEntry.Text = dlg.Filename;
                }
            } finally {
                dlg.Destroy ();
            }
        }
Пример #31
0
 // Save
 protected void OnButton17Pressed(object sender, EventArgs e)
 {
     FileChooserDialog sav = new FileChooserDialog("Save My Nes palette present file",
                                 this, FileChooserAction.Save,
                                 Stock.Cancel, ResponseType.Cancel,
                                 Stock.Save, ResponseType.Accept);
     FileFilter filter = new FileFilter();
     filter.Name = "My Nes Palette Present (*.mnpp)";
     filter.AddMimeType("mnpp");
     filter.AddPattern("*.mnpp");
     sav.AddFilter(filter);
     sav.SetFilename("present.mnpp");
     if (sav.Run() == (int)ResponseType.Accept)
     {
         List<string> lines = new List<string>();
         lines.Add("Brightness=" + NTSCPaletteGenerator.brightness);
         lines.Add("Contrast=" + NTSCPaletteGenerator.contrast);
         lines.Add("Gamma=" + NTSCPaletteGenerator.gamma);
         lines.Add("Hue=" + NTSCPaletteGenerator.hue_tweak);
         lines.Add("Saturation=" + NTSCPaletteGenerator.saturation);
         File.WriteAllLines(sav.Filename, lines.ToArray());
     }
     sav.Destroy();
 }
		// This is actually both for "Save As" and saving a file that never
		// been saved before.  Either way, we need to prompt for a filename.
		private bool SaveFileAs (Document document)
		{
			var fcd = new FileChooserDialog (Mono.Unix.Catalog.GetString ("Save Image File"),
									       PintaCore.Chrome.MainWindow,
									       FileChooserAction.Save,
									       Gtk.Stock.Cancel,
									       Gtk.ResponseType.Cancel,
									       Gtk.Stock.Save, Gtk.ResponseType.Ok);

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

			bool hasFile = document.HasFile;

			if (hasFile)
				fcd.SetFilename (document.PathAndFileName);

			Dictionary<FileFilter, FormatDescriptor> filetypes = new Dictionary<FileFilter, FormatDescriptor> ();

			// Add all the formats we support to the save dialog
			foreach (var format in PintaCore.System.ImageFormats.Formats) {
				if (!format.IsReadOnly ()) {
					fcd.AddFilter (format.Filter);
					filetypes.Add (format.Filter, format);

					// Set the filter to anything we found
					// We want to ensure that *something* is selected in the filetype
					fcd.Filter = format.Filter;
				}
			}

			// If we already have a format, set it to the default.
			// If not, default to jpeg
			FormatDescriptor format_desc = null;

			if (hasFile)
				format_desc = PintaCore.System.ImageFormats.GetFormatByFile (document.Filename);

			if (format_desc == null) {
				format_desc = PintaCore.System.ImageFormats.GetDefaultSaveFormat ();

				// Gtk doesn't like it if we set the file name to an extension that we don't have
				// a filter for, so we change the extension to our default extension.
				if (hasFile)
					fcd.SetFilename (Path.ChangeExtension (document.PathAndFileName, format_desc.Extensions[0]));
			}

			fcd.Filter = format_desc.Filter;

            fcd.AddNotification("filter", this.OnFilterChanged);

			// Replace GTK's ConfirmOverwrite with our own, for UI consistency
			fcd.ConfirmOverwrite += (eventSender, eventArgs) => {
				if (this.ConfirmOverwrite (fcd, fcd.Filename))
					eventArgs.RetVal = FileChooserConfirmation.AcceptFilename;
				else
					eventArgs.RetVal = FileChooserConfirmation.SelectAgain;
			};

			while (fcd.Run () == (int)Gtk.ResponseType.Ok) {
				FormatDescriptor format = filetypes[fcd.Filter];
				string file = fcd.Filename;

				if (string.IsNullOrEmpty (Path.GetExtension (file))) {
					// No extension; add one from the format descriptor.
					file = string.Format ("{0}.{1}", file, format.Extensions[0]);
					fcd.CurrentName = Path.GetFileName (file);

					// We also need to display an overwrite confirmation message manually,
					// because MessageDialog won't do this for us in this case.
					if (File.Exists (file) && !ConfirmOverwrite (fcd, file))
						continue;
				}

				// Always follow the extension rather than the file type drop down
				// ie: if the user chooses to save a "jpeg" as "foo.png", we are going
				// to assume they just didn't update the dropdown and really want png
				var format_type = PintaCore.System.ImageFormats.GetFormatByFile (file);

				if (format_type != null)
					format = format_type;

				PintaCore.System.LastDialogDirectory = fcd.CurrentFolder;

				// If saving the file failed or was cancelled, let the user select
				// a different file type.
				if (!SaveFile (document, file, format, fcd))
					continue;

				//The user is saving the Document to a new file, so technically it
				//hasn't been saved to its associated file in this session.
				document.HasBeenSavedInSession = false;

				RecentManager.Default.AddFull (fcd.Uri, PintaCore.System.RecentData);
				PintaCore.System.ImageFormats.SetDefaultFormat (Path.GetExtension (file));

				document.HasFile = true;
				document.PathAndFileName = file;

				fcd.Destroy ();
				return true;
			}

			fcd.Destroy ();
			return false;
		}
Пример #33
0
    void OnExportAsXDFActionActivated(object sender, EventArgs e)
    {
        SelectedChoice choice;
        var responseType = DisplaySelectDataDialog (out choice);
        if (responseType == ResponseType.Cancel)
            return;

        string pathSuggested = ScoobyRom.Data.PathWithNewExtension (data.Rom.Path, ".xdf");
        var fc = new Gtk.FileChooserDialog ("Export as TunerPro XDF file", this,
                     FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Save, ResponseType.Accept);
        try {
            FileFilter filter = new FileFilter ();
            filter.Name = "XDF files";
            filter.AddPattern ("*.xdf");
            fc.AddFilter (filter);

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

            fc.DoOverwriteConfirmation = true;
            fc.SetFilename (pathSuggested);
            fc.CurrentName = System.IO.Path.GetFileName (pathSuggested);

            if (fc.Run () == (int)ResponseType.Accept) {
                data.SaveAsTunerProXdf (fc.Filename, choice);
            }
        } catch (Exception ex) {
            ErrorMsg ("Error writing file", ex.Message);
        } finally {
            if (fc != null)
                fc.Destroy ();
        }
    }
Пример #34
0
    protected void OnOpenActionActivated(object sender, EventArgs e)
    {
        FileChooserDialog openD = new FileChooserDialog("Open file",
                                      this, FileChooserAction.Open,
                                      Stock.Cancel, ResponseType.Cancel,
                                      Stock.Open, ResponseType.Accept);
        FileFilter filter = new FileFilter();
        filter.Name = "INES rom (*.nes)";
        filter.AddMimeType("Ines");
        filter.AddPattern("*.nes");
        openD.AddFilter(filter);

        openD.SetFilename(MyNesGTK.Settings.LastUsedFile);
        if (openD.Run() == (int)ResponseType.Accept)
        {
            MyNesGTK.Settings.LastUsedFile = openD.Filename;
            LoadRom(openD.Filename);
        }
        openD.Destroy();
    }
Пример #35
0
		/// <summary>
		/// Opens the file chooser to select multiple files.
		/// </summary>
		/// <returns>Array of file names or null, if dialog was cancled</returns>
		/// <param name="title">Title.</param>
		private String[] OpenFileChooser(String title) {
			String[] filenames = null;
			Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog (title, m_mainWindow, FileChooserAction.Open,
				"_Cancel", ResponseType.Cancel,
				"_Open", ResponseType.Accept);
			fcd.DoOverwriteConfirmation = true;
			fcd.SelectMultiple = true;
			if(!String.IsNullOrWhiteSpace(m_currentPath)) fcd.SetFilename (m_currentPath);
			if ((Gtk.ResponseType)fcd.Run() == Gtk.ResponseType.Accept) {
				filenames = fcd.Filenames;
				if(filenames != null && filenames.Length > 0)
					m_currentPath = filenames[0];
			}
			fcd.Destroy ();

			return filenames;
		}
Пример #36
0
		private void ConnectEventsMainWindow() {

			// ----------------------------------------------------------------------------------------------------
			m_imagemenuitemNew.Activated += delegate(object o, EventArgs args) {
				UpdateGui (m_defaultSettings);
			};

			m_imagemenuitemOpen.Activated += delegate(object o, EventArgs args) {
				Gtk.Application.Invoke(delegate {
					Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog ("Load configuration", m_mainWindow, FileChooserAction.Open,
						"_Cancel", ResponseType.Cancel,
						"_Open", ResponseType.Accept);
					fcd.LocalOnly = false;
					if(!String.IsNullOrWhiteSpace(m_currentPath)) fcd.SetFilename(m_currentPath);
					if ((Gtk.ResponseType)fcd.Run() == Gtk.ResponseType.Accept) {
						LoadSaveStateFromFile (fcd.Filename);
					}
					fcd.Destroy ();
				});
			};

			// ----------------------------------------------------------------------------------------------------
			EventHandler imagemenuItemSave = delegate(object o, EventArgs arg) {
				Gtk.Application.Invoke(delegate {
					Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog ("Save configuration to file", m_mainWindow, FileChooserAction.Save,
						"_Cancel", ResponseType.Cancel,
						"_Save", ResponseType.Accept);
					fcd.DoOverwriteConfirmation = true;
					fcd.LocalOnly = false;
					if(!String.IsNullOrWhiteSpace(m_currentPath)) fcd.SetFilename(m_currentPath);
					if ((Gtk.ResponseType)fcd.Run() == Gtk.ResponseType.Accept) {
						SaveStateToFile (fcd.Filename);
					}
					fcd.Destroy ();
				});
			};

			// ----------------------------------------------------------------------------------------------------
			m_imagemenuitemSave.Activated += imagemenuItemSave;
			m_imagemenuitemSaveAs.Activated += imagemenuItemSave;

			// ----------------------------------------------------------------------------------------------------
			m_imagemenuitemClose.Activated += delegate(object obj, EventArgs args) {
				Application.Quit ();
			};


			// ----------------------------------------------------------------------------------------------------
			m_buttonTargetLanguageChoose.Clicked += delegate(object o, EventArgs e) {
				// Open file dialog
				String[] filenames = OpenFileChooser ("Select subtitles file in target language");
				if (filenames == null)
					return;

				m_entryTargetLanguage.Text = AddFilesToEntry(m_entryTargetLanguage.Text, filenames, "Error in target language file entry field: ");
			};

			// ----------------------------------------------------------------------------------------------------
			m_buttonDirectoryChoose.Clicked += delegate(object o, EventArgs e) {

				Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog ("Select output folder", m_mainWindow, FileChooserAction.SelectFolder,
					"_Cancel", ResponseType.Cancel,
					"_Choose", ResponseType.Accept);
				fcd.DoOverwriteConfirmation = true;
				fcd.SelectMultiple = true;
				if(!String.IsNullOrWhiteSpace(m_currentPath)) fcd.SelectFilename(m_currentPath);
				if ((Gtk.ResponseType)fcd.Run () == Gtk.ResponseType.Accept) {
					m_entryOutputDirectory.Text = fcd.Filename;
					m_currentPath = fcd.Filename;
				}
				fcd.Destroy ();
			};

			// ----------------------------------------------------------------------------------------------------
			m_buttonNativeLanguageChoose.Clicked += delegate(object o, EventArgs e) {
				// Open file dialog
				String[] filenames = OpenFileChooser ("Select subtitles file in native language");
				if (filenames == null)
					return;

				m_entryNativeLanguage.Text = AddFilesToEntry(m_entryNativeLanguage.Text, filenames, "Error in native language file entry field: ");
			};

			// ----------------------------------------------------------------------------------------------------
			m_buttonVideoFileChoose.Clicked += delegate(object o, EventArgs e) {
				// Open file dialog
				String[] filenames = OpenFileChooser ("Select video files");
				if (filenames == null)
					return;

				m_entryVideoFile.Text = AddFilesToEntry(m_entryVideoFile.Text, filenames, "Error in video file entry field: ");
			};


			// ----------------------------------------------------------------------------------------------------
			m_buttonTargetLanguageOptions.Clicked += delegate(object o, EventArgs e) {
				OpenSubtitleWindow(0);
			};

			// ----------------------------------------------------------------------------------------------------
			m_buttonNativeLanguageOptions.Clicked += delegate(object o, EventArgs e) {
				OpenSubtitleWindow(1);
			};

			// ----------------------------------------------------------------------------------------------------
			m_buttonPreview.Clicked += delegate(object o, EventArgs args) {
				PreviewButtonClicked();
			};

			// ----------------------------------------------------------------------------------------------------
			m_mainWindow.DeleteEvent += delegate(object obj, DeleteEventArgs args) {
				Application.Quit ();
			};
		}
Пример #37
0
        // Save as .pal
        protected void OnButton19Pressed(object sender, EventArgs e)
        {
            FileChooserDialog sav = new FileChooserDialog("Save Palette file",
                                        this, FileChooserAction.Save,
                                        Stock.Cancel, ResponseType.Cancel,
                                        Stock.Save, ResponseType.Accept);
            FileFilter filter1 = new FileFilter();
            filter1.Name = "Palette file '64 indexes' (*.pal)";
            filter1.AddMimeType("pal");
            filter1.AddPattern("*.pal");
            sav.AddFilter(filter1);
            FileFilter filter2 = new FileFilter();
            filter2.Name = "Palette file '512 indexes' (*.pal)";
            filter2.AddMimeType("pal");
            filter2.AddPattern("*.pal");
            sav.AddFilter(filter2);
            sav.SetFilename("palette.pal");
            if (sav.Run() == (int)ResponseType.Accept)
            {
                //get pallete
                List<byte> palette = new List<byte>();
                int[] NesPalette = (combobox_paletteOf.Active == 0) ? NTSCPaletteGenerator.GeneratePalette() :
                    PALBPaletteGenerator.GeneratePalette();

                for (int i = 0; i < ((sav.Filter == filter1) ? 64 : 512); i++)
                {
                    int color = NesPalette[i];
                    palette.Add((byte)((color >> 16) & 0xFF));//Red
                    palette.Add((byte)((color >> 8) & 0xFF));//Green
                    palette.Add((byte)((color >> 0) & 0xFF));//Blue
                }

                Stream str = new FileStream(sav.Filename, FileMode.Create, FileAccess.Write);
                str.Write(palette.ToArray(), 0, palette.Count);
                str.Close();
            }
            sav.Destroy();
        }