📄 bkmkmgrfrm.pas
字号:
unit BkmkMgrFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, ToolWin, Menus, StdCtrls, ImgList, ActnList;
type
TBkmkMgrForm = class(TForm)
MainMenu: TMainMenu;
FileMenu: TMenuItem;
StatusBar: TStatusBar;
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;
ListView: TListView;
FileNewGroupItem: TMenuItem;
FileN1Item: TMenuItem;
FileN2Item: TMenuItem;
FileDeleteGroupItem: TMenuItem;
FileModifyGroupItem: TMenuItem;
CoolBar: TCoolBar;
ToolBar: TToolBar;
NewItemToolButton: TToolButton;
DeleteItemToolButton: TToolButton;
ModifyItemToolButton: TToolButton;
TopSplitterPanel: TPanel;
GroupsPanel: TPanel;
GroupsComboBox: TComboBox;
Label1: TLabel;
ActionList: TActionList;
NewItemAction: TAction;
NewGroupAction: TAction;
ModifyItemAction: TAction;
ModifyGroupAction: TAction;
DeleteItemAction: TAction;
DeleteGroupAction: TAction;
PopupMenu: TPopupMenu;
PopNewItem: TMenuItem;
PopModifyItem: TMenuItem;
PopN1Item: TMenuItem;
PopDeleteItem: TMenuItem;
GotoAction: TAction;
PopGotoItem: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure GroupsComboBoxChange(Sender: TObject);
procedure FileCloseItemClick(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 ListViewDblClick(Sender: TObject);
procedure NewItemActionExecute(Sender: TObject);
procedure NewGroupActionExecute(Sender: TObject);
procedure ModifyItemActionExecute(Sender: TObject);
procedure ModifyGroupActionExecute(Sender: TObject);
procedure DeleteItemActionExecute(Sender: TObject);
procedure DeleteGroupActionExecute(Sender: TObject);
procedure ListViewChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure GotoActionExecute(Sender: TObject);
private
{ Private declarations }
procedure FillGroupsComboBox;
procedure FillItemsListView(GroupIdx: Integer);
public
{ Public declarations }
end;
var
BkmkMgrForm: TBkmkMgrForm;
procedure ShowBkmkMgrForm;
implementation
{$R *.DFM}
uses
Misc, PrjMisc, MainFrm, BkmkMgr, InputFrm, InpBkmkFrm, AboutFrm;
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
ListView.Items.BeginUpdate;
ListView.Items.Clear;
if GroupIdx = -1 then
begin
ListView.Items.EndUpdate;
Exit;
end;
Count := Length(BkmkManager.Groups[GroupIdx].Items);
for I := 0 to Count - 1 do
begin
ListItem := ListView.Items.Add;
ListItem.Caption := IntToStr(BkmkManager.Groups[GroupIdx].Items[I].Offset);
ListItem.SubItems.Add(BkmkManager.Groups[GroupIdx].Items[I].Description);
end;
ListView.Items.EndUpdate;
end;
procedure TBkmkMgrForm.FormCreate(Sender: TObject);
begin
FillGroupsComboBox;
end;
procedure TBkmkMgrForm.FormResize(Sender: TObject);
begin
GroupsComboBox.Width := GroupsPanel.ClientWidth - GroupsComboBox.Left;
end;
procedure TBkmkMgrForm.GroupsComboBoxChange(Sender: TObject);
begin
FillItemsListView(GroupsComboBox.ItemIndex);
DeleteGroupAction.Enabled := (GroupsComboBox.ItemIndex <> -1);
ModifyGroupAction.Enabled := (GroupsComboBox.ItemIndex <> -1);
end;
procedure TBkmkMgrForm.FileCloseItemClick(Sender: TObject);
begin
Close;
end;
procedure TBkmkMgrForm.ViewToolBarItemClick(Sender: TObject);
begin
ViewToolBarItem.Checked := not ViewToolBarItem.Checked;
CoolBar.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;
ListView.GridLines := ViewGridLineItem.Checked;
end;
procedure TBkmkMgrForm.HelpContentItemClick(Sender: TObject);
begin
ShowHelp;
end;
procedure TBkmkMgrForm.HelpAboutItemClick(Sender: TObject);
begin
ShowAboutForm;
end;
procedure TBkmkMgrForm.ListViewDblClick(Sender: TObject);
begin
if GotoAction.Enabled then
GotoActionExecute(nil);
end;
procedure TBkmkMgrForm.NewItemActionExecute(Sender: TObject);
var
Item: TBkmkItem;
GroupIdx: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then
begin
NewGroupActionExecute(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 ListView.Items.Add do
begin
Caption := IntToStr(Item.Offset);
SubItems.Add(Item.Description);
end;
end;
end;
procedure TBkmkMgrForm.NewGroupActionExecute(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.ModifyItemActionExecute(Sender: TObject);
var
Item: TBkmkItem;
GroupIdx, ItemIdx: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
if ListView.Selected = nil then Exit;
ItemIdx := ListView.Selected.Index;
Item := BkmkManager.Groups[GroupIdx].Items[ItemIdx];
if ShowInpBkmkForm(Item) then
begin
BkmkManager.ModifyItem(GroupIdx, ItemIdx, Item);
with ListView.Items[ItemIdx] do
begin
Caption := IntToStr(Item.Offset);
SubItems[0] := Item.Description;
end;
end;
end;
procedure TBkmkMgrForm.ModifyGroupActionExecute(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.DeleteItemActionExecute(Sender: TObject);
var
GroupIdx, ItemIdx, R: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
R := MsgBox('确实要删除该地址吗?', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2);
if R = ID_NO then Exit;
if ListView.Selected = nil then Exit;
ItemIdx := ListView.Selected.Index;
BkmkManager.DeleteItem(GroupIdx, ItemIdx);
ListView.Items.Delete(ItemIdx);
end;
procedure TBkmkMgrForm.DeleteGroupActionExecute(Sender: TObject);
var
GroupIdx, R: Integer;
begin
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
R := MsgBox('确实要删除该组吗?', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2);
if R = ID_NO then Exit;
BkmkManager.DeleteGroup(GroupIdx);
FillGroupsComboBox;
end;
procedure TBkmkMgrForm.GotoActionExecute(Sender: TObject);
var
GroupIdx, ItemIdx: Integer;
Offset: Integer;
begin
if MainForm.GetCurDoc = nil then Exit;
GroupIdx := GroupsComboBox.ItemIndex;
if GroupIdx = -1 then Exit;
if ListView.Selected = nil then Exit;
ItemIdx := ListView.Selected.Index;
Offset := BkmkManager.Groups[GroupIdx].Items[ItemIdx].Offset;
if (Offset >= 0) and (Offset < MainForm.GetCurDoc.DataSize) then
begin
MainForm.GetCurDoc.HexEdit.Offset := Offset;
MainForm.BringToFront;
MainForm.GetCurDoc.BringToFront;
end;
end;
procedure TBkmkMgrForm.ListViewChange(Sender: TObject;
Item: TListItem; Change: TItemChange);
var
SelItem: TListItem;
begin
SelItem := ListView.Selected;
DeleteItemAction.Enabled := (SelItem <> nil);
ModifyItemAction.Enabled := (SelItem <> nil);
GotoAction.Enabled := (SelItem <> nil);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -