DocumentClass 完整定義
public class DocumentClass {
internal DocumentClass(frmMain frm) { myForm = frm; }
private frmMain myForm = null;
public string Text {
get => myForm.txtEditor.Text;
set => myForm.txtEditor.Text = value;
}
public void AppendText(string text) => myForm.txtEditor.AppendText(text);
public string Selection {
get => myForm.txtEditor.SelectedText;
set => myForm.txtEditor.SelectedText = value;
}
public string FileName => myForm.FileName;
public bool New() => myForm.Function_New();
public bool Save() => myForm.Function_Save();
public bool SaveAs() => myForm.Function_SaveAs();
public bool Open() => myForm.Function_Open();
public void Cut() => myForm.Function_Cut();
public void Copy() => myForm.Function_Copy();
public void Paste() => myForm.Function_Paste();
public void Delete() => myForm.Function_Delete();
public void SelectAll() => myForm.Function_SelectAll();
}
封裝設計重點
- 將主表單
frmMain 的文字編輯器操作包裝為文件導向介面
- 暴露
Text/Selection/AppendText 等核心編輯功能
- 委派檔案操作(新增/開啟/儲存)給主表單對應方法
- 編輯命令(剪下/複製/貼上/刪除/全選)同樣轉發
- 腳本透過
document 全域物件即可完整控制編輯器行為