Browse Source

Converted more MenuItemBuilders to WPF.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0wpf@3388 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
48ff67d4c1
  1. 118
      src/Main/Base/Project/Src/Commands/MenuItemBuilders.cs
  2. 8
      src/Main/Base/Project/Src/Gui/IWorkbenchLayout.cs
  3. 18
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs
  4. 2
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs
  5. 10
      src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
  6. 12
      src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs
  7. 7
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs
  8. 10
      src/Main/ICSharpCode.Core.Presentation/PixelSnapper.cs

118
src/Main/Base/Project/Src/Commands/MenuItemBuilders.cs

@ -143,69 +143,63 @@ namespace ICSharpCode.SharpDevelop.Commands
} }
} }
public class RecentFilesMenuBuilder : ISubmenuBuilder public class RecentFilesMenuBuilder : IMenuItemBuilder
{ {
public ToolStripItem[] BuildSubmenu(Codon codon, object owner) public ICollection BuildItems(Codon codon, object owner)
{ {
RecentOpen recentOpen = FileService.RecentOpen; RecentOpen recentOpen = FileService.RecentOpen;
if (recentOpen.RecentFile.Count > 0) { if (recentOpen.RecentFile.Count > 0) {
MenuCommand[] items = new MenuCommand[recentOpen.RecentFile.Count]; var items = new System.Windows.Controls.MenuItem[recentOpen.RecentFile.Count];
for (int i = 0; i < recentOpen.RecentFile.Count; ++i) { for (int i = 0; i < recentOpen.RecentFile.Count; ++i) {
string accelaratorKeyPrefix = i < 10 ? "&" + ((i + 1) % 10) + " " : ""; // variable inside loop, so that anonymous method refers to correct recent file
items[i] = new MenuCommand(accelaratorKeyPrefix + recentOpen.RecentFile[i], new EventHandler(LoadRecentFile)); string recentFile = recentOpen.RecentFile[i];
items[i].Tag = recentOpen.RecentFile[i].ToString(); string accelaratorKeyPrefix = i < 10 ? "_" + ((i + 1) % 10) + " " : "";
items[i].Description = StringParser.Parse(ResourceService.GetString("Dialog.Componnents.RichMenuItem.LoadFileDescription"), items[i] = new System.Windows.Controls.MenuItem() {
new string[,] { {"FILE", recentOpen.RecentFile[i].ToString()} }); Header = accelaratorKeyPrefix + recentFile
};
items[i].Click += delegate {
FileService.OpenFile(recentFile);
};
} }
return items; return items;
} else {
return new [] { new System.Windows.Controls.MenuItem {
Header = StringParser.Parse("${res:Dialog.Componnents.RichMenuItem.NoRecentFilesString}"),
IsEnabled = false
} };
} }
MenuCommand defaultMenu = new MenuCommand("${res:Dialog.Componnents.RichMenuItem.NoRecentFilesString}");
defaultMenu.Enabled = false;
return new MenuCommand[] { defaultMenu };
}
void LoadRecentFile(object sender, EventArgs e)
{
MenuCommand item = (MenuCommand)sender;
FileService.OpenFile(item.Tag.ToString());
} }
} }
public class RecentProjectsMenuBuilder : ISubmenuBuilder public class RecentProjectsMenuBuilder : IMenuItemBuilder
{ {
public ToolStripItem[] BuildSubmenu(Codon codon, object owner) public ICollection BuildItems(Codon codon, object owner)
{ {
RecentOpen recentOpen = FileService.RecentOpen; RecentOpen recentOpen = FileService.RecentOpen;
if (recentOpen.RecentProject.Count > 0) { if (recentOpen.RecentFile.Count > 0) {
MenuCommand[] items = new MenuCommand[recentOpen.RecentProject.Count]; var items = new System.Windows.Controls.MenuItem[recentOpen.RecentFile.Count];
for (int i = 0; i < recentOpen.RecentProject.Count; ++i) { for (int i = 0; i < recentOpen.RecentProject.Count; ++i) {
string accelaratorKeyPrefix = i < 10 ? "&" + ((i + 1) % 10) + " " : ""; // variable inside loop, so that anonymous method refers to correct recent file
items[i] = new MenuCommand(accelaratorKeyPrefix + recentOpen.RecentProject[i], new EventHandler(LoadRecentProject)); string recentProject = recentOpen.RecentProject[i];
items[i].Tag = recentOpen.RecentProject[i].ToString(); string accelaratorKeyPrefix = i < 10 ? "_" + ((i + 1) % 10) + " " : "";
items[i].Description = StringParser.Parse(ResourceService.GetString("Dialog.Componnents.RichMenuItem.LoadProjectDescription"), items[i] = new System.Windows.Controls.MenuItem() {
new string[,] { {"PROJECT", recentOpen.RecentProject[i].ToString()} }); Header = accelaratorKeyPrefix + recentProject
};
items[i].Click += delegate {
ProjectService.LoadSolution(recentProject);
};
} }
return items; return items;
} else {
return new [] { new System.Windows.Controls.MenuItem {
Header = StringParser.Parse("${res:Dialog.Componnents.RichMenuItem.NoRecentProjectsString}"),
IsEnabled = false
} };
} }
MenuCommand defaultMenu = new MenuCommand("${res:Dialog.Componnents.RichMenuItem.NoRecentProjectsString}");
defaultMenu.Enabled = false;
return new MenuCommand[] { defaultMenu };
}
void LoadRecentProject(object sender, EventArgs e)
{
MenuCommand item = (MenuCommand)sender;
string fileName = item.Tag.ToString();
FileUtility.ObservedLoad(new NamedFileOperationDelegate(ProjectService.LoadSolution), fileName);
} }
} }
@ -292,40 +286,26 @@ namespace ICSharpCode.SharpDevelop.Commands
} }
} }
public class OpenContentsMenuBuilder : ISubmenuBuilder public class OpenContentsMenuBuilder : IMenuItemBuilder
{ {
public ICollection BuildItems(Codon codon, object owner)
class MyMenuItem : MenuCheckBox
{
IWorkbenchWindow window;
public MyMenuItem(IWorkbenchWindow window) : base(StringParser.Parse(window.Title))
{
this.window = window;
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
Checked = true;
window.SelectWindow();
}
}
public ToolStripItem[] BuildSubmenu(Codon codon, object owner)
{ {
int windowCount = WorkbenchSingleton.Workbench.WorkbenchWindowCollection.Count; int windowCount = WorkbenchSingleton.Workbench.WorkbenchWindowCollection.Count;
if (windowCount == 0) { if (windowCount == 0) {
return new ToolStripItem[] {}; return new object[] {};
} }
ToolStripItem[] items = new ToolStripItem[windowCount + 1]; var items = new object[windowCount + 1];
items[0] = new MenuSeparator(null, null); items[0] = new System.Windows.Controls.Separator();
for (int i = 0; i < windowCount; ++i) { for (int i = 0; i < windowCount; ++i) {
IWorkbenchWindow window = WorkbenchSingleton.Workbench.WorkbenchWindowCollection[i]; IWorkbenchWindow window = WorkbenchSingleton.Workbench.WorkbenchWindowCollection[i];
MenuCheckBox item = new MyMenuItem(window); var item = new System.Windows.Controls.MenuItem() {
item.Tag = window; IsChecked = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow == window,
item.Checked = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow == window; IsCheckable = true,
item.Description = "Activate this window"; Header = StringParser.Parse(window.Title)
};
item.Click += delegate {
window.SelectWindow();
};
items[i + 1] = item; items[i + 1] = item;
} }
return items; return items;

8
src/Main/Base/Project/Src/Gui/IWorkbenchLayout.cs

@ -6,6 +6,7 @@
// </file> // </file>
using System; using System;
using System.Collections.Generic;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
{ {
@ -24,6 +25,13 @@ namespace ICSharpCode.SharpDevelop.Gui
get; get;
} }
/// <summary>
/// Gets the open workbench windows.
/// </summary>
IList<IWorkbenchWindow> WorkbenchWindows {
get;
}
/// <summary> /// <summary>
/// The active content. This can be either a IViewContent or a IPadContent, depending on /// The active content. This can be either a IViewContent or a IPadContent, depending on
/// where the focus currently is. /// where the focus currently is.

18
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs

@ -26,22 +26,25 @@ namespace ICSharpCode.SharpDevelop.Gui
WpfWorkbench workbench; WpfWorkbench workbench;
DockingManager dockingManager = new DockingManager(); DockingManager dockingManager = new DockingManager();
DocumentPane documentPane = new DocumentPane(); DocumentPane documentPane = new DocumentPane();
List<IWorkbenchWindow> workbenchWindows = new List<IWorkbenchWindow>();
internal bool Busy; internal bool Busy;
public DockingManager DockingManager { public DockingManager DockingManager {
get { return dockingManager; } get { return dockingManager; }
} }
public DocumentPane DocumentPane {
get { return documentPane; }
}
public AvalonDockLayout() public AvalonDockLayout()
{ {
dockingManager.Content = documentPane; dockingManager.Content = documentPane;
dockingManager.PropertyChanged += dockingManager_PropertyChanged; dockingManager.PropertyChanged += dockingManager_PropertyChanged;
} }
public void OnWorkbenchWindowClosed(AvalonWorkbenchWindow window)
{
workbenchWindows.Remove(window);
documentPane.Items.Remove(window);
}
void dockingManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) void dockingManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
if (e.PropertyName == "ActiveContent") { if (e.PropertyName == "ActiveContent") {
@ -72,6 +75,12 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
public IList<IWorkbenchWindow> WorkbenchWindows {
get {
return workbenchWindows.AsReadOnly();
}
}
public void Attach(IWorkbench workbench) public void Attach(IWorkbench workbench)
{ {
if (this.workbench != null) if (this.workbench != null)
@ -213,6 +222,7 @@ namespace ICSharpCode.SharpDevelop.Gui
public IWorkbenchWindow ShowView(IViewContent content) public IWorkbenchWindow ShowView(IViewContent content)
{ {
AvalonWorkbenchWindow window = new AvalonWorkbenchWindow(this); AvalonWorkbenchWindow window = new AvalonWorkbenchWindow(this);
workbenchWindows.Add(window);
window.ViewContents.Add(content); window.ViewContents.Add(content);
window.ViewContents.AddRange(content.SecondaryViewContents); window.ViewContents.AddRange(content.SecondaryViewContents);
documentPane.Items.Add(window); documentPane.Items.Add(window);

2
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs

@ -342,7 +342,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
dockLayout.DocumentPane.Items.Remove(this); dockLayout.OnWorkbenchWindowClosed(this);
Dispose(); Dispose();
CommandManager.InvalidateRequerySuggested(); CommandManager.InvalidateRequerySuggested();
return true; return true;

10
src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs

@ -45,7 +45,6 @@ namespace ICSharpCode.SharpDevelop.Gui
public Window MainWindow { get { return this; } } public Window MainWindow { get { return this; } }
List<PadDescriptor> padViewContentCollection = new List<PadDescriptor>(); List<PadDescriptor> padViewContentCollection = new List<PadDescriptor>();
List<IViewContent> viewContentCollection = new List<IViewContent>();
ToolBar[] toolBars; ToolBar[] toolBars;
@ -101,14 +100,16 @@ namespace ICSharpCode.SharpDevelop.Gui
public ICollection<IViewContent> ViewContentCollection { public ICollection<IViewContent> ViewContentCollection {
get { get {
return viewContentCollection.AsReadOnly(); return WorkbenchWindowCollection.SelectMany(w => w.ViewContents).ToList().ToArray();
} }
} }
public IList<IWorkbenchWindow> WorkbenchWindowCollection { public IList<IWorkbenchWindow> WorkbenchWindowCollection {
get { get {
return viewContentCollection.Select(vc => vc.WorkbenchWindow) if (workbenchLayout != null)
.Distinct().ToList().AsReadOnly(); return workbenchLayout.WorkbenchWindows;
else
return new IWorkbenchWindow[0];
} }
} }
@ -231,7 +232,6 @@ namespace ICSharpCode.SharpDevelop.Gui
if (content == null) if (content == null)
throw new ArgumentNullException("content"); throw new ArgumentNullException("content");
System.Diagnostics.Debug.Assert(WorkbenchLayout != null); System.Diagnostics.Debug.Assert(WorkbenchLayout != null);
viewContentCollection.Add(content);
WorkbenchLayout.ShowView(content); WorkbenchLayout.ShowView(content);
content.WorkbenchWindow.SelectWindow(); content.WorkbenchWindow.SelectWindow();

12
src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

@ -244,6 +244,11 @@ namespace ICSharpCode.SharpDevelop.Project
} }
public static void LoadSolution(string fileName) public static void LoadSolution(string fileName)
{
FileUtility.ObservedLoad(LoadSolutionInternal, fileName);
}
static void LoadSolutionInternal(string fileName)
{ {
if (!Path.IsPathRooted(fileName)) if (!Path.IsPathRooted(fileName))
throw new ArgumentException("Path must be rooted!"); throw new ArgumentException("Path must be rooted!");
@ -307,12 +312,17 @@ namespace ICSharpCode.SharpDevelop.Project
/// Load a single project as solution. /// Load a single project as solution.
/// </summary> /// </summary>
public static void LoadProject(string fileName) public static void LoadProject(string fileName)
{
FileUtility.ObservedLoad(LoadSolutionInternal, fileName);
}
static void LoadProjectInternal(string fileName)
{ {
if (!Path.IsPathRooted(fileName)) if (!Path.IsPathRooted(fileName))
throw new ArgumentException("Path must be rooted!"); throw new ArgumentException("Path must be rooted!");
string solutionFile = Path.ChangeExtension(fileName, ".sln"); string solutionFile = Path.ChangeExtension(fileName, ".sln");
if (File.Exists(solutionFile)) { if (File.Exists(solutionFile)) {
LoadSolution(solutionFile); LoadSolutionInternal(solutionFile);
if (openSolution != null) { if (openSolution != null) {
bool found = false; bool found = false;

7
src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs

@ -71,9 +71,14 @@ namespace ICSharpCode.Core.Presentation
case "Command": case "Command":
return new MenuCommand(inputBindingOwner, codon, descriptor.Caller, createCommand); return new MenuCommand(inputBindingOwner, codon, descriptor.Caller, createCommand);
case "Menu": case "Menu":
return new CoreMenuItem(codon, descriptor.Caller) { var item = new CoreMenuItem(codon, descriptor.Caller) {
ItemsSource = CreateMenuItems(inputBindingOwner, descriptor.SubItems) ItemsSource = CreateMenuItems(inputBindingOwner, descriptor.SubItems)
}; };
item.SubmenuOpened += (sender, args) => {
item.ItemsSource = CreateMenuItems(inputBindingOwner, descriptor.SubItems);
args.Handled = true;
};
return item;
case "Builder": case "Builder":
return codon.AddIn.CreateObject(codon.Properties["class"]); return codon.AddIn.CreateObject(codon.Properties["class"]);
default: default:

10
src/Main/ICSharpCode.Core.Presentation/PixelSnapper.cs

@ -5,9 +5,11 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using System; using System;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace ICSharpCode.Core.Presentation namespace ICSharpCode.Core.Presentation
{ {
@ -18,7 +20,6 @@ namespace ICSharpCode.Core.Presentation
{ {
public PixelSnapper() public PixelSnapper()
{ {
LayoutUpdated += new EventHandler(OnLayoutUpdated);
} }
public PixelSnapper(UIElement visualChild) public PixelSnapper(UIElement visualChild)
@ -80,13 +81,14 @@ namespace ICSharpCode.Core.Presentation
_pixelOffset = GetPixelOffset(); _pixelOffset = GetPixelOffset();
//LoggingService.Debug("Arrange, Pixel Offset=" + _pixelOffset); //LoggingService.Debug("Arrange, Pixel Offset=" + _pixelOffset);
_visualChild.Arrange(new Rect(new Point(_pixelOffset.X, _pixelOffset.Y), finalRect.Size)); _visualChild.Arrange(new Rect(new Point(_pixelOffset.X, _pixelOffset.Y), finalRect.Size));
// check again after the whole layout pass has finished, maybe we need to move
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new ThreadStart(CheckLayout));
} }
} }
private void OnLayoutUpdated(object sender, EventArgs e) private void CheckLayout()
{ {
// This event just means that layout happened somewhere. However, this is
// what we need since layout anywhere could affect our pixel positioning.
Point pixelOffset = GetPixelOffset(); Point pixelOffset = GetPixelOffset();
if (!AreClose(pixelOffset, _pixelOffset)) { if (!AreClose(pixelOffset, _pixelOffset)) {
InvalidateArrange(); InvalidateArrange();

Loading…
Cancel
Save