Browse Source

Implemented SD2-1054: Opening a file with different editor

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2647 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
195ecac29e
  1. 1
      src/Main/Base/Project/Src/Gui/Dialogs/OpenWithDialog.Designer.cs
  2. 41
      src/Main/Base/Project/Src/Gui/Dialogs/OpenWithDialog.cs
  3. 4
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/DefaultFileNodeCommands.cs
  4. 60
      src/Main/Base/Project/Src/Services/DisplayBinding/DisplayBindingService.cs

1
src/Main/Base/Project/Src/Gui/Dialogs/OpenWithDialog.Designer.cs generated

@ -99,6 +99,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -99,6 +99,7 @@ namespace ICSharpCode.SharpDevelop.Gui
this.setAsDefaultButton.TabIndex = 4;
this.setAsDefaultButton.Text = "Set as Default";
this.setAsDefaultButton.UseVisualStyleBackColor = true;
this.setAsDefaultButton.Click += new System.EventHandler(this.SetAsDefaultButtonClick);
//
// okButton
//

41
src/Main/Base/Project/Src/Gui/Dialogs/OpenWithDialog.cs

@ -21,21 +21,27 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -21,21 +21,27 @@ namespace ICSharpCode.SharpDevelop.Gui
sealed class ListEntry
{
internal readonly DisplayBindingDescriptor desc;
internal readonly bool IsDefault;
public ListEntry(DisplayBindingDescriptor desc)
public ListEntry(DisplayBindingDescriptor desc, bool isDefault)
{
this.desc = desc;
this.IsDefault = isDefault;
}
public override string ToString()
{
return StringParser.Parse(desc.Title);
if (IsDefault)
return StringParser.Parse(desc.Title) + " (Default)";
else
return StringParser.Parse(desc.Title);
}
}
string fileExtension;
int defaultBindingIndex;
public OpenWithDialog(ICollection<DisplayBindingDescriptor> displayBindings, string fileExtension)
public OpenWithDialog(IList<DisplayBindingDescriptor> displayBindings, int defaultBindingIndex, string fileExtension)
{
if (displayBindings == null)
throw new ArgumentNullException("list");
@ -44,14 +50,15 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -44,14 +50,15 @@ namespace ICSharpCode.SharpDevelop.Gui
InitializeComponent();
this.fileExtension = fileExtension;
this.defaultBindingIndex = defaultBindingIndex;
if (string.IsNullOrEmpty(fileExtension))
addButton.Enabled = false;
foreach (DisplayBindingDescriptor desc in displayBindings) {
programListBox.Items.Add(new ListEntry(desc));
for (int i = 0; i < displayBindings.Count; i++) {
programListBox.Items.Add(new ListEntry(displayBindings[i], i == defaultBindingIndex));
}
if (programListBox.Items.Count != 0) {
programListBox.SelectedIndex = 0;
if (defaultBindingIndex < programListBox.Items.Count) {
programListBox.SelectedIndex = defaultBindingIndex;
}
}
@ -78,7 +85,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -78,7 +85,7 @@ namespace ICSharpCode.SharpDevelop.Gui
Title = dlg.DisplayName,
Id = Guid.NewGuid().ToString()
};
programListBox.Items.Add(new ListEntry(DisplayBindingService.AddExternalProcessDisplayBinding(binding)));
programListBox.Items.Add(new ListEntry(DisplayBindingService.AddExternalProcessDisplayBinding(binding), false));
}
}
}
@ -88,9 +95,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -88,9 +95,11 @@ namespace ICSharpCode.SharpDevelop.Gui
DisplayBindingDescriptor binding = SelectedBinding;
if (binding != null) {
okButton.Enabled = true;
setAsDefaultButton.Enabled = true;
removeButton.Enabled = binding.GetLoadedBinding() is ExternalProcessDisplayBinding;
} else {
okButton.Enabled = false;
setAsDefaultButton.Enabled = false;
removeButton.Enabled = false;
}
}
@ -98,7 +107,23 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -98,7 +107,23 @@ namespace ICSharpCode.SharpDevelop.Gui
void RemoveButtonClick(object sender, EventArgs e)
{
DisplayBindingService.RemoveExternalProcessDisplayBinding((ExternalProcessDisplayBinding)SelectedBinding.GetLoadedBinding());
if (defaultBindingIndex == programListBox.SelectedIndex)
defaultBindingIndex = -1;
programListBox.Items.RemoveAt(programListBox.SelectedIndex);
}
void SetAsDefaultButtonClick(object sender, EventArgs e)
{
if (defaultBindingIndex >= 0) {
programListBox.Items[defaultBindingIndex] = new ListEntry(
((ListEntry)programListBox.Items[defaultBindingIndex]).desc,
false);
}
defaultBindingIndex = programListBox.SelectedIndex;
programListBox.Items[defaultBindingIndex] = new ListEntry(
((ListEntry)programListBox.Items[defaultBindingIndex]).desc,
true);
DisplayBindingService.SetDefaultCodon(fileExtension, SelectedBinding);
}
}
}

4
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/DefaultFileNodeCommands.cs

