ygoe / TxTranslation

Tx Translation & Localisation for .NET and WPF
GNU General Public License v3.0
28 stars 12 forks source link

.txd file is not reloaded when saved with TxEditor #1

Closed maratoss closed 9 years ago

maratoss commented 9 years ago

Hi! Great project :)

I have the problem with updating *.txd file via TxEditor. When i update it via TxEditor, MainWindow.xaml form of project WpfDemo doesn't update. If i do it via any text editor (e.g. notepad++) it works. Could you help me with this problem?

ygoe commented 9 years ago

You did click on the Save button in both cases, and can confirm that your change from TxEditor is reflected in the .txd XML file, right?

maratoss commented 9 years ago

Yes, right. TxEditor does changes in *.txd but despite of it WpfDemo didn't update own GUI.

Seems like that FileWatcher doesn't work properly If you add following code in MainViewModel.cs it works

MainViewModel.cs

...
        private void WriteXmlToFile(XmlDocument xmlDoc, string fileName)
        {
            XmlWriterSettings xws = new XmlWriterSettings();
            xws.Encoding = Encoding.UTF8;
            xws.Indent = true;
            xws.IndentChars = "\t";
            xws.OmitXmlDeclaration = false;
            using (XmlWriter xw = XmlWriter.Create(fileName + ".tmp", xws))
            {
                xmlDoc.Save(xw);
            }

            File.Delete(fileName);
            File.Move(fileName + ".tmp", fileName);
// added code
            using (StreamWriter streamWriter = File.AppendText(fileName))
            {
                streamWriter.Write(' ');
                streamWriter.Flush();
            }
        }
...
ygoe commented 9 years ago

Ah, that could be because another editor writes directly to the file, changing it, whereas TxEditor performs a safe write, renaming it. Maybe the FileSystemWatcher doesn't listen to that. I'll look into it.

maratoss commented 9 years ago

Great, thanks!

ygoe commented 9 years ago

Yep, that was exactly the cause. It's working now. Thanks for your report!