Exemplo n.º 1
0
        static List <FoldSegment> GetFoldSegments(Document doc)
        {
            List <FoldSegment>  result       = new List <FoldSegment> ();
            Stack <FoldSegment> foldSegments = new Stack <FoldSegment> ();

            for (int i = 0; i < doc.Length - 1; ++i)
            {
                char ch = doc.GetCharAt(i);

                if ((ch == '+' || ch == '-') && doc.GetCharAt(i + 1) == '[')
                {
                    FoldSegment segment = new FoldSegment("...", i, 0, FoldingType.None);
                    segment.IsFolded = ch == '+';
                    foldSegments.Push(segment);
                }
                 else if (ch == ']' && foldSegments.Count > 0)
                {
                    FoldSegment segment = foldSegments.Pop();
                    segment.Length = i - segment.Offset + 1;
                    result.Add(segment);
                    System.Console.WriteLine("Add:" + segment);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        private void ParseFoldingRegion(MatchCollection mc, ref List <FoldSegment> list, int start)
        {
            int needStart = 1;
            int findEnd   = 0;

            if (mc == null || mc.Count < 1)
            {
                return;
            }

            if (start >= mc.Count)
            {
                return;
            }

            Match startMatch = mc[start];

            if (startMatch.Value.Contains("@endregion"))
            {
                start++;
                ParseFoldingRegion(mc, ref list, start);
                return;
            }
            for (int i = start + 1; i < mc.Count; i++)
            {
                if (!mc[i].Value.Contains("@endregion"))
                {
                    needStart++;
                }
                else
                {
                    findEnd++;

                    if (needStart == findEnd)
                    {
                        int startIndex = startMatch.Index;
                        int endIndex   = mc[i].Index - startIndex + mc[i].Value.Length;

                        Regex  regex = new Regex(@"//\s*?@region", RegexOptions.Compiled);
                        string text  = regex.Replace(startMatch.Value, "");

                        text = text.Trim();
                        if (String.IsNullOrEmpty(text))
                        {
                            text = "....";
                        }

                        FoldSegment fs = new FoldSegment(text, startIndex, endIndex, FoldingType.Region);
                        list.Add(fs);
                        break;
                    }
                }
            }
            start++;
            ParseFoldingRegion(mc, ref list, start);
        }
Exemplo n.º 3
0
        private void ParseFolding(MatchCollection mc, ref List <FoldSegment> list, int start, string startExpresion, string endExpresion)
        {
            int needStart = 1;
            int findEnd   = 0;

            if (mc == null || mc.Count < 1)
            {
                return;
            }

            if (start >= mc.Count)
            {
                return;
            }

            Match startMatch = mc[start];

            if (startMatch.Value.Contains(endExpresion))            //"}"
            {
                start++;
                ParseFolding(mc, ref list, start, startExpresion, endExpresion);
                return;
            }

            for (int i = start + 1; i < mc.Count; i++)
            {
                if (mc[i].Value.Contains(startExpresion))                //"}"
                {
                    needStart++;
                }
                else if (mc[i].Value.Contains(endExpresion))
                {
                    findEnd++;

                    if (needStart == findEnd)
                    {
                        int startIndex = startMatch.Index;
                        int endIndex   = mc[i].Index - startIndex + mc[i].Value.Length;

                        FoldSegment fs = new FoldSegment("....", startIndex, endIndex, FoldingType.Region);
                        list.Add(fs);
                        break;
                    }
                }
            }
            start++;
            ParseFolding(mc, ref list, start, startExpresion, endExpresion);
        }
Exemplo n.º 4
0
		static List<FoldSegment> GetFoldSegments (Document doc)
		{
			List<FoldSegment> result = new List<FoldSegment> ();
			Stack<FoldSegment> foldSegments = new Stack<FoldSegment> ();
			
			for (int i = 0; i < doc.Length - 1; ++i) {
				char ch = doc.GetCharAt (i);
				
				if ((ch == '+' || ch == '-') && doc.GetCharAt(i + 1) == '[') {
					FoldSegment segment = new FoldSegment (doc, "...", i, 0, FoldingType.None);
					segment.IsFolded = ch == '+';
					foldSegments.Push (segment);
				} else if (ch == ']' && foldSegments.Count > 0) {
					FoldSegment segment = foldSegments.Pop ();
					segment.Length = i - segment.Offset;
					result.Add (segment);
				}
			}
			return result;
		}
Exemplo n.º 5
0
        static List <FoldSegment> GetFoldSegments(TextDocument doc)
        {
            List <FoldSegment>  result       = new List <FoldSegment> ();
            Stack <FoldSegment> foldSegments = new Stack <FoldSegment> ();

            for (int i = 0; i < doc.Length - 1; ++i)
            {
                char ch = doc.GetCharAt(i);

                if ((ch == '+' || ch == '-') && doc.GetCharAt(i + 1) == '[')
                {
                    FoldSegment segment = new FoldSegment("...", i, 0, FoldingType.Unknown);
                    segment.IsCollapsed = ch == '+';
                    foldSegments.Push(segment);
                }
                 else if (ch == ']' && foldSegments.Count > 0)
                {
                    FoldSegment segment = foldSegments.Pop();
                    segment.Length = i - segment.Offset;
                    result.Add(segment);
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        public static TextEditorData Create(string content, ITextEditorOptions options = null, string mimeType = null)
        {
            var data = new TextEditorData();

            if (options != null)
            {
                data.Options = options;
            }
            if (mimeType != null)
            {
                data.Document.MimeType = mimeType;
            }
            var sb = new StringBuilder();
            int caretIndex = -1, selectionStart = -1, selectionEnd = -1;
            var foldSegments = new List <FoldSegment> ();
            var foldStack    = new Stack <FoldSegment> ();

            for (int i = 0; i < content.Length; i++)
            {
                var ch = content [i];
                switch (ch)
                {
                case '$':
                    caretIndex = sb.Length;
                    break;

                case '<':
                    if (i + 1 < content.Length)
                    {
                        if (content [i + 1] == '-')
                        {
                            selectionStart = sb.Length;
                            i++;
                            break;
                        }
                    }
                    goto default;

                case '-':
                    if (i + 1 < content.Length)
                    {
                        var next = content [i + 1];
                        if (next == '>')
                        {
                            selectionEnd = sb.Length;
                            i++;
                            break;
                        }
                        if (next == '[')
                        {
                            var segment = new FoldSegment("...", sb.Length, 0, FoldingType.Unknown);
                            segment.IsCollapsed = false;
                            foldStack.Push(segment);
                            i++;
                            break;
                        }
                    }
                    goto default;

                case '+':
                    if (i + 1 < content.Length)
                    {
                        var next = content [i + 1];
                        if (next == '[')
                        {
                            var segment = new FoldSegment("...", sb.Length, 0, FoldingType.Unknown);
                            segment.IsCollapsed = true;
                            foldStack.Push(segment);
                            i++;
                            break;
                        }
                    }
                    goto default;

                case ']':
                    if (foldStack.Count > 0)
                    {
                        FoldSegment segment = foldStack.Pop();
                        segment.Length = sb.Length - segment.Offset;
                        foldSegments.Add(segment);
                        break;
                    }
                    goto default;

                default:
                    sb.Append(ch);
                    break;
                }
            }

            data.Text = sb.ToString();

            if (caretIndex >= 0)
            {
                data.Caret.Offset = caretIndex;
            }
            if (selectionStart >= 0)
            {
                if (caretIndex == selectionStart)
                {
                    data.SetSelection(selectionEnd, selectionStart);
                }
                else
                {
                    data.SetSelection(selectionStart, selectionEnd);
                    if (caretIndex < 0)
                    {
                        data.Caret.Offset = selectionEnd;
                    }
                }
            }
            if (foldSegments.Count > 0)
            {
                data.Document.UpdateFoldSegments(foldSegments);
            }
            return(data);
        }
		public static TextEditorData Create (string content, ITextEditorOptions options = null)
		{
			var data = new TextEditorData ();
			if (options != null)
				data.Options = options;
			var sb = new StringBuilder ();
			int caretIndex = -1, selectionStart = -1, selectionEnd = -1;
			var foldSegments = new List<FoldSegment> ();
			var foldStack = new Stack<FoldSegment> ();

			for (int i = 0; i < content.Length; i++) {
				var ch = content [i];
				switch (ch) {
				case '$':
					caretIndex = sb.Length;
					break;
				case '<':
					if (i + 1 < content.Length) {
						if (content [i + 1] == '-') {
							selectionStart = sb.Length;
							i++;
							break;
						}
					}
					goto default;
				case '-':
					if (i + 1 < content.Length) {
						var next = content [i + 1];
						if (next == '>') {
							selectionEnd = sb.Length;
							i++;
							break;
						}
						if (next == '[') {
							var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None);
							segment.IsFolded = false;
							foldStack.Push (segment);
							i++;
							break;
						}
					}
					goto default;
				case '+':
					if (i + 1 < content.Length) {
						var next = content [i + 1];
						if (next == '[') {
							var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None);
							segment.IsFolded = true;
							foldStack.Push (segment);
							i++;
							break;
						}
					}
					goto default;
				case ']':
					if (foldStack.Count > 0) {
						FoldSegment segment = foldStack.Pop ();
						segment.Length = sb.Length - segment.Offset;
						foldSegments.Add (segment);
						break;
					}
					goto default;
				default:
					sb.Append (ch);
					break;
				}
			}

			data.Text = sb.ToString ();

			if (caretIndex >= 0)
				data.Caret.Offset = caretIndex;
			if (selectionStart >= 0) {
				if (caretIndex == selectionStart) {
					data.SetSelection (selectionEnd, selectionStart);
				} else {
					data.SetSelection (selectionStart, selectionEnd);
				}
			}
			if (foldSegments.Count > 0)
				data.Document.UpdateFoldSegments (foldSegments);
			return data;
		}
Exemplo n.º 8
0
        public SourceEditor(string filePath)
        {
            if (MainClass.Settings.SourceEditorSettings == null)
            {
                MainClass.Settings.SourceEditorSettings = new  Moscrif.IDE.Option.Settings.SourceEditorSetting();
            }

            errors         = new List <ErrorMarker>();
            lastPrecompile = DateTime.Now;
            control        = new Gtk.ScrolledWindow();
            (control as Gtk.ScrolledWindow).ShadowType = Gtk.ShadowType.Out;

            editorAction  = new Gtk.ActionGroup("sourceeditor");
            searchPattern = null;

            editor = new TextEdit();

            LoadSetting();

            SyntaxMode mode = new SyntaxMode();

            string extension = System.IO.Path.GetExtension(filePath);

            //editor.AccelCanActivate

            switch (extension)
            {
            case ".ms":
            {
                try{
                    mode = SyntaxModeService.GetSyntaxMode("text/moscrif");
                }catch (Exception ex) {
                    MessageDialogs msd = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("error_load_syntax"), MainClass.Languages.Translate("error_load_syntax_f1"), Gtk.MessageType.Error, null);
                    msd.ShowDialog();
                    Tool.Logger.Error(ex.Message);
                }
                isCompileExtension = true;

                (editor as ICompletionWidget).BanCompletion = false;
                break;
            }

            case ".js":
            {
                try{
                    mode = SyntaxModeService.GetSyntaxMode("text/x-java");
                }catch (Exception ex) {
                    MessageDialogs msd = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("error_load_syntax"), MainClass.Languages.Translate("error_load_syntax_f1"), Gtk.MessageType.Error, null);
                    msd.ShowDialog();
                    Tool.Logger.Error(ex.Message);
                }
                isCompileExtension = true;

                (editor as ICompletionWidget).BanCompletion = false;
                break;
            }

            case ".mso":
            {
                try{
                    mode = SyntaxModeService.GetSyntaxMode("text/moscrif");
                }catch (Exception ex) {
                    MessageDialogs msd = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("error_load_syntax"), MainClass.Languages.Translate("error_load_syntax_f1"), Gtk.MessageType.Error, null);
                    msd.ShowDialog();
                    Tool.Logger.Error(ex.Message);
                }
                isCompileExtension = true;
                break;
            }

            case ".xml":
            {
                mode = SyntaxModeService.GetSyntaxMode("application/xml");
                break;
            }

            case ".txt":
            case ".app":
                break;

            default:
                break;
            }

            //editor.Document.
            editor.Document.SyntaxMode = mode;
            //modified = true;
            editor.Document.LineChanged += delegate(object sender, LineEventArgs e) {
                OnBookmarkUpdate();
                OnModifiedChanged(true);
            };

            editor.Caret.PositionChanged += delegate(object sender, DocumentLocationEventArgs e) {
                OnWriteToStatusbar(String.Format(statusFormat, editor.Caret.Location.Line + 1, editor.Caret.Location.Column, editor.Caret.Offset));
            };

            FileAttributes fa = File.GetAttributes(filePath);

            if ((fa & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                onlyRead = true;
                //editor.Document.ReadOnly= true;
            }

            try {
                using (StreamReader file = new StreamReader(filePath)) {
                    editor.Document.Text = file.ReadToEnd();
                    file.Close();
                    file.Dispose();
                }
            } catch (Exception ex) {
                MessageDialogs ms = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("file_cannot_open", filePath), ex.Message, Gtk.MessageType.Error, null);
                ms.ShowDialog();
                return;
            }

            //Console.WriteLine(editor.Document.Text.Replace("\r","^").Replace("\n","$"));

            (control as Gtk.ScrolledWindow).Add(editor);
            control.ShowAll();
            fileName = filePath;

            fileSeting = MainClass.Workspace.WorkspaceUserSetting.FilesSetting.Find(x => x.FileName == fileName);

            if (fileSeting == null)
            {
                fileSeting = new FileSetting(fileName);
            }

            editor.TextViewMargin.ButtonPressed += OnTextMarginButtonPress;
            editor.IconMargin.ButtonPressed     += OnIconMarginButtonPress;
            //editor.KeyPressEvent += OnKeyPressEvent;
            editor.KeyReleaseEvent  += OnKeyReleaseEvent;
            editor.ButtonPressEvent += OnButtonPressEvent;

            bookmarkActions     = new IdeBookmarkActions(editor, fileSeting);
            breakpointActions   = new IdeBreakpointActions(editor);
            autoCompleteActions = new IdeAutocompleteAction(editor, editor);
            editAction          = new IdeEditAction(editor);

            Gtk.Action act = new Gtk.Action("sourceeditor_togglebookmark", "");
            act.Activated += bookmarkActions.ToggleBookmark;
            editorAction.Add(act);

            Gtk.Action act2 = new Gtk.Action("sourceeditor_clearbookmark", "");
            act2.Activated += bookmarkActions.ClearBookmarks;
            editorAction.Add(act2);

            Gtk.Action act3 = new Gtk.Action("sourceeditor_nextbookmark", "");
            act3.Activated += bookmarkActions.NextBookmark;
            editorAction.Add(act3);

            Gtk.Action act4 = new Gtk.Action("sourceeditor_prevbookmark", "");
            act4.Activated += bookmarkActions.PreviousBookmark;
            editorAction.Add(act4);

            Gtk.Action act5 = new Gtk.Action("sourceeditor_addbreakpoint", "");
            act5.Activated += breakpointActions.AddBreakpoints;
            editorAction.Add(act5);

            Gtk.Action act6 = new Gtk.Action("sourceeditor_inserttemplate", "");
            act6.Activated += autoCompleteActions.InsertTemplate;
            editorAction.Add(act6);

            Gtk.Action act7 = new Gtk.Action("sourceeditor_insertautocomplete", "");
            act7.Activated += autoCompleteActions.InsertCompletion;
            editorAction.Add(act7);

            Gtk.Action act8 = new Gtk.Action("sourceeditor_pasteClipboard", "");
            act8.Activated += editAction.PasteText;
            editorAction.Add(act8);

            Gtk.Action act9 = new Gtk.Action("sourceeditor_copyClipboard", "");
            act9.Activated += editAction.CopyText;
            editorAction.Add(act9);

            Gtk.Action act10 = new Gtk.Action("sourceeditor_cutClipboard", "");
            act10.Activated += editAction.CutText;
            editorAction.Add(act10);

            Gtk.Action act11 = new Gtk.Action("sourceeditor_gotoDefinition", "");
            act11.Activated += editAction.GoToDefinition;
            editorAction.Add(act11);

            Gtk.Action act12 = new Gtk.Action("sourceeditor_commentUncomment", "");
            act12.Activated += editAction.CommentUncomment;
            editorAction.Add(act12);

            List <FoldSegment> list = editor.GetFolding();

            foreach (SettingValue sv in fileSeting.Folding)
            {
                FoldSegment foldS = list.Find(x => x.Offset.ToString() == sv.Display);
                if (foldS != null)
                {
                    bool isfolding = false;
                    if (Boolean.TryParse(sv.Value, out isfolding))
                    {
                        foldS.IsFolded = isfolding;
                    }
                }
            }

            this.editor.Document.UpdateFoldSegments(list, true);

            //foreach (int bm in fileSeting.Bookmarks){
            foreach (MyBookmark bm in fileSeting.Bookmarks2)
            {
                LineSegment ls = this.editor.Document.GetLine(bm.Line);
                if (ls != null)
                {
                    ls.IsBookmarked = true;
                }
                //this.editor.Document.Lines[bm].IsBookmarked = true;
            }
        }