Пример #1
0
        public DocumentPanel(string fileName)
        {
            InitializeComponent();
            _fileName = fileName;
            TabText = _fileName;
            if (PlatformSupport.Platform == PlatformType.Windows)
            {
                Icon = Properties.Resources.document_properties;

                // SharpDevelop text editor is Windows only.
                var txtDocument = new TextEditorControl {Dock = DockStyle.Fill, IsReadOnly = true, Name = "txtDocument"};
                Controls.Add(txtDocument);

                txtDocument.SetHighlighting("SMI"); // Activate the highlighting, use the name from the SyntaxDefinition node.
                txtDocument.LoadFile(_fileName);
            }
            else
            {
                var txtDocument = new RichTextBox {Dock = DockStyle.Fill, Name = "txtDocument", ReadOnly = true};
                Controls.Add(txtDocument);

                txtDocument.LoadFile(_fileName, RichTextBoxStreamType.PlainText);
            }
        }
Пример #2
0
 public void Load(Stream stream)
 {
     _editor.LoadFile("", stream, true, true);
     _lastTextSet = Text;
 }
Пример #3
0
        public TabInfo Open(string file, OpenType type, bool addToMRU = true, bool alwaysNew = false)
        {
            if (type == OpenType.File) {
                if (!Path.IsPathRooted(file)) {
                    file = Path.GetFullPath(file);
                }
                //Add this file to the recent files list
                if (addToMRU) {
                    Settings.AddRecentFile(file);
                }
                UpdateRecentList();
                //If this is an int, decompile
                if (string.Compare(Path.GetExtension(file), ".int", true) == 0) {
                    var compiler = new Compiler();
                    string decomp = compiler.Decompile(file);
                    if (decomp == null) {
                        MessageBox.Show("Decompilation of '" + file + "' was not successful", "Error");
                        return null;
                    } else {
                        file = decomp;
                        type = OpenType.Text;
                    }
                } else {
                    //Check if the file is already open
                    for (int i = 0; i < tabs.Count; i++) {
                        if (string.Compare(tabs[i].filepath, file, true) == 0) {
                            tabControl1.SelectTab(i);
                            return tabs[i];
                        }
                    }
                }
            }
            //Create the text editor and set up the tab
            ICSharpCode.TextEditor.TextEditorControl te = new ICSharpCode.TextEditor.TextEditorControl();
            te.ShowVRuler = false;
            te.Document.FoldingManager.FoldingStrategy = new CodeFolder();
            te.IndentStyle = IndentStyle.Smart;
            te.ConvertTabsToSpaces = Settings.tabsToSpaces;
            te.TabIndent = Settings.tabSize;
            te.Document.TextEditorProperties.IndentationSize = Settings.tabSize;
            if (type == OpenType.File)
                te.LoadFile(file, false, true);
            else if (type == OpenType.Text)
                te.Text = file;
            if (type == OpenType.File && string.Compare(Path.GetExtension(file), ".msg", true) == 0)
                te.SetHighlighting("msg");
            else
                te.SetHighlighting("ssl"); // Activate the highlighting, use the name from the SyntaxDefinition node.
            te.TextChanged += textChanged;
            te.ActiveTextAreaControl.TextArea.MouseDown += delegate(object a1, MouseEventArgs a2) {
                if (a2.Button == MouseButtons.Left)
                    UpdateEditorToolStripMenu();
                lbAutocomplete.Hide();
            };
            te.ActiveTextAreaControl.TextArea.KeyPress += KeyPressed;
            te.HorizontalScroll.Visible = false;

            te.ActiveTextAreaControl.TextArea.PreviewKeyDown += delegate(object sender, PreviewKeyDownEventArgs a2) {
                if (lbAutocomplete.Visible) {
                    if ((a2.KeyCode == Keys.Down || a2.KeyCode == Keys.Up || a2.KeyCode == Keys.Tab)) {
                        lbAutocomplete.Focus();
                        lbAutocomplete.SelectedIndex = 0;
                    } else if (a2.KeyCode == Keys.Escape) {
                        lbAutocomplete.Hide();
                    }
                } else {
                    if (toolTipAC.Active && a2.KeyCode != Keys.Left && a2.KeyCode != Keys.Right)
                        toolTipAC.Hide(panel1);
                }
            };

            TabInfo ti = new TabInfo();
            ti.textEditor = te;
            ti.changed = false;
            if (type == OpenType.File && !alwaysNew) {
                ti.filepath = file;
                ti.filename = Path.GetFileName(file);
            } else {
                ti.filepath = null;
                ti.filename = unsaved;
            }
            ti.index = tabControl1.TabCount;
            te.ActiveTextAreaControl.TextArea.ToolTipRequest += new ToolTipRequestEventHandler(TextArea_ToolTipRequest);
            te.ContextMenuStrip = editorMenuStrip;

            tabs.Add(ti);
            TabPage tp = new TabPage(ti.filename);
            tp.Controls.Add(te);
            te.Dock = DockStyle.Fill;

            tabControl1.TabPages.Add(tp);
            if (type == OpenType.File & !alwaysNew) {
                tp.ToolTipText = ti.filepath;
                System.String ext = Path.GetExtension(file).ToLower();
                if (ext == ".ssl" || ext == ".h") {
                    ti.shouldParse = true;
                    ti.needsParse = true;
                    if (Settings.autoOpenMsgs && ti.filepath != null)
                        AssossciateMsg(ti, false);
                }
            }
            if (tabControl1.TabPages.Count > 1) {
                tabControl1.SelectTab(tp);
            } else {
                tabControl1_Selected(null, null);
            }
            return ti;
        }
Пример #4
0
        private void OpenFiles(string[] fns, string caption)
        {
            // Open file(s)
            foreach (string fn in fns)
            {
                FrmDocument dummyDoc = new FrmDocument(); ;
                TextEditorControl editor = new TextEditorControl();

                try
                {
                    if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
                    {
                        dummyDoc = CreateNewDocument(Path.GetFileName(fn));
                        dummyDoc.MdiParent = this;
                        dummyDoc.Show();
                    }
                    else
                    {
                        foreach (IDockContent content in dockPanel.Documents)
                        {
                            dummyDoc = content as FrmDocument;
                            if (dummyDoc != null)
                            {
                                editor = dummyDoc.Controls[0] as TextEditorControl;
                                if (editor.FileName == fn)
                                {
                                    content.DockHandler.Show();
                                    return;
                                }
                            }
                        }

                        dummyDoc = CreateNewDocument(Path.GetFileName(fn));
                        editor = dummyDoc.Controls[0] as TextEditorControl;
                        editor.LoadFile(fn);
                        editor.Document.DocumentChanged += new DocumentEventHandler(Document_DocumentChanged);
                        // Modified flag is set during loading because the document 
                        // "changes" (from nothing to something). So, clear it again.
                        SetModifiedFlag(editor, false);
                        if (!String.IsNullOrEmpty(caption))
                            dummyDoc.Text = caption;
                        dummyDoc.LastWriteTime = new FileInfo(fn).LastWriteTime;
                        dummyDoc.Show(dockPanel);
                    }
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().Name);
                    dummyDoc.Close();
                    dummyDoc.Dispose();
                    return;
                }

                // ICSharpCode.TextEditor doesn't have any built-in code folding
                // strategies, so I've included a simple one. Apparently, the
                // foldings are not updated automatically, so in this demo the user
                // cannot add or remove folding regions after loading the file.
                editor.Document.FoldingManager.FoldingStrategy = new RegionFoldingStrategy();
                editor.Document.FoldingManager.UpdateFoldings(null, null);
            }
        }
Пример #5
0
        private void Init()
        {
            //sourceCodeTextEditorControl = this.FindName("sourceCodeTextEditorControl") as TextEditorControl;
            editor = winFormHost.Child as TextEditorControl;

            if (!Directory.Exists("Teszt"))
                Directory.CreateDirectory("Teszt");
            if (File.Exists("Teszt\\teszt.psi"))
                editor.LoadFile("Teszt\\teszt.psi");

            // DynamicHighLight Settings
            HighlightingManager.Manager.AddSyntaxModeFileProvider(new FileSyntaxModeProvider(@"References\SyntaxRes\"));

            // HighLightting Strategy Name is Psimulex
            editor.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("Psimulex");

            currentCommandToHighLight = 0;
        }