Exemplo n.º 1
0
        /// <summary>
        /// Creates a new code editor.
        /// </summary>
        /// <param name="file">The associated file.</param>
        public Designer(File file)
            : base(file)
        {
            InitializeComponent();

            // Listen for events.
            file.Project.FileRenamed += new EventHandler<FileEventArgs>((sender, e) =>
            {
                if (e.File == this.File)
                {
                    if (this.c_CodeEditor.Text != this.m_SavedText)
                        this.TabText = this.File.FileInfo.Name + " *";
                    else
                        this.TabText = this.File.FileInfo.Name;
                }
            });

            // Initialize the code editor.
            this.c_CodeEditor = new CodeEditor(
                Central.Manager.CacheManager,
                (this.File.FileInfo.Extension.Substring(1) == "lua" ||
                 this.File.FileInfo.Extension.Substring(1) == "rks" ||
                 this.File.FileInfo.Extension.Substring(1) == "rs")
                );
            this.c_CodeEditor.DwellStart += new EventHandler<ScintillaNet.ScintillaMouseEventArgs>(c_CodeEditor_DwellStart);
            this.c_CodeEditor.DwellEnd += new EventHandler<ScintillaNet.ScintillaMouseEventArgs>(c_CodeEditor_DwellEnd);
            this.c_CodeEditor.KeyUp += new KeyEventHandler(c_CodeEditor_KeyUp);
            this.c_CodeEditor.SyntaxCheckRequested += new EventHandler(c_CodeEditor_SyntaxCheckRequested);
            this.c_CodeEditor.SelectionChanged += new EventHandler(c_CodeEditor_SelectionChanged);
            this.c_CodeEditor.GotFocus += new EventHandler(c_CodeEditor_GotFocus);
            this.c_CodeEditor.LostFocus += new EventHandler(c_CodeEditor_LostFocus);
            this.c_CodeEditor.MarginClick += new EventHandler<ScintillaNet.MarginClickEventArgs>(c_CodeEditor_MarginClick);

            // Initalize the context menu for the code editor.
            this.c_CodeEditor.ContextMenuStrip = ActionWrapper.GetContextMenu(new Platform.Menus.Action[]
            {
                    new Platform.Menus.Definitions.Actions.Undo(this.c_CodeEditor),
                    new Platform.Menus.Definitions.Actions.Redo(this.c_CodeEditor),
                    new SeperatorAction(),
                    new Platform.Menus.Definitions.Actions.Cut(this.c_CodeEditor),
                    new Platform.Menus.Definitions.Actions.Copy(this.c_CodeEditor),
                    new Platform.Menus.Definitions.Actions.Paste(this.c_CodeEditor),
                    new Platform.Menus.Definitions.Actions.Delete(this.c_CodeEditor)
            });

            // Now load the file data.
            using (System.IO.StreamReader reader = new System.IO.StreamReader(this.File.FileInfo.FullName))
            {
                this.c_CodeEditor.Text = reader.ReadToEnd();
            }
            this.m_SavedText = this.c_CodeEditor.Text;

            // Load the breakpoints.
            string relname = PathHelpers.GetRelativePath(this.File.Project.ProjectInfo.DirectoryName, this.File.FileInfo.FullName);
            List<IBreakpoint> breakpoints = Central.Manager.DebugManager.Breakpoints.Where(result => result.SourceFile == relname).ToList();
            foreach (IBreakpoint b in breakpoints)
            {
                this.c_CodeEditor.Lines[(int)b.SourceLine - 1].AddMarker(0);
            }

            // Detect if this file is read-only.
            this.p_CanSave = !this.File.FileInfo.IsReadOnly;
            if (this.p_CanSave)
                this.TabText = this.File.FileInfo.Name;
            else
            {
                this.TabText = this.File.FileInfo.Name + " (Read Only)";
                this.c_CodeEditor.NativeInterface.SetReadOnly(true);
            }

            // Add the code editor to the tab.
            this.Controls.Add(this.c_CodeEditor);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new code editor.
        /// </summary>
        /// <param name="file">The associated file.</param>
        public Designer(File file)
            : base(file)
        {
            InitializeComponent();

            // Listen for events.
            file.Project.FileRenamed += new EventHandler <FileEventArgs>((sender, e) =>
            {
                if (e.File == this.File)
                {
                    if (this.c_CodeEditor.Text != this.m_SavedText)
                    {
                        this.TabText = this.File.FileInfo.Name + " *";
                    }
                    else
                    {
                        this.TabText = this.File.FileInfo.Name;
                    }
                }
            });

            // Initialize the code editor.
            this.c_CodeEditor = new CodeEditor(
                Central.Manager.CacheManager,
                (this.File.FileInfo.Extension.Substring(1) == "lua" ||
                 this.File.FileInfo.Extension.Substring(1) == "rks" ||
                 this.File.FileInfo.Extension.Substring(1) == "rs")
                );
            this.c_CodeEditor.DwellStart           += new EventHandler <ScintillaNet.ScintillaMouseEventArgs>(c_CodeEditor_DwellStart);
            this.c_CodeEditor.DwellEnd             += new EventHandler <ScintillaNet.ScintillaMouseEventArgs>(c_CodeEditor_DwellEnd);
            this.c_CodeEditor.KeyUp                += new KeyEventHandler(c_CodeEditor_KeyUp);
            this.c_CodeEditor.SyntaxCheckRequested += new EventHandler(c_CodeEditor_SyntaxCheckRequested);
            this.c_CodeEditor.SelectionChanged     += new EventHandler(c_CodeEditor_SelectionChanged);
            this.c_CodeEditor.GotFocus             += new EventHandler(c_CodeEditor_GotFocus);
            this.c_CodeEditor.LostFocus            += new EventHandler(c_CodeEditor_LostFocus);
            this.c_CodeEditor.MarginClick          += new EventHandler <ScintillaNet.MarginClickEventArgs>(c_CodeEditor_MarginClick);

            // Initalize the context menu for the code editor.
            this.c_CodeEditor.ContextMenuStrip = ActionWrapper.GetContextMenu(new Platform.Menus.Action[]
            {
                new Platform.Menus.Definitions.Actions.Undo(this.c_CodeEditor),
                new Platform.Menus.Definitions.Actions.Redo(this.c_CodeEditor),
                new SeperatorAction(),
                new Platform.Menus.Definitions.Actions.Cut(this.c_CodeEditor),
                new Platform.Menus.Definitions.Actions.Copy(this.c_CodeEditor),
                new Platform.Menus.Definitions.Actions.Paste(this.c_CodeEditor),
                new Platform.Menus.Definitions.Actions.Delete(this.c_CodeEditor)
            });

            // Now load the file data.
            using (System.IO.StreamReader reader = new System.IO.StreamReader(this.File.FileInfo.FullName))
            {
                this.c_CodeEditor.Text = reader.ReadToEnd();
            }
            this.m_SavedText = this.c_CodeEditor.Text;

            // Load the breakpoints.
            string             relname     = PathHelpers.GetRelativePath(this.File.Project.ProjectInfo.DirectoryName, this.File.FileInfo.FullName);
            List <IBreakpoint> breakpoints = Central.Manager.DebugManager.Breakpoints.Where(result => result.SourceFile == relname).ToList();

            foreach (IBreakpoint b in breakpoints)
            {
                this.c_CodeEditor.Lines[(int)b.SourceLine - 1].AddMarker(0);
            }

            // Detect if this file is read-only.
            this.p_CanSave = !this.File.FileInfo.IsReadOnly;
            if (this.p_CanSave)
            {
                this.TabText = this.File.FileInfo.Name;
            }
            else
            {
                this.TabText = this.File.FileInfo.Name + " (Read Only)";
                this.c_CodeEditor.NativeInterface.SetReadOnly(true);
            }

            // Add the code editor to the tab.
            this.Controls.Add(this.c_CodeEditor);
        }