~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/codetools/ide/addwithblockdlg.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
 ***************************************************************************
 
3
 *                                                                         *
 
4
 *   This source is free software; you can redistribute it and/or modify   *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This code is distributed in the hope that it will be useful, but      *
 
10
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 
12
 *   General Public License for more details.                              *
 
13
 *                                                                         *
 
14
 *   A copy of the GNU General Public License is available on the World    *
 
15
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 
16
 *   obtain it by writing to the Free Software Foundation,                 *
 
17
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 
18
 *                                                                         *
 
19
 ***************************************************************************
 
20
 
 
21
  Author: Mattias Gaertner
 
22
 
 
23
  Abstract:
 
24
    An IDE dialog to add a "With" block to the sourceeditor selection.
 
25
}
 
26
unit AddWithBlockDlg;
 
27
 
 
28
{$mode objfpc}{$H+}
 
29
 
 
30
interface
 
31
 
 
32
uses
 
33
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
 
34
  ButtonPanel, StdCtrls, Grids,
 
35
  // Codetools
 
36
  CodeCache, CodeToolManager, FileProcs, FindDeclarationTool,
 
37
  // IDEIntf
 
38
  IDEDialogs, LazIDEIntf, SrcEditorIntf, CodyStrConsts, CodyUtils;
 
39
 
 
40
type
 
41
 
 
42
  { TAddWithBlockDialog }
 
43
 
 
44
  TAddWithBlockDialog = class(TForm)
 
45
    ButtonPanel1: TButtonPanel;
 
46
    WithExprGroupBox: TGroupBox;
 
47
    WithExprStringGrid: TStringGrid;
 
48
    procedure ButtonPanel1OKButtonClick(Sender: TObject);
 
49
    procedure FormCreate(Sender: TObject);
 
50
  private
 
51
  public
 
52
    SrcEdit: TSourceEditorInterface;
 
53
    Code: TCodeBuffer;
 
54
    StartPos: TPoint;
 
55
    EndPos: TPoint;
 
56
    Candidates: TStringList;
 
57
    function Check(aSrcEdit: TSourceEditorInterface): boolean;
 
58
  end;
 
59
 
 
60
procedure ShowAddWithBlockDialog(Sender: TObject);
 
61
 
 
62
function CompareObjectThenText(List: TStringList; Index1, Index2: Integer): integer;
 
63
 
 
64
implementation
 
65
 
 
66
procedure ShowAddWithBlockDialog(Sender: TObject);
 
67
var
 
68
  AddWithBlockDialog: TAddWithBlockDialog;
 
69
  SrcEdit: TSourceEditorInterface;
 
70
  i: Integer;
 
71
  WithExpr: String;
 
72
begin
 
73
  // commit changes form source editor to codetools
 
74
  if not LazarusIDE.BeginCodeTools then exit;
 
75
  // check context at cursor
 
76
  SrcEdit:=SourceEditorManagerIntf.ActiveEditor;
 
77
  if (SrcEdit=nil) or (SrcEdit.Selection='') then begin
 
78
    IDEMessageDialog(crsCWError,
 
79
      crsPleaseSelectSomeCodeInTheSourceEditor, mtError, [mbCancel]);
 
80
    exit;
 
81
  end;
 
82
 
 
83
  AddWithBlockDialog:=TAddWithBlockDialog.Create(nil);
 
84
  try
 
85
    if not AddWithBlockDialog.Check(SrcEdit) then exit;
 
86
    if AddWithBlockDialog.ShowModal<>mrOk then exit;
 
87
 
 
88
    with AddWithBlockDialog do begin
 
89
      i:=WithExprStringGrid.Row;
 
90
      if (i<1) then begin
 
91
        debugln(['ShowAddWithBlockDialog nothing selected']);
 
92
        exit;
 
93
      end;
 
94
      WithExpr:=WithExprStringGrid.Cells[0,i];
 
95
      if not CodeToolBoss.AddWithBlock(Code,StartPos.X,StartPos.Y,
 
96
        EndPos.X,EndPos.Y,WithExpr,nil)
 
97
      then begin
 
98
        LazarusIDE.DoJumpToCodeToolBossError;
 
99
        exit;
 
100
      end;
 
101
    end;
 
102
 
 
103
  finally
 
104
    AddWithBlockDialog.Free;
 
105
  end;
 
106
end;
 
107
 
 
108
function CompareObjectThenText(List: TStringList; Index1, Index2: Integer
 
109
  ): integer;
 
110
var
 
111
  n1: PtrUInt;
 
112
  n2: PtrUInt;
 
113
begin
 
114
  n1:=PtrUInt(List.Objects[Index1]);
 
115
  n2:=PtrUInt(List.Objects[Index2]);
 
116
  if n1>n2 then exit(-1);
 
117
  if n2>n1 then exit(1);
 
118
  Result:=CompareText(List[Index1],List[Index2]);
 
119
end;
 
120
 
 
121
{ TAddWithBlockDialog }
 
122
 
 
123
procedure TAddWithBlockDialog.FormCreate(Sender: TObject);
 
124
begin
 
125
  Caption:=crsAddWithBlock;
 
126
  WithExprGroupBox.Caption:=crsSelectExpression;
 
127
  WithExprStringGrid.Columns[0].Title.Caption:=crsExpression;
 
128
  WithExprStringGrid.Columns[1].Title.Caption:=crsCount;
 
129
 
 
130
  ButtonPanel1.HelpButton.Caption:=crsHelp;
 
131
  ButtonPanel1.OKButton.Caption:=crsBTNOK;
 
132
  ButtonPanel1.CancelButton.Caption:=crsBTNCancel;
 
133
end;
 
134
 
 
135
procedure TAddWithBlockDialog.ButtonPanel1OKButtonClick(Sender: TObject);
 
136
var
 
137
  i: Integer;
 
138
begin
 
139
  i:=WithExprStringGrid.Row;
 
140
  if (i<1) then exit;
 
141
  ModalResult:=mrOk;
 
142
end;
 
143
 
 
144
function TAddWithBlockDialog.Check(aSrcEdit: TSourceEditorInterface): boolean;
 
145
var
 
146
  i: Integer;
 
147
begin
 
148
  Result:=false;
 
149
  SrcEdit:=aSrcEdit;
 
150
  Code:=TCodeBuffer(SrcEdit.CodeToolsBuffer);
 
151
  StartPos:=SrcEdit.BlockBegin;
 
152
  EndPos:=SrcEdit.BlockEnd;
 
153
  Candidates:=TStringList.Create;
 
154
  try
 
155
    //debugln(['TAddWithBlockDialog.Check ',dbgs(StartPos),' ',dbgs(EndPos)]);
 
156
    if not CodeToolBoss.AddWithBlock(Code,StartPos.X,StartPos.Y,EndPos.X,EndPos.Y,
 
157
      '',Candidates)
 
158
    then begin
 
159
      debugln(['ShowAddWithBlockDialog CodeToolBoss.AddWithBlock check failed']);
 
160
      LazarusIDE.DoJumpToCodeToolBossError;
 
161
      exit;
 
162
    end;
 
163
 
 
164
    if Candidates.Count=0 then begin
 
165
      IDEMessageDialog(crsCWError,
 
166
        crsPleaseSelectSomeCodeInTheSourceEditorForANewWithBl,mtError,[mbCancel]);
 
167
      exit;
 
168
    end;
 
169
 
 
170
    Candidates.CustomSort(@CompareObjectThenText);
 
171
 
 
172
    WithExprStringGrid.RowCount:=Candidates.Count+1;
 
173
    for i:=0 to Candidates.Count-1 do begin
 
174
      WithExprStringGrid.Cells[0,i+1]:=Candidates[i];
 
175
      WithExprStringGrid.Cells[1,i+1]:=IntToStr(PtrUInt(Candidates.Objects[i]));
 
176
    end;
 
177
 
 
178
    WithExprStringGrid.Row:=1;
 
179
    WithExprStringGrid.Col:=0;
 
180
  finally
 
181
    Candidates.Free;
 
182
  end;
 
183
 
 
184
  Result:=true;
 
185
end;
 
186
 
 
187
{$R *.lfm}
 
188
 
 
189
end.
 
190