private void adornedElement_PreviewKeyUp(object sender, KeyEventArgs e) { if ((this.richTextBox != null) && (((e != null) && (e.Key == Key.Space)) || ((e == null) && this.performURLParsing))) { bool isWWWPrefixed; this.performURLParsing = false; string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.Document.ContentEnd).Text; string str2 = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text; int length = str2.Length; if (((length - 1) <= text.Length) && (length != 0)) { int startIndex = -1; if ((length - 2) >= 0) { startIndex = text.LastIndexOf("http://", (int)(length - 2)); startIndex = (startIndex == -1) ? text.LastIndexOf("https://", (int)(length - 2)) : startIndex; startIndex = (startIndex == -1) ? (startIndex = text.LastIndexOf("www.", (int)(length - 2))) : startIndex; } if (startIndex == -1) { startIndex = 0; } if (str2.Substring(0, str2.Length - 1).EndsWith("\r\n")) { startIndex = length - 1; } this.lastWord = text.Substring(startIndex, length - startIndex); isWWWPrefixed = false; int num3 = this.lastWord.LastIndexOf("http://"); num3 = (num3 == -1) ? this.lastWord.LastIndexOf("https://") : num3; if (num3 == -1) { num3 = this.lastWord.LastIndexOf("www."); isWWWPrefixed = true; } if (num3 != -1) { string url; ContextMenu buttonContextMenu; Button button; MenuItem expandContractMenuItem; MenuItem gotoLinkMenuitem; Func<string> shortenURLDelegate; int index = this.lastWord.IndexOf(' ', num3); if (index != -1) { url = this.lastWord.Substring(num3, index - num3); int num5 = url.Length; if (isWWWPrefixed) { num5 += "http://".Length; } if ((num5 >= this.URL_LENGTH_THRESHOLD) && !this.IsAlreadyShortened(url)) { int x = text.IndexOf(url) - GetInlineUIContainerCountUpToPointer(this.richTextBox, this.richTextBox.CaretPosition); TextPointer start = new TextRange(GetPoint(this.richTextBox.Document.ContentStart, x), this.richTextBox.Document.ContentEnd).Start; start.DeleteTextInRun(url.Length); buttonContextMenu = new ContextMenu(); button = new Button(); button.SetResourceReference(FrameworkElement.StyleProperty, "URLButton"); button.Content = "shortening..."; button.Click += delegate(object s, RoutedEventArgs e2) { buttonContextMenu.PlacementTarget = button; buttonContextMenu.Placement = PlacementMode.Bottom; buttonContextMenu.IsOpen = true; }; expandContractMenuItem = new MenuItem { Header = "Expand link", IsEnabled = false }; gotoLinkMenuitem = new MenuItem { Header = "Open link in browser", IsEnabled = false }; buttonContextMenu.Items.Add(gotoLinkMenuitem); buttonContextMenu.Items.Add(expandContractMenuItem); InlineUIContainer container = new InlineUIContainer(button, start); shortenURLDelegate = delegate { Dictionary<string, string> dictionary = new Dictionary<string, string>(); if (CoreServices.Instance.CurrentURLShorteningService(this.TwitterAccountID) != null) { string key = CoreServices.Instance.CurrentURLShorteningService(this.TwitterAccountID).Name; if (!App.ShortenedURLCache.ContainsKey(key)) { Dictionary<string, string> dictionary2 = new Dictionary<string, string>(); App.ShortenedURLCache.Add(key, dictionary2); dictionary = dictionary2; } else { dictionary = App.ShortenedURLCache[key]; } } string text1 = url; if (isWWWPrefixed) { text1 = string.Format("http://{0}", text1); } string str3 = string.Empty; if (App.ShortenedURLCache.ContainsKey(text1)) { return dictionary[text1]; } str3 = this.ShortenURL(text1); dictionary[text1] = str3; return str3; }; shortenURLDelegate.BeginInvoke(delegate(IAsyncResult result) { string originalURL = url; if (isWWWPrefixed) { originalURL = string.Format("http://{0}", originalURL); } string returnedValue = shortenURLDelegate.EndInvoke(result); Application.Current.Dispatcher.BeginInvoke((Action)(() => { Button wrappedButton = button; wrappedButton.Content = returnedValue; wrappedButton.ToolTip = originalURL.ToString(); gotoLinkMenuitem.Click += (gs, ge) => Process.Start(returnedValue); expandContractMenuItem.Click += delegate(object sc, RoutedEventArgs ec) { if (expandContractMenuItem.Header.ToString() == "Expand link") { wrappedButton.Content = originalURL; expandContractMenuItem.Header = "Shorten link"; } else { wrappedButton.Content = returnedValue; expandContractMenuItem.Header = "Expand link"; } Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>(null), CommonCommands.MultiAccountifyToken(ViewModelMessages.UpdateActualTweetText, this.TwitterAccountID)); }; expandContractMenuItem.IsEnabled = true; gotoLinkMenuitem.IsEnabled = true; Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>(null), CommonCommands.MultiAccountifyToken(ViewModelMessages.UpdateActualTweetText, this.TwitterAccountID)); Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>(null), CommonCommands.MultiAccountifyToken(ViewModelMessages.DecrementPostTweetCounter, this.TwitterAccountID)); }), DispatcherPriority.ContextIdle, new object[0]); }, null); Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>(null), CommonCommands.MultiAccountifyToken(ViewModelMessages.IncrementPostTweetCounter, this.TwitterAccountID)); } } } } } }
private void InsertSelectedEntry(char characterInsertion) { if (this.intellisenseListBox.SelectedIndex <= -1 || !this.intellisensePopup.IsOpen) return; string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text; int startIndex = text.LastIndexOf(' '); string currentWord = startIndex != -1 ? text.Substring(startIndex).TrimStart(new char[0]) : text.TrimStart(new char[0]); IntellisenseItem intellisenseItem = this.intellisenseListBox.SelectedItem as IntellisenseItem; bool flag = text.StartsWith("d ", StringComparison.InvariantCultureIgnoreCase) && !IntellisenseAdorner.DM_EXPRESSION_WITH_END_SPACE.IsMatch(text); string textData = this.IgnorePrefix || flag ? intellisenseItem.FilterValue : intellisenseItem.DisplayValue; if (textData.StartsWith("@") || textData.StartsWith("#")) { int charactersToDelete = IntellisenseAdorner.GetNumberOfCharactersToDelete(currentWord, textData.StartsWith("@") ? "@" : "#"); if (currentWord.EndsWith(" ")) this.richTextBox.CaretPosition.DeleteTextInRun(-(charactersToDelete - 1)); else this.richTextBox.CaretPosition.DeleteTextInRun(-charactersToDelete); } else if (currentWord.EndsWith(" ")) this.richTextBox.CaretPosition.DeleteTextInRun(-(currentWord.Length - 1)); else this.richTextBox.CaretPosition.DeleteTextInRun(-currentWord.Length); if ((int)characterInsertion != 0 && !this.IgnorePrefix) textData = textData + (object)characterInsertion; this.richTextBox.CaretPosition = this.richTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward) ?? this.richTextBox.CaretPosition; if (!flag) { this.richTextBox.CaretPosition.InsertTextInRun(textData); } else { this.richTextBox.CaretPosition.InsertTextInRun(textData); Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)intellisenseItem.FilterValue), (object)CommonCommands.MultiAccountifyToken((Enum)ViewModelMessages.DirectMessage, intellisenseItem.TwitterAccountID)); } this.ignoreDisplay = true; }
private void richTextBox_PreviewKeyUp(object sender, KeyEventArgs e) { if (((e.Key != Key.Up) && (e.Key != Key.Down)) && ((e.Key != Key.Space) || !this.IgnorePrefix)) { if ((e.Key == Key.Space) || (e.Key == Key.Escape)) { this.HideMethodsPopup(); } if (((((e.Key == Key.Escape) || (e.Key == Key.Left)) || ((e.Key == Key.Right) || (e.Key == Key.Return))) || ((this.IgnorePrefix && (e.Key == Key.D2)) && (Keyboard.Modifiers == ModifierKeys.Shift))) || this.ignoreDisplay) { this.HideMethodsPopup(); this.ignoreDisplay = false; } else { IEnumerable<IntellisenseItem> results = null; string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text; int startIndex = text.LastIndexOf(' '); string input = (startIndex != -1) ? text.Substring(startIndex).TrimStart(new char[0]) : text.TrimStart(new char[0]); if (((input == "@") || (input == "#")) && this.IgnorePrefix) { this.HideMethodsPopup(); this.ignoreDisplay = false; } else if (!(this.ExcludeMentions || (((input != "@") && !input.EndsWith("@")) && !(text == "d ")))) { results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches("@"); Rect rect = this.richTextBox.CaretPosition.GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.intellisenseListBox.SelectedIndex = -1; }); } else if ((input == "#") || input.EndsWith("#")) { results = IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.GetMatches("#"); Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.intellisenseListBox.SelectedIndex = -1; }); } else if (!(this.ExcludeMentions || (!MENTION_EXPRESSION.IsMatch(input) && !this.IgnorePrefix))) { string currentWordExcludingPrefix = string.Empty; currentWordExcludingPrefix = this.IgnorePrefix ? input : MENTION_EXPRESSION.Match(input).Groups[1].Value; results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches(currentWordExcludingPrefix); Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.SetSelection(currentWordExcludingPrefix); }); } else if (!((this.ExcludeMentions || !DM_EXPRESSION.IsMatch(text)) || DM_EXPRESSION_WITH_END_SPACE.IsMatch(text))) { string currentWordExcludingPrefix = DM_EXPRESSION.Match(text).Groups[1].Value; results = IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.GetMatches(currentWordExcludingPrefix); Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).MentionsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.SetSelection(currentWordExcludingPrefix); }); } else if (TAG_EXPRESSION.IsMatch(input)) { string partialWord = TAG_EXPRESSION.Match(input).Groups[1].Value; results = IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.GetMatches(partialWord); Rect rect = GetPoint(this.richTextBox.Document.ContentStart, startIndex).GetCharacterRect(LogicalDirection.Forward); this.BindResults(results, this.intellisenseListBox, rect, IntellisenseDataSource.Instance(this.TwitterAccountID).TagsCollection.ContainsEntries, delegate { this.ShowMethodsPopup(rect, this.richTextBox); this.intellisenseListBox.SelectedIndex = -1; }); } else { this.HideMethodsPopup(); } } } }
private void rtbEdit_PreviewKeyDown(object sender, KeyEventArgs e) { timer.Interval = COUNTDOWN; if (e.Key == Key.V && (Keyboard.Modifiers & (ModifierKeys.Control)) == (ModifierKeys.Control)) { if (Clipboard.ContainsImage()) { e.Handled = true; BitmapSource bitmap = Clipboard.GetImage(); PngBitmapEncoder pE = new PngBitmapEncoder(); string tempFile = Path.GetTempFileName(); pE.Frames.Add(BitmapFrame.Create(bitmap)); using (Stream stream = File.Create(tempFile)) { pE.Save(stream); } Helper.ImageHelper.InsertImg(rtbEdit, tempFile); File.Delete(tempFile); } } else { string strText = new TextRange(rtbEdit.Document.ContentStart, rtbEdit.Document.ContentEnd).Text; if (strText.LastIndexOf("\r\n") > 0) { strText = strText.Remove(strText.LastIndexOf("\r\n")); } if (strText.Length <= 0) return; int titleEnd = strText.IndexOf("\r\n"); if (titleEnd > 31 || titleEnd < 0) titleEnd = 0; strText = strText.Remove(0, titleEnd); int count = Regex.Matches(strText, @"[^\s]").Count; if (count <= 0) return; tbCount.Text = count + ""; if (count > countAll + 10 || count < countAll - 10) { countAll = count; SaveAndUpdate(); } } }