Browse Source

Allow the user to add custom layout configurations.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1765 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
c1944ef3cb
  1. BIN
      data/resources/StringResources.cz.resources
  2. BIN
      data/resources/StringResources.de.resources
  3. BIN
      data/resources/StringResources.es-mx.resources
  4. BIN
      data/resources/StringResources.es.resources
  5. BIN
      data/resources/StringResources.fr.resources
  6. BIN
      data/resources/StringResources.hu.resources
  7. BIN
      data/resources/StringResources.it.resources
  8. BIN
      data/resources/StringResources.kr.resources
  9. BIN
      data/resources/StringResources.nl.resources
  10. BIN
      data/resources/StringResources.no.resources
  11. BIN
      data/resources/StringResources.pl.resources
  12. BIN
      data/resources/StringResources.pt-br.resources
  13. BIN
      data/resources/StringResources.ro.resources
  14. BIN
      data/resources/StringResources.se.resources
  15. BIN
      data/resources/StringResources.tr.resources
  16. 85
      src/Main/Base/Project/Src/Commands/ChooseLayoutCommand.cs
  17. 79
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/LayoutConfiguration.cs
  18. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources

BIN
data/resources/StringResources.cz.resources

Binary file not shown.

BIN
data/resources/StringResources.de.resources

Binary file not shown.

BIN
data/resources/StringResources.es-mx.resources

Binary file not shown.

BIN
data/resources/StringResources.es.resources

Binary file not shown.

BIN
data/resources/StringResources.fr.resources

Binary file not shown.

BIN
data/resources/StringResources.hu.resources

Binary file not shown.

BIN
data/resources/StringResources.it.resources

Binary file not shown.

BIN
data/resources/StringResources.kr.resources

Binary file not shown.

BIN
data/resources/StringResources.nl.resources

Binary file not shown.

BIN
data/resources/StringResources.no.resources

Binary file not shown.

BIN
data/resources/StringResources.pl.resources

Binary file not shown.

BIN
data/resources/StringResources.pt-br.resources

Binary file not shown.

BIN
data/resources/StringResources.ro.resources

Binary file not shown.

BIN
data/resources/StringResources.se.resources

Binary file not shown.

BIN
data/resources/StringResources.tr.resources

Binary file not shown.

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

