Exemplo n.º 1
0
        private void AddNewItem(CrumbBarItem parent)
        {
            IDesignerHost dh = (IDesignerHost)GetDesignService(typeof(IDesignerHost));
            DesignerTransaction dt = null;
            if (dh != null)
            {
                dt = dh.CreateTransaction("New CrumbBarItem");
            }
            bool isEmpty = advTree1.Nodes.Count == 0;
            CrumbBarItem item = CreateItem();
            if (item == null) return;

            IComponentChangeService cc = GetDesignService(typeof(IComponentChangeService)) as IComponentChangeService;
            if (cc != null)
            {
                if (parent == null)
                    cc.OnComponentChanging(_CrumbBar, TypeDescriptor.GetProperties(_CrumbBar)["Items"]);
                else
                    cc.OnComponentChanging(parent, TypeDescriptor.GetProperties(parent)["SubItems"]);
            }

            if (parent == null)
                _CrumbBar.Items.Add(item);
            else
                parent.SubItems.Add(item);

            if (cc != null)
            {
                if (parent == null)
                    cc.OnComponentChanged(_CrumbBar, TypeDescriptor.GetProperties(_CrumbBar)["Items"], null, null);
                else
                    cc.OnComponentChanged(parent, TypeDescriptor.GetProperties(parent)["SubItems"], null, null);
            }

            if (dt != null)
                dt.Commit();

            if (parent == null)
                advTree1.Nodes.Add(CreateNodeForItem(item));
            else
            {
                advTree1.SelectedNode.Nodes.Add(CreateNodeForItem(item));
                advTree1.SelectedNode.Expand();
            }

            if (isEmpty && advTree1.SelectedNode == null && advTree1.Nodes.Count > 0)
                advTree1.SelectedNode = advTree1.Nodes[0];
        }
 /// <summary>
 /// Inserts new object into the collection.
 /// </summary>
 /// <param name="index">Position of the object.</param>
 /// <param name="value">Object to insert.</param>
 public void Insert(int index, CrumbBarItem value)
 {
     List.Insert(index, value);
 }
 /// <summary>
 /// Returns index of the object inside of the collection.
 /// </summary>
 /// <param name="value">Reference to the object.</param>
 /// <returns>Index of the object.</returns>
 public int IndexOf(CrumbBarItem value)
 {
     return List.IndexOf(value);
 }
Exemplo n.º 4
0
 internal static object CreateViewForItem(CrumbBarItem item)
 {
     CrumbBarItemView view = new CrumbBarItemView();
     view.AttachedItem = item;
     return view;
 }
 /// <summary>
 /// Adds new object to the collection.
 /// </summary>
 /// <param name="ch">Object to add.</param>
 /// <returns>Index of newly added object.</returns>
 public int Add(CrumbBarItem ch)
 {
     return List.Add(ch);
 }
Exemplo n.º 6
0
 private void DeleteItem(CrumbBarItem item)
 {
     IDesignerHost dh = (IDesignerHost)GetDesignService(typeof(IDesignerHost));
     if (dh == null)
         return;
     dh.DestroyComponent(item);
 }
Exemplo n.º 7
0
 private void loadin(CrumbBarItem parent)
 {
     //MessageBox.Show(croldpath.ToString() + '\n' + crpaths + '\n' + l+'\n'+nowx);
     //ToastNotification.Show(this, croldpath.ToString() + '\n' + crpaths + '\n' + l + '\n' + nowx, 5000);
     //MessageBox.Show("Test1");
     // Load folders are selection changes...
     //if (parent == null || parent.SubItems.Count > 0){
     //    MessageBox.Show("out"); return;}
     DirectoryInfo dirInfo = null;
     if (parent.Tag is DriveInfo)
     {
         DriveInfo driveInfo = (DriveInfo) parent.Tag;
         dirInfo = driveInfo.RootDirectory;
     }
     else if (parent.Tag is DirectoryInfo)
     {
         dirInfo = (DirectoryInfo) parent.Tag;
     }
     else
     {
         return;
     }
     parent.SubItems.Clear();
     DirectoryInfo[] subDirectories = dirInfo.GetDirectories();
     string lsfilename;
     if(nowx>3 && nowx<l-1)
         crpaths += '\\';
     for (i = nowx; i < l; ++i)
     {
         if (i == l - 1)
         {
             crpaths += croldpath[i];
             break;
         }
         else if (croldpath[i] == '\\')
             break;
         crpaths += croldpath[i];
     }
     nowx = i + 1;
     lsfilename = Path.GetFileName(crpaths);
     parent.ShowSubItems = true;
     foreach (DirectoryInfo directoryInfo in subDirectories)
     {
         CrumbBarItem node = new CrumbBarItem();
         node.Tag = directoryInfo;
         node.Text = directoryInfo.Name;
         node.Image = Properties.Resources.folderp;
         parent.SubItems.Add(node);
         if (node.Text == lsfilename)
         {
             if (nowx >= l - 1)
             {
                 Gib.nowcrst = 1;
                 fpcrumb.SelectedItem = node;
                 break;
             }
             loadin(node);
         }
     }
     if (l == 3 && parent.Text.Length == 3)
     {
         Gib.nowcrst = 1;
         fpcrumb.SelectedItem = parent;
     }
 }
Exemplo n.º 8
0
 internal void OnItemsCleared()
 {
     this.SelectedItem = null;
 }
 /// <summary>
 /// Returns whether collection contains specified object.
 /// </summary>
 /// <param name="value">Object to look for.</param>
 /// <returns>true if object is part of the collection, otherwise false.</returns>
 public bool Contains(CrumbBarItem value)
 {
     return List.Contains(value);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Gets whether an item is in selected path to the currently selected item as either one of the parents of selected item
 /// or selected item itself.
 /// </summary>
 /// <param name="item">Item to test.</param>
 /// <returns>true if item is in selected path otherwise false.</returns>
 public bool GetIsInSelectedPath(CrumbBarItem item)
 {
     for (int i = 2; i < _ViewContainer.SubItems.Count; i++)
     {
         CrumbBarItemView view = _ViewContainer.SubItems[i] as CrumbBarItemView;
         if (view != null && view.AttachedItem == item) return true;
     }
     return false;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the CrumbBarSelectionEventArgs class.
 /// </summary>
 /// <param name="newSelectedItem"></param>
 public CrumbBarSelectionEventArgs(CrumbBarItem newSelectedItem)
 {
     NewSelectedItem = newSelectedItem;
 }
Exemplo n.º 12
0
 private object GetItemView(CrumbBarItem current, bool canCreateNewView)
 {
     for (int i = 2; i < _ViewContainer.SubItems.Count; i++)
     {
         CrumbBarItemView view = _ViewContainer.SubItems[i] as CrumbBarItemView;
         if (view != null && view.AttachedItem == current) return view;
     }
     if(canCreateNewView)
         return CrumbBarItemView.CreateViewForItem(current);
     return null;
 }
Exemplo n.º 13
0
        private void UpdateSelectedItemImage(CrumbBarItem selection)
        {
            if (selection == null)
            {
                _ViewContainer.ImageLabel.Visible = false;
                return;
            }

            CompositeImage image = selection.GetImage();
            if (image != null)
            {
                _ViewContainer.ImageLabel.Visible = true;
                if (image.IsIcon)
                    _ViewContainer.ImageLabel.Icon = image.Icon;
                else
                    _ViewContainer.ImageLabel.Image = image.Image;
            }
            else
            {
                _ViewContainer.ImageLabel.Visible = false;
            }            
        }
Exemplo n.º 14
0
        /// <summary>
        /// Sets the currently selected item in the control.
        /// </summary>
        /// <param name="selection">Reference to selected item.</param>
        /// <param name="source">Source of the event.</param>
        public void SetSelectedItem(CrumbBarItem selection, eEventSource source)
        {
            bool raiseChangedEvents = selection != _SelectedItem;

            if (raiseChangedEvents)
            {
                CrumbBarSelectionEventArgs eventArgs = new CrumbBarSelectionEventArgs(selection);
                OnSelectedItemChanging(eventArgs);
                if (eventArgs.Cancel) return;
                selection = eventArgs.NewSelectedItem;
            }

            if (_SelectedItem != null)
                _SelectedItem.IsSelected = false;

            ArrayList newItems = new ArrayList();
            if (selection == null)
                selection = GetFirstVisibleItem();
            _ViewContainer.Expanded = false; // closes any open popups
            _ViewContainer.RestoreOverflowItems();

            if (selection != null)
            {
                CrumbBarItem current = selection;
                while (current != null)
                {
                    newItems.Insert(0, GetItemView(current, true));
                    current = current.Parent as CrumbBarItem;
                }

                UpdateSelectedItemImage(selection);
            }
            else
                UpdateSelectedItemImage(null);

            // Remove current view items
            _ViewContainer.ClearViewItems();
            if (selection != null)
            {
                _ViewContainer.SubItems.AddRange((BaseItem[])newItems.ToArray(typeof(BaseItem)));
            }
            _ViewContainer.NeedRecalcSize = true;

            _SelectedItem = selection;
            if (_SelectedItem != null)
                _SelectedItem.IsSelected = true;

            this.RecalcLayout();

            if (raiseChangedEvents)
            {
                CrumbBarSelectionEventArgs eventArgs = new CrumbBarSelectionEventArgs(selection);
                OnSelectedItemChanged(eventArgs);
            }
        }
Exemplo n.º 15
0
 private void LoadSubItems(Node parent, CrumbBarItem item)
 {
     foreach (BaseItem o in item.SubItems)
     {
         if (o is CrumbBarItem)
         {
             CrumbBarItem cb = (CrumbBarItem)o;
             Node node = CreateNodeForItem(cb);
             parent.Nodes.Add(node);
             LoadSubItems(node, cb);
         }
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Removes specified object from the collection.
 /// </summary>
 /// <param name="value"></param>
 public void Remove(CrumbBarItem value)
 {
     List.Remove(value);
 }
Exemplo n.º 17
0
 private Node CreateNodeForItem(CrumbBarItem item)
 {
     Node node = new Node();
     node.Expanded = true;
     node.Tag = item;
     node.Text = item.Text;
     node.Image = item.GetItemImage();
     node.Cells.Add(new Cell(item.Name));
     return node;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Copies collection into the specified array.
 /// </summary>
 /// <param name="array">Array to copy collection to.</param>
 /// <param name="index">Starting index.</param>
 public void CopyTo(CrumbBarItem[] array, int index)
 {
     List.CopyTo(array, index);
 }
Exemplo n.º 19
0
        private void fpcrumb_SelectedItemChanging(object sender, CrumbBarSelectionEventArgs e)
        {
            //MessageBox.Show(Gib.nowcrst.ToString());
            //ToastNotification.Show(this, Gib.nowcrst.ToString());
            if (Gib.nowcrst == 0)
            {
                //ToastNotification.Show(this, "fpcrumb_SelectedItemChanging" + e.ToString(), 5000);
                //MessageBox.Show("Test1");
                // Load folders are selection changes...
                CrumbBarItem parent = e.NewSelectedItem;
                //if (parent == null || parent.SubItems.Count > 0){
                //    MessageBox.Show("out"); return;}
                for(i=0;i<26;++i)
                    if (parent.Text == ((char)( i + 'A')).ToString()+":\\")
                    {
                        Gib.nowcrst = 1;
                        parent.SubItems.Clear();
                        break;
                    }

                DirectoryInfo dirInfo = null;
                if (parent.Tag is DriveInfo)
                {
                    DriveInfo driveInfo = (DriveInfo) parent.Tag;
                    dirInfo = driveInfo.RootDirectory;
                }
                else if (parent.Tag is DirectoryInfo)
                {
                    dirInfo = (DirectoryInfo) parent.Tag;
                }
                else
                {
                    return;
                }
                DirectoryInfo[] subDirectories = dirInfo.GetDirectories();
                foreach (DirectoryInfo directoryInfo in subDirectories)
                {
                    CrumbBarItem node = new CrumbBarItem();
                    node.Tag = directoryInfo;
                    node.Text = directoryInfo.Name;
                    node.Image = Properties.Resources.folderp;
                    parent.SubItems.Add(node);
                }
                Gib.fpos[Gib.nowtab, ++Gib.nowp[Gib.nowtab]] = dirInfo.FullName;
                Gib.maxn[Gib.nowtab] = Gib.maxn[Gib.nowtab] > Gib.nowp[Gib.nowtab]
                    ? Gib.maxn[Gib.nowtab]
                    : Gib.nowp[Gib.nowtab];
                filepath.Text = Gib.fpos[Gib.nowtab, Gib.nowp[Gib.nowtab]];
                reffile(Gib.fpos[Gib.nowtab, Gib.nowp[Gib.nowtab]], Gib.smode);
            }
            else
                Gib.nowcrst = 0;
        }
Exemplo n.º 20
0
 /// <summary>
 /// Copies contained items to the CrumbBarItem array.
 /// </summary>
 /// <param name="array">Array to copy to.</param>
 internal void CopyTo(CrumbBarItem[] array)
 {
     List.CopyTo(array, 0);
 }
Exemplo n.º 21
0
        public void reffile(string repath, int mode)
        {
            if (Directory.Exists(repath) == false)
            {
                if (repath != "")
                    MessageBox.Show("路径不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int i, j, k, progs;
            //Gib.fpos[Gib.nowtab, Gib.nowp[Gib.nowtab] + 1] = "";
            filepath.Text = repath;

            l = repath.Length;
            croldpath = repath.ToCharArray();

            crpaths = croldpath[0].ToString() + croldpath[1] + croldpath[2];
            //crpathc[3] = '\0';

            CrumbBarItem myComputer = new CrumbBarItem();
            myComputer.Text = "计算机";
            myComputer.Image = Properties.Resources.computer;
            fpcrumb.Items.Add(myComputer);
            // Load disks, we will lazy load folders are disk are selected
            nowx = 3;

            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo driveInfo in drives)
            {
                if (driveInfo.DriveType != DriveType.Fixed) continue;
                CrumbBarItem node = new CrumbBarItem();
                node.Tag = driveInfo;
                node.Text = driveInfo.Name;
                node.Image = Properties.Resources.hdd;
                myComputer.SubItems.Add(node);
                if (node.Text == Path.GetPathRoot(repath))
                    loadin(node);
            }
            // Finally select My Computer
            Gib.nowcrst = 0;

            //fileprog.IsRunning = true;
            //ToggleEndlessProgress.Execute();
            nowstate.Text = "正在载入...";
            Gib.cname = new string[100000];
            Gib.cpath = new string[100000];
            Gib.clast = new string[100000];
            Gib.cmode = new int[100000];//1:file  2:folder
            //FrmMain frm = (FrmMain)this.Owner;
            if (Gib.nowtab == 1) filev1.Items.Clear();
            else if (Gib.nowtab == 2) filev2.Items.Clear();
            else filev3.Items.Clear();
            File.WriteAllText("C:\\ProgramData\\CW Soft\\CW File Viewer\\TempPath.txt", repath);
            Gib.fsum = 0;
            DirectoryInfo dinfo = new DirectoryInfo(repath);
            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            progs = fsinfos.Length;

            if (progs == 0)
                progs = 1;
            nowprog.Maximum = progs;

            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                //++fileprog.Value;
                if (fsinfo is DirectoryInfo)
                {
                    DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                    ++Gib.fsum;
                    Gib.cname[Gib.fsum] = dirinfo.Name;
                    Gib.cpath[Gib.fsum] = repath;
                    if (Gib.cpath[Gib.fsum].Length > 3)
                        Gib.cpath[Gib.fsum] = Gib.cpath[Gib.fsum] + '\\';
                    Gib.clast[Gib.fsum] = "";
                    Gib.cpath[Gib.fsum] = Gib.cpath[Gib.fsum] + Gib.cname[Gib.fsum];
                    Gib.cmode[Gib.fsum] = 2;
                }
                else if (onlyfolder.Checked == false)
                {
                    //使用获取的文件名称实例化FileInfo对象
                    FileInfo finfo = new FileInfo(fsinfo.FullName);
                    ++Gib.fsum;
                    Gib.cname[Gib.fsum] = fsinfo.Name;
                    Gib.cpath[Gib.fsum] = repath;
                    if (Gib.cpath[Gib.fsum].Length > 3)
                        Gib.cpath[Gib.fsum] = Gib.cpath[Gib.fsum] + '\\';
                    Gib.cpath[Gib.fsum] = Gib.cpath[Gib.fsum] + Gib.cname[Gib.fsum];
                    Gib.clast[Gib.fsum] = Path.GetExtension(Gib.cpath[Gib.fsum]);
                    Gib.cmode[Gib.fsum] = 1;
                }
                nowprog.Value = Gib.fsum;
            }
            string lins;
            int ils;
            if (Gib.nowtab == 1) filev1.Columns[0].Text = "共" + Gib.fsum.ToString() + "个对象";
            else if (Gib.nowtab == 2) filev2.Columns[0].Text = "共" + Gib.fsum.ToString() + "个对象";
            else filev3.Columns[0].Text = "共" + Gib.fsum.ToString() + "个对象";
            nowstate.Text = "正在排序...";
            if (mode == 1)
            {
                if (goodsort.Checked == true)
                {
                    Gib.cname[0] = "";
                    for (i = 1; i < Gib.fsum; ++i)
                    {
                        k = i-1;
                        for (j = i; j <= Gib.fsum; ++j)
                            if (goodcmp(Gib.cname[j], Gib.cname[k]))
                                k = j;
                        if (k != i-1)
                        {
                            lins = Gib.cname[i - 1];
                            Gib.cname[i - 1] = Gib.cname[k];
                            Gib.cname[k] = lins;

                            lins = Gib.cpath[i - 1];
                            Gib.cpath[i - 1] = Gib.cpath[k];
                            Gib.cpath[k] = lins;

                            lins = Gib.clast[i - 1];
                            Gib.clast[i - 1] = Gib.clast[k];
                            Gib.clast[k] = lins;

                            ils = Gib.cmode[i - 1];
                            Gib.cmode[i - 1] = Gib.cmode[k];
                            Gib.cmode[k] = ils;
                        }
                    }
                    if (goodcmp(Gib.cname[Gib.fsum], Gib.cname[Gib.fsum - 1]))
                    {
                        lins = Gib.cname[Gib.fsum - 1];
                        Gib.cname[Gib.fsum - 1] = Gib.cname[Gib.fsum];
                        Gib.cname[Gib.fsum] = lins;

                        lins = Gib.cpath[Gib.fsum - 1];
                        Gib.cpath[Gib.fsum - 1] = Gib.cpath[Gib.fsum];
                        Gib.cpath[Gib.fsum] = lins;

                        lins = Gib.clast[Gib.fsum - 1];
                        Gib.clast[Gib.fsum - 1] = Gib.clast[Gib.fsum];
                        Gib.clast[Gib.fsum] = lins;

                        ils = Gib.cmode[Gib.fsum - 1];
                        Gib.cmode[Gib.fsum - 1] = Gib.cmode[Gib.fsum];
                        Gib.cmode[Gib.fsum] = ils;
                    }
                }
                else
                {
                    for (i = 1; i < Gib.fsum; ++i)
                    {
                        k = i - 1;
                        for (j = i; j <= Gib.fsum; ++j)
                            if (String.Compare(Gib.cname[j], Gib.cname[k]) < 0)
                                k = j;
                        if (k != i - 1)
                        {
                            lins = Gib.cname[i - 1];
                            Gib.cname[i - 1] = Gib.cname[k];
                            Gib.cname[k] = lins;

                            lins = Gib.cpath[i - 1];
                            Gib.cpath[i - 1] = Gib.cpath[k];
                            Gib.cpath[k] = lins;

                            lins = Gib.clast[i - 1];
                            Gib.clast[i - 1] = Gib.clast[k];
                            Gib.clast[k] = lins;

                            ils = Gib.cmode[i - 1];
                            Gib.cmode[i - 1] = Gib.cmode[k];
                            Gib.cmode[k] = ils;
                        }
                    }
                }
            }
            else if (mode == 2)
            {
                for (i = 1; i < Gib.fsum; ++i)
                {
                    k = i - 1;
                    for (j = i; j <= Gib.fsum; ++j)
                        if (String.Compare(Gib.clast[j], Gib.clast[k]) < 0)
                            k = j;
                    if (k != i - 1)
                    {
                        lins = Gib.cname[i - 1];
                        Gib.cname[i - 1] = Gib.cname[k];
                        Gib.cname[k] = lins;

                        lins = Gib.cpath[i - 1];
                        Gib.cpath[i - 1] = Gib.cpath[k];
                        Gib.cpath[k] = lins;

                        lins = Gib.clast[i - 1];
                        Gib.clast[i - 1] = Gib.clast[k];
                        Gib.clast[k] = lins;

                        ils = Gib.cmode[i - 1];
                        Gib.cmode[i - 1] = Gib.cmode[k];
                        Gib.cmode[k] = ils;
                    }
                }
            }

            //listView1.Items.Add("temp.txt", FileIconIndex(@"c:/temp/temp.txt"));
            if (Gib.nowtab == 1) imageList1.Images.Clear();
            else if (Gib.nowtab == 2) imageList2.Images.Clear();
            else imageList3.Images.Clear();

            nowstate.Text = "正在更新列表...";

            if (repath != "C:\\" && repath != "D:\\" && repath != "E:\\" && repath != "F:\\")
                tablsname = Path.GetFileName(repath);
            else
                tablsname = repath;

            putinfilev();

            nowstate.Text = "完成";
            nowprog.Value = progs;

            try
            {
                if (Gib.lpos[Gib.nowtab, Gib.nowp[Gib.nowtab]] > 0 &&
                    Gib.lpos[Gib.nowtab, Gib.nowp[Gib.nowtab]] <= Gib.fsum)
                {
                    if (Gib.nowtab == 1) filev1.Items[Gib.lpos[Gib.nowtab, Gib.nowp[Gib.nowtab]]].EnsureVisible();
                    else if (Gib.nowtab == 2) filev2.Items[Gib.lpos[Gib.nowtab, Gib.nowp[Gib.nowtab]]].EnsureVisible();
                    else filev3.Items[Gib.lpos[Gib.nowtab, Gib.nowp[Gib.nowtab]]].EnsureVisible();
                }
            }
            catch{ }
        }
Exemplo n.º 22
0
        void refcrb(string repath)
        {
            l = repath.Length;
            croldpath = repath.ToCharArray();

            crpaths = croldpath[0].ToString() + croldpath[1] + croldpath[2];

            CrumbBarItem myComputer = new CrumbBarItem();
            myComputer.Text = "";
            myComputer.Image = Properties.Resources.computer;
            fpcrumb.Items.Add(myComputer);
            // Load disks, we will lazy load folders are disk are selected
            nowx = 3;

            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo driveInfo in drives)
            {
                if (driveInfo.DriveType != DriveType.Fixed) continue;
                CrumbBarItem node = new CrumbBarItem();
                node.Tag = driveInfo;
                node.Text = driveInfo.Name;
                node.Image = Properties.Resources.hdd;
                myComputer.SubItems.Add(node);
                if (node.Text == Path.GetPathRoot(repath))
                    loadin(node);
            }
            // Finally select My Computer
            Gib.nowcrst = 0;
        }