示例#1
0
        void PopulateTemplate(string fileName, string savePath, int targetColumn)
        {
            LanguageFile          langfile = targetColumn == 1 ? LanguageFile1 : LanguageFile2;
            ICollectionView       view     = (ICollectionView)LanguageGrid.ItemsSource;
            IList <LanguageEntry> entries  = (IList <LanguageEntry>)view.SourceCollection;
            string tmp;

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GreenshotLanguageEditor." + fileName)) {
                using (StreamReader reader = new StreamReader(stream)) {
                    tmp = reader.ReadToEnd();
                    foreach (LanguageEntry e in entries)
                    {
                        string entryString = targetColumn == 1 ? e.Entry1 : e.Entry2;
                        tmp = tmp.Replace("${" + e.Key + "}", entryString);
                    }
                    tmp = tmp.Replace("${lang}", extractIetfLanguageCode(savePath));
                }
            }
            FileInfo   fi = new FileInfo(savePath.Replace(".xml", fileName.Substring(fileName.IndexOf("."))));
            FileStream fs = fi.Open(FileMode.OpenOrCreate);

            byte[] barr = Encoding.GetEncoding("UTF-8").GetBytes(tmp);
            fs.Write(barr, 0, barr.Length);
            fs.Close();
        }
示例#2
0
        private void languageComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int          targetColumn = GetTargetColumn((Control)sender);
            LanguageFile file         = (LanguageFile)((ComboBox)sender).SelectedItem;

            if ((targetColumn == 1 && file.Equals(LanguageFile1)) || (targetColumn == 2 && file.Equals(LanguageFile2)))
            {
                // nothing changed
                return;
            }
            if ((targetColumn == 1 && unsavedChangesInLanguage1) || (targetColumn == 2 && unsavedChangesInLanguage2))
            {
                MessageBoxResult res = MessageBox.Show("Do you really want to switch language? Unsaved changes will be lost.", "Confirm language switch", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel, MessageBoxOptions.None);
                if (res != MessageBoxResult.OK)
                {
                    // cancelled by user
                    ((ComboBox)sender).SelectedItem = (targetColumn == 1) ? LanguageFile1 : LanguageFile2;
                    return;
                }
            }
            if (targetColumn == 1)
            {
                LanguageFile1 = file;
            }
            else if (targetColumn == 2)
            {
                LanguageFile2 = file;
            }
            PopulateColumn(file, targetColumn);
            // TODO Language resources does not implement notifycollectionwhatever interface. does not work when keys are removed
        }
示例#3
0
        private void saveButtonClicked(object sender, RoutedEventArgs e)
        {
            int          targetColumn = GetTargetColumn((Control)sender);
            LanguageFile editedFile   = (LanguageFile)(targetColumn == 1 ? language1ComboBox.SelectedItem : language2ComboBox.SelectedItem);

            CreateXML(editedFile.FilePath, targetColumn);

            if (editedFile.FileName.Contains("website"))
            {
                CreateWebsitePart(editedFile.FilePath, targetColumn);
            }
            else if (editedFile.FileName.Contains("installer"))
            {
                CreateInstallerPart(editedFile.FilePath, targetColumn);
            }

            if (targetColumn == 1)
            {
                unsavedChangesInLanguage1 = false;
            }
            else if (targetColumn == 2)
            {
                unsavedChangesInLanguage2 = false;
            }
        }
示例#4
0
        private void PopulateColumn(LanguageFile languageFile, int columnIndex)
        {
            ClearColumn(columnIndex);
            IDictionary <string, string> resources = GreenshotLanguage.ReadLanguageFile(languageFile);

            foreach (string key in resources.Keys)
            {
                LanguageEntry entry = GetOrCreateLanguageEntry(key);
                if (columnIndex == 1)
                {
                    entry.Entry1 = resources[key];
                }
                else if (columnIndex == 2)
                {
                    entry.Entry2 = resources[key];
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Argument columnIndex must be either 1 or 2");
                }
            }
            if (columnIndex == 1)
            {
                unsavedChangesInLanguage1 = false;
            }
            if (columnIndex == 2)
            {
                unsavedChangesInLanguage2 = false;
            }
        }
