예제 #1
0
        public override void Execute(object parameter)
        {
            var context = parameter as ContentTreeContext;

            if (context == null)
            {
                return;
            }

            var databaseUri = DatabaseUri.Empty;

            var database = context.SelectedItems.FirstOrDefault() as DatabaseTreeViewItem;

            if (database != null)
            {
                databaseUri = database.DatabaseUri;
            }
            else
            {
                var selectedItem = context.SelectedItems.FirstOrDefault() as ItemTreeViewItem;
                if (selectedItem != null)
                {
                    databaseUri = selectedItem.ItemUri.DatabaseUri;
                }
            }

            if (databaseUri == DatabaseUri.Empty)
            {
                return;
            }

            LayoutSchemaHelper.GenerateSchema(databaseUri, false, () => { });
        }
        public override void Execute(object parameter)
        {
            var context = parameter as IItemSelectionContext;

            if (context == null)
            {
                return;
            }

            var selectedItem = context.Items.FirstOrDefault();

            if (selectedItem == null)
            {
                return;
            }

            string initialDirectory = null;

            var project = AppHost.Projects.FirstOrDefault(p => p.Site == selectedItem.ItemUri.Site);

            if (project != null)
            {
                initialDirectory = AppHost.Settings.GetString(@"Layouts\\XmlLayoutFolder", @"Last", project.FolderName);
            }

            var dialog = new SaveFileDialog
            {
                Title            = "Add Layout File to Project",
                CheckPathExists  = true,
                OverwritePrompt  = true,
                InitialDirectory = initialDirectory,
                FileName         = selectedItem.Name + ".layout.xml",
                Filter           = "Layout (*.layout.xml)|*.layout.xml|All Files|(*.*)"
            };

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

            AppHost.Settings.SetString(@"Layouts\\XmlLayoutFolder", @"Last", Path.GetDirectoryName(dialog.FileName) ?? string.Empty);

            var itemUri = new ItemVersionUri(selectedItem.ItemUri, LanguageManager.CurrentLanguage, Version.Latest);

            LayoutSchemaHelper.GenerateSchema(dialog.FileName, itemUri.ItemUri, selectedItem, AddLayout);
        }