View Issue Details

IDProjectCategoryView StatusLast Update
0015751LazarusIDEpublic2011-04-02 22:27
ReporterFlávio Etrusco (notifications not working)Assigned ToZeljan Rikalo 
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version0.9.28.3 (SVN)Product Build 
Target Version0.9.30Fixed in Version0.9.30 
Summary0015751: [patch] View Project Units/Form enhancement
DescriptionThis patch changes the search box to search an item that contains the text, not only one that starts with it.
Also it searches the next match on VK_RIGHT press (I played with the idea of using VK_DOWN if Text='', but thought people would find it confusing...)

Also I don't understand what's the deal with the "Multiple selection" checkbox. Why not remove it and always enable multisel?
I'd make the search a filter and keep the focus always on the editor too (Key:=0 in OnKeyPress)

I tried to keep the changes at a minimum, but I'm very tempted to make a deep refactor and can do it if so is desired ;-)
And last: the LFM is plenty of obsolete/default properties stored.
TagsNo tags attached.
Fixed in Revision23701,25658
LazTarget-
Widgetset
Attached Files
  • view_unit.diff (1,982 bytes)
    diff --git a/ide/viewunit_dlg.pp b/ide/viewunit_dlg.pp
    --- a/ide/viewunit_dlg.pp
    +++ b/ide/viewunit_dlg.pp
    @@ -71,6 +71,7 @@ type
       private
         FBlockListBoxChange: boolean;
         procedure FocusEdit;
    +    procedure SearchList(StartIndex: Integer = -1);
       public
         constructor Create(TheOwner: TComponent); override;
       end;
    @@ -115,15 +116,15 @@ begin
       end;
     end;
     
    -function SearchItem(Items: TStrings; Text: String): Integer;
    +function SearchItem(Items: TStrings; Text: String; StartIndex: Integer = -1): Integer;
     var
       i: integer;
     begin
       // Items can be unsorted => use simple traverse
       Result := -1;
       Text := LowerCase(Text);
    -  for i := 0 to Items.Count - 1 do
    -    if Pos(Text, LowerCase(Items[i])) = 1 then
    +  for i := StartIndex +1 to Items.Count - 1 do
    +    if Pos(Text, LowerCase(Items[i])) >= 1 then
         begin
           Result := i;
           break;
    @@ -192,6 +193,7 @@ begin
         VK_NEXT: MoveItemIndex(PageCount);
         VK_PRIOR: MoveItemIndex(-PageCount);
         VK_RETURN: OKButtonClick(nil);
    +    VK_RIGHT: SearchList(ListBox.ItemIndex);
       end;
     end;
     
    @@ -203,16 +205,7 @@ begin
       // so don't make any changes to the listbox
       if FBlockListBoxChange then exit;
       
    -  Index := SearchItem(ListBox.Items, Edit.Text);
    -  ListBox.ItemIndex := Index;
    -  ListBox.MakeCurrentVisible;
    -
    -  if ListBox.MultiSelect then
    -  begin
    -    ListBox.ClearSelection;
    -    if Index <> -1 then
    -      ListBox.Selected[Index] := True;
    -  end;
    +  SearchList();
     end;
     
     procedure TViewUnitDialog.EditEnter(Sender: TObject);
    @@ -254,5 +247,22 @@ begin
       Edit.SetFocus;
     end;
     
    +procedure TViewUnitDialog.SearchList(StartIndex: Integer);
    +var
    +  Index: Integer;
    +begin
    +  Index := SearchItem(ListBox.Items, Edit.Text, StartIndex);
    +  if Index >= 0 then
    +  begin
    +    ListBox.ItemIndex := Index;
    +    ListBox.MakeCurrentVisible;
    +    if ListBox.MultiSelect then
    +    begin
    +      ListBox.ClearSelection;
    +      ListBox.Selected[Index] := True;
    +    end;
    +  end;
    +end;
    +
     end.
     
    
    view_unit.diff (1,982 bytes)
  • unit_list_cleanup.diff (9,803 bytes)
    diff --git a/ide/viewunit_dlg.lfm b/ide/viewunit_dlg.lfm
    --- a/ide/viewunit_dlg.lfm
    +++ b/ide/viewunit_dlg.lfm
    @@ -1,164 +1,69 @@
     object ViewUnitDialog: TViewUnitDialog
       Left = 330
       Height = 301
       Top = 280
       Width = 378
    -  HelpContext = 0
       ActiveControl = Edit
    -  Align = alNone
    -  AllowDropFiles = False
       AutoScroll = True
    -  AutoSize = False
       BorderIcons = [biSystemMenu]
    -  BorderStyle = bsSizeable
       Caption = 'View Project Units'
    -  ChildSizing.LeftRightSpacing = 0
    -  ChildSizing.TopBottomSpacing = 0
    -  ChildSizing.HorizontalSpacing = 0
    -  ChildSizing.VerticalSpacing = 0
    -  ChildSizing.ControlsPerLine = 0
       ClientHeight = 301
       ClientWidth = 378
    -  DockSite = False
    -  DragKind = dkDrag
    -  DragMode = dmManual
    -  Enabled = True
    -  Font.Height = 0
    -  Font.Style = []
    -  FormStyle = fsNormal
    -  ParentBiDiMode = True
    -  ParentFont = False
       Position = poScreenCenter
    -  ShowInTaskBar = stDefault
    -  UseDockManager = False
    -  LCLVersion = '0.9.27'
    -  WindowState = wsNormal
    +  LCLVersion = '0.9.29'
       object Edit: TEdit
         Left = 6
         Height = 25
         Top = 6
         Width = 366
    -    HelpContext = 0
         Align = alTop
    -    Anchors = [akRight]
    +    Anchors = [akLeft]
         AutoSize = False
         AutoSelect = False
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
         BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    CharCase = ecNormal
    -    DragCursor = crDrag
    -    DragMode = dmManual
    -    EchoMode = emNormal
    -    Enabled = True
    -    MaxLength = -1
    -    ParentBidiMode = True
         OnChange = EditChange
         OnEnter = EditEnter
         OnKeyDown = EditKeyDown
    -    ParentFont = True
    -    ParentShowHint = True
    -    PasswordChar = #0
    -    ReadOnly = False
    -    TabStop = True
         TabOrder = 1
    -    Visible = True
       end
       object Listbox: TListBox
         AnchorSideTop.Side = asrBottom
         AnchorSideRight.Side = asrBottom
    -    AnchorSideBottom.Control = MultiSelectCheckBox
         Left = 6
    -    Height = 182
    +    Height = 212
         Top = 37
         Width = 366
    -    HelpContext = 0
         Align = alClient
         Anchors = [akBottom]
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
         BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    BorderStyle = bsSingle
         ClickOnSelChange = False
    -    Columns = 0
    -    DragCursor = crDrag
    -    DragKind = dkDrag
    -    DragMode = dmManual
    -    ExtendedSelect = True
    -    Enabled = True
    -    IntegralHeight = False
         ItemHeight = 0
    -    MultiSelect = False
         OnClick = ListboxClick
         OnDblClick = OKButtonClick
         OnKeyDown = ListboxKeyDown
    -    ParentBidiMode = True
    -    ParentShowHint = True
    -    ParentFont = True
    -    Sorted = False
    -    Style = lbStandard
    +    PopupMenu = popListBox
         TabOrder = 0
    -    TabStop = True
         TopIndex = -1
    -    Visible = True
    -  end
    -  object MultiSelectCheckBox: TCheckBox
    -    AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Side = asrBottom
    -    Left = 6
    -    Height = 22
    -    Top = 225
    -    Width = 366
    -    HelpContext = 0
    -    Align = alBottom
    -    AllowGrayed = False
    -    Anchors = [akLeft, akBottom]
    -    AutoSize = True
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
    -    BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    Caption = 'Multi Select'
    -    Checked = False
    -    DragCursor = crDrag
    -    DragKind = dkDrag
    -    DragMode = dmManual
    -    Enabled = True
    -    OnClick = MultiselectCheckBoxClick
    -    ParentColor = True
    -    ParentFont = True
    -    ParentShowHint = True
    -    ParentBidiMode = True
    -    State = cbUnchecked
    -    TabOrder = 2
    -    TabStop = True
    -    UseOnChange = False
    -    Visible = True
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 48
    -    Top = 253
    +    Height = 40
    +    Top = 255
         Width = 366
    -    HelpContext = 0
    -    Align = alBottom
    -    AutoSize = True
    -    ButtonOrder = boDefault
    -    TabOrder = 3
    -    DefaultButton = pbOK
    +    TabOrder = 2
         ShowButtons = [pbOK, pbCancel, pbHelp]
    -    ShowGlyphs = [pbOK, pbCancel, pbClose, pbHelp]
    -    Visible = True
    +  end
    +  object popListBox: TPopupMenu
    +    left = 144
    +    top = 112
    +    object mniMultiSelect: TMenuItem
    +      AutoCheck = True
    +      Caption = 'Multi Select'
    +      OnClick = MultiselectCheckBoxClick
    +    end
    +    object mniSort: TMenuItem
    +      Caption = 'Sort'
    +      OnClick = mniSortClick
    +    end
       end
     end
    diff --git a/ide/viewunit_dlg.pp b/ide/viewunit_dlg.pp
    --- a/ide/viewunit_dlg.pp
    +++ b/ide/viewunit_dlg.pp
    @@ -39,11 +39,11 @@ unit ViewUnit_Dlg;
     interface
     
     uses
       SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls,
       LazarusIdeStrConsts, LCLType, LCLIntf, LMessages, IDEWindowIntf, IDEContextHelpEdit,
    -  ExtCtrls, ButtonPanel;
    +  ExtCtrls, ButtonPanel, Menus;
     
     type
       TViewUnitsEntry = class
       public
         Name: string;
    @@ -56,15 +56,18 @@ type
     
       TViewUnitDialog = class(TForm)
         ButtonPanel: TButtonPanel;
         Edit: TEdit;
         ListBox: TListBox;
    -    MultiSelectCheckBox: TCheckBox;
    +    mniMultiSelect: TMenuItem;
    +    mniSort: TMenuItem;
    +    popListBox: TPopupMenu;
         procedure EditChange(Sender: TObject);
         procedure EditEnter(Sender: TObject);
         procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
         procedure HelpButtonClick(Sender: TObject);
    +    procedure mniSortClick(Sender: TObject);
         Procedure OKButtonClick(Sender :TObject);
         Procedure CancelButtonClick(Sender :TObject);
         procedure ListboxClick(Sender: TObject);
         procedure ListboxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
         procedure MultiselectCheckBoxClick(Sender :TObject);
    @@ -82,22 +85,25 @@ function ShowViewUnitsDlg(Entries: TStri
     
     implementation
     
     {$R *.lfm}
     
    +uses
    +  StrUtils;
    +
     function ShowViewUnitsDlg(Entries: TStringList; MultiSelect: boolean;
       const Caption: string): TModalResult;
     var
       ViewUnitDialog: TViewUnitDialog;
       i: integer;
     begin
       ViewUnitDialog:=TViewUnitDialog.Create(nil);
       try
         ViewUnitDialog.Caption:=Caption;
    -    ViewUnitDialog.MultiselectCheckBox.Enabled:=MultiSelect;
    -    ViewUnitDialog.MultiselectCheckBox.Checked:=MultiSelect;
    -    ViewUnitDialog.ListBox.Multiselect:=ViewUnitDialog.MultiselectCheckBox.Checked;
    +    ViewUnitDialog.mniMultiSelect.Enabled:=MultiSelect;
    +    ViewUnitDialog.mniMultiSelect.Checked:=MultiSelect;
    +    ViewUnitDialog.ListBox.Multiselect:=ViewUnitDialog.mniMultiSelect.Checked;
         with ViewUnitDialog.ListBox.Items do begin
           BeginUpdate;
           Clear;
           for i:=0 to Entries.Count-1 do
             Add(TViewUnitsEntry(Entries.Objects[i]).Name);
    @@ -120,13 +126,13 @@ function SearchItem(Items: TStrings; Tex
     var
       i: integer;
     begin
       // Items can be unsorted => use simple traverse
       Result := -1;
    -  Text := LowerCase(Text);
    +  Text := AnsiLowerCase(Text);
       for i := StartIndex +1 to Items.Count - 1 do
    -    if Pos(Text, LowerCase(Items[i])) >= 1 then
    +    if AnsiContainsText(Text, Items[i]) then
         begin
           Result := i;
           break;
         end;
     end;
    @@ -146,11 +152,11 @@ end;
     
     constructor TViewUnitDialog.Create(TheOwner: TComponent);
     begin
       inherited Create(TheOwner);
       IDEDialogLayoutList.ApplyLayout(Self,450,300);
    -  MultiSelectCheckBox.Caption := dlgMultiSelect;
    +  mniMultiSelect.Caption := dlgMultiSelect;
     
       ButtonPanel.OKButton.OnClick := @OKButtonClick;
       ButtonPanel.CancelButton.OnClick := @CancelButtonClick;
       ButtonPanel.HelpButton.OnClick := @HelpButtonClick;
     end;
    @@ -164,10 +170,48 @@ End;
     procedure TViewUnitDialog.HelpButtonClick(Sender: TObject);
     begin
       ShowContextHelpForIDE(Self);
     end;
     
    +procedure TViewUnitDialog.mniSortClick(Sender: TObject);
    +var
    +  TmpList: TStringList;
    +  i: Integer;
    +  SelName: String;
    +begin
    +  TmpList := TStringList.Create;
    +  try
    +    TmpList.Assign(ListBox.Items);
    +    if ListBox.MultiSelect then
    +    begin
    +      for i := 0 to ListBox.Count -1 do
    +        if ListBox.Selected[i] then
    +          TmpList.Objects[i] := TObject(-1);
    +    end;
    +    TmpList.Sort;
    +    if ListBox.ItemIndex >= 0 then
    +      SelName := ListBox.Items[ListBox.ItemIndex]
    +    else
    +      SelName := '';
    +    ListBox.Items := TmpList;
    +    if SelName <> '' then
    +    begin
    +      ListBox.ItemIndex := TmpList.IndexOf(SelName);
    +      ListBox.MakeCurrentVisible;
    +    end;
    +    if ListBox.MultiSelect then
    +    begin
    +      ListBox.ClearSelection;
    +      for i := 0 to TmpList.Count -1 do
    +        if TmpList.Objects[i] <> nil then
    +          ListBox.Selected[i] := True;
    +    end;
    +  finally
    +    TmpList.Free;
    +  end;
    +end;
    +
     procedure TViewUnitDialog.EditKeyDown(Sender: TObject; var Key: Word;
       Shift: TShiftState);
       
       procedure MoveItemIndex(d: integer); inline;
       var
    @@ -187,11 +231,16 @@ procedure TViewUnitDialog.EditKeyDown(Se
       end;
       
     begin
       case Key of
         VK_UP: MoveItemIndex(-1);
    -    VK_DOWN: MoveItemIndex(1);
    +    VK_DOWN:
    +      begin
    +        MoveItemIndex(1);
    +        // Avoid switching to next control in TabOrder in gtk2
    +        Key := 0;
    +      end;
         VK_NEXT: MoveItemIndex(PageCount);
         VK_PRIOR: MoveItemIndex(-PageCount);
         VK_RETURN: OKButtonClick(nil);
         VK_RIGHT: SearchList(ListBox.ItemIndex);
       end;
    @@ -234,11 +283,11 @@ begin
         OKButtonClick(nil);
     end;
     
     procedure TViewUnitDialog.MultiselectCheckBoxClick(Sender :TObject);
     begin
    -  ListBox.Multiselect := MultiselectCheckBox.Checked;
    +  ListBox.Multiselect := mniMultiSelect.Checked;
     end;
     
     procedure TViewUnitDialog.FocusEdit;
     begin
       Edit.SelectAll;
    
    unit_list_cleanup.diff (9,803 bytes)
  • unit_list_cleanup (9,060 bytes)
    # HG changeset patch
    # User etrusco <flavio.etrusco@gmail.com>
    
    [mq]: unit_list_cleanup
    
    diff --git a/ide/viewunit_dlg.lfm b/ide/viewunit_dlg.lfm
    --- a/ide/viewunit_dlg.lfm
    +++ b/ide/viewunit_dlg.lfm
    @@ -3,162 +3,67 @@ object ViewUnitDialog: TViewUnitDialog
       Height = 301
       Top = 280
       Width = 378
    -  HelpContext = 0
       ActiveControl = Edit
    -  Align = alNone
    -  AllowDropFiles = False
       AutoScroll = True
    -  AutoSize = False
       BorderIcons = [biSystemMenu]
    -  BorderStyle = bsSizeable
       Caption = 'View Project Units'
    -  ChildSizing.LeftRightSpacing = 0
    -  ChildSizing.TopBottomSpacing = 0
    -  ChildSizing.HorizontalSpacing = 0
    -  ChildSizing.VerticalSpacing = 0
    -  ChildSizing.ControlsPerLine = 0
       ClientHeight = 301
       ClientWidth = 378
    -  DockSite = False
    -  DragKind = dkDrag
    -  DragMode = dmManual
    -  Enabled = True
    -  Font.Height = 0
    -  Font.Style = []
    -  FormStyle = fsNormal
    -  ParentBiDiMode = True
    -  ParentFont = False
       Position = poScreenCenter
    -  ShowInTaskBar = stDefault
    -  UseDockManager = False
    -  LCLVersion = '0.9.27'
    -  WindowState = wsNormal
    +  LCLVersion = '0.9.29'
       object Edit: TEdit
         Left = 6
         Height = 25
         Top = 6
         Width = 366
    -    HelpContext = 0
         Align = alTop
    -    Anchors = [akRight]
    +    Anchors = [akLeft]
         AutoSize = False
         AutoSelect = False
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
         BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    CharCase = ecNormal
    -    DragCursor = crDrag
    -    DragMode = dmManual
    -    EchoMode = emNormal
    -    Enabled = True
    -    MaxLength = -1
    -    ParentBidiMode = True
         OnChange = EditChange
         OnEnter = EditEnter
         OnKeyDown = EditKeyDown
    -    ParentFont = True
    -    ParentShowHint = True
    -    PasswordChar = #0
    -    ReadOnly = False
    -    TabStop = True
         TabOrder = 1
    -    Visible = True
       end
       object Listbox: TListBox
         AnchorSideTop.Side = asrBottom
         AnchorSideRight.Side = asrBottom
    -    AnchorSideBottom.Control = MultiSelectCheckBox
         Left = 6
    -    Height = 182
    +    Height = 212
         Top = 37
         Width = 366
    -    HelpContext = 0
         Align = alClient
         Anchors = [akBottom]
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
         BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    BorderStyle = bsSingle
         ClickOnSelChange = False
    -    Columns = 0
    -    DragCursor = crDrag
    -    DragKind = dkDrag
    -    DragMode = dmManual
    -    ExtendedSelect = True
    -    Enabled = True
    -    IntegralHeight = False
         ItemHeight = 0
    -    MultiSelect = False
         OnClick = ListboxClick
         OnDblClick = OKButtonClick
         OnKeyDown = ListboxKeyDown
    -    ParentBidiMode = True
    -    ParentShowHint = True
    -    ParentFont = True
    -    Sorted = False
    -    Style = lbStandard
    +    PopupMenu = popListBox
         TabOrder = 0
    -    TabStop = True
         TopIndex = -1
    -    Visible = True
    -  end
    -  object MultiSelectCheckBox: TCheckBox
    -    AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Side = asrBottom
    -    Left = 6
    -    Height = 22
    -    Top = 225
    -    Width = 366
    -    HelpContext = 0
    -    Align = alBottom
    -    AllowGrayed = False
    -    Anchors = [akLeft, akBottom]
    -    AutoSize = True
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
    -    BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    Caption = 'Multi Select'
    -    Checked = False
    -    DragCursor = crDrag
    -    DragKind = dkDrag
    -    DragMode = dmManual
    -    Enabled = True
    -    OnClick = MultiselectCheckBoxClick
    -    ParentColor = True
    -    ParentFont = True
    -    ParentShowHint = True
    -    ParentBidiMode = True
    -    State = cbUnchecked
    -    TabOrder = 2
    -    TabStop = True
    -    UseOnChange = False
    -    Visible = True
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 48
    -    Top = 253
    +    Height = 40
    +    Top = 255
         Width = 366
    -    HelpContext = 0
    -    Align = alBottom
    -    AutoSize = True
    -    ButtonOrder = boDefault
    -    TabOrder = 3
    -    DefaultButton = pbOK
    +    TabOrder = 2
         ShowButtons = [pbOK, pbCancel, pbHelp]
    -    ShowGlyphs = [pbOK, pbCancel, pbClose, pbHelp]
    -    Visible = True
    +  end
    +  object popListBox: TPopupMenu
    +    left = 144
    +    top = 112
    +    object mniMultiSelect: TMenuItem
    +      AutoCheck = True
    +      Caption = 'Multi Select'
    +      OnClick = MultiselectCheckBoxClick
    +    end
    +    object mniSort: TMenuItem
    +      Caption = 'Sort'
    +      OnClick = mniSortClick
    +    end
       end
     end
    diff --git a/ide/viewunit_dlg.pp b/ide/viewunit_dlg.pp
    --- a/ide/viewunit_dlg.pp
    +++ b/ide/viewunit_dlg.pp
    @@ -41,7 +41,7 @@ interface
     uses
       SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls,
       LazarusIdeStrConsts, LCLType, LCLIntf, LMessages, IDEWindowIntf, IDEContextHelpEdit,
    -  ExtCtrls, ButtonPanel;
    +  ExtCtrls, ButtonPanel, Menus;
     
     type
       TViewUnitsEntry = class
    @@ -58,11 +58,14 @@ type
         ButtonPanel: TButtonPanel;
         Edit: TEdit;
         ListBox: TListBox;
    -    MultiSelectCheckBox: TCheckBox;
    +    mniMultiSelect: TMenuItem;
    +    mniSort: TMenuItem;
    +    popListBox: TPopupMenu;
         procedure EditChange(Sender: TObject);
         procedure EditEnter(Sender: TObject);
         procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
         procedure HelpButtonClick(Sender: TObject);
    +    procedure mniSortClick(Sender: TObject);
         Procedure OKButtonClick(Sender :TObject);
         Procedure CancelButtonClick(Sender :TObject);
         procedure ListboxClick(Sender: TObject);
    @@ -84,6 +87,9 @@ implementation
     
     {$R *.lfm}
     
    +uses
    +  StrUtils;
    +
     function ShowViewUnitsDlg(Entries: TStringList; MultiSelect: boolean;
       const Caption: string): TModalResult;
     var
    @@ -93,9 +99,9 @@ begin
       ViewUnitDialog:=TViewUnitDialog.Create(nil);
       try
         ViewUnitDialog.Caption:=Caption;
    -    ViewUnitDialog.MultiselectCheckBox.Enabled:=MultiSelect;
    -    ViewUnitDialog.MultiselectCheckBox.Checked:=MultiSelect;
    -    ViewUnitDialog.ListBox.Multiselect:=ViewUnitDialog.MultiselectCheckBox.Checked;
    +    ViewUnitDialog.mniMultiSelect.Enabled:=MultiSelect;
    +    ViewUnitDialog.mniMultiSelect.Checked:=MultiSelect;
    +    ViewUnitDialog.ListBox.Multiselect:=ViewUnitDialog.mniMultiSelect.Checked;
         with ViewUnitDialog.ListBox.Items do begin
           BeginUpdate;
           Clear;
    @@ -122,9 +128,9 @@ var
     begin
       // Items can be unsorted => use simple traverse
       Result := -1;
    -  Text := LowerCase(Text);
    +  Text := AnsiLowerCase(Text);
       for i := StartIndex +1 to Items.Count - 1 do
    -    if Pos(Text, LowerCase(Items[i])) >= 1 then
    +    if AnsiContainsText(Items[i], Text) then
         begin
           Result := i;
           break;
    @@ -148,7 +154,7 @@ constructor TViewUnitDialog.Create(TheOw
     begin
       inherited Create(TheOwner);
       IDEDialogLayoutList.ApplyLayout(Self,450,300);
    -  MultiSelectCheckBox.Caption := dlgMultiSelect;
    +  mniMultiSelect.Caption := dlgMultiSelect;
     
       ButtonPanel.OKButton.OnClick := @OKButtonClick;
       ButtonPanel.CancelButton.OnClick := @CancelButtonClick;
    @@ -166,6 +172,44 @@ begin
       ShowContextHelpForIDE(Self);
     end;
     
    +procedure TViewUnitDialog.mniSortClick(Sender: TObject);
    +var
    +  TmpList: TStringList;
    +  i: Integer;
    +  SelName: String;
    +begin
    +  TmpList := TStringList.Create;
    +  try
    +    TmpList.Assign(ListBox.Items);
    +    if ListBox.MultiSelect then
    +    begin
    +      for i := 0 to ListBox.Count -1 do
    +        if ListBox.Selected[i] then
    +          TmpList.Objects[i] := TObject(-1);
    +    end;
    +    TmpList.Sort;
    +    if ListBox.ItemIndex >= 0 then
    +      SelName := ListBox.Items[ListBox.ItemIndex]
    +    else
    +      SelName := '';
    +    ListBox.Items := TmpList;
    +    if SelName <> '' then
    +    begin
    +      ListBox.ItemIndex := TmpList.IndexOf(SelName);
    +      ListBox.MakeCurrentVisible;
    +    end;
    +    if ListBox.MultiSelect then
    +    begin
    +      ListBox.ClearSelection;
    +      for i := 0 to TmpList.Count -1 do
    +        if TmpList.Objects[i] <> nil then
    +          ListBox.Selected[i] := True;
    +    end;
    +  finally
    +    TmpList.Free;
    +  end;
    +end;
    +
     procedure TViewUnitDialog.EditKeyDown(Sender: TObject; var Key: Word;
       Shift: TShiftState);
       
    @@ -189,7 +233,12 @@ procedure TViewUnitDialog.EditKeyDown(Se
     begin
       case Key of
         VK_UP: MoveItemIndex(-1);
    -    VK_DOWN: MoveItemIndex(1);
    +    VK_DOWN:
    +      begin
    +        MoveItemIndex(1);
    +        // Avoid switching to next control in TabOrder in gtk2
    +        Key := 0;
    +      end;
         VK_NEXT: MoveItemIndex(PageCount);
         VK_PRIOR: MoveItemIndex(-PageCount);
         VK_RETURN: OKButtonClick(nil);
    @@ -236,7 +285,7 @@ end;
     
     procedure TViewUnitDialog.MultiselectCheckBoxClick(Sender :TObject);
     begin
    -  ListBox.Multiselect := MultiselectCheckBox.Checked;
    +  ListBox.Multiselect := mniMultiSelect.Checked;
     end;
     
     procedure TViewUnitDialog.FocusEdit;
    
    unit_list_cleanup (9,060 bytes)
  • unit_list_cleanup_r24209.patch (9,410 bytes)
    # HG changeset patch
    # User etrusco <flavio.etrusco@gmail.com>
    # Date 1267407780 10800
    # Branch trunk
    # Node ID abe6c88349221586c172df2cdc02b8f244e81fbe
    # Parent  79c97133273d44fbafe680fc5a1007c51eb87253
    [mq]: unit_list_cleanup
    
    diff --git a/ide/viewunit_dlg.lfm b/ide/viewunit_dlg.lfm
    --- a/ide/viewunit_dlg.lfm
    +++ b/ide/viewunit_dlg.lfm
    @@ -3,162 +3,67 @@ object ViewUnitDialog: TViewUnitDialog
       Height = 301
       Top = 280
       Width = 378
    -  HelpContext = 0
       ActiveControl = Edit
    -  Align = alNone
    -  AllowDropFiles = False
       AutoScroll = True
    -  AutoSize = False
       BorderIcons = [biSystemMenu]
    -  BorderStyle = bsSizeable
       Caption = 'View Project Units'
    -  ChildSizing.LeftRightSpacing = 0
    -  ChildSizing.TopBottomSpacing = 0
    -  ChildSizing.HorizontalSpacing = 0
    -  ChildSizing.VerticalSpacing = 0
    -  ChildSizing.ControlsPerLine = 0
       ClientHeight = 301
       ClientWidth = 378
    -  DockSite = False
    -  DragKind = dkDrag
    -  DragMode = dmManual
    -  Enabled = True
    -  Font.Height = 0
    -  Font.Style = []
    -  FormStyle = fsNormal
    -  ParentBiDiMode = True
    -  ParentFont = False
       Position = poScreenCenter
    -  ShowInTaskBar = stDefault
    -  UseDockManager = False
    -  LCLVersion = '0.9.27'
    -  WindowState = wsNormal
    +  LCLVersion = '0.9.29'
       object Edit: TEdit
         Left = 6
         Height = 25
         Top = 6
         Width = 366
    -    HelpContext = 0
         Align = alTop
    -    Anchors = [akRight]
    +    Anchors = [akLeft]
         AutoSize = False
         AutoSelect = False
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
         BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    CharCase = ecNormal
    -    DragCursor = crDrag
    -    DragMode = dmManual
    -    EchoMode = emNormal
    -    Enabled = True
    -    MaxLength = -1
    -    ParentBidiMode = True
         OnChange = EditChange
         OnEnter = EditEnter
         OnKeyDown = EditKeyDown
    -    ParentFont = True
    -    ParentShowHint = True
    -    PasswordChar = #0
    -    ReadOnly = False
    -    TabStop = True
         TabOrder = 1
    -    Visible = True
       end
       object Listbox: TListBox
         AnchorSideTop.Side = asrBottom
         AnchorSideRight.Side = asrBottom
    -    AnchorSideBottom.Control = MultiSelectCheckBox
         Left = 6
    -    Height = 182
    +    Height = 212
         Top = 37
         Width = 366
    -    HelpContext = 0
         Align = alClient
         Anchors = [akBottom]
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
         BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    BorderStyle = bsSingle
         ClickOnSelChange = False
    -    Columns = 0
    -    DragCursor = crDrag
    -    DragKind = dkDrag
    -    DragMode = dmManual
    -    ExtendedSelect = True
    -    Enabled = True
    -    IntegralHeight = False
         ItemHeight = 0
    -    MultiSelect = False
         OnClick = ListboxClick
         OnDblClick = OKButtonClick
         OnKeyDown = ListboxKeyDown
    -    ParentBidiMode = True
    -    ParentShowHint = True
    -    ParentFont = True
    -    Sorted = False
    -    Style = lbStandard
    +    PopupMenu = popListBox
         TabOrder = 0
    -    TabStop = True
         TopIndex = -1
    -    Visible = True
    -  end
    -  object MultiSelectCheckBox: TCheckBox
    -    AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Side = asrBottom
    -    Left = 6
    -    Height = 22
    -    Top = 225
    -    Width = 366
    -    HelpContext = 0
    -    Align = alBottom
    -    AllowGrayed = False
    -    Anchors = [akLeft, akBottom]
    -    AutoSize = True
    -    BorderSpacing.Left = 0
    -    BorderSpacing.Top = 0
    -    BorderSpacing.Right = 0
    -    BorderSpacing.Bottom = 0
    -    BorderSpacing.Around = 6
    -    BorderSpacing.CellAlignHorizontal = ccaFill
    -    BorderSpacing.CellAlignVertical = ccaFill
    -    Caption = 'Multi Select'
    -    Checked = False
    -    DragCursor = crDrag
    -    DragKind = dkDrag
    -    DragMode = dmManual
    -    Enabled = True
    -    OnClick = MultiselectCheckBoxClick
    -    ParentColor = True
    -    ParentFont = True
    -    ParentShowHint = True
    -    ParentBidiMode = True
    -    State = cbUnchecked
    -    TabOrder = 2
    -    TabStop = True
    -    UseOnChange = False
    -    Visible = True
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 48
    -    Top = 253
    +    Height = 40
    +    Top = 255
         Width = 366
    -    HelpContext = 0
    -    Align = alBottom
    -    AutoSize = True
    -    ButtonOrder = boDefault
    -    TabOrder = 3
    -    DefaultButton = pbOK
    +    TabOrder = 2
         ShowButtons = [pbOK, pbCancel, pbHelp]
    -    ShowGlyphs = [pbOK, pbCancel, pbClose, pbHelp]
    -    Visible = True
    +  end
    +  object popListBox: TPopupMenu
    +    left = 144
    +    top = 112
    +    object mniMultiSelect: TMenuItem
    +      AutoCheck = True
    +      Caption = 'Multi Select'
    +      OnClick = MultiselectCheckBoxClick
    +    end
    +    object mniSort: TMenuItem
    +      Caption = 'Sort'
    +      OnClick = mniSortClick
    +    end
       end
     end
    diff --git a/ide/viewunit_dlg.pp b/ide/viewunit_dlg.pp
    --- a/ide/viewunit_dlg.pp
    +++ b/ide/viewunit_dlg.pp
    @@ -41,7 +41,7 @@ interface
     uses
       SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls,
       LazarusIdeStrConsts, LCLType, LCLIntf, LMessages, IDEWindowIntf, IDEContextHelpEdit,
    -  ExtCtrls, ButtonPanel;
    +  ExtCtrls, ButtonPanel, Menus, StrUtils;
     
     type
       TViewUnitsEntry = class
    @@ -58,11 +58,14 @@ type
         ButtonPanel: TButtonPanel;
         Edit: TEdit;
         ListBox: TListBox;
    -    MultiSelectCheckBox: TCheckBox;
    +    mniMultiSelect: TMenuItem;
    +    mniSort: TMenuItem;
    +    popListBox: TPopupMenu;
         procedure EditChange(Sender: TObject);
         procedure EditEnter(Sender: TObject);
         procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
         procedure HelpButtonClick(Sender: TObject);
    +    procedure mniSortClick(Sender: TObject);
         Procedure OKButtonClick(Sender :TObject);
         Procedure CancelButtonClick(Sender :TObject);
         procedure ListboxClick(Sender: TObject);
    @@ -93,9 +96,9 @@ begin
       ViewUnitDialog:=TViewUnitDialog.Create(nil);
       try
         ViewUnitDialog.Caption:=Caption;
    -    ViewUnitDialog.MultiselectCheckBox.Enabled := AllowMultiSelect;
    -    ViewUnitDialog.MultiselectCheckBox.Checked := CheckMultiSelect;
    -    ViewUnitDialog.ListBox.MultiSelect:=ViewUnitDialog.MultiselectCheckBox.Checked;
    +    ViewUnitDialog.mniMultiselect.Enabled := AllowMultiSelect;
    +    ViewUnitDialog.mniMultiselect.Checked := CheckMultiSelect;
    +    ViewUnitDialog.ListBox.MultiSelect := ViewUnitDialog.mniMultiselect.Enabled;
         with ViewUnitDialog.ListBox.Items do begin
           BeginUpdate;
           Clear;
    @@ -110,7 +113,7 @@ begin
           for i:=0 to Entries.Count-1 do begin
             TViewUnitsEntry(Entries.Objects[i]).Selected:=ViewUnitDialog.ListBox.Selected[i];
           end;
    -      CheckMultiSelect := ViewUnitDialog.MultiselectCheckBox.Checked;
    +      CheckMultiSelect := ViewUnitDialog.mniMultiselect.Checked;
         end;
       finally
         ViewUnitDialog.Free;
    @@ -123,9 +126,9 @@ var
     begin
       // Items can be unsorted => use simple traverse
       Result := -1;
    -  Text := LowerCase(Text);
    +  Text := AnsiLowerCase(Text);
       for i := StartIndex +1 to Items.Count - 1 do
    -    if Pos(Text, LowerCase(Items[i])) >= 1 then
    +    if AnsiContainsText(Items[i], Text) then
         begin
           Result := i;
           break;
    @@ -149,7 +152,7 @@ constructor TViewUnitDialog.Create(TheOw
     begin
       inherited Create(TheOwner);
       IDEDialogLayoutList.ApplyLayout(Self,450,300);
    -  MultiSelectCheckBox.Caption := dlgMultiSelect;
    +  mniMultiSelect.Caption := dlgMultiSelect;
     
       ButtonPanel.OKButton.OnClick := @OKButtonClick;
       ButtonPanel.CancelButton.OnClick := @CancelButtonClick;
    @@ -167,6 +170,44 @@ begin
       ShowContextHelpForIDE(Self);
     end;
     
    +procedure TViewUnitDialog.mniSortClick(Sender: TObject);
    +var
    +  TmpList: TStringList;
    +  i: Integer;
    +  SelName: String;
    +begin
    +  TmpList := TStringList.Create;
    +  try
    +    TmpList.Assign(ListBox.Items);
    +    if ListBox.MultiSelect then
    +    begin
    +      for i := 0 to ListBox.Count -1 do
    +        if ListBox.Selected[i] then
    +          TmpList.Objects[i] := TObject(-1);
    +    end;
    +    TmpList.Sort;
    +    if ListBox.ItemIndex >= 0 then
    +      SelName := ListBox.Items[ListBox.ItemIndex]
    +    else
    +      SelName := '';
    +    ListBox.Items := TmpList;
    +    if SelName <> '' then
    +    begin
    +      ListBox.ItemIndex := TmpList.IndexOf(SelName);
    +      ListBox.MakeCurrentVisible;
    +    end;
    +    if ListBox.MultiSelect then
    +    begin
    +      ListBox.ClearSelection;
    +      for i := 0 to TmpList.Count -1 do
    +        if TmpList.Objects[i] <> nil then
    +          ListBox.Selected[i] := True;
    +    end;
    +  finally
    +    TmpList.Free;
    +  end;
    +end;
    +
     procedure TViewUnitDialog.EditKeyDown(Sender: TObject; var Key: Word;
       Shift: TShiftState);
       
    @@ -190,7 +231,12 @@ procedure TViewUnitDialog.EditKeyDown(Se
     begin
       case Key of
         VK_UP: MoveItemIndex(-1);
    -    VK_DOWN: MoveItemIndex(1);
    +    VK_DOWN:
    +      begin
    +        MoveItemIndex(1);
    +        // Avoid switching to next control in TabOrder in gtk2
    +        Key := 0;
    +      end;
         VK_NEXT: MoveItemIndex(PageCount);
         VK_PRIOR: MoveItemIndex(-PageCount);
         VK_RETURN: OKButtonClick(nil);
    @@ -237,7 +283,7 @@ end;
     
     procedure TViewUnitDialog.MultiselectCheckBoxClick(Sender :TObject);
     begin
    -  ListBox.Multiselect := MultiselectCheckBox.Checked;
    +  ListBox.Multiselect := mniMultiSelect.Checked;
     end;
     
     procedure TViewUnitDialog.FocusEdit;
    

Activities

2010-02-13 06:34

 

view_unit.diff (1,982 bytes)
diff --git a/ide/viewunit_dlg.pp b/ide/viewunit_dlg.pp
--- a/ide/viewunit_dlg.pp
+++ b/ide/viewunit_dlg.pp
@@ -71,6 +71,7 @@ type
   private
     FBlockListBoxChange: boolean;
     procedure FocusEdit;
+    procedure SearchList(StartIndex: Integer = -1);
   public
     constructor Create(TheOwner: TComponent); override;
   end;
@@ -115,15 +116,15 @@ begin
   end;
 end;
 
-function SearchItem(Items: TStrings; Text: String): Integer;
+function SearchItem(Items: TStrings; Text: String; StartIndex: Integer = -1): Integer;
 var
   i: integer;
 begin
   // Items can be unsorted => use simple traverse
   Result := -1;
   Text := LowerCase(Text);
-  for i := 0 to Items.Count - 1 do
-    if Pos(Text, LowerCase(Items[i])) = 1 then
+  for i := StartIndex +1 to Items.Count - 1 do
+    if Pos(Text, LowerCase(Items[i])) >= 1 then
     begin
       Result := i;
       break;
@@ -192,6 +193,7 @@ begin
     VK_NEXT: MoveItemIndex(PageCount);
     VK_PRIOR: MoveItemIndex(-PageCount);
     VK_RETURN: OKButtonClick(nil);
+    VK_RIGHT: SearchList(ListBox.ItemIndex);
   end;
 end;
 
@@ -203,16 +205,7 @@ begin
   // so don't make any changes to the listbox
   if FBlockListBoxChange then exit;
   
-  Index := SearchItem(ListBox.Items, Edit.Text);
-  ListBox.ItemIndex := Index;
-  ListBox.MakeCurrentVisible;
-
-  if ListBox.MultiSelect then
-  begin
-    ListBox.ClearSelection;
-    if Index <> -1 then
-      ListBox.Selected[Index] := True;
-  end;
+  SearchList();
 end;
 
 procedure TViewUnitDialog.EditEnter(Sender: TObject);
@@ -254,5 +247,22 @@ begin
   Edit.SetFocus;
 end;
 
+procedure TViewUnitDialog.SearchList(StartIndex: Integer);
+var
+  Index: Integer;
+begin
+  Index := SearchItem(ListBox.Items, Edit.Text, StartIndex);
+  if Index >= 0 then
+  begin
+    ListBox.ItemIndex := Index;
+    ListBox.MakeCurrentVisible;
+    if ListBox.MultiSelect then
+    begin
+      ListBox.ClearSelection;
+      ListBox.Selected[Index] := True;
+    end;
+  end;
+end;
+
 end.
 
view_unit.diff (1,982 bytes)
Forgot to mention that patch is based on latest svn (r23695). BTW I changed the search Edit behavior because all widgetsets AFAIK already have builtin navigatation.

Mattias Gaertner

2010-02-13 11:56

manager   ~0034435

About multi select: AFAIK it is there for historic reasons. You can remove it.

About LFM default properties:
Quite the opposite. If they are written in the LFM, then TWriter thinks they are *not* default. So either the property definition in the LCL does not define the right "default" or someone changed the property (on purpose or by accident).
Feel free to check and improve it.

Zeljan Rikalo

2010-02-13 12:31

developer   ~0034436

Please don't remove multi select checkbox.Rather create option in env options for default state - I'm using this dlg without multi select many times, but probably others too (if I'm alone in this case - then remove it).
But what's the problem with multiselect? What usability issue does it create (and why am I not getting notifications for this bugs - and most others? :-/)
Mattias, I meant that when you save the form 70% of it is removed (what I think are default properties).
Mattias, what about my other comments (keep the focus on the search edit)? Any opinions?
Just now I'm realizing that the behavior I want to avoid occurs only in gtk and won't occur in Windows. Mattias, please set "Key:=0" on VK_UP and VK_DOWN in OnKeyPress, otherwise gtk will move the focus to the control bellow.
BTW, thanks for applying the patch.

2010-02-14 06:44

 

unit_list_cleanup.diff (9,803 bytes)
diff --git a/ide/viewunit_dlg.lfm b/ide/viewunit_dlg.lfm
--- a/ide/viewunit_dlg.lfm
+++ b/ide/viewunit_dlg.lfm
@@ -1,164 +1,69 @@
 object ViewUnitDialog: TViewUnitDialog
   Left = 330
   Height = 301
   Top = 280
   Width = 378
-  HelpContext = 0
   ActiveControl = Edit
-  Align = alNone
-  AllowDropFiles = False
   AutoScroll = True
-  AutoSize = False
   BorderIcons = [biSystemMenu]
-  BorderStyle = bsSizeable
   Caption = 'View Project Units'
-  ChildSizing.LeftRightSpacing = 0
-  ChildSizing.TopBottomSpacing = 0
-  ChildSizing.HorizontalSpacing = 0
-  ChildSizing.VerticalSpacing = 0
-  ChildSizing.ControlsPerLine = 0
   ClientHeight = 301
   ClientWidth = 378
-  DockSite = False
-  DragKind = dkDrag
-  DragMode = dmManual
-  Enabled = True
-  Font.Height = 0
-  Font.Style = []
-  FormStyle = fsNormal
-  ParentBiDiMode = True
-  ParentFont = False
   Position = poScreenCenter
-  ShowInTaskBar = stDefault
-  UseDockManager = False
-  LCLVersion = '0.9.27'
-  WindowState = wsNormal
+  LCLVersion = '0.9.29'
   object Edit: TEdit
     Left = 6
     Height = 25
     Top = 6
     Width = 366
-    HelpContext = 0
     Align = alTop
-    Anchors = [akRight]
+    Anchors = [akLeft]
     AutoSize = False
     AutoSelect = False
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
     BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    CharCase = ecNormal
-    DragCursor = crDrag
-    DragMode = dmManual
-    EchoMode = emNormal
-    Enabled = True
-    MaxLength = -1
-    ParentBidiMode = True
     OnChange = EditChange
     OnEnter = EditEnter
     OnKeyDown = EditKeyDown
-    ParentFont = True
-    ParentShowHint = True
-    PasswordChar = #0
-    ReadOnly = False
-    TabStop = True
     TabOrder = 1
-    Visible = True
   end
   object Listbox: TListBox
     AnchorSideTop.Side = asrBottom
     AnchorSideRight.Side = asrBottom
-    AnchorSideBottom.Control = MultiSelectCheckBox
     Left = 6
-    Height = 182
+    Height = 212
     Top = 37
     Width = 366
-    HelpContext = 0
     Align = alClient
     Anchors = [akBottom]
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
     BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    BorderStyle = bsSingle
     ClickOnSelChange = False
-    Columns = 0
-    DragCursor = crDrag
-    DragKind = dkDrag
-    DragMode = dmManual
-    ExtendedSelect = True
-    Enabled = True
-    IntegralHeight = False
     ItemHeight = 0
-    MultiSelect = False
     OnClick = ListboxClick
     OnDblClick = OKButtonClick
     OnKeyDown = ListboxKeyDown
-    ParentBidiMode = True
-    ParentShowHint = True
-    ParentFont = True
-    Sorted = False
-    Style = lbStandard
+    PopupMenu = popListBox
     TabOrder = 0
-    TabStop = True
     TopIndex = -1
-    Visible = True
-  end
-  object MultiSelectCheckBox: TCheckBox
-    AnchorSideLeft.Control = Owner
-    AnchorSideTop.Side = asrBottom
-    Left = 6
-    Height = 22
-    Top = 225
-    Width = 366
-    HelpContext = 0
-    Align = alBottom
-    AllowGrayed = False
-    Anchors = [akLeft, akBottom]
-    AutoSize = True
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
-    BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    Caption = 'Multi Select'
-    Checked = False
-    DragCursor = crDrag
-    DragKind = dkDrag
-    DragMode = dmManual
-    Enabled = True
-    OnClick = MultiselectCheckBoxClick
-    ParentColor = True
-    ParentFont = True
-    ParentShowHint = True
-    ParentBidiMode = True
-    State = cbUnchecked
-    TabOrder = 2
-    TabStop = True
-    UseOnChange = False
-    Visible = True
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 48
-    Top = 253
+    Height = 40
+    Top = 255
     Width = 366
-    HelpContext = 0
-    Align = alBottom
-    AutoSize = True
-    ButtonOrder = boDefault
-    TabOrder = 3
-    DefaultButton = pbOK
+    TabOrder = 2
     ShowButtons = [pbOK, pbCancel, pbHelp]
-    ShowGlyphs = [pbOK, pbCancel, pbClose, pbHelp]
-    Visible = True
+  end
+  object popListBox: TPopupMenu
+    left = 144
+    top = 112
+    object mniMultiSelect: TMenuItem
+      AutoCheck = True
+      Caption = 'Multi Select'
+      OnClick = MultiselectCheckBoxClick
+    end
+    object mniSort: TMenuItem
+      Caption = 'Sort'
+      OnClick = mniSortClick
+    end
   end
 end
diff --git a/ide/viewunit_dlg.pp b/ide/viewunit_dlg.pp
--- a/ide/viewunit_dlg.pp
+++ b/ide/viewunit_dlg.pp
@@ -39,11 +39,11 @@ unit ViewUnit_Dlg;
 interface
 
 uses
   SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls,
   LazarusIdeStrConsts, LCLType, LCLIntf, LMessages, IDEWindowIntf, IDEContextHelpEdit,
-  ExtCtrls, ButtonPanel;
+  ExtCtrls, ButtonPanel, Menus;
 
 type
   TViewUnitsEntry = class
   public
     Name: string;
@@ -56,15 +56,18 @@ type
 
   TViewUnitDialog = class(TForm)
     ButtonPanel: TButtonPanel;
     Edit: TEdit;
     ListBox: TListBox;
-    MultiSelectCheckBox: TCheckBox;
+    mniMultiSelect: TMenuItem;
+    mniSort: TMenuItem;
+    popListBox: TPopupMenu;
     procedure EditChange(Sender: TObject);
     procedure EditEnter(Sender: TObject);
     procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     procedure HelpButtonClick(Sender: TObject);
+    procedure mniSortClick(Sender: TObject);
     Procedure OKButtonClick(Sender :TObject);
     Procedure CancelButtonClick(Sender :TObject);
     procedure ListboxClick(Sender: TObject);
     procedure ListboxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     procedure MultiselectCheckBoxClick(Sender :TObject);
@@ -82,22 +85,25 @@ function ShowViewUnitsDlg(Entries: TStri
 
 implementation
 
 {$R *.lfm}
 
+uses
+  StrUtils;
+
 function ShowViewUnitsDlg(Entries: TStringList; MultiSelect: boolean;
   const Caption: string): TModalResult;
 var
   ViewUnitDialog: TViewUnitDialog;
   i: integer;
 begin
   ViewUnitDialog:=TViewUnitDialog.Create(nil);
   try
     ViewUnitDialog.Caption:=Caption;
-    ViewUnitDialog.MultiselectCheckBox.Enabled:=MultiSelect;
-    ViewUnitDialog.MultiselectCheckBox.Checked:=MultiSelect;
-    ViewUnitDialog.ListBox.Multiselect:=ViewUnitDialog.MultiselectCheckBox.Checked;
+    ViewUnitDialog.mniMultiSelect.Enabled:=MultiSelect;
+    ViewUnitDialog.mniMultiSelect.Checked:=MultiSelect;
+    ViewUnitDialog.ListBox.Multiselect:=ViewUnitDialog.mniMultiSelect.Checked;
     with ViewUnitDialog.ListBox.Items do begin
       BeginUpdate;
       Clear;
       for i:=0 to Entries.Count-1 do
         Add(TViewUnitsEntry(Entries.Objects[i]).Name);
@@ -120,13 +126,13 @@ function SearchItem(Items: TStrings; Tex
 var
   i: integer;
 begin
   // Items can be unsorted => use simple traverse
   Result := -1;
-  Text := LowerCase(Text);
+  Text := AnsiLowerCase(Text);
   for i := StartIndex +1 to Items.Count - 1 do
-    if Pos(Text, LowerCase(Items[i])) >= 1 then
+    if AnsiContainsText(Text, Items[i]) then
     begin
       Result := i;
       break;
     end;
 end;
@@ -146,11 +152,11 @@ end;
 
 constructor TViewUnitDialog.Create(TheOwner: TComponent);
 begin
   inherited Create(TheOwner);
   IDEDialogLayoutList.ApplyLayout(Self,450,300);
-  MultiSelectCheckBox.Caption := dlgMultiSelect;
+  mniMultiSelect.Caption := dlgMultiSelect;
 
   ButtonPanel.OKButton.OnClick := @OKButtonClick;
   ButtonPanel.CancelButton.OnClick := @CancelButtonClick;
   ButtonPanel.HelpButton.OnClick := @HelpButtonClick;
 end;
@@ -164,10 +170,48 @@ End;
 procedure TViewUnitDialog.HelpButtonClick(Sender: TObject);
 begin
   ShowContextHelpForIDE(Self);
 end;
 
+procedure TViewUnitDialog.mniSortClick(Sender: TObject);
+var
+  TmpList: TStringList;
+  i: Integer;
+  SelName: String;
+begin
+  TmpList := TStringList.Create;
+  try
+    TmpList.Assign(ListBox.Items);
+    if ListBox.MultiSelect then
+    begin
+      for i := 0 to ListBox.Count -1 do
+        if ListBox.Selected[i] then
+          TmpList.Objects[i] := TObject(-1);
+    end;
+    TmpList.Sort;
+    if ListBox.ItemIndex >= 0 then
+      SelName := ListBox.Items[ListBox.ItemIndex]
+    else
+      SelName := '';
+    ListBox.Items := TmpList;
+    if SelName <> '' then
+    begin
+      ListBox.ItemIndex := TmpList.IndexOf(SelName);
+      ListBox.MakeCurrentVisible;
+    end;
+    if ListBox.MultiSelect then
+    begin
+      ListBox.ClearSelection;
+      for i := 0 to TmpList.Count -1 do
+        if TmpList.Objects[i] <> nil then
+          ListBox.Selected[i] := True;
+    end;
+  finally
+    TmpList.Free;
+  end;
+end;
+
 procedure TViewUnitDialog.EditKeyDown(Sender: TObject; var Key: Word;
   Shift: TShiftState);
   
   procedure MoveItemIndex(d: integer); inline;
   var
@@ -187,11 +231,16 @@ procedure TViewUnitDialog.EditKeyDown(Se
   end;
   
 begin
   case Key of
     VK_UP: MoveItemIndex(-1);
-    VK_DOWN: MoveItemIndex(1);
+    VK_DOWN:
+      begin
+        MoveItemIndex(1);
+        // Avoid switching to next control in TabOrder in gtk2
+        Key := 0;
+      end;
     VK_NEXT: MoveItemIndex(PageCount);
     VK_PRIOR: MoveItemIndex(-PageCount);
     VK_RETURN: OKButtonClick(nil);
     VK_RIGHT: SearchList(ListBox.ItemIndex);
   end;
@@ -234,11 +283,11 @@ begin
     OKButtonClick(nil);
 end;
 
 procedure TViewUnitDialog.MultiselectCheckBoxClick(Sender :TObject);
 begin
-  ListBox.Multiselect := MultiselectCheckBox.Checked;
+  ListBox.Multiselect := mniMultiSelect.Checked;
 end;
 
 procedure TViewUnitDialog.FocusEdit;
 begin
   Edit.SelectAll;
unit_list_cleanup.diff (9,803 bytes)

Flávio Etrusco (notifications not working)

2010-02-14 06:45

developer   ~0034461

Last edited: 2010-02-15 21:15

For the sake of it, here's a patch to clean the LFM, convert the MultiSelect check into a popup menu, add sort command, and avoid gtk2 control navigation with VK_DOWN.

Edit: my patch was bogus, inverted AnsiContainsText parameters.

2010-02-15 21:12

 

unit_list_cleanup (9,060 bytes)
# HG changeset patch
# User etrusco <flavio.etrusco@gmail.com>

[mq]: unit_list_cleanup

diff --git a/ide/viewunit_dlg.lfm b/ide/viewunit_dlg.lfm
--- a/ide/viewunit_dlg.lfm
+++ b/ide/viewunit_dlg.lfm
@@ -3,162 +3,67 @@ object ViewUnitDialog: TViewUnitDialog
   Height = 301
   Top = 280
   Width = 378
-  HelpContext = 0
   ActiveControl = Edit
-  Align = alNone
-  AllowDropFiles = False
   AutoScroll = True
-  AutoSize = False
   BorderIcons = [biSystemMenu]
-  BorderStyle = bsSizeable
   Caption = 'View Project Units'
-  ChildSizing.LeftRightSpacing = 0
-  ChildSizing.TopBottomSpacing = 0
-  ChildSizing.HorizontalSpacing = 0
-  ChildSizing.VerticalSpacing = 0
-  ChildSizing.ControlsPerLine = 0
   ClientHeight = 301
   ClientWidth = 378
-  DockSite = False
-  DragKind = dkDrag
-  DragMode = dmManual
-  Enabled = True
-  Font.Height = 0
-  Font.Style = []
-  FormStyle = fsNormal
-  ParentBiDiMode = True
-  ParentFont = False
   Position = poScreenCenter
-  ShowInTaskBar = stDefault
-  UseDockManager = False
-  LCLVersion = '0.9.27'
-  WindowState = wsNormal
+  LCLVersion = '0.9.29'
   object Edit: TEdit
     Left = 6
     Height = 25
     Top = 6
     Width = 366
-    HelpContext = 0
     Align = alTop
-    Anchors = [akRight]
+    Anchors = [akLeft]
     AutoSize = False
     AutoSelect = False
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
     BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    CharCase = ecNormal
-    DragCursor = crDrag
-    DragMode = dmManual
-    EchoMode = emNormal
-    Enabled = True
-    MaxLength = -1
-    ParentBidiMode = True
     OnChange = EditChange
     OnEnter = EditEnter
     OnKeyDown = EditKeyDown
-    ParentFont = True
-    ParentShowHint = True
-    PasswordChar = #0
-    ReadOnly = False
-    TabStop = True
     TabOrder = 1
-    Visible = True
   end
   object Listbox: TListBox
     AnchorSideTop.Side = asrBottom
     AnchorSideRight.Side = asrBottom
-    AnchorSideBottom.Control = MultiSelectCheckBox
     Left = 6
-    Height = 182
+    Height = 212
     Top = 37
     Width = 366
-    HelpContext = 0
     Align = alClient
     Anchors = [akBottom]
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
     BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    BorderStyle = bsSingle
     ClickOnSelChange = False
-    Columns = 0
-    DragCursor = crDrag
-    DragKind = dkDrag
-    DragMode = dmManual
-    ExtendedSelect = True
-    Enabled = True
-    IntegralHeight = False
     ItemHeight = 0
-    MultiSelect = False
     OnClick = ListboxClick
     OnDblClick = OKButtonClick
     OnKeyDown = ListboxKeyDown
-    ParentBidiMode = True
-    ParentShowHint = True
-    ParentFont = True
-    Sorted = False
-    Style = lbStandard
+    PopupMenu = popListBox
     TabOrder = 0
-    TabStop = True
     TopIndex = -1
-    Visible = True
-  end
-  object MultiSelectCheckBox: TCheckBox
-    AnchorSideLeft.Control = Owner
-    AnchorSideTop.Side = asrBottom
-    Left = 6
-    Height = 22
-    Top = 225
-    Width = 366
-    HelpContext = 0
-    Align = alBottom
-    AllowGrayed = False
-    Anchors = [akLeft, akBottom]
-    AutoSize = True
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
-    BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    Caption = 'Multi Select'
-    Checked = False
-    DragCursor = crDrag
-    DragKind = dkDrag
-    DragMode = dmManual
-    Enabled = True
-    OnClick = MultiselectCheckBoxClick
-    ParentColor = True
-    ParentFont = True
-    ParentShowHint = True
-    ParentBidiMode = True
-    State = cbUnchecked
-    TabOrder = 2
-    TabStop = True
-    UseOnChange = False
-    Visible = True
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 48
-    Top = 253
+    Height = 40
+    Top = 255
     Width = 366
-    HelpContext = 0
-    Align = alBottom
-    AutoSize = True
-    ButtonOrder = boDefault
-    TabOrder = 3
-    DefaultButton = pbOK
+    TabOrder = 2
     ShowButtons = [pbOK, pbCancel, pbHelp]
-    ShowGlyphs = [pbOK, pbCancel, pbClose, pbHelp]
-    Visible = True
+  end
+  object popListBox: TPopupMenu
+    left = 144
+    top = 112
+    object mniMultiSelect: TMenuItem
+      AutoCheck = True
+      Caption = 'Multi Select'
+      OnClick = MultiselectCheckBoxClick
+    end
+    object mniSort: TMenuItem
+      Caption = 'Sort'
+      OnClick = mniSortClick
+    end
   end
 end
diff --git a/ide/viewunit_dlg.pp b/ide/viewunit_dlg.pp
--- a/ide/viewunit_dlg.pp
+++ b/ide/viewunit_dlg.pp
@@ -41,7 +41,7 @@ interface
 uses
   SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls,
   LazarusIdeStrConsts, LCLType, LCLIntf, LMessages, IDEWindowIntf, IDEContextHelpEdit,
-  ExtCtrls, ButtonPanel;
+  ExtCtrls, ButtonPanel, Menus;
 
 type
   TViewUnitsEntry = class
@@ -58,11 +58,14 @@ type
     ButtonPanel: TButtonPanel;
     Edit: TEdit;
     ListBox: TListBox;
-    MultiSelectCheckBox: TCheckBox;
+    mniMultiSelect: TMenuItem;
+    mniSort: TMenuItem;
+    popListBox: TPopupMenu;
     procedure EditChange(Sender: TObject);
     procedure EditEnter(Sender: TObject);
     procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     procedure HelpButtonClick(Sender: TObject);
+    procedure mniSortClick(Sender: TObject);
     Procedure OKButtonClick(Sender :TObject);
     Procedure CancelButtonClick(Sender :TObject);
     procedure ListboxClick(Sender: TObject);
@@ -84,6 +87,9 @@ implementation
 
 {$R *.lfm}
 
+uses
+  StrUtils;
+
 function ShowViewUnitsDlg(Entries: TStringList; MultiSelect: boolean;
   const Caption: string): TModalResult;
 var
@@ -93,9 +99,9 @@ begin
   ViewUnitDialog:=TViewUnitDialog.Create(nil);
   try
     ViewUnitDialog.Caption:=Caption;
-    ViewUnitDialog.MultiselectCheckBox.Enabled:=MultiSelect;
-    ViewUnitDialog.MultiselectCheckBox.Checked:=MultiSelect;
-    ViewUnitDialog.ListBox.Multiselect:=ViewUnitDialog.MultiselectCheckBox.Checked;
+    ViewUnitDialog.mniMultiSelect.Enabled:=MultiSelect;
+    ViewUnitDialog.mniMultiSelect.Checked:=MultiSelect;
+    ViewUnitDialog.ListBox.Multiselect:=ViewUnitDialog.mniMultiSelect.Checked;
     with ViewUnitDialog.ListBox.Items do begin
       BeginUpdate;
       Clear;
@@ -122,9 +128,9 @@ var
 begin
   // Items can be unsorted => use simple traverse
   Result := -1;
-  Text := LowerCase(Text);
+  Text := AnsiLowerCase(Text);
   for i := StartIndex +1 to Items.Count - 1 do
-    if Pos(Text, LowerCase(Items[i])) >= 1 then
+    if AnsiContainsText(Items[i], Text) then
     begin
       Result := i;
       break;
@@ -148,7 +154,7 @@ constructor TViewUnitDialog.Create(TheOw
 begin
   inherited Create(TheOwner);
   IDEDialogLayoutList.ApplyLayout(Self,450,300);
-  MultiSelectCheckBox.Caption := dlgMultiSelect;
+  mniMultiSelect.Caption := dlgMultiSelect;
 
   ButtonPanel.OKButton.OnClick := @OKButtonClick;
   ButtonPanel.CancelButton.OnClick := @CancelButtonClick;
@@ -166,6 +172,44 @@ begin
   ShowContextHelpForIDE(Self);
 end;
 
+procedure TViewUnitDialog.mniSortClick(Sender: TObject);
+var
+  TmpList: TStringList;
+  i: Integer;
+  SelName: String;
+begin
+  TmpList := TStringList.Create;
+  try
+    TmpList.Assign(ListBox.Items);
+    if ListBox.MultiSelect then
+    begin
+      for i := 0 to ListBox.Count -1 do
+        if ListBox.Selected[i] then
+          TmpList.Objects[i] := TObject(-1);
+    end;
+    TmpList.Sort;
+    if ListBox.ItemIndex >= 0 then
+      SelName := ListBox.Items[ListBox.ItemIndex]
+    else
+      SelName := '';
+    ListBox.Items := TmpList;
+    if SelName <> '' then
+    begin
+      ListBox.ItemIndex := TmpList.IndexOf(SelName);
+      ListBox.MakeCurrentVisible;
+    end;
+    if ListBox.MultiSelect then
+    begin
+      ListBox.ClearSelection;
+      for i := 0 to TmpList.Count -1 do
+        if TmpList.Objects[i] <> nil then
+          ListBox.Selected[i] := True;
+    end;
+  finally
+    TmpList.Free;
+  end;
+end;
+
 procedure TViewUnitDialog.EditKeyDown(Sender: TObject; var Key: Word;
   Shift: TShiftState);
   
@@ -189,7 +233,12 @@ procedure TViewUnitDialog.EditKeyDown(Se
 begin
   case Key of
     VK_UP: MoveItemIndex(-1);
-    VK_DOWN: MoveItemIndex(1);
+    VK_DOWN:
+      begin
+        MoveItemIndex(1);
+        // Avoid switching to next control in TabOrder in gtk2
+        Key := 0;
+      end;
     VK_NEXT: MoveItemIndex(PageCount);
     VK_PRIOR: MoveItemIndex(-PageCount);
     VK_RETURN: OKButtonClick(nil);
@@ -236,7 +285,7 @@ end;
 
 procedure TViewUnitDialog.MultiselectCheckBoxClick(Sender :TObject);
 begin
-  ListBox.Multiselect := MultiselectCheckBox.Checked;
+  ListBox.Multiselect := mniMultiSelect.Checked;
 end;
 
 procedure TViewUnitDialog.FocusEdit;
unit_list_cleanup (9,060 bytes)

2010-03-25 22:04

 

unit_list_cleanup_r24209.patch (9,410 bytes)
# HG changeset patch
# User etrusco <flavio.etrusco@gmail.com>
# Date 1267407780 10800
# Branch trunk
# Node ID abe6c88349221586c172df2cdc02b8f244e81fbe
# Parent  79c97133273d44fbafe680fc5a1007c51eb87253
[mq]: unit_list_cleanup

diff --git a/ide/viewunit_dlg.lfm b/ide/viewunit_dlg.lfm
--- a/ide/viewunit_dlg.lfm
+++ b/ide/viewunit_dlg.lfm
@@ -3,162 +3,67 @@ object ViewUnitDialog: TViewUnitDialog
   Height = 301
   Top = 280
   Width = 378
-  HelpContext = 0
   ActiveControl = Edit
-  Align = alNone
-  AllowDropFiles = False
   AutoScroll = True
-  AutoSize = False
   BorderIcons = [biSystemMenu]
-  BorderStyle = bsSizeable
   Caption = 'View Project Units'
-  ChildSizing.LeftRightSpacing = 0
-  ChildSizing.TopBottomSpacing = 0
-  ChildSizing.HorizontalSpacing = 0
-  ChildSizing.VerticalSpacing = 0
-  ChildSizing.ControlsPerLine = 0
   ClientHeight = 301
   ClientWidth = 378
-  DockSite = False
-  DragKind = dkDrag
-  DragMode = dmManual
-  Enabled = True
-  Font.Height = 0
-  Font.Style = []
-  FormStyle = fsNormal
-  ParentBiDiMode = True
-  ParentFont = False
   Position = poScreenCenter
-  ShowInTaskBar = stDefault
-  UseDockManager = False
-  LCLVersion = '0.9.27'
-  WindowState = wsNormal
+  LCLVersion = '0.9.29'
   object Edit: TEdit
     Left = 6
     Height = 25
     Top = 6
     Width = 366
-    HelpContext = 0
     Align = alTop
-    Anchors = [akRight]
+    Anchors = [akLeft]
     AutoSize = False
     AutoSelect = False
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
     BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    CharCase = ecNormal
-    DragCursor = crDrag
-    DragMode = dmManual
-    EchoMode = emNormal
-    Enabled = True
-    MaxLength = -1
-    ParentBidiMode = True
     OnChange = EditChange
     OnEnter = EditEnter
     OnKeyDown = EditKeyDown
-    ParentFont = True
-    ParentShowHint = True
-    PasswordChar = #0
-    ReadOnly = False
-    TabStop = True
     TabOrder = 1
-    Visible = True
   end
   object Listbox: TListBox
     AnchorSideTop.Side = asrBottom
     AnchorSideRight.Side = asrBottom
-    AnchorSideBottom.Control = MultiSelectCheckBox
     Left = 6
-    Height = 182
+    Height = 212
     Top = 37
     Width = 366
-    HelpContext = 0
     Align = alClient
     Anchors = [akBottom]
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
     BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    BorderStyle = bsSingle
     ClickOnSelChange = False
-    Columns = 0
-    DragCursor = crDrag
-    DragKind = dkDrag
-    DragMode = dmManual
-    ExtendedSelect = True
-    Enabled = True
-    IntegralHeight = False
     ItemHeight = 0
-    MultiSelect = False
     OnClick = ListboxClick
     OnDblClick = OKButtonClick
     OnKeyDown = ListboxKeyDown
-    ParentBidiMode = True
-    ParentShowHint = True
-    ParentFont = True
-    Sorted = False
-    Style = lbStandard
+    PopupMenu = popListBox
     TabOrder = 0
-    TabStop = True
     TopIndex = -1
-    Visible = True
-  end
-  object MultiSelectCheckBox: TCheckBox
-    AnchorSideLeft.Control = Owner
-    AnchorSideTop.Side = asrBottom
-    Left = 6
-    Height = 22
-    Top = 225
-    Width = 366
-    HelpContext = 0
-    Align = alBottom
-    AllowGrayed = False
-    Anchors = [akLeft, akBottom]
-    AutoSize = True
-    BorderSpacing.Left = 0
-    BorderSpacing.Top = 0
-    BorderSpacing.Right = 0
-    BorderSpacing.Bottom = 0
-    BorderSpacing.Around = 6
-    BorderSpacing.CellAlignHorizontal = ccaFill
-    BorderSpacing.CellAlignVertical = ccaFill
-    Caption = 'Multi Select'
-    Checked = False
-    DragCursor = crDrag
-    DragKind = dkDrag
-    DragMode = dmManual
-    Enabled = True
-    OnClick = MultiselectCheckBoxClick
-    ParentColor = True
-    ParentFont = True
-    ParentShowHint = True
-    ParentBidiMode = True
-    State = cbUnchecked
-    TabOrder = 2
-    TabStop = True
-    UseOnChange = False
-    Visible = True
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 48
-    Top = 253
+    Height = 40
+    Top = 255
     Width = 366
-    HelpContext = 0
-    Align = alBottom
-    AutoSize = True
-    ButtonOrder = boDefault
-    TabOrder = 3
-    DefaultButton = pbOK
+    TabOrder = 2
     ShowButtons = [pbOK, pbCancel, pbHelp]
-    ShowGlyphs = [pbOK, pbCancel, pbClose, pbHelp]
-    Visible = True
+  end
+  object popListBox: TPopupMenu
+    left = 144
+    top = 112
+    object mniMultiSelect: TMenuItem
+      AutoCheck = True
+      Caption = 'Multi Select'
+      OnClick = MultiselectCheckBoxClick
+    end
+    object mniSort: TMenuItem
+      Caption = 'Sort'
+      OnClick = mniSortClick
+    end
   end
 end
diff --git a/ide/viewunit_dlg.pp b/ide/viewunit_dlg.pp
--- a/ide/viewunit_dlg.pp
+++ b/ide/viewunit_dlg.pp
@@ -41,7 +41,7 @@ interface
 uses
   SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls,
   LazarusIdeStrConsts, LCLType, LCLIntf, LMessages, IDEWindowIntf, IDEContextHelpEdit,
-  ExtCtrls, ButtonPanel;
+  ExtCtrls, ButtonPanel, Menus, StrUtils;
 
 type
   TViewUnitsEntry = class
@@ -58,11 +58,14 @@ type
     ButtonPanel: TButtonPanel;
     Edit: TEdit;
     ListBox: TListBox;
-    MultiSelectCheckBox: TCheckBox;
+    mniMultiSelect: TMenuItem;
+    mniSort: TMenuItem;
+    popListBox: TPopupMenu;
     procedure EditChange(Sender: TObject);
     procedure EditEnter(Sender: TObject);
     procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     procedure HelpButtonClick(Sender: TObject);
+    procedure mniSortClick(Sender: TObject);
     Procedure OKButtonClick(Sender :TObject);
     Procedure CancelButtonClick(Sender :TObject);
     procedure ListboxClick(Sender: TObject);
@@ -93,9 +96,9 @@ begin
   ViewUnitDialog:=TViewUnitDialog.Create(nil);
   try
     ViewUnitDialog.Caption:=Caption;
-    ViewUnitDialog.MultiselectCheckBox.Enabled := AllowMultiSelect;
-    ViewUnitDialog.MultiselectCheckBox.Checked := CheckMultiSelect;
-    ViewUnitDialog.ListBox.MultiSelect:=ViewUnitDialog.MultiselectCheckBox.Checked;
+    ViewUnitDialog.mniMultiselect.Enabled := AllowMultiSelect;
+    ViewUnitDialog.mniMultiselect.Checked := CheckMultiSelect;
+    ViewUnitDialog.ListBox.MultiSelect := ViewUnitDialog.mniMultiselect.Enabled;
     with ViewUnitDialog.ListBox.Items do begin
       BeginUpdate;
       Clear;
@@ -110,7 +113,7 @@ begin
       for i:=0 to Entries.Count-1 do begin
         TViewUnitsEntry(Entries.Objects[i]).Selected:=ViewUnitDialog.ListBox.Selected[i];
       end;
-      CheckMultiSelect := ViewUnitDialog.MultiselectCheckBox.Checked;
+      CheckMultiSelect := ViewUnitDialog.mniMultiselect.Checked;
     end;
   finally
     ViewUnitDialog.Free;
@@ -123,9 +126,9 @@ var
 begin
   // Items can be unsorted => use simple traverse
   Result := -1;
-  Text := LowerCase(Text);
+  Text := AnsiLowerCase(Text);
   for i := StartIndex +1 to Items.Count - 1 do
-    if Pos(Text, LowerCase(Items[i])) >= 1 then
+    if AnsiContainsText(Items[i], Text) then
     begin
       Result := i;
       break;
@@ -149,7 +152,7 @@ constructor TViewUnitDialog.Create(TheOw
 begin
   inherited Create(TheOwner);
   IDEDialogLayoutList.ApplyLayout(Self,450,300);
-  MultiSelectCheckBox.Caption := dlgMultiSelect;
+  mniMultiSelect.Caption := dlgMultiSelect;
 
   ButtonPanel.OKButton.OnClick := @OKButtonClick;
   ButtonPanel.CancelButton.OnClick := @CancelButtonClick;
@@ -167,6 +170,44 @@ begin
   ShowContextHelpForIDE(Self);
 end;
 
+procedure TViewUnitDialog.mniSortClick(Sender: TObject);
+var
+  TmpList: TStringList;
+  i: Integer;
+  SelName: String;
+begin
+  TmpList := TStringList.Create;
+  try
+    TmpList.Assign(ListBox.Items);
+    if ListBox.MultiSelect then
+    begin
+      for i := 0 to ListBox.Count -1 do
+        if ListBox.Selected[i] then
+          TmpList.Objects[i] := TObject(-1);
+    end;
+    TmpList.Sort;
+    if ListBox.ItemIndex >= 0 then
+      SelName := ListBox.Items[ListBox.ItemIndex]
+    else
+      SelName := '';
+    ListBox.Items := TmpList;
+    if SelName <> '' then
+    begin
+      ListBox.ItemIndex := TmpList.IndexOf(SelName);
+      ListBox.MakeCurrentVisible;
+    end;
+    if ListBox.MultiSelect then
+    begin
+      ListBox.ClearSelection;
+      for i := 0 to TmpList.Count -1 do
+        if TmpList.Objects[i] <> nil then
+          ListBox.Selected[i] := True;
+    end;
+  finally
+    TmpList.Free;
+  end;
+end;
+
 procedure TViewUnitDialog.EditKeyDown(Sender: TObject; var Key: Word;
   Shift: TShiftState);
   
@@ -190,7 +231,12 @@ procedure TViewUnitDialog.EditKeyDown(Se
 begin
   case Key of
     VK_UP: MoveItemIndex(-1);
-    VK_DOWN: MoveItemIndex(1);
+    VK_DOWN:
+      begin
+        MoveItemIndex(1);
+        // Avoid switching to next control in TabOrder in gtk2
+        Key := 0;
+      end;
     VK_NEXT: MoveItemIndex(PageCount);
     VK_PRIOR: MoveItemIndex(-PageCount);
     VK_RETURN: OKButtonClick(nil);
@@ -237,7 +283,7 @@ end;
 
 procedure TViewUnitDialog.MultiselectCheckBoxClick(Sender :TObject);
 begin
-  ListBox.Multiselect := MultiselectCheckBox.Checked;
+  ListBox.Multiselect := mniMultiSelect.Checked;
 end;
 
 procedure TViewUnitDialog.FocusEdit;

Zeljan Rikalo

2010-05-26 10:40

developer   ~0038001

Thanks, applied. Test and close if ok.

Issue History

Date Modified Username Field Change
2010-02-13 06:34 Flávio Etrusco (notifications not working) New Issue
2010-02-13 06:34 Flávio Etrusco (notifications not working) File Added: view_unit.diff
2010-02-13 06:40 Flávio Etrusco (notifications not working) Note Added: 0034423
2010-02-13 11:56 Mattias Gaertner Fixed in Revision => 23701
2010-02-13 11:56 Mattias Gaertner LazTarget => -
2010-02-13 11:56 Mattias Gaertner Note Added: 0034435
2010-02-13 11:56 Mattias Gaertner Assigned To => Mattias Gaertner
2010-02-13 11:56 Mattias Gaertner Status new => resolved
2010-02-13 11:56 Mattias Gaertner Resolution open => fixed
2010-02-13 12:31 Zeljan Rikalo Note Added: 0034436
2010-02-13 17:27 Flávio Etrusco (notifications not working) Note Added: 0034449
2010-02-13 17:29 Flávio Etrusco (notifications not working) Note Added: 0034450
2010-02-13 17:34 Flávio Etrusco (notifications not working) Note Added: 0034451
2010-02-13 18:24 Flávio Etrusco (notifications not working) Status resolved => assigned
2010-02-13 18:24 Flávio Etrusco (notifications not working) Resolution fixed => reopened
2010-02-13 18:24 Flávio Etrusco (notifications not working) Note Added: 0034454
2010-02-14 06:44 Flávio Etrusco (notifications not working) File Added: unit_list_cleanup.diff
2010-02-14 06:45 Flávio Etrusco (notifications not working) Note Added: 0034461
2010-02-15 21:12 Flávio Etrusco (notifications not working) File Added: unit_list_cleanup
2010-02-15 21:15 Flávio Etrusco (notifications not working) Note Edited: 0034461
2010-03-25 18:26 Flávio Etrusco (notifications not working) Status assigned => resolved
2010-03-25 18:26 Flávio Etrusco (notifications not working) Resolution reopened => fixed
2010-03-25 22:01 Flávio Etrusco (notifications not working) Assigned To Mattias Gaertner =>
2010-03-25 22:01 Flávio Etrusco (notifications not working) Status resolved => assigned
2010-03-25 22:01 Flávio Etrusco (notifications not working) Resolution fixed => reopened
2010-03-25 22:04 Flávio Etrusco (notifications not working) File Added: unit_list_cleanup_r24209.patch
2010-03-25 22:04 Flávio Etrusco (notifications not working) Status assigned => new
2010-05-26 10:40 Zeljan Rikalo Fixed in Revision 23701 => 23701,25658
2010-05-26 10:40 Zeljan Rikalo Status new => resolved
2010-05-26 10:40 Zeljan Rikalo Resolution reopened => fixed
2010-05-26 10:40 Zeljan Rikalo Assigned To => Zeljan Rikalo
2010-05-26 10:40 Zeljan Rikalo Note Added: 0038001
2011-04-02 22:27 Flávio Etrusco (notifications not working) Status resolved => closed
2011-04-02 22:27 Flávio Etrusco (notifications not working) Fixed in Version => 0.9.30
2011-04-02 22:27 Flávio Etrusco (notifications not working) Target Version => 0.9.30