/// <summary> /// 初始化数据库啥的 /// </summary> /// <param name="e"></param> protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); #if CONSOLE ConsoleHelper.Show(); #endif MarkdownViewer.SetRenderHook(new RenderHook()); SqliteHelper.Init(Path.GetFullPath("./tesla.db")); FileCacheHelper.AppCacheDirectory = string.Format("{0}\\{1}\\Cache\\", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Process.GetCurrentProcess().ProcessName); }
private void FillMd(int selectedIndex) { string name = tabNames[selectedIndex]; var content = dicTexts[name]; var path = MdFullPath(name); mViewer = new MarkdownViewer(Skin, path, content); EditorApplication.update += delegate { if (mViewer != null && mViewer.Update()) { Repaint(); } }; }
public void OnDispose() { mPackageKitWindow = null; mSplitView = null; mDisposableList.Dispose(); mDisposableList = null; mCategoriesSelectorView = null; mLeftLayout.Dispose(); mLeftLayout = null; mRightLayout.Dispose(); mRightLayout = null; mMarkdownViewer = null; }
public override void OnApplyTemplate() { _markDownControl = GetTemplateElement <MarkdownViewer>(MarkDownControl); _markDownControl.Pipeline = BuildPipeline(); _markDownControl.CommandBindings.Add(new CommandBinding(Commands.Hyperlink, ExecuteHyperlink)); _updateButton = GetTemplateElement <Button>(PartUpdateButton); _updateButton.Click += UpdateButton_Click; _textBox = GetTemplateElement <TextBox>(PartTextBox); GenerateDocument(Text); _textBox.TextChanged += TextBox_TextChanged; _pinButton = GetTemplateElement <Button>(PinButton); _pinButton.Click += PinButton_Click; _autoUpdateButton = GetTemplateElement <Button>(AutoUpdateButton); _autoUpdateButton.Click += AutoUpdateButton_Click; }
/// <summary> /// /// </summary> /// <param name="markdownViewer"></param> public MarkdownViewerRenderer(MarkdownViewer markdownViewer) : base(markdownViewer) { }
public void Init(IQFrameworkContainer container) { Container = container; var localPackageVersionModel = this.GetModel <ILocalPackageVersionModel>(); // 左侧 mLeftLayout = EasyIMGUI.Vertical() .AddChild(EasyIMGUI.Area().WithRectGetter(() => mLeftRect) // 间距 20 .AddChild(EasyIMGUI.Vertical() .AddChild(EasyIMGUI.Space().Pixel(20))) // 搜索 .AddChild(EasyIMGUI.Horizontal() .AddChild(EasyIMGUI.Label().Text("搜索:") .FontBold() .FontSize(12) .Width(40) ).AddChild(EasyIMGUI.TextField() .Height(20) .Self(search => { search.Content .Bind(key => { this.SendCommand(new SearchCommand(key)); }) .AddToDisposeList(mDisposableList); }) ) ) // 权限 .AddChild(EasyIMGUI.Toolbar() .Menus(new List <string>() { "All", PackageAccessRight.Public.ToString(), PackageAccessRight.Private.ToString() }) .Self(self => { self.IndexProperty.Bind(value => { PackageManagerState.AccessRightIndex.Value = value; this.SendCommand(new SearchCommand(PackageManagerState.SearchKey.Value)); }).AddToDisposeList(mDisposableList); })) // 分类 .AddChild( EasyIMGUI.Horizontal() .AddChild(PopupView.Create() .ToolbarStyle() .Self(self => { self.IndexProperty.Bind(value => { PackageManagerState.CategoryIndex.Value = value; this.SendCommand(new SearchCommand(PackageManagerState.SearchKey.Value)); }).AddToDisposeList(mDisposableList); mCategoriesSelectorView = self; })) ) // 是否是官方 .AddChild( EasyIMGUI.Horizontal() .AddChild(EasyIMGUI.Toggle().IsOn(mIsOfficial) .Self(t => t.ValueProperty.Bind(v => mIsOfficial = v))) .AddChild(EasyIMGUI.Label().Text("官方")) .AddChild(EasyIMGUI.FlexibleSpace()) ) .AddChild(EasyIMGUI.Scroll() .AddChild(EasyIMGUI.Custom().OnGUI(() => { PackageManagerState.PackageRepositories.Value .Where(p => p.isOfficial == mIsOfficial) .OrderByDescending(p => { var installedVersion = localPackageVersionModel.GetByName(p.name); if (installedVersion == null) { return(-1); } else if (installedVersion.VersionNumber < p.VersionNumber) { return(2); } else if (installedVersion.VersionNumber == p.VersionNumber) { return(1); } else { return(0); } }) .ThenBy(p => p.name) .ForEach(p => { GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal(); { GUILayout.Label(p.name); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { EasyIMGUI.Box().Text(p.latestVersion) .Self(self => self.BackgroundColor = Color.green) .DrawGUI(); GUILayout.FlexibleSpace(); var installedVersion = localPackageVersionModel.GetByName(p.name); if (installedVersion == null) { if (GUILayout.Button(LocaleText.Import)) { RenderEndCommandExecutor.PushCommand(() => { this.SendCommand(new ImportPackageCommand(p)); }); } } else if (installedVersion.VersionNumber < p.VersionNumber) { if (GUILayout.Button(LocaleText.Update)) { RenderEndCommandExecutor.PushCommand(() => { this.SendCommand(new UpdatePackageCommand(p)); }); } } else if (installedVersion.VersionNumber == p.VersionNumber) { if (GUILayout.Button(LocaleText.Reimport)) { RenderEndCommandExecutor.PushCommand(() => { this.SendCommand(new ReimportPackageCommand(p)); }); } } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); var rect = GUILayoutUtility.GetLastRect(); if (mSelectedPackageRepository == p) { GUI.Box(rect, "", mSelectionRect); } if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseUp) { mSelectedPackageRepository = p; Event.current.Use(); } }); })) ) ); // var skin = AssetDatabase.LoadAssetAtPath<GUISkin>( var skin = AssetDatabase.LoadAssetAtPath <GUISkin>( "Assets/QFramework/Framework/Toolkits/Core/Editor/Markdown/Skin/MarkdownSkinQS.guiskin"); mMarkdownViewer = new MarkdownViewer(skin, string.Empty, ""); // 右侧 mRightLayout = EasyIMGUI.Vertical() .AddChild(EasyIMGUI.Area().WithRectGetter(() => mRightRect) // 间距 20 .AddChild(EasyIMGUI.Vertical() .AddChild(EasyIMGUI.Space().Pixel(20)) ) // 详细信息 .AddChild(EasyIMGUI.Vertical() .WithVisibleCondition(() => mSelectedPackageRepository != null) // 名字 .AddChild(EasyIMGUI.Label() .TextGetter(() => mSelectedPackageRepository.name) .FontSize(30) .FontBold()) .AddChild(EasyIMGUI.Space()) // 服务器版本 .AddChild(EasyIMGUI.Label() .TextGetter(() => "服务器版本: " + mSelectedPackageRepository.latestVersion) .FontSize(15)) // 本地版本 .AddChild(EasyIMGUI.Label() .WithVisibleCondition(() => localPackageVersionModel.GetByName(mSelectedPackageRepository.name).IsNotNull()) .TextGetter(() => "本地版本:" + localPackageVersionModel.GetByName(mSelectedPackageRepository.name).Version) .FontSize(15)) // 作者 .AddChild(EasyIMGUI.Label() .TextGetter(() => "作者:" + mSelectedPackageRepository.author) .FontSize(15)) // 权限 .AddChild(EasyIMGUI.Label() .TextGetter(() => "权限:" + mSelectedPackageRepository.accessRight) .FontSize(15)) // 主页 .AddChild( EasyIMGUI.Horizontal() .AddChild(EasyIMGUI.Label() .FontSize(15) .Text("插件主页:")) .AddChild(EasyIMGUI.Button() .TextGetter(() => UrlHelper.PackageUrl(mSelectedPackageRepository)) .FontSize(15) .OnClick(() => { this.SendCommand(new OpenDetailCommand(mSelectedPackageRepository)); }) ) .AddChild(EasyIMGUI.FlexibleSpace()) ) // 描述 .AddChild(EasyIMGUI.Label() .TextGetter(() => "描述:") .FontSize(15) ) .AddChild(EasyIMGUI.Space()) // 描述内容 .AddChild(EasyIMGUI.Custom().OnGUI(() => { mMarkdownViewer.UpdateText(mSelectedPackageRepository.description); var lastRect = GUILayoutUtility.GetLastRect(); mMarkdownViewer.DrawWithRect(new Rect(lastRect.x, lastRect.y + lastRect.height, mRightRect.width - 210, mRightRect.height - lastRect.y - lastRect.height)); // mMarkdownViewer.Draw(); })) ) ); mPackageKitWindow = EditorWindow.GetWindow <PackageKitWindow>(); this.SendCommand <PackageManagerInitCommand>(); PackageManagerState.Categories.Bind(value => { mCategoriesSelectorView.Menus(value); mPackageKitWindow.Repaint(); }).AddToDisposeList(mDisposableList); // 创建双屏 mSplitView = mSplitView = new VerticalSplitView { Split = 240, fistPan = rect => { mLeftRect = rect; mLeftLayout.DrawGUI(); }, secondPan = rect => { mRightRect = rect; mRightLayout.DrawGUI(); } }; }
/// <summary> /// /// </summary> /// <param name="markdownViewer"></param> public MarkdownViewerBrowser(MarkdownViewer markdownViewer) : base(markdownViewer) { }
/// <summary> /// /// </summary> /// <param name="markdownViewer"></param> public AbstractRenderer(MarkdownViewer markdownViewer) { this.markdownViewer = markdownViewer; InitializeComponent(); Init(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { string text = ""; string stylePath = ""; string assetPath = ""; bool hasText = DA.GetData("Text", ref text); bool hasStylePath = DA.GetData("Styles File", ref stylePath); bool hasAssetPath = DA.GetData("Asset Directory", ref assetPath); if (!hasText) { return; } var MarkdownViewer = new MarkdownViewer(text, stylePath, assetPath); DA.SetData("Markdown Viewer", new UIElement_Goo(MarkdownViewer, "Markdown Viewer", InstanceGuid, DA.Iteration)); // BUT YOU'RE NOT DONE YET!!! // OK, you *might* be done, if all you're creating is a static object to display. But in most cases you'll want to do a few things: // 1. Make sure the element plays nice with the "Value Listener" so that you can get data from user interaction with the element // 2. Create a companion "Set" object so you can modify its contents without re-launching the entire window. This is optional - // but generally any component that displays data or information should do this. (if it just TAKES user input, you're probably fine // without this.) // 3. Make sure the element plays nice with Save/Restore State. // 4. Set behaviors for "Adjust Element Appearance" where appropriate. //Here's how to do those things: // 1. - Value Listener Integration // There are two key methods in the value listener that you will have to augment in order for it to be able to // listen for the appropriate events // with your element. These are ValueListener_Component.RemoveEvents(), and ValueListener_Component.AddEvents(). // For elements where you want to return the index of some user selection in the element, you'll need to modify // HUI_Util.GetElementIndex() as well. // These look pretty similar to each other - big-ass switch statements operating on the type name. For example (AddEvents): //case "System.Windows.Controls.Slider": // Slider s = u as Slider; // s.ValueChanged -= ExpireThis; // s.ValueChanged += ExpireThis; // return; // For RemoveEvents, you'll just get rid of the line that does +=. // I'm not actually totally sure that the removing before adding is totally necessary in AddEvents - my thinking // was that it would prevent events from getting added twice, so I've left it in. // You will want to add your own new case to both of these methods, and attach the "ExpireThis" handler // to whatever method is appropriate depending on your element. You'll need to cast "u" (the arbitrary ui element passed to the methods) // into your specific type to get access to the right events. // 2. - Handle "Setting" values. // See the "Set_TEMPLATE_Component.cs" file in the "UI_Output folder/namespace. // 3. Play nice w/ Save/Restore State // Similar to Value Listener integration, there are a couple more methods to modify. // These live in HUI_Util.cs: // * GetElementValue(UIElement u) // * TrySetElementValue(UIElement u, object o) //As w/ Value Listener, you just have to add a case for your element to the switch statements in each of these. // simple examples w/ textbox: // GetElementValue: // case "System.Windows.Controls.TextBox": // TextBox tb = u as TextBox; // return tb.Text; // TrySetElementValue: // case "System.Windows.Controls.TextBox": // TextBox tb = u as TextBox; // tb.Text = (string)o; // return; // 4. - Adjust Element Appearance compliance // There are default behaviors that work in many cases, but if you want to // override or add behavior, just look at the method ColorTextElement in the // AdjustElementAppearance_Component class - you can add another test case like // the one below: // //Try Textblock // TextBlock textblock = f as TextBlock; // if (textblock != null) // { // textblock.Foreground = foregroundBrush; // if (bgCol != System.Drawing.Color.Transparent) textblock.Background = backgroundBrush; // if (fontSize > 0) textblock.FontSize = fontSize; // return; // } }