[Mono-list] ListViewItemSorter property for FileDialog to folow .Net functions
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. [EMAIL PROTECTED] 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 [EMAIL PROTECTED] +// 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 t
Re: [Mono-list] ListViewItemSorter property for FileDialog to folow .Net functions
As sayed on IRC, better to attach the patch file. 2008/9/16 Petit Eric <[EMAIL PROTECTED]>: > 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. > > > [EMAIL PROTECTED] 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 [EMAIL PROTECTED] > +// 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
Re: [Mono-list] ListViewItemSorter property for FileDialog to folow .Net functions
Sorry for that, i'm really newbie and it is my first really patch, i just did copy/paste the content of the console in the patch file and , it doesn't work (UTF8 or something else) so here it is a new one with : svn diff FileDialog.cs > FileDialog.diff and now it should work. 2008/9/16 Petit Eric <[EMAIL PROTECTED]>: > As sayed on IRC, better to attach the patch file. > > 2008/9/16 Petit Eric <[EMAIL PROTECTED]>: >> 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. >> >> >> [EMAIL PROTECTED] 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 [EMAIL PROTECTED] >> +// 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); >>
Re: [Mono-list] ListViewItemSorter property for FileDialog to folow .Net functions
Hey Petit, I just review your patch and I think that you can improve it before get it on SVN. Also I think that is better if you create a bug report in bugzilla an attach your patch, in description you can use "[Patch]" to identify that it is a patch so we can track it in bugzilla like all other patches. You can see some examples about how we track patches in https://bugzilla.novell.com/show_bug.cgi?id=325809 or you can see also other bugs marked as "patch". So, now let us go to my suggestions to your patch: * Indent your code using Tab instead of spaces like the rest of MWF code and we have an "space" before every "(" in method declaration. * On top of mcs svn module we have CodingStyle file, you can read it to see more about Mono code style. Also you can read it on our wiki: http://www.mono-project.com/Coding_Guidelines. * The method mwfFileView_ColumnClick could be called OnColumnClickFileView to be in accord with all other mwfFileView methods. Also, remove the System.Windows.Forms. from ColumnClickEventHandler, look to the line before and do the same. * Rename ListViewItemComparer to MwfFileViewItemComparer so later if we need to implement another comparer class we will not have problems with names. * In mwfFileView_ColumnClick now ColumnClickEventHandler we have one try-catch that send a error message to console, I dont think that we need this try-catch but if we really need it will be better to prevent errors on MwfFileViewItemComparer class. * AscDesc var is also not a good name for a private member (Coding_Guidelines) maybe you can use something like "mwffileview_order" or "fileview_order". * According to MSDN, after use ListViewItemSorter you dont need to call sort maybe MSDN is wrong (it happens a lot) so is better to test if we really need to call Sort method. * Check also private member names in MwfFileViewItemComparer class. Ah, make sure that the patch is also generated using last Mono SVN trunk. Thank you very much, Everaldo. ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] ListViewItemSorter property for FileDialog to folow .Net functions
I posted the patch yesterday at bugzilla, and CC yu in it with your novel adress , i just see , i forget to change bracket disposition, sorry, change is always hard and also i used VS C# who made indent and all paging automaticaly. 2008/9/18 Everaldo Canuto <[EMAIL PROTECTED]>: > Hey Petit, > > I just review your patch and I think that you can improve it before get it on > SVN. Also I think that is better if you create a bug report in bugzilla an > attach your patch, in description you can use "[Patch]" to identify that it > is a > patch so we can track it in bugzilla like all other patches. > > > You can see some examples about how we track patches in > https://bugzilla.novell.com/show_bug.cgi?id=325809 or you can see also other > bugs marked as "patch". > > So, now let us go to my suggestions to your patch: > > * Indent your code using Tab instead of spaces like the rest of MWF code and >we have an "space" before every "(" in method declaration. > > * On top of mcs svn module we have CodingStyle file, you can read it to see >more about Mono code style. Also you can read it on our wiki: > >http://www.mono-project.com/Coding_Guidelines. > > * The method mwfFileView_ColumnClick could be called OnColumnClickFileView >to be in accord with all other mwfFileView methods. Also, remove the >System.Windows.Forms. from ColumnClickEventHandler, look to the line before >and do the same. > > * Rename ListViewItemComparer to MwfFileViewItemComparer so later if we need >to implement another comparer class we will not have problems with names. > > * In mwfFileView_ColumnClick now ColumnClickEventHandler we have one > try-catch >that send a error message to console, I dont think that we need this >try-catch but if we really need it will be better to prevent errors on >MwfFileViewItemComparer class. > > * AscDesc var is also not a good name for a private member > (Coding_Guidelines) >maybe you can use something like "mwffileview_order" or "fileview_order". > > * According to MSDN, after use ListViewItemSorter you dont need to call sort >maybe MSDN is wrong (it happens a lot) so is better to test if we really >need to call Sort method. > > * Check also private member names in MwfFileViewItemComparer class. > > > Ah, make sure that the patch is also generated using last Mono SVN trunk. > > Thank you very much, > Everaldo. > -- 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. ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list