示例#1
0
 private void SetupFolding()
 {
     var foldingStrategy = new BraceFoldingStrategy();
     var foldingManager = FoldingManager.Install(TextEditor.TextArea);
     foldingStrategy.UpdateFoldings(foldingManager, TextEditor.Document);
     TextEditor.TextChanged +=
         (sender, args) => foldingStrategy.UpdateFoldings(foldingManager, TextEditor.Document);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <returns>true when a new tab is created</returns>
        public bool OpenScript(string path)
        {
            int srcFileOpen = FileIsOpen(path);

            if (srcFileOpen == -1) // not found
            {
                FoldingManager foldingManager;
                AbstractFoldingStrategy foldingStrategy;
                foldingStrategy = new BraceFoldingStrategy();

                TextEditor textEditor = new TextEditor();
                textEditor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(textEditor.Options);
                textEditor.Foreground = FindResource("ForegroundGray") as Brush;
                textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
                textEditor.ScrollToEnd();
                textEditor.FontFamily = new FontFamily("Consolas");
                textEditor.FontSize = 11;
                textEditor.ShowLineNumbers = true;
                textEditor.Text = File.ReadAllText(path, Encoding.UTF8);
                textEditor.Tag = path; // stores the file path in memory
                textEditor.TextChanged += textEditor_TextChanged;
                textEditor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                textEditor.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

                foldingManager = FoldingManager.Install(textEditor.TextArea);
                foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);

                TabItem tabItem = new TabItem();
                tabItem.Style = FindResource("TabItemStyle") as Style;
                tabItem.Foreground = FindResource("ForegroundGray") as Brush;
                tabItem.Header = System.IO.Path.GetFileNameWithoutExtension(path);
                tabItem.Content = textEditor;
                tabItem.Tag = path; // stores the file path in memory
                tabItem.Loaded += tabItem_Loaded;

                tabControl.Items.Add(tabItem);

                tabControl.SelectedIndex = tabControl.Items.Count - 1;

                return true;
            }
            else
            {
                tabControl.SelectedIndex = srcFileOpen;
 
                this.Activate();

                FLASHWINFO pf = new FLASHWINFO();

                pf.cbSize = Convert.ToUInt32(Marshal.SizeOf(pf));
                pf.hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle; 
                pf.dwFlags = FLASHW_TIMER | FLASHW_TRAY; // (or FLASHW_ALL to flash and if it is not minimized)
                pf.uCount = 8;
                pf.dwTimeout = 75;

                FlashWindowEx(ref pf);

                return false;
            }
        }