Example #1
0
 public override void OnDisable()
 {
     if (packageExtends != null)
     {
         foreach (var item in packageExtends)
         {
             item.valueChanged.RemoveListener(window.Repaint);
         }
     }
     if (pluginExtends != null)
     {
         foreach (var item in pluginExtends)
         {
             item.valueChanged.RemoveListener(window.Repaint);
         }
     }
     if (RemotepluginExtends != null)
     {
         foreach (var item in RemotepluginExtends)
         {
             item.valueChanged.RemoveListener(window.Repaint);
         }
     }
     if (doc != null)
     {
         doc.Release();
         doc = null;
     }
     base.OnDisable();
 }
        public override void OnGUI()
        {
            base.OnGUI();
            //CheckDoc
            MarkDownDoc doc = null;

            if (string.IsNullOrEmpty(CurrentDocName))
            {
                if (Docs.TryGetValue("Index", out doc))
                {
                    CurrentDocName = "Index";
                }
            }
            else
            {
                doc = Docs[CurrentDocName];
                if (Event.current.type == EventType.Layout)
                {
                    if (DocPages.Count > 0)
                    {
                        var oldDoc = Docs[DocPages.Peek()];
                        if (oldDoc.datas.Count > 0)
                        {
                            oldDoc.Release();
                        }
                    }
                    if (doc.datas.Count == 0)
                    {
                        doc.Load();
                    }
                    else
                    {
                        if (AutoRefresh && doc.RawDoc.text != doc.rawDoc)
                        {
                            doc.Release();
                            doc.rawDoc = doc.RawDoc.text;
                            doc.Load();
                        }
                    }
                }
            }
            //DrawDoc
            if (doc != null)
            {
                //ToolBar
                ToolBar();
                //DocContent
                EditorGUI.DrawRect(DrawRect, ColorPalette.Get(ColorSettings, "BackGround", Color.white));
                v = GUILayout.BeginScrollView(v);
                {
                    if (searched != null)
                    {
                        if (Event.current.type == EventType.Repaint)
                        {
                            EditorGUI.DrawRect(searched.drawRect, ColorPalette.Get(ColorSettings, "HightLight", Color.white));
                        }
                        if (Search.Current.IsNullOrEmpty())
                        {
                            searched = null;
                        }
                    }
                    EditorMarkDownDrawer.DrawDoc(doc, changePage, changeDoc, window.Repaint);
                }
                GUILayout.EndScrollView();
                if (Event.current.type == EventType.Repaint)
                {
                    DrawRect = GUILayoutUtility.GetLastRect();
                }
            }
            else
            {
                EditorGUILayout.SelectableLabel("Can't find Index.md Document at :" + PathTools.RelativeAssetPath(this.GetType(), RelativePath));
                EditorGUILayout.SelectableLabel("First you should create default page");
                if (GUILayout.Button("CreateReadMe"))
                {
                    if (EditorUtility.DisplayDialog("CreateIndex.md", "After create .md file,you have to reopen this editorwindow.", "OK", "Cancel"))
                    {
                        //Template
                        string[]  assets = AssetDatabase.FindAssets("TMP_ReadMe");
                        TextAsset text   = AssetDatabase.LoadAssetAtPath <TextAsset>(AssetDatabase.GUIDToAssetPath(assets[0]));
                        //
                        var DirRoot     = PathTools.RelativeAssetPath(this.GetType(), RelativePath);
                        var FileDirRoot = Directory.GetParent(DirRoot).FullName + @"\" + Path.GetFileName(DirRoot);
                        if (!Directory.Exists(FileDirRoot))
                        {
                            Directory.CreateDirectory(FileDirRoot);
                        }
                        FileTools.WriteAllText(FileDirRoot + "/Index.md", text.text);

                        AssetDatabase.Refresh();
                        window.Close();
                    }
                }
            }
            //PingDocScript
            if (EditScript)
            {
                GUILayout.BeginHorizontal();
                {
                    AutoRefresh = GUILayout.Toggle(AutoRefresh, "自动刷新");
                    OnGUIUtility.ScriptField("Editor Script", this.GetType());
                }
                GUILayout.EndHorizontal();
            }
        }