-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathFrmSettingsFrame.pas
More file actions
144 lines (123 loc) · 3.46 KB
/
FrmSettingsFrame.pas
File metadata and controls
144 lines (123 loc) · 3.46 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
unit FrmSettingsFrame;
interface
uses
System.Classes,
Vcl.Controls,
Vcl.Forms,
Vcl.StdCtrls,
Vcl.ComCtrls,
Vcl.Dialogs,
ToolsAPI;
type
TFrmSettingsFrame = class(TFrame)
lblVSCodeCommand: TLabel;
edVSCodeCommand: TEdit;
btnBrowse: TButton;
lblCommandHint: TLabel;
lblShortcut: TLabel;
hkShortcut: THotKey;
lblShortcutHint: TLabel;
procedure btnBrowseClick(Sender: TObject);
end;
/// <summary>
/// Registers the plugin's settings into the IDE Tools > Options... dialog.
/// The IDE calls GetFrameClass to instantiate TFrmSettingsFrame, then
/// FrameCreated to populate it, and DialogClosed to apply changes.
/// The object is NOT reference-counted (_AddRef/_Release return -1):
/// lifetime is managed explicitly by the plugin via FreeAndNil.
/// </summary>
TEditInVSCodeOptions = class(TInterfacedObject, INTAAddInOptions)
strict private
FFrame: TFrmSettingsFrame;
protected
// IInterface - non-reference-counted: lifetime managed by owner
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
public
function GetArea: string;
function GetCaption: string;
function GetFrameClass: TCustomFrameClass;
procedure FrameCreated(AFrame: TCustomFrame);
procedure DialogClosed(Accepted: Boolean);
function ValidateContents: Boolean;
function GetHelpContext: Integer;
function IncludeInIDEInsight: Boolean;
end;
implementation
{$R *.dfm}
uses
System.SysUtils,
Vcl.Menus,
PluginSettings;
{ TFrmSettingsFrame }
procedure TFrmSettingsFrame.btnBrowseClick(Sender: TObject);
var
dlg: TOpenDialog;
begin
dlg := TOpenDialog.Create(nil);
try
dlg.Title := 'Select VS Code Executable';
dlg.Filter := 'Scripts and executables|*.cmd;*.exe;*.bat|All files|*.*';
dlg.FileName := edVSCodeCommand.Text;
if dlg.Execute(Handle) then
edVSCodeCommand.Text := dlg.FileName;
finally
dlg.Free;
end;
end;
function TEditInVSCodeOptions._AddRef: Integer;
begin
Result := -1; // not reference-counted
end;
function TEditInVSCodeOptions._Release: Integer;
begin
Result := -1; // not reference-counted
end;
{ TEditInVSCodeOptions }
function TEditInVSCodeOptions.GetArea: string;
begin
Result := 'Third Party';
end;
function TEditInVSCodeOptions.GetCaption: string;
begin
Result := 'Edit in VS Code';
end;
function TEditInVSCodeOptions.GetFrameClass: TCustomFrameClass;
begin
Result := TFrmSettingsFrame;
end;
procedure TEditInVSCodeOptions.FrameCreated(AFrame: TCustomFrame);
begin
FFrame := AFrame as TFrmSettingsFrame;
FFrame.edVSCodeCommand.Text := TPluginSettings.VSCodeCommand;
FFrame.hkShortcut.HotKey := TPluginSettings.Shortcut;
end;
procedure TEditInVSCodeOptions.DialogClosed(Accepted: Boolean);
var
newCmd: string;
begin
if not Accepted then
Exit;
newCmd := Trim(FFrame.edVSCodeCommand.Text);
if newCmd = '' then
newCmd := DEFAULT_VSCODE_COMMAND;
TPluginSettings.VSCodeCommand := newCmd;
TPluginSettings.Shortcut := FFrame.hkShortcut.HotKey;
TPluginSettings.Save;
TPluginSettings.NotifyShortcutChanged;
end;
function TEditInVSCodeOptions.ValidateContents: Boolean;
begin
Result := True;
end;
function TEditInVSCodeOptions.GetHelpContext: Integer;
begin
Result := 0;
end;
function TEditInVSCodeOptions.IncludeInIDEInsight: Boolean;
begin
// This page is small and self-contained. Keeping it out of IDE Insight
// avoids extra indexing work when the IDE builds preferences metadata.
Result := False;
end;
end.