LunarPresentation/Commands/ExTemplate.cs
(开头部分) 9KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Windows;
using System.Xml.Linq;
namespace SHomeWorkshop.LunarPresentation.Commands
{
public partial class Command
{
/// <summary>
/// 将当前公式添加为一个模板。
/// </summary>
/// <param name="cmdString">应传入自定义的命令文本(必须是全英文,分大小写)。命令不能与已存在的某个模板的命令重复。</param>
public static bool ExTemplateAdd(string cmdString)
{
if (Globals.selectedEditor == null) return false;
if (Globals.selectedEditor.SelectedExpression == null) return false;
if (cmdString == null || cmdString.Length <= 0)
{
MessageBox.Show("请为新公式模板设置一个(纯字母组成的)字符串作为调用命令!\r\n\r\n" +
"自定义命令应跟随两个斜杠“//”之后。\r\n\r\n" +
"在将当前公式设置为模板后,可以使用“/(命令文本)”的格式(单斜框,括号不输入)来直接插入此模板!",
Globals.appName, MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
LunarPresentation.Expressions.Expression curEx
= Globals.selectedEditor.SelectedExpression;
if (curEx is Expressions.SubPanel)
{
MessageBox.Show("子面板不能被设置为公式模板!", Globals.appName,
MessageBoxButton.OK, MessageBoxImage.Warning);
return false;//子面板不支持。
}
string templateFilePath = Globals.pathOfUserDirectory + "DefTemplates.xml";
if (Globals.templateXDoc == null)
{
if (System.IO.File.Exists(templateFilePath))
{
try
{
Globals.templateXDoc = XDocument.Load(templateFilePath);
if (Globals.templateXDoc.Root == null)
{
Globals.templateXDoc.Add(new XElement("Templates"));
}
if (Globals.templateXDoc.Root.Name.ToString() != "Templates")
{
Globals.templateXDoc.RemoveNodes();
Globals.templateXDoc.Add(new XElement("Templates"));
}
}
catch
{
后面还有 171 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。