示例#1
0
 private void closeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // dgvTranslations.Rows.Clear();
     _modelTranslations = null;
     _jsonFilename = string.Empty;
     btnSave.Enabled = false;
 }
示例#2
0
 private void closeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // dgvTranslations.Rows.Clear();
     _modelTranslations = null;
     _jsonFilename      = string.Empty;
     btnSave.Enabled    = false;
 }
示例#3
0
        private ModelTranslations LoadJsonCulturesFile()
        {
            OpenFileDialog openJsonFileDialog = new OpenFileDialog();

            // openJsonFileDialog.InitialDirectory = "c:\\";
            // We don't set initial directory, so it is the same as last operation...
            openJsonFileDialog.Filter           = "json files (*.json)|*.json|All files (*.*)|*.*";
            openJsonFileDialog.FilterIndex      = 1;
            openJsonFileDialog.RestoreDirectory = true;

            if (openJsonFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    StreamReader myStream = null;
                    if ((myStream = new StreamReader(File.OpenRead(openJsonFileDialog.FileName))) != null)
                    {
                        _jsonFilename = openJsonFileDialog.FileName;
                        using (myStream)
                        {
                            JsonSerializer    deserializer = new JsonSerializer();
                            ModelTranslations cultures     = (ModelTranslations)deserializer.Deserialize(myStream, typeof(ModelTranslations));
                            return(cultures);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read json file from disk. Original error: " + ex.Message);
                }
            }
            return(null);
        }
示例#4
0
 private void closeToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     _modelTranslations = null;
     cbCultures.SelectedItem = null;
     cbCultures.Items.Clear();
     cbCultures.Enabled = false;
     btnSave.Enabled = false;
     dgvTranslations.DataSource = null;
 }
示例#5
0
 private void closeToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     if (ConfirmCloseFile())
     {
         _modelTranslations      = null;
         cbCultures.SelectedItem = null;
         cbCultures.Items.Clear();
         cbCultures.Enabled         = false;
         btnSave.Enabled            = false;
         dgvTranslations.DataSource = null;
     }
 }
示例#6
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //load cultures
     _modelTranslations = LoadJsonCulturesFile();
     //Set up the UI
     if (_modelTranslations != null && _modelTranslations.cultures != null)
     {
         cbCultures.Enabled = true;
         cbCultures.Items.Clear();
         foreach (var culture in _modelTranslations.cultures)
         {
             cbCultures.Items.Add(culture.name);
         }
         cbCultures.SelectedIndex = 0;
         btnSave.Enabled          = true;
     }
 }
示例#7
0
 private void SaveJsonCulturesFile(ModelTranslations translations, string filename)
 {
     try
     {
         using (StreamWriter file = File.CreateText(filename))
         {
             JsonSerializer serializer = new JsonSerializer();
             serializer.Formatting        = Formatting.Indented;
             serializer.NullValueHandling = NullValueHandling.Ignore;
             serializer.Serialize(file, translations);
             _unsavedChanges = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: Could not save json file to disk. Original error: " + ex.Message);
     }
 }
示例#8
0
 private void SaveJsonCulturesFile(ModelTranslations translations, string filename)
 {
     try
     {
         using (StreamWriter file = File.CreateText(filename))
         {
             JsonSerializer serializer = new JsonSerializer();
             serializer.Formatting = Formatting.Indented;
             serializer.NullValueHandling = NullValueHandling.Ignore;
             serializer.Serialize(file, translations);
             _unsavedChanges = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: Could not save json file to disk. Original error: " + ex.Message);
     }
 }
示例#9
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //load cultures
     _modelTranslations = LoadJsonCulturesFile();
     //Set up the UI
     if (_modelTranslations != null && _modelTranslations.cultures != null)
     {
         cbCultures.Enabled = true;
         cbCultures.Items.Clear();
         foreach (var culture in _modelTranslations.cultures)
         {
             cbCultures.Items.Add(culture.name);
         }
         cbCultures.SelectedIndex = 0;
         btnSave.Enabled = true;
     }
 }