⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgkeyboardmap.pas

📁 Delphi编写的一个支持语法高亮显示和很多语言的文本编辑器
💻 PAS
字号:
{
  syn
  Copyright (C) 2000-2002, Ascher Stefan. All rights reserved.
  stievie@utanet.at, http://web.utanet.at/ascherst/

  The contents of this file are subject to the Mozilla Public License
  Version 1.1 (the "License"); you may not use this file except in compliance
  with the License. You may obtain a copy of the License at
  http://www.mozilla.org/MPL/

  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  the specific language governing rights and limitations under the License.

  The Original Code is dlgKeyboardMap.pas, released Sun, 26 May 2002 09:02:11 UTC.

  The Initial Developer of the Original Code is Ascher Stefan.
  Portions created by Ascher Stefan are Copyright (C) 2000-2002 Ascher Stefan.
  All Rights Reserved.

  Contributor(s): .

  Alternatively, the contents of this file may be used under the terms of the
  GNU General Public License Version 2 or later (the "GPL"), in which case
  the provisions of the GPL are applicable instead of those above.
  If you wish to allow use of your version of this file only under the terms
  of the GPL and not to allow others to use your version of this file
  under the MPL, indicate your decision by deleting the provisions above and
  replace them with the notice and other provisions required by the GPL.
  If you do not delete the provisions above, a recipient may use your version
  of this file under either the MPL or the GPL.

  You may retrieve the latest version of this file at the syn home page,
  located at http://syn.sourceforge.net/

  $Id: dlgKeyboardMap.pas,v 1.3 2002/08/08 22:01:26 stievie Exp $
}

unit dlgKeyboardMap;


interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, dMain, StdCtrls, Menus, ExtCtrls, ToolWin;

type
  TKeyboardMapDialog = class(TForm)
    lvKeyMap: TListView;
    Panel1: TPanel;
    Label1: TLabel;
    cboCategory: TComboBox;
    ToolBar1: TToolBar;
    tbbPrint: TToolButton;
    tbbCopy: TToolButton;
    procedure cboCategoryClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure lvKeyMapColumnClick(Sender: TObject; Column: TListColumn);
    procedure tbbPrintClick(Sender: TObject);
    procedure tbbCopyClick(Sender: TObject);
    procedure lvKeyMapResize(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  KeyboardMapDialog: TKeyboardMapDialog;

implementation

{$R *.DFM}

uses
  fMain, ActnList, ClipBrd, uOptVars, printers;

var
  ColumnToSort: integer;
  ASSort: boolean;

function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
var
  ix: Integer;
begin
  if ColumnToSort = 0 then
    Result := CompareText(Item1.Caption, Item2.Caption)
  else begin
   ix := ColumnToSort - 1;
   Result := CompareText(Item1.SubItems[ix], Item2.SubItems[ix]);
  end;
  if ASSort then
    Result := -Result;
end;

procedure TKeyboardMapDialog.cboCategoryClick(Sender: TObject);
  procedure AddAction(ac: TAction);
  var
    li: TListItem;
  begin
    li := lvKeyMap.Items.Add;
    li.Caption := ReplaceAcc(ac.Caption);
    li.SubItems.Add(ShortCutToText(ac.ShortCut));
    li.SubItems.Add(GetlongHint(ac.Hint));
  end;
  procedure AddAllActions(ABoundOnly: boolean);
  var
    j: integer;
  begin
    with dmMain.actMain do
      for j := 0 to ActionCount - 1 do
        if (Actions[j].Category <> '') and ((TAction(Actions[j]).ShortCut <> 0) or not ABoundOnly) then
          AddAction(TAction(Actions[j]));
  end;
  procedure AddActionCat(Cat: string);
  var
    i: integer;
  begin
    with dmMain.actMain do
      for i := 0 to ActionCount - 1 do
        if SameText(Actions[i].Category, Cat) then
          AddAction(TAction(Actions[i]));
  end;
begin
  lvKeyMap.Items.BeginUpdate;
  lvKeyMap.Items.Clear;
  if cboCategory.ItemIndex > 1 then
    AddActionCat(cboCategory.Text)
  else
    AddAllActions(cboCategory.ItemIndex = 0);
  lvKeyMap.Items.EndUpdate;
  if lvKeyMap.Items.Count > 0 then
    lvKeyMap.Items[0].Selected := true;
  ASSort := true;
end;

procedure TKeyboardMapDialog.FormCreate(Sender: TObject);
begin
  Screen.Cursor := crHourGlass;
  try
    cboCategory.ItemIndex := 0;
    cboCategoryClick(cboCategory);
    ASSort := true;
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TKeyboardMapDialog.lvKeyMapColumnClick(Sender: TObject;
  Column: TListColumn);
begin
  ColumnToSort := Column.Index;
  (Sender as TCustomListView).CustomSort(@CustomSortProc, 0);
  ASSort := not ASSort;
end;

procedure TKeyboardMapDialog.tbbPrintClick(Sender: TObject);
var
  i, cury, page: integer;
resourcestring
  SPrintTitle = 'cEdit - Keyboardmap';
  SPageNum = '- %d -';
  SHeader = 'cEdit Help - Keyboardmap: %s';
  function GetString(li: TListItem): string;
  begin
    with li do begin
      Result := Caption + StringOfChar(#32, 28 - Length(Caption));
      if SubItems[0] = '' then
        Result := Result + '-' + StringOfChar(#32, 15)
      else
        Result := Result + SubItems[0] + StringOfChar(#32, 16 - Length(SubItems[0]));
      Result := Result + SubItems[1];
    end;
  end;
  procedure PrintHeader;
  var
    s: string;
  begin
    s := Format(SPageNum, [page]);
    Printer.Canvas.TextOut((Printer.PageWidth div 2) -
      (Printer.Canvas.TextWidth(s) div 2), cury, s);
    Inc(cury, Printer.Canvas.TextHeight('Og') + 10);
    s := Format(SHeader, [cboCategory.Text]);
    Printer.Canvas.TextOut((Printer.PageWidth div 2) -
      (Printer.Canvas.TextWidth(s) div 2), cury, s);
    Inc(cury, (Printer.Canvas.TextHeight('Og') + 10) * 2);
  end;
begin
  with TPrintDialog.Create(Self) do begin
    try
      if Execute then begin
        Screen.Cursor := crHourGlass;
        try
          with Printer do begin
            Canvas.Font.Name := 'Courier New';
            Canvas.Font.Size := 8;
            BeginDoc;
            cury := 50;
            page := 1;
            PrintHeader;
            Title := SPrintTitle;
            for i := 0 to lvKeyMap.Items.Count - 1 do begin
              Canvas.TextOut(50, cury, GetString(lvKeyMap.Items[i]));
              Inc(cury, Canvas.TextHeight('Og') + 10);
              if (cury + 50 > PageHeight) and (i < lvKeyMap.Items.Count - 1) then begin
                NewPage;
                Inc(page);
                cury := 50;
                PrintHeader;
              end;
            end;
            EndDoc;
          end;
        finally
          Screen.Cursor := crDefault;
        end;
      end;
    finally
      Free;
    end;
  end;

end;

procedure TKeyboardMapDialog.tbbCopyClick(Sender: TObject);
var
  c: TClipboard;
  i: integer;

  // longest Caption = 27
  // longest Shortcut = 15
  procedure AddToString(const li: TListItem);
  var
    s: string;
  begin
    with li do begin
      s := s + Caption + StringOfChar(#32, 28 - Length(Caption));
      if SubItems[0] = '' then
        s := s + '-' + StringOfChar(#32, 15)
      else
        s := s + SubItems[0] + StringOfChar(#32, 16 - Length(SubItems[0]));
      s := s + SubItems[1];
    end;
    if c.AsText = '' then
      c.AsText := c.AsText + s
    else
      c.AsText := c.AsText + CrLf + s;
  end;
begin
  Screen.Cursor := crHourGlass;
  try
    if lvKeyMap.SelCount > 0 then begin
      c := TClipboard.Create;
      try
        c.Clear;
        for i := 0 to lvKeyMap.Items.Count - 1 do
          if lvKeyMap.Items[i].Selected then
            AddToString(lvKeyMap.Items[i]);
      finally
        c.Free;
      end;
    end;
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TKeyboardMapDialog.lvKeyMapResize(Sender: TObject);
begin
  lvKeyMap.Columns[2].Width := lvKeyMap.ClientWidth - lvKeyMap.Columns[0].Width - lvKeyMap.Columns[1].Width;
end;

end.

⌨️ 快捷键说明

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