Browse Source

Add WPF ToolBar ComboBox.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0wpf@3456 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
88fe850807
  1. 17
      src/AddIns/Misc/SearchAndReplace/Project/Commands/SearchToolbarCommands.cs
  2. 9
      src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj
  3. 43
      src/Main/Base/Project/Src/Commands/ChooseLayoutCommand.cs
  4. 1
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  5. 31
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarComboBox.cs
  6. 3
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs

17
src/AddIns/Misc/SearchAndReplace/Project/Commands/SearchToolbarCommands.cs

@ -6,9 +6,9 @@
// </file> // </file>
using System; using System;
using System.Windows.Forms; using System.Windows.Controls;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.WinForms; using System.Windows.Input;
namespace SearchAndReplace namespace SearchAndReplace
{ {
@ -18,6 +18,7 @@ namespace SearchAndReplace
public class FindComboBox : AbstractComboBoxCommand public class FindComboBox : AbstractComboBoxCommand
{ {
ComboBox comboBox; ComboBox comboBox;
public FindComboBox() public FindComboBox()
{ {
} }
@ -31,9 +32,9 @@ namespace SearchAndReplace
comboBox.Text = SearchOptions.FindPattern; comboBox.Text = SearchOptions.FindPattern;
} }
void OnKeyPress(object sender, KeyPressEventArgs e) void OnKeyPress(object sender, KeyEventArgs e)
{ {
if (e.KeyChar == '\r') { if (e.Key == Key.Enter) {
CommitSearch(); CommitSearch();
e.Handled = true; e.Handled = true;
} }
@ -60,10 +61,10 @@ namespace SearchAndReplace
protected override void OnOwnerChanged(EventArgs e) protected override void OnOwnerChanged(EventArgs e)
{ {
base.OnOwnerChanged(e); base.OnOwnerChanged(e);
ToolBarComboBox toolbarItem = (ToolBarComboBox)Owner; comboBox = (ComboBox)Owner;
comboBox = toolbarItem.ComboBox; comboBox.IsEditable = true;
comboBox.DropDownStyle = ComboBoxStyle.DropDown; comboBox.KeyDown += OnKeyPress;
comboBox.KeyPress += OnKeyPress; comboBox.Width = 130;
SearchOptions.Properties.PropertyChanged += new PropertyChangedEventHandler(SearchOptionsChanged); SearchOptions.Properties.PropertyChanged += new PropertyChangedEventHandler(SearchOptionsChanged);
RefreshComboBox(); RefreshComboBox();

9
src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj

@ -36,6 +36,12 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup> <ItemGroup>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
@ -44,6 +50,9 @@
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources\FindPanel.xfrm" /> <EmbeddedResource Include="Resources\FindPanel.xfrm" />

43
src/Main/Base/Project/Src/Commands/ChooseLayoutCommand.cs

@ -8,11 +8,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.WinForms;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Commands namespace ICSharpCode.SharpDevelop.Commands
{ {
@ -42,7 +41,7 @@ namespace ICSharpCode.SharpDevelop.Commands
if (editingLayout) return; if (editingLayout) return;
LoggingService.Debug("ChooseLayoutCommand.Run()"); LoggingService.Debug("ChooseLayoutCommand.Run()");
ComboBox comboBox = ((ToolBarComboBox)Owner).ComboBox; var comboBox = (System.Windows.Controls.ComboBox)Owner;
string dataPath = Path.Combine(PropertyService.DataDirectory, "resources" + Path.DirectorySeparatorChar + "layouts"); string dataPath = Path.Combine(PropertyService.DataDirectory, "resources" + Path.DirectorySeparatorChar + "layouts");
string configPath = Path.Combine(PropertyService.ConfigDirectory, "layouts"); string configPath = Path.Combine(PropertyService.ConfigDirectory, "layouts");
if (!Directory.Exists(configPath)) { if (!Directory.Exists(configPath)) {
@ -157,8 +156,7 @@ namespace ICSharpCode.SharpDevelop.Commands
{ {
if (editingLayout) return; if (editingLayout) return;
LoggingService.Debug("ChooseLayoutCommand.LayoutChanged(object,EventArgs)"); LoggingService.Debug("ChooseLayoutCommand.LayoutChanged(object,EventArgs)");
ToolBarComboBox toolbarItem = (ToolBarComboBox)Owner; var comboBox = (System.Windows.Controls.ComboBox)Owner;
ComboBox comboBox = toolbarItem.ComboBox;
for (int i = 0; i < comboBox.Items.Count; ++i) { for (int i = 0; i < comboBox.Items.Count; ++i) {
if (((LayoutConfiguration)comboBox.Items[i]).Name == LayoutConfiguration.CurrentLayoutName) { if (((LayoutConfiguration)comboBox.Items[i]).Name == LayoutConfiguration.CurrentLayoutName) {
comboBox.SelectedIndex = i; comboBox.SelectedIndex = i;
@ -169,23 +167,28 @@ namespace ICSharpCode.SharpDevelop.Commands
protected override void OnOwnerChanged(EventArgs e) protected override void OnOwnerChanged(EventArgs e)
{ {
base.OnOwnerChanged(e); base.OnOwnerChanged(e);
ToolBarComboBox toolbarItem = (ToolBarComboBox)Owner;
ComboBox comboBox = toolbarItem.ComboBox; editingLayout = true;
comboBox.Items.Clear(); try {
int index = 0; var comboBox = (System.Windows.Controls.ComboBox)Owner;
foreach (LayoutConfiguration config in LayoutConfiguration.Layouts) { comboBox.Items.Clear();
if (LayoutConfiguration.CurrentLayoutName == config.Name) { int index = 0;
index = comboBox.Items.Count; foreach (LayoutConfiguration config in LayoutConfiguration.Layouts) {
if (LayoutConfiguration.CurrentLayoutName == config.Name) {
index = comboBox.Items.Count;
}
comboBox.Items.Add(config);
} }
comboBox.Items.Add(config); editIndex = comboBox.Items.Count;
comboBox.Items.Add(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.ChooseLayoutCommand.EditItem}"));
resetIndex = comboBox.Items.Count;
comboBox.Items.Add(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.ChooseLayoutCommand.ResetToDefaultItem}"));
comboBox.SelectedIndex = index;
} finally {
editingLayout = false;
} }
editIndex = comboBox.Items.Count;
comboBox.Items.Add(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.ChooseLayoutCommand.EditItem}"));
resetIndex = comboBox.Items.Count;
comboBox.Items.Add(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.ChooseLayoutCommand.ResetToDefaultItem}"));
comboBox.SelectedIndex = index;
} }
} }
} }

1
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -71,6 +71,7 @@
<Compile Include="PresentationResourceService.cs" /> <Compile Include="PresentationResourceService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ToolBar\ToolBarButton.cs" /> <Compile Include="ToolBar\ToolBarButton.cs" />
<Compile Include="ToolBar\ToolBarComboBox.cs" />
<Compile Include="ToolBar\ToolBarService.cs" /> <Compile Include="ToolBar\ToolBarService.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

31
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarComboBox.cs

@ -0,0 +1,31 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Controls;
namespace ICSharpCode.Core.Presentation
{
sealed class ToolBarComboBox : ComboBox
{
// readonly Codon codon;
// readonly object caller;
IComboBoxCommand menuCommand;
public ToolBarComboBox(Codon codon, object caller)
{
this.IsEditable = false;
menuCommand = (IComboBoxCommand)codon.AddIn.CreateObject(codon.Properties["class"]);
menuCommand.Owner = this;
}
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
base.OnSelectionChanged(e);
menuCommand.Run();
}
}
}

3
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs

@ -64,8 +64,7 @@ namespace ICSharpCode.Core.Presentation
case "Item": case "Item":
return new ToolBarButton(codon, caller, createCommand); return new ToolBarButton(codon, caller, createCommand);
case "ComboBox": case "ComboBox":
return "ComboBox"; return new ToolBarComboBox(codon, caller);
//return new ToolBarComboBox(codon, caller);
case "TextBox": case "TextBox":
return "TextBox"; return "TextBox";
//return new ToolBarTextBox(codon, caller); //return new ToolBarTextBox(codon, caller);

Loading…
Cancel
Save