Autor Beitrag
Ace
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37

WinXP
Delphi 7 Pers. / Turbo Delphi.NET
BeitragVerfasst: Do 30.10.03 10:20 
Ich würde gerne ein IDE PlugIn erstellen welches mir einen neuen Menüpunkt im Delphimenü hinzufügt. Z.B. hinter Tools.
Ich hab es nur hinbekommen ein Untermenü innerhalb des Toolsmenü hinzuzufügen. Meine Frage also: Wie füge ich ein neues Menü zum Delphi Standardmenü hinzu?

Dann möchte ich noch gerne über mein PlugIn Text im Delphi Quellcode Editor an der aktuellen Textposition einfügen. Hab schon mit der Unit EditIntf rumgespielt aber es leider nicht hinbekommen. Hab dazu TIEditWriter und dann Insert probier. Wie genau muss ich das verwenden um Text an der Cursorposition einzufügen?
Ace Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37

WinXP
Delphi 7 Pers. / Turbo Delphi.NET
BeitragVerfasst: Do 30.10.03 10:58 
Das Problem mit dem Text einfügen habe ich gelöst. Hab einen Code gefunden der den markierten Text sortiert. Diesen habe ich angepasst und schon geht's. Der Code ist noch nicht bereinigt, also nicht wundern.
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
uses ... , ExptIntf, ToolIntf, EditIntf;

resourcestring
  sCloseViews = 'Alle Views ausser einem geschlossen';

procedure Insert(txt: string);
var
  Module: TIModuleInterface;
  Editor: TIEditorInterface;
  View: TIEditView;

  BlockStart: TCharPos;
  BlockAfter: TCharPos;
  StartPos, EndPos: LongInt;
  Reader: TIEditReader;
  Writer: TIEditWriter;
  TopPos, CursorPos: TEditPos;
  Text: string;
  Strings: TStringList;
begin

  // Get the module interface for the current file.
  with ToolServices do
    Module := GetModuleInterface(GetCurrentFile);
  // If no file is open, Module is nil.
  if Module = nil then
    Exit;

  try
    // Get the interface to the source editor.
    Editor := Module.GetEditorInterface;
    // If the file is not a source file, Editor is nil.
    if Editor = nil then
      Exit;

    try
      // The expert cannot tell which view is active, so force
      // the user to have only one view at a time.
      if Editor.GetViewCount > 1 then
        raise Exception.Create(sCloseViews);

      View := Editor.GetView(0);
    except
    end;

  except
  end;

  // Get the limits of the selected text.
  BlockStart := Editor.BlockStart;
  BlockAfter := Editor.BlockAfter;

  // Sort entire lines, so modify the positions accordingly.
  BlockStart.CharIndex := 0;   // start of line
  if BlockAfter.CharIndex > 0 then
  begin
    // Select the entire line by setting the After position
    // to the start of the next line.
    BlockAfter.CharIndex := 0;
    Inc(BlockAfter.Line);
  end;

  // Convert the character positions to buffer positions.
  StartPos := View.CharPosToPos(BlockStart);
  EndPos   := View.CharPosToPos(BlockAfter);

  // Get the selected text.
  Reader := Editor.CreateReader;
  try
    SetLength(Text, EndPos - StartPos - 1);
    Reader.GetText(StartPos, PChar(Text), Length(Text));
  finally
    Reader.Free;
  end;

  // Sort the text. Use a TStringList because it's easy.
{  Strings := TStringList.Create;
  try
    Strings.Text := Text;
    Strings.Sort;
    Text := Strings.Text;
  finally
    Strings.Free;
  end; }


  // Replace the selection with the sorted text.
  Writer := Editor.CreateUndoableWriter;
  try
    Writer.CopyTo(StartPos);
    Writer.DeleteTo(EndPos);
    Writer.Insert(PChar(txt));
  finally
    Writer.Free;
  end;

  // Set the cursor to the start of the sorted text.
  View.ConvertPos(False, CursorPos, BlockStart);
  View.CursorPos := CursorPos;

  // Make sure the top of the sorted text is visible.
  // Scroll the edit window if ncessary.
  if (BlockStart.Line < View.TopPos.Line) or
     (BlockAfter.Line >= View.TopPos.Line + View.ViewSize.CY) then
  begin
    View.ConvertPos(False, TopPos, BlockStart);
    View.TopPos := TopPos;
  end;

  // Select the newly inserted, sorted text.
  Editor.BlockVisible := False;
  Editor.BlockType    := btNonInclusive;
  Editor.BlockStart   := BlockStart;
  Editor.BlockAfter   := BlockAfter;
  Editor.BlockVisible := True;
end;

Bleibt nur noch die Sache mit dem Menü.

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 03.11.03 10:45 
Ace hat folgendes geschrieben:
Ich hab es nur hinbekommen ein Untermenü innerhalb des Toolsmenü hinzuzufügen.

Kannst du mal den Code posten? Dann kann man eventl. besser helfen.

Gruß
Tino
Ace Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37

WinXP
Delphi 7 Pers. / Turbo Delphi.NET
BeitragVerfasst: Di 04.11.03 17:20 
Ich habe es nun auch geschafft ein eigenes Menü in die Delphi MainBar einzufügen. Würde es gerne hier posten aber es ist ein komplettes Package und wäre hier als post wohl etwas unübersichtlich. Falls jemand den Code haben möchte schicke ich ihn aber gerne als E-Mail. Einfach bei mir melden.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 05.11.03 10:04 
Du brauchst doch nur den Code posten der für das einfügen des Menü-Items zuständig ist.

Gruß
Tino