-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomCommand.cs
More file actions
62 lines (58 loc) · 2.23 KB
/
Copy pathCustomCommand.cs
File metadata and controls
62 lines (58 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraRichEdit.Services;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.Commands;
using System.Windows.Forms;
using DevExpress.XtraEditors;
namespace SaveDocumentSample
{
#region #savecommand
public class CustomRichEditCommandFactoryService : IRichEditCommandFactoryService
{
readonly IRichEditCommandFactoryService service;
readonly RichEditControl control;
public CustomRichEditCommandFactoryService(RichEditControl control, IRichEditCommandFactoryService service)
{
DevExpress.Utils.Guard.ArgumentNotNull(control, "control");
DevExpress.Utils.Guard.ArgumentNotNull(service, "service");
this.control = control;
this.service = service;
}
public RichEditCommand CreateCommand(RichEditCommandId id)
{
if (id == RichEditCommandId.FileSaveAs)
return new CustomSaveDocumentAsCommand(control);
return service.CreateCommand(id);
}
}
public class CustomSaveDocumentAsCommand : SaveDocumentAsCommand
{
public CustomSaveDocumentAsCommand(IRichEditControl control)
: base(control) {}
protected override void ExecuteCore()
{
using (XtraSaveFileDialog dialog = new XtraSaveFileDialog())
{
dialog.Filter = "Rich Text Format Files (*.rtf)|*.rtf|All Files (*.*)|*.*";
dialog.FileName = "SavedDocument.rtf";
dialog.RestoreDirectory = true;
dialog.CheckFileExists = false;
dialog.CheckPathExists = true;
dialog.OverwritePrompt = true;
dialog.DereferenceLinks = true;
dialog.ValidateNames = true;
dialog.AddExtension = false;
dialog.FilterIndex = 1;
dialog.InitialDirectory = "C:\\Temp";
if (dialog.ShowDialog() == DialogResult.OK)
{
((RichEditControl)this.Control).SaveDocument(dialog.FileName, DocumentFormat.Rtf);
}
}
//base.ExecuteCore();
}
}
#endregion #savecommand
}