コード例 #1
0
ファイル: MainForm.cs プロジェクト: jojozhuang/Projects
 public void ShowTaskEditor(TaskInfo task)
 {
     FrmTaskEditor frmtaskeditor = new FrmTaskEditor();
     frmtaskeditor.TaskId = task.TaskId;
     frmtaskeditor.TaskName = task.TaskName;
     frmtaskeditor.GroupName = task.GroupName;
     frmtaskeditor.Text = task.TaskName;
     frmtaskeditor.taskSaved += new FrmTaskEditor.TaskSavedEventHandler(frmtaskeditor_taskSaved);
     if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
     {
         frmtaskeditor.MdiParent = this;
         frmtaskeditor.Show();
     }
     else
     {
         foreach (IDockContent content in dockPanel.Documents)
         {
             FrmTaskEditor form = content as FrmTaskEditor;
             if (form != null && form.TaskId == task.TaskId)
             {
                 content.DockHandler.Show();
                 return;
             }
         }
         frmtaskeditor.Show(dockPanel);
     }
 }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: jojozhuang/Projects
        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;
        }