Exemple #1
0
        public NewItemDialogViewModel(IProjectFolder folder) : base("New Item")
        {
            var shell = IoC.Get <IShell>();

            templates = new ObservableCollection <ICodeTemplate>();

            var compatibleTemplates = shell.CodeTemplates.Where(t => t.IsCompatible(folder.Project));

            foreach (var template in compatibleTemplates)
            {
                templates.Add(template);
            }

            SelectedTemplate = templates.FirstOrDefault();

            this.folder = folder;

            OKCommand = ReactiveCommand.Create();

            OKCommand.Subscribe(_ =>
            {
                SelectedTemplate?.Generate(folder);

                Close();
            });
        }
Exemple #2
0
        /// <summary>
        /// Looks at the SelectedTemplate first to find a template that should be conditionally
        /// used. If there is no match then all templates in the same category that have the
        /// same template id are checked. This allows multiple templates with the same id in the
        /// same category to be supported. .NET Core 2.0 and .NET Core 1.0 project templates
        /// currently use the same template id so only one item is shown in the recently used
        /// items list but use different templates.
        /// </summary>
        SolutionTemplate GetConditionalTemplateForProcessing()
        {
            string language = GetLanguageForTemplateProcessing();

            SolutionTemplate template = SelectedTemplate.GetTemplate(language, finalConfigurationPage.Parameters);

            if (template != null)
            {
                return(template);
            }

            // Fallback to checking all templates that match the template id in the same category
            // and support the condition.
            SolutionTemplate matchedTemplate = TemplatingService.GetTemplate(
                templateCategories,
                currentTemplate => IsTemplateMatch(currentTemplate, SelectedTemplate, language, finalConfigurationPage.Parameters),
                category => true,
                category => true);

            if (matchedTemplate != null)
            {
                return(matchedTemplate.GetTemplate(language, finalConfigurationPage.Parameters));
            }

            return(null);
        }
 private void ResetTemplateExecute()
 {
     if (SelectedTemplate != null)
     {
         SelectedTemplate.ResetTemplate();
     }
 }
 private void SaveTemplateExecute()
 {
     if (SelectedTemplate != null)
     {
         SelectedTemplate.SaveTemplate();
     }
 }
 private void SaveTemplateAsExecute()
 {
     if (SelectedTemplate != null)
     {
         var newTemplate = SelectedTemplate.SaveTemplateAs();
         if (newTemplate != null)
         {
             _recentTemplates.Add(newTemplate);
         }
     }
 }
        /// <summary>
        /// Constructor
        /// </summary>
        public MainWindowViewModel()
        {
            SupportedTypes = new ObservableCollection <string>()
            {
                "string",
                "bool",
                "int", "long",
                "double", "float", "decimal",
                "object",
                "char",
                "uint", "ulong", "short", "ushort", "byte", "sbyte",
            };

            PrivatePrefix = "m_";  // inkl. updateTemplate();

            //create some rows
            for (int i = 0; i < 10; i++)
            {
                AddRow();
            }

            CommandAddRow = new RelayCommand(p1 => AddRow());

            CommandGenerateCode = new RelayCommand(p1 =>
            {
                ResultSourceCode = "";
                foreach (var aProp in Properties)
                {
                    if (!String.IsNullOrEmpty(aProp.Name))
                    {
                        ResultSourceCode += SelectedTemplate.Replace("#Name#", aProp.Name).
                                            Replace("#Comment#", aProp.Comment).
                                            Replace("#Type#", aProp.PropertyType);
                        ResultSourceCode += Environment.NewLine;
                    }
                }
            });

            CommandCopyToClipboard = new RelayCommand(p1 => Clipboard.SetText(ResultSourceCode));

            ResultSourceCode = Environment.NewLine + "   Fill out the table and then press 'Generate Code'";

            myInfoView             = new InfoView();
            myInfoView.DataContext = this;
            InfoText = "To use this syntax, your class should be inherited from ViewModelBase ( see code below ).";
            InfoCode =
                myViewModelBaseCode + Environment.NewLine +
                myClassBeginCode + Environment.NewLine +
                _ + "//your code here " + Environment.NewLine + Environment.NewLine +
                myClassEndCode;
            CommandShowInfo = new RelayCommand(p => myInfoView.Show());
            CommandCopyInfoCodeToClipboard = new RelayCommand(p1 => Clipboard.SetText(InfoCode));
            CommandCloseInfo = new RelayCommand(p => myInfoView.Hide());
        }
        public SolutionTemplate GetSelectedTemplateForSelectedLanguage()
        {
            if (SelectedTemplate != null)
            {
                SolutionTemplate languageTemplate = SelectedTemplate.GetTemplate(SelectedLanguage);
                if (languageTemplate != null)
                {
                    return(languageTemplate);
                }
            }

            return(SelectedTemplate);
        }
Exemple #8
0
 public void AddSetting()
 {
     if (SelectedTemplate != null)
     {
         var clone = SelectedTemplate.Clone();
         InnerSettings.Add(clone);
     }
     else
     {
         var messageBoxStandardWindow = MessageBoxManager.GetMessageBoxStandardWindow("Error", "Select a type of settings to add");
         messageBoxStandardWindow.Show();
     }
 }
 SolutionTemplate GetTemplateForProcessing()
 {
     if (SelectedTemplate.HasCondition)
     {
         string           language = GetLanguageForTemplateProcessing();
         SolutionTemplate template = SelectedTemplate.GetTemplate(language, finalConfigurationPage.Parameters);
         if (template != null)
         {
             return(template);
         }
         throw new ApplicationException(String.Format("No template found matching condition '{0}'.", SelectedTemplate.Condition));
     }
     return(GetSelectedTemplateForSelectedLanguage());
 }
 private void AddDrawingExecute()
 {
     try
     {
         if (SelectedTemplate != null)
         {
             SelectedTemplate.AddDrawingToDatabase();
             StatusMessage = "Added drawing " + SelectedTemplate.Drawing.Number + " to the database.";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #11
0
        public void AddMonsterFromTemplate()
        {
            WindowManager wm = new WindowManager();

            Dictionary <string, object> settings = new Dictionary <string, object>();

            settings.Add("Height", 500);
            settings.Add("Width", 500);
            settings.Add("SizeToContent", System.Windows.SizeToContent.Manual);

            AddMonsterFromTemplateViewModel amftvm = new AddMonsterFromTemplateViewModel();
            bool?success = wm.ShowDialog(amftvm, null, settings);

            if (success == true)
            {
                Monsters.Add(SelectedTemplate.GetMonster(amftvm.SelectedLevel, (Models.MonsterType)Enum.Parse(typeof(Models.MonsterType), amftvm.SelectedMonsterType), amftvm.MonsterName, amftvm.MonsterText));
            }
        }
        protected override string UpdateNameFromSelectedTemplate()
        {
            var selectedTemplate = SelectedTemplate?.GetTemplate() as TemplateAssetDescription;

            if (selectedTemplate == null || !selectedTemplate.RequireName)
            {
                return(null);
            }

            // If the mount point of the current folder does not support this type of asset, try to select the first mount point that support it.
            var assetType = selectedTemplate.GetAssetType();

            TargetDirectory = AssetViewModel.FindValidCreationLocation(assetType, CurrentDirectory);
            if (TargetDirectory == null)
            {
                return(null);
            }

            var baseName = selectedTemplate.DefaultOutputName ?? selectedTemplate.AssetTypeName;
            var name     = NamingHelper.ComputeNewName(baseName, TargetDirectory.Assets, x => x.Name, "{0}{1}");

            return(name);
        }
Exemple #13
0
        public void Create()
        {
            if (Validate(nameof(PlaceName)) != string.Empty)
            {
                return;
            }

            Game.Workspace.LoadPlace(null);
            try
            {
                Game.Workspace.PlaceId = PlaceName;
                Game.DataModel.ClearContent(false);
                SelectedTemplate.LoadTemplate();
                Game.DataModel.SaveGame(SaveFilter.SaveWorld);
                Game.Workspace.LoadPlace(PlaceName);
            }
            catch (Exception e)
            {
                MessageBox.Show($"Could not create place: {e.Message}");
                TryClose();
            }
            TryClose(true);
        }