@ -68,7 +68,9 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -68,7 +68,9 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
/// </summary>
public static void OpenWith(string fileName)
{
using (OpenWithDialog dlg = new OpenWithDialog(DisplayBindingService.GetCodonsPerFileName(fileName), Path.GetExtension(fileName))) {
var codons = DisplayBindingService.GetCodonsPerFileName(fileName);
int defaultCodonIndex = codons.IndexOf(DisplayBindingService.GetDefaultCodonPerFileName(fileName));
using (OpenWithDialog dlg = new OpenWithDialog(codons, defaultCodonIndex, Path.GetExtension(fileName))) {
if (dlg.ShowDialog(WorkbenchSingleton.MainForm) == DialogResult.OK) {
FileUtility.ObservedLoad(new FileService.LoadFileWrapper(dlg.SelectedBinding.Binding).Invoke, fileName);
}

60
src/Main/Base/Project/Src/Services/DisplayBinding/DisplayBindingService.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
@ -20,13 +21,16 @@ namespace ICSharpCode.SharpDevelop @@ -20,13 +21,16 @@ namespace ICSharpCode.SharpDevelop
{
const string displayBindingPath = "/SharpDevelop/Workbench/DisplayBindings";
static Properties displayBindingServiceProperties;
static List<DisplayBindingDescriptor> bindings;
static List<ExternalProcessDisplayBinding> externalProcessDisplayBindings = new List<ExternalProcessDisplayBinding>();
internal static void InitializeService()
{
bindings = AddInTree.BuildItems<DisplayBindingDescriptor>("/SharpDevelop/Workbench/DisplayBindings", null, true);
foreach (ExternalProcessDisplayBinding binding in PropertyService.Get("OpenWithExternalProcesses", new ExternalProcessDisplayBinding[0])) {
displayBindingServiceProperties = PropertyService.Get("DisplayBindingService", new Properties());
foreach (ExternalProcessDisplayBinding binding in displayBindingServiceProperties.Get("ExternalProcesses", new ExternalProcessDisplayBinding[0])) {
if (binding != null) {
AddExternalProcessDisplayBindingInternal(binding);
}
@ -44,7 +48,7 @@ namespace ICSharpCode.SharpDevelop @@ -44,7 +48,7 @@ namespace ICSharpCode.SharpDevelop
static void SaveExternalProcessDisplayBindings()
{
PropertyService.Set("OpenWithExternalProcesses", externalProcessDisplayBindings.ToArray());
displayBindingServiceProperties.Set("ExternalProcesses", externalProcessDisplayBindings.ToArray());
}
static DisplayBindingDescriptor AddExternalProcessDisplayBindingInternal(ExternalProcessDisplayBinding binding)
@ -79,22 +83,46 @@ namespace ICSharpCode.SharpDevelop @@ -79,22 +83,46 @@ namespace ICSharpCode.SharpDevelop
/// </summary>
public static IDisplayBinding GetBindingPerFileName(string filename)
{
DisplayBindingDescriptor codon = GetCodonPerFileName(filename);
DisplayBindingDescriptor codon = GetDefaultCodonPerFileName(filename);
return codon == null ? null : codon.Binding;
}
static DisplayBindingDescriptor GetCodonPerFileName(string filename)
/// <summary>
/// Gets the default primary display binding for the specified file name.
/// </summary>
public static DisplayBindingDescriptor GetDefaultCodonPerFileName(string filename)
{
foreach (DisplayBindingDescriptor binding in bindings) {
if (!binding.IsSecondary && binding.CanOpenFile(filename)) {
if (binding.Binding != null && binding.Binding.CanCreateContentForFile(filename)) {
return binding;
string defaultCommandID = displayBindingServiceProperties.Get("Default" + Path.GetExtension(filename).ToLowerInvariant()) as string;
if (!string.IsNullOrEmpty(defaultCommandID)) {
foreach (DisplayBindingDescriptor binding in bindings) {
if (binding.Id == defaultCommandID) {
if (IsPrimaryBindingValidForFileName(binding, filename)) {
return binding;
}
}
}
}
foreach (DisplayBindingDescriptor binding in bindings) {
if (IsPrimaryBindingValidForFileName(binding, filename)) {
return binding;
}
}
return null;
}
public static void SetDefaultCodon(string extension, DisplayBindingDescriptor bindingDescriptor)
{
if (bindingDescriptor == null)
throw new ArgumentNullException("bindingDescriptor");
if (extension == null)
throw new ArgumentNullException("extension");
if (!extension.StartsWith("."))
throw new ArgumentException("extension must start with '.'");
displayBindingServiceProperties.Set("Default" + extension.ToLowerInvariant(), bindingDescriptor.Id);
}
/// <summary>
/// Gets list of possible primary display bindings for the specified file name.
/// </summary>
@ -102,15 +130,23 @@ namespace ICSharpCode.SharpDevelop @@ -102,15 +130,23 @@ namespace ICSharpCode.SharpDevelop
{
List<DisplayBindingDescriptor> list = new List<DisplayBindingDescriptor>();
foreach (DisplayBindingDescriptor binding in bindings) {
if (!binding.IsSecondary && binding.CanOpenFile(filename)) {
if (binding.Binding != null && binding.Binding.CanCreateContentForFile(filename)) {
list.Add(binding);
}
if (IsPrimaryBindingValidForFileName(binding, filename)) {
list.Add(binding);
}
}
return list;
}
static bool IsPrimaryBindingValidForFileName(DisplayBindingDescriptor binding, string filename)
{
if (!binding.IsSecondary && binding.CanOpenFile(filename)) {
if (binding.Binding != null && binding.Binding.CanCreateContentForFile(filename)) {
return true;
}
}
return false;
}
/// <summary>
/// Attach secondary view contents to the view content.
/// </summary>

Loading…
Cancel
Save