public void AddHeaderColumn(Collumns col)
        {
            var gridView    = this.lvHeader.View as GridView;
            var gridviewcol = new GridViewColumn();

            gridviewcol.Header = col.Name;
            gridviewcol.Width  = col.Width;
            gridView.Columns.Add(gridviewcol);
        }
Exemplo n.º 2
0
        public static void SetSplitButton(this Collumns column, IntPtr handle, int index)
        {
            var item = new HDITEM {
                mask = HDITEM.Mask.Format
            };

            User32.SendMessage(handle, MSG.HDM_GETITEM, index, ref item);

            item.fmt |= HDITEM.Format.HDF_SPLITBUTTON;

            User32.SendMessage(handle, MSG.HDM_SETITEM, index, ref item);
        }
Exemplo n.º 3
0
        public static IOrderedEnumerable <IListItemEx> SetSortCollumn(this IEnumerable <IListItemEx> items, ShellView view, Boolean isReorder, Collumns column, SortOrder order, Boolean reverseOrder = true)
        {
            if (column == null)
            {
                column = view.Collumns.FirstOrDefault();
            }

            try {
                IOrderedEnumerable <IListItemEx> result = null;
                //var selectedItems = this.SelectedItems.ToArray();
                if (column.ID == view.LastSortedColumnId && reverseOrder)
                {
                    // Reverse the current sort direction for this column.
                    view.LastSortOrder = view.LastSortOrder == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending;
                }
                else
                {
                    // Set the column number that is to be sorted; default to ascending.
                    view.LastSortedColumnId = column.ID;
                    view.LastSortOrder      = order;
                }

                if (isReorder)
                {
                    var itemsQuery = items.Where(w => view.ShowHidden || !w.IsHidden).OrderByDescending(o => o.IsFolder);
                    if (column.CollumnType != typeof(String))
                    {
                        if (order == SortOrder.Ascending)
                        {
                            result = itemsQuery.ThenBy(o => o.GetPropertyValue(column.pkey, typeof(String)).Value ?? "1");
                        }
                        else
                        {
                            result = itemsQuery.ThenByDescending(o => o.GetPropertyValue(column.pkey, typeof(String)).Value ?? "1");
                        }
                    }
                    else
                    {
                        if (order == SortOrder.Ascending)
                        {
                            result = itemsQuery.ThenBy(o => o.GetPropertyValue(column.pkey, typeof(String)).Value?.ToString(), NaturalStringComparer.Default);
                        }
                        else
                        {
                            result = itemsQuery.ThenByDescending(o => o.GetPropertyValue(column.pkey, typeof(String)).Value?.ToString(), NaturalStringComparer.Default);
                        }
                    }

                    var i = 0;
                }


                //var colIndexReal = view.Collumns.IndexOf(view.Collumns.FirstOrDefault(w => w.ID == view.LastSortedColumnId));
                //if (colIndexReal > -1) {
                //  User32.SendMessage(view.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, colIndexReal, 0);
                //  view.SetSortIcon(colIndexReal, order);
                //} else {
                //  User32.SendMessage(view.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, -1, 0);
                //}

                //if (!this.IsRenameInProgress) {
                //  this.SelectItems(selectedItems);
                //}
                return(result);
            } catch {
                return(null);
            }
        }
        public void RemoveHeaderColumn(Collumns col)
        {
            var gridView = this.lvHeader.View as GridView;

            gridView.Columns.RemoveAt(col.Index);
        }
