/// <summary>
        /// Keep the Actual selected logitems then refresh the view and reset the selected log item
        /// </summary>
        public void RefreshView()
        {
            EntryDiffViewModel l = SelectedItem;

            SelectedItem = null;
            if (LogView != null)
            {
                LogView.Refresh();
                RaisePropertyChanged(() => LogView);

                // Attempt to restore selected item if there was one before
                // and if it is not part of the filtered set of items
                // (ScrollItemBehaviour may scroll it into view when filter is applied)
                if (l != null)
                {
                    if (OnFilterLogItems(l))
                    {
                        SelectedItem = l;
                    }
                }
            }

            UpdateFilteredCounters(LogView);

            CommandManager.InvalidateRequerySuggested();
        }
 /// <summary>
 /// This method can be invoked to tell parent that details in this item have changed
 /// and may need synchronization with other views of the same detail.
 /// </summary>
 /// <param name="thisEntryHasChanged"></param>
 void IEntryDiffViewModelParent.UpdateDiffEntry(EntryDiffViewModel thisEntryHasChanged)
 {
     SelectedItemBuffer = new EntryDiffViewModel(SelectedItem)
     {
         Parent = null
     };
     IsDirty = true;
 }
예제 #3
0
        /// <summary>
        /// Method is executed when user starts to edit a cell in the gridview.
        /// </summary>
        void IEditableObject.BeginEdit()
        {
            if (mEdit == true)
            {
                return;
            }

            mEdit      = true;
            backupCopy = MemberwiseClone() as EntryDiffViewModel;
        }
예제 #4
0
        /// <summary>
        /// Copy class constructor
        /// </summary>
        /// <param name="copyThis"></param>
        public EntryDiffViewModel(EntryDiffViewModel copyThis)
            : this()
        {
            if (copyThis == null)
            {
                return;
            }

            Parent           = null;
            mTranslationDiff = new EntryDiffModel(copyThis.mTranslationDiff);
            TargetRowId      = copyThis.TargetRowId;
            SourceRowId      = copyThis.SourceRowId;
        }
예제 #5
0
        /// <summary>
        /// Method is executed when user ends editing a cell in the gridview.
        /// (User has pressed AltGR+Enter to confirm change)
        /// </summary>
        void IEditableObject.EndEdit()
        {
            if (mEdit == false)
            {
                return;
            }

            mEdit      = false;
            backupCopy = null;

            if (Parent != null)
            {
                Parent.UpdateDiffEntry(this);  // Tell parent that this entry has been updated
            }
        }
        /// <summary>
        /// Loads a source and target file from the file system into an internal
        /// collection such that a 'diff' on each string can be computed. A 'diff'
        /// is in this context an answer to the question:
        /// 1> Whether all source language strings can be mapped into a target language string
        /// 2> Whether all target language strings can be mapped into a source language string
        /// 3> Whether all source to target language string mappings have been verified by a translator (native speaker)
        /// </summary>
        /// <param name="sourcePath"></param>
        /// <param name="targetPath"></param>
        /// <param name="bLoadTarget"></param>
        public void LoadFilesForDiff(string sourcePath,
                                     string targetPath,
                                     bool bLoadTarget = true,
                                     CancellationTokenSource cancelTokenSource = null)
        {
            Dictionary <string, EntryDiffViewModel> dic   = null;
            ObservableCollection <Entry>            items = null;

            try
            {
                var reader     = ServiceContainer.Instance.GetService <IStringFileParseServiceList>();
                var resxReader = reader.Select("RESX");

                if (cancelTokenSource != null)
                {
                    cancelTokenSource.Token.ThrowIfCancellationRequested();
                }

                if (System.IO.File.Exists(sourcePath) == false)
                {
                    throw new Exception(string.Format(Local.Strings.CantAccessFile_Error_Text, sourcePath));
                }

                items = new ObservableCollection <Entry>();

                int iRowId = 0;

                foreach (var item in resxReader.LoadFile(sourcePath, cancelTokenSource))
                {
                    if (cancelTokenSource != null)
                    {
                        cancelTokenSource.Token.ThrowIfCancellationRequested();
                    }

                    items.Add(new Entry(item.Item1, item.Item2, item.Item3));
                }

                // Insert entries from first file into dictionary since we now know the number of entries
                dic = new Dictionary <string, EntryDiffViewModel>(items.Count);
                foreach (var item in items)
                {
                    if (cancelTokenSource != null)
                    {
                        cancelTokenSource.Token.ThrowIfCancellationRequested();
                    }

                    dic.Add(item.KeyString, new EntryDiffViewModel(item.KeyString,
                                                                   item.ValueString,
                                                                   item.CommentString,
                                                                   iRowId,
                                                                   TypeOfDiff.SourceOnly));

                    iRowId++;
                }
            }
            catch
            {
                cancelTokenSource.Cancel();
                throw;
            }

            try
            {
                var resxReader = ServiceContainer.Instance.GetService <IStringFileParseServiceList>().Select("RESX");

                if (cancelTokenSource != null)
                {
                    cancelTokenSource.Token.ThrowIfCancellationRequested();
                }

                // Target file may not exist, yet, so we do not load it but create it from scratch when saving.
                if (bLoadTarget == true)
                {
                    if (System.IO.File.Exists(sourcePath) == false)
                    {
                        throw new Exception(string.Format(LocultApp.Local.Strings.CantAccessFile_Error_Text, targetPath));
                    }

                    int iRowId = 0; // Load strings from target file

                    foreach (var item in resxReader.LoadFile(targetPath, cancelTokenSource))
                    {
                        if (cancelTokenSource != null)
                        {
                            cancelTokenSource.Token.ThrowIfCancellationRequested();
                        }

                        EntryDiffViewModel o;
                        dic.TryGetValue(item.Item1, out o); // Have we seen this key entry before ???

                        // Either construct a new entry or set target entries
                        if (o == null)
                        {
                            // Insert Key, value, comment strings into collection
                            var newItem = new EntryDiffViewModel(item.Item1, item.Item2, item.Item3, iRowId,
                                                                 TypeOfDiff.TargetOnly);
                            dic.Add(item.Item1, newItem);
                        }
                        else
                        {
                            o.SetTargetValueComment(item.Item2, item.Item3);
                        }

                        iRowId++;
                    }
                }

                // Doing it this way to keep GUI and backend thread seperated as long as possible...
                StringCollectionViewModel s = new StringCollectionViewModel(mDocumentBase);
                s.RebuildLogView(dic.Values);

                if (DiffSource != null)
                {
                    mFileSource.Dispose();
                    Interlocked.Exchange(ref mFileSource, null);
                }

                DiffSource = s;
                ////this.DiffSource.SelectAllElements();
            }
            catch (Exception)
            {
                cancelTokenSource.Cancel();
                throw;
            }
        }