Ejemplo n.º 1
0
        void ReloadFiles()
        {
            QueryResult res = Database.QuickQuery("SELECT rowid,* FROM files where rowid>" + lastrowid, Root.Connection);

            foreach (object[] obj in res.Rows)
            {
                lastrowid = (long)obj[0];

                string   file = (string)obj[1];
                string[] tags = ((string)obj[2]).Split(',');

                StringBuilder sb    = new StringBuilder();
                bool          first = true;
                foreach (string tag in tags)
                {
                    foreach (Tag t in Tags)
                    {
                        if (t.ID.ToString() == tag)
                        {
                            sb.Append((first ? "" : ", ") + t.Name);
                            first = false;
                        }
                    }
                }

                FileAttributes attr = File.GetAttributes(file);

                ListViewItemGradient lvi = new ListViewItemGradient(Path.GetFileName(file))
                {
                    BackColor = Color.White
                };
                lvi.SubItems.Add(Path.GetDirectoryName(file));
                lvi.SubItems.Add(sb.ToString());
                lvi.SubItems.Add(((long)obj[0]).ToString());
                lvi.ImageIndexExt = ((attr & FileAttributes.Directory) == FileAttributes.Directory ? 0 : GetIcon(file));
                list.Items.Add(lvi);
            }
            Root.Log("Loaded " + res.Returned + " new files");
        }
Ejemplo n.º 2
0
        void OpenRunFile(ListViewItemGradient i)
        {
            string s   = i.SubItems[1].Text + Root.PathDelimiter + i.SubItems[0].Text;
            bool   exe = i.ImageIndexExt == Root.ICON_EXE;

            if (!File.Exists(s))
            {
                return;
            }

            if (exe && MessageBox.Show("Are you sure you want to execute this file?\n\nExecutables can damage your computer, make sure to only run files from sources you trust.", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }

            Process proc = null;

            try
            {
                proc = new Process();
                proc.StartInfo.FileName = s;
                if (exe)
                {
                    proc.Exited       += delegate { i.VirtualBackColor = Color.White; };
                    i.VirtualBackColor = ListViewExtended.cInuse;
                }
                proc.EnableRaisingEvents = true;
                proc.Start();
                list.SelectedItems.Clear();
            }
            catch (Win32Exception)
            {
                proc.Dispose();
                MessageBox.Show("There is no default program setup to open this type of file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        private void list_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool hasitems = list.SelectedIndices.Count > 0;
            bool hasone   = list.SelectedIndices.Count == 1;

            menuEditEdit.Enabled   = menuEditEngrave.Enabled = cmsEdit.Enabled = cmsEngrave.Enabled = cmsOpen.Enabled = cmsOpendir.Enabled = hasone;
            menuEditRemove.Enabled = cmsRemove.Enabled = hasitems;

            if (hasone)
            {
                ListViewItemGradient i = (ListViewItemGradient)list.SelectedItems[0];

                if (i.ImageIndexExt == 4)
                {
                    cmsOpen.Text  = "Execute";
                    cmsOpen.Image = Properties.Resources.application_xp_terminal;
                }
                else
                {
                    cmsOpen.Text  = "Open";
                    cmsOpen.Image = null;
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnDrawItem(DrawListViewItemEventArgs e)
        {
            int MID = 0;

            if (ExtType == ListViewExtendedType.Normal)
            {
                e.DrawDefault = true;
            }
            else if (ExtType == ListViewExtendedType.Clean)
            {
                Color bg;
                if (e.Item.Selected)
                {
                    bg = cSelected; ((ListViewItemGradient)e.Item).Focus = true;
                }
                else
                {
                    bg = e.Item.BackColor;
                }
                ListViewItemGradient lvig = (ListViewItemGradient)e.Item;
                if (lvig.Processed == false)
                {
                    short r = (short)(bg.R + Math.Round((255 - bg.R) * MOD_GRADIENT));
                    short g = (short)(bg.G + Math.Round((255 - bg.G) * MOD_GRADIENT));
                    short b = (short)(bg.B + Math.Round((255 - bg.B) * MOD_GRADIENT));

                    if (r > 255)
                    {
                        r = 255;
                    }
                    if (g > 255)
                    {
                        g = 255;
                    }
                    if (b > 255)
                    {
                        b = 255;
                    }
                    lvig.Gradient  = new LinearGradientBrush(e.Bounds.Location, new Point(0, e.Bounds.Bottom), Color.FromArgb(r, g, b), bg);
                    lvig.Processed = true;

                    if (bg == Color.White)
                    {
                        lvig.Extreme = new Pen(Color.White);
                    }
                    else
                    {
                        r = (short)(bg.R - Math.Round(bg.R * MOD));
                        g = (short)(bg.G - Math.Round(bg.G * MOD));
                        b = (short)(bg.B - Math.Round(bg.B * MOD));
                        if (r < 0)
                        {
                            r = 0;
                        }
                        if (g < 0)
                        {
                            g = 0;
                        }
                        if (b < 0)
                        {
                            b = 0;
                        }
                        lvig.Extreme = new Pen(Color.FromArgb(r, g, b));
                    }
                }

                if (!GridLines)
                {
                    /* Draw background */
                    e.Graphics.FillRectangle(lvig.Gradient, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2));
                    /* Top */
                    e.Graphics.DrawLine(lvig.Extreme, e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Y);
                    /* Bottom */
                    e.Graphics.DrawLine(lvig.Extreme, e.Bounds.X + 1, e.Bounds.Bottom - 1, e.Bounds.Width - 2, e.Bounds.Bottom - 1);
                    /* Left */
                    e.Graphics.DrawLine(lvig.Extreme, e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X, e.Bounds.Bottom - 2);
                    /* Right */
                    e.Graphics.DrawLine(lvig.Extreme, e.Bounds.Right - 1, e.Bounds.Y + 1, e.Bounds.Right - 1, e.Bounds.Bottom - 2);
                }
                else
                {
                    /* Draw background */
                    e.Graphics.FillRectangle(lvig.Gradient, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2));
                    /* Top */
                    e.Graphics.DrawLine(lvig.Extreme, e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Y);
                    /* Bottom */
                    e.Graphics.DrawLine(lvig.Extreme, e.Bounds.X + 1, e.Bounds.Bottom - 2, e.Bounds.Width - 2, e.Bounds.Bottom - 2);
                    /* Left */
                    e.Graphics.DrawLine(lvig.Extreme, e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X, e.Bounds.Bottom - 3);
                    /* Right */
                    e.Graphics.DrawLine(lvig.Extreme, e.Bounds.Right - 1, e.Bounds.Y + 1, e.Bounds.Right - 1, e.Bounds.Bottom - 3);
                }

                if (!SingleColumn && bg == Color.White)
                {
                    e.Graphics.FillRectangle(SystemBrushes.MenuBar, new Rectangle(e.Bounds.X, e.Bounds.Y, Columns[0].Width - 1, e.Bounds.Height));
                }

                int offsetx = 0;
                for (int i = 0; i < Columns.Count && i < e.Item.SubItems.Count; i++)
                {
                    if (i > 0)
                    {
                        offsetx += this.Columns[i - 1].Width;
                    }
                    int x = e.Bounds.X + 3 + offsetx;
                    if (MID == 0f)
                    {
                        MID = (int)Math.Round((e.Bounds.Height / 2f) - (iFont.GetHeight() / 2f));
                    }
                    int y = e.Bounds.Y + MID - (GridLines ? 5 : 4);

                    if (i == 0 && ImageListExt.Count > 0 && ((ListViewItemGradient)e.Item).ImageIndexExt >= 0 && ((ListViewItemGradient)e.Item).ImageIndexExt < ImageListExt.Count)
                    {
                        e.Graphics.DrawImage(ImageListExt[((ListViewItemGradient)e.Item).ImageIndexExt], x, e.Bounds.Y + 2);
                        TextRenderer.DrawText(e.Graphics, e.Item.SubItems[i].Text, iFont, new Rectangle(x + 18, y, Columns[i].Width - 20, e.Bounds.Height), Color.Black, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
                    }
                    else
                    {
                        TextRenderer.DrawText(e.Graphics, e.Item.SubItems[i].Text, iFont, new Rectangle(x, y, Columns[i].Width, e.Bounds.Height), Color.Black, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
                    }
                }
            }
            base.OnDrawItem(e);
        }