73 changed files with 1524 additions and 433 deletions
@ -0,0 +1,132 @@ |
|||||||
|
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
// software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||||
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||||
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
// substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Markup; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.Tests.Designer |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class MarkupExtensionModelTests : ModelTestHelper |
||||||
|
{ |
||||||
|
private const string PathWithCommasAndSpaces = "C:\\Folder A\\Sub,Folder,A\\SubFolderB\\file,with,commas and spaces.txt"; |
||||||
|
private const string Simple = "AbcDef"; |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ElementMarkupExtensionWithSimpleString() |
||||||
|
{ |
||||||
|
TestMarkupExtensionPrinter(Simple, true); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ShorthandMarkupExtensionWithSimpleString() |
||||||
|
{ |
||||||
|
TestMarkupExtensionPrinter(Simple, false); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ElementMarkupExtensionWithFilePathString() |
||||||
|
{ |
||||||
|
TestMarkupExtensionPrinter(PathWithCommasAndSpaces, true); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ShorthandMarkupExtensionWithFilePathString() |
||||||
|
{ |
||||||
|
TestMarkupExtensionPrinter(PathWithCommasAndSpaces, false); |
||||||
|
} |
||||||
|
|
||||||
|
private void TestMarkupExtensionPrinter(string s, bool useElementStyle) |
||||||
|
{ |
||||||
|
var checkBoxItem = CreateCanvasContext("<CheckBox/>"); |
||||||
|
var tagProp = checkBoxItem.Properties["Tag"]; |
||||||
|
|
||||||
|
tagProp.SetValue(new DataExtension()); |
||||||
|
tagProp.Value.Properties["Data"].SetValue(s); |
||||||
|
|
||||||
|
string expectedXaml; |
||||||
|
|
||||||
|
if (useElementStyle) { |
||||||
|
// Setting this should force element style
|
||||||
|
tagProp.Value.Properties["Object"].SetValue(new ExampleClass()); |
||||||
|
|
||||||
|
expectedXaml = @"<CheckBox>
|
||||||
|
<CheckBox.Tag> |
||||||
|
<t:DataExtension Data=""" + s + @"""> |
||||||
|
<t:DataExtension.Object> |
||||||
|
<t:ExampleClass /> |
||||||
|
</t:DataExtension.Object> |
||||||
|
</t:DataExtension> |
||||||
|
</CheckBox.Tag> |
||||||
|
</CheckBox>";
|
||||||
|
} else { |
||||||
|
StringBuilder sb = new StringBuilder("<CheckBox Tag=\"{t:Data Data="); |
||||||
|
|
||||||
|
bool containsSpace = s.Contains(' '); |
||||||
|
|
||||||
|
if(containsSpace) { |
||||||
|
sb.Append('\''); |
||||||
|
} |
||||||
|
|
||||||
|
sb.Append(s.Replace("\\", "\\\\")); |
||||||
|
|
||||||
|
if(containsSpace) { |
||||||
|
sb.Append('\''); |
||||||
|
} |
||||||
|
|
||||||
|
sb.Append("}\" />"); |
||||||
|
|
||||||
|
expectedXaml = sb.ToString(); |
||||||
|
} |
||||||
|
|
||||||
|
AssertCanvasDesignerOutput(expectedXaml, checkBoxItem.Context); |
||||||
|
AssertLog(""); |
||||||
|
|
||||||
|
// The following tests that the official XamlReader is parsing the resulting xaml into the
|
||||||
|
// same string that we are testing, regardless if element or shorthand style is being used.
|
||||||
|
|
||||||
|
string xaml = expectedXaml.Insert("<CheckBox".Length, " xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " + |
||||||
|
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " + |
||||||
|
"xmlns:t=\"" + DesignerTestsNamespace + "\""); |
||||||
|
|
||||||
|
var checkBox = (CheckBox)System.Windows.Markup.XamlReader.Parse(xaml); |
||||||
|
|
||||||
|
Assert.AreEqual(s, (string)checkBox.Tag); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class DataExtension : MarkupExtension |
||||||
|
{ |
||||||
|
public DataExtension() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override object ProvideValue(IServiceProvider serviceProvider) |
||||||
|
{ |
||||||
|
return Data; |
||||||
|
} |
||||||
|
|
||||||
|
public string Data { get; set; } |
||||||
|
|
||||||
|
public object Object { get; set; } |
||||||
|
} |
||||||
|
} |
@ -1,28 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using NuGet; |
|
||||||
|
|
||||||
namespace ICSharpCode.PackageManagement |
|
||||||
{ |
|
||||||
public interface ISettingsFactory |
|
||||||
{ |
|
||||||
ISettings CreateSettings(string directory); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,14 @@ |
|||||||
|
// 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 NuGet; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement |
||||||
|
{ |
||||||
|
public interface ISettingsProvider |
||||||
|
{ |
||||||
|
event EventHandler SettingsChanged; |
||||||
|
ISettings LoadSettings(); |
||||||
|
} |
||||||
|
} |
@ -1,32 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using NuGet; |
|
||||||
|
|
||||||
namespace ICSharpCode.PackageManagement |
|
||||||
{ |
|
||||||
public class SettingsFactory : ISettingsFactory |
|
||||||
{ |
|
||||||
public ISettings CreateSettings(string directory) |
|
||||||
{ |
|
||||||
var fileSystem = new PhysicalFileSystem(directory); |
|
||||||
return new Settings(fileSystem); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,62 @@ |
|||||||
|
// 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.IO; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using NuGet; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement |
||||||
|
{ |
||||||
|
public class SettingsProvider : ISettingsProvider |
||||||
|
{ |
||||||
|
public static Func<IFileSystem, string, IMachineWideSettings, ISettings> LoadDefaultSettings |
||||||
|
= Settings.LoadDefaultSettings; |
||||||
|
|
||||||
|
IPackageManagementProjectService projectService; |
||||||
|
|
||||||
|
public SettingsProvider() |
||||||
|
: this(PackageManagementServices.ProjectService) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public SettingsProvider(IPackageManagementProjectService projectService) |
||||||
|
{ |
||||||
|
this.projectService = projectService; |
||||||
|
projectService.SolutionOpened += OnSettingsChanged; |
||||||
|
projectService.SolutionClosed += OnSettingsChanged; |
||||||
|
} |
||||||
|
|
||||||
|
public event EventHandler SettingsChanged; |
||||||
|
|
||||||
|
void OnSettingsChanged(object sender, SolutionEventArgs e) |
||||||
|
{ |
||||||
|
if (SettingsChanged != null) { |
||||||
|
SettingsChanged(this, new EventArgs()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public ISettings LoadSettings() |
||||||
|
{ |
||||||
|
return LoadSettings(GetSolutionDirectory()); |
||||||
|
} |
||||||
|
|
||||||
|
string GetSolutionDirectory() |
||||||
|
{ |
||||||
|
ISolution solution = projectService.OpenSolution; |
||||||
|
if (solution != null) { |
||||||
|
return Path.Combine(solution.Directory, ".nuget"); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
ISettings LoadSettings(string directory) |
||||||
|
{ |
||||||
|
if (directory == null) { |
||||||
|
return LoadDefaultSettings(null, null, null); |
||||||
|
} |
||||||
|
|
||||||
|
return LoadDefaultSettings(new PhysicalFileSystem(directory), null, null); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,37 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using ICSharpCode.PackageManagement; |
|
||||||
using ICSharpCode.PackageManagement.Design; |
|
||||||
using NuGet; |
|
||||||
|
|
||||||
namespace PackageManagement.Tests.Helpers |
|
||||||
{ |
|
||||||
public class FakeSettingsFactory : ISettingsFactory |
|
||||||
{ |
|
||||||
public FakeSettings FakeSettings = new FakeSettings(); |
|
||||||
public string DirectoryPassedToCreateSettings; |
|
||||||
|
|
||||||
public ISettings CreateSettings(string directory) |
|
||||||
{ |
|
||||||
DirectoryPassedToCreateSettings = directory; |
|
||||||
return FakeSettings; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,80 @@ |
|||||||
|
// 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 ICSharpCode.PackageManagement; |
||||||
|
using ICSharpCode.PackageManagement.Design; |
||||||
|
using NuGet; |
||||||
|
using NUnit.Framework; |
||||||
|
using PackageManagement.Tests.Helpers; |
||||||
|
|
||||||
|
namespace PackageManagement.Tests |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class SettingsProviderTests |
||||||
|
{ |
||||||
|
SettingsProvider settingsProvider; |
||||||
|
FakeSettings fakeSettings; |
||||||
|
FakePackageManagementProjectService projectService; |
||||||
|
IFileSystem fileSystemUsedToLoadSettings; |
||||||
|
string configFileUsedToLoadSettings; |
||||||
|
IMachineWideSettings machinesettingsUsedToLoadSettings; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void SetUp() |
||||||
|
{ |
||||||
|
fakeSettings = new FakeSettings(); |
||||||
|
projectService = new FakePackageManagementProjectService(); |
||||||
|
SettingsProvider.LoadDefaultSettings = LoadDefaultSettings; |
||||||
|
settingsProvider = new SettingsProvider(projectService); |
||||||
|
} |
||||||
|
|
||||||
|
ISettings LoadDefaultSettings(IFileSystem fileSystem, string configFile, IMachineWideSettings machineSettings) |
||||||
|
{ |
||||||
|
fileSystemUsedToLoadSettings = fileSystem; |
||||||
|
configFileUsedToLoadSettings = configFile; |
||||||
|
machinesettingsUsedToLoadSettings = machineSettings; |
||||||
|
|
||||||
|
return fakeSettings; |
||||||
|
} |
||||||
|
|
||||||
|
void OpenSolution(string fileName) |
||||||
|
{ |
||||||
|
var helper = new SolutionHelper(fileName); |
||||||
|
projectService.OpenSolution = helper.MSBuildSolution; |
||||||
|
} |
||||||
|
|
||||||
|
[TearDown] |
||||||
|
public void TearDown() |
||||||
|
{ |
||||||
|
// This resets SettingsProvider.LoadDefaultSettings.
|
||||||
|
TestablePackageManagementOptions.CreateSettingsProvider(fakeSettings, projectService); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void LoadSettings_NoSolutionOpen_NullFileSystemAndNullConfigFileAndNullMachineSettingsUsed() |
||||||
|
{ |
||||||
|
fileSystemUsedToLoadSettings = new FakeFileSystem(); |
||||||
|
configFileUsedToLoadSettings = "configFile"; |
||||||
|
|
||||||
|
ISettings settings = settingsProvider.LoadSettings(); |
||||||
|
|
||||||
|
Assert.IsNull(fileSystemUsedToLoadSettings); |
||||||
|
Assert.IsNull(configFileUsedToLoadSettings); |
||||||
|
Assert.IsNull(machinesettingsUsedToLoadSettings); |
||||||
|
Assert.AreEqual(fakeSettings, settings); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void LoadSettings_SolutionOpen_FileSystemWithRootSetToSolutionDotNuGetDirectoryUsedToLoadSettings() |
||||||
|
{ |
||||||
|
string fileName = @"d:\projects\MyProject\MyProject.sln"; |
||||||
|
OpenSolution(fileName); |
||||||
|
|
||||||
|
ISettings settings = settingsProvider.LoadSettings(); |
||||||
|
|
||||||
|
Assert.AreEqual(@"d:\projects\MyProject\.nuget", fileSystemUsedToLoadSettings.Root); |
||||||
|
Assert.AreEqual(fakeSettings, settings); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,68 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.05.2014 |
||||||
|
* Time: 20:05 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.Core.WinForms; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.Addin.Commands |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of DesignerVerbSubmenuBuilder.
|
||||||
|
/// </summary>
|
||||||
|
public class DesignerVerbSubmenuBuilder : IMenuItemBuilder |
||||||
|
{ |
||||||
|
#region IMenuItemBuilder implementation
|
||||||
|
|
||||||
|
public IEnumerable<object> BuildItems(Codon codon, object owner) |
||||||
|
{ |
||||||
|
var menuCommandService = (IMenuCommandService)owner; |
||||||
|
|
||||||
|
var items = new List<ToolStripItem>(); |
||||||
|
|
||||||
|
foreach (DesignerVerb verb in menuCommandService.Verbs) { |
||||||
|
Console.WriteLine("{0}",verb.Text); |
||||||
|
items.Add(new ContextMenuCommand(verb)); |
||||||
|
} |
||||||
|
|
||||||
|
// add separator at the end of custom designer verbs
|
||||||
|
if (items.Count > 0) { |
||||||
|
items.Add(new MenuSeparator()); |
||||||
|
} |
||||||
|
|
||||||
|
return items.ToArray(); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
|
||||||
|
sealed class ContextMenuCommand : ICSharpCode.Core.WinForms.MenuCommand |
||||||
|
{ |
||||||
|
DesignerVerb verb; |
||||||
|
|
||||||
|
public ContextMenuCommand(DesignerVerb verb) : base(verb.Text) |
||||||
|
{ |
||||||
|
this.Enabled = verb.Enabled; |
||||||
|
// this.Checked = verb.Checked;
|
||||||
|
this.verb = verb; |
||||||
|
Click += InvokeCommand; |
||||||
|
} |
||||||
|
|
||||||
|
void InvokeCommand(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
try { |
||||||
|
verb.Invoke(); |
||||||
|
} catch (Exception ex) { |
||||||
|
MessageService.ShowException(ex); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,83 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.05.2014 |
||||||
|
* Time: 20:35 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.Reporting.Addin.Views; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.Addin.Commands |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of FormsCommands.
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public abstract class AbstractFormsDesignerCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public abstract CommandID CommandID { |
||||||
|
get; |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual bool CanExecuteCommand(IDesignerHost host) |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
protected static DesignerView ReportDesigner { |
||||||
|
get { |
||||||
|
var window = SD.Workbench; |
||||||
|
if (window == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return window.ActiveViewContent as DesignerView; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
var formDesigner = ReportDesigner; |
||||||
|
if (formDesigner != null && CanExecuteCommand(formDesigner.Host)) { |
||||||
|
var menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService)); |
||||||
|
menuCommandService.GlobalInvoke(CommandID); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
internal virtual void CommandCallBack(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
Run(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class ViewCode : AbstractFormsDesignerCommand |
||||||
|
{ |
||||||
|
public override CommandID CommandID { |
||||||
|
get { |
||||||
|
return StandardCommands.ViewCode; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
// var window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
|
||||||
|
var window = SD.Workbench; |
||||||
|
if (window == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
var formDesigner = AbstractFormsDesignerCommand.ReportDesigner; |
||||||
|
if (formDesigner != null) { |
||||||
|
formDesigner.ShowSourceCode(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.05.2014 |
||||||
|
* Time: 19:37 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.SharpDevelop.WinForms; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.Addin.UndoRedo |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of ReportDesignerUndoEngine.
|
||||||
|
/// </summary>
|
||||||
|
public class ReportDesignerUndoEngine : UndoEngine, IUndoHandler |
||||||
|
{ |
||||||
|
Stack<UndoEngine.UndoUnit> undoStack = new Stack<UndoEngine.UndoUnit>(); |
||||||
|
Stack<UndoEngine.UndoUnit> redoStack = new Stack<UndoEngine.UndoUnit>(); |
||||||
|
|
||||||
|
public ReportDesignerUndoEngine(IServiceProvider provider) : base(provider) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
#region IUndoHandler
|
||||||
|
public bool EnableUndo { |
||||||
|
get { |
||||||
|
return undoStack.Count > 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnableRedo { |
||||||
|
get { |
||||||
|
return redoStack.Count > 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Undo() |
||||||
|
{ |
||||||
|
if (undoStack.Count > 0) { |
||||||
|
UndoEngine.UndoUnit unit = undoStack.Pop(); |
||||||
|
unit.Undo(); |
||||||
|
redoStack.Push(unit); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Redo() |
||||||
|
{ |
||||||
|
if (redoStack.Count > 0) { |
||||||
|
UndoEngine.UndoUnit unit = redoStack.Pop(); |
||||||
|
unit.Undo(); |
||||||
|
undoStack.Push(unit); |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
protected override void AddUndoUnit(UndoEngine.UndoUnit unit) |
||||||
|
{ |
||||||
|
undoStack.Push(unit); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue