Пример #1
0
        private void SelectAtomObject_Do(string mediaType, MediaItemViewModel file, bool asAnswer)
        {
            var index = CurrentPosition;

            if (index == -1)
            {
                index = Count - 1;
            }

            OwnerDocument.BeginChange();

            try
            {
                if (asAnswer)
                {
                    if (!_isComplex)
                    {
                        AddMarker_Executed(null);
                        index = Count - 1;
                    }
                }
                else if (string.IsNullOrWhiteSpace(this[index].Model.Text))
                {
                    RemoveAt(index--);
                }

                var atom = new AtomViewModel(new Atom {
                    Type = mediaType, Text = ""
                });
                Insert(index + 1, atom);

                SIDocument.SetLink(atom.Model, file.Model.Name);
                OwnerDocument.ActiveItem = null;
            }
            catch (Exception exc)
            {
                OwnerDocument.OnError(exc);
            }
            finally
            {
                OwnerDocument.CommitChange();
            }
        }
Пример #2
0
        private void AddAtomObject(string mediaType, bool asAnswer)
        {
            QDocument document;

            try
            {
                document = OwnerDocument;
            }
            catch (Exception exc)
            {
                PlatformManager.Instance.ShowErrorMessage(exc.Message);
                return;
            }

            if (document == null)
            {
                return;
            }

            var collection = document.Images;

            if (mediaType == AtomTypes.Audio)
            {
                collection = document.Audio;
            }
            else if (mediaType == AtomTypes.Video)
            {
                collection = document.Video;
            }

            var was = collection.Files.Count;

            document.BeginChange();

            try
            {
                collection.AddItem.Execute(null);

                if (!collection.HasPendingChanges)
                {
                    return;
                }

                if (was == collection.Files.Count)
                {
                    return;
                }

                var index = CurrentPosition;
                if (index == -1 || index >= Count)
                {
                    if (Count == 0)
                    {
                        return;
                    }

                    index = Count - 1;
                }

                if (asAnswer)
                {
                    if (!_isComplex)
                    {
                        AddMarker_Executed(null);
                        index = Count - 1;
                    }
                }
                else if (string.IsNullOrWhiteSpace(this[index].Model.Text) && this[index].Model.Type != AtomTypes.Marker)
                {
                    RemoveAt(index--);
                }

                var atom = new AtomViewModel(new Atom {
                    Type = mediaType, Text = ""
                });
                Insert(index + 1, atom);

                var last = collection.Files.LastOrDefault();
                if (last != null)
                {
                    SIDocument.SetLink(atom.Model, last.Model.Name);
                }

                document.ActiveItem = null;
            }
            catch (Exception exc)
            {
                document.OnError(exc);
            }
            finally
            {
                document.CommitChange();
            }
        }