📄 jvqoutlookbarform.pas
字号:
N: TTreeNode;
begin
N := tvItems.Selected;
if N.Parent <> nil then
N := N.Parent;
P := TJvOutlookBarPage(N.Data);
B := P.Buttons.Add;
B.Caption := GetButtonName(OutlookBar);
tvItems.Selected := tvItems.Items.AddChildObject(N, B.Caption, B);
end;
procedure TFrmOLBEditor.acDeleteExecute(Sender: TObject);
var
pr: TPersistent;
P: TJvOutlookBarPage;
N: TTreeNode;
begin
tvItems.Items.BeginUpdate;
try
N := tvItems.Selected;
pr := TPersistent(N.Data);
if pr is TJvOutlookBarPage then
THackOutlookBar(OutlookBar).Pages.Delete(TJvOutlookBarPage(pr).Index)
else
if pr is TJvOutlookBarButton then
begin
P := TJvOutlookBarPage(N.Parent.Data);
P.Buttons.Delete(TJvOutlookBarButton(pr).Index);
end;
DeleteItem(N);
finally
tvItems.Items.EndUpdate;
end;
end;
procedure TFrmOLBEditor.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;
class function TFrmOLBEditor.GetButtonName(OLBar: TJvCustomOutlookBar): string;
const
cPrefix = 'JvOutlookBarButton';
cTemplate = cPrefix + '%d';
var
K: Integer;
Tmp: string;
function IsUnique(const S: string): Boolean;
var
I, J: Integer;
begin
Result := False;
for I := 0 to THackOutlookBar(OLBar).Pages.Count - 1 do
for J := 0 to THackOutlookBar(OLBar).Pages[I].Buttons.Count - 1 do
if AnsiSameText(THackOutlookBar(OLBar).Pages[I].Buttons[J].Caption, S) then
Exit;
Result := True;
end;
begin
Result := cPrefix;
if OLBar <> nil then
for K := 1 to MaxInt - 1 do
begin
Tmp := Format(cTemplate, [K]);
if IsUnique(Tmp) then
begin
Result := Tmp;
Exit;
end;
end;
end;
class function TFrmOLBEditor.GetPageName(OLBar: TJvCustomOutlookBar): string;
const
cPrefix = 'JvOutlookBarPage';
cTemplate = cPrefix + '%d';
var
K: Integer;
Tmp: string;
function IsUnique(const S: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to THackOutlookBar(OLBar).Pages.Count - 1 do
if AnsiSameText(THackOutlookBar(OLBar).Pages[I].Caption, S) then
Exit;
Result := True;
end;
begin
Result := cPrefix;
if OLBar <> nil then
for K := 1 to MaxInt - 1 do
begin
Tmp := Format(cTemplate, [K]);
if IsUnique(Tmp) then
begin
Result := Tmp;
Exit;
end;
end;
end;
procedure TFrmOLBEditor.UpdateItems;
var
N, N2: TTreeNode;
begin
tvItems.Items.BeginUpdate;
N2 := nil;
try
N := tvItems.Items.GetFirstNode;
while Assigned(N) do
begin
if TObject(N.Data) is TJvOutlookBarPage then
begin
N.Text := TJvOutlookBarPage(N.Data).Caption;
if TJvOutlookBarPage(N.Data) = OutlookBar.ActivePage then
N2 := N;
end
else
if TObject(N.Data) is TJvOutlookBarButton then
begin
N.Text := TJvOutlookBarButton(N.Data).Caption;
if N.Selected then
N2 := N;
end;
N := N.GetNext;
end;
finally
tvItems.Items.EndUpdate;
end;
tvItems.FullExpand;
if Screen.ActiveForm = Self then
tvItems.Selected := N2;
end;
procedure TFrmOLBEditor.tvItemsChange(Sender: TObject; Node: TTreeNode);
begin
SelectItem(Node);
end;
procedure TFrmOLBEditor.tvItemsCollapsing(Sender: TObject; Node: TTreeNode;
var AllowCollapse: Boolean);
begin
AllowCollapse := False;
end;
procedure TFrmOLBEditor.tvItemsKeyPress(Sender: TObject; var Key: Char);
begin
if tvItems.Selected <> nil then
begin
SelectItem(tvItems.Selected);
ActivateInspector(Key);
Key := #0;
end;
end;
procedure TFrmOLBEditor.acUpdateExecute(Sender: TObject);
begin
UpdateList;
end;
procedure TFrmOLBEditor.acUpExecute(Sender: TObject);
var
N: TTreeNode;
begin
N := tvItems.Selected;
SwitchItems(tvItems.Selected, N.getPrevSibling);
N.MoveTo(N.getPrevSibling, naInsert);
N.Expand(True);
tvItems.Selected := N;
end;
procedure TFrmOLBEditor.acDownExecute(Sender: TObject);
var
N: TTreeNode;
begin
SwitchItems(tvItems.Selected, tvItems.Selected.getNextSibling);
N := tvItems.Selected.getNextSibling;
N.MoveTo(tvItems.Selected, naInsert);
N.Expand(True);
end;
procedure TFrmOLBEditor.acShowTextLabelsExecute(Sender: TObject);
begin
acShowTextLabels.Checked := not acShowTextLabels.Checked;
tbTop.ShowCaptions := acShowTextLabels.Checked;
tbTop.ButtonHeight := 16;
tbTop.ButtonWidth := 16;
// ClientWidth := Max(ClientWidth, btnDown.Left + btnDown.Width + 4);
end;
procedure TFrmOLBEditor.StoreSettings;
{$IFDEF MSWINDOWS}
begin
with TRegIniFile.Create do
try
RootKey := HKEY_CURRENT_USER;
OpenKey(GetRegPath, True);
// Width, Height, TextLabels
WriteInteger(cJvOutlookBar, cWidth, Width);
WriteInteger(cJvOutlookBar, cHeight, Height);
WriteBool(cJvOutlookBar, cTextLabels, acShowTextLabels.Checked);
WriteBool(cJvOutlookBar, cToolBar, acToolBar.Checked);
finally
Free;
end;
end;
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
begin
with TJvRegistryIniFile.Create do
try
if OpenKey(GetRegPath, True) then
try
// Width, Height, TextLabels
WriteInteger(cWidth, Width);
WriteInteger(cHeight, Height);
WriteBool(cTextLabels, acShowTextLabels.Checked);
WriteBool(cToolBar, acToolBar.Checked);
finally
CloseKey;
end;
finally
Free;
end;
end;
{$ENDIF UNIX}
procedure TFrmOLBEditor.LoadSettings;
{$IFDEF MSWINDOWS}
begin
with TRegIniFile.Create do
try
RootKey := HKEY_CURRENT_USER;
OpenKey(GetRegPath, True);
// Width, Height, TextLabels
Width := ReadInteger(cJvOutlookBar, cWidth, Width);
Height := ReadInteger(cJvOutlookBar, cHeight, Height);
acToolBar.Checked := not ReadBool(cJvOutlookBar, cToolBar, True);
acToolBar.Execute;
acShowTextLabels.Checked := not ReadBool(cJvOutlookBar, cTextLabels, False);
acShowTextLabels.Execute; // toggles
finally
Free;
end;
end;
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
begin
with TJvRegistryIniFile.Create do
try
if OpenKey(GetRegPath, True) then
try
// Width, Height, TextLabels
WriteInteger(cWidth, Width);
WriteInteger(cHeight, Height);
WriteBool(cTextLabels, acShowTextLabels.Checked);
WriteBool(cToolBar, acToolBar.Checked);
finally
CloseKey;
end;
finally
Free;
end;
end;
{$ENDIF UNIX}
function TFrmOLBEditor.GetRegPath: string;
{$IFDEF MSWINDOWS}
const
cRegKey = '\JVCL\OutlookBar Editor';
begin
Result := Designer.GetBaseRegKey + cRegKey;
end;
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
const
cRegKey = 'OutlookBar Editor';
begin
Result := SDelphiKey + RsPropertyEditors + cRegKey + PathDelim + cJvOutlookBar;
end;
{$ENDIF UNIX}
procedure TFrmOLBEditor.SwitchItems(Node1, Node2: TTreeNode);
var
I: Integer;
begin
if TObject(Node1.Data) is TJvOutlookBarButton then
begin
I := TJvOutlookBarButton(Node1.Data).Index;
TJvOutlookBarButton(Node1.Data).Index := TJvOutlookBarButton(Node2.Data).Index;
TJvOutlookBarButton(Node2.Data).Index := I;
end
else
if TObject(Node1.Data) is TJvOutlookBarPage then
begin
I := TJvOutlookBarPage(Node1.Data).Index;
TJvOutlookBarPage(Node1.Data).Index := TJvOutlookBarPage(Node2.Data).Index;
TJvOutlookBarPage(Node2.Data).Index := I;
end;
end;
procedure TFrmOLBEditor.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
StoreSettings;
end;
procedure TFrmOLBEditor.FormShow(Sender: TObject);
begin
LoadSettings;
end;
procedure TFrmOLBEditor.acToolBarExecute(Sender: TObject);
begin
acToolBar.Checked := not acToolBar.Checked;
tbTop.Visible := acToolBar.Checked;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -