Antes de comenzar con CopilotEdit
This commit is contained in:
parent
7b5b6709bd
commit
e2ab9ef6d6
|
@ -0,0 +1,100 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Microsoft.Windows.Controls
|
||||
{
|
||||
public class InputDialogResult
|
||||
{
|
||||
public bool IsOk { get; set; }
|
||||
public string Result { get; set; }
|
||||
}
|
||||
|
||||
public class InputDialog
|
||||
{
|
||||
public static InputDialogResult Show(string title, string promptText, string defaultValue = "")
|
||||
{
|
||||
var dialog = new Window
|
||||
{
|
||||
Title = title,
|
||||
Width = 400,
|
||||
Height = 150,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||
Owner = Application.Current.MainWindow,
|
||||
ResizeMode = ResizeMode.NoResize
|
||||
};
|
||||
|
||||
var grid = new Grid { Margin = new Thickness(10) };
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(10) });
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
|
||||
|
||||
var promptLabel = new TextBlock
|
||||
{
|
||||
Text = promptText,
|
||||
Margin = new Thickness(0, 0, 0, 5)
|
||||
};
|
||||
Grid.SetRow(promptLabel, 0);
|
||||
|
||||
var inputBox = new TextBox
|
||||
{
|
||||
Text = defaultValue,
|
||||
Margin = new Thickness(0)
|
||||
};
|
||||
Grid.SetRow(inputBox, 2);
|
||||
|
||||
var buttonPanel = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
Margin = new Thickness(0, 10, 0, 0)
|
||||
};
|
||||
Grid.SetRow(buttonPanel, 4);
|
||||
|
||||
var okButton = new Button
|
||||
{
|
||||
Content = "Aceptar",
|
||||
Width = 75,
|
||||
Height = 23,
|
||||
Margin = new Thickness(0, 0, 10, 0),
|
||||
IsDefault = true
|
||||
};
|
||||
|
||||
var cancelButton = new Button
|
||||
{
|
||||
Content = "Cancelar",
|
||||
Width = 75,
|
||||
Height = 23,
|
||||
IsCancel = true
|
||||
};
|
||||
|
||||
buttonPanel.Children.Add(okButton);
|
||||
buttonPanel.Children.Add(cancelButton);
|
||||
|
||||
grid.Children.Add(promptLabel);
|
||||
grid.Children.Add(inputBox);
|
||||
grid.Children.Add(buttonPanel);
|
||||
|
||||
dialog.Content = grid;
|
||||
|
||||
var result = new InputDialogResult();
|
||||
|
||||
okButton.Click += (s, e) =>
|
||||
{
|
||||
result.Result = inputBox.Text;
|
||||
result.IsOk = true;
|
||||
dialog.Close();
|
||||
};
|
||||
|
||||
cancelButton.Click += (s, e) =>
|
||||
{
|
||||
result.IsOk = false;
|
||||
dialog.Close();
|
||||
};
|
||||
|
||||
inputBox.Focus();
|
||||
dialog.ShowDialog();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
101
MainWindow.xaml
101
MainWindow.xaml
|
@ -3,30 +3,14 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewmodels="clr-namespace:DirectoryCreator.ViewModels" mc:Ignorable="d" Title="Crear Directorios Base"
|
||||
Height="300" Width="500" WindowStartupLocation="CenterScreen">
|
||||
Height="450" Width="700" WindowStartupLocation="CenterScreen" MinWidth="600" MinHeight="400">
|
||||
|
||||
<Window.Icon>
|
||||
<BitmapImage UriSource="/Assets/app.png" />
|
||||
</Window.Icon>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Barra superior con el tema -->
|
||||
<Border Background="{DynamicResource SecondaryBackground}" Padding="5">
|
||||
<DockPanel LastChildFill="True">
|
||||
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="Tema Oscuro" Margin="0,0,5,0" VerticalAlignment="Center" />
|
||||
<CheckBox IsChecked="{Binding IsDarkTheme}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<!-- Contenido principal -->
|
||||
<Grid Grid.Row="1" Margin="20">
|
||||
<Border BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Margin="0">
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="20" />
|
||||
|
@ -35,33 +19,72 @@
|
|||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="20" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="20" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal">
|
||||
<TextBlock Text="Configuración:" VerticalAlignment="Center" />
|
||||
<ComboBox Margin="10,0" ItemsSource="{Binding AvailableConfigurations}"
|
||||
SelectedItem="{Binding SelectedConfiguration}" DisplayMemberPath="Description" MinWidth="200"
|
||||
VerticalContentAlignment="Center" />
|
||||
<Button Content="Editar Configuraciones" Command="{Binding EditConfigurationsCommand}" />
|
||||
</StackPanel>
|
||||
<!-- Configuration Section -->
|
||||
<Border Grid.Row="0" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Padding="15">
|
||||
<DockPanel>
|
||||
<TextBlock Text="Configuración:" VerticalAlignment="Center" MinWidth="100" />
|
||||
<Button Content="Editar" Command="{Binding EditConfigurationsCommand}" DockPanel.Dock="Right"
|
||||
Padding="20,8" Margin="10,0,0,0" />
|
||||
<ComboBox ItemsSource="{Binding AvailableConfigurations}"
|
||||
SelectedItem="{Binding SelectedConfiguration}" DisplayMemberPath="Description" Height="30"
|
||||
Margin="5,0" />
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<TextBlock Grid.Row="2" Text="Last Project:" />
|
||||
<TextBlock Grid.Row="2" Margin="100,0,0,0" Text="{Binding LastProjectNumber}" />
|
||||
<!-- Project Management Section -->
|
||||
<Border Grid.Row="2" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Padding="15">
|
||||
<DockPanel>
|
||||
<TextBlock Text="Proyecto Actual:" VerticalAlignment="Center" MinWidth="100" />
|
||||
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" Margin="10,0,0,0">
|
||||
<Button Content="Renombrar" Command="{Binding RenameProjectCommand}" Padding="15,8"
|
||||
Margin="0,0,10,0" />
|
||||
<Button Content="Eliminar" Command="{Binding DeleteProjectCommand}" Padding="15,8"
|
||||
Background="LightPink" />
|
||||
</StackPanel>
|
||||
<ComboBox ItemsSource="{Binding ExistingProjects}" SelectedItem="{Binding SelectedProject}"
|
||||
Height="30" Margin="5,0" />
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<TextBlock Grid.Row="4" Text="Base Path:" />
|
||||
<TextBlock Grid.Row="4" Margin="100,0,0,0" Text="{Binding BasePath}" />
|
||||
<!-- Project Info Section -->
|
||||
<Border Grid.Row="4" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Padding="15">
|
||||
<StackPanel>
|
||||
<DockPanel Margin="0,0,0,10">
|
||||
<TextBlock Text="Último Proyecto:" MinWidth="100" />
|
||||
<TextBlock Text="{Binding LastProjectNumber}" Margin="5,0" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
<TextBlock Text="Ruta Base:" MinWidth="100" />
|
||||
<Button Content="Abrir" Command="{Binding OpenBaseFolderCommand}" DockPanel.Dock="Right"
|
||||
Padding="15,5" />
|
||||
<TextBlock Text="{Binding BasePath}" Margin="5,0" TextWrapping="Wrap" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<TextBlock Grid.Row="6" Text="New Project Name:" />
|
||||
<TextBox Grid.Row="6" Margin="100,0,0,0"
|
||||
Text="{Binding NewProjectName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<!-- New Project Section -->
|
||||
<Border Grid.Row="6" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Padding="15">
|
||||
<DockPanel>
|
||||
<TextBlock Text="Nuevo Proyecto:" VerticalAlignment="Center" MinWidth="100" />
|
||||
<TextBox Text="{Binding NewProjectName, UpdateSourceTrigger=PropertyChanged}" Height="30"
|
||||
Margin="5,0" />
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<StackPanel Grid.Row="8" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Content="Abrir Carpeta Base" Command="{Binding OpenBaseFolderCommand}" Padding="20,10"
|
||||
Margin="0,0,10,0" />
|
||||
<Button Content="Crear Directorios" Command="{Binding CreateDirectoriesCommand}" Padding="20,10" />
|
||||
</StackPanel>
|
||||
<!-- Actions Section -->
|
||||
<Border Grid.Row="8" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Padding="15">
|
||||
<DockPanel>
|
||||
<CheckBox Content="Tema Oscuro" IsChecked="{Binding IsDarkTheme}" VerticalAlignment="Center" />
|
||||
<Button Content="Crear Directorios" Command="{Binding CreateDirectoriesCommand}"
|
||||
DockPanel.Dock="Right" Padding="20,8" Background="{DynamicResource ButtonBackground}" />
|
||||
</DockPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Window>
|
|
@ -111,16 +111,6 @@ namespace DirectoryCreator.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedConfigurationChanged(FolderConfig value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
currentConfig = value;
|
||||
BasePath = value.BasePath;
|
||||
LoadLastProjectNumber();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenBaseFolder()
|
||||
{
|
||||
|
@ -241,6 +231,195 @@ namespace DirectoryCreator.ViewModels
|
|||
Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<string> existingProjects = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private string selectedProject;
|
||||
|
||||
private void LoadExistingProjects()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(BasePath) || !Directory.Exists(BasePath))
|
||||
{
|
||||
ExistingProjects = new ObservableCollection<string>();
|
||||
return;
|
||||
}
|
||||
|
||||
var directories = Directory.GetDirectories(BasePath)
|
||||
.Select(d => new DirectoryInfo(d).Name)
|
||||
.OrderByDescending(name => name)
|
||||
.ToList();
|
||||
|
||||
ExistingProjects = new ObservableCollection<string>(directories);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error al cargar proyectos existentes: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
ExistingProjects = new ObservableCollection<string>();
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedConfigurationChanged(FolderConfig value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
currentConfig = value;
|
||||
BasePath = value.BasePath;
|
||||
LoadLastProjectNumber();
|
||||
LoadExistingProjects(); // Cargar proyectos existentes cuando cambia la configuración
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task RenameProject()
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedProject))
|
||||
{
|
||||
MessageBox.Show("Por favor seleccione un proyecto para renombrar", "Advertencia", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = Microsoft.Windows.Controls.InputDialog.Show(
|
||||
"Renombrar Proyecto",
|
||||
"Ingrese el nuevo nombre del proyecto:",
|
||||
SelectedProject);
|
||||
|
||||
if (result.IsOk)
|
||||
{
|
||||
string newName = result.Result;
|
||||
if (string.IsNullOrWhiteSpace(newName))
|
||||
{
|
||||
MessageBox.Show("El nombre no puede estar vacío", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var structure in currentConfig.FolderStructures)
|
||||
{
|
||||
var basePath = structure.BasePath.Replace("{year}", DateTime.Now.Year.ToString());
|
||||
var oldPath = Path.Combine(basePath, SelectedProject);
|
||||
var newPath = Path.Combine(basePath, newName);
|
||||
|
||||
if (Directory.Exists(oldPath))
|
||||
{
|
||||
if (Directory.Exists(newPath))
|
||||
{
|
||||
MessageBox.Show($"Ya existe un directorio con el nombre: {newName}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Directory.Move(oldPath, newPath);
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("Proyecto renombrado exitosamente!", "Éxito", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
LoadExistingProjects(); // Recargar la lista de proyectos
|
||||
SelectedProject = newName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error al renombrar el proyecto: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Agregar este método en la clase MainWindowViewModel
|
||||
[RelayCommand]
|
||||
private void DeleteProject()
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedProject))
|
||||
{
|
||||
MessageBox.Show("Por favor seleccione un proyecto para eliminar", "Advertencia", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Recopilar todos los directorios a verificar
|
||||
List<string> directoriesToCheck = new List<string>();
|
||||
List<string> nonEmptyDirectories = new List<string>();
|
||||
|
||||
// Primero encontrar todos los directorios del proyecto
|
||||
foreach (var structure in currentConfig.FolderStructures)
|
||||
{
|
||||
var basePath = structure.BasePath.Replace("{year}", DateTime.Now.Year.ToString());
|
||||
var projectPath = Path.Combine(basePath, SelectedProject);
|
||||
|
||||
if (Directory.Exists(projectPath))
|
||||
{
|
||||
directoriesToCheck.Add(projectPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (!directoriesToCheck.Any())
|
||||
{
|
||||
MessageBox.Show("No se encontraron directorios para eliminar.", "Información", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// Verificar que todos los directorios estén vacíos
|
||||
foreach (var directory in directoriesToCheck)
|
||||
{
|
||||
if (!IsDirectoryEmpty(directory))
|
||||
{
|
||||
nonEmptyDirectories.Add(directory);
|
||||
}
|
||||
}
|
||||
|
||||
// Si hay directorios con contenido, mostrar mensaje y cancelar
|
||||
if (nonEmptyDirectories.Any())
|
||||
{
|
||||
string message = "Los siguientes directorios contienen archivos y no pueden ser eliminados:\n\n";
|
||||
message += string.Join("\n", nonEmptyDirectories);
|
||||
message += "\n\nDebe vaciar estos directorios antes de poder eliminar el proyecto.";
|
||||
MessageBox.Show(message, "Directorios no vacíos", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
// Si todos están vacíos, pedir confirmación
|
||||
var result = MessageBox.Show(
|
||||
$"Se eliminarán los siguientes directorios:\n\n{string.Join("\n", directoriesToCheck)}\n\n¿Está seguro que desea continuar?",
|
||||
"Confirmar eliminación",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
// Eliminar todos los directorios
|
||||
foreach (var directory in directoriesToCheck)
|
||||
{
|
||||
if (Directory.Exists(directory))
|
||||
{
|
||||
Directory.Delete(directory, false); // false porque ya sabemos que están vacíos
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("Proyecto eliminado exitosamente!", "Éxito", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
LoadExistingProjects(); // Recargar la lista de proyectos
|
||||
SelectedProject = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error al eliminar el proyecto: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsDirectoryEmpty(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return !Directory.EnumerateFileSystemEntries(path, "*", SearchOption.AllDirectories).Any();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CreateDirectories()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue