Ejemplo n.º 1
0
    private void on_overwrite_file_accepted(object o, EventArgs args)
    {
        try {
            //if multimedia_and_encoder, then copy the folder. If not checked, then copy only the db file
            if (check_backup_multimedia_and_encoder.Active)
            {
                Directory.Delete(fileCopy, true);
                thread = new Thread(new ThreadStart(copyRecursive));
                GLib.Idle.Add(new GLib.IdleHandler(PulseGTK));

                backup_doing_sensitive_start_end(true);

                LogB.ThreadStart();
                thread.Start();
            }
            else
            {
                File.Delete(fileCopy);
                File.Copy(fileDB, fileCopy);

                fc.Hide();
                string myString = string.Format(Catalog.GetString("Copied to {0}"), fileCopy);
                new DialogMessage(Constants.MessageTypes.INFO, myString);
            }
        } catch {
            string myString = string.Format(Catalog.GetString("Cannot copy to {0} "), fileCopy);
            new DialogMessage(Constants.MessageTypes.WARNING, myString);
        }
    }
Ejemplo n.º 2
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 ();
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
    void on_button_export_clicked(object o, EventArgs args)
    {
        Gtk.FileChooserDialog fc =
            new Gtk.FileChooserDialog(Catalog.GetString("Export to file"),
                                      encoder_configuration,
                                      FileChooserAction.Save,
                                      Catalog.GetString("Cancel"), ResponseType.Cancel,
                                      Catalog.GetString("Accept"), ResponseType.Accept
                                      );

        if (fc.Run() == (int)ResponseType.Accept)
        {
            exportFileName = fc.Filename;
            exportFileName = Util.AddTxtIfNeeded(exportFileName);

            try {
                if (File.Exists(exportFileName))
                {
                    LogB.Information(string.Format(
                                         "File {0} exists with attributes {1}, created at {2}",
                                         exportFileName,
                                         File.GetAttributes(exportFileName),
                                         File.GetCreationTime(exportFileName)));
                    LogB.Information("Overwrite...");
                    ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString(
                                                                      "Are you sure you want to overwrite file: "), "",
                                                                  exportFileName);

                    confirmWin.Button_accept.Clicked +=
                        new EventHandler(on_overwrite_file_export_accepted);
                }
                else
                {
                    on_file_export_accepted();

                    string myString = string.Format(Catalog.GetString("Saved to {0}"),
                                                    exportFileName);
                    new DialogMessage(Constants.MessageTypes.INFO, myString);
                }
            }
            catch {
                string myString = string.Format(
                    Catalog.GetString("Cannot save file {0} "), exportFileName);
                new DialogMessage(Constants.MessageTypes.WARNING, myString);
            }
        }
        else
        {
            LogB.Information("cancelled");
            new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Cancelled."));
            fc.Hide();
            return;
        }

        //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
        fc.Destroy();

        return;
    }
 protected virtual void OnChooseClick(object sender, System.EventArgs e)
 {
     FileChooserDialog dlg = new FileChooserDialog (Catalog.GetString ("Choose Executable or Script"), this,
                                                    FileChooserAction.Open, Catalog.GetString ("Cancel"),
                                                    ResponseType.Cancel, Catalog.GetString ("OK"),
                                                    ResponseType.Accept);
     if (dlg.Run () == (int)ResponseType.Accept) {
         execEntry.Text = dlg.Filename;
         dlg.Hide ();
     }
     dlg.Destroy ();
 }
Ejemplo n.º 6
0
 protected void OnAdd(object s, EventArgs args)
 {
     FileChooserDialog dialog = new FileChooserDialog (Catalog.GetString (Catalog.GetString ("Add Widget Library")), null, FileChooserAction.Open,
                        Gtk.Stock.Cancel, Gtk.ResponseType.Cancel,
                        Gtk.Stock.Open, Gtk.ResponseType.Ok);
     int response = dialog.Run ();
     if (response == (int)Gtk.ResponseType.Ok) {
         SteticMain.SteticApp.AddWidgetLibrary (dialog.Filename);
         AddLibrary (dialog.Filename);
         LoadList ();
     }
     dialog.Hide ();
 }
Ejemplo n.º 7
0
    protected void OnOpen(object o, EventArgs e)
    {
        if (!ChangeConfirm("load a new level"))
        {
            return;
        }
        fileChooser.Title  = "Choose a Level";
        fileChooser.Action = Gtk.FileChooserAction.Open;
        fileChooser.SetCurrentFolder(Settings.Instance.LastDirectoryName);
        fileChooser.Filter = fileChooser.Filters[0];
        int result = fileChooser.Run();

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

        Settings.Instance.LastDirectoryName = fileChooser.CurrentFolder;
        Settings.Instance.Save();
        Load(fileChooser.Filename);
        EditProperties(CurrentLevel, "Level");
    }
Ejemplo n.º 8
0
    protected virtual void OnOpenActionActivated(object sender, System.EventArgs e)
    {
        m_dlgOpen.SelectFilename(m_LastDir);
        int res = m_dlgOpen.Run();

        m_dlgOpen.Hide();
        if (res != (int)ResponseType.Ok)
        {
            return;
        }
        m_LastDir = System.IO.Path.GetDirectoryName(m_dlgOpen.Filenames[0]);

        m_nFiles = 0;
        string title = " New Analysis ";
        int    tlen  = title.Length;

        Log.Text = title.PadLeft(40 + tlen / 2, '*').PadRight(80, '*');
        State    = States.LOADING;
        try {
            bool bThresholds = true;
            m_Mapper           = Mapper.Create(m_dlgOpen.Filename, m_Software);
            m_Mapper.OnNotify += WriteLog;
            foreach (string xmlpath in m_dlgOpen.Filenames)
            {
                m_Mapper.Load(xmlpath, true);
                if (m_Mapper.PlgsThreshold == Peptide.ConfidenceType.NoThreshold)
                {
                    bThresholds = false;
                }
                m_nFiles++;
            }
            m_Mapper.PlgsThreshold = bThresholds ? Peptide.ConfidenceType.Yellow : Peptide.ConfidenceType.NoThreshold;
        } catch (Exception ex) {
            WriteLog("Error loading XML: " + ex.Message);
            WriteLog("Stack trace:\n" + ex.StackTrace);
            State = States.EMPTY;
            return;
        }
        WriteLog("Completed!");
        if (m_Mapper.Spectra.Count != 0)
        {
            WriteLog("\tLoaded " + m_Mapper.Spectra.Count + " spectra");
            WriteLog("\tLoaded " + m_Mapper.PsmCount + " PSMs");
        }
        WriteLog("\tLoaded " + m_Mapper.Peptides.Count + " possible peptides");
        WriteLog("\tLoaded " + m_Mapper.Proteins.Count + " possible proteins");
        DisplayData();
        State = States.LOADED;
    }
Ejemplo n.º 9
0
    protected virtual void OnSaveActionActivated(object sender, System.EventArgs e)
    {
        int res = m_dlgSave.Run();

        m_dlgSave.Hide();
        if (res != (int)ResponseType.Ok)
        {
            return;
        }
        WriteLog("\nSaving ...");
        string fpath = m_dlgSave.Filename;

        try {
            m_Mapper.Save(fpath);
        } catch (Exception ex) {
            WriteLog("Error saving results: " + ex.Message);
            return;
        }
        WriteLog("Done!");
    }
Ejemplo n.º 10
0
        ///<summary>Handle file->open command from menu</summary>
        public void OnOpenActivated(object o, EventArgs args)
        {
            // Get path of file(s) to open
            Gtk.FileChooserDialog fs = new Gtk.FileChooserDialog(Catalog.GetString("Open File(s)"), mainWindow, FileChooserAction.Open,
                                                                 Gtk.Stock.Cancel, ResponseType.Cancel,
                                                                 Gtk.Stock.Open, ResponseType.Accept);

            fs.SelectMultiple = true;
            ResponseType result = (ResponseType)fs.Run();

            fs.Hide();

            // if user does not cancel load the file(s)
            if (result == ResponseType.Accept)
            {
                Services.File.LoadFiles(fs.Filenames);
            }

            fs.Destroy();
        }
Ejemplo n.º 11
0
    protected void openFileClicked(object sender, EventArgs e)
    {
        // Open sprite sheet.
        var dialog = new Gtk.FileChooserDialog("Select Sprite Sheet", this, FileChooserAction.Open,
                                               "gtk-cancel", ResponseType.Cancel,
                                               "gtk-ok", ResponseType.Ok);

        dialog.Filter = new FileFilter();
        dialog.Filter.AddPattern("*.png");
        var result = (ResponseType)dialog.Run();

        dialog.Hide();

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

        var app = m_app;

        app.Filename = dialog.Filename;
        app.Do(Act.Analyze);
    }
        public ImagePreviewWidget()
        {
            this.Build ();
            saveDialog = new FileChooserDialog (
                "",
                null,
                FileChooserAction.Save,
                "Cancel", ResponseType.Cancel,
                "Save", ResponseType.Accept
            );

            imageloader.OnLoaded += (ImageLoader obj) => {
                imageloader.ShowButtons = true;
                UpdateTitle ();
            };

            imageloader.OnSaveClick += (string obj) => {
                saveDialog.CurrentName = System.IO.Path.GetFileName (imageloader.Url);
                if (saveDialog.Run () == (int)ResponseType.Accept) {
                    imageloader.Image.Pixbuf.Save (saveDialog.Filename, "jpeg");
                }
                saveDialog.Hide ();
            };
        }
Ejemplo n.º 13
0
        public static bool SaveProjectAs()
        {
            FileChooserDialog dialog =
                new FileChooserDialog (Catalog.GetString ("Save Stetic File As"), null, FileChooserAction.Save,
                               Gtk.Stock.Cancel, Gtk.ResponseType.Cancel,
                               Gtk.Stock.Save, Gtk.ResponseType.Ok);

            if (Project.FileName != null)
                dialog.CurrentName = Project.FileName;

            int response = dialog.Run ();
            if (response == (int)Gtk.ResponseType.Ok) {
                string name = dialog.Filename;
                if (System.IO.Path.GetExtension (name) == "")
                    name = name + ".stetic";
                try {
                    Project.Save (name);
                    Project.Modified = false;
                    SteticMain.UIManager.AddRecentFile (name);
                } catch (Exception ex) {
                    ReportError (Catalog.GetString ("The project could not be saved."), ex);
                    return false;
                }
            }
            dialog.Hide ();
            return true;
        }
Ejemplo n.º 14
0
 protected void OnButtonSavePhotoClicked(object sender, EventArgs e)
 {
     FileChooserDialog fc =
         new FileChooserDialog ("Укажите файл для сохранения фотографии",
             (Window)this.Toplevel,
             FileChooserAction.Save,
             "Отмена", ResponseType.Cancel,
             "Сохранить", ResponseType.Accept);
     fc.CurrentName = (GetSaveFileName != null ? GetSaveFileName() : "фото")  + ".jpg";
     fc.Show ();
     if (fc.Run () == (int)ResponseType.Accept) {
         fc.Hide ();
         FileStream fs = new FileStream (fc.Filename, FileMode.Create, FileAccess.Write);
         fs.Write (ImageFile, 0, ImageFile.Length);
         fs.Close ();
     }
     fc.Destroy ();
 }
Ejemplo n.º 15
0
        ///<summary>
        /// Manage high-level file saving procedures (eg confirm file overwrites, get filenames etc)
        ///</summary>
        public bool SaveFile(DataView dv, string filename, bool forceSaveAs, bool synchronous)
        {
            ByteBuffer bb = dv.Buffer;

            if (!dv.Buffer.FileOperationsAllowed)
            {
                return(false);
            }

            // if a filename is given, save the file under the specified filename
            if (!forceSaveAs && filename != null)
            {
                return(SaveFileInternal(dv, filename, synchronous));
            }

            // if a filename is not given but buffer
            // has a file associated with it, save it under the same filename
            if (!forceSaveAs && filename == null && bb.HasFile == true && bb.Filename.Length != 0)
            {
                return(SaveFileInternal(dv, bb.Filename, synchronous));
            }

            // otherwise prompt user for a name
            Gtk.FileChooserDialog fs = new Gtk.FileChooserDialog(Catalog.GetString("Save File As"), mainWindow, FileChooserAction.Save,
                                                                 Gtk.Stock.Cancel, ResponseType.Cancel,
                                                                 Gtk.Stock.Save, ResponseType.Accept);

            bool done      = false;
            bool fileSaved = true;

            do
            {
                ResponseType response = (ResponseType)fs.Run();
                fs.Hide();
                if (response == ResponseType.Accept)
                {
                    // check to see whether file exists and prompt user to confirm
                    if (File.Exists(fs.Filename))
                    {
                        FileOverwriteAlert ea        = new FileOverwriteAlert(fs.Filename, mainWindow);
                        ResponseType       response1 = (ResponseType)ea.Run();
                        ea.Destroy();
                        if (response1 == ResponseType.Ok)
                        {
                            fileSaved = SaveFileInternal(dv, fs.Filename, synchronous);
                            done      = true;
                        }
                        else
                        {
                            done = false;
                        }
                    }
                    else              // !File.Exists(fs.Filename)
                    {
                        fileSaved = SaveFileInternal(dv, fs.Filename, synchronous);
                        done      = true;
                    }
                }
                else           // response!=ResponseType.OK
                {
                    done      = true;
                    fileSaved = false;
                }
            } while (!done);

            fs.Destroy();

            //UpdateRevert(dv);

            return(fileSaved);
        }
Ejemplo n.º 16
0
		// File Menu
		
		protected virtual void OnOpenActivated (object sender, System.EventArgs e)
		{
			BuildFilters ();
			using (FileChooserDialog fcd = new FileChooserDialog ("Open Assembly...", this, FileChooserAction.Open, 
				"Cancel", ResponseType.Cancel, "Open", ResponseType.Accept)) {
				
				if (current_directory != null)
					fcd.SetCurrentFolder (current_directory);
					
				fcd.SelectMultiple = true;
				fcd.AddFilter (dotnet_filter);
				fcd.AddFilter (list_filter);
				fcd.AddFilter (all_filter);
				
				bool ok = (fcd.Run () == (int) ResponseType.Accept);
				fcd.Hide ();
				if (ok) {
					Load (fcd.Filenames);
					
					current_directory = fcd.CurrentFolder;
				}
			}
		}
Ejemplo n.º 17
0
        public void on_save_activate(System.Object b, EventArgs e)
        {
            FileChooserDialog fd = new FileChooserDialog (Catalog.GetString("Save Game"), csboardWindow, FileChooserAction.Save);

            fd.AddButton (Stock.Close, (int) ResponseType.Close);
                        fd.AddButton (Stock.Save, (int) ResponseType.Ok);

                        int res = fd.Run();
            fd.Hide ();

                        if (res == (int) ResponseType.Ok) {

                                        if (System.IO.File.Exists (fd.Filename)) {
                                                MessageDialog md =
                                                new MessageDialog (csboardWindow,
                                                           DialogFlags.
                                                           DestroyWithParent,
                                                           MessageType.Warning,
                                                           ButtonsType.OkCancel,
                                                           Catalog.GetString("File ") + fd.Filename +
                                                           Catalog.GetString(" already exists\n\n") +
                                                           Catalog.GetString("Do you wish to overwrite it?"));
                                                if (md.Run () == (int)ResponseType.Ok) {
                                                        control.SaveGame (fd.Filename);
                                                }
                                                md.Hide ();
                                                md.Dispose ();
                                        } else {
                                                control.SaveGame (fd.Filename);
                                        }
                                }

                        fd.Dispose ();
        }
Ejemplo n.º 18
0
        protected void OnOpenActionActivated(object sender, EventArgs e)
        {
            FileChooserDialog Chooser = new FileChooserDialog("Выберите файл шаблона распознования...",
                                                              this,
                                                              FileChooserAction.Open,
                                                              "Отмена", ResponseType.Cancel,
                                                              "Открыть", ResponseType.Accept );

            FileFilter Filter = new FileFilter();
            Filter.AddMimeType("text/xml");
            Filter.Name = "xml";
            Chooser.AddFilter(Filter);

            if((ResponseType) Chooser.Run () == ResponseType.Accept)
            {
                Chooser.Hide();
                FileStream fs = new FileStream(Chooser.Filename, FileMode.Open, FileAccess.Read);
                //FIXME Обработать ошибки загрузки.
                DocTemplate = RecognizeTemplate.Load(fs);
                fs.Close();
                labelTemplateName.LabelProp = DocTemplate.Name;
                DocTemplate.DocTypeId = TypeId;
            }
            Chooser.Destroy();
        }
Ejemplo n.º 19
0
        void OnCommandProgram(object sender, EventArgs args)
        {
            FileChooserDialog dlg = new FileChooserDialog("Program file",
            null, FileChooserAction.Open,
            new object[]{Stock.Cancel, ResponseType.Cancel,
                 Stock.Ok, ResponseType.Ok});

            dlg.DefaultResponse = ResponseType.Ok;

            if ((ResponseType)dlg.Run() == ResponseType.Ok)
            debugPane.DebugView.RunCommand("prog " + dlg.Filename);

            dlg.Hide();
        }
Ejemplo n.º 20
0
    protected void checkFile(Constants.EncoderCheckFileOp checkFileOp)
    {
        string exportString = "";
        if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL)
            exportString = Catalog.GetString ("Export set in CSV format");
        else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE)
            exportString = Catalog.GetString ("Save image");
        else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
            exportString = Catalog.GetString ("Export repetition in CSV format");
        else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
            exportString = Catalog.GetString ("Save table");

        string nameString = currentPerson.Name + "_" + currentSession.DateShortAsSQL;
        if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL)
            nameString += "_encoder_set_export.csv";
        else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE)
            nameString += ".png";
        else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
            nameString += "_encoder_repetition_export.csv";
        else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
            nameString += "_encoder_curves_table.csv";

        Gtk.FileChooserDialog fc=
            new Gtk.FileChooserDialog(exportString,
                    app1,
                    FileChooserAction.Save,
                    Catalog.GetString("Cancel"),ResponseType.Cancel,
                    Catalog.GetString("Accept"),ResponseType.Accept
                    );
        fc.CurrentName = nameString;

        if (fc.Run() == (int)ResponseType.Accept)
        {
            exportFileName = fc.Filename;
            //add ".csv" if needed
            if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL ||
                    checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB ||
                    checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
                exportFileName = Util.AddCsvIfNeeded(exportFileName);
            else
                exportFileName = Util.AddPngIfNeeded(exportFileName);
            try {
                if (File.Exists(exportFileName)) {
                    LogB.Information(string.Format(
                                "File {0} exists with attributes {1}, created at {2}",
                                exportFileName,
                                File.GetAttributes(exportFileName),
                                File.GetCreationTime(exportFileName)));
                    LogB.Information("Overwrite...");
                    ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString(
                                "Are you sure you want to overwrite file: "), "",
                            exportFileName);

                    if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL)
                        confirmWin.Button_accept.Clicked +=
                            new EventHandler(on_overwrite_file_export_all_curves_accepted);
                    else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE)
                        confirmWin.Button_accept.Clicked +=
                            new EventHandler(on_overwrite_file_encoder_save_image_accepted);
                    else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
                        confirmWin.Button_accept.Clicked +=
                            new EventHandler(on_overwrite_file_encoder_save_AB_accepted);
                    else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
                        confirmWin.Button_accept.Clicked +=
                            new EventHandler(on_overwrite_file_encoder_save_table_accepted);

                } else {
                    if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL)
                        on_button_encoder_export_all_curves_file_selected (exportFileName);
                    else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE)
                        on_button_encoder_save_image_file_selected (exportFileName);
                    else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
                        on_button_encoder_save_AB_file_selected (exportFileName);
                    else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
                        on_button_encoder_save_table_file_selected (exportFileName);

                    string myString = string.Format(Catalog.GetString("Saved to {0}"),
                            exportFileName);
                    if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL ||
                            checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
                        myString += Constants.SpreadsheetString;
                    new DialogMessage(Constants.MessageTypes.INFO, myString);
                }
            } catch {
                string myString = string.Format(
                        Catalog.GetString("Cannot save file {0} "), exportFileName);
                new DialogMessage(Constants.MessageTypes.WARNING, myString);
            }
        }
        else {
            LogB.Information("cancelled");
            //report does not currently send the appBar reference
            new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Cancelled."));
            fc.Hide ();
            return ;
        }

        //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
        fc.Destroy();

        return;
    }
Ejemplo n.º 21
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();
    }
Ejemplo n.º 22
0
 private void OnSingleWizBrowseButtonClicked(object o, EventArgs e)
 {
     FileChooserDialog filedlg = new FileChooserDialog("", Util.GS("Select a file..."), this, FileChooserAction.Open, Stock.Cancel, ResponseType.Cancel,Stock.Ok, ResponseType.Ok);
      FileFilter filter = new FileFilter();
                 filter.Name = "PKCS12 files";
                 filter.AddMimeType("PKCS12|p12");
                 filter.AddPattern("*.p12");
                 filedlg.AddFilter(filter);
                 filter = new FileFilter();
                 filter.Name = "PFX files";
                 filter.AddMimeType("PFX|pfx");
                 filter.AddPattern("*.pfx");
                 filedlg.AddFilter(filter);
                 filter = new FileFilter();
                 filter.Name = "All files";
                 filter.AddMimeType("All|all");
                 filter.AddPattern("*.*");
                 filedlg.AddFilter(filter);
                 int res = filedlg.Run();
                 string str = filedlg.Filename;
                 filedlg.Hide();
                 filedlg.Destroy();
                 if( res == (int)ResponseType.Ok)
                 {
                         this.p12FilePath.Text = str;
                 }
 }
Ejemplo n.º 23
0
 private void OnImportBrowseButtonClicked(object o, EventArgs e)
 {
     FileChooserDialog filedlg = new FileChooserDialog("", Util.GS("Select a file ...."), this, FileChooserAction.Open, Stock.Cancel, ResponseType.Cancel,Stock.Ok, ResponseType.Ok);
     FileFilter filter = new FileFilter();
                 filter.Name = "XML files";
                 filter.AddMimeType("XML files|xml");
                 filter.AddPattern("*.xml");
                 filedlg.AddFilter(filter);
                 int res = filedlg.Run();
                 string str = filedlg.Filename;
                 filedlg.Hide();
                 filedlg.Destroy();
                 if( res == (int)ResponseType.Ok)
                 {
                         this.importLocation.Text = str;
                 }
 }
Ejemplo n.º 24
0
 private void OnImportBrowseButtonClicked(object o, EventArgs e)
 {
     FileChooserDialog filedlg = new FileChooserDialog("", Util.GS("Select a file ...."), this, FileChooserAction.Open, Stock.Cancel, ResponseType.Cancel,Stock.Ok, ResponseType.Ok);
                 int res = filedlg.Run();
                 string str = filedlg.Filename;
                 filedlg.Hide();
                 filedlg.Destroy();
                 if( res == (int)ResponseType.Ok)
                 {
                         this.importLocation.Text = str;
                 }
 }
Ejemplo n.º 25
0
        protected void OnButtonAddClicked(object sender, EventArgs e)
        {
            FileChooserDialog Chooser = new FileChooserDialog ("Выберите файл для прикрепления...",
                                                               (Gtk.Window)this.Toplevel,
                                                               FileChooserAction.Open,
                                                               "Отмена", ResponseType.Cancel,
                                                               "Прикрепить", ResponseType.Accept);
            if ((ResponseType)Chooser.Run () == ResponseType.Accept) {
                Chooser.Hide ();
                logger.Info ("Чтение файла...");

                byte[] file;
                using (FileStream fs = new FileStream (Chooser.Filename, FileMode.Open, FileAccess.Read)) {
                    using (MemoryStream ms = new MemoryStream ()) {
                        fs.CopyTo (ms);
                        file = ms.ToArray ();
                    }
                }
                string fileName = System.IO.Path.GetFileName (Chooser.Filename);
                //При необходимости обрезаем имя файла.
                if(fileName.Length > MaxFileNameLength)
                {
                    string ext = System.IO.Path.GetExtension (fileName);
                    string name = System.IO.Path.GetFileNameWithoutExtension (fileName);
                    fileName = String.Format ("{0}{1}",
                                              name.Remove ((int)MaxFileNameLength - ext.Length),
                                                ext);
                }

                FilesStore.AppendValues (-1,
                                         fileName,
                                         file.LongLength,
                                         FileIconWorks.GetPixbufForFile (Chooser.Filename),
                                         file
                );
                logger.Info ("Ok");
            }
            Chooser.Destroy ();
        }
Ejemplo n.º 26
0
		protected virtual void OnSaveActivated (object sender, System.EventArgs e)
		{
			using (FileChooserDialog fcd = new FileChooserDialog ("Save Assembly List...", this, FileChooserAction.Save, 
				"Cancel", ResponseType.Cancel, "Save", ResponseType.Accept)) {
				
				if (current_directory != null)
					fcd.SetCurrentFolder (current_directory);
					
				bool ok = (fcd.Run () == (int) ResponseType.Accept);
				fcd.Hide ();
				if (ok) {
					SaveAssemblyList (fcd.Filename);
					
					current_directory = fcd.CurrentFolder;
				}
			}
		}
Ejemplo n.º 27
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);
    }
Ejemplo n.º 28
0
        public static void Main(string[] args)
        {
            string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            if(folderPath != null && folderPath.Length > 0)
            {
                if(folderPath[folderPath.Length - 1] != Path.DirectorySeparatorChar)
                {
                    folderPath += Path.DirectorySeparatorChar;
                }

                settingsFile = new FileInfo(folderPath + ".tehthuconfig");
            }

            Assembly ass = Assembly.GetExecutingAssembly();

            //Useful for seeing the names of embedded resources....
            /*
            string[] resources = ass.GetManifestResourceNames();
            foreach(string ss in resources)
            {
                Console.WriteLine("Resource " + ss);
            }
            */

            StreamReader ms = new StreamReader(new MemoryStream(TehthuGUI.Properties.Resources.teh));
            string gladefile = ms.ReadToEnd();

            Application.Init ();
            xml = new Glade.XML(gladefile, gladefile.Length, "MW", null);
            if(xml == null)
            {
                Console.WriteLine("Failed to open Glade XML file!");
                return;
            }

            mainwindow = (Gtk.Window) xml.GetWidget("MW");
            if(mainwindow == null)
            {
                Console.WriteLine("Failed to create main window!");
                return;
            }
            else
            {
                object[] _button_options = {Gtk.Stock.Open, Gtk.ResponseType.Accept, Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, null};
                FileChooserDialog fcd = new FileChooserDialog("Open A Dictionary", mainwindow, FileChooserAction.Open, _button_options);

                inputView = (Gtk.TextView) xml.GetWidget("InputView");
                outputView = (Gtk.TextView) xml.GetWidget("OutputView");
                debugView = (Gtk.TextView) xml.GetWidget("DebugView");

                mainwindow.DestroyEvent += delegate(object o, DestroyEventArgs dea) {
                    Application.Quit();
                };

                mainwindow.Destroyed += delegate(object sender, EventArgs e) {
                    Application.Quit();
                };

                Gtk.MenuItem quit = (Gtk.MenuItem) xml.GetWidget("Quit");
                quit.Activated += delegate(object sender, EventArgs e) {
                    Application.Quit();
                };

                Gtk.Notebook nb = (Gtk.Notebook) xml.GetWidget("Notebook");

                Gtk.RadioButton leftButton = (Gtk.RadioButton) xml.GetWidget("LeftButton");
                leftButton.Toggled += delegate(object sender, EventArgs e) {
                    leftToRight = true;

                    try
                    {
                        Gtk.Label inputTabLabel = (Gtk.Label)nb.GetTabLabel(nb.GetNthPage(0));
                        inputTabLabel.Text = "Input ("
                            + (leftToRight ? teh.getLeftLanguageName() : teh.getRightLanguageName())
                            + ")";

                        Gtk.Label outputTabLabel = (Gtk.Label)nb.GetTabLabel(nb.GetNthPage(1));
                        outputTabLabel.Text = "Output ("
                            + (leftToRight ? teh.getRightLanguageName() : teh.getLeftLanguageName())
                            + ")";
                    }
                    catch (Exception eee)
                    {
                        Console.WriteLine("boo");
                    }
                };

                Gtk.RadioButton rightButton = (Gtk.RadioButton) xml.GetWidget("RightButton");
                rightButton.Toggled += delegate(object sender, EventArgs e) {
                    leftToRight = false;

                    try {
                    Gtk.Label inputTabLabel = (Gtk.Label) nb.GetTabLabel(nb.GetNthPage(0));
                    inputTabLabel.Text = "Input ("
                        + (leftToRight ? teh.getLeftLanguageName() : teh.getRightLanguageName())
                        + ")";

                    Gtk.Label outputTabLabel = (Gtk.Label) nb.GetTabLabel(nb.GetNthPage(1));
                    outputTabLabel.Text = "Output ("
                        + (leftToRight ? teh.getRightLanguageName() : teh.getLeftLanguageName())
                        + ")";
                    }
                    catch (Exception eee)
                    {
                        Console.WriteLine("boo");
                    }
                };

                Gtk.Entry input = (Gtk.Entry) xml.GetWidget("Input");
                input.KeyReleaseEvent += delegate(object _o, KeyReleaseEventArgs _args) {
                    if(_args.Event.Key == Gdk.Key.Return && input.Text.Length > 0)
                    {
                        string translated = teh.translate(input.Text, leftToRight ? TranslateDirection.LeftToRight : TranslateDirection.RightToLeft);
                        inputView.Buffer.Text += input.Text + Environment.NewLine;
                        outputView.Buffer.Text += translated + Environment.NewLine;
                        input.Text = "";
                    }
                };

                Gtk.Button send = (Gtk.Button) xml.GetWidget("Send");
                send.Pressed += delegate(object sender, EventArgs e) {
                    string translated = teh.translate(input.Text, leftToRight ? TranslateDirection.LeftToRight : TranslateDirection.RightToLeft);
                    inputView.Buffer.Text += input.Text + Environment.NewLine;
                    outputView.Buffer.Text += translated + Environment.NewLine;
                    input.Text = "";
                };

                input.Sensitive = false;
                send.Sensitive = false;
                input.IsEditable = false;

                Gtk.MenuItem open = (Gtk.MenuItem) xml.GetWidget("Open");
                open.Activated += delegate(object sender, EventArgs e) {
                    int retval = fcd.Run();

                    fcd.Hide();

                    if((int) Gtk.ResponseType.Accept != retval)
                    {
                        return;
                    }

                    initialize(new FileInfo(fcd.Filename), input, send, nb, leftButton, rightButton);
                };

                //If the settings file already has the name of a dictionary, try to open it.
                //We just want to read the file at this point, not write it.
                if(settingsFile.Exists)
                {
                    TextReader tr = new StreamReader(settingsFile.OpenRead());
                    String settingsLine = tr.ReadLine();
                    tr.Close();
                    if(settingsLine != null)
                    {
                        FileInfo sett = new FileInfo(settingsLine);
                        if(sett.Exists)
                        {
                            initialize(sett, input, send, nb, leftButton, rightButton);
                        }
                    }
                }

                mainwindow.Show();
            }

            Application.Run ();
            if(monitor != null && monitor.IsAlive)
            {
                monitor.Join(500);
                monitor.Abort();
            }
        }
Ejemplo n.º 29
0
 private void SaveLog()
 {
     try
        {
     int rc = 0;
     bool saveFile = true;
     string filename = null;
     string initialPath = Util.LastSavedSyncLogPath;
     FileChooserDialog fcd = new FileChooserDialog(
      Util.GS("Save as..."), this,
      FileChooserAction.Save,
      Stock.Cancel, ResponseType.Cancel,
          Stock.Save, ResponseType.Ok);
      fcd.SelectMultiple = false;
      fcd.CurrentName = Util.GS("iFolder Synchronization Log.txt");
      if (initialPath != null)
       fcd.SetCurrentFolder(initialPath);
     while (saveFile)
     {
      rc = fcd.Run();
      fcd.Hide();
      if(rc == (int)ResponseType.Ok)
      {
       filename = fcd.Filename;
       if(File.Exists(filename))
       {
        iFolderMsgDialog dialog = new iFolderMsgDialog(
     this,
     iFolderMsgDialog.DialogType.Question,
     iFolderMsgDialog.ButtonSet.YesNo,
     "",
     Util.GS("Overwrite the existing file?"),
     Util.GS("The file you selected exists.  Selecting yes will overwrite the contents of this file."));
        rc = dialog.Run();
        dialog.Hide();
        dialog.Destroy();
        if(rc != -8)
     saveFile = false;
       }
      }
      else
       break;
      if(saveFile)
      {
       FileStream fs = null;
       try
       {
        fs = File.Create(filename);
       }
       catch (System.UnauthorizedAccessException uae)
       {
        iFolderMsgDialog dg = new iFolderMsgDialog(
     this,
     iFolderMsgDialog.DialogType.Error,
     iFolderMsgDialog.ButtonSet.Ok,
     "",
     Util.GS("Insufficient access"),
     Util.GS("You do not have access to save the file in the location you specified.  Please select a different location."));
        dg.Run();
        dg.Hide();
        dg.Destroy();
        continue;
       }
       catch (Exception e)
       {
        iFolderMsgDialog dg = new iFolderMsgDialog(
     this,
     iFolderMsgDialog.DialogType.Error,
     iFolderMsgDialog.ButtonSet.Ok,
     "",
     Util.GS("Error saving the log file"),
     string.Format(Util.GS("An exception occurred trying to save the log: {0}"), e.Message),
     e.StackTrace);
        dg.Run();
        dg.Hide();
        dg.Destroy();
        continue;
       }
       if(fs != null)
       {
        TreeIter iter;
        StreamWriter w = new StreamWriter(fs);
        if(LogTreeStore.GetIterFirst(out iter))
        {
     string logEntry =
      (string)LogTreeStore.GetValue(iter, 0);
     w.WriteLine(logEntry);
     while(LogTreeStore.IterNext(ref iter))
     {
      logEntry =
       (string)LogTreeStore.GetValue(iter, 0);
      w.WriteLine(logEntry);
     }
        }
        w.Close();
        Util.LastSavedSyncLogPath = filename;
        break;
       }
       else
       {
        iFolderMsgDialog dg = new iFolderMsgDialog(
     this,
     iFolderMsgDialog.DialogType.Error,
     iFolderMsgDialog.ButtonSet.Ok,
     "",
     Util.GS("Error saving the log file"),
     Util.GS("The iFolder Client experienced an error trying to save the log.  Please report this bug."));
        dg.Run();
        dg.Hide();
        dg.Destroy();
       }
      }
     }
     fcd.Destroy();
        }
        catch(Exception e)
        {
     iFolderMsgDialog dg = new iFolderMsgDialog(
      this,
      iFolderMsgDialog.DialogType.Error,
      iFolderMsgDialog.ButtonSet.Ok,
      "",
      Util.GS("Error saving the log file"),
      Util.GS("The iFolder Client experienced an exception trying to save the log.  Please report this bug.")
      + "\n\n" +
      Util.GS("Please ensure you have the lastest updates of gtk2 and gtk-sharp2 installed on your system."));
     dg.Run();
     dg.Hide();
     dg.Destroy();
        }
 }
Ejemplo n.º 30
0
        protected void OnButtonLoadImageClicked(object sender, EventArgs e)
        {
            FileChooserDialog Chooser = new FileChooserDialog("Выберите svg для загрузки...",
                this,
                FileChooserAction.Open,
                "Отмена", ResponseType.Cancel,
                "Загрузить", ResponseType.Accept );

            FileFilter Filter = new FileFilter();
            Filter.Name = "SVG изображение";
            Filter.AddMimeType("image/svg+xml");
            Filter.AddPattern("*.svg");
            Chooser.AddFilter(Filter);

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

            if((ResponseType) Chooser.Run () == ResponseType.Accept)
            {
                Chooser.Hide();
                MainClass.StatusMessage("Загрузка изображения основы...");
                if(entryName.Text == "")
                {
                    entryName.Text = System.IO.Path.GetFileNameWithoutExtension(Chooser.Filename);
                }
                using (FileStream fs = new FileStream(Chooser.Filename, FileMode.Open, FileAccess.Read))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        fs.CopyTo(ms);
                        SVGHelper FrameTest = new SVGHelper();
                        byte[] NewFile = ms.ToArray();
                        if(FrameTest.LoadImage(NewFile))
                        {
                            ImageHelper = FrameTest;
                            ImageHelper.PrepairForDBSave();
                            ImageChanged = true;
                        }
                        else
                        {
                            MessageDialog md = new MessageDialog ( this, DialogFlags.DestroyWithParent,
                                MessageType.Warning,
                                ButtonsType.Ok,
                                "Не удалось загрузить изображение основы. Для успешной загрузки формат файла должен быть svg. " +
                                "В файле изображения должен быть прямоугольник(rect) с id=framework указывающий положение рамки в которую вставлюятся кубы. " +
                                "Размерность исходного изображения должна быть 1 куб.");
                            md.Run ();
                            md.Destroy();
                        }
                    }
                }
                drawBasis.QueueDraw();
                MainClass.StatusMessage("Ok");
            }
            Chooser.Destroy ();
        }
Ejemplo n.º 31
0
 protected void OnSaveAsActionActivated(object sender, EventArgs e)
 {
     if(DocTemplate == null)
         return;
     FileChooserDialog fc=
         new FileChooserDialog("Укажите файл для сохранения шаблона...",
                               this,
                               FileChooserAction.Save,
                               "Отмена",ResponseType.Cancel,
                               "Сохранить",ResponseType.Accept);
     //FileFilter filter = new FileFilter();
     fc.CurrentName = DocTemplate.Name + ".xml";
     fc.Show();
     if(fc.Run() == (int) ResponseType.Accept)
     {
         fc.Hide();
         FileStream fs = new FileStream(fc.Filename, FileMode.Create, FileAccess.Write);
         DocTemplate.SaveToStream(fs);
         fs.Close();
     }
     fc.Destroy();
 }
Ejemplo n.º 32
0
 public void SaveAs()
 {
     FileChooserDialog fc = new FileChooserDialog (
             GettextCatalog.GetString ("Save your project as"),
             null,
             FileChooserAction.Save);
     FileFilter filter;
     // xmi files filter
     filter = new FileFilter ();
     filter.Name = GettextCatalog.GetString ("XMI files");
     filter.AddPattern ("*.xmi");
     fc.AddFilter (filter);
     // configures the buttons
     fc.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
     fc.AddButton (Gtk.Stock.SaveAs, Gtk.ResponseType.Ok);
     // runs the file chooser
     fc.SelectMultiple = false;
     Gtk.ResponseType response = (Gtk.ResponseType) fc.Run();
     fc.Hide ();
     if (response == Gtk.ResponseType.Ok)
     {
         string filename = fc.Filename;
         // filename can't be empty, I promise :)
         if (!filename.EndsWith(".xmi")) { filename += ".xmi"; }
         bool doSave = true;
         if (System.IO.File.Exists (filename))
         {
             MessageDialog md = new MessageDialog (null,
                 DialogFlags.DestroyWithParent,
                 MessageType.Question,
                 ButtonsType.YesNo,
                 GettextCatalog.GetString ("A file named {0} already exists.\nDo you want to replace it with the one you are saving?"), filename);
             ResponseType result = (ResponseType)md.Run ();
             md.Hide ();
             doSave = (result == ResponseType.Yes);
             md.Destroy ();
         }
         if (doSave)
         {
             System.Console.WriteLine ("saving as " + filename);
             _ser.Serialize (_elementsList, filename);
             _filename = filename;
         }
     }
     fc.Destroy ();
 }
Ejemplo n.º 33
0
    void on_button_db_backup_clicked(object o, EventArgs args)
    {
        System.IO.FileInfo file1 = new System.IO.FileInfo(databaseURL);         //potser cal una arrobar abans (a windows)
        System.IO.FileInfo file2 = new System.IO.FileInfo(databaseTempURL);     //potser cal una arrobar abans (a windows)
        fileDB = "";

        long length1 = 0;

        if (file1.Exists)
        {
            length1 = file1.Length;
        }
        long length2 = 0;

        if (file2.Exists)
        {
            length2 = file2.Length;
        }

        if (length1 == 0 && length2 == 0)
        {
            new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("Error. Cannot find database."));
        }
        else if (length1 > length2)
        {
            fileDB = databaseURL;
        }
        else
        {
            fileDB = databaseTempURL;
        }

        fc = new Gtk.FileChooserDialog(Catalog.GetString("Copy database to:"),
                                       preferences_win,
                                       FileChooserAction.SelectFolder,
                                       Catalog.GetString("Cancel"), ResponseType.Cancel,
                                       Catalog.GetString("Copy"), ResponseType.Accept
                                       );

        if (fc.Run() == (int)ResponseType.Accept)
        {
            //if multimedia_and_encoder, then copy the folder. If not checked, then copy only the db file
            if (check_backup_multimedia_and_encoder.Active)
            {
                fileCopy = fc.Filename + Path.DirectorySeparatorChar + "chronojump";
            }
            else
            {
                fileCopy = fc.Filename + Path.DirectorySeparatorChar + "chronojump_copy.db";
            }

            try {
                fc.Hide();

                bool exists = false;
                if (check_backup_multimedia_and_encoder.Active)
                {
                    if (Directory.Exists(fileCopy))
                    {
                        LogB.Information(string.Format("Directory {0} exists, created at {1}",
                                                       fileCopy, Directory.GetCreationTime(fileCopy)));
                        exists = true;
                    }
                }
                else
                {
                    if (File.Exists(fileCopy))
                    {
                        LogB.Information(string.Format("File {0} exists with attributes {1}, created at {2}",
                                                       fileCopy, File.GetAttributes(fileCopy), File.GetCreationTime(fileCopy)));
                        exists = true;
                    }
                }

                if (exists)
                {
                    LogB.Information("Overwrite...");
                    ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString("Are you sure you want to overwrite: "), "", fileCopy);
                    confirmWin.Button_accept.Clicked += new EventHandler(on_overwrite_file_accepted);
                }
                else
                {
                    //if multimedia_and_encoder, then copy the folder. If not checked, then copy only the db file
                    if (check_backup_multimedia_and_encoder.Active)
                    {
                        thread = new Thread(new ThreadStart(copyRecursive));
                        GLib.Idle.Add(new GLib.IdleHandler(PulseGTK));

                        backup_doing_sensitive_start_end(true);

                        LogB.ThreadStart();
                        thread.Start();
                    }
                    else
                    {
                        File.Copy(fileDB, fileCopy);

                        string myString = string.Format(Catalog.GetString("Copied to {0}"), fileCopy);
                        new DialogMessage(Constants.MessageTypes.INFO, myString);
                    }
                }
            }
            catch {
                string myString = string.Format(Catalog.GetString("Cannot copy to {0} "), fileCopy);
                new DialogMessage(Constants.MessageTypes.WARNING, myString);
            }
        }
        else
        {
            fc.Hide();
            return;
        }

        //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
        fc.Destroy();
    }
Ejemplo n.º 34
0
        protected void OnButtonSaveClicked(object sender, EventArgs e)
        {
            TreePath sel = iconviewFiles.SelectedItems [0];
            TreeIter iter;
            FilesStore.GetIter (out iter, sel);

            FileChooserDialog fc =
                new FileChooserDialog ("Укажите путь для сохранения файла",
                                       (Gtk.Window)this.Toplevel,
                                       FileChooserAction.Save,
                                       "Отмена", ResponseType.Cancel,
                                       "Сохранить", ResponseType.Accept);

            fc.CurrentName = (string)FilesStore.GetValue (iter, (int)FilesCol.name);
            fc.Show ();
            if (fc.Run () == (int)ResponseType.Accept) {
                fc.Hide ();
                logger.Info ("Сохраняем файл на диск...");
                byte[] file = (byte[])FilesStore.GetValue (iter, (int)FilesCol.file);
                if (file == null) {
                    file = LoadFileFromDB ((int)FilesStore.GetValue (iter, (int)FilesCol.id));
                }
                System.IO.File.WriteAllBytes (fc.Filename, file);
            }
            fc.Destroy ();
            logger.Info ("Ок");
        }
Ejemplo n.º 35
0
        protected virtual void OnOpenActivated(object sender, System.EventArgs e)
        {
            FileFilter torrentFilter = new FileFilter ();
            FileFilter allFilter = new FileFilter ();
            FileChooserDialog fileChooser = new FileChooserDialog (_("Open torrent(s)"), this, FileChooserAction.Open, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Open, ResponseType.Accept);

            torrentFilter.Name = _("Torrent files");
            torrentFilter.AddPattern ("*.torrent");

            allFilter.Name = _("All files");
            allFilter.AddPattern ("*.*");

            fileChooser.AddFilter (torrentFilter);
            fileChooser.AddFilter (allFilter);

            fileChooser.SelectMultiple=true;
            ResponseType result = (ResponseType) fileChooser.Run ();
            fileChooser.Hide ();

            if (result == ResponseType.Accept) {
                logger.Debug ("Open torrent dialog response recieved");
                foreach (String fileName in fileChooser.Filenames)
                    LoadTorrent (fileName);
            }

            fileChooser.Destroy ();
        }
Ejemplo n.º 36
0
        protected void OnButtonLoadImageClicked(object sender, EventArgs e)
        {
            FileChooserDialog Chooser = new FileChooserDialog("Выберите svg для загрузки...",
                this,
                FileChooserAction.Open,
                "Отмена", ResponseType.Cancel,
                "Загрузить", ResponseType.Accept );

            FileFilter Filter = new FileFilter();
            Filter.Name = "SVG изображение";
            Filter.AddMimeType("image/svg+xml");
            Filter.AddPattern("*.svg");
            Chooser.AddFilter(Filter);

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

            if((ResponseType) Chooser.Run () == ResponseType.Accept)
            {
                Chooser.Hide();
                MainClass.StatusMessage("Загрузка изображения куба...");
                if(entryName.Text == "")
                {
                    entryName.Text = System.IO.Path.GetFileNameWithoutExtension(Chooser.Filename);
                }
                using (FileStream fs = new FileStream(Chooser.Filename, FileMode.Open, FileAccess.Read))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        fs.CopyTo(ms);
                        ImageFile = ms.ToArray();
                    }
                }
                ImageChanged = true;
                drawCube.QueueDraw();
                MainClass.StatusMessage("Ok");
            }
            Chooser.Destroy ();
            TestCanSave();
        }
Ejemplo n.º 37
0
        protected virtual void OnOpenButtonClicked(object sender, System.EventArgs e)
        {
            FileChooserDialog dlg = null;
            try {
                dlg = new FileChooserDialog (Catalog.GetString ("Open Map Description File"), null, FileChooserAction.Open, Catalog.GetString ("Cancel"), ResponseType.Cancel, Catalog.GetString ("Open"), ResponseType.Accept);
                //dlg.SetCurrentFolder (m_conf.DataDirectory);
                FileFilter filter = new FileFilter ();
                filter.Name = Catalog.GetString("OCM Map Files");
                filter.AddPattern ("*.xml");
                dlg.AddFilter (filter);

                if (dlg.Run () == (int)ResponseType.Accept) {
                    dlg.Hide ();
                    m_maps.AddRange(MapManager.GetMapsFromFile(dlg.Filename));
                    ReloadMaps();
                    dlg.Destroy ();
                } else {
                    dlg.Hide ();
                    dlg.Destroy ();
                }
            } catch (Exception exception) {
                OCMApp.ShowException(exception);
                if (dlg != null) {
                    dlg.Hide();
                    dlg.Destroy();
                }
            }
        }
Ejemplo n.º 38
0
        public void OnSaveMenuItemActivated(object o, EventArgs args)
        {
            Gtk.FileChooserDialog FCD = new Gtk.FileChooserDialog("Save...", MainWindow, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);
            FCD.CurrentName = FileNameEntry.Text;
            FCD.DoOverwriteConfirmation = true;

            int Response = FCD.Run();
            FCD.Hide();

            // TODO wrap this in try catch block to handle FS errors!!
            if (Response == (int)ResponseType.Accept)
            {
                FileStream file = new FileStream(FCD.Filename, FileMode.OpenOrCreate, FileAccess.Write);

                /* Clear the file pre writing or we end up with weird output. */
                file.SetLength(0);
                file.Flush();

                StreamWriter writer = new StreamWriter(file);

                calculateSHCoefficients();

                /* Write comments out to the file before the array. */
                writer.Write(CommentView.Buffer.Text + "\n");

                // Write values being used out to another commend block after the specified one!
                writer.Write("/* Generated by FreeTherm " + VERSION + " using the following parameters:\n");
                writer.Write(" *\n");
                writer.Write(" * Bias Resistor:\n");
                writer.Write(" * Value: " + biasRes + "\n");
                writer.Write(" *\n");
                writer.Write(" * Sensor Sample Points:\n");
                writer.Write(" * Temp Low  : " + lowTemp  + "\n");
                writer.Write(" * Temp Mid  : " + midTemp  + "\n");
                writer.Write(" * Temp High : " + highTemp + "\n");
                writer.Write(" * Res Low   : " + lowRes   + "\n");
                writer.Write(" * Res Mid   : " + midRes   + "\n");
                writer.Write(" * Res High  : " + highRes  + "\n");
                writer.Write(" *\n");
                writer.Write(" * Temp Units:\n");
                writer.Write(" * Input Temp Scale: " + inputTempScale + "\n");
                writer.Write(" * Output Temp Scale: " + outputTempScale + "\n");
                writer.Write(" *\n");
                writer.Write(" */\n\n"); // Close comment block

                /* First line of the code itself is composed of different parts. Element count
                 * should be included as verification that the array is correctly sized. */
                writer.WriteLine(KeyWords + DataType + ArrayNameEntry.Text + "[" + Elements.ToString() + "] = {");

                /* First value is always max due to maths involved. */
                writer.Write(Ceiling.ToString(DataFormat));

                /* Loop is one short because the first one will always be NAN and is a special case. */
                for (int loop = 1; loop < Elements; loop++)
                {
                    /* Calculate the resistance. */
                    double res = biasRes / ( ( 1.0 / ( (double) loop / (double) Elements) ) - 1.0 );

                    /* And the temperature */
                    double y = Math.Log(res);
                    double yc = Math.Pow(y, 3);
                    double temp = 1 / (A + B * y + C * yc);

            //					if ((loop - 1) % 128 == 0) {
            //						dWriteLine("Input temp is : " + temp.ToString());
            //					}

                    /* Convert to output scale if required */
                    if (outputTempScale == TempScale.Celcius) {
                        temp = temp - KelvinOffset;
                    } else if (outputTempScale == TempScale.Fahrenheit) {
                        temp = (((temp - KelvinOffset) * 9) / 5) + FahrenheitOffset;
                    } else if (outputTempScale == TempScale.Kelvin) {
                        // Do nothing, default is Kelvin
                    } else {
                        Console.WriteLine("This line should never be printed!"); // To alert the user to the issue
                        writer.WriteLine("This line should never be printed!"); // To break the file for compilation
                        // return; uncomment once finally block installed. // To fail fast
                    }

            //					if ((loop - 1) % 128 == 0) {
            //						dWriteLine("Output temp is : " + temp.ToString());
            //					}

                    /* Multiply and Shift. */
                    temp *= outputFactor;
                    temp += outputOffset;

            //					if ((loop - 1) % 128 == 0) {
            //						dWriteLine("Translated temp is : " + temp.ToString());
            //					}

                    /* Cap the output at the ceiling and floor values. */
                    if (temp > Ceiling) {
                        temp = Ceiling;
                    } else if (temp < Floor) {
                        temp = Floor;
                    }

            //					if ((loop - 1) % 128 == 0) {
            //						dWriteLine("RangeLimited temp is : " + temp.ToString());
            //					}

                    /* Decide whether to hit enter or space out. */
                    string filler = " ";
                    if (loop % elementsPerLine == 0) {
                        filler = EOL;

                    }

                    /* Write the comma, newline, and value out to the file. */
                    writer.Write("," + filler + temp.ToString(DataFormat));
                }

                /* Close the array. */
                writer.WriteLine("\n};");

                /* Tidy up our file writer. TODO this should be in a finally block with appropriate null checks etc */
                writer.Flush();
                writer.Close();
            }
            FCD.Destroy();
        }
Ejemplo n.º 39
0
        public void on_open_activate(System.Object b, EventArgs e)
        {
            statusbar.Pop (gameStatusbarId);

                        FileChooserDialog fd = new FileChooserDialog (Catalog.GetString ("Open Game"), csboardWindow, FileChooserAction.Open);

            fd.AddButton (Stock.Close, (int) ResponseType.Close);
                        fd.AddButton (Stock.Open, (int) ResponseType.Ok);

                        if (fd.Run () == (int)ResponseType.Ok) {
                                control.OpenGame (fd.Filename);
                                control.SaveGame(App.session.Filename);
                                }
                        fd.Hide ();
                        fd.Dispose ();
        }
Ejemplo n.º 40
0
    protected void checkFile(string formatFile)
    {
        string exportString = "";

        if (formatFile == "report")
        {
            exportString = Catalog.GetString("Save report as...");
        }
        else
        {
            exportString = Catalog.GetString("Export session in format " + formatFile);
        }


        Gtk.FileChooserDialog fc =
            new Gtk.FileChooserDialog(exportString,
                                      app1,
                                      FileChooserAction.Save,
                                      Catalog.GetString("Cancel"), ResponseType.Cancel,
                                      Catalog.GetString("Export"), ResponseType.Accept
                                      );

        //set default name
        string nameString = mySession.Name + "_" + mySession.DateShortAsSQL;

        if (formatFile == "report")
        {
            if (UtilAll.IsWindows())
            {
                nameString += ".htm";
            }
            else
            {
                nameString += ".html";
            }
        }
        else
        {
            nameString += ".csv";
        }

        fc.CurrentName = nameString;

        if (fc.Run() == (int)ResponseType.Accept)
        {
            fileName = fc.Filename;
            if (formatFile == "report")
            {
                //add ".html" if needed, remember that on windows should be .htm
                fileName = addHtmlIfNeeded(fileName);
            }
            else
            {
                //add ".csv" if needed
                fileName = Util.AddCsvIfNeeded(fileName);
            }
            try {
                if (File.Exists(fileName))
                {
                    LogB.Warning(string.Format("File {0} exists with attributes {1}, created at {2}",
                                               fileName, File.GetAttributes(fileName), File.GetCreationTime(fileName)));
                    LogB.Information("Overwrite...");
                    ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString("Are you sure you want to overwrite file: "), "", fileName);
                    confirmWin.Button_accept.Clicked += new EventHandler(on_overwrite_file_accepted);
                }
                else
                {
                    writer = File.CreateText(fileName);
                    getData();
                    printData();
                    closeWriter();

                    string myString = string.Format(Catalog.GetString("Saved to {0}"), fileName) + spreadsheetString;
                    new DialogMessage(Constants.MessageTypes.INFO, myString);
                }
            }
            catch {
                string myString = string.Format(Catalog.GetString("Cannot export to file {0} "), fileName);
                new DialogMessage(Constants.MessageTypes.WARNING, myString);
            }
        }
        else
        {
            LogB.Information("cancelled");
            //report does not currently send the appBar reference
            if (formatFile != "report")
            {
                new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Cancelled."));
            }
            fc.Hide();
            return;
        }

        //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
        fc.Destroy();

        return;
    }