Exemplo n.º 5
0
    private void NavigateSearch(IListItemEx destination, Boolean isInSameTab = false, Boolean refresh = false, Boolean isCancel = false) {
      SaveSettingsToDatabase(this.CurrentFolder);
      if (destination == null) return;
      if (this.RequestedCurrentLocation == destination && !refresh) return;
      //if (this._RequestedCurrentLocation != destination) {
      //}

      _ResetEvent.Set();

      if (this._Threads.Any()) {
        _Mre.Set();
        this._ResetEvent.Set();
        foreach (var thread in this._Threads.ToArray()) {
          thread.Abort();
          this._Threads.Remove(thread);
        }
      }

      this._UnvalidateTimer.Stop();
      this._IsDisplayEmptyText = false;
      User32.SendMessage(this.LVHandle, MSG.LVM_SETITEMCOUNT, 0, 0);
      this.DisableGroups();

      this._ItemForRename = -1;
      this._LastItemForRename = -1;

      Items.Clear();
      this._AddedItems.Clear();
      this.LargeImageList.ReInitQueues();
      this.SmallImageList.ReInitQueues();
      this._CuttedIndexes.Clear();
      this.RequestedCurrentLocation = destination;
      if (!refresh)
        Navigating?.Invoke(this, new NavigatingEventArgs(destination, isInSameTab));

      var columns = new Collumns();
      Int32 CurrentI = 0, LastI = 0, K = 0;
      this.IsNavigationInProgress = true;

      _ResetTimer.Stop();

      this.RemoveAllCollumns();
      this.AddDefaultColumns(false, true);

      this.IsViewSelectionAllowed = true;
      this.Invoke((Action)(() => this._NavWaitTimer.Start()));
      var navigationThread = new Thread(() => {
        destination = FileSystemListItem.ToFileSystemItem(destination.ParentHandle, destination.PIDL);
        this.RequestedCurrentLocation = destination;
        this.Invoke((Action)(() => {
          if (!this._SearchTimer.Enabled) {
            this._SearchTimer.Start();
          }
        }));

        foreach (var shellItem in destination.TakeWhile(shellItem => !this.IsCancelRequested)) {
          CurrentI++;
          _Smre.WaitOne();

          if (this.ShowHidden || !shellItem.IsHidden) {
            shellItem.ItemIndex = K++;
            this.Items.Add(shellItem);
            if (CurrentI == 1) {
              this.Invoke((Action)(() => {
                this._NavWaitTimer.Stop();
                this._IsDisplayEmptyText = false;
                this._IIListView.ResetEmptyText();
              }));
            }
          }

          var delta = CurrentI - LastI;
          if (delta >= (this.IsSearchNavigating ? 1 : 5000)) {
            LastI = CurrentI;
          }
          if (this.IsSearchNavigating && delta >= 20)
            Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
        }
        this.IsCancelRequested = false;
        this.IsNavigationInProgress = false;

        if (this.RequestedCurrentLocation.NavigationStatus != HResult.S_OK) {
          this.Invoke((Action)(() => {
            if (this._SearchTimer.Enabled)
              this._SearchTimer.Stop();
          }));
          this.BeginInvoke((Action)(() => {
            var navArgs = new NavigatedEventArgs(this.RequestedCurrentLocation, this.CurrentFolder, isInSameTab);
            this.CurrentFolder = this.RequestedCurrentLocation;

            if (!refresh)
              Navigated?.Invoke(this, navArgs);
          }));

          GC.Collect();
          Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
          if (this._Threads.Count <= 1) return;
          _Mre.Set();
          this._ResetEvent.Set();
          this._Threads[0].Abort();
          this._Threads.RemoveAt(0);
          return;
        }

        var headerhandle = User32.SendMessage(this.LVHandle, MSG.LVM_GETHEADER, 0, 0);
        for (var i = 0; i < this.Collumns.Count; i++) {
          this.Collumns[i].SetSplitButton(headerhandle, i);
        }

        if (this.View != ShellViewStyle.Details) AutosizeAllColumns(-2);

        var sortColIndex = 0;
        if (sortColIndex > -1) this.SetSortIcon(sortColIndex, SortOrder.Ascending);

        this.SetSortCollumn(false, this.Collumns.First(), SortOrder.Ascending, false);

        this.BeginInvoke((Action)(() => {
          var navArgs = new NavigatedEventArgs(this.RequestedCurrentLocation, this.CurrentFolder, isInSameTab);
          this.CurrentFolder = this.RequestedCurrentLocation;
          if (!refresh)
            Navigated?.Invoke(this, navArgs);
        }));

        GC.Collect();
        Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
        this.Invoke((Action)(() => {
          if (this._SearchTimer.Enabled)
            this._SearchTimer.Stop();
        }));
        _Mre.Reset();
        _Mre.WaitOne();
      });
      navigationThread.SetApartmentState(ApartmentState.STA);
      this._Threads.Add(navigationThread);
      navigationThread.Start();
    }
Exemplo n.º 6
0
    private void Navigate(IListItemEx destination, Boolean isInSameTab = false, Boolean refresh = false, Boolean isCancel = false) {
      this.SaveSettingsToDatabase(this.CurrentFolder);

      // TODO: Document isCancel Param better
      if (destination == null) {
        return;
      }
      destination = FileSystemListItem.ToFileSystemItem(destination.ParentHandle, destination.PIDL);
      if (this.RequestedCurrentLocation == destination && !refresh) {
        return;
      }
      //if (this.RequestedCurrentLocation != destination) {
      //  this.IsCancelRequested = true;
      //}
      this.LargeImageList.ResetEvent.Set();
      this.SmallImageList.ResetEvent.Set();
      this._ResetEvent.Set();

      if (this._Threads.Count > 0) {
        this._Mre.Set();
        this._ResetEvent.Set();
        this.LargeImageList.ResetEvent.Set();
        this.SmallImageList.ResetEvent.Set();
        foreach (var thread in this._Threads.ToArray()) {
          thread.Abort();
          this._Threads.Remove(thread);
        }
      }

      this._UnvalidateTimer.Stop();
      this._IsDisplayEmptyText = false;
      User32.SendMessage(this.LVHandle, MSG.LVM_SETITEMCOUNT, 0, 0);
      this.DisableGroups();
      this.Focus(false, true);
      this._ItemForRename = -1;
      this._LastItemForRename = -1;
      this.Items.Clear();
      this._AddedItems.Clear();
      this.LargeImageList.ReInitQueues();
      this.SmallImageList.ReInitQueues();
      this._CuttedIndexes.Clear();

      FolderSettings folderSettings;
      var isThereSettings = false;

      isThereSettings = LoadSettingsFromDatabase(destination, out folderSettings);
      this.RequestedCurrentLocation = destination;
      if (!refresh)
        Navigating?.Invoke(this, new NavigatingEventArgs(destination, isInSameTab));

      var columns = new Collumns();
      Int32 CurrentI = 0, LastI = 0, K = 0;
      this.IsNavigationInProgress = true;

      _ResetTimer.Stop();
      if (isThereSettings) {
        if (folderSettings.Columns != null) {
          this.RemoveAllCollumns();
          foreach (var collumn in folderSettings.Columns.Elements()) {
            var theColumn = this.AllAvailableColumns.FirstOrDefault(w => w.Value.ID == collumn.Attribute("ID").Value).Value;//.Single();
            if (theColumn == null) continue;
            if (this.Collumns.Any(c => c.ID == theColumn?.ID)) continue;
            if (collumn.Attribute("Width").Value != "0") theColumn.Width = Convert.ToInt32(collumn.Attribute("Width").Value);
            this.Collumns.Add(theColumn);
            var column = theColumn.ToNativeColumn(folderSettings.View == ShellViewStyle.Details);
            User32.SendMessage(this.LVHandle, MSG.LVM_INSERTCOLUMN, this.Collumns.Count - 1, ref column);
            if (folderSettings.View != ShellViewStyle.Details) this.AutosizeColumn(this.Collumns.Count - 1, -2);
          }
        }
      } else {
        this.RemoveAllCollumns();
        this.AddDefaultColumns(false, true);
      }

      if (!String.IsNullOrEmpty(folderSettings.GroupCollumn)) {
        var colData = this.AllAvailableColumns.FirstOrDefault(w => w.Value.ID == folderSettings.GroupCollumn).Value;
        if (colData != null)
          this.EnableGroups();
        else
          this.DisableGroups();
      } else {
        this.DisableGroups();
      }

      columns = this.AllAvailableColumns.FirstOrDefault(w => w.Value.ID == folderSettings.SortColumn).Value;
      this.IsViewSelectionAllowed = false;
      if (!isThereSettings) {
        this.View = ShellViewStyle.Details;
      }

      if (folderSettings.View == ShellViewStyle.Details || folderSettings.View == ShellViewStyle.SmallIcon || folderSettings.View == ShellViewStyle.List) {
        this.ResizeIcons(16);
        this.View = folderSettings.View;
      } else if (folderSettings.IconSize >= 16) {
        this.ResizeIcons(folderSettings.IconSize);
        var view = (ShellViewStyle)folderSettings.IconSize;
        if (folderSettings.IconSize != 48 && folderSettings.IconSize != 96 && folderSettings.IconSize != 256)
          this.View = ShellViewStyle.Thumbnail;
        else
          this.View = folderSettings.View;
      }

      this.IsViewSelectionAllowed = true;
      this.Invoke((Action)(() => this._NavWaitTimer.Start()));

      var navigationThread = new Thread(() => {
        this.IsCancelRequested = false;
        destination = FileSystemListItem.ToFileSystemItem(destination.ParentHandle, destination.PIDL);
        if (destination.IsFileSystem) {
          if (this._FsWatcher != null) {
            this._FsWatcher.EnableRaisingEvents = false;
            this._FsWatcher.Dispose();
            try {
              this._FsWatcher = new FileSystemWatcher(@destination.ParsingName);
              //this._FsWatcher.InternalBufferSize = 64 * 1024 * 1024;
              this._FsWatcher.Changed += (sender, args) => {
                try {
                  var objUpdateItem = FileSystemListItem.ToFileSystemItem(this.LVHandle, args.FullPath);
                  if (objUpdateItem.IsInCurrentFolder(this.CurrentFolder)) {
                    var exisitingUItem = this.Items.ToArray().FirstOrDefault(w => w.Equals(objUpdateItem));
                    if (exisitingUItem != null)
                      this.RefreshItem(exisitingUItem.ItemIndex, true);

                    if (this.RequestedCurrentLocation != null && objUpdateItem.Equals(this.RequestedCurrentLocation))
                      this.UnvalidateDirectory();
                  }
                } catch (FileNotFoundException) {
                  //Probably a temporary file 
                  this._TemporaryFiles.Add(args.FullPath);
                } catch {
                }
              };
              this._FsWatcher.Error += (sender, args) => {
                var ex = args.GetException();
              };
              this._FsWatcher.Created += (sender, args) => {
                try {
                  //var existing = this.Items.FirstOrDefault(s => s.ParsingName.Equals(args.FullPath));
                  //if (existing != null) return;
                  if (Path.GetExtension(args.FullPath).ToLowerInvariant() == ".tmp" ||
                          Path.GetExtension(args.FullPath) == String.Empty) {
                    if (!this._TemporaryFiles.Contains(args.FullPath))
                      this._TemporaryFiles.Add(args.FullPath);
                  }
                  var obj = FileSystemListItem.ToFileSystemItem(this.LVHandle, args.FullPath);
                  if (obj.IsInCurrentFolder(this.CurrentFolder)) {
                    if (this.IsRenameNeeded) {
                      var existingItem = this.Items.ToArray().FirstOrDefault(s => s.Equals(obj));
                      if (existingItem == null) {
                        var itemIndex = this.InsertNewItem(obj);
                        this.SelectItemByIndex(itemIndex, true, true);
                        this.RenameSelectedItem(itemIndex);
                        this.IsRenameNeeded = false;
                      } else {
                        this.RenameSelectedItem(existingItem.ItemIndex);
                      }
                    } else {
                      if (this._ItemsQueue.Enqueue(new Tuple<ItemUpdateType, IListItemEx>(ItemUpdateType.Created, obj)))
                        this.UnvalidateDirectory();
                    }
                  }
                } catch (FileNotFoundException) {
                  this.QueueDeleteItem(args);
                } catch { }
              };

              this._FsWatcher.Deleted += (sender, args) => this.QueueDeleteItem(args);
              this._FsWatcher.Renamed += (sender, args) => { };
              this._FsWatcher.IncludeSubdirectories = false;
              this._FsWatcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.Attributes |
              NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
            } catch (ArgumentException) {
              this._FsWatcher = new FileSystemWatcher();
            }
          }

          try {
            if (this._FsWatcher != null && !String.IsNullOrEmpty(this._FsWatcher.Path)) {
              this._FsWatcher.EnableRaisingEvents = true;
            }
          } catch (FileNotFoundException) { }
        }

        this.RequestedCurrentLocation = destination;
        var column = columns ?? this.AllAvailableColumns.Single(s => s.Value.ID == "A0").Value;
        var order = folderSettings.SortOrder;
        var content = destination;

        foreach (var shellItem in destination.IsNetworkPath ? destination.TakeWhile(shellItem => !this.IsCancelRequested) : content.TakeWhile(shellItem => !this.IsCancelRequested)) {
          CurrentI++;

          if (!this.RequestedCurrentLocation.Equals(shellItem.Parent) && this.IsNavigationCancelRequested) {
            this.IsNavigationCancelRequested = false;
            return;
          }

          if (this.ShowHidden || !shellItem.IsHidden) {
            shellItem.ItemIndex = K++;
            this.Items.Add(shellItem);
            if (CurrentI == 1) {
              this.Invoke((Action)(() => {
                this._NavWaitTimer.Stop();
                this._IsDisplayEmptyText = false;
                this._IIListView.ResetEmptyText();
              }));
            }
          }

          var delta = CurrentI - LastI;
          if (delta >= 4750) {
            LastI = CurrentI;
            this.BeginInvoke((MethodInvoker)(() => this._IIListView.SetItemCount(this.Items.Count, 0x2)));
          }
        }

        this.IsCancelRequested = false;
        this.IsNavigationInProgress = false;

        if (this.RequestedCurrentLocation.NavigationStatus != HResult.S_OK) {
          GC.Collect();
          Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
          if (this._Threads.Count <= 1) return;
          _Mre.Set();
          this._ResetEvent.Set();
          this._Threads[0].Abort();
          this._Threads.RemoveAt(0);
          return;
        }

        var headerhandle = User32.SendMessage(this.LVHandle, MSG.LVM_GETHEADER, 0, 0);
        for (var i = 0; i < this.Collumns.Count; i++) {
          this.Collumns[i].SetSplitButton(headerhandle, i);
        }

        if (this.View != ShellViewStyle.Details) AutosizeAllColumns(-2);

        //User32.SendMessage(this.LVHandle, MSG.LVM_SETITEMCOUNT, this.Items.Count, 0x2);

        var sortColIndex = this.Collumns.SingleOrDefault(s => s.ID == columns?.ID)?.Index;
        if (sortColIndex != null) {
          this.SetSortIcon(sortColIndex.Value, folderSettings.SortOrder == SortOrder.None ? SortOrder.Ascending : folderSettings.SortOrder);
        }

        if (isThereSettings) {
          if (columns?.ID == "A0" && String.Equals(this.RequestedCurrentLocation.ParsingName, KnownFolders.Computer.ParsingName, StringComparison.InvariantCultureIgnoreCase))
            this.SetSortCollumn(true, this.AvailableColumns().Single(s => s.Value.ID == "A180").Value, SortOrder.Ascending, false);
          else
            this.SetSortCollumn(true, columns, folderSettings.SortOrder, false);
        } else if (String.Equals(this.RequestedCurrentLocation.ParsingName, KnownFolders.Computer.ParsingName, StringComparison.InvariantCultureIgnoreCase)) {
          this.Items = this.Items.OrderBy(o => o.ParsingName).ToList();
          var i = 0;
          this.Items.ForEach(e => e.ItemIndex = i++);
          User32.SendMessage(this.LVHandle, MSG.LVM_SETITEMCOUNT, this.Items.Count, 0x2);
        } else {
          this.Items = this.Items.OrderByDescending(o => o.IsFolder).ThenBy(o => o.DisplayName).ToList();
          var i = 0;
          this.Items.ToList().ForEach(e => e.ItemIndex = i++);
          User32.SendMessage(this.LVHandle, MSG.LVM_SETITEMCOUNT, this.Items.Count, 0x2);
        }

        if (this.IsGroupsEnabled) {
          var colData = this.AllAvailableColumns.FirstOrDefault(w => w.Value.ID == folderSettings.GroupCollumn).Value;
          this.GenerateGroupsFromColumn(colData, folderSettings.GroupOrder == SortOrder.Descending);
        }

        if (!isThereSettings) {
          this.LastSortedColumnId = "A0";
          this.LastSortOrder = SortOrder.Ascending;
          this.SetSortIcon(0, SortOrder.Ascending);
          User32.SendMessage(this.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, 0, 0);
        }

        this._IsDisplayEmptyText = false;
        this.BeginInvoke((Action)(() => {
          var navArgs = new NavigatedEventArgs(this.RequestedCurrentLocation, this.CurrentFolder, isInSameTab);
          this.CurrentFolder = this.RequestedCurrentLocation;
          if (!refresh)
            Navigated?.Invoke(this, navArgs);
        }));

        this.Invoke((Action)(() => {
          this._NavWaitTimer.Stop();
          this._IsDisplayEmptyText = false;
          this._IIListView.ResetEmptyText();
        }));

        GC.Collect();
        Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
        this.Invoke((Action)(() => {
          if (this._SearchTimer.Enabled)
            this._SearchTimer.Stop();
        }));

        _Mre.Reset();
        _Mre.WaitOne();
      });

      navigationThread.SetApartmentState(ApartmentState.STA);
      this._Threads.Add(navigationThread);
      navigationThread.Start();
    }
Exemplo n.º 7
0
    public void GenerateGroupsFromColumn(Collumns col, Boolean reversed = false) {
      if (col == null) return;
      this.BeginInvoke(new MethodInvoker(() => this._IIListView.RemoveAllGroups()));

      this.Groups.Clear();
      if (col.CollumnType == typeof(String)) {
        if (this.IsTraditionalNameGrouping) {
          var groups = this.Items.ToArray().GroupBy(k => k.DisplayName.ToUpperInvariant().First(), e => e).OrderBy(o => o.Key);
          var i = reversed ? groups.Count() - 1 : 0;
          foreach (var group in groups) {
            var groupItems = group.Select(s => s).ToArray();
            groupItems.ToList().ForEach(c => c.GroupIndex = this.Groups.Count);
            this.Groups.Add(new ListViewGroupEx() { Items = groupItems, Index = reversed ? i-- : i++, Header = $"{group.Key.ToString()} ({groupItems.Count()})" });
          }
        } else {
          var i = reversed ? 3 : 0;

          Action<String, String, Boolean> addNameGroup = (String char1, String char2, Boolean isOthers) => {
            var testgrn = new ListViewGroupEx();
            if (isOthers) {
              testgrn.Items =
                              this.Items.Where(
                                              w =>
                                                              (w.DisplayName.ToUpperInvariant().First() < Char.Parse("A") ||
                                                              w.DisplayName.ToUpperInvariant().First() > Char.Parse("Z")) && (w.DisplayName.ToUpperInvariant().First() < Char.Parse("0") || w.DisplayName.ToUpperInvariant().First() > Char.Parse("9"))).ToArray();
            } else {
              testgrn.Items =
                              this.Items.Where(
                                              w =>
                                                              w.DisplayName.ToUpperInvariant().First() >= Char.Parse(char1) &&
                                                              w.DisplayName.ToUpperInvariant().First() <= Char.Parse(char2)).ToArray();
            }
            testgrn.Header = isOthers
                            ? char1 + $" ({testgrn.Items.Count()})"
                            : char1 + " - " + char2 + $" ({testgrn.Items.Count()})";
            testgrn.Index = reversed ? i-- : i++;
            this.Groups.Add(testgrn);
          };

          addNameGroup("0", "9", false);
          addNameGroup("A", "H", false);
          addNameGroup("I", "P", false);
          addNameGroup("Q", "Z", false);
          addNameGroup("Others", String.Empty, true);
        }
      } else if (col.CollumnType == typeof(Int64)) {
        var j = reversed ? 7 : 0;
        //TODO: Upgrade next to use an Action<>

        var uspec = new ListViewGroupEx();
        uspec.Items = this.Items.Where(w => w.IsFolder).ToArray();
        uspec.Header = $"Unspecified ({uspec.Items.Count()})";
        uspec.Index = reversed ? j-- : j++;
        this.Groups.Add(uspec);

        var testgrn = new ListViewGroupEx();
        testgrn.Items =
                this.Items.Where(w => Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) == 0 && !w.IsFolder)
                        .ToArray();
        testgrn.Header = $"Empty ({testgrn.Items.Count()})";
        testgrn.Index = reversed ? j-- : j++;
        this.Groups.Add(testgrn);

        var testgr = new ListViewGroupEx();
        testgr.Items =
                this.Items.Where(
                        w =>
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) > 0 &&
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) <= 10 * 1024).ToArray();
        testgr.Header = $"Very Small ({testgr.Items.Count()})";
        testgr.Index = reversed ? j-- : j++;
        this.Groups.Add(testgr);

        var testgr2 = new ListViewGroupEx();
        testgr2.Items =
                this.Items.Where(
                        w =>
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) > 10 * 1024 &&
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) <= 100 * 1024).ToArray();
        testgr2.Header = $"Small ({testgr2.Items.Count()})";
        testgr2.Index = reversed ? j-- : j++;
        this.Groups.Add(testgr2);

        var testgr3 = new ListViewGroupEx();
        testgr3.Items =
                this.Items.Where(
                        w =>
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) > 100 * 1024 &&
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) <= 1 * 1024 * 1024).ToArray();
        testgr3.Header = $"Medium ({testgr3.Items.Count()})";
        testgr3.Index = reversed ? j-- : j++;
        this.Groups.Add(testgr3);

        var testgr4 = new ListViewGroupEx();
        testgr4.Items =
                this.Items.Where(
                        w =>
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) > 1 * 1024 * 1024 &&
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) <= 16 * 1024 * 1024).ToArray();
        testgr4.Header = $"Big ({testgr4.Items.Count()})";
        testgr4.Index = reversed ? j-- : j++;
        this.Groups.Add(testgr4);

        var testgr5 = new ListViewGroupEx();
        testgr5.Items =
                this.Items.Where(
                        w =>
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) > 16 * 1024 * 1024 &&
                                Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) <= 128 * 1024 * 1024).ToArray();
        testgr5.Header = $"Huge ({testgr5.Items.Count()})";
        testgr5.Index = reversed ? j-- : j++;
        this.Groups.Add(testgr5);

        var testgr6 = new ListViewGroupEx();
        testgr6.Items =
                this.Items.Where(w => Convert.ToInt64(w.GetPropertyValue(col.pkey, typeof(Int64)).Value) > 128 * 1024 * 1024)
                        .ToArray();
        testgr6.Header = $"Gigantic ({testgr6.Items.Count()})";
        testgr6.Index = reversed ? j-- : j++;
        this.Groups.Add(testgr6);
      } else if (col.CollumnType == typeof(PerceivedType)) {
        var groups = this.Items.GroupBy(k => k.GetPropertyValue(col.pkey, typeof(String)).Value, e => e).OrderBy(o => o.Key);
        var i = reversed ? groups.Count() - 1 : 0;
        foreach (var group in groups.ToArray()) {
          var groupItems = group.Select(s => s).ToArray();
          this.Groups.Add(new ListViewGroupEx() { Items = groupItems, Index = reversed ? i-- : i++, Header = $"{((PerceivedType)group.Key).ToString()} ({groupItems.Count()})" });
        }
      } else {
        var groups = this.Items.GroupBy(k => k.GetPropertyValue(col.pkey, typeof(String)).Value, e => e).OrderBy(o => o.Key);
        var i = reversed ? groups.Count() - 1 : 0;
        foreach (var group in groups.ToArray()) {
          var groupItems = group.Select(s => s).ToArray();
          this.Groups.Add(new ListViewGroupEx() { Items = groupItems, Index = reversed ? i-- : i++, Header = $"{group.Key.ToString()} ({groupItems.Count()})" });
        }
      }

      if (reversed) this.Groups.Reverse();
      this.Invoke(new MethodInvoker(() => {
        this._IIListView.SetItemCount(this.Items.Count, 0x2);
      }));
      foreach (var group in this.Groups.ToArray()) {
        group.Items.ToList().ForEach(e => e.GroupIndex = group.Index);
        var nativeGroup = group.ToNativeListViewGroup();
        var insertedPosition = -1;
        this.BeginInvoke(new MethodInvoker(() => {
          this._IIListView.InsertGroup(-1, nativeGroup, out insertedPosition);
        }));
      }

      this.LastGroupCollumn = col;
      this.LastGroupOrder = reversed ? SortOrder.Descending : SortOrder.Ascending;
      this.SetSortIcon(this.Collumns.IndexOf(col), this.LastGroupOrder);
    }
