Browse Source

Adjust IViewContent to OpenedFile models.

filemodels
Daniel Grunwald 12 years ago
parent
commit
6a6c8a645d
  1. 16
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs
  2. 16
      src/AddIns/DisplayBindings/ILSpyAddIn/DecompiledViewContent.cs
  3. 2
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  4. 24
      src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs
  5. 117
      src/Main/Base/Project/Workbench/AbstractSecondaryViewContent.cs
  6. 40
      src/Main/Base/Project/Workbench/AbstractViewContent.cs
  7. 33
      src/Main/Base/Project/Workbench/AbstractViewContentHandlingLoadErrors.cs
  8. 75
      src/Main/Base/Project/Workbench/AbstractViewContentWithoutFile.cs
  9. 43
      src/Main/Base/Project/Workbench/IViewContent.cs

16
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs

@ -29,7 +29,7 @@ namespace ICSharpCode.WixBinding
/// <summary> /// <summary>
/// Displays the setup package files. /// Displays the setup package files.
/// </summary> /// </summary>
public class PackageFilesView : AbstractViewContentWithoutFile, IWixDocumentWriter public class PackageFilesView : AbstractViewContent, IWixDocumentWriter, ICustomizedCommands
{ {
IWixPackageFilesControl packageFilesControl; IWixPackageFilesControl packageFilesControl;
WixProject project; WixProject project;
@ -88,9 +88,17 @@ namespace ICSharpCode.WixBinding
{ {
return this.project == project; return this.project == project;
} }
bool ICustomizedCommands.SaveCommand()
{
Save();
return true;
}
public override void Load() bool ICustomizedCommands.SaveAsCommand()
{ {
Save();
return true;
} }
public override void Save() public override void Save()
@ -98,6 +106,10 @@ namespace ICSharpCode.WixBinding
packageFilesControl.Save(); packageFilesControl.Save();
} }
public override bool IsViewOnly {
get { return false; }
}
public override bool IsDirty { public override bool IsDirty {
get { return packageFilesControl.IsDirty; } get { return packageFilesControl.IsDirty; }
} }

16
src/AddIns/DisplayBindings/ILSpyAddIn/DecompiledViewContent.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.ILSpyAddIn
/// <summary> /// <summary>
/// Hosts a decompiled type. /// Hosts a decompiled type.
/// </summary> /// </summary>
class DecompiledViewContent : AbstractViewContentWithoutFile class DecompiledViewContent : AbstractViewContent
{ {
/// <summary> /// <summary>
/// Entity to jump to once decompilation has finished. /// Entity to jump to once decompilation has finished.
@ -102,20 +102,6 @@ namespace ICSharpCode.ILSpyAddIn
} }
#endregion #endregion
#region Load/Save
public override void Load()
{
// nothing to do...
}
public override void Save()
{
if (!decompilationFinished)
return;
// TODO: show Save As dialog to allow the user to save the decompiled file
}
#endregion
public override INavigationPoint BuildNavPoint() public override INavigationPoint BuildNavPoint()
{ {
return codeEditor.BuildNavPoint(); return codeEditor.BuildNavPoint();

2
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -350,10 +350,8 @@
<Compile Include="WinForms\IWinFormsToolbarService.cs" /> <Compile Include="WinForms\IWinFormsToolbarService.cs" />
<Compile Include="WinForms\WinFormsExtensions.cs" /> <Compile Include="WinForms\WinFormsExtensions.cs" />
<Compile Include="Workbench\AbstractPadContent.cs" /> <Compile Include="Workbench\AbstractPadContent.cs" />
<Compile Include="Workbench\AbstractSecondaryViewContent.cs" />
<Compile Include="Workbench\AbstractViewContent.cs" /> <Compile Include="Workbench\AbstractViewContent.cs" />
<Compile Include="Workbench\AbstractViewContentHandlingLoadErrors.cs" /> <Compile Include="Workbench\AbstractViewContentHandlingLoadErrors.cs" />
<Compile Include="Workbench\AbstractViewContentWithoutFile.cs" />
<Compile Include="Workbench\DisplayBinding\DisplayBindingDescriptor.cs" /> <Compile Include="Workbench\DisplayBinding\DisplayBindingDescriptor.cs" />
<Compile Include="Workbench\DisplayBinding\ExternalProcessDisplayBinding.cs" /> <Compile Include="Workbench\DisplayBinding\ExternalProcessDisplayBinding.cs" />
<Compile Include="Workbench\DisplayBinding\IDisplayBinding.cs" /> <Compile Include="Workbench\DisplayBinding\IDisplayBinding.cs" />

24
src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
/// <summary> /// <summary>
/// Option view for project options. /// Option view for project options.
/// </summary> /// </summary>
public class ProjectOptionsView : AbstractViewContentWithoutFile public class ProjectOptionsView : AbstractViewContent, ICustomizedCommands
{ {
List<IOptionPanelDescriptor> descriptors = new List<IOptionPanelDescriptor>(); List<IOptionPanelDescriptor> descriptors = new List<IOptionPanelDescriptor>();
TabbedOptions tabControl = new TabbedOptions(); TabbedOptions tabControl = new TabbedOptions();
@ -69,14 +69,11 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
get { return tabControl.IsDirty; } get { return tabControl.IsDirty; }
} }
public override void Load() public override bool IsViewOnly {
{ get { return false; }
foreach (IOptionPanel op in tabControl.OptionPanels) {
op.LoadOptions();
}
} }
public override void Save() public bool Save()
{ {
try { try {
foreach (IOptionPanel op in tabControl.OptionPanels) { foreach (IOptionPanel op in tabControl.OptionPanels) {
@ -84,9 +81,20 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
} }
} catch (Exception ex) { } catch (Exception ex) {
MessageService.ShowException(ex, "Error saving project options panel"); MessageService.ShowException(ex, "Error saving project options panel");
return; return false;
} }
project.Save(); project.Save();
return true;
}
bool ICustomizedCommands.SaveCommand()
{
return Save();
}
bool ICustomizedCommands.SaveAsCommand()
{
return Save();
} }
public override void Dispose() public override void Dispose()

117
src/Main/Base/Project/Workbench/AbstractSecondaryViewContent.cs

@ -1,117 +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 System.Collections.Generic;
using System.IO;
namespace ICSharpCode.SharpDevelop.Workbench
{
/// <summary>
/// A view content that is based on another (primary) view content.
/// Loading works by getting the content from the primary view content,
/// saving by merging it back to the primary view content and then saving the
/// primary view content.
/// AbstractSecondaryViewContent implements the [Support]Switch* methods to make switching
/// between the primary view content and the secondary possible without having to save/load the
/// primary view content.
/// </summary>
public abstract class AbstractSecondaryViewContent : AbstractViewContent
{
readonly IViewContent primaryViewContent;
readonly OpenedFile primaryFile;
public IViewContent PrimaryViewContent {
get { return primaryViewContent; }
}
public sealed override OpenedFile PrimaryFile {
get { return primaryFile; }
}
protected AbstractSecondaryViewContent(IViewContent primaryViewContent)
{
if (primaryViewContent == null)
throw new ArgumentNullException("primaryViewContent");
if (primaryViewContent.PrimaryFile == null)
throw new ArgumentException("primaryViewContent.PrimaryFile must not be null");
this.primaryViewContent = primaryViewContent;
primaryFile = primaryViewContent.PrimaryFile;
this.Files.Add(primaryFile);
}
public override void Load(OpenedFile file, Stream stream)
{
if (file != this.PrimaryFile)
throw new ArgumentException("file must be the primary file of the primary view content, override Load() to handle other files");
primaryViewContent.Load(file, stream);
LoadFromPrimary();
}
public override void Save(OpenedFile file, Stream stream)
{
if (file != this.PrimaryFile)
throw new ArgumentException("file must be the primary file of the primary view content, override Save() to handle other files");
SaveToPrimary();
primaryViewContent.Save(file, stream);
}
public override bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
{
if (file == this.PrimaryFile)
return newView.SupportsSwitchToThisWithoutSaveLoad(file, primaryViewContent);
else
return base.SupportsSwitchFromThisWithoutSaveLoad(file, newView);
}
public override bool SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
{
if (file == this.PrimaryFile)
return oldView.SupportsSwitchToThisWithoutSaveLoad(file, primaryViewContent);
else
return base.SupportsSwitchFromThisWithoutSaveLoad(file, oldView);
}
public override void SwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
{
if (file == this.PrimaryFile && this != newView) {
SaveToPrimary();
primaryViewContent.SwitchFromThisWithoutSaveLoad(file, newView);
}
}
public override void SwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
{
if (file == this.PrimaryFile && oldView != this) {
primaryViewContent.SwitchToThisWithoutSaveLoad(file, oldView);
LoadFromPrimary();
}
}
protected abstract void LoadFromPrimary();
protected abstract void SaveToPrimary();
/// <summary>
/// Gets the list of sibling secondary view contents.
/// </summary>
public override ICollection<IViewContent> SecondaryViewContents {
get { return primaryViewContent.SecondaryViewContents; }
}
}
}

40
src/Main/Base/Project/Workbench/AbstractViewContent.cs

@ -196,38 +196,6 @@ namespace ICSharpCode.SharpDevelop.Workbench
return secondaryViewContentCollection; return secondaryViewContentCollection;
} }
} }
/// <summary>
/// Gets switching without a Save/Load cycle for <paramref name="file"/> is supported
/// when switching from this view content to <paramref name="newView"/>.
/// </summary>
public virtual bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
{
return newView == this;
}
/// <summary>
/// Gets switching without a Save/Load cycle for <paramref name="file"/> is supported
/// when switching from <paramref name="oldView"/> to this view content.
/// </summary>
public virtual bool SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
{
return oldView == this;
}
/// <summary>
/// Executes an action before switching from this view content to the new view content.
/// </summary>
public virtual void SwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
{
}
/// <summary>
/// Executes an action before switching from the old view content to this view content.
/// </summary>
public virtual void SwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
{
}
#endregion #endregion
#region Files #region Files
@ -573,14 +541,6 @@ namespace ICSharpCode.SharpDevelop.Workbench
#endregion #endregion
public virtual void Save(OpenedFile file, Stream stream)
{
}
public virtual void Load(OpenedFile file, Stream stream)
{
}
public virtual INavigationPoint BuildNavPoint() public virtual INavigationPoint BuildNavPoint()
{ {
return null; return null;

33
src/Main/Base/Project/Workbench/AbstractViewContentHandlingLoadErrors.cs

@ -94,7 +94,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
TextBox errorTextBox; TextBox errorTextBox;
void ShowError(Exception ex) protected void ShowError(Exception ex)
{ {
if (errorTextBox == null) { if (errorTextBox == null) {
errorTextBox = new TextBox(); errorTextBox = new TextBox();
@ -114,36 +114,5 @@ namespace ICSharpCode.SharpDevelop.Workbench
protected virtual string LoadErrorHeaderText { protected virtual string LoadErrorHeaderText {
get { return String.Empty; } get { return String.Empty; }
} }
public override sealed void Load(OpenedFile file, Stream stream)
{
try {
LoadInternal(file, new UnclosableStream(stream));
if (errorList.Count > 0) {
errorList.Remove(file);
if (errorList.Count == 0) {
SD.WinForms.SetContent(contentControl, userContent, this);
} else {
ShowError(errorList.Values.First().exception);
}
}
} catch (Exception ex) {
errorList[file] = new LoadError(ex, stream);
ShowError(ex);
}
}
public override sealed void Save(OpenedFile file, Stream stream)
{
if (errorList.ContainsKey(file)) {
byte[] data = errorList[file].fileData;
stream.Write(data, 0, data.Length);
} else {
SaveInternal(file, stream);
}
}
protected abstract void LoadInternal(OpenedFile file, Stream stream);
protected abstract void SaveInternal(OpenedFile file, Stream stream);
} }
} }

75
src/Main/Base/Project/Workbench/AbstractViewContentWithoutFile.cs

@ -1,75 +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;
namespace ICSharpCode.SharpDevelop.Workbench
{
/// <summary>
/// Base class for view contents that are not based on a file, but can be loaded/saved.
/// If you need a view content that cannot save (IsViewOnly==true), you should instead derive
/// directly from AbstractViewContent and leave the Files collection empty.
///
/// AbstractViewContentWithoutFile implements ICustomizedCommands to make "File > Save" work
/// without requiring an OpenedFile. "File > Save as" will also cause Save() to be called, without
/// showing a "Save as" dialog.
/// </summary>
public abstract class AbstractViewContentWithoutFile : AbstractViewContent, ICustomizedCommands
{
public override bool IsViewOnly {
get { return false; }
}
[Obsolete("AbstractViewContentWithoutFile.PrimaryFile is always null")]
public sealed override OpenedFile PrimaryFile { get { return null; } }
[Obsolete("This method is not supported on an AbstractViewContentWithoutFile")]
public sealed override void Load(OpenedFile file, System.IO.Stream stream)
{
throw new NotSupportedException();
}
[Obsolete("This method is not supported on an AbstractViewContentWithoutFile")]
public sealed override void Save(OpenedFile file, System.IO.Stream stream)
{
throw new NotSupportedException();
}
/// <summary>
/// Load the view content.
/// </summary>
public abstract void Load();
/// <summary>
/// Save the view content.
/// </summary>
public abstract void Save();
bool ICustomizedCommands.SaveCommand()
{
Save();
return true;
}
bool ICustomizedCommands.SaveAsCommand()
{
Save();
return true;
}
}
}

43
src/Main/Base/Project/Workbench/IViewContent.cs

@ -96,26 +96,6 @@ namespace ICSharpCode.SharpDevelop
/// </summary> /// </summary>
event EventHandler InfoTipChanged; event EventHandler InfoTipChanged;
/// <summary>
/// Saves the content to the location <code>fileName</code>
/// </summary>
/// <remarks>
/// When the user switches between multiple views editing the same file, a view
/// change will trigger one view content to save that file into a memory stream
/// and the other view content will load the file from that memory stream.
/// </remarks>
void Save(OpenedFile file, Stream stream);
/// <summary>
/// Load or reload the content of the specified file from the stream.
/// </summary>
/// <remarks>
/// When the user switches between multiple views editing the same file, a view
/// change will trigger one view content to save that file into a memory stream
/// and the other view content will load the file from that memory stream.
/// </remarks>
void Load(OpenedFile file, Stream stream);
/// <summary> /// <summary>
/// Gets the list of files that are being edited using this view content. /// Gets the list of files that are being edited using this view content.
/// The returned collection usually is read-only. /// The returned collection usually is read-only.
@ -161,29 +141,6 @@ namespace ICSharpCode.SharpDevelop
/// Gets the collection that stores the secondary view contents. /// Gets the collection that stores the secondary view contents.
/// </summary> /// </summary>
ICollection<IViewContent> SecondaryViewContents { get; } ICollection<IViewContent> SecondaryViewContents { get; }
/// <summary>
/// Gets switching without a Save/Load cycle for <paramref name="file"/> is supported
/// when switching from this view content to <paramref name="newView"/>.
/// </summary>
bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView);
/// <summary>
/// Gets switching without a Save/Load cycle for <paramref name="file"/> is supported
/// when switching from <paramref name="oldView"/> to this view content.
/// </summary>
bool SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView);
/// <summary>
/// Executes an action before switching from this view content to the new view content.
/// </summary>
void SwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView);
/// <summary>
/// Executes an action before switching from the old view content to this view content.
/// </summary>
void SwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView);
#endregion #endregion
} }
} }

Loading…
Cancel
Save