Browse Source

Convert Python tools options panel to WPF.

pull/30/head
Matt Ward 13 years ago
parent
commit
edeab80387
  1. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  2. 51
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.cs
  3. 44
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.xaml
  4. 71
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.xaml.cs
  5. 82
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonOptionsPanelTestFixture.cs
  6. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

16
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj

@ -128,6 +128,10 @@ @@ -128,6 +128,10 @@
<Compile Include="Src\PythonModuleCompletionItemsFactory.cs" />
<Compile Include="Src\PythonImportResolver.cs" />
<Compile Include="Src\PythonNamespaceResolver.cs" />
<Compile Include="Src\PythonOptionsPanel.xaml.cs">
<DependentUpon>PythonOptionsPanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\PythonProperty.cs" />
<Compile Include="Src\PythonPropertyAssignment.cs" />
<Compile Include="Src\PythonResolverContext.cs" />
@ -178,7 +182,6 @@ @@ -178,7 +182,6 @@
<Compile Include="Src\PythonImportExpressionContext.cs" />
<Compile Include="Src\PythonLanguageProperties.cs" />
<Compile Include="Src\PythonImportModuleResolveResult.cs" />
<Compile Include="Src\PythonOptionsPanel.cs" />
<Compile Include="Src\PythonParser.cs" />
<Compile Include="Src\PythonProject.cs" />
<Compile Include="Src\PythonPropertyValueAssignment.cs" />
@ -278,11 +281,19 @@ @@ -278,11 +281,19 @@
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Analysis\UnitTesting\UnitTesting.csproj">
<Project>{1F261725-6318-4434-A1B1-6C70CE4CD324}</Project>
<Name>UnitTesting</Name>
@ -299,4 +310,7 @@ @@ -299,4 +310,7 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="Src\PythonOptionsPanel.xaml" />
</ItemGroup>
</Project>

51
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.cs

@ -1,51 +0,0 @@ @@ -1,51 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Gui.OptionPanels;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Panel that displays the python options.
/// </summary>
public class PythonOptionsPanel : XmlFormsOptionPanel
{
PythonAddInOptions options;
TextBox pythonFileNameTextBox;
TextBox pythonLibraryPathTextBox;
public PythonOptionsPanel() : this(new PythonAddInOptions())
{
}
public PythonOptionsPanel(PythonAddInOptions options)
{
this.options = options;
}
public override void LoadPanelContents()
{
SetupFromXmlStream(GetType().Assembly.GetManifestResourceStream("ICSharpCode.PythonBinding.Resources.PythonOptionsPanel.xfrm"));
pythonFileNameTextBox = (TextBox)ControlDictionary["pythonFileNameTextBox"];
pythonFileNameTextBox.Text = options.PythonFileName;
pythonLibraryPathTextBox = (TextBox)ControlDictionary["pythonLibraryPathTextBox"];
pythonLibraryPathTextBox.Text = options.PythonLibraryPath;
ConnectBrowseButton("browseButton", "pythonFileNameTextBox", "${res:SharpDevelop.FileFilter.ExecutableFiles}|*.exe", TextBoxEditMode.EditRawProperty);
}
public override bool StorePanelContents()
{
options.PythonFileName = pythonFileNameTextBox.Text;
options.PythonLibraryPath = pythonLibraryPathTextBox.Text;
return true;
}
}
}

44
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.xaml

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
<gui:OptionPanel
x:Class="ICSharpCode.PythonBinding.PythonOptionsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<GroupBox
Header="Python Configuration"
Padding="4">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Command:"/>
<TextBox
Grid.Column="1"
Text="{Binding PythonFileName}"/>
<Button
Grid.Column="2"
Content="..."
Command="{Binding BrowseCommand}"
Padding="4, 0"
Margin="4,0"/>
<Label
Grid.Row="1"
Content="Path:"/>
<TextBox
Grid.Column="1"
Grid.ColumnSpan="2"
Grid.Row="1"
Text="{Binding PythonLibraryPath}"/>
</Grid>
</GroupBox>
</StackPanel>
</gui:OptionPanel>

71
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.xaml.cs