@ -1,12 +1,12 @@ @@ -1,12 +1,12 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Xml;
@ -36,8 +36,12 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -36,8 +36,12 @@ namespace ICSharpCode.SharpDevelop.Commands
}
int oldItem = 0;
bool editingLayout;
public override void Run()
{
if (editingLayout) return;
ComboBox comboBox = ((ToolBarComboBox)Owner).ComboBox;
string dataPath = Path.Combine(PropertyService.DataDirectory, "resources" + Path.DirectorySeparatorChar + "layouts");
string configPath = Path.Combine(PropertyService.ConfigDirectory, "layouts");
@ -50,8 +54,11 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -50,8 +54,11 @@ namespace ICSharpCode.SharpDevelop.Commands
}
if (comboBox.SelectedIndex == editIndex) {
MessageService.ShowMessage("Todo: Edit configurations");
editingLayout = true;
ShowLayoutEditor();
OnOwnerChanged(EventArgs.Empty);
comboBox.SelectedIndex = oldItem;
editingLayout = false;
} else if (comboBox.SelectedIndex == resetIndex) {
ResetToDefaults();
@ -64,6 +71,74 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -64,6 +71,74 @@ namespace ICSharpCode.SharpDevelop.Commands
oldItem = comboBox.SelectedIndex;
}
static IEnumerable<string> CustomLayoutNames {
get {
foreach (LayoutConfiguration layout in LayoutConfiguration.Layouts) {
if (layout.Custom) {
yield return layout.Name;
}
}
}
}
void ShowLayoutEditor()
{
using (Form frm = new Form()) {
frm.Text = StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.ChooseLayoutCommand.EditLayouts.Title}");
StringListEditor ed = new StringListEditor();
ed.Dock = DockStyle.Fill;
ed.ManualOrder = false;
ed.BrowseForDirectory = false;
ed.TitleText = StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.ChooseLayoutCommand.EditLayouts.Label}");
ed.AddButtonText = StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.ChooseLayoutCommand.EditLayouts.AddLayout}");
ed.LoadList(CustomLayoutNames);
FlowLayoutPanel p = new FlowLayoutPanel();
p.Dock = DockStyle.Bottom;
p.FlowDirection = FlowDirection.RightToLeft;
Button btn = new Button();
p.Height = btn.Height + 8;
btn.DialogResult = DialogResult.Cancel;
btn.Text = ResourceService.GetString("Global.CancelButtonText");
frm.CancelButton = btn;
p.Controls.Add(btn);
btn = new Button();
btn.DialogResult = DialogResult.OK;
btn.Text = ResourceService.GetString("Global.OKButtonText");
frm.AcceptButton = btn;
p.Controls.Add(btn);
frm.Controls.Add(ed);
frm.Controls.Add(p);
frm.FormBorderStyle = FormBorderStyle.FixedDialog;
frm.MaximizeBox = false;
frm.MinimizeBox = false;
frm.ClientSize = new System.Drawing.Size(400, 300);
frm.StartPosition = FormStartPosition.CenterParent;
if (frm.ShowDialog(WorkbenchSingleton.MainForm) == DialogResult.OK) {
IList<string> oldNames = new List<string>(CustomLayoutNames);
IList<string> newNames = ed.GetList();
// add newly added layouts
foreach (string newLayoutName in newNames) {
if (!oldNames.Contains(newLayoutName)) {
oldNames.Add(newLayoutName);
LayoutConfiguration.CreateCustom(newLayoutName);
}
}
// remove deleted layouts
LayoutConfiguration.Layouts.RemoveAll(delegate(LayoutConfiguration lc) {
return lc.Custom && !newNames.Contains(lc.Name);
});
LayoutConfiguration.SaveCustomLayoutConfiguration();
}
}
}
void ResetToDefaults()
{
if (MessageService.AskQuestion("${res:ICSharpCode.SharpDevelop.Commands.ChooseLayoutCommand.ResetToDefaultsQuestion}")) {
@ -83,6 +158,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -83,6 +158,7 @@ namespace ICSharpCode.SharpDevelop.Commands
void LayoutChanged(object sender, EventArgs e)
{
if (editingLayout) return;
ToolBarComboBox toolbarItem = (ToolBarComboBox)Owner;
ComboBox comboBox = toolbarItem.ComboBox;
for (int i = 0; i < comboBox.Items.Count; ++i) {
@ -92,11 +168,12 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -92,11 +168,12 @@ namespace ICSharpCode.SharpDevelop.Commands
}
}
}
protected override void OnOwnerChanged(EventArgs e)
protected override void OnOwnerChanged(EventArgs e)
{
base.OnOwnerChanged(e);
ToolBarComboBox toolbarItem = (ToolBarComboBox)Owner;
ComboBox comboBox = toolbarItem.ComboBox;
comboBox.Items.Clear();
int index = 0;
foreach (LayoutConfiguration config in LayoutConfiguration.Layouts) {
if (LayoutConfiguration.CurrentLayoutName == config.Name) {

79
src/Main/Base/Project/Src/Gui/Workbench/Layouts/LayoutConfiguration.cs

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
// </file>
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Xml;
@ -18,18 +18,31 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -18,18 +18,31 @@ namespace ICSharpCode.SharpDevelop.Gui
{
public class LayoutConfiguration
{
readonly static string configFile = "LayoutConfig.xml";
public static ArrayList Layouts = new ArrayList();
public static string[] DefaultLayouts = new string[] {
const string DataLayoutSubPath = "resources/layouts";
const string configFile = "LayoutConfig.xml";
public static readonly List<LayoutConfiguration> Layouts = new List<LayoutConfiguration>();
public static string[] DefaultLayouts = new string[] {
"Default",
"Debug",
"Plain"
};
string name;
string fileName;
string displayName = null;
bool readOnly;
bool custom;
public bool Custom {
get {
return custom;
}
set {
custom = value;
}
}
public string FileName {
get {
@ -67,16 +80,28 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -67,16 +80,28 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
public LayoutConfiguration()
LayoutConfiguration()
{
}
LayoutConfiguration(XmlElement el)
LayoutConfiguration(XmlElement el, bool custom)
{
name = el.GetAttribute("name");
fileName = el.GetAttribute("file");
readOnly = Boolean.Parse(el.GetAttribute("readonly"));
this.custom = custom;
}
public static LayoutConfiguration CreateCustom(string name)
{
LayoutConfiguration l = new LayoutConfiguration();
l.name = name;
l.fileName = Path.GetRandomFileName() + ".xml";
File.Copy(Path.Combine(Path.Combine(PropertyService.DataDirectory, DataLayoutSubPath), "Default.xml"),
Path.Combine(Path.Combine(PropertyService.ConfigDirectory, "layouts"), l.fileName));
l.custom = true;
Layouts.Add(l);
return l;
}
public override string ToString()
@ -113,7 +138,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -113,7 +138,7 @@ namespace ICSharpCode.SharpDevelop.Gui
public static string CurrentLayoutTemplateFileName {
get {
string dataPath = Path.Combine(PropertyService.DataDirectory, "resources" + Path.DirectorySeparatorChar + "layouts");
string dataPath = Path.Combine(PropertyService.DataDirectory, DataLayoutSubPath);
LayoutConfiguration current = CurrentLayout;
if (current != null) {
return Path.Combine(dataPath, current.FileName);
@ -145,25 +170,41 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -145,25 +170,41 @@ namespace ICSharpCode.SharpDevelop.Gui
internal static void LoadLayoutConfiguration()
{
if (Layouts.Count == 0) {
string configPath = Path.Combine(PropertyService.ConfigDirectory, "layouts");
if (File.Exists(Path.Combine(configPath, configFile))) {
LoadLayoutConfiguration(Path.Combine(configPath, configFile));
}
string dataPath = Path.Combine(PropertyService.DataDirectory, "resources" + Path.DirectorySeparatorChar + "layouts");
if (File.Exists(Path.Combine(dataPath, configFile))) {
LoadLayoutConfiguration(Path.Combine(dataPath, configFile));
}
Layouts.Clear();
string configPath = Path.Combine(PropertyService.ConfigDirectory, "layouts");
if (File.Exists(Path.Combine(configPath, configFile))) {
LoadLayoutConfiguration(Path.Combine(configPath, configFile), true);
}
string dataPath = Path.Combine(PropertyService.DataDirectory, DataLayoutSubPath);
if (File.Exists(Path.Combine(dataPath, configFile))) {
LoadLayoutConfiguration(Path.Combine(dataPath, configFile), false);
}
}
static void LoadLayoutConfiguration(string layoutConfig)
static void LoadLayoutConfiguration(string layoutConfig, bool custom)
{
XmlDocument doc = new XmlDocument();
doc.Load(layoutConfig);
foreach (XmlElement el in doc.DocumentElement.ChildNodes) {
Layouts.Add(new LayoutConfiguration(el));
Layouts.Add(new LayoutConfiguration(el, custom));
}
}
public static void SaveCustomLayoutConfiguration()
{
string configPath = Path.Combine(PropertyService.ConfigDirectory, "layouts");
using (XmlTextWriter w = new XmlTextWriter(Path.Combine(configPath, configFile), System.Text.Encoding.UTF8)) {
w.Formatting = Formatting.Indented;
w.WriteStartElement("LayoutConfig");
foreach (LayoutConfiguration lc in Layouts) {
w.WriteStartElement("Layout");
w.WriteAttributeString("name", lc.name);
w.WriteAttributeString("file", lc.fileName);
w.WriteAttributeString("readonly", lc.readOnly.ToString());
w.WriteEndElement();
}
w.WriteEndElement();
}
}

BIN
src/Main/StartUp/Project/Resources/StringResources.resources

Binary file not shown.
Loading…
Cancel
Save