ini.pad

来自「Jedi Code Library JCL JVCL 组件包 JCL+JVCL超」· PAD 代码 · 共 96 行

PAD
96
字号
{
  Ini-file specific support
}

unit Ini;

{ Global variables }
var
  IniItem: TMenuItem;
  IniItemAdd: TMenuItem;
  IniShowSectionsItem: TMenuItem;

const
  IniGotoSectionLineOffset = 3;

{ function NewItem(const ACaption: string; AShortCut: TShortCut; AChecked, AEnabled: Boolean; AOnClick: TNotifyEvent; hCtx: Word; const AName: string): TMenuItem; }

procedure InitIni;
var
  Empty: Integer;
  Ctrl: Integer;
begin
  IniItem := nil;
  IniItem := NewItem('&Ini', 0, False, True, 0, nil {ignored - always must be nil}, 'miIni');
  MainWindow.Menu.Items.Insert(MainWindow.Menu.Items.Count - 1, IniItem);
  IniItem.OnClick := IniClick;
  IniItem.Visible := False;

  Empty := [];
  Ctrl := [ssCtrl];

  IniShowSectionsItem := NewItem('Go To Section', ShortCut(ord('L'), Ctrl), False, True, 0, 0, 'miIniShowSectionsItem');
  IniShowSectionsItem.OnClick := IniShowSectionsItemClick;
  IniItem.Add(IniShowSectionsItem);
end;

procedure OpenIni(FileName: string);
begin
  IniItem.Visible := Cmp(Editor.HighlighterName, 'Ini');
end;

procedure CloseIni(FileName: string);
begin
  IniItem.Visible := False;
end;

procedure IniClick(Sender: TObject);
begin
//  IniItemFind.Enabled := P > 0;
end;

procedure IniShowSectionsItemClick(Sender: TObject);
var
  Form: TForm;
  ListBox: TListBox;
  i: Integer;
  S: string;
  Y: Integer;
  YY: Integer;
begin
  // All forms was constructed in Delphi 5....
  Form := JvInterpreterMakeForm(WorkingDir + 'fIniSections.pas');
  try
    ListBox := Form.FindComponent('ListBox1');
    Y := Editor.CaretY;
    YY := -1;
    for i := 0 to Editor.Lines.Count - 1 do
    begin
      S := Editor.Lines.Strings[i];
      if Length(S) > 2 then
        if (S[1] = '[') and (S[Length(S)] = ']') then
        begin
          ListBox.Items.AddObject(Copy(S, 2, Length(S) - 2), i);
          if (YY = -1) and (Y < i) then
            YY := ListBox.Items.Count - 2;
        end;
    end;
    if YY = -1 then
      YY := ListBox.Items.Count - 1;
    ListBox.ItemIndex := YY;
    if Form.ShowModal = mrOk then
      if ListBox.ItemIndex > -1 then
      begin
        i := Integer(ListBox.Items.Objects[ListBox.ItemIndex]);
        Editor.SetLeftTop(0, i - IniGotoSectionLineOffset);
        Editor.CaretY := i + 1;
        Editor.CaretX := 0;
      end;
  finally
    Form.Free;
  end;
end;


end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?