Esempio n. 1
0
        private void LoadImportedThemes(List <ThemeConfig> themes, ImportDialog importDialog)
        {
            themes.Sort((t1, t2) => t1.themeId.CompareTo(t2.themeId));
            Size thumbnailSize        = ThemeThumbLoader.GetThumbnailSize(this);
            ImageListViewItem newItem = null;

            Task.Run(() =>
            {
                for (int i = 0; i < themes.Count; i++)
                {
                    this.Invoke(new Action(() => EnsureThemeNotDuplicated(themes[i].themeId)));

                    string themeName = ThemeManager.GetThemeName(themes[i]);
                    themeNames.Add(themeName);
                    themeNames.Sort();
                    int itemIndex = themeNames.IndexOf(themeName) + 1;

                    using (Image thumbnailImage = ThemeThumbLoader.GetThumbnailImage(themes[i],
                                                                                     thumbnailSize, false))
                    {
                        this.Invoke(new Action(() =>
                        {
                            imageListView1.Items.Insert(itemIndex,
                                                        ThemeManager.GetThemeName(themes[i]), thumbnailImage);
                            newItem     = imageListView1.Items[itemIndex];
                            newItem.Tag = themes[i].themeId;
                        }));
                    }
                }

                if (newItem != null)
                {
                    this.Invoke(new Action(() =>
                    {
                        imageListView1.ClearSelection();
                        newItem.Selected = true;
                        imageListView1.EnsureVisible(newItem.Index);
                    }));
                }

                importDialog.thumbnailsLoaded = true;
                this.Invoke(new Action(() => importDialog.Close()));
            });
        }
Esempio n. 2
0
        private void LoadThemes(List <ThemeConfig> themes, string activeTheme = null)
        {
            Size         thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);
            ListViewItem focusedItem   = null;

            foreach (ThemeConfig theme in themes)
            {
                using (Image thumbnailImage = ThemeThumbLoader.GetThumbnailImage(theme, thumbnailSize, true))
                {
                    this.Invoke(new Action(() =>
                    {
                        listView1.LargeImageList.Images.Add(thumbnailImage);
                        string itemText = ThemeManager.GetThemeName(theme);
                        if (JsonConfig.settings.favoriteThemes != null &&
                            JsonConfig.settings.favoriteThemes.Contains(theme.themeId))
                        {
                            itemText = "★ " + itemText;
                        }
                        ListViewItem newItem = listView1.Items.Add(itemText, listView1.LargeImageList.Images.Count - 1);
                        newItem.Tag          = theme.themeId;

                        if (activeTheme == null || activeTheme == theme.themeId)
                        {
                            focusedItem = newItem;
                        }
                    }));
                }
            }

            this.Invoke(new Action(() =>
            {
                listView1.Sort();

                if (focusedItem == null)
                {
                    focusedItem = listView1.Items[0];
                }

                focusedItem.Selected = true;
                listView1.EnsureVisible(focusedItem.Index);

                ThemeThumbLoader.CacheThumbnails(listView1);
            }));
        }
Esempio n. 3
0
        public void ImportThemes(List <string> themePaths)
        {
            this.Enabled = false;
            List <string> duplicateThemeNames = new List <string>();

            foreach (string themePath in themePaths)
            {
                string themeId    = Path.GetFileNameWithoutExtension(themePath);
                int    themeIndex = ThemeManager.themeSettings.FindIndex(t => t.themeId == themeId);

                if (themeIndex != -1)
                {
                    duplicateThemeNames.Add(ThemeManager.GetThemeName(
                                                ThemeManager.themeSettings[themeIndex]));
                }
            }

            if (duplicateThemeNames.Count > 0)
            {
                DialogResult result = MessageDialog.ShowQuestion(string.Format(_("The following themes are already " +
                                                                                 "installed:\n\t{0}\n\nDo you want to overwrite them?"), string.Join("\n\t", duplicateThemeNames)),
                                                                 _("Question"), true);

                if (result != DialogResult.Yes)
                {
                    this.Enabled = true;
                    return;
                }
            }

            ImportDialog importDialog = new ImportDialog()
            {
                Owner = this
            };

            importDialog.FormClosing += OnImportDialogClosing;
            importDialog.Show();
            importDialog.InitImport(themePaths);
        }
Esempio n. 4
0
        private void ApplySelectedTheme()
        {
            if (selectedIndex > 0)
            {
                ThemeManager.currentTheme = ThemeManager.themeSettings[selectedIndex - 1];
            }
            else
            {
                ThemeManager.currentTheme = null;
            }

            JsonConfig.settings.themeName = ThemeManager.currentTheme?.themeId;

            if (selectedIndex == 0)
            {
                WallpaperApi.SetWallpaper(windowsWallpaper);
            }
            else
            {
                AppContext.wpEngine.RunScheduler();
                AppContext.ShowPopup(string.Format(_("New theme applied: {0}"),
                                                   ThemeManager.GetThemeName(ThemeManager.currentTheme)));
            }
        }
Esempio n. 5
0
        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int         itemIndex = imageListView1.SelectedItems[0].Index;
            string      themeId   = (string)imageListView1.Items[itemIndex].Tag;
            ThemeConfig theme     = ThemeManager.themeSettings.Find(t => t.themeId == themeId);

            DialogResult result = MessageBox.Show(string.Format(_("Are you sure you want to " +
                                                                  "remove the '{0}' theme?"), ThemeManager.GetThemeName(theme)), _("Question"),
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                imageListView1.Items.RemoveAt(itemIndex);
                imageListView1.Items[itemIndex - 1].Selected = true;
                themeNames.RemoveAt(itemIndex - 1);

                Task.Run(() => ThemeManager.RemoveTheme(theme));
            }
        }
Esempio n. 6
0
        public void InitDownload(ThemeConfig theme)
        {
            ThemeManager.downloadMode = true;
            this.Invoke(new Action(() =>
                                   label1.Text = string.Format(_("Downloading images for '{0}'..."), ThemeManager.GetThemeName(theme))));

            themeUris     = DefaultThemes.GetThemeUriList(theme.themeId).ToList();
            themeUriIndex = 0;
            themeZipDest  = Path.Combine("themes", theme.themeId + ".zip");
            DownloadNext(theme);
        }
Esempio n. 7
0
        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int         itemIndex = imageListView1.SelectedItems[0].Index;
            string      themeId   = (string)imageListView1.Items[itemIndex].Tag;
            ThemeConfig theme     = ThemeManager.themeSettings.Find(t => t.themeId == themeId);

            DialogResult result = MessageDialog.ShowQuestion(string.Format(_("Are you sure you want to remove the " +
                                                                             "'{0}' theme?"), ThemeManager.GetThemeName(theme)), _("Question"), true);

            if (result == DialogResult.Yes)
            {
                if (!ThemeManager.defaultThemes.Contains(theme.themeId))
                {
                    imageListView1.Items.RemoveAt(itemIndex);
                    imageListView1.Items[itemIndex - 1].Selected = true;
                    themeNames.RemoveAt(itemIndex - 1);
                }

                Task.Run(() => {
                    ThemeManager.RemoveTheme(theme);

                    if (ThemeManager.defaultThemes.Contains(theme.themeId))
                    {
                        this.Invoke(new Action(() => UpdateSelectedItem()));
                    }
                });
            }
        }
        private void themeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int         itemIndex = imageListView1.SelectedItems[0].Index;
            string      themeId   = (string)imageListView1.Items[itemIndex].Tag;
            ThemeConfig theme     = ThemeManager.themeSettings.Find(t => t.themeId == themeId);

            if (ThemeManager.IsThemeDownloaded(theme))
            {
                DialogResult result = MessageDialog.ShowQuestion(string.Format(_("Are you sure you want to remove the " +
                                                                                 "'{0}' theme?"), ThemeManager.GetThemeName(theme)), _("Question"), true);

                if (result == DialogResult.Yes)
                {
                    if (!ThemeManager.defaultThemes.Contains(theme.themeId))
                    {
                        imageListView1.Items.RemoveAt(itemIndex);
                        imageListView1.Items[itemIndex - 1].Selected = true;
                        themeNames.RemoveAt(itemIndex - 1);
                    }

                    Task.Run(() => {
                        ThemeManager.RemoveTheme(theme);

                        if (ThemeManager.defaultThemes.Contains(theme.themeId))
                        {
                            this.Invoke(new Action(() => UpdateSelectedItem()));
                        }
                    });
                }
            }
            else
            {
                DownloadDialog downloadDialog = new DownloadDialog()
                {
                    Owner = this, applyPending = false
                };
                downloadDialog.FormClosed += OnDownloadDialogClosed;
                downloadDialog.Show();
                this.Enabled = false;
                downloadDialog.InitDownload(theme);
            }
        }
 private void UpdateDownloadStatus(ThemeConfig theme)
 {
     label1.Text = string.Format(_("Downloading images for '{0}'..."),
                                 ThemeManager.GetThemeName(theme));
 }