Example #1
0
        private FrmDocument CreateNewDocument(string text)
        {
            FrmDocument dummyDoc = new FrmDocument();
            dummyDoc.Text = text;

            _editor = dummyDoc.Controls[0] as TextEditorControl;           
            if (_editorSettings == null)
            {
                _editorSettings = _editor.TextEditorProperties;
                OnSettingsChanged();
            }
            else
                _editor.TextEditorProperties = _editorSettings;

            return dummyDoc;
        }
Example #2
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);
            }
        }
Example #3
0
        private IDockContent GetContentFromPersistString(string persistString)
        {
            if (persistString == typeof(FrmTaskManager).ToString())
                return _taskManagerForm;
            else if (persistString == typeof(FrmProperty).ToString())
                return _propertyForm;
            else if (persistString == typeof(FrmToolbox).ToString())
                return _toolboxForm;
            else if (persistString == typeof(FrmOutput).ToString())
                return _outputForm;
            else if (persistString == typeof(DummyTaskList).ToString())
                return _taskListForm;
            else if (persistString == typeof(FrmAccountManager).ToString())
                return _accountManagerForm;
            else
            {
                string[] parsedStrings = persistString.Split(new char[] { ',' });
                if (parsedStrings.Length == 3)
                {
                    if (parsedStrings[0] != typeof(FrmDocument).ToString())
                        return null;

                    FrmDocument dummyDoc = new FrmDocument();
                    TextEditorControl editor;
                    if (parsedStrings[1] != string.Empty && parsedStrings[2] != string.Empty)
                    {
                        if (!File.Exists(parsedStrings[1]))
                            return null;

                        dummyDoc = CreateNewDocument(Path.GetFileName(parsedStrings[1]));
                        editor = dummyDoc.Controls[0] as TextEditorControl;
                        editor.LoadFile(parsedStrings[1]);
                        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(parsedStrings[2]))
                            dummyDoc.Text = parsedStrings[2];
                        dummyDoc.LastWriteTime = new FileInfo(parsedStrings[1]).LastWriteTime;
                        dummyDoc.Show(dockPanel);
                    }
                    else
                    {
                        dummyDoc = CreateNewDocument("新文档");
                        editor = dummyDoc.Controls[0] as TextEditorControl;
                        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);
                        dummyDoc.Show(dockPanel);
                    }
                    //文档已经打开,只是为了符合函数返回类型               
                    return dummyDoc;
                }
                else if (parsedStrings.Length == 5)
                {
                    if (parsedStrings[0] != typeof(FrmTaskEditor).ToString())
                        return null;

                    if (parsedStrings[1] != string.Empty && parsedStrings[2] != string.Empty && parsedStrings[3] != string.Empty && parsedStrings[4] != string.Empty)
                    {
                        Collection<TaskInfo> tasks = ConfigCtrl.GetSimpleTasks();
                        foreach (TaskInfo task in tasks)
                        {
                            if (task.TaskId == parsedStrings[1] &&
                                task.TaskName == parsedStrings[2] &&
                                task.GroupName == parsedStrings[3])
                            {
                                FrmTaskEditor frmtaskeditor = new FrmTaskEditor();
                                frmtaskeditor.TaskId = parsedStrings[1];
                                frmtaskeditor.TaskName = parsedStrings[2];
                                frmtaskeditor.GroupName = parsedStrings[3];
                                frmtaskeditor.Text = parsedStrings[4];
                                frmtaskeditor.taskSaved += new FrmTaskEditor.TaskSavedEventHandler(frmtaskeditor_taskSaved);
                                frmtaskeditor.Show(dockPanel);
                                return frmtaskeditor;
                            }
                        }                        
                    }
                }
                else
                {
                    return null;
                }
            }

            return null;
        }