aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/ProcessParametersTablesGroupsViewVM.cs
blob: 2ce13ffef3b57fe5483e4f577f3756519abb8710 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.MachineStudio.Common.Notifications;

namespace Tango.MachineStudio.DB.ViewModels
{
    public class ProcessParametersTablesGroupsViewVM : DbTableViewModel<ProcessParametersTablesGroup>
    {
        public ProcessParametersTablesGroupsViewVM(INotificationProvider notification) : base(notification)
        {
            
        }

        protected override void OnBeforeEntitySave(DialogOpenMode mode, ProcessParametersTablesGroup entity)
        {
            entity.SaveDate = DateTime.UtcNow;

            if (entity.Rml != null && entity.Active)
            {
                foreach (var group in entity.Rml.ProcessParametersTablesGroups.Where(x => x != entity))
                {
                    group.Active = false;
                }
            }

            base.OnBeforeEntitySave(mode, entity);
        }
    }
}
span class="w"> get; set; } public TextDocument Document { get; set; } public TextRunProperties GlobalTextRunProperties { get; set; } public override TextRun GetTextRun(int textSourceCharacterIndex) { try { foreach (VisualLineElement element in VisualLine.Elements) { if (textSourceCharacterIndex >= element.VisualColumn && textSourceCharacterIndex < element.VisualColumn + element.VisualLength) { int relativeOffset = textSourceCharacterIndex - element.VisualColumn; TextRun run = element.CreateTextRun(textSourceCharacterIndex, this); if (run == null) throw new ArgumentNullException(element.GetType().Name + ".CreateTextRun"); if (run.Length == 0) throw new ArgumentException("The returned TextRun must not have length 0.", element.GetType().Name + ".Length"); if (relativeOffset + run.Length > element.VisualLength) throw new ArgumentException("The returned TextRun is too long.", element.GetType().Name + ".CreateTextRun"); InlineObjectRun inlineRun = run as InlineObjectRun; if (inlineRun != null) { inlineRun.VisualLine = VisualLine; VisualLine.hasInlineObjects = true; TextView.AddInlineObject(inlineRun); } return run; } } if (TextView.Options.ShowEndOfLine && textSourceCharacterIndex == VisualLine.VisualLength) { return CreateTextRunForNewLine(); } return new TextEndOfParagraph(1); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); throw; } } TextRun CreateTextRunForNewLine() { string newlineText = ""; DocumentLine lastDocumentLine = VisualLine.LastDocumentLine; if (lastDocumentLine.DelimiterLength == 2) { newlineText = "¶"; } else if (lastDocumentLine.DelimiterLength == 1) { char newlineChar = Document.GetCharAt(lastDocumentLine.Offset + lastDocumentLine.Length); if (newlineChar == '\r') newlineText = "\\r"; else if (newlineChar == '\n') newlineText = "\\n"; else newlineText = "?"; } return new FormattedTextRun(new FormattedTextElement(TextView.cachedElements.GetTextForNonPrintableCharacter(newlineText, this), 0), GlobalTextRunProperties); } public override TextSpan<CultureSpecificCharacterBufferRange> GetPrecedingText(int textSourceCharacterIndexLimit) { try { foreach (VisualLineElement element in VisualLine.Elements) { if (textSourceCharacterIndexLimit > element.VisualColumn && textSourceCharacterIndexLimit <= element.VisualColumn + element.VisualLength) { TextSpan<CultureSpecificCharacterBufferRange> span = element.GetPrecedingText(textSourceCharacterIndexLimit, this); if (span == null) break; int relativeOffset = textSourceCharacterIndexLimit - element.VisualColumn; if (span.Length > relativeOffset) throw new ArgumentException("The returned TextSpan is too long.", element.GetType().Name + ".GetPrecedingText"); return span; } } CharacterBufferRange empty = CharacterBufferRange.Empty; return new TextSpan<CultureSpecificCharacterBufferRange>(empty.Length, new CultureSpecificCharacterBufferRange(null, empty)); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); throw; } } public override int GetTextEffectCharacterIndexFromTextSourceCharacterIndex(int textSourceCharacterIndex) { throw new NotSupportedException(); } string cachedString; int cachedStringOffset; public StringSegment GetText(int offset, int length) { if (cachedString != null) { if (offset >= cachedStringOffset && offset + length <= cachedStringOffset + cachedString.Length) { return new StringSegment(cachedString, offset - cachedStringOffset, length); } } cachedStringOffset = offset; return new StringSegment(cachedString = this.Document.GetText(offset, length)); } } }