5 changed files with 240 additions and 8 deletions
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<UserControl |
||||
x:Class="ICSharpCode.SharpDevelop.Gui.StringListEditorXaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" xmlns:core="http://icsharpcode.net/sharpdevelop/core"> |
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition |
||||
Height="30"></RowDefinition> |
||||
<RowDefinition |
||||
Height="30"></RowDefinition> |
||||
<RowDefinition |
||||
Height="30"></RowDefinition> |
||||
<RowDefinition |
||||
Height="30"></RowDefinition> |
||||
<RowDefinition Height="150"></RowDefinition> |
||||
</Grid.RowDefinitions> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition |
||||
Width="300"></ColumnDefinition> |
||||
<ColumnDefinition |
||||
Width="40"></ColumnDefinition> |
||||
</Grid.ColumnDefinitions> |
||||
<Label |
||||
x:Name="title" |
||||
Content="Title"></Label> |
||||
<TextBox |
||||
x:Name="editTextBox" |
||||
Margin="5,3,5,3" |
||||
TextChanged="EditTextBox_TextChanged" |
||||
Grid.Row="1"></TextBox> |
||||
<Button |
||||
x:Name="browseButton" |
||||
Content="..." |
||||
Visibility="Hidden" |
||||
Margin="0,3,5,0" |
||||
Grid.Column="1" |
||||
Grid.Row="1" |
||||
Click="BrowseButtonClick" |
||||
/> |
||||
<widgets:StackPanelWithSpacing |
||||
Orientation="Horizontal" |
||||
Margin="5,3,5,3" |
||||
SpaceBetweenItems="5" |
||||
Grid.Row="2"> |
||||
<Button |
||||
x:Name="addButton" |
||||
IsEnabled="False" |
||||
|
||||
Click="AddButton_Click" |
||||
Content="{core:Localize Global.AddButtonText}" |
||||
Style="{x:Static core:GlobalStyles.ButtonStyle}"></Button> |
||||
<Button |
||||
x:Name="updateButton" |
||||
IsEnabled="False" |
||||
|
||||
Click="UpdateButton_Click" |
||||
Content="{core:Localize Global.UpdateButtonText}" |
||||
Style="{x:Static core:GlobalStyles.ButtonStyle}"></Button> |
||||
<Button |
||||
x:Name="removeButton" |
||||
Visibility="Hidden" |
||||
|
||||
Content="{core:Localize Global.DeleteButtonText}" |
||||
Style="{x:Static core:GlobalStyles.ButtonStyle}"></Button> |
||||
</widgets:StackPanelWithSpacing> |
||||
<Label |
||||
x:Name="listlabel" |
||||
Grid.Row="3" |
||||
Content="List"></Label> |
||||
<ListBox |
||||
x:Name="listBox" |
||||
Margin="5,3,5,3" |
||||
SelectionChanged="ListBox_SelectionChanged" |
||||
Grid.Row="4"></ListBox> |
||||
</Grid> |
||||
</UserControl> |
@ -0,0 +1,147 @@
@@ -0,0 +1,147 @@
|
||||
/* |
||||
* Erstellt mit SharpDevelop. |
||||
* Benutzer: Peter Forstmeier |
||||
* Datum: 23.03.2012 |
||||
* Zeit: 19:44 |
||||
* |
||||
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern. |
||||
*/ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using Microsoft.Win32; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for StringListEditorXaml.xaml
|
||||
/// </summary>
|
||||
public partial class StringListEditorXaml : UserControl |
||||
{ |
||||
bool browseForDirectory; |
||||
|
||||
public event EventHandler ListChanged; |
||||
|
||||
public string TitleText { |
||||
get { return this.title.Content.ToString(); } |
||||
set { this.title.Content = value;} |
||||
} |
||||
|
||||
|
||||
public string ListCaption |
||||
{ |
||||
get {return this.listlabel.Content.ToString();} |
||||
set {this.listlabel.Content = value;} |
||||
} |
||||
|
||||
|
||||
public string AddButtonText { |
||||
get {return addButton.Content.ToString();} |
||||
set {addButton.Content = value;} |
||||
} |
||||
|
||||
|
||||
public bool BrowseForDirectory { |
||||
get { |
||||
return browseForDirectory; |
||||
} |
||||
set { |
||||
browseForDirectory = value; |
||||
if (browseForDirectory) { |
||||
browseButton.Visibility = Visibility.Visible; |
||||
} else { |
||||
browseButton.Visibility = Visibility.Hidden; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public bool AutoAddAfterBrowse {get;set;} |
||||
|
||||
void AddButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
editTextBox.Text = editTextBox.Text.Trim(); |
||||
if (editTextBox.Text.Length > 0) { |
||||
int index = listBox.Items.IndexOf(editTextBox.Text); |
||||
if (index < 0) { |
||||
index = listBox.Items.Add(editTextBox.Text); |
||||
OnListChanged(EventArgs.Empty); |
||||
} |
||||
listBox.SelectedIndex = index; |
||||
} |
||||
} |
||||
|
||||
|
||||
void UpdateButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
editTextBox.Text = editTextBox.Text.Trim(); |
||||
if (editTextBox.Text.Length > 0) { |
||||
listBox.Items[listBox.SelectedIndex] = editTextBox.Text; |
||||
OnListChanged(EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
|
||||
private void BrowseButtonClick (object sender, EventArgs e) |
||||
{ |
||||
using (System.Windows.Forms.FolderBrowserDialog fdiag = FileService.CreateFolderBrowserDialog("${res:Dialog.ProjectOptions.SelectFolderTitle}")) |
||||
{ |
||||
if (fdiag.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
||||
{ |
||||
string path = fdiag.SelectedPath; |
||||
if (!path.EndsWith("\\") && !path.EndsWith("/")) |
||||
path += "\\"; |
||||
editTextBox.Text = path; |
||||
|
||||
if (AutoAddAfterBrowse) { |
||||
AddButton_Click(null, null); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
void EditTextBox_TextChanged(object sender, TextChangedEventArgs e) |
||||
{ |
||||
addButton.IsEnabled = editTextBox.Text.Length > 0; |
||||
updateButton.IsEnabled = listBox.SelectedIndex >= 0 && editTextBox.Text.Length > 0; |
||||
} |
||||
|
||||
|
||||
protected virtual void OnListChanged(EventArgs e) |
||||
{ |
||||
|
||||
if (ListChanged != null) { |
||||
ListChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
|
||||
void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) |
||||
{ |
||||
if (listBox.SelectedIndex >= 0) { |
||||
editTextBox.Text = listBox.Items[listBox.SelectedIndex].ToString(); |
||||
} |
||||
// moveUpButton.Enabled = listBox.SelectedIndex > 0;
|
||||
// moveDownButton.Enabled = listBox.SelectedIndex >= 0 && listBox.SelectedIndex < listBox.Items.Count - 1;
|
||||
// removeButton.IsEnabled = deleteButton.Enabled = listBox.SelectedIndex >= 0;
|
||||
updateButton.IsEnabled = listBox.SelectedIndex >= 0 && editTextBox.Text.Length > 0; |
||||
} |
||||
|
||||
|
||||
public StringListEditorXaml() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue