[Mono-list] ListViewItemSorter property for FileDialog to folow .Net functions

Petit Eric surfzoid at gmail.com
Tue Sep 16 17:02:08 EDT 2008


As sayed on IRC, better to attach the patch file.

2008/9/16 Petit Eric <surfzoid at gmail.com>:
> Hi
> i add the listview item comparer for FileDialog, like this in a FSdlg,
> yu can click to a collumn header (details view) to change the order,
> like in .NET.
> a perfect think, should be to add "order by group".
>
> At this time, this patch provide similar way as .NET, except for one
> thing, with .NET that work as it, yu click on the first column header
> it  order asc and class by the first column item, yu click on the 2th
> column header, it order asc and class by the 2th clm header.
> Mine patch, change order asc/desc, each time yu click on a column, it
> will need to copy paste my method for each column and dont continu to
> use the same click event void to use my order function/class.
>
>
> [root at SurfzoidPC System.Windows.Forms]# svn diff FileDialog.cs
> Index: FileDialog.cs
> ===================================================================
> --- FileDialog.cs       (révision 113212)
> +++ FileDialog.cs       (copie de travail)
> @@ -360,6 +360,9 @@
>                        mwfFileView.SelectedFileChanged += new
> EventHandler (OnSelectedFileChangedFileView);
>                        mwfFileView.ForceDialogEnd += new EventHandler
> (OnForceDialogEndFileView);
>                        mwfFileView.SelectedFilesChanged += new
> EventHandler (OnSelectedFilesChangedFileView);
> +
> +                       //Add Column click event for manual sorting. line 379
> +                       mwfFileView.ColumnClick += new
> System.Windows.Forms.ColumnClickEventHandler(mwfFileView_ColumnClick);
>
>                        dirComboBox.DirectoryChanged += new
> EventHandler (OnDirectoryChangedDirComboBox);
>                        popupButtonPanel.DirectoryChanged += new
> EventHandler (OnDirectoryChangedPopupButtonPanel);
> @@ -373,6 +376,25 @@
>  #endif
>                }
>
> +               bool AscDesc = true;
> +               private void mwfFileView_ColumnClick(object sender,
> ColumnClickEventArgs e)
> +               {
> +                       try
> +                       {
> +                               AscDesc = !AscDesc;
> +
> +                               // Set the ListViewItemSorter property
> to a new ListViewItemComparer object.
> +                               mwfFileView.ListViewItemSorter = new
> ListViewItemComparer(e.Column, AscDesc);
> +                               // Call the sort method to manually sort.
> +                               mwfFileView.Sort();
> +
> +                       }
> +                       catch (Exception ex)
> +                       {
> +                               Console.WriteLine(DateTime.Now + ": "
> + ex.Message + Environment.NewLine + ex.StackTrace);
> +                       }
> +               }
> +
>                [DefaultValue(true)]
>                public bool AddExtension {
>                        get {
> @@ -2198,6 +2220,41 @@
>        }
>        #endregion
>
> +       #region ListViewItemComparer Added by surfzoid at gmail.com
> +    // Implements the manual sorting of items by column.
> +    class ListViewItemComparer : IComparer
> +    {
> +               private int col;
> +               private bool AscDescInternal;
> +               public ListViewItemComparer()
> +               {
> +                       col = 0;
> +               }
> +
> +               public ListViewItemComparer(int column, bool AscDesc)
> +               {
> +                       col = column;
> +                       AscDescInternal = AscDesc;
> +               }
> +               public int Compare(object x, object y)
> +               {
> +                       int returnVal = -1;
> +                       if (AscDescInternal == true)
> +                       {
> +                               returnVal =
> String.Compare(((ListViewItem)x).SubItems[col].Text,
> +                               ((ListViewItem)y).SubItems[col].Text);
> +                       }
> +
> +                       else
> +                       {
> +                               returnVal =
> String.Compare(((ListViewItem)y).SubItems[col].Text,
> +                               ((ListViewItem)x).SubItems[col].Text);
> +                       }
> +               return returnVal;
> +               }
> +       }
> +    #endregion
> +
>        #region MWFFileView
>
>        internal class MWFFileView : ListView
> @@ -2333,14 +2390,14 @@
>                        columns [1] = CreateColumnHeader ("Size ", 80,
> HorizontalAlignment.Right);
>                        columns [2] = CreateColumnHeader (" Type",
> 100, HorizontalAlignment.Left);
>                        columns [3] = CreateColumnHeader (" Last
> Access", 150, HorizontalAlignment.Left);
> -
> +
>                        AllowColumnReorder = true;
>
>                        ResumeLayout (false);
>
>                        KeyDown += new KeyEventHandler (MWF_KeyDown);
>                }
> -
> +
>                ColumnHeader CreateColumnHeader (string text, int
> width, HorizontalAlignment alignment)
>                {
>                        ColumnHeader col = new ColumnHeader ();
>
>
> --
>
> Cordially.
>
> Small Eric Quotations of the days:
> ---------------------------------------------------------------------------
> If one day one reproaches you that your work is not a work of
> professional, say you that:
> Amateurs built the arch of Noah, and professionals the Titanic.
> ---------------------------------------------------------------------------
>
> Few people are done for independence, it is the privilege of the powerful ones.
> ---------------------------------------------------------------------------
>
> No key was wounded during the drafting of this message.
>



-- 

Cordially.

Small Eric Quotations of the days:
---------------------------------------------------------------------------
If one day one reproaches you that your work is not a work of
professional, say you that:
Amateurs built the arch of Noah, and professionals the Titanic.
---------------------------------------------------------------------------

Few people are done for independence, it is the privilege of the powerful ones.
---------------------------------------------------------------------------

No key was wounded during the drafting of this message.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FsDlgItemComparer.patch
Type: application/octet-stream
Size: 4091 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20080916/f463a2db/attachment.obj 


More information about the Mono-list mailing list