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. 31
      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 @@ -11,5 +11,8 @@ namespace ICSharpCode.SharpDevelop.Gui
}
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 @@ @@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Templates;
using ICSharpCode.SharpDevelop.Widgets;
@ -18,16 +19,71 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -18,16 +19,71 @@ namespace ICSharpCode.SharpDevelop.Gui
{
public class NewFileViewModel : ViewModelBase
{
#region Backing properties
private NewFileCategory _selectedCategory;
private string _searchFor;
private ObservableCollection<NewFileTemplateItem> _allTemplate;
private NewFileTemplateItem _selectedItem;
#endregion
public NewFileViewModel()
{
AllTemplate = new ObservableCollection<NewFileTemplateItem>();
Templates = new ObservableCollection<NewFileCategory>()
{
new NewFileCategory("Empty file")
};
Icons= new Dictionary<IImage, int>();
_allTemplate = new ObservableCollection<NewFileTemplateItem>();
Icons = new Dictionary<IImage, int>();
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
{
get;
@ -48,14 +104,30 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -48,14 +104,30 @@ namespace ICSharpCode.SharpDevelop.Gui
public FileTemplateResult Result { get; set; }
public string SearchFor { get; set; }
public string Description { get; set; }
public ObservableCollection<NewFileTemplateItem> AllTemplate { get; set; }
public string SearchFor
{
get { return _searchFor; }
set { _searchFor = value; }
}
public string Description
{
get
{
return SelectedItem == null
? string.Empty
: SelectedItem.Template.Description;
}
set { }
}
public Dictionary<IImage, int> Icons {
get;
set;
}
public Dictionary<IImage, int> Icons
{
get;
set;
}
public ObservableCollection<NewFileCategory> Categories { get; set; }

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

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

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

@ -41,6 +41,15 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -41,6 +41,15 @@ namespace ICSharpCode.SharpDevelop.Gui
ViewModel.Project = project;
ViewModel.BasePath = basePath;
ViewModel.AllowUntitledFiles = basePath == null;
if(ViewModel.AllowUntitledFiles)
{
categoryTreeView.Focus();
}
else
{
fileNameTextBox.Focus();
}
InitializeTemplates(templateCategories, ViewModel.Categories);
}
@ -74,7 +83,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -74,7 +83,8 @@ namespace ICSharpCode.SharpDevelop.Gui
{
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);
}
return node;
@ -88,5 +98,10 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -88,5 +98,10 @@ namespace ICSharpCode.SharpDevelop.Gui
{
Close();
}
void CategoryTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
ViewModel.SelectedCategory = (NewFileCategory)categoryTreeView.SelectedItem;
ViewModel.UpdatedSelection();
}
}
}
Loading…
Cancel
Save