Exemple #1
0
        void lvMain_SubItemEndEditing(object sender, ListViewEx.SubItemEndEditingEventArgs e)
        {
            if (e.Cancel)
            {
                return;
            }

            try
            {
                string resultText = e.DisplayText;
                if (ei_.HasResult)
                {
                    e.DisplayText = resultText = ei_.Result;
                }

                LVInfo   lvinfo = (LVInfo)e.Item.Tag;
                LinkData lnk    = new LinkData(lvinfo.FullName, this);

                string column = GetColumnName(e.SubItem);
                if (column == COLUMN_NAME)
                {
                    try
                    {
                        string from = lvinfo.FullName;
                        string to   = Path.Combine(lvinfo.ParentDir, e.DisplayText + ".lnk");
                        System.IO.File.Move(from, to);
                        e.Item.Tag = new LVInfo(to);
                    }
                    catch (Exception ex)
                    {
                        Alert(ex.Message);
                    }
                }
                else if (column == COLUMN_PATH)
                {
                    lnk.Path = resultText;
                }
                else if (column == COLUMN_ARGUMENTS)
                {
                    lnk.Arguments = resultText;
                }
                else if (column == COLUMN_WORKINGDIRECTORY)
                {
                    lnk.WorkingDirectory = resultText;
                }
                else if (column == COLUMN_ICONPATH)
                {
                    lnk.IconPath = resultText;
                }
                else if (column == COLUMN_ICONINDEX)
                {
                    lnk.IconIndex = int.Parse(resultText);
                }
                else if (column == COLUMN_RUNASADMIN)
                {
                    lnk.IsRunAsAdmin = bool.Parse(resultText);
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            catch (Exception ex)
            {
                Alert(ex.Message);
            }

            UpdateItem(e.Item);
            e.DisplayText = e.Item.SubItems[e.SubItem].Text;
        }
Exemple #2
0
        void UpdateItem(ListViewItem item)
        {
            LVInfo info = (LVInfo)item.Tag;

            item.Text = Path.GetFileNameWithoutExtension(info.FileName);


            {
                NativeMethods.SHFILEINFO shfi = new NativeMethods.SHFILEINFO();
                IntPtr himl = NativeMethods.SHGetFileInfo(info.FullName,
                                                          128, //FileAttribute.Normal,
                                                          ref shfi,
                                                          (uint)Marshal.SizeOf(shfi),
                                                          16 | //SHGFI_USEFILEATTRIBUTES
                                                          NativeMethods.SHGFI_DISPLAYNAME |
                                                          NativeMethods.SHGFI_SYSICONINDEX |
                                                          NativeMethods.SHGFI_SMALLICON |
                                                          0
                                                          );
                Debug.Assert(himl == hSysImgList); // should be the same imagelist as the one we set
                item.ImageIndex = shfi.iIcon;
            }

            LinkData lnk = new LinkData(info.FullName, this);

            foreach (ColumnHeader ch in lvMain.Columns)
            {
                if (ch.Name == COLUMN_NAME)
                {
                    continue;
                }

                ListViewItem.ListViewSubItem sub = item.SubItems[ch.Name];
                if (sub == null)
                {
                    sub      = new ListViewItem.ListViewSubItem();
                    sub.Name = ch.Name;
                    item.SubItems.Add(sub);
                }

                if (ch.Name == COLUMN_PATH)
                {
                    sub.Text = lnk.Path;
                }
                else if (ch.Name == COLUMN_ARGUMENTS)
                {
                    sub.Text = lnk.Arguments;
                }
                else if (ch.Name == COLUMN_WORKINGDIRECTORY)
                {
                    sub.Text = lnk.WorkingDirectory;
                }
                else if (ch.Name == COLUMN_ICONPATH)
                {
                    sub.Text = lnk.IconPath;
                }
                else if (ch.Name == COLUMN_ICONINDEX)
                {
                    sub.Text = lnk.IconIndex.ToString();
                }
                else if (ch.Name == COLUMN_RUNASADMIN)
                {
                    sub.Text = lnk.IsRunAsAdmin.ToString();
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            //if(lvMain.Items.Count!=0)
            //    lvMain.RedrawItems(0, lvMain.Items.Count-1, false);
        }