Example #1
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;
            }
        }
Example #2
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;
            }
        }