📄 bkmkmgrfrm.pas
字号:
unit BkmkMgrFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, ToolWin, Menus, StdCtrls, ImgList;
type
TBkmkMgrForm = class(TForm)
ToolBar: TToolBar;
MainMenu: TMainMenu;
FileMenu: TMenuItem;
NewItemToolButton: TToolButton;
DeleteItemToolButton: TToolButton;
StatusBar: TStatusBar;
ToolButton4: TToolButton;
GroupsComboBox: TComboBox;
ModifyItemToolButton: TToolButton;
FileNewBkmkItem: TMenuItem;
FileDeleteBkmkItem: TMenuItem;
FileModifyBkmkItem: TMenuItem;
FileN3Item: TMenuItem;
FileCloseItem: TMenuItem;
ViewMenu: TMenuItem;
ViewToolBarItem: TMenuItem;
ViewStatusBarItem: TMenuItem;
ViewN1Item: TMenuItem;
ViewGridLineItem: TMenuItem;
HelpMenu: TMenuItem;
HelpContentItem: TMenuItem;
HelpN1Item: TMenuItem;
HelpAboutItem: TMenuItem;
ImageList: TImageList;
ItemsListView: TListView;
FileNewGroupItem: TMenuItem;
FileN1Item: TMenuItem;
FileN2Item: TMenuItem;
FileDeleteGroupItem: TMenuItem;
FileModifyGroupItem: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure GroupsComboBoxChange(Sender: TObject);
procedure FileNewGroupItemClick(Sender: TObject);
procedure FileNewBkmkItemClick(Sender: TObject);
procedure FileModifyBkmkItemClick(Sender: TObject);
procedure FileDeleteGroupItemClick(Sender: TObject);
procedure FileDeleteBkmkItemClick(Sender: TObject);
procedure FileCloseItemClick(Sender: TObject);
procedure FileModifyGroupItemClick(Sender: TObject);
procedure ViewToolBarItemClick(Sender: TObject);
procedure ViewStatusBarItemClick(Sender: TObject);
procedure ViewGridLineItemClick(Sender: TObject);
procedure HelpContentItemClick(Sender: TObject);
procedure HelpAboutItemClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure ItemsListViewDblClick(Sender: TObject);
private
{ Private declarations }
procedure FillGroupsComboBox;
procedure FillItemsListView(GroupIdx: Integer);
public
{ Public declarations }
end;
var
BkmkMgrForm: TBkmkMgrForm;
procedure ShowBkmkMgrForm;
implementation
{$R *.DFM}
uses
MainFrm, BkmkMgr, InputFrm, InpBkmkFrm, AboutFrm, Misc;
procedure ShowBkmkMgrForm;
begin
if BkmkMgrForm = nil then
begin
BkmkManager.LoadAllGroups;
BkmkMgrForm := TBkmkMgrForm.Create(Application);
end;
BkmkMgrForm.Show;
end;
procedure TBkmkMgrForm.FillGroupsComboBox;
var
i: Integer;
begin
GroupsComboBox.Items.Clear;
for i := 0 to Length(BkmkManager.Groups) - 1 do
GroupsComboBox.Items.Add(BkmkManager.Groups[i].GroupName);
if GroupsComboBox.Items.Count > 0 then GroupsComboBox.ItemIndex := 0;
GroupsComboBoxChange(nil);
end;
procedure TBkmkMgrForm.FillItemsListView(GroupIdx: Integer);
var
i, Count: Integer;
ListItem: TListItem;
begin
ItemsListView.Items.BeginUpdate;
ItemsListView.Items.Clear;
if GroupIdx = -1 then
begin
ItemsListView.Items.EndUpdate;
Exit;
end;
Count := Length(BkmkManager.Groups[GroupIdx].Items);
for i := 0 to Count - 1 do
begin
ListItem := ItemsListView.Items.Add;
ListItem.Caption := IntToStr(BkmkManager.Groups[GroupIdx].Items[i].Offset);
ListItem.SubItems.Add(BkmkManager.Groups[GroupIdx].Items[i].Description);
end;
ItemsListView.Items.EndUpdate;
end;
procedure TBkmkMgrForm.FormCreate(Sender: TObject);
begin
FillGroupsComboBox;
end;
procedure TBkmkMgrForm.FormResize(Sender: TObject);
begin
GroupsComboBox.Width := ToolBar.ClientWidth - GroupsComboBox.Left;
end;
procedure TBkmkMgrForm.GroupsComboBoxChange(Sender: TObject);
begin
FillItemsListView(GroupsComboBox.ItemIndex);
end;
procedure TBkmkMgrForm.FileNewGroupItemClick(Sender: TObject);
var
GroupName: string;
begin
GroupName := '';
if ShowInputForm('新建组', '输入组名:', GroupName) then
begin
BkmkManager.AddGroup(GroupName);
GroupsComboBox.Items.Add(GroupName);
GroupsComboBox.ItemIndex := GroupsComboBox.Items.Count - 1;
GroupsComboBoxChange(nil);
end;
end;
procedure TBkmkMgrForm.FileNewBkmkItemClick(Sender: TObject);
var
Item: TBkmkItem;
GroupIdx: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then
begin
FileNewGroupItemClick(nil);
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
end;
Item.Offset := 0;
Item.Description := '';
if ShowInpBkmkForm(Item) then
begin
BkmkManager.AddItem(GroupIdx, Item);
with ItemsListView.Items.Add do
begin
Caption := IntToStr(Item.Offset);
SubItems.Add(Item.Description);
end;
end;
end;
procedure TBkmkMgrForm.FileModifyGroupItemClick(Sender: TObject);
var
GroupName: string;
GroupIdx: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
GroupName := BkmkManager.Groups[GroupIdx].GroupName;
if ShowInputForm('修改组名', '输入组名:', GroupName) then
begin
BkmkManager.ModifyGroup(GroupIdx, GroupName);
GroupsComboBox.Items[GroupIdx] := GroupName;
GroupsComboBox.ItemIndex := GroupIdx;
end;
end;
procedure TBkmkMgrForm.FileModifyBkmkItemClick(Sender: TObject);
var
Item: TBkmkItem;
GroupIdx, ItemIdx: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
if ItemsListView.Selected = nil then Exit;
ItemIdx := ItemsListView.Selected.Index;
Item := BkmkManager.Groups[GroupIdx].Items[ItemIdx];
if ShowInpBkmkForm(Item) then
begin
BkmkManager.ModifyItem(GroupIdx, ItemIdx, Item);
with ItemsListView.Items[ItemIdx] do
begin
Caption := IntToStr(Item.Offset);
SubItems[0] := Item.Description;
end;
end;
end;
procedure TBkmkMgrForm.FileDeleteGroupItemClick(Sender: TObject);
var
GroupIdx: Integer;
R: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
R := MessageBox(Handle, '真的删除该组吗?', '提示', 36+256);
if R = ID_NO then Exit;
BkmkManager.DeleteGroup(GroupIdx);
FillGroupsComboBox;
end;
procedure TBkmkMgrForm.FileDeleteBkmkItemClick(Sender: TObject);
var
GroupIdx, ItemIdx: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
if ItemsListView.Selected = nil then Exit;
ItemIdx := ItemsListView.Selected.Index;
BkmkManager.DeleteItem(GroupIdx, ItemIdx);
ItemsListView.Items.Delete(ItemIdx);
end;
procedure TBkmkMgrForm.FileCloseItemClick(Sender: TObject);
begin
Close;
end;
procedure TBkmkMgrForm.ViewToolBarItemClick(Sender: TObject);
begin
ViewToolBarItem.Checked := not ViewToolBarItem.Checked;
ToolBar.Visible := ViewToolBarItem.Checked;
end;
procedure TBkmkMgrForm.ViewStatusBarItemClick(Sender: TObject);
begin
ViewStatusBarItem.Checked := not ViewStatusBarItem.Checked;
StatusBar.Visible := ViewStatusBarItem.Checked;
end;
procedure TBkmkMgrForm.ViewGridLineItemClick(Sender: TObject);
begin
ViewGridLineItem.Checked := not ViewGridLineItem.Checked;
ItemsListView.GridLines := ViewGridLineItem.Checked;
end;
procedure TBkmkMgrForm.HelpContentItemClick(Sender: TObject);
begin
ShowHelp;
end;
procedure TBkmkMgrForm.HelpAboutItemClick(Sender: TObject);
begin
ShowAboutForm;
end;
procedure TBkmkMgrForm.ItemsListViewDblClick(Sender: TObject);
var
GroupIdx, ItemIdx: Integer;
Offset: Integer;
begin
if MHMainForm.GetCurDoc = nil then Exit;
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
if ItemsListView.Selected = nil then Exit;
ItemIdx := ItemsListView.Selected.Index;
Offset := BkmkManager.Groups[GroupIdx].Items[ItemIdx].Offset;
if (Offset >= 0) and (Offset < MHMainForm.GetCurDoc.BufSize) then
begin
MHMainForm.GetCurDoc.Offset := Offset;
MHMainForm.BringToFront;
MHMainForm.GetCurDoc.BringToFront;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -