Ejemplo n.º 1
0
        // Add items based on folder's items.
        // Also change center icon to folder's icon.
        public void SwitchToFolder(PieFolderItem folder)
        {
            ClearItems();

            CurrentFolder = folder;

            // Create display info
            for (int i = 0; i < folder.Items.Count; i++)
            {
                CreateDisplayInfo(folder.Items[i], i, folder.Items.Count);
            }

            // Create all buttons first and THEN labels, so labels are always on top.
            foreach (ItemDisplayInfo info in ItemDisplayInfos)
            {
                mainGrid.Children.Add(info.ItemButton);
            }

            foreach (ItemDisplayInfo info in ItemDisplayInfos)
            {
                mainGrid.Children.Add(info.ItemLabel);
            }

            // Change center icon
            InnerDisk.Source = folder.Icon.ImageBitmapSource;
        }
Ejemplo n.º 2
0
        public override void LoadConfig(XmlElement element)
        {
            base.LoadConfig(element);

            foreach (var itemElementAsXmlNode in element.ChildNodes)
            {
                // TODO: I hope this never fails. Maybe check ahead of time?
                XmlElement itemElement = (XmlElement)itemElementAsXmlNode;

                PieItem subItem = null;

                // Fill with default values
                // The rest of the values will be filled in after calling LoadConfig() on this.
                switch (itemElement.Name)
                {
                case PieFolderItem.TYPE_NAME:
                    // (except we need to fill with prevFolder now)
                    subItem = new PieFolderItem(false, null, false, null, this);
                    break;

                case FileItem.TYPE_NAME:
                    subItem = new FileItem(false, null, false, null, null, null, FileItemType.File);
                    break;

                default:     // This should NEVER happen.
                             // TODO: Add error message if it does?
                    break;
                }

                // This should NEVER be null afterwards.
                subItem.LoadConfig(itemElement);
                Items.Add(subItem);
            }
        }
Ejemplo n.º 3
0
        public static void SaveItems(PieFolderItem root)
        {
            XmlDocument config   = new XmlDocument();
            XmlElement  rootNode = config.CreateElement("Root");

            config.AppendChild(rootNode);

            root.SaveConfig(config.DocumentElement);

            config.Save(ItemSaveLocation);
        }
Ejemplo n.º 4
0
 // Refresh the "file not found" icons.
 // TODO: This is inefficient. Will refresh if not using a custom icon
 //       but successfully loaded an icon from the file.
 // TODO: This is also awful. Much better to be rid of the Copy() portion used somewhere
 //       and just directly pointed to Config.FileNotFoundIcon.
 public void ClearCachedImagesFileNotFound(PieFolderItem folder, string oldPath, string newPath)
 {
     foreach (PieItem item in folder.Items)
     {
         if (item is FileItem && !item.IsCustomIcon && item.Icon.ImagePath == oldPath)
         {
             item.Icon.ClearCache();
             item.Icon.ImagePath = newPath;
         }
         else if (item is PieFolderItem)
         {
             ClearCachedImagesFileNotFound((PieFolderItem)item, oldPath, newPath);
         }
     }
 }
Ejemplo n.º 5
0
        public static PieFolderItem LoadItems()
        {
            XmlDocument   config     = new XmlDocument();
            PieFolderItem rootFolder = new PieFolderItem(false, null, true, InnerDiskImagePath, null);

            try
            {
                config.Load(ItemSaveLocation);
                rootFolder.LoadConfig(config.DocumentElement);
            }
            catch (Exception e) // TODO: You know, I should really handle this stuff better.
            {
            }

            return(rootFolder);
        }
Ejemplo n.º 6
0
        // TODO: Similar here.
        public void ClearCachedImagesDefaultFolder(PieFolderItem folder, string oldPath, string newPath)
        {
            if (!folder.IsCustomIcon && folder.Icon.ImagePath == oldPath)
            {
                folder.Icon.ClearCache();
                folder.Icon.ImagePath = newPath;
            }

            foreach (PieItem item in folder.Items)
            {
                if (item is PieFolderItem)
                {
                    ClearCachedImagesDefaultFolder((PieFolderItem)item, oldPath, newPath);
                }
            }
        }
Ejemplo n.º 7
0
        // Preload the icons for speed
        public void PreloadIconsRecursive(PieFolderItem folder)
        {
            // Force each icon to load (at least) once.
            // Preloading is handled in the IconAsBitmapSource property.
            //
            // No need to worry about "preloading twice".
            // The second time, it has already been preloaded.
            BitmapSource temp;

            folder.Icon.CreateCache();

            foreach (PieItem item in folder.Items)
            {
                item.Icon.CreateCache();
            }

            foreach (PieItem item in folder.Items)
            {
                if (item is PieFolderItem)
                {
                    PreloadIconsRecursive((PieFolderItem)item);
                }
            }
        }
        /*
         * containingFolder is the folder that contains this PieItem.
         */
        public PieItemSettingsWindow(PieItem item, PieFolderItem containingFolder) : this()
        {
            OldPieItem       = item;
            NewPieItem       = item; // TODO: Feels mildly clunky. Rewrite?
            ContainingFolder = containingFolder;
            Saved            = false;

            if (item.IsCustomName)
            {
                textBoxName.Text       = (item.Name == null) ? "" : item.Name;
                checkBoxName.IsChecked = true;
                checkBoxName_Checked(null, null);
            }
            else
            {
                checkBoxName.IsChecked = false;
                checkBoxName_Unchecked(null, null);
            }

            if (item.IsCustomIcon)
            {
                textBoxIcon.Text       = (item.Icon.ImagePath == null) ? "" : item.Icon.ImagePath;
                checkBoxIcon.IsChecked = true;
                checkBoxIcon_Checked(null, null);
            }
            else
            {
                checkBoxIcon.IsChecked = false;
                checkBoxIcon_Unchecked(null, null);
            }

            // Type-specific configuration.
            if (item is PieFolderItem)
            {
                radioButtonPieFolder.IsChecked = true;
                radioButtonPieFolder_Checked(null, null);
            }
            else if (item is FileItem)
            {
                switch (((FileItem)item).Type)
                {
                case FileItemType.File:
                    radioButtonFile.IsChecked = true;
                    radioButtonFile_Checked(null, null);
                    break;

                case FileItemType.Folder:
                    radioButtonFolder.IsChecked = true;
                    radioButtonFolder_Checked(null, null);
                    break;

                case FileItemType.Other:
                    radioButtonOther.IsChecked = true;
                    radioButtonOther_Checked(null, null);
                    break;
                }

                textBoxTarget.Text    = (((FileItem)item).FilePath == null) ? "" : ((FileItem)item).FilePath;
                textBoxArguments.Text = (((FileItem)item).Arguments == null) ? "" : ((FileItem)item).Arguments;
            }
        }
        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            // TODO: Use nicer message boxes everywhere (not only in this class)?
            if (checkBoxIcon.IsChecked.HasValue &&
                checkBoxIcon.IsChecked.Value == true &&
                !File.Exists(textBoxIcon.Text))
            {
                MessageBox.Show("Icon does not exist");
                return;
            }

            //TODO: Might be worth being consistent with HasValue and != null

            // TODO: Creating a new object every time even if the type doesn't change is a bit clunky. Rewrite?

            // TODO: Warn about switching from a PieFolderItem to a non-PieFolderItem.
            //       Everything in that folder will be lost!
            //
            // TODO: Check to make sure nothing gets saved as null. Might cause some problems? Ex: null FileItem.Arguments?

            // PieFolderItem is handled separately
            if (radioButtonPieFolder.IsChecked != null && radioButtonPieFolder.IsChecked.Value == true)
            {
                NewPieItem = new PieFolderItem(
                    checkBoxName.IsChecked == null ? false : checkBoxName.IsChecked.Value,
                    textBoxName.Text,
                    checkBoxIcon.IsChecked == null ? false : checkBoxIcon.IsChecked.Value,
                    textBoxIcon.Text,
                    ContainingFolder
                    );

                // Do NOT lose the items in a PieFolderItem if we're starting/ending with a PieFolderItem
                if (OldPieItem is PieFolderItem)
                {
                    foreach (PieItem item in ((PieFolderItem)OldPieItem).Items)
                    {
                        ((PieFolderItem)NewPieItem).Items.Add(item);
                    }
                }
            }
            else // Everything else uses the FileItem class
            {
                // Placeholder value for now.
                FileItemType type = FileItemType.File;

                if (radioButtonFile.IsChecked.HasValue &&
                    radioButtonFile.IsChecked == true)
                {
                    if (!File.Exists(textBoxTarget.Text))
                    {
                        MessageBox.Show("Target file does not exist.");
                        return;
                    }

                    type = FileItemType.File;
                }

                if (radioButtonFolder.IsChecked.HasValue &&
                    radioButtonFolder.IsChecked == true)
                {
                    if (!Directory.Exists(textBoxTarget.Text))
                    {
                        MessageBox.Show("Target folder does not exist.");
                        return;
                    }

                    type = FileItemType.Folder;
                }

                if (radioButtonOther.IsChecked.HasValue &&
                    radioButtonOther.IsChecked == true)
                {
                    type = FileItemType.Other;
                }

                NewPieItem = new FileItem(
                    checkBoxName.IsChecked == null ? false : checkBoxName.IsChecked.Value,
                    textBoxName.Text,
                    checkBoxIcon.IsChecked == null ? false : checkBoxIcon.IsChecked.Value,
                    textBoxIcon.Text,
                    textBoxTarget.Text,
                    textBoxArguments.Text,
                    type
                    );
            }

            Saved = true;

            Close();
        }
Ejemplo n.º 10
0
 public PieFolderItem(bool customName, string label, bool customIcon, string iconPath, PieFolderItem prevFolder) : base(customName, label, customIcon, iconPath)
 {
     Items      = new List <PieItem>();
     PrevFolder = prevFolder;
 }