Ejemplo n.º 1
0
    public override async Task OnOpen(CancelEventArgs e)
    {
        await base.OnOpen(e);

        var settings = _settingsService.LoadSettings();

        if (!Directory.Exists(settings.PrintsPath))
        {
            MessageBox.Show(_translationManager.GetTranslation(nameof(StringTable.Msg_PrintProjectsFolderNotConfigured)), "CuraManager", AlertButton.Ok, AlertImage.Information);
            e.Cancel = true;
        }
        else
        {
            _cache ??= _cachingService.LoadCache(settings.PrintsPath);
            if (_currentPrintsPath != settings.PrintsPath)
            {
                _currentPrintsPath = settings.PrintsPath;
                PrintElements.ForEach(x => x.Dispose());
                PrintElements.Clear();
            }

            var newElements = await _printsService.GetNewPrintElements(_cache, PrintElements).ToListAsync();

            newElements.ForEach(x => AvailableTags.AddIfNotExists(x.Tags));
            PrintElements.Add(newElements);
            PrintElementsViewSource.View.Refresh();
        }
    }
        private void InsertSorted(string tag)
        {
            if (AvailableTags.Any(x => string.Equals(tag, x.Label, StringComparison.InvariantCultureIgnoreCase)))
            {
                return;
            }

            var index = -1;

            for (var i = 0; i < AvailableTags.Count; i++)
            {
                if (string.Compare(AvailableTags[i].Label, tag, StringComparison.InvariantCultureIgnoreCase) > 0)
                {
                    index = i;
                    break;
                }
            }

            if (index < 0)
            {
                AvailableTags.Add(new FilterTag {
                    Label = tag
                });
            }
            else
            {
                AvailableTags.Insert(index, new FilterTag {
                    Label = tag
                });
            }
        }
        private ModTag HitTest(IEnumerable <string> tags, Graphics g, CellEventArgs e)
        {
            if (tags == null || e.SubItem == null)
            {
                return(null);
            }

            var bounds = e.SubItem.Bounds;
            var offset = new Point(bounds.X + TagRenderInfo.rX,
                                   bounds.Y + TagRenderInfo.rY);
            var tagList = AvailableTags.Where(t => tags.Select(s => s.ToLower()).Contains(t.Key)).Select(kvp => kvp.Value);

            foreach (var tag in tagList)
            {
                var tagSize    = g.MeasureString(tag.Label, e.SubItem.Font).ToSize();
                var renderInfo = new TagRenderInfo(offset, bounds, tagSize, Color.Black);

                if (renderInfo.HitBox.Contains(e.Location))
                {
                    return(tag);
                }

                offset.X += renderInfo.HitBox.Width + TagRenderInfo.rX;
                // stop drawing outside of the column bounds
                if (offset.X > bounds.Right)
                {
                    break;
                }
            }

            return(null);
        }
        private void DoFilter(object obj)
        {
            var filterTag = obj as FilterTag;

            if (filterTag == null)
            {
                return;
            }

            if (!filterTag.IsAllFilter && filterTag.IsSelected)
            {
                AvailableTags.First(x => x.IsAllFilter).IsSelected = false;
            }

            if (!filterTag.IsAllFilter && !filterTag.IsSelected && AvailableTags.All(x => !x.IsSelected))
            {
                AvailableTags.First(x => x.IsAllFilter).IsSelected = true;
            }

            if (filterTag.IsAllFilter && filterTag.IsSelected)
            {
                foreach (var tag in AvailableTags.Where(x => !x.IsAllFilter))
                {
                    tag.IsSelected = false;
                }
            }

            CollectionViewSourceBuildAdapters.View.Refresh();
        }
        private void RenameTag(ModTag tag, string newTag)
        {
            if (tag != null && string.IsNullOrEmpty(newTag) == false)
            {
                var oldTag = tag.Label;

                if (AvailableTags.ContainsKey(newTag.ToLower()) == false)
                {
                    tag.Label = newTag;

                    AvailableTags.Remove(oldTag.ToLower());
                    AvailableTags[newTag.ToLower()] = tag;
                }
                else if (oldTag.ToLower().Equals(newTag.ToLower()))
                {
                    AvailableTags[oldTag.ToLower()].Label = newTag;
                }

                foreach (var mod in Mods.All)
                {
                    if (mod.Tags.Select(t => t.ToLower()).Contains(oldTag.ToLower()))
                    {
                        mod.Tags.Remove(mod.Tags.First(t => t.ToLower().Equals(oldTag.ToLower())));
                        AddTag(mod, newTag);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static void UpdateAvailableTags()
        {
            AvailableTags = m_editorContract.tags.ToArray();
            Array.Sort(AvailableTags, (x, y) => string.Compare(x.name, y.name));

            // Build string tag array
            AvailableTagsString = AvailableTags.Select(x => x.name).ToArray();
        }
Ejemplo n.º 7
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds a tag to the list of tags (not to the solution).</summary>
 ///--------------------------------------------------------------------------------
 protected void OnAdd()
 {
     if (AvailableTags.Contains(TagName) == false)
     {
         AvailableTags.Add(TagName);
     }
     AvailableTags.Sort(s => s, ListSortDirection.Ascending);
     TagName = null;
     OnPropertyChanged("AvailableTags");
 }
Ejemplo n.º 8
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method updates the view model data and sends update command back
 /// to the solution builder.</summary>
 ///--------------------------------------------------------------------------------
 public void AddTag()
 {
     if (TagNameValidationMessage != String.Empty && TagName != String.Empty)
     {
         if (AvailableTags.Contains(TagName) == false)
         {
             AvailableTags.Add(TagName);
         }
         TagName = String.Empty;
     }
 }
Ejemplo n.º 9
0
 private void TagSelector_TextSubmitted(ComboBox sender, ComboBoxTextSubmittedEventArgs args)
 {
     if (!string.IsNullOrEmpty(args.Text))
     {
         AvailableTags.Add(args.Text);
         CurrentTag = args.Text;
     }
     else
     {
         args.Handled = true;
     }
 }
Ejemplo n.º 10
0
 partial void OnSelectedElementChanged(PrintElement previous, PrintElement value)
 {
     Task.Run(() =>
     {
         Thread.Sleep(100);
         Application.Current.Dispatcher.Invoke(() =>
         {
             if (value?.Initialize() == true)
             {
                 AvailableTags.AddIfNotExists(value.Tags);
             }
         });
     });
 }
Ejemplo n.º 11
0
    private void ExecuteCreateTag(PrintElement project)
    {
        var dialog = new RenameDialog(_translationManager.GetTranslation(nameof(StringTable.Title_CreateTag)), _translationManager.GetTranslation(nameof(StringTable.Desc_CreateTag)), string.Empty, s => null)
        {
            CustomIcon = new IconPresenter {
                Icon = new MaterialDesignIcon(MaterialDesignIconCode.Plus)
            },
            SubmitButtonContent = _translationManager.GetTranslation(nameof(StringTable.Create)),
        };

        if (dialog.ShowDialog() == true)
        {
            AvailableTags.AddIfNotExists(dialog.NewName);
            project.Tags.AddIfNotExists(dialog.NewName);
        }
    }
Ejemplo n.º 12
0
        private bool AddTag(ModEntry mod, string newTag)
        {
            if (mod != null && string.IsNullOrEmpty(newTag) == false && mod.Tags.Contains(newTag) == false)
            {
                if (AvailableTags.ContainsKey(newTag.ToLower()) == false)
                {
                    AvailableTags[newTag.ToLower()] = new ModTag(newTag);
                }

                mod.Tags.Add(newTag);

                return(true);
            }

            return(false);
        }
Ejemplo n.º 13
0
        private void CollectionViewSourceBuildAdaptersFilter(object sender, FilterEventArgs e)
        {
            if (AvailableTags.Count == 0 || AvailableTags.First(x => x.IsAllFilter).IsSelected)
            {
                e.Accepted = true;
                return;
            }

            var buildAdapter = e.Item as BuildAdapter;

            if (buildAdapter == null)
            {
                e.Accepted = false;
                return;
            }

            e.Accepted =
                AvailableTags.Where(filterTag => filterTag.IsSelected).Any(
                    filterTag => buildAdapter.Tags.Any(word => string.Equals(filterTag.Label, word, StringComparison.InvariantCultureIgnoreCase)));
        }
Ejemplo n.º 14
0
        /// <summary>Fills the available tags.</summary>
        internal void FillAvailableTags()
        {
            foreach (var tag in BuildAdapters.SelectMany(x => x.Tags))
            {
                InsertSorted(tag);
            }

            for (var i = 0; i < AvailableTags.Count; i++)
            {
                if (AvailableTags[i].IsAllFilter)
                {
                    continue;
                }

                if (!BuildAdapters.SelectMany(x => x.Tags).Any(x => string.Equals(x, AvailableTags[i].Label, StringComparison.CurrentCulture)))
                {
                    AvailableTags.RemoveAt(i);
                    i--;
                }
            }
        }
Ejemplo n.º 15
0
        private void PersistanceModelOnFileChanged(object sender, FileChangedEventArgs fileChangedEventArgs)
        {
            if (fileChangedEventArgs.File.Name != Name)
            {
                return;
            }

            Tags.Clear();
            AvailableTags.Clear();

            foreach (var tag in _tagsModel.Tags.Select(t => t.Text))
            {
                if (fileChangedEventArgs.File.Tags.Contains(tag))
                {
                    Tags.Add(new TagViewModel(this, tag));
                }
                else
                {
                    AvailableTags.Add(new TagViewModel(this, tag));
                }
            }
        }
Ejemplo n.º 16
0
        private void RenameTag(ModTag tag, string newTag)
        {
            if (tag != null && string.IsNullOrEmpty(newTag) == false)
            {
                var oldTag = tag.Label;

                if (AvailableTags.ContainsKey(newTag) == false)
                {
                    tag.Label = newTag;

                    AvailableTags.Remove(oldTag);
                    AvailableTags[newTag] = tag;
                }

                foreach (var mod in Mods.All)
                {
                    if (mod.Tags.Contains(oldTag))
                    {
                        mod.Tags.Remove(oldTag);
                        AddTag(mod, newTag);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private void ExportLoadButtonClick(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                Filter          = "Text files|*.txt",
                DefaultExt      = "txt",
                CheckPathExists = true,
                CheckFileExists = true,
                Multiselect     = false,
            };

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            bool OverrideTags;

            if (!Settings.NeverImportTags)
            {
                OverrideTags = MessageBox.Show("Do you want to override the tags and categories of your current mods with the tags saved in your profile?\r\n" +
                                               "Warning: This action cannot be undone", "Importing profile", MessageBoxButtons.YesNo) == DialogResult.Yes;
            }
            else
            {
                OverrideTags = false;
            }
            // parse file

            var categoryRegex = new Regex(@"^(?<category>.*?)\s\(\d*\):$", RegexOptions.Compiled | RegexOptions.Multiline);
            var modEntryRegex = new Regex(@"^\s*(?<name>.*?)[ ]*\t(?<id>.*?)[ ]*\t(?:.*=)?(?<sourceID>\d+)([ ]*\t(?<tags>.*?))?$", RegexOptions.Compiled | RegexOptions.Multiline);

            var mods         = Mods.All.ToList();
            var activeMods   = new List <ModEntry>();
            var missingMods  = new List <Match>();
            var categoryName = "";

            foreach (var line in File.ReadAllLines(dialog.FileName))
            {
                var categoryMatch = categoryRegex.Match(line);
                if (categoryMatch.Success)
                {
                    categoryName = categoryMatch.Groups["category"].Value;
                }

                var modMatch = modEntryRegex.Match(line);
                if (!modMatch.Success)
                {
                    continue;
                }

                //        var active = false;
                //        if (modMatch.Groups["active"].Success)
                //        {
                //// Try just in case the value doesn't work, failsafe value is false, so this shouldn't be an issue
                //         try
                //{
                //	active = bool.Parse(modMatch.Groups["active"].Value);
                //}
                //catch
                //{ }
                //        }

                var entries = mods.Where(mod => mod.ID == modMatch.Groups["id"].Value).ToList();

                if (entries.Count == 0)
                {
                    // Mod missing
                    // -> add to list
                    missingMods.Add(modMatch);
                    continue;
                }

                activeMods.AddRange(entries);

                if (OverrideTags)
                {
                    var tags = modMatch.Groups["tags"].Value.Split(';').Where(t => !string.IsNullOrWhiteSpace(t));

                    foreach (var tag in tags)
                    {
                        if (AvailableTags.ContainsKey(tag.ToLower()) == false)
                        {
                            AvailableTags[tag.ToLower()] = new ModTag(tag);
                        }
                    }

                    foreach (var modEntry in entries)
                    {
                        modEntry.Tags = tags.ToList();
                        Mods.RemoveMod(modEntry);
                        Mods.AddMod(categoryName, modEntry);
                    }
                }
            }

            // Check entries
            if (activeMods.Count == 0)
            {
                MessageBox.Show("No mods found. Bad profile?");
                return;
            }

            // Check missing
            if (missingMods.Count > 0)
            {
                var steamMissingMods = missingMods.Where(match => match.Groups["sourceID"].Value != "Unknown").ToList();

                var text = $"This profile contains {missingMods.Count} mod(s) that are not currently installed:\r\n\r\n";

                foreach (var match in missingMods)
                {
                    text += match.Groups["name"].Value;

                    if (steamMissingMods.Contains(match))
                    {
                        text += "*";
                    }

                    text += "\r\n";
                }

                if (steamMissingMods.Count != 0)
                {
                    text += "\r\nDo you want to subscribe to the mods marked with an asterisk on Steam?";

                    var result = FlexibleMessageBox.Show(this, text, "Mods missing!", MessageBoxButtons.YesNoCancel);

                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (result == DialogResult.Yes)
                    {
                        // subscribe
                        foreach (var id in steamMissingMods.Select(match => ulong.Parse(match.Groups["sourceID"].Value)))
                        {
                            SteamUGC.SubscribeItem(id.ToPublishedFileID());
                        }

                        MessageBox.Show("Done. Close the launcher, wait for steam to download the mod(s) and try again.");
                        return;
                    }
                }
                else
                {
                    text += "\r\nDo you wish to continue?";

                    if (FlexibleMessageBox.Show(this, text, "Mods missing!", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }
                }
            }

            // Confirm
            if (FlexibleMessageBox.Show(this, $"Adopt profile? {activeMods.Count} mods found.", "Confirm", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            // Apply changes
            foreach (var mod in mods)
            {
                mod.isActive = false;
            }

            foreach (var mod in activeMods)
            {
                mod.isActive = true;
            }

            modlist_ListObjectListView.UpdateObjects(mods);

            UpdateExport();
            UpdateLabels();
        }