Browse Source

Make selection and most grid items to work. Grid splitter works also.

Known errors:
- OK button does nothing
- images and resources code is not working
pull/517/head^2
Ciprian Khlud 11 years ago
parent
commit
bd3c023dd9
  1. 3
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileTemplateItem.cs
  2. 98
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileViewModel.cs
  3. 33
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileWindow.xaml
  4. 17
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileWindow.xaml.cs

3
src/Main/Base/Project/Src/Gui/Dialogs/NewFileTemplateItem.cs

@ -11,5 +11,8 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
public FileTemplate Template { get; private set; } public FileTemplate Template { get; private set; }
public string DisplayName { get { return Template.DisplayName; } }
public string Description { get { return Template.Description; } }
public string Name { get { return Template.Name; } }
} }
} }

98
src/Main/Base/Project/Src/Gui/Dialogs/NewFileViewModel.cs

@ -9,6 +9,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Templates; using ICSharpCode.SharpDevelop.Templates;
using ICSharpCode.SharpDevelop.Widgets; using ICSharpCode.SharpDevelop.Widgets;
@ -18,16 +19,71 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
public class NewFileViewModel : ViewModelBase public class NewFileViewModel : ViewModelBase
{ {
#region Backing properties
private NewFileCategory _selectedCategory;
private string _searchFor;
private ObservableCollection<NewFileTemplateItem> _allTemplate;
private NewFileTemplateItem _selectedItem;
#endregion
public NewFileViewModel() public NewFileViewModel()
{ {
AllTemplate = new ObservableCollection<NewFileTemplateItem>(); _allTemplate = new ObservableCollection<NewFileTemplateItem>();
Templates = new ObservableCollection<NewFileCategory>()
{ Icons = new Dictionary<IImage, int>();
new NewFileCategory("Empty file")
};
Icons= new Dictionary<IImage, int>();
Categories = new ObservableCollection<NewFileCategory>(); Categories = new ObservableCollection<NewFileCategory>();
AllFileTemplates = new NewFileCategory("All");
Categories.Add(AllFileTemplates);
}
public NewFileCategory AllFileTemplates { get; set; }
public NewFileCategory SelectedCategory
{
get { return _selectedCategory; }
set
{
_selectedCategory = value;
OnPropertyChanged();
}
}
public ObservableCollection<NewFileTemplateItem> SelectedTemplates
{
get
{
UpdatedSelection();
return _allTemplate;
}
}
public void UpdatedSelection()
{
_allTemplate.Clear();
var selectedCategory = _selectedCategory;
if (selectedCategory != null)
{
foreach (var item in selectedCategory.Templates)
{
_allTemplate.Add(item);
}
}
} }
public NewFileTemplateItem SelectedItem
{
get { return _selectedItem; }
set
{
_selectedItem = value;
OnPropertyChanged();
OnPropertyChanged("Description");
}
}
public IProject Project public IProject Project
{ {
get; get;
@ -48,14 +104,30 @@ namespace ICSharpCode.SharpDevelop.Gui
public FileTemplateResult Result { get; set; } public FileTemplateResult Result { get; set; }
public string SearchFor { get; set; } public string SearchFor
public string Description { get; set; } {
public ObservableCollection<NewFileTemplateItem> AllTemplate { get; set; } get { return _searchFor; }
set { _searchFor = value; }
}
public Dictionary<IImage, int> Icons { public string Description
get; {
set; get
} {
return SelectedItem == null
? string.Empty
: SelectedItem.Template.Description;
}
set { }
}
public Dictionary<IImage, int> Icons
{
get;
set;
}
public ObservableCollection<NewFileCategory> Categories { get; set; } public ObservableCollection<NewFileCategory> Categories { get; set; }

33
src/Main/Base/Project/Src/Gui/Dialogs/NewFileWindow.xaml

@ -22,7 +22,7 @@
<ColumnDefinition Width="5" /> <ColumnDefinition Width="5" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions > </Grid.ColumnDefinitions >
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <Grid >
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition /> <RowDefinition />
@ -30,7 +30,9 @@
<TextBlock Text="Categories" /> <TextBlock Text="Categories" />
<TreeView Grid.Row="1" <TreeView Grid.Row="1"
ItemsSource="{Binding Categories}" ItemsSource="{Binding Categories}"
x:Name="categoryTreeView"> x:Name="categoryTreeView"
SelectedItemChanged="CategoryTreeView_SelectedItemChanged"
>
<TreeView.ItemTemplate> <TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}"> <HierarchicalDataTemplate ItemsSource="{Binding Children}">
@ -39,9 +41,9 @@
</TreeView.ItemTemplate> </TreeView.ItemTemplate>
</TreeView> </TreeView>
</Grid> </Grid>
<GridSplitter Grid.Column="1" Width="5" /> <GridSplitter Grid.Column="1" ResizeDirection="Columns" Width="5" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
<Grid Grid.Column="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" > <Grid Grid.Column="2" >
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -50,10 +52,15 @@
<TextBlock Text="Search:" VerticalAlignment="Center" /> <TextBlock Text="Search:" VerticalAlignment="Center" />
<TextBox Text="{Binding SearchFor}" Margin="2" Width="100"></TextBox> <TextBox Text="{Binding SearchFor}" Margin="2" Width="100"></TextBox>
</StackPanel> </StackPanel>
<ListBox Grid.Row="1" ItemsSource="{Binding Templates}"> <ListBox Grid.Row="1" ItemsSource="{Binding SelectedTemplates}"
SelectedItem="{Binding SelectedItem}"
>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding DisplayName}"></TextBlock> <StackPanel>
<Label Content="{Binding DisplayName}" FontWeight="Bold" />
<Label Content="{Binding Description}" />
</StackPanel>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
@ -61,8 +68,16 @@
</Grid> </Grid>
<StackPanel Grid.Row="2"> <StackPanel Grid.Row="2">
<TextBlock Text="{Binding Description}" ></TextBlock> <Label Content="{Binding Description}" />
<widgets:UniformGridWithSpacing Columns="2" HorizontalAlignment="Right" Margin="0,4,12,12"> <Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="File name: " VerticalAlignment="Center" />
<TextBox Grid.Column="1" Text="{Binding ItemFileName}" x:Name="fileNameTextBox" />
</Grid>
<widgets:UniformGridWithSpacing Columns="2" HorizontalAlignment="Right" Margin="0,4,12,12">
<Button <Button
Content="{core:Localize Global.OKButtonText}" Content="{core:Localize Global.OKButtonText}"
IsDefault="True" IsDefault="True"

17
src/Main/Base/Project/Src/Gui/Dialogs/NewFileWindow.xaml.cs

@ -41,6 +41,15 @@ namespace ICSharpCode.SharpDevelop.Gui
ViewModel.Project = project; ViewModel.Project = project;
ViewModel.BasePath = basePath; ViewModel.BasePath = basePath;
ViewModel.AllowUntitledFiles = basePath == null; ViewModel.AllowUntitledFiles = basePath == null;
if(ViewModel.AllowUntitledFiles)
{
categoryTreeView.Focus();
}
else
{
fileNameTextBox.Focus();
}
InitializeTemplates(templateCategories, ViewModel.Categories); InitializeTemplates(templateCategories, ViewModel.Categories);
} }
@ -74,7 +83,8 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
ViewModel.Icons[titem.Template.Icon] = 0; // "create template icon" ViewModel.Icons[titem.Template.Icon] = 0; // "create template icon"
} }
ViewModel.AllTemplate.Add(titem); ViewModel.AllFileTemplates.Templates.Add(titem);
ViewModel.SelectedTemplates.Add(titem);
node.Templates.Add(titem); node.Templates.Add(titem);
} }
return node; return node;
@ -88,5 +98,10 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
Close(); Close();
} }
void CategoryTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
ViewModel.SelectedCategory = (NewFileCategory)categoryTreeView.SelectedItem;
ViewModel.UpdatedSelection();
}
} }
} }
Loading…
Cancel
Save