Exemplo n.º 8
0
    public void SetSortCollumn(Boolean isReorder, Collumns column, SortOrder order, Boolean reverseOrder = true) {
      if (column == null) return;
      try {
        var itemsArray = this.Items;
        var selectedItems = this.SelectedItems.ToArray();
        if (column.ID == this.LastSortedColumnId && reverseOrder) {
          // Reverse the current sort direction for this column.
          this.LastSortOrder = this.LastSortOrder == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending;
        } else {
          // Set the column number that is to be sorted; default to ascending.
          this.LastSortedColumnId = column.ID;
          this.LastSortOrder = order;
        }
        if (isReorder) {
          var itemsQuery = itemsArray.Where(w => this.ShowHidden || !w.IsHidden).OrderByDescending(o => o.IsFolder);
          if (column.CollumnType != typeof(String)) {
            if (order == SortOrder.Ascending) {
              this.Items =
                              itemsQuery.ThenBy(
                                              o =>
                                                              o.GetPropertyValue(column.pkey, typeof(String)).Value ?? "1")
                                              .ToList();
            } else {
              this.Items =
                              itemsQuery.ThenByDescending(
                                              o =>
                                                              o.GetPropertyValue(column.pkey, typeof(String)).Value ?? "1")
                                              .ToList();
            }
          } else {
            if (order == SortOrder.Ascending) {
              this.Items =
                              itemsQuery.ThenBy(
                                              o =>
                                                              o.GetPropertyValue(column.pkey, typeof(String)).Value == null
                                                                              ? "1"
                                                                              : o.GetPropertyValue(column.pkey, typeof(String)).Value.ToString(), NaturalStringComparer.Default)
                                              .ToList();
            } else {
              this.Items =
                              itemsQuery.ThenByDescending(
                                              o =>
                                                              o.GetPropertyValue(column.pkey, typeof(String)).Value == null
                                                                              ? "1"
                                                                              : o.GetPropertyValue(column.pkey, typeof(String)).Value.ToString(), NaturalStringComparer.Default)
                                              .ToList();
            }
          }
          var i = 0;
          this.Items.ForEach(e => e.ItemIndex = i++);
        }
        this.BeginInvoke((Action)(() => {
          this._IIListView.SetItemCount(this.Items.Count, 0x2);
        }));

        var colIndexReal = this.Collumns.IndexOf(this.Collumns.FirstOrDefault(w => w.ID == this.LastSortedColumnId));
        if (colIndexReal > -1) {
          User32.SendMessage(this.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, colIndexReal, 0);
          this.SetSortIcon(colIndexReal, order);
        } else {
          User32.SendMessage(this.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, -1, 0);
        }

        if (!this.IsRenameInProgress) this.SelectItems(selectedItems);
      } catch {
      }
    }
Exemplo n.º 9
0
    public void SetColInView(Collumns col, Boolean remove) {
      if (remove) {
        var theColumn = this.Collumns.FirstOrDefault(s => s.pkey.fmtid == col.pkey.fmtid && s.pkey.pid == col.pkey.pid);
        if (theColumn != null) {
          var colIndex = this.Collumns.IndexOf(theColumn);
          this.Collumns.Remove(theColumn);
          User32.SendMessage(this.LVHandle, MSG.LVM_DELETECOLUMN, colIndex, 0);
          if (theColumn.ID == this.LastSortedColumnId) {
            User32.SendMessage(this.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, -1, 0);
          }
        }
      } else if (!this.Collumns.Any(s => s.pkey.fmtid == col.pkey.fmtid && s.pkey.pid == col.pkey.pid)) {
        this.Collumns.Add(col);
        var column = col.ToNativeColumn(this.View == ShellViewStyle.Details);
        var colIndex = this.Collumns.Count - 1;
        User32.SendMessage(this.LVHandle, MSG.LVM_INSERTCOLUMN, colIndex, ref column);
        if (col.ID == this.LastSortedColumnId) {
          this.SetSortIcon(colIndex, this.LastSortOrder);
          User32.SendMessage(this.LVHandle, MSG.LVM_SETSELECTEDCOLUMN, colIndex, 0);
        }
        if (this.View != ShellViewStyle.Details) {
          this.AutosizeColumn(this.Collumns.Count - 1, -2);
        }
      }

      var headerhandle = User32.SendMessage(this.LVHandle, MSG.LVM_GETHEADER, 0, 0);
      for (var i = 0; i < this.Collumns.Count; i++) {
        this.Collumns[i].SetSplitButton(headerhandle, i);
      }

		this.OnListViewCollumnsChanged?.Invoke(this, new CollumnsChangedArgs(remove));
    }