示例#5
0
 public static IDictionary <string, string> ReadLanguageFile(LanguageFile languageFile)
 {
     return((from resource in XDocument.Load(languageFile.FilePath).Descendants("resource")
             where !string.IsNullOrEmpty(resource.Value)
             select new {
         Name = (string)resource.Attribute("name"),
         Text = resource.Value.Trim()
     }
             ).ToDictionary(item => item.Name, item => item.Text));
 }
示例#6
0
        private void cancelButtonClicked(object sender, RoutedEventArgs e)
        {
            int targetColumn = GetTargetColumn((Control)sender);

            if ((targetColumn == 1 && unsavedChangesInLanguage1) || (targetColumn == 2 && unsavedChangesInLanguage2))
            {
                MessageBoxResult res = MessageBox.Show("Do you really want to reset this column? Unsaved changes will be lost.", "Confirm language reset", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel, MessageBoxOptions.None);
                if (res == MessageBoxResult.OK)
                {
                    LanguageFile file = (LanguageFile)(targetColumn == 1 ? language1ComboBox.SelectedItem : language2ComboBox.SelectedItem);
                    PopulateColumn(file, targetColumn);
                }
            }
        }
示例#7
0
        public void CreateXML(string savePath, int targetColumn)
        {
            LanguageFile          langfile = targetColumn == 1 ? LanguageFile1 : LanguageFile2;
            ICollectionView       view     = (ICollectionView)LanguageGrid.ItemsSource;
            IList <LanguageEntry> entries  = (IList <LanguageEntry>)view.SourceCollection;
            List <LanguageEntry>  sortList = new List <LanguageEntry>(entries);

            sortList.Sort(compareEntryKeys);

            using (XmlTextWriter xmlWriter = new XmlTextWriter(savePath, Encoding.UTF8)) {
                xmlWriter.Formatting  = Formatting.Indented;
                xmlWriter.Indentation = 1;
                xmlWriter.IndentChar  = '\t';
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("language");
                xmlWriter.WriteAttributeString("description", langfile.Description);
                xmlWriter.WriteAttributeString("ietf", langfile.IETF);
                xmlWriter.WriteAttributeString("version", langfile.Version);
                xmlWriter.WriteAttributeString("languagegroup", langfile.Languagegroup);
                xmlWriter.WriteStartElement("resources");
                foreach (LanguageEntry entry in sortList)
                {
                    string entryValue = (targetColumn == 1) ? entry.Entry1 : entry.Entry2;
                    if (!String.IsNullOrWhiteSpace(entryValue) && !String.IsNullOrWhiteSpace(entry.Key))
                    {
                        xmlWriter.WriteStartElement("resource");
                        xmlWriter.WriteAttributeString("name", entry.Key);
                        xmlWriter.WriteString(entryValue);
                        xmlWriter.WriteEndElement();
                    }
                }
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndDocument();
            }
        }
示例#8
0
        private void newButtonClicked(object sender, RoutedEventArgs e)
        {
            int targetColumn = GetTargetColumn((Control)sender);

            if ((targetColumn == 1 && unsavedChangesInLanguage1) || (targetColumn == 2 && unsavedChangesInLanguage2))
            {
                MessageBoxResult res = MessageBox.Show("Do you really want to discard this column? Unsaved changes will be lost.", "Confirm new language file creation", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel, MessageBoxOptions.None);
                if (res != MessageBoxResult.OK)
                {
                    return;
                }
            }
            LanguageFile newLang = new LanguageFile();

            newLang.FileDir = languagePath;
            new MetaEditorWindow(newLang).ShowDialog();
            if (newLang.FileName != null && newLang.FileName.Length > 0)
            {
                ClearColumn(targetColumn);
                CreateXML(newLang.FilePath, targetColumn);
                LanguageFiles.Add(newLang);

                LanguageFiles = LanguageFiles.OrderBy(f => f.FileName).ToList();
                if (targetColumn == 1)
                {
                    LanguageFile1 = newLang;
                    language1ComboBox.SelectedItem = newLang;
                }
                else
                {
                    LanguageFile2 = newLang;
                    language2ComboBox.SelectedItem = newLang;
                }
                PopulateColumn(newLang, targetColumn);
            }
        }
示例#9
0
 public MetaEditorWindow(LanguageFile langFile)
 {
     InitializeComponent();
     this.LangFile = langFile;
     this.Closing += new System.ComponentModel.CancelEventHandler(OnClosing);
 }