@ -0,0 +1,71 @@ @@ -0,0 +1,71 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Widgets;
using Microsoft.Win32;
using SDCore = ICSharpCode.Core;
namespace ICSharpCode.PythonBinding
{
public partial class PythonOptionsPanel : OptionPanel, INotifyPropertyChanged
{
PythonAddInOptions options = new PythonAddInOptions();
string pythonFileName;
string pythonLibraryPath;
public PythonOptionsPanel()
{
InitializeComponent();
this.pythonFileName = options.PythonFileName;
this.pythonLibraryPath = options.PythonLibraryPath;
this.BrowseCommand = new RelayCommand(Browse);
this.DataContext = this;
}
public ICommand BrowseCommand { get; private set; }
public string PythonFileName {
get { return pythonFileName; }
set {
pythonFileName = value;
OnPropertyChanged("PythonFileName");
}
}
public string PythonLibraryPath {
get { return pythonLibraryPath; }
set { pythonLibraryPath = value; }
}
void Browse()
{
var dialog = new OpenFileDialog();
dialog.Filter = SDCore.StringParser.Parse("${res:SharpDevelop.FileFilter.ExecutableFiles}|*.exe");
if (dialog.ShowDialog() ?? false) {
PythonFileName = dialog.FileName;
}
}
public override bool SaveOptions()
{
options.PythonFileName = pythonFileName;
options.PythonLibraryPath = pythonLibraryPath;
return true;
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string name)
{
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
}

82
src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonOptionsPanelTestFixture.cs

@ -1,82 +0,0 @@ @@ -1,82 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Gui.OptionPanels;
using NUnit.Framework;
namespace PythonBinding.Tests.Gui
{
/// <summary>
/// Tests the PythonOptionsPanel.
/// </summary>
[TestFixture]
public class PythonOptionsPanelTestFixture
{
PythonOptionsPanel optionsPanel;
Properties properties;
PythonAddInOptions options;
TextBox fileNameTextBox;
TextBox pythonLibraryPathTextBox;
[SetUp]
public void SetUp()
{
properties = new Properties();
options = new PythonAddInOptions(properties);
options.PythonFileName = @"C:\Python\ipy.exe";
options.PythonLibraryPath = @"C:\Python26\lib";
optionsPanel = new PythonOptionsPanel(options);
optionsPanel.LoadPanelContents();
fileNameTextBox = (TextBox)optionsPanel.ControlDictionary["pythonFileNameTextBox"];
pythonLibraryPathTextBox = (TextBox)optionsPanel.ControlDictionary["pythonLibraryPathTextBox"];
}
[TearDown]
public void TearDown()
{
optionsPanel.Dispose();
}
[Test]
public void PythonFileNameDisplayed()
{
Assert.AreEqual(@"C:\Python\ipy.exe", fileNameTextBox.Text);
}
[Test]
public void PythonLibraryPathIsDisplayed()
{
Assert.AreEqual(@"C:\Python26\lib", pythonLibraryPathTextBox.Text);
}
[Test]
public void PanelIsOptionsPanel()
{
Assert.IsNotNull(optionsPanel as XmlFormsOptionPanel);
}
[Test]
public void SavingOptionsUpdatesIronPythonFileName()
{
string fileName = @"C:\Program Files\IronPython\ipy.exe";
fileNameTextBox.Text = fileName;
optionsPanel.StorePanelContents();
Assert.AreEqual(fileName, options.PythonFileName);
}
[Test]
public void SavingOptionsUpdatesIronPythonLibraryPath()
{
string path = @"c:\Program Files\Python\lib";
pythonLibraryPathTextBox.Text = path;
optionsPanel.StorePanelContents();
Assert.AreEqual(path, options.PythonLibraryPath);
}
}
}

5
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -322,7 +322,6 @@ @@ -322,7 +322,6 @@
<Compile Include="Gui\DebugPythonCommandTests.cs" />
<Compile Include="Gui\FormsDesignerDisplayBindingTestFixture.cs" />
<Compile Include="Gui\PythonFormattingStrategyTests.cs" />
<Compile Include="Gui\PythonOptionsPanelTestFixture.cs" />
<Compile Include="Gui\RunPythonCommandTests.cs" />
<Compile Include="Parsing\ClassWithBaseClassTestFixture.cs" />
<Compile Include="Parsing\InvalidCastInPythonParserTestFixture.cs" />
@ -467,6 +466,10 @@ @@ -467,6 +466,10 @@
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj">
<Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project>
<Name>ICSharpCode.Core.WinForms</Name>

Loading…
Cancel
Save