private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (lstOptions.Visibility == Visibility.Visible)
            {
                lstOptions.Focus();
                return;
            }

            if (!IsCaretPositionValid())
            {
                this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd;
                return;
            }

            if (e.Key == Key.Space)
            {
                var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                   richTextBox1.CaretPosition).Text;
                command = command.Substring(command.IndexOf(">") + 1).Trim();
                ShowOptions(command);
                return;
            }

            if (e.Key == Key.Enter)
            {
                var command = GetCommand();
                RunCommand(command);
                e.Handled = true;
            }
            else if (e.Key == Key.Up)
            {
                GetCommand(--commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Down)
            {
                GetCommand(++commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Escape)
            {
                ChangePrompt("", BRUSH_PROMPT);
                lstOptions.Visibility = Visibility.Collapsed;
            }
            else if (e.Key == Key.Back)
            {
                var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                    richTextBox1.CaretPosition).Text;
                if (text.EndsWith(">")) e.Handled = true;
            }
        }
Ejemplo n.º 2
0
        private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (lstOptions.Visibility == Visibility.Visible)
            {
                if (e.Key == Key.Escape)
                {
                    this.HideOptions();
                }
                else
                {
                    lstOptions.Focus();
                }
                return;
            }

            if (!IsCaretPositionValid())
            {
                this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd;
                return;
            }

            if (e.Key == Key.Space)
            {
                var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                   richTextBox1.CaretPosition).Text;
                command = command.Substring(command.IndexOf(">") + 1).Trim();
                ShowOptions(command);
                return;
            }

            if (e.Key == Key.Enter)
            {
                var command = GetCommand();
                if (this.IsProcessRunning)
                {
                    this.WriteInput(command);
                }
                else
                {
                    RunCommand(command);
                    e.Handled = true;
                }
            }
            else if (e.Key == Key.Up)
            {
                GetCommand(--commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Down)
            {
                GetCommand(++commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Escape)
            {
                ChangePrompt("", BRUSH_PROMPT);
                this.HideOptions();
            }
            else if (e.Key == Key.Back)
            {
                var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                    richTextBox1.CaretPosition).Text;
                if (text.EndsWith(">") && text.IndexOf(">") == text.Length - 1) e.Handled = true;
            }
            else if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
            {
                if (IsProcessRunning)
                {
                    SendShutdownToConsole();
                    e.Handled = true;
                }
            }
            else if (lstOptions.Visibility == Visibility.Visible)
            {
                //lstOptions.KeyDown()
            }
        }
Ejemplo n.º 3
0
        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));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void RenderInputGraphics_Click(object sender, RoutedEventArgs e)
        {
            string myText = new TextRange(GraphicsInput.Document.ContentStart, GraphicsInput.Document.ContentEnd).Text;

            if (!string.IsNullOrEmpty(myText) && (myText.IndexOf("linkto") == -1))
            {
                if (visType == VisualisationType.XAML)

                    showXAML(myText);

                else if (visType == VisualisationType.SVG)

                    showSVG(myText);
            }
            else if (myText.IndexOf("linkto") != -1)
            {
                ReportStatusBar.ShowStatus("Modified graphics have to be processed first, then use \"Render output graphics\" to render", ReportIcon.Error);
                logger.log("Render input graphics error -> " + "Modified graphics have to be processed first", ReportIcon.Error);
            }
            else
            {
                ReportStatusBar.ShowStatus("Input graphics is empty!", ReportIcon.Error);
                logger.log("Render input graphics error -> " + "Input is empty!", ReportIcon.Error);
            }
        }
Ejemplo n.º 5
0
        private void BuildNotation_Click(object sender, RoutedEventArgs e)
        {
            ReportStatusBar.clearReportMessage();

            if (String.IsNullOrEmpty(NotationNameTextBox.Text))
            {
                ReportStatusBar.ShowStatus("Notation name is not provided!", ReportIcon.Error);
                logger.log("Building \'" + NotationNameTextBox.Text + "\' failed -> " + "Notation name is not provided!", ReportIcon.Error);
                NotationNameTextBox.Focus();
            }
            else
            {
                string graphicsText = new TextRange(GraphicsInput.Document.ContentStart, GraphicsInput.Document.ContentEnd).Text;
                if (String.IsNullOrEmpty(graphicsText))
                {
                    ReportStatusBar.ShowStatus("Notation graphics code is missing!", ReportIcon.Error);
                    logger.log("Building \'" + NotationNameTextBox.Text + "\' failed -> " + "Notation graphics code is missing!", ReportIcon.Error);
                    GraphicsInput.Focus();
                }
                else
                {
                    if ((graphicsText.IndexOf("linkto") == -1) && (graphicsText.IndexOf("callfor") == -1))
                    {
                        MessageBoxResult mbresult;
                        mbresult = MessageBox.Show("No semantic link between data and graphics is provided, if you continue the notation will be static!", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning);

                        if (mbresult == MessageBoxResult.Cancel)
                        {
                            ReportStatusBar.ShowStatus("Build canceled!", ReportIcon.Warning);
                            logger.log("Building \'" + NotationNameTextBox.Text + "\' canceled!", ReportIcon.Error);
                            return;
                        }
                    }

                    string dataText = generate_Data(graphicsText, NotationNameTextBox.Text);
                    TextRange temp = new TextRange(XMLDataInput.Document.ContentStart, XMLDataInput.Document.ContentEnd);
                    temp.Text = "";
                    XMLDataInput.AppendText(prettyPrinter.PrintToString(dataText));

                    if (String.IsNullOrEmpty(dataText))
                    {
                        ReportStatusBar.ShowStatus("Data XML is missing!", ReportIcon.Error);
                        logger.log("Building \'" + NotationNameTextBox.Text + "\' failed -> " + "Data XML is missing!", ReportIcon.Error);
                        XMLDataInput.Focus();
                    }
                    else
                    {
                        //do build
                        string check = buildNotation(graphicsText, dataText);
                        if (!String.IsNullOrEmpty(check))
                        {
                            TextRange range = new TextRange(GraphicsOutput.Document.ContentStart, GraphicsOutput.Document.ContentEnd);
                            range.Text = "";
                            range.Text = check;
                            ReportStatusBar.ShowStatus("Noation built!", ReportIcon.OK);
                            logger.log("Notation \'" + NotationNameTextBox.Text + "\' is built.", ReportIcon.OK);

                            SkinOutputTabControl.SelectedIndex = 4;
                        }
                    }
                }
            }
        }
        private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                   richTextBox1.CaretPosition).Text;
                command = command.Substring(command.IndexOf(">") + 1).Trim();
                ShowOptions(command);
                return;
            }
            else if (e.Key == Key.Tab || e.Key == Key.Down)
            {
                if (lstOptions.Visibility == Visibility.Visible)
                {
                    lstOptions.Focus();
                    return;
                }
            }
            else
            {
                lstOptions.Visibility = Visibility.Collapsed;
            }

            if (e.Key == Key.Enter)
            {
                var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                    richTextBox1.CaretPosition.GetLineStartPosition(1) ?? richTextBox1.CaretPosition.DocumentEnd).Text;
                command = command.Replace("\r", "").Replace("\n", "");
                RunCommand(command);
                e.Handled = true;
            }
            else if (e.Key == Key.Up)
            {
                GetCommand(--commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Down)
            {
                GetCommand(++commandIdx);
                e.Handled = true;
            }
            else if (e.Key == Key.Escape)
            {
                ChangePrompt("",  new SolidColorBrush(Colors.Black));
            }
            else if (e.Key == Key.Back)
            {
                var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0),
                    richTextBox1.CaretPosition).Text;
                if (text.EndsWith(">")) e.Handled = true;
            }
            else
            {
                var text = new TextRange(richTextBox1.CaretPosition, richTextBox1.CaretPosition.DocumentEnd).Text;
                if (text.Contains(">")) //e.Handled = true;
                    this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd;
            }
        }
Ejemplo n.º 7
0
        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();
                }
            }
        }