📄 tipmainform.pas
字号:
end;
finally
R.CloseKey;
end;
finally
R.Free;
end;
end; {= TFrmTipExplorer.SaveSettings =}
{$ENDIF}
procedure TFrmTipExplorer.FormShow(Sender: TObject);
begin
TvwTips.SetFocus; { Set initial focus to tree view }
end;
procedure TFrmTipExplorer.DisplayHint( Sender : TObject );
begin
{ If hint is not empty, then use SimplePanel to display it }
{ otherwise, original status bar is restored }
StsMain.SimplePanel := Application.Hint <> '';
if StsMain.SimplePanel then
StsMain.SimpleText := Application.Hint;
end;
procedure TFrmTipExplorer.MnuExitClick(Sender: TObject);
begin
Close;
end;
procedure TFrmTipExplorer.EnableTreeViewFunctions(Level : Integer);
var
Enable : Boolean;
begin
Enable := Level >= 1; { True if category or tip selected }
MnuNewTip.Enabled := Enable;
MnuNewD1Tip.Enabled := Enable;
MnuNewD2Tip.Enabled := Enable;
MnuDelete.Enabled := Enable;
BtnUpOneLevel.Enabled := Enable;
Enable := Level > 1; { True only if tip selected }
BtnPrint.Enabled := Enable;
MnuPrint.Enabled := Enable;
end;
procedure TFrmTipExplorer.EnableTipFunctions( Enable : Boolean );
begin
BtnCut.Enabled := Enable;
MnuCut.Enabled := Enable;
BtnCopy.Enabled := Enable;
MnuCopy.Enabled := Enable;
BtnPaste.Enabled := Enable;
MnuPaste.Enabled := Enable;
MnuSelectAll.Enabled := Enable;
CbxFontName.Enabled := Enable;
EdtFontSize.Enabled := Enable;
SpnFontSize.Enabled := Enable;
if not Enable then
begin
CbxFontName.Text := '';
EdtFontSize.Text := '0';
end;
BtnBold.Enabled := Enable;
BtnItalic.Enabled := Enable;
BtnUnderline.Enabled := Enable;
MnuFont.Enabled := Enable;
BtnBullets.Enabled := Enable;
MnuBullets.Enabled := Enable;
end;
procedure TFrmTipExplorer.UpdateStatusBar( Panel1, Panel2: string );
begin
StsMain.Panels[ 0 ].Text := Panel1;
StsMain.Panels[ 1 ].Text := Panel2;
end;
{== Tree View Methods =}
procedure TFrmTipExplorer.LoadTips;
var
RootNode, TipNode, CatNode : TTreeNode;
Category : string;
VersionNum : Integer;
begin
TblTips.DisableControls;
TvwTips.Items.Clear; { Make sure tree view is empty }
{ Use the Add method to "create" the root node }
RootNode := TvwTips.Items.Add( nil, 'Tips' );
RootNode.ImageIndex := 0; { Specify which bitmap to use }
RootNode.SelectedIndex := 0;
TblCategories.First; { For each category... }
while not TblCategories.EOF do
begin
Category := TblCategories[ 'Category' ];
CatNode := TvwTips.Items.AddChild( RootNode, Category );
CatNode.ImageIndex := 1;
CatNode.SelectedIndex := 2;
{ Filter tips table on current category }
TblTips.Filter := Format( 'Category = ''%s''', [ Category ] );
TblTips.First; { For each tip in category ... }
while not TblTips.EOF do
begin
{ Add tip node: Subject field stored in string; }
{ Version number stored in object }
VersionNum := StrToInt( TblTips[ 'Version' ] );
TipNode := TvwTips.Items.AddChildObject( CatNode,
TblTips[ 'Subject' ],
Pointer(VersionNum));
TipNode.ImageIndex := 3;
TipNode.SelectedIndex := 4;
TblTips.Next;
end;
TblCategories.Next;
end;
TblTips.Filter := ''; { Clear the filter }
TblTips.EnableControls;
RootNode.Expand( False ); { Expand root node; non-recursive }
RootNode.Selected := True; { Highlight the root node }
end;
procedure TFrmTipExplorer.TvwTipsEditing( Sender : TObject;
Node : TTreeNode; var AllowEdit : Boolean );
begin
if Node.HasChildren then
AllowEdit := False; { Cannot edit root or category nodes }
end;
procedure TFrmTipExplorer.TvwTipsEdited( Sender : TObject;
Node : TTreeNode; var S : string );
begin
TblTips.DisableControls;
try
TblTips.Edit;
TblTips[ 'Subject' ] := S; { Update the subject }
TblTips.Post;
finally
TblTips.EnableControls;
Node.Text := S;
UpdateStatusBar( '', S );
end;
Node.Selected := True;
end; {= TFrmTipExplorer.TvwTipsEdited =}
procedure TFrmTipExplorer.TvwTipsChange( Sender : TObject;
Node : TTreeNode );
var
I : Integer;
ListItem : TListItem;
VersionNum : Integer;
begin
UpdateTip; { Update modified tip before moving }
if Node.Level = nlRoot then { If select to root node ... }
begin
LvwCategories.Items.BeginUpdate; { Do not update display }
try
LvwCategories.Items.Clear; { Clear list view }
for I := 0 to Node.Count - 1 do
begin { Add a list item for each category }
ListItem := LvwCategories.Items.Add;
ListItem.Caption := Node.Item[ I ].Text;
ListItem.ImageIndex := 1
end;
finally
LvwCategories.Items.EndUpdate;
end;
UpdateStatusBar( IntToStr(Node.Count) + ' Categories', '' );
NbkListView.PageIndex := pgCategory;
end
else if Node.Level = nlCategory then
begin
LvwSubjects.Items.BeginUpdate; { Do not update display }
try
LvwSubjects.Items.Clear;
for I := 0 to Node.Count - 1 do
begin { Add a list item for each subject }
ListItem := LvwSubjects.Items.Add;
ListItem.Caption := Node.Item[ I ].Text;
{ Version number for each subject stored in tree node }
VersionNum := Integer( Node.Item[ I ].Data );
{ Add version number as sub item; sub items }
{ appear as additional columns in report format }
if VersionNum = 0 then
ListItem.SubItems.Add( 'All' )
else
ListItem.SubItems.Add( Format( '%d', [ VersionNum ] ) );
ListItem.ImageIndex := 3;
end;
finally
LvwSubjects.Items.EndUpdate;
end;
UpdateStatusBar( IntToStr( Node.Count ) + ' Subjects', '' );
NbkListView.PageIndex := pgSubject;
end
else { A Subject Node was Selected }
begin
TblTips.DisableControls;
try { Move table cursor to selected subject }
TblTips.Locate( 'Subject', Node.Text, [] );
finally
TblTips.EnableControls;
end;
UpdateStatusBar( '', Node.Text );
NbkListView.PageIndex := pgTip;
end;
EnableTreeViewFunctions( Node.Level );
end; {= TFrmTipExplorer.TvwTipsChange =}
procedure TFrmTipExplorer.MnuNewCategoryClick(Sender: TObject);
var
CatNode : TTreeNode;
begin
TvwTips.SetFocus;
{ Insert new category in table }
TblCategories.InsertRecord( [ 'New Category' ] );
{ Create a new child node from the root node }
CatNode := TvwTips.Items.AddChild( TvwTips.Items.GetFirstNode,
'New Category' );
CatNode.ImageIndex := 1;
CatNode.SelectedIndex := 2;
CatNode.EditText; { Immediately allow user to edit category }
LvwSubjects.Items.Clear; { No subjects yet for this category }
NbkListView.PageIndex := pgSubject;
end;
procedure TFrmTipExplorer.MnuNewTipClick(Sender: TObject);
var
ParentNode, TipNode : TTreeNode;
VersionNum : Integer;
begin
TvwTips.SetFocus;
VersionNum := TMenuItem( Sender ).Tag; { Ver num of new tip }
ParentNode := TvwTips.Selected; { Parent of new tip node }
if ParentNode.Level = nlTip then{ Parent cannot be a tip node }
ParentNode := TvwTips.Selected.Parent;
TblTips.InsertRecord(['New Subject',ParentNode.Text, VersionNum]);
TipNode := TvwTips.Items.AddChildObject( ParentNode,'New Subject',
Pointer( VersionNum ) );
TipNode.ImageIndex := 3; { Normal tip bitmap }
TipNode.SelectedIndex := 4; { Highlighted tip bitmap }
TipNode.MakeVisible; { Move new tip node into view }
TipNode.EditText; { Immediately allow user to edit subject }
EnableTreeViewFunctions( TipNode.Level );
RtfTip.Clear;
RtfTip.Modified := False;
NbkListView.PageIndex := pgTip;
end; {= TFrmTipExplorer.MnuNewTipClick =}
procedure TFrmTipExplorer.TvwTipsEnter(Sender: TObject);
begin
EnableTipFunctions( False );
EnableTreeViewFunctions( TvwTips.Selected.Level );
end;
procedure TFrmTipExplorer.LvwSubjectsEnter(Sender: TObject);
begin
EnableTipFunctions( False );
EnableTreeViewFunctions( nlTip );
end;
procedure TFrmTipExplorer.LvwCategoriesEnter(Sender: TObject);
begin
EnableTipFunctions( False );
EnableTreeViewFunctions( nlCategory );
end;
{== List View Methods ==}
procedure TFrmTipExplorer.LvwSubjectsChange(Sender: TObject;
Item: TListItem; Change: TItemChange);
begin
if Change = ctState then { Check for ctState, so only update }
begin { table position when selection changes }
UpdateTip;
TblTips.DisableControls;
try
TblTips.Locate( 'Subject', Item.Caption, [] );
finally
TblTips.EnableControls;
end;
UpdateStatusBar( '', Item.Caption );
EnableTreeViewFunctions( nlTip );
end;
end;
procedure TFrmTipExplorer.ListViewDblClick(Sender: TObject);
var
I : Integer;
begin
TvwTips.Selected.Expand( False );
{ Select the tree node corresponding to list item clicked }
I := TListView( Sender ).Selected.Index;
TvwTips.Selected.Item[ I ].Selected := True;
NbkListView.PageIndex := TListView( Sender ).Tag;
end;
procedure TFrmTipExplorer.LvwCategoriesEditing(Sender: TObject;
Item: TListItem; var AllowEdit: Boolean);
begin
AllowEdit := False; { Cannot edit categories }
end;
procedure TFrmTipExplorer.LvwSubjectsEdited(Sender: TObject;
Item: TListItem; var S: string);
var
I : Integer;
begin
TblTips.DisableControls;
try
TblTips.Edit;
TblTips[ 'Subject' ] := S;
TblTips.Post;
{ Must also update corresponding tree node }
I := TListView( Sender ).Selected.Index;
TvwTips.Selected.Item[ I ].Text := S;
finally
TblTips.EnableControls;
end;
end;
procedure TFrmTipExplorer.MnuViewStyleClick(Sender: TObject);
begin
with Sender as TMenuItem do
begin
LvwCategories.ViewStyle := TViewStyle( Tag );
LvwSubjects.ViewStyle := TViewStyle( Tag );
{ Because of new RadioItem property, it is not necessary to }
{ "uncheck" the other menu items in the group }
Checked := True;
end;
end;
{== Tip RichEdit Methods ==}
procedure TFrmTipExplorer.SrcTipsDataChange( Sender : TObject;
Field : TField );
var
S : TBlobStream;
begin
if FLoadingTips or ( SrcTips.State in dsEditModes ) then
Exit;
S := TBlobStream.Create( TMemoField( TblTips.FieldByName('Tip') ),
bmRead );
try
RtfTip.Lines.LoadFromStream( S ); { Load from memo field }
RtfTip.Modified := False;
finally
S.Free;
end;
end;
procedure TFrmTipExplorer.TblTipsBeforePost(DataSet: TDataSet);
var
S : TBlobStream;
begin
S := TBlobStream.Create( TMemoField( TblTips.FieldByName('Tip') ),
bmReadWrite );
try
RtfTip.Lines.SaveToStream( S ); { Store tip in memo field }
finally
S.Free;
end;
end;
procedure TFrmTipExplorer.UpdateTip;
begin
if RtfTip.Modified then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -