Example #1
0
 public void TakeAllFrom(MetaSet set)
 {
     Objects.AddRange(set.Objects);
     Actions.AddRange(set.Actions);
     Tutorials.AddRange(set.Tutorials);
     Mechanisms.AddRange(set.Mechanisms);
     Tags.AddRange(set.Tags);
     Commands.AddRange(set.Commands);
     Languages.AddRange(set.Languages);
     Events.AddRange(set.Events);
 }
        protected async override void OnInitialize()
        {
            base.OnInitialize();

            var gitHubData = new GitHubDataSource();
            var repositories = await gitHubData.LoadRepositories();

            var languages = from r in repositories
                            group r by r.Language into l
                            select new LanguageViewModel
                            {
                                Name = l.Key ?? "Unknown",
                                Repositories = new BindableCollection<RepositoryViewModel>(l)
                            };

            Languages.AddRange(languages);
        }
    public static void RefreshLanguages(bool includeIncomplete)
    {
        // Clear the collection
        Languages.Clear();

        // Add complete languages
        Languages.AddRange(new CultureInfo[]
        {
            DefaultCulture,

            // Dutch (Netherlands)
            new CultureInfo("nl-NL"),

            // Italian (Italy)
            new CultureInfo("it-IT"),

            // Polish (Poland)
            new CultureInfo("pl-PL"),

            // Portuguese (Portugal)
            new CultureInfo("pt-PT"),

            // Russian (Russia)
            new CultureInfo("ru-RU"),
        });

        if (includeIncomplete)
        {
            // Add incomplete languages
            Languages.AddRange(new CultureInfo[]
            {
                // Serbian (Cyrillic)
                new CultureInfo("sr-Cyrl"),

                // Spanish (Mexico)
                new CultureInfo("es-MX"),

                // Spanish (Spain)
                new CultureInfo("es-ES"),

                // Swedish (Sweden)
                new CultureInfo("sv-SE"),
            });
        }
    }
Example #4
0
        public EditFlashcardViewModel(Flashcard flashcard, Language currentLanguage, IEnumerable <Language> languages)
        {
            FlashcardID = flashcard.ID;
            Name        = flashcard.Name;
            if (currentLanguage != null)
            {
                var translations = flashcard.FlashcardTranslations.Where(t => t.LanguageID == currentLanguage.ID).ToList();
                Translations = translations.Select(t => new EditTranslationViewModel(t)).ToList();
            }
            else
            {
                Translations = new List <EditTranslationViewModel>();
            }

            Images = flashcard.FlashcardImages.ToList()
                     .Select(img => new EditFlashcardImageViewModel(img)).ToList();

            Languages.Add(new SelectListItem()
            {
                Value = "",
                Text  = "-- Select Language --"
            });

            Languages.AddRange(languages.Select(l => new SelectListItem()
            {
                Text  = l.EnglishName,
                Value = l.Symbol
            }));

            LanguageSymbol = currentLanguage?.Symbol;

            Disabled   = LanguageSymbol == null ? "disabled" : "";
            LanguageID = currentLanguage?.ID;

            NewTranslation.Significance = 1.0;
        }
        public ProjectViewModel(ILifetimeScope lifetimeScope, Dispatcher dispatcher, LocLocalizer localizer, ProjectFileWorkspace workspace)
            : base(lifetimeScope, dispatcher)
        {
            #region Init

            var loadTrigger = new CommandTrigger();

            Receive <IncommingEvent>(e => e.Action());

            IsEnabled = RegisterProperty <bool>(nameof(IsEnabled)).WithDefaultValue(!workspace.ProjectFile.IsEmpty);

            ProjectEntrys = this.RegisterUiCollection <ProjectEntryModel>(nameof(ProjectEntrys))
                            .AndAsync();
            SelectedIndex = RegisterProperty <int>(nameof(SelectedIndex));

            var self = Context.Self;

            void TryUpdateEntry((string ProjectName, string EntryName, ActiveLanguage Lang, string Content) data)
            {
                var(projectName, entryName, lang, content) = data;
                self.Tell(new UpdateRequest(entryName, lang, content, projectName));
            }

            void TryRemoveEntry((string ProjectName, string EntryName) data)
            {
                var(projectName, entryName) = data;
                self.Tell(new RemoveRequest(entryName, projectName));
            }

            OnPreRestart += (exception, o) => Self.Tell(new InitProjectViewModel(workspace.Get(_project)));

            void InitProjectViewModel(InitProjectViewModel obj)
            {
                _project = obj.Project.ProjectName;

                Languages !.Add(new ProjectViewLanguageModel(localizer.ProjectViewLanguageBoxFirstLabel, true));
                Languages.AddRange(obj.Project.ActiveLanguages.Select(al => new ProjectViewLanguageModel(al.Name, false)));
                SelectedIndex += 0;

                foreach (var projectEntry in obj.Project.Entries.OrderBy(le => le.Key))
                {
                    ProjectEntrys.Add(new ProjectEntryModel(obj.Project, projectEntry, TryUpdateEntry, TryRemoveEntry));
                }

                ImportetProjects !.AddRange(obj.Project.Imports);
                loadTrigger.Trigger();
            }

            Receive <InitProjectViewModel>(InitProjectViewModel);

            #endregion

            #region New Entry

            IEnumerable <NewEntryInfoBase> GetEntrys()
            {
                var list = ImportetProjects.ToList();

                list.Add(_project);

                var allEntrys = list.SelectMany(pro => workspace.Get(pro).Entries.Select(e => e.Key)).ToArray();

                return(allEntrys.Select(e => new NewEntryInfo(e)).OfType <NewEntryInfoBase>()
                       .Concat(allEntrys
                               .Select(s => s.Split('_', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault())
                               .Where(s => !string.IsNullOrWhiteSpace(s))
                               .Distinct(StringComparer.Ordinal)
                               .Select(s => new NewEntrySuggestInfo(s !))));
            }

            void AddEntry(EntryAdd entry)
            {
                if (_project != entry.Entry.Project)
                {
                    return;
                }

                ProjectEntrys.Add(new ProjectEntryModel(workspace.Get(_project), entry.Entry, TryUpdateEntry, TryRemoveEntry));
            }

            NewCommad
            .ThenFlow(this.ShowDialog <INewEntryDialog, NewEntryDialogResult?, IEnumerable <NewEntryInfoBase> >(GetEntrys),
                      b =>
            {
                b.Mutate(workspace.Entrys).With(em => em.EntryAdd, em => res => em.NewEntry(_project, res !.Name)).ToSelf()
                .Then(b2 => b2.Action(AddEntry));
            })