Example #1
0
    public void UpdateItem(IListItemEx obj1, IListItemEx obj2) {
      if (!obj2.IsInCurrentFolder(this.CurrentFolder) || obj2.Equals(obj1)) return;
      var items = this.Items.ToArray();
      var oldItem =
        items.SingleOrDefault(s =>
          s.Equals(obj1) ||
          (obj1.Extension.Equals(".library-ms") &&
          s.ParsingName.Equals(Path.Combine(KnownFolders.Libraries.ParsingName, Path.GetFileName(obj1.ParsingName)))));

      var theItem =
        items.FirstOrDefault(s =>
        s.ParsingName == obj2.ParsingName ||
        (obj2.Extension.Equals(".library-ms") && s.ParsingName.Equals(Path.Combine(KnownFolders.Libraries.ParsingName, Path.GetFileName(obj2.ParsingName)))));

      if (theItem == null) {
        if (oldItem != null) {
          this.Items.Remove(oldItem);
          this._AddedItems.Remove(oldItem.PIDL);
        }
        this.Items.Add(obj2.Extension.Equals(".library-ms")
            ? FileSystemListItem.InitializeWithIShellItem(this.LVHandle,
                ShellLibrary.Load(obj2.DisplayName, true).ComInterface)
            : obj2);
        var col = this.AllAvailableColumns.FirstOrDefault(w => w.Value.ID == this.LastSortedColumnId).Value;
        this.SetSortCollumn(true, col, this.LastSortOrder, false);
        if (this.IsGroupsEnabled) this.SetGroupOrder(false);
        var obj2Real =
            this.Items.FirstOrDefault(s =>
            s.ParsingName == obj2.ParsingName ||
            (obj2.Extension.Equals(".library-ms") && s.ParsingName.Equals(Path.Combine(KnownFolders.Libraries.ParsingName, Path.GetFileName(obj2.ParsingName)))));

        if (obj2Real != null) {
          this.SelectItemByIndex(obj2Real.ItemIndex, true, true);
          this.RefreshItem(obj2Real.ItemIndex, true);
        }
      } else if (oldItem == null && obj2.Extension == String.Empty) {
        //probably a temporary file
        this._TemporaryFiles.Add(obj2.ParsingName);
      }

      this.IsFocusAllowed = true;
      this.Focus();
    }
Example #2
0
 /// <summary>
 /// Inserts a new item into the control If and only If it is new. Returns the item's index OR -1 if already existing
 /// </summary>
 /// <param name="obj">The item you want to insert</param>
 /// <returns>If item is new Then returns <see cref="IListItemEx.ItemIndex">obj.ItemIndex</see> Else returns -1</returns>
 public Int32 InsertNewItem(IListItemEx obj) {
   if (!this._AddedItems.Contains(obj.PIDL) && !String.IsNullOrEmpty(obj.ParsingName) && obj.IsInCurrentFolder(this.CurrentFolder)) {
     this.Items.Add(obj);
     this._AddedItems.Add(obj.PIDL);
     var col = this.AllAvailableColumns.FirstOrDefault(w => w.Value.ID == this.LastSortedColumnId).Value;
     this.SetSortCollumn(true, col, this.LastSortOrder, false);
     if (this.IsGroupsEnabled) this.SetGroupOrder(false);
     var itemIndex = obj.ItemIndex;
     return itemIndex;
   }
   return -1;
 }