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

📄 foptions.pas

📁 Delphi编写的一个支持语法高亮显示和很多语言的文本编辑器
💻 PAS
📖 第 1 页 / 共 4 页
字号:
resourcestring
  SAlreadyExists = 'This Item already exists.';
var
  aei: integer;
begin
  aei := AlreadyExists(txtAutocorrReplace.Text);
  if aei > -1 then begin
    lvwAutocorrect.Items[aei].Selected := true;
    Application.MessageBox(PChar(SAlreadyExists), PChar(SAppTitle), MB_ICONSTOP + MB_OK);
  end else begin
    with lvwAutocorrect.Items.Add do begin
      Caption := txtAutocorrReplace.Text;
      SubItems.Add(txtAutocorrWith.Text);
      Selected := true;
    end;
    fAutoCorrect.Add(txtAutocorrReplace.Text + Chr(9) + txtAutocorrWith.Text);
    lvwAutocorrect.AlphaSort;
    fAutoCorrect.Sort;
    txtAutocorrReplace.SetFocus;
  end;
end;

procedure TfrmOptions.btnAutoCorrReplaceClick(Sender: TObject);
begin
  with lvwAutocorrect.Selected do begin
    Caption := txtAutocorrReplace.Text;
    SubItems[0] := txtAutocorrWith.Text;
    fAutoCorrect[Index] := txtAutocorrReplace.Text + Chr(9) + txtAutocorrWith.Text;
  end;
  lvwAutocorrect.AlphaSort;
  fAutoCorrect.Sort;
end;

procedure TfrmOptions.btnAutocorrectRemoveClick(Sender: TObject);
begin
  fAutoCorrect.Delete(lvwAutocorrect.Selected.Index);
  lvwAutocorrect.Items.Delete(lvwAutocorrect.Selected.Index);
end;

procedure TfrmOptions.lvwAutocorrectSelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
  if Selected then begin
    txtAutocorrReplace.Text := Item.Caption;
    txtAutocorrWith.Text := Item.SubItems[0];
  end;
  btnAutoCorrReplace.Enabled := Selected and btnAutocorrectAdd.Enabled;
  btnAutocorrectRemove.Enabled := Selected;
end;

procedure TfrmOptions.TemporaryDirectory1Click(Sender: TObject);
var
  e: TEdit;
begin
  if popDirs.Tag = 1 then
    e := txtToolCommand
  else
    e := txtToolCommand;
  case (Sender as TMenuItem).Tag of
    3: e.SelText := SVarWinDirShort;
    4: e.SelText := SVarSysDirShort;
    5: e.SelText := SVarTempDirShort;
  end;
end;

procedure TfrmOptions.SystemDirectory1Click(Sender: TObject);
var
  cp: TPoint;
begin
  GetcursorPos(cp);
  popDirs.Tag := (Sender as TCorelButton).Tag;
  popDirs.Popup(cp.x, cp.y);
end;

procedure TfrmOptions.Prompt1Click(Sender: TObject);
var
  e: TEdit;
begin
  if popParams.Tag = 1 then
    e := txtToolArgs
  else
    e := txtToolCommand;
  case (Sender as TMenuItem).Tag of
    50: e.SelText := SVarWinDirShort;
    51: e.SelText := SVarSysDirShort;
    52: e.SelText := SVarTempDirShort;
  end;
end;

procedure TfrmOptions.btnCEDeleteClick(Sender: TObject);
resourcestring
  SDelete = 'Do you want to delete the Code Template "%s" (%s)?' + CrLf +
    'This can not be undone.';
  SCaption = 'Confirm Delete';
var
  ix: integer;
  l, d: string;
begin
  if Assigned(lvwAutoComplete.Selected) then begin
    ix := lvwAutoComplete.Selected.Index;
    l := lvwAutoComplete.Selected.Caption;
    d := lvwAutoComplete.Selected.SubItems[0];
    if Application.MessageBox(PChar(Format(SDelete, [l, d])),
      PChar(SCaption), MB_ICONQUESTION + MB_YESNO) = ID_YES then begin
      lvwAutoComplete.Items.Delete(ix);
    end;
  end;
end;

procedure TfrmOptions.btnToolDirParamClick(Sender: TObject);
var
  cp: TPoint;
begin
  GetcursorPos(cp);
  popDirs.Tag := (Sender as TCorelButton).Tag;
  popDirs.Popup(cp.x, cp.y);
end;

procedure TfrmOptions.btnExternalClick(Sender: TObject);
begin
  with OpenDialog1 do begin
    Filter := 'Executable Files (*.exe)|*.exe|All Files (*.*)|*.*';
    if FileExists(edtExternalBrowser.Text) then
      FileName := edtExternalBrowser.Text;
    if Execute then begin
      edtExternalBrowser.Text := FileName;
    end;
  end;
end;

procedure TfrmOptions.btnCreateClick(Sender: TObject);
var
  i: Integer;
begin
  cHighlighter := TSynAnySyn.Create(dmMain);
  pgCustomLang.Enabled := True;
  For i:=0 to cHighlighter.AttrCount - 1 do
    lstAttributesCustom.Items.Add(cHighlighter.Attribute[i].Name);
  lstAttributesCustom.ItemIndex := 0;
end;

procedure TfrmOptions.chkBoldCustClick(Sender: TObject);
var
  Style: TFontStyles;
begin
  if cHighlighter <> nil then begin
    Style := [];
    if chkBold.Checked then
      Include(Style, fsBold);
    if chkItalic.Checked then
      Include(Style, fsItalic);
    if chkUnderLine.Checked then
      Include(Style, fsUnderline);
    if chkStrike.Checked then
      Include(Style, fsStrikeOut);
    cHighlighter.Attribute[lstAttributesCustom.ItemIndex].Style := Style;
  end;
end;

procedure TfrmOptions.clrButBackChange(Sender: TObject);
begin
  if cHighlighter <> nil then
    cHighlighter.Attribute[lstAttributesCustom.ItemIndex].Background := clrButBack.SelectionColor;
end;

procedure TfrmOptions.clrButForChange(Sender: TObject);
begin
  if cHighlighter <> nil then
    cHighlighter.Attribute[lstAttributesCustom.ItemIndex].Foreground := clrButFor.SelectionColor;
end;

procedure TfrmOptions.btnSaveClick(Sender: TObject);
var
  ini: TiniFile;
  b,i: Integer;
  strList: TStringList;
begin
  if cHighlighter = nil then exit;
  cHighlighter.SaveToFile(ExtractFilePath(Application.ExeName) + 'highlighters\' + edtFilename.Text);
  ini := tinifile.Create(ExtractFilePath(Application.ExeName) + 'highlighters\' + edtFilename.Text);
  ini.WriteString('Name', 'LanguageName', edtName.Text);
  ini.WriteString('Filter', 'DefaultFilter', edtFilter.Text);
  ini.WriteString('CommentStyle', 'ansi', cmbAnsi.Text);
  ini.WriteString('CommentStyle', 'asm', cmbASM.Text);
  ini.WriteString('CommentStyle', 'bas', cmbBas.Text);
  ini.WriteString('CommentStyle', 'c', cmbC.Text);
  ini.WriteString('CommentStyle', 'pas', cmbPas.Text);
  ini.WriteString('CommentStyle', 'vb', cmbVB.Text);
  ini.WriteString('String Delimiter', 'Double Quotes', cmbDoubleLine.Text);
  ini.WriteString('String Delimiter', 'Single Quotes', cmbSingleLine.Text);
  ini.WriteString('Switches', 'markup', cmbMarkup.Text);
  ini.WriteString('Switches', 'entity', cmbEntity.Text);
  ini.WriteString('Switches', 'dollarvariables', cmbDollar.Text);
  ini.WriteString('Switches', 'ActiveDot', cmbActive.Text);

  ini.WriteString('Objects', 'Objects', '');
  ini.WriteString('Constants', 'Constants', '');
  ini.WriteString('Keys', 'Keys', '');
  ini.EraseSection('Objects');
  ini.EraseSection('Constants');
  ini.EraseSection('Keywords');
  strList := TStringList.Create;
  strList.LoadFromFile(ini.Filename);
  strList.Add('[Objects]');
  for i:=0 to memoObjects.Lines.Count -1 do
    strList.Add(memoObjects.Lines[i]);
  strList.Add('[Constants]');
  for i:=0 to memoConstants.Lines.Count -1 do
    strList.Add(memoConstants.Lines[i]);
  strList.Add('[Keywords]');
  for i:=0 to memoKeywords.Lines.Count -1 do
    strList.Add(memoKeywords.Lines[i]);
  strList.SaveToFile(ini.Filename);
  ini.Free;
  cHighlighter := nil
end;

procedure TfrmOptions.lstAttributesCustomClick(Sender: TObject);
var
  Attr: TSynHighlighterAttributes;
begin
  if cHighlighter = nil then exit;
  Attr := TSynHighlighterAttributes.Create('');
  Attr.Assign(cHighlighter.Attribute[lstAttributesCustom.itemindex]);
  clrButFor.SelectionColor := attr.Foreground;
  clrButBack.SelectionColor := attr.Background;
  chkBoldCust.Checked := (fsBold in attr.Style);
  chkItalicCust.Checked := (fsItalic in attr.Style);
  chkUnderlineCust.Checked := (fsUnderline in attr.Style);
  chkStrikeCust.Checked := (fsStrikeout in attr.Style);
end;

procedure TfrmOptions.edtCommentChange(Sender: TObject);
begin
  synHighlighter.DefaultFilter := edtFilters.Text;
end;

procedure TfrmOptions.lstLangs2Click(Sender: TObject);
begin
  synHighlighter := dmMain.SetHighlighter(lstLangs2.Items[lstLangs2.ItemIndex]);
  if synHighlighter = nil then exit;
  lstKeywords.Items.Assign(synHighlighter.FunctionKeys);
  chkWords.Checked := synHighlighter.CanhaveCharsBefore;
end;

procedure TfrmOptions.btnAddKeyClick(Sender: TObject);
begin
  if edtKeyword.Text <> '' then begin
   if synHighlighter = nil then exit;
   synHighlighter.FunctionKeys.Add(edtKeyword.text);
   lstKeywords.Items.Assign(synHighlighter.FunctionKeys);
  end;
end;

procedure TfrmOptions.chkWordsClick(Sender: TObject);
begin
  if SynHighlighter <> nil then
    SynHighlighter.CanhaveCharsBefore := chkWords.Checked;
end;

procedure TfrmOptions.lstLang3Click(Sender: TObject);
var
  d: PSecurityAttributes;
  s,l: String;
  rec: TSearchRec;
begin
  synSnippet.Highlighter := dmMain.SetHighlighter(lstLang3.Items[lstLang3.ItemIndex]);
  s := AnsiReplaceText(lstLang3.Items[lstLang3.ItemIndex], '\', '');
  s := AnsiReplaceText(s, '/', '');
  l := ExtractFilePath(Application.ExeName) + 'snippets\' + s;
  if DirectoryExists(l) = false then begin
    CreateDir(PChar(l));
    exit;
  end;
  lstSnippets.Items.Clear;
  if findFirst(ExtractFilePath(Application.ExeName) + 'snippets\' + s + '\*.snp', faAnyFile, Rec) = 0 then begin
    lstSnippets.Items.Add(Rec.Name);
  end;
  While FindNext(rec) = 0 do
  begin
    lstSnippets.Items.Add(Rec.Name);
  end;
end;

procedure TfrmOptions.btnSaveSnippetClick(Sender: TObject);
var
  s,l: String;
  d: PSecurityAttributes;
  rec: TSearchRec;
begin
  s := AnsiReplaceText(lstLang3.Items[lstLang3.ItemIndex], '\', '');
  s := AnsiReplaceText(s, '/', '');
  l := ExtractFilePath(Application.ExeName) + 'snippets\';
  if DirectoryExists(l) = false then CreateDir(PChar(l));
  if edtSave.Text = '' then begin
    MessageBox(frmOptions.Handle, 'You must include a filename.', 'Error', 0);
    exit;
  end;
  synSnippet.Lines.SaveToFile(l +  '\' + s + '\' + edtSave.Text + '.snp');
  lstSnippets.Items.Clear;
  if findFirst(ExtractFilePath(Application.ExeName) + 'snippets\' + s + '\*.snp', faAnyFile, Rec) = 0 then begin
    lstSnippets.Items.Add(Rec.Name);
  end;
  While FindNext(rec) = 0 do
  begin
    lstSnippets.Items.Add(Rec.Name);
  end;

end;

procedure TfrmOptions.lstSnippetsClick(Sender: TObject);
var
  d: PSecurityAttributes;
  s,l: String;
  rec: TSearchRec;
begin

  s := AnsiReplaceText(lstLang3.Items[lstLang3.ItemIndex], '\', '');
  s := AnsiReplaceText(s, '/', '');
  l := ExtractFilePath(Application.ExeName) + 'snippets\' + s + '\' + lstSnippets.Items[lstSnippets.ItemIndex];
  edtSave.Text := LeftStr(lstSnippets.Items[lstSnippets.ItemIndex], StrLen(PChar(lstSnippets.Items[lstSnippets.ItemIndex])) - (StrLen(PChar(ExtractFileExt(PChar(lstSnippets.Items[lstSnippets.ItemIndex]))))));
  synSnippet.Lines.LoadFromFile(l);
  synSnippet.Highlighter := dmMain.SetHighlighter(lstLang3.Items[lstLang3.ItemIndex]);
end;

procedure TfrmOptions.chkDefaultClick(Sender: TObject);
begin
  cmbLangs.Enabled := chkDefault.Checked; 
end;

procedure TfrmOptions.FormShow(Sender: TObject);
begin
  SetOptions;
end;
procedure TfrmOptions.LoadTagsi(strFile: String);
var
  strList: TStringList;
  tNode: TElTreeItem;
  tmpStr: String;
  strData: String;
  i: Integer;
begin
  strList := TStringList.Create;

  strList.LoadFromFile(ExtractFilePath(Application.ExeName) + 'tags\' + strFile);
  lstTags.Items.Clear;
  tmpStr := '';
  lockWindowUpdate(lstTags.Handle);
  for i := 0 to strList.Count-1 do begin
    if (LeftStr(strList[i], 2) = '#T') or (i = strList.Count-1) then begin
      if strData <> '' then begin
        with lstTags.Items.Add do begin

          Caption := strData;
          Subitems.Add(tmpStr);
          tmpStr := '';

        end;
      end;
        strData := MIdStr(strList[i], 4, Length(strList[i]));

      if (i <> strList.Count-1) then begin

      end;

    end
    else begin
      if tmpStr <> '' then
        tmpStr := tmpStr + Chr(10) + strList[i]
      else
        tmpStr := strList[i];
      //TagList.Add(tmpStr);
    end;
  end;
  //MessageBox(0, PChar(TagList.Text), 'test', mB_OK);
  LockWindowUpdate(0);
end;


procedure TfrmOptions.FormCreate(Sender: TObject);
begin
  LoadTags;
end;

procedure TfrmOptions.cmbTagsChange(Sender: TObject);
begin
  LoadTagsi(cmbTags.Text);
end;

procedure TfrmOptions.btnEditTagClick(Sender: TObject);
begin
  if lstTags.Selected = nil then exit;
  With TfrmTagEdit.Create(nil) do begin
    edtTag.Text := lstTags.Selected.Caption;
    memTag.Text := lstTags.Selected.SubItems[0];
    ShowModal;
  end;
end;

procedure TfrmOptions.btnDeleteTagClick(Sender: TObject);
begin
  if lstTags.Selected <> nil then begin
    lstTags.Selected.Delete;
    SaveTags;
  end;
end;

procedure TfrmOptions.btnAddTagClick(Sender: TObject);
begin
  With TfrmTagEdit.Create(nil) do begin
    bNewTag := True;
    ShowModal;
  end;
end;

procedure TfrmOptions.btnCreateTagFileClick(Sender: TObject);
var
  str: String;
  p: TStringList;
begin
  if InputQuery('New Tag File', 'Please input a filename for the new tag file with no extension', str) then begin
    p := TStringList.Create;
    p.SaveToFile(ExtractFilePath(Application.Exename) + 'tags\' + str + '.tag');
    p.Free;
    LoadTags;
  end;
end;

procedure TfrmOptions.btnRemClick(Sender: TObject);
var
  s,l: String;
  rec: TSearchRec;  
begin
  s := AnsiReplaceText(lstLang3.Items[lstLang3.ItemIndex], '\', '');
  s := AnsiReplaceText(s, '/', '');
  l := ExtractFilePath(Application.ExeName) + 'snippets\' + s + '\';
  DeleteFile(l + lstSnippets.Items[lstSnippets.ItemIndex]);
  lstSnippets.Items.Clear;
  if findFirst(ExtractFilePath(Application.ExeName) + 'snippets\' + s + '\*.snp', faAnyFile, Rec) = 0 then begin
    lstSnippets.Items.Add(Rec.Name);
  end;
  While FindNext(rec) = 0 do
  begin
    lstSnippets.Items.Add(Rec.Name);
  end;
end;

end.

⌨️ 快捷键说明

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