working on script editor

This commit is contained in:
codeimp 2008-11-11 06:43:33 +00:00
parent 869113c389
commit 72f4763c13
5 changed files with 85 additions and 30 deletions

View file

@ -61,6 +61,7 @@ namespace CodeImp.DoomBuilder.Controls
public virtual bool IsSaveAsRequired { get { return true; } }
public virtual bool IsClosable { get { return true; } }
public virtual bool IsReconfigurable { get { return true; } }
public virtual string Filename { get { return null; } }
public bool IsChanged { get { return editor.IsChanged; } }
public ScriptConfiguration Config { get { return config; } }

View file

@ -30,6 +30,7 @@ using CodeImp.DoomBuilder.Config;
using CodeImp.DoomBuilder.Types;
using CodeImp.DoomBuilder.IO;
using System.Globalization;
using System.IO;
#endregion
@ -112,9 +113,22 @@ namespace CodeImp.DoomBuilder.Controls
// Load this!
ScriptLumpDocumentTab t = new ScriptLumpDocumentTab(maplumpinfo.name, maplumpinfo.script);
tabs.TabPages.Add(t);
tabs.SelectedIndex = 0;
}
}
// Load the files that were previously opened for this map
foreach(String filename in General.Map.Options.ScriptFiles)
{
// Does this file exist?
if(File.Exists(filename))
{
// Load this!
OpenFile(filename);
}
}
// Select the first tab
if(tabs.TabPages.Count > 0) tabs.SelectedIndex = 0;
// Done
UpdateToolbar();
@ -124,6 +138,17 @@ namespace CodeImp.DoomBuilder.Controls
#region ================== Methods
// This writes all explicitly opened files to the configuration
public void WriteOpenFilesToConfiguration()
{
List<string> files = new List<string>();
foreach(ScriptDocumentTab t in tabs.TabPages)
{
if(t.ExplicitSave) files.Add(t.Filename);
}
General.Map.Options.ScriptFiles = files;
}
// This asks to save files and returns the result
public bool AskSaveAll()
{
@ -238,6 +263,38 @@ namespace CodeImp.DoomBuilder.Controls
ForceFocus();
}
}
// This opens the given file
public void OpenFile(string filename)
{
ScriptConfiguration foundconfig = new ScriptConfiguration();
// Find the most suitable script configuration to use
foreach(ScriptConfiguration cfg in scriptconfigs)
{
foreach(string ext in cfg.Extensions)
{
// Use this configuration if the extension matches
if(filename.EndsWith("." + ext, true, CultureInfo.InvariantCulture))
{
foundconfig = cfg;
break;
}
}
}
// Create new document
ScriptFileDocumentTab t = new ScriptFileDocumentTab(foundconfig);
if(t.Open(filename))
{
// Add to tabs
tabs.TabPages.Add(t);
tabs.SelectedTab = t;
// Done
UpdateToolbar();
}
}
#endregion
@ -278,33 +335,8 @@ namespace CodeImp.DoomBuilder.Controls
// Show open file dialog
if(openfile.ShowDialog(this.ParentForm) == DialogResult.OK)
{
ScriptConfiguration foundconfig = new ScriptConfiguration();
// Find the most suitable script configuration to use
foreach(ScriptConfiguration cfg in scriptconfigs)
{
foreach(string ext in cfg.Extensions)
{
// Use this configuration if the extension matches
if(openfile.FileName.EndsWith("." + ext, true, CultureInfo.InvariantCulture))
{
foundconfig = cfg;
break;
}
}
}
// Create new document
ScriptFileDocumentTab t = new ScriptFileDocumentTab(foundconfig);
if(t.Open(openfile.FileName))
{
// Add to tabs
tabs.TabPages.Add(t);
tabs.SelectedTab = t;
// Done
UpdateToolbar();
}
// TODO: Make multi-select possible
OpenFile(openfile.FileName);
}
}

View file

@ -50,6 +50,7 @@ namespace CodeImp.DoomBuilder.Controls
#region ================== Properties
public override bool IsSaveAsRequired { get { return (filepathname.Length == 0); } }
public override string Filename { get { return filepathname; } }
#endregion

View file

@ -1084,6 +1084,9 @@ namespace CodeImp.DoomBuilder
{
if(!scriptwindow.IsDisposed)
{
// Remember what files were open
scriptwindow.Editor.WriteOpenFilesToConfiguration();
// Remember if lumps are changed
scriptschanged |= scriptwindow.Editor.CheckImplicitChanges();

View file

@ -51,12 +51,16 @@ namespace CodeImp.DoomBuilder.Map
// Additional resources
private DataLocationList resources;
// Script files opened
private List<string> scriptfiles;
#endregion
#region ================== Properties
public string ConfigFile { get { return configfile; } set { configfile = value; } }
public DataLocationList Resources { get { return resources; } }
public List<string> ScriptFiles { get { return scriptfiles; } set { scriptfiles = value; } }
public string PreviousName { get { return previousname; } set { previousname = value; } }
public string CurrentName
{
@ -86,6 +90,7 @@ namespace CodeImp.DoomBuilder.Map
this.configfile = "";
this.resources = new DataLocationList();
this.mapconfig = new Configuration(true);
this.scriptfiles = new List<string>();
}
// Constructor to load from Doom Builder Map Settings Configuration
@ -100,9 +105,12 @@ namespace CodeImp.DoomBuilder.Map
this.configfile = cfg.ReadSetting("gameconfig", "");
this.resources = new DataLocationList();
this.mapconfig = new Configuration(true);
this.scriptfiles = new List<string>();
// Go for all items in the map info
// Read map configuration
this.mapconfig.Root = cfg.ReadSetting("maps." + mapname, new Hashtable());
// Resources
IDictionary reslist = this.mapconfig.ReadSetting("resources", new Hashtable());
foreach(DictionaryEntry mp in reslist)
{
@ -123,12 +131,18 @@ namespace CodeImp.DoomBuilder.Map
AddResource(res);
}
}
// Scripts
IDictionary scplist = this.mapconfig.ReadSetting("scripts", new Hashtable());
foreach(DictionaryEntry mp in scplist)
scriptfiles.Add(mp.Value.ToString());
}
~MapOptions()
{
// Clean up
this.resources = null;
this.scriptfiles = null;
}
#endregion
@ -140,9 +154,13 @@ namespace CodeImp.DoomBuilder.Map
{
Configuration wadcfg;
// Write settings to config
// Write resources to config
resources.WriteToConfig(mapconfig, "resources");
// Write scripts to config
for(int i = 0; i < scriptfiles.Count; i++)
mapconfig.WriteSetting("scripts." + "file" + i.ToString(CultureInfo.InvariantCulture), scriptfiles[i]);
// Load the file or make a new file
if(File.Exists(settingsfile))
wadcfg = new Configuration(settingsfile, true);