Delphi-PRAXiS
Seite 2 von 4     12 34      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Die Delphi-IDE (https://www.delphipraxis.net/62-die-delphi-ide/)
-   -   Feature: Block oder Zeile duplizieren (https://www.delphipraxis.net/166096-feature-block-oder-zeile-duplizieren.html)

haentschman 30. Jan 2012 13:09

AW: Feature: Block oder Zeile duplizieren
 
Zitat:

nur sollte man sich dann fragen, ob man es nicht in eine Routine mit entsprechenden Parameteraufruf auslagern sollte.
Klar kann man alles in eine Procedure packen. Aber bei 20 verschieden Listen mit 20 verschiedenen Objektypen der dazugehörigen SQL aus 20 verschiedenen Tabellen... sind mir 20 kleine übersichtliche Prozeduren allemal lieber.

himitsu 30. Jan 2012 13:16

AW: Feature: Block oder Zeile duplizieren
 
Ich würde es anders ausdrücken.

Diese Zeilen-/Block Kopierfunktion kompiert ja untereinanderliegende Zeilen/Blöcke.
Und so nh zusammenliegend sollte man nicht kopieren (das schreit regelrecht nach DRY).

Und ja, auch ich kopiere hin und wieder. (verändere danach aber auch so Einiges daran, also nicht 1:1)
Aber das ich dafür eine extra Tastenkombi benötige, ist mir noch nicht vorgekommen ... sooooooooo oft kopiere ich dann auch nicht :roll:

DeddyH 30. Jan 2012 13:20

AW: Feature: Block oder Zeile duplizieren
 
Folgendes Beispiel:
Delphi-Quellcode:
type
  IDings = interface
  ['{DCA3F4EE-8DDF-422C-8235-1AB3ADC70596}']
    procedure Machwas;
    procedure MachNochwas;
    procedure MachGarnix;
  end;

  TTest = class(TInterfacedObject, IDings)

  end;

  TNochnTest = class(TInterfacedObject, IDings)

  end;
Wenn mir nun jemand den Shortcut nennt, mit dem die Methoden aus dem Interface, die ja in den Klassen durch Einbinden desselben implementiert werden müssen, in die Klassendeklarationen kopiert werden, dann behaupte ich auch, C&P braucht man eigentlich nie. Es müssen auch nicht unbedingt Interfaces sein, Elternklassen mit abstrakten Methoden genügen auch.

himitsu 30. Jan 2012 14:26

AW: Feature: Block oder Zeile duplizieren
 
Hier wäre das Refactoring doch gut, also wenn man wie bei Strg+Shift+C die Methoden des Interfaces kopieren lassen könnte.
Ansonsten helfen doch auch die normalen Kopierfunktionen (Strg+C und Co.) oder was wölltest du einer spezialisierten Tastenkombo nich mitgeben wollen?

Ansonsten wäre sowas schön, wo Delphi die Public-Methoden und Property als Interface veröffentlicht und bei TTest dieses Interface mit verknüpft.
Delphi-Quellcode:
type
  TTest = class(TInterfacedObject)

  end;

  ITest = generate interface for TTest;

DeddyH 30. Jan 2012 14:32

AW: Feature: Block oder Zeile duplizieren
 
Zitat:

Zitat von himitsu (Beitrag 1148329)
Hier wäre das Refactoring doch gut, also wenn man wie bei Strg+Shift+C die Methoden des Interfaces kopieren lassen könnte.

Eben.
Zitat:

Zitat von himitsu (Beitrag 1148329)
Ansonsten helfen doch auch die normalen Kopierfunktionen (Strg+C und Co.)

Und genau darum geht es doch die ganze Zeit.

himitsu 30. Jan 2012 14:48

AW: Feature: Block oder Zeile duplizieren
 
Ich dachte jemand wollte eine Blockkopierfunktion, also einen eigenen Shortcut dafür?

DeddyH 30. Jan 2012 14:51

AW: Feature: Block oder Zeile duplizieren
 
Ab #5 kam der "Beigeschmack" auf, dass C&P beinahe zwangsgerade auf einen Verstoß gegen DRY hinweist/hinweisen könnte. Manchmal kommt man aber ohne nicht aus (C&P meine ich, nicht DRY), einfach weil die IDE keine Alternative bietet, das wollte ich mit meinem Beispiel zeigen.

ChrisE 30. Jan 2012 14:54

AW: Feature: Block oder Zeile duplizieren
 
Aber er hat doch extra drum gebeten:
Zitat:

Zitat von s.h.a.r.k (Beitrag 1148240)
Bitte keine Diskussion über Copy-and-Paste-Fehler anfangen! Danke :stupid:

Es ging doch nur um die Möglichkeit - um sonst nichts :-D

jaenicke 30. Jan 2012 16:35

AW: Feature: Block oder Zeile duplizieren
 
Zitat:

Zitat von DeddyH (Beitrag 1148269)
Wenn mir nun jemand den Shortcut nennt, mit dem die Methoden aus dem Interface, die ja in den Klassen durch Einbinden desselben implementiert werden müssen, in die Klassendeklarationen kopiert werden, dann behaupte ich auch, C&P braucht man eigentlich nie. Es müssen auch nicht unbedingt Interfaces sein, Elternklassen mit abstrakten Methoden genügen auch.

Dafür habe ich einen Experten geschrieben. Leider kann der die neue Syntax noch nicht. Der ist bei D2006 stehen geblieben. Und ich glaube auch nicht, dass ich den in absehbarer Zeit auf den Stand von XE2 bringen kann.
Aber ich könnte das Ding ja einfach mal veröffentlichen, vielleicht macht ja jemand weiter...

madtom 30. Jan 2012 17:14

AW: Feature: Block oder Zeile duplizieren
 
Hallo,

ein Stichwort wäre Key Binding über die ToolsAPI:
Delphi-Quellcode:
// Duplicate Line Key Binding
// Copyright (c) 2001-2010 Cary Jensen, Jensen Data Systems, Inc.


unit Dupline;

// Duplicate Line Key Binding
// Copyright (c) 2001-2010 Cary Jensen, Jensen Data Systems, Inc.
//
// You may freely distribute this unit, so long as this comment
// section is retained, and no fee is charged for it.
//
// This key binding is provided as a demonstration of key bindings.
//
// To use this key binding, install it into a design-time package.
//
// Once installed, this key binding adds a Ctrl-Shift-D (duplicate line) function to the code editor.
//
// No warranty is intended or implied concerning the
// appropriateness of this code example for any other use. If you use
// this examples, or any part of it, you assume all responsibility
// for ensuring that it works as intended.
//
// For information concerning Delphi training, visit www.jensendatasystems.com.

interface

uses
  SysUtils, Classes, Dialogs, Controls, Windows, Menus, ToolsAPI;

procedure register;

implementation

type
  TDupLineBinding = class(TNotifierObject, IOTAKeyboardBinding)
  private
  public
    procedure Dupline(const Context: IOTAKeyContext; KeyCode: TShortcut;
      var BindingResult: TKeyBindingResult);
    procedure AppendComment(const Context: IOTAKeyContext; KeyCode: TShortcut;
      var BindingResult: TKeyBindingResult);
    procedure CommentToggle(const Context: IOTAKeyContext; KeyCode: TShortcut;
      var BindingResult: TKeyBindingResult);
    procedure CommentToggle1(const Context: IOTAKeyContext; KeyCode: TShortcut;
      var BindingResult: TKeyBindingResult);

    { IOTAKeyboardBinding }
    function GetBindingType: TBindingType;
    function GetDisplayName: string;
    function GetName: string;
    procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
  end;

procedure register;
begin
  (BorlandIDEServices as IOTAKeyboardServices).AddKeyboardBinding(TDupLineBinding.Create);
end;

{ TKeyBindingImpl }

function TDupLineBinding.GetBindingType: TBindingType;
begin
  Result := btPartial;
end;

function TDupLineBinding.GetDisplayName: string;
begin
  Result := 'Duplicate Line Binding';
end;

function TDupLineBinding.GetName: string;
begin
  Result := 'jdsi.dupline';
end;

procedure TDupLineBinding.BindKeyboard(const BindingServices: IOTAKeyBindingServices);
begin
  BindingServices.AddKeyBinding([Shortcut(Ord('D'), [ssShift, ssCtrl])], Dupline, nil);
  // BindingServices.AddKeyBinding([Shortcut(Ord('C'), [ssShift, ssCtrl])], AppendComment, nil);
  BindingServices.AddKeyBinding([Shortcut(VK_F1, [ssShift, ssCtrl])], CommentToggle, nil);
  // BindingServices.AddKeyBinding([Shortcut(VK_F1, [ssShift, ssCtrl])], CommentToggle1, nil);
  // Add additional key bindings here
end;

procedure TDupLineBinding.Dupline(const Context: IOTAKeyContext; KeyCode: TShortcut;
  var BindingResult: TKeyBindingResult);
var
  EditPosition: IOTAEditPosition;
  EditBlock: IOTAEditBlock;
  CurrentRow: Integer;
  CurrentRowEnd: Integer;
  BlockSize: Integer;
  IsAutoIndent: Boolean;
  CodeLine: string;
begin
  EditPosition := Context.EditBuffer.EditPosition;
  EditBlock := Context.EditBuffer.EditBlock;
  // Save the current edit block and edit position
  EditBlock.Save;
  EditPosition.Save;
  try
    // Store original cursor row
    CurrentRow := EditPosition.Row;
    // Length of the selected block (0 means no block)
    BlockSize := EditBlock.Size;
    // Store AutoIndent property
    IsAutoIndent := Context.EditBuffer.BufferOptions.AutoIndent;
    // Turn off AutoIndent, if necessary
    if IsAutoIndent then
      Context.EditBuffer.BufferOptions.AutoIndent := False;
    // If no block is selected, or the selected block is a single line,
    // then duplicate just the current line
    if (BlockSize = 0) or (EditBlock.StartingRow = EditPosition.Row) or
      ((BlockSize <> 0) and ((EditBlock.StartingRow + 1) = (EditPosition.Row)) and
        (EditBlock.EndingColumn = 1)) then
    begin
      // Only a single line to duplicate
      // Move to end of current line
      EditPosition.MoveEOL;
      // Get the column position
      CurrentRowEnd := EditPosition.Column;
      // Move to beginning of current line
      EditPosition.MoveBOL;
      // Get the text of the current line, less the EOL marker
      CodeLine := EditPosition.read(CurrentRowEnd - 1);
      // Add a line
      EditPosition.InsertText(#13);
      // Move to column 1
      EditPosition.Move(CurrentRow, 1);
      // Insert the copied line
      EditPosition.InsertText(CodeLine);
    end
    else
    begin
      // More than one line selected. Get block text
      CodeLine := EditBlock.Text;
      // Move to the end of the block
      EditPosition.Move(EditBlock.EndingRow, EditBlock.EndingColumn);
      // Add a line
      EditPosition.InsertText(#13);
      // Insert block text
      EditPosition.InsertText(CodeLine);
    end;
    // Restore AutoIndent, if necessary
    if IsAutoIndent then
      Context.EditBuffer.BufferOptions.AutoIndent := True;
    BindingResult := krHandled;
  finally
    // Move cursor to original position
    EditPosition.Restore;
    // Restore the original block (if one existed)
    EditBlock.Restore;
  end;
end;

procedure TDupLineBinding.AppendComment(const Context: IOTAKeyContext; KeyCode: TShortcut;
  var BindingResult: TKeyBindingResult);
var
  EditPosition: IOTAEditPosition;
  eColumn: Integer;
begin
  EditPosition := Context.EditBuffer.EditPosition;
  EditPosition.MoveEOL;
  eColumn := EditPosition.Column;
  EditPosition.InsertText(' // ' + DateTimeToStr(Now) + #13);
  EditPosition.Move(EditPosition.Row, eColumn);
  EditPosition.InsertText(' // Author: Cary Jensen');
  BindingResult := krHandled;
end;

procedure TDupLineBinding.CommentToggle(const Context: IOTAKeyContext; KeyCode: TShortcut;
  var BindingResult: TKeyBindingResult);
var
  EditPosition: IOTAEditPosition;
  EditBlock: IOTAEditBlock;
  StartRow: Integer;
  EndRow: Integer;
  Comment: Boolean;
begin
  // original edit position
  EditPosition := Context.EditBuffer.EditPosition;
  EditPosition.Save;
  // edit block
  EditBlock := Context.EditBuffer.EditBlock;
  // find the starting and ending rows to operate on
  if EditBlock.Size = 0 then
  begin
    StartRow := EditPosition.Row;
    EndRow := EditPosition.Row;
  end

  else if (EditBlock.EndingColumn = 1) then
  begin
    StartRow := EditBlock.StartingRow;
    EndRow := EditBlock.EndingRow - 1;
  end

  else
  begin
    StartRow := EditBlock.StartingRow;
    EndRow := EditBlock.EndingRow;
  end;

  // toggle comments
  repeat
  begin
    EditPosition.Move(StartRow, 1);
    while EditPosition.IsWhiteSpace do
      EditPosition.MoveRelative(0, 1);
    if EditPosition.Character = '/' then
    begin
      EditPosition.MoveRelative(0, 1);
      if EditPosition.Character = '/' then
        Comment := True
      else
        Comment := False
    end
    else
      Comment := False;

    if Comment then
    begin
      EditPosition.MoveRelative(0, -1);
      EditPosition.Delete(2);
    end
    else
    begin
      EditPosition.MoveBOL;
      EditPosition.InsertText('//');
    end;
    Inc(StartRow);
  end;
  until
    (StartRow > EndRow);
  // update caret position
  EditPosition.Restore;
  EditPosition.Move(StartRow, EditPosition.Column);
  // All done
  BindingResult := krHandled;
end;

procedure TDupLineBinding.CommentToggle1(const Context: IOTAKeyContext; KeyCode: TShortcut;
  var BindingResult: TKeyBindingResult);
begin
  //
end;

end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:38 Uhr.
Seite 2 von 4     12 34      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz