Example #1
0
        static void Main(string[] args)
        {
            var editor = new ThemeEditorViewModel();

            if (File.Exists(s_ThemesPath))
            {
                editor.Load(s_ThemesPath);
            }

            BuildAvaloniaApp().Start <MainWindow>(() => editor);

            editor.Save(s_ThemesPath);
        }
Example #2
0
        public ActionResult Edit(Guid id, ThemeEditorViewModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(model));
            }
            var userId = User.Identity.UserId();
            var theme  = this.DB.Themes.First(t => t.ThemeId == id && t.Owner == userId);

            theme.Description = model.Description;
            this.DB.SaveChanges();

            return(Redirect("~/"));
        }
Example #3
0
        public ActionResult Post(string themeType, ThemeEditorViewModel model)
        {
            model.ThemeType = Enum <ThemeType> .Parse(themeType);

            if (ModelState.IsValid == false)
            {
                return(View(model));
            }
            this.DB.Themes.Add(new Theme
            {
                Owner       = User.Identity.UserId(),
                ThemeType   = (int)Enum <ThemeType> .Parse(themeType),
                Description = model.Description
            });
            this.DB.SaveChanges();
            return(Redirect("~/"));
        }
Example #4
0
    public override void OnFrameworkInitializationCompleted()
    {
        var mainWindowViewModel = new ThemeEditorViewModel();

        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
        {
            if (File.Exists(s_ThemesPath))
            {
                mainWindowViewModel.LoadFromFile(s_ThemesPath);
            }
            else
            {
                mainWindowViewModel.LoadFromResource <App>(s_ThemesResource);
            }

            var mainWindow = new MainWindow
            {
                DataContext = mainWindowViewModel,
            };

            desktopLifetime.MainWindow = mainWindow;

            desktopLifetime.Exit += (sennder, e) =>
            {
                mainWindowViewModel.SaveAsFile(s_ThemesPath);
            };
        }
        else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime)
        {
            mainWindowViewModel.LoadFromResource <App>(s_ThemesResource);

            var mainView = new MainView()
            {
                DataContext = mainWindowViewModel
            };

            singleViewLifetime.MainView = mainView;
        }
        base.OnFrameworkInitializationCompleted();
    }
Example #5
0
        public ActionResult Editor(bool ismobile)
        {
            // check that there are theme files, otherwise copy
            var handler = new ThemeHandler(MASTERdomain, ismobile);

            if (!handler.IsCustom && !handler.ThemeCopiedOK())
            {
                DirectoryInfo sourceThemeDir = ismobile
                                                   ? handler.GetMobileThemeRepositorySourceDir()
                                                   : handler.GetThemeRepositorySourceDir();
                if (sourceThemeDir == null)
                {
                    throw new NotImplementedException();
                }
                handler.CopyThemeToUserThemeDirectory(sourceThemeDir);
            }

            var viewmodel = new ThemeEditorViewModel()
            {
                themeType = ismobile ? ThemeType.MOBILE : ThemeType.MAIN
            };

            var themedir = handler.GetThemeDirectory();

            foreach (var dir in themedir.GetDirectories().OrderByDescending(x => x.Name))
            {
                var folder = new ThemeDirectory()
                {
                    foldername = dir.Name
                };
                switch (dir.Name)
                {
                case "templates":
                    viewmodel.templates_folder = folder;
                    break;

                case "assets":
                    viewmodel.asset_folder = folder;
                    break;

                case "snippets":
                    viewmodel.snippets_folder = folder;
                    break;

                case "layout":
                    viewmodel.layout_folder = folder;
                    break;

                case "config":
                    viewmodel.config_folder = folder;
                    break;

                default:
                    throw new ArgumentException("Unknown directory " + dir.Name);
                }
                foreach (var entry in dir.GetFiles())
                {
                    var ext  = entry.Extension.ToLower();
                    var file = new ThemeFile();
                    file.classname = string.Format("ext_{0}", ext.Substring(1));
                    file.url       = string.Format("/{0}/{1}", dir.Name, entry.Name);
                    file.filename  = entry.Name;

                    folder.files.Add(file);
                }
            }

            return(View(viewmodel));
        }