Skip to content

Commit 0c10b22

Browse files
committed
协议工具 - 显示保存
1 parent 4aad349 commit 0c10b22

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

‎Fantasy.Packages/Fantasy.ProtocolEditor/Models/EditorTab.cs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,25 @@ public EditorTab(string filePath, EditorType editorType)
8484
_document = new TextDocument();
8585
_editorType = editorType;
8686
}
87+
88+
string _nameCache = string.Empty;
89+
const string UnSaved = "(未保存)";
90+
91+
partial void OnIsModifiedChanged(bool value)
92+
{
93+
if (value)
94+
{
95+
// 文件名加上星号
96+
if(!FileName.StartsWith(UnSaved))
97+
{
98+
_nameCache = _fileName;
99+
FileName = $"{UnSaved}{_fileName}";
100+
}
101+
}
102+
else
103+
{
104+
// 恢复原始文件名
105+
FileName = _nameCache;
106+
}
107+
}
87108
}

‎Fantasy.Packages/Fantasy.ProtocolEditor/Views/MainWindow.axaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@
127127

128128
<!-- 保存按钮 -->
129129
<Button Grid.Column="1"
130-
Content="💿"
131-
ToolTip.Tip="Save All (Ctrl+S)"
130+
Content=""
131+
ToolTip.Tip="Save Changes (Ctrl+S)"
132132
Background="Transparent"
133133
BorderThickness="0"
134134
Foreground="#CCCCCC"
@@ -165,7 +165,7 @@
165165

166166
<!-- 导出协议按钮 -->
167167
<Button Grid.Column="3"
168-
Content=""
168+
Content="🚀"
169169
ToolTip.Tip="Export Protocols"
170170
Background="Transparent"
171171
BorderThickness="0"

‎Fantasy.Packages/Fantasy.ProtocolEditor/Views/MainWindow.axaml.cs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private void InitializeTextEditor()
252252

253253
if (DataContext is MainWindowViewModel vm)
254254
{
255-
vm.OutputText += "编辑器已就绪,支持 Protobuf 语法高亮、验证和自动补全\n";
255+
vm.OutputText += "编辑器已就绪。\n";
256256
}
257257
}
258258

@@ -567,6 +567,16 @@ private void OnDocumentTextChanged(object? sender, EventArgs e)
567567
// 重启计时器(防止频繁验证)
568568
_validationTimer?.Stop();
569569
_validationTimer?.Start();
570+
571+
if (DataContext is MainWindowViewModel vm)
572+
{
573+
var activeTab = vm.ActiveTab;
574+
if (activeTab != null)
575+
{
576+
// ��记当前活动的标签页为已修改
577+
activeTab.IsModified = true;
578+
}
579+
}
570580
}
571581

572582
/// <summary>
@@ -602,9 +612,17 @@ private void ValidateDocument()
602612
// 刷新视图
603613
TextEditor.TextArea.TextView.Redraw();
604614

605-
// 输出错误信息到控制台
615+
// 更新 MainWindowViewModel 信息输出
606616
if (DataContext is MainWindowViewModel vm)
607617
{
618+
// 更新语法相关信息
619+
foreach (Models.EditorTab tab in vm.OpenedTabs) {
620+
if (tab.Document == TextEditor.Document)
621+
{
622+
vm.OutputText += tab.IsModified? $"{tab.FileName}\n" : "";
623+
}
624+
}
625+
608626
// 如果之前有错误输出,先删除它
609627
if (_lastErrorOutputPosition >= 0 && _lastErrorOutputPosition < vm.OutputText.Length)
610628
{

0 commit comments

Comments
 (0)