コード例 #1
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 public void sendTextWithoutHistory(MeTLTextBox box, string thisPrivacy)
 {
     sendTextWithoutHistory(box, thisPrivacy, currentSlide);
 }
コード例 #2
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private void textboxLostFocus(object sender, RoutedEventArgs e)
 {
     var box = (MeTLTextBox)sender;
     var currentTag = box.tag();
     ClearAdorners();
     if (currentTag.privacy != Globals.privacy)
     {
         Commands.SendDirtyText.ExecuteAsync(new TargettedDirtyElement(currentSlide, Globals.me, target, currentTag.privacy, currentTag.id));
         currentTag.privacy = privacy;
         box.tag(currentTag);
         Commands.SendTextBox.ExecuteAsync(new TargettedTextBox(currentSlide, Globals.me, target, currentTag.privacy, box));
     }
     myTextBox = null;
     requeryTextCommands();
     if (box.Text.Length == 0)
         Children.Remove(box);
     else
         setAppropriatePrivacyHalo(box);
 }
コード例 #3
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private void textboxGotFocus(object sender, RoutedEventArgs e)
 {
     if (((MeTLTextBox)sender).tag().author != Globals.me) return; //cannot edit other peoples textboxes
     myTextBox = (MeTLTextBox)sender;
     updateTools();
     requeryTextCommands();
     Select(new List<UIElement>());
     originalText = myTextBox.Text;
     Commands.ChangeTextMode.Execute("None");
 }
コード例 #4
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
        public static MeTLTextBox clone(this MeTLTextBox box)
        {
            var newBox = new MeTLTextBox();
            newBox.Text = box.Text;
            newBox.TextAlignment = box.TextAlignment;
            newBox.TextDecorations = box.TextDecorations;
            newBox.FontFamily = box.FontFamily;
            newBox.FontSize = box.FontSize;
            newBox.Foreground = box.Foreground;
            newBox.Background = box.Background;
            newBox.tag(box.tag());
            InkCanvas.SetLeft(newBox, InkCanvas.GetLeft(box));
            InkCanvas.SetTop(newBox, InkCanvas.GetTop(box));

            return newBox;
        }
コード例 #5
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private MeTLTextBox applyDefaultAttributes(MeTLTextBox box)
 {
     box.AcceptsReturn = true;
     box.TextWrapping = TextWrapping.WrapWithOverflow;
     box.GotFocus += textboxGotFocus;
     box.LostFocus += textboxLostFocus;
     box.PreviewTextInput += box_PreviewTextInput;
     box.TextChanged += SendNewText;
     box.IsUndoEnabled = false;
     box.UndoLimit = 0;
     box.BorderThickness = new Thickness(0);
     box.BorderBrush = new SolidColorBrush(Colors.Transparent);
     box.Background = new SolidColorBrush(Colors.Transparent);
     box.Focusable = canEdit && canFocus;
     return box;
 }
コード例 #6
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private bool alreadyHaveThisTextBox(MeTLTextBox box)
 {
     bool result = false;
     Dispatcher.adopt(() =>
     {
         var boxId = box.tag().id;
         var privacy = box.tag().privacy;
         foreach (var text in Children)
             if (text is MeTLTextBox)
                 if (((MeTLTextBox)text).tag().id == boxId && ((MeTLTextBox)text).tag().privacy == privacy) result = true;
     });
     return result;
 }
コード例 #7
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
        public static IEnumerable<Point> getTextPoints(MeTLTextBox text)
        {
            if (text == null) return null;
            var y = GetTop(text);
            var x = GetLeft(text);
            var width = text.FontSize * text.Text.Count();
            var height = (text.Text.Where(l => l.Equals('\n')).Count() + 1) * text.FontSize + 2;
            return new[]
            {
                new Point(x, y),
                new Point(x + width, y),
                new Point(x + width, y + height),
                new Point(x, y + height)
            };

        }
コード例 #8
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private void sendBox(MeTLTextBox box)
 {
     myTextBox = box;
     if(Children.ToList().Where(c => ((MeTLTextBox)c).tag().id == box.tag().id).ToList().Count == 0)
         Children.Add(box);
     box.TextChanged += SendNewText;
     box.PreviewTextInput += box_PreviewTextInput;
     sendTextWithoutHistory(box, box.tag().privacy);
 }
コード例 #9
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
        private void resetTextbox(object obj)
        {
            if (myTextBox == null && GetSelectedElements().Count != 1) return;
            if(myTextBox == null)
                myTextBox = (MeTLTextBox)GetSelectedElements().First();
            var currentTextBox = myTextBox;
            var undoInfo = getInfoOfBox(currentTextBox);
            Action undo = () =>
            {
                ClearAdorners();
                applyStylingTo(currentTextBox, undoInfo);
                sendTextWithoutHistory(currentTextBox, currentTextBox.tag().privacy);

                updateTools();
                
            };
            Action redo = () =>
                              {
                                  ClearAdorners();
                                  resetText(currentTextBox);
                                  updateTools();
                              };
            UndoHistory.Queue(undo, redo);
            redo();
        }
コード例 #10
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private void dirtyTextBoxWithoutHistory(MeTLTextBox box)
 {
     RemovePrivacyStylingFromElement(box);
     if (Children.ToList().Where(c => ((MeTLTextBox)c).tag().id == box.tag().id).ToList().Count != 0)
         Children.Remove(Children.ToList().Where(b => ((MeTLTextBox)b).tag().id == box.tag().id).First());
     Commands.SendDirtyText.ExecuteAsync(new TargettedDirtyElement(currentSlide, box.tag().author, target, box.tag().privacy, box.tag().id));
 }
コード例 #11
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private void removeBox(MeTLTextBox box)
 {
     myTextBox = box;
     dirtyTextBoxWithoutHistory(box);
     myTextBox = null;
 }
コード例 #12
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private static TextInformation getInfoOfBox(MeTLTextBox box)
 {
     var underline = false;
     var strikethrough = false;
     if(box.TextDecorations.Count > 0)
     {
         underline = box.TextDecorations.First().Location.ToString().ToLower() == "underline";
         strikethrough = box.TextDecorations.First().Location.ToString().ToLower() == "strikethrough";
     }
     return new TextInformation
                {
                    Bold = box.FontWeight == FontWeights.Bold,
                    Italics = box.FontStyle == FontStyles.Italic,
                    Size = box.FontSize,
                    Underline = underline,
                    Strikethrough = strikethrough,
                    Family = box.FontFamily,
                    Color = ((SolidColorBrush) box.Foreground).Color
                };
 }
コード例 #13
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private static void applyStylingTo(MeTLTextBox currentTextBox, TextInformation info)
 {
     currentTextBox.FontStyle = info.Italics ? FontStyles.Italic : FontStyles.Normal;
     currentTextBox.FontWeight = info.Bold ? FontWeights.Bold : FontWeights.Normal;
     currentTextBox.TextDecorations = new TextDecorationCollection();
     if(info.Underline)
         currentTextBox.TextDecorations = TextDecorations.Underline;
     else if(info.Strikethrough)
         currentTextBox.TextDecorations= TextDecorations.Strikethrough;
     currentTextBox.FontSize = info.Size;
     currentTextBox.FontFamily = info.Family;
     currentTextBox.Foreground = new SolidColorBrush(info.Color);
 }
コード例 #14
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 public static MeTLTextBox toMeTLTextBox(this TextBox OldBox)
 {
     var box = new MeTLTextBox(); 
     box.AcceptsReturn = true;
     box.TextWrapping = TextWrapping.WrapWithOverflow;
     box.BorderThickness = new Thickness(0);
     box.BorderBrush = new SolidColorBrush(Colors.Transparent);
     box.Background = new SolidColorBrush(Colors.Transparent);
     box.tag(OldBox.tag());
     box.FontFamily = OldBox.FontFamily;
     box.FontStyle = OldBox.FontStyle;
     box.FontWeight = OldBox.FontWeight;
     box.TextDecorations = OldBox.TextDecorations;
     box.FontSize = OldBox.FontSize;
     box.Foreground = OldBox.Foreground;
     box.Text = OldBox.Text;
     box.Width = OldBox.Width;
     //box.Height = OldBox.Height;
     InkCanvas.SetLeft(box, InkCanvas.GetLeft(OldBox));
     InkCanvas.SetTop(box, InkCanvas.GetTop(OldBox));
     return box;
 }
コード例 #15
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 public void sendTextWithoutHistory(MeTLTextBox box, string thisPrivacy, int slide)
 {
     RemovePrivacyStylingFromElement(box);
     if (box.tag().privacy != Globals.privacy)
         dirtyTextBoxWithoutHistory(box);
     var oldTextTag = box.tag();
     var newTextTag = new MeTLLib.DataTypes.TextTag(oldTextTag.author, thisPrivacy, oldTextTag.id);
     box.tag(newTextTag);
     var privateRoom = string.Format("{0}{1}", currentSlide, box.tag().author);
     if(thisPrivacy.ToLower() == "private" && Globals.isAuthor && Globals.me != box.tag().author)
         Commands.SneakInto.Execute(privateRoom);
     Commands.SendTextBox.ExecuteAsync(new TargettedTextBox(slide, box.tag().author, target, thisPrivacy, box));
     if(thisPrivacy.ToLower() == "private" && Globals.isAuthor && Globals.me != box.tag().author)
         Commands.SneakOutOf.Execute(privateRoom);
 }
コード例 #16
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private void resetText(MeTLTextBox box)
 {
     RemovePrivacyStylingFromElement(box);
     currentColor = Colors.Black;
     box.FontWeight = FontWeights.Normal;
     box.FontStyle = FontStyles.Normal;
     box.TextDecorations = new TextDecorationCollection();
     box.FontFamily = new FontFamily("Arial");
     box.FontSize = 24;
     box.Foreground = Brushes.Black;
     var info = new TextInformation
                    {
                        Family = box.FontFamily,
                        Size = box.FontSize,
                    };
     Commands.TextboxFocused.ExecuteAsync(info);
     sendTextWithoutHistory(box, box.tag().privacy);
 }
コード例 #17
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private void setAppropriatePrivacyHalo(MeTLTextBox box)
 {
     if (!Children.Contains(box)) return;
     ApplyPrivacyStylingToElement(box, privacy);
 }
コード例 #18
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 private void placeCursor(object sender, MouseButtonEventArgs e)
 {
     if (EditingMode != InkCanvasEditingMode.None) return;
     if (!canEdit) return;
     var pos = e.GetPosition(this);
     var source = (InkCanvas)sender;
     MeTLTextBox box = createNewTextbox();
     Children.Add(box);
     SetLeft(box, pos.X);
     SetTop(box, pos.Y);
     myTextBox = box;
     box.Focus();
 }
コード例 #19
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
 public MeTLTextBox Clone(MeTLTextBox OldBox)
 {
     var box = new MeTLTextBox();
     box.AcceptsReturn = true;
     box.TextWrapping = TextWrapping.WrapWithOverflow;
     box.GotFocus += textboxGotFocus;
     box.LostFocus += textboxLostFocus;
     box.BorderThickness = new Thickness(0);
     box.BorderBrush = new SolidColorBrush(Colors.Transparent);
     box.Background = new SolidColorBrush(Colors.Transparent);
     box.Focusable = canEdit && canFocus;
     box.tag(OldBox.tag());
     box.Height = OldBox.Height;
     box.Width = OldBox.Width;
     box.FontFamily = OldBox.FontFamily;
     box.FontWeight = OldBox.FontWeight;
     box.FontStyle = OldBox.FontStyle;
     box.TextDecorations = OldBox.TextDecorations;
     box.FontSize = OldBox.FontSize;
     box.Foreground = OldBox.Foreground;
     box.Text = OldBox.Text;
     SetLeft(box, GetLeft(OldBox));
     SetTop(box, GetTop(OldBox));
     return box;
 }
コード例 #20
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
        public MeTLTextBox createNewTextbox()
        {
            var box = new MeTLTextBox();
            box.tag(new TextTag
                        {
                            author = Globals.me,
                            privacy = privacy,
                            id = string.Format("{0}:{1}", Globals.me, SandRibbonObjects.DateTimeFactory.Now())
                        });
            box.FontFamily = currentFamily;
            box.FontSize = currentSize;
            box.Foreground = new SolidColorBrush(currentColor);
            box.UndoLimit = 0;
            box.LostFocus += (_sender, _args) =>
            {
                myTextBox = null;

            };
            return applyDefaultAttributes(box);
        }
コード例 #21
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
        protected override void HandleCopy()
        {
            try
            {
                if (myTextBox != null && myTextBox.SelectionLength > 0)
                {
                    Action undo = () => Clipboard.GetText();
                    Action redo = () => Clipboard.SetText(myTextBox.SelectedText);
                    redo();
                    UndoHistory.Queue(undo, redo);

                }
                else
                {
                    myTextBox = null;
                    var elements =  GetSelectedElements().Where(e => e is MeTLTextBox);
                    Action undo = () => {
                        foreach(var box in elements)
                            Clipboard.GetText();
                    };
                    Action redo = () =>
                                      {
                                          foreach (var box in elements)
                                              Clipboard.SetText(((MeTLTextBox)box).Text);
                                      };
                    UndoHistory.Queue(undo, redo);
                    redo();
                    
                }
            }
            catch (Exception)
            {
                
            }
        }
コード例 #22
0
ファイル: Text.cs プロジェクト: StackableRegiments/metl2011
        protected override void HandleCut()
        {
            try
            {
                if (myTextBox != null && myTextBox.SelectionLength > 0)
                {
                    var selection = myTextBox.SelectedText;
                    var text = myTextBox.Text;
                    var start = myTextBox.SelectionStart;
                    var length = myTextBox.SelectionLength;
                    var currentTextBox = myTextBox.clone();
                    Action undo = () =>
                                      {
                                          ClearAdorners();
                                          var activeTextbox = ((MeTLTextBox)Children.ToList().Where(c => ((MeTLTextBox)c).tag().id ==  currentTextBox.tag().id).FirstOrDefault());
                                          activeTextbox.Text = text;
                                          activeTextbox.CaretIndex = start + length;
                                          if (!alreadyHaveThisTextBox(activeTextbox))
                                              sendTextWithoutHistory(currentTextBox, currentTextBox.tag().privacy);
                                          Clipboard.GetText();
                                          addAdorners();
                                      };
                    Action redo = () =>
                                      {
                                          ClearAdorners();
                                          Clipboard.SetText(selection);
                                          var activeTextbox = ((MeTLTextBox)Children.ToList().Where(c => ((MeTLTextBox)c).tag().id ==  currentTextBox.tag().id).FirstOrDefault());
                                          if (activeTextbox == null) return;
                                          activeTextbox.Text = text.Remove(start, length);
                                          activeTextbox.CaretIndex = start;
                                          if (activeTextbox.Text.Length == 0)
                                          {
                                              ClearAdorners();
                                              myTextBox = null;
                                              dirtyTextBoxWithoutHistory(currentTextBox);
                                          }
                                          addAdorners();
                                      };
                    redo();
                    UndoHistory.Queue(undo, redo);

                }
                else
                {
                    var listToCut = new List<MeTLTextBox>();
                    var selectedElements = GetSelectedElements().Select(tb => Clone((MeTLTextBox) tb)).ToList().Select(Clone);
                    foreach (MeTLTextBox box in GetSelectedElements().Where(e => e is MeTLTextBox))
                    {
                        Clipboard.SetText(box.Text);
                        listToCut.Add(box);
                    }
                    ClearAdorners();
                    Action redo = () =>
                                      {
                                          ClearAdorners();
                                          myTextBox = null;
                                          foreach (var element in listToCut)
                                              dirtyTextBoxWithoutHistory(element);
                                          addAdorners();
                                      };
                    Action undo = () =>
                                      {

                                          ClearAdorners();
                                          var mySelectedElements = selectedElements.Select(t => t.clone());
                                          List<UIElement> selection = new List<UIElement>();
                                          foreach (var box in mySelectedElements)
                                              Clipboard.GetText();
                                          foreach (var box in mySelectedElements)
                                          {
                                              sendBox(box.toMeTLTextBox());
                                              selection.Add(box);
                                          }
                                          Select(selection);
                                          addAdorners();
                                      };
                    UndoHistory.Queue(undo, redo);
                    redo();
                }


            }
            catch (Exception)
            {
            }
        }