working on script editor

This commit is contained in:
codeimp 2008-11-09 17:59:13 +00:00
parent b1792c9c10
commit 2a568cb7d7
11 changed files with 387 additions and 101 deletions

BIN
Resources/Icons/Close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

View file

@ -644,6 +644,7 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\Copy.png" /> <None Include="Resources\Copy.png" />
<None Include="Resources\Cut.png" /> <None Include="Resources\Cut.png" />
<None Include="Resources\Close.png" />
<Content Include="Resources\DB2.ico" /> <Content Include="Resources\DB2.ico" />
<None Include="Resources\ScriptCompile.png" /> <None Include="Resources\ScriptCompile.png" />
<None Include="Resources\ScriptConstant.xpm" /> <None Include="Resources\ScriptConstant.xpm" />

View file

@ -47,7 +47,11 @@ namespace CodeImp.DoomBuilder.Controls
#region ================== Variables #region ================== Variables
// The script edit control
protected ScriptEditorControl editor; protected ScriptEditorControl editor;
// Derived classes must set this!
protected ScriptConfiguration config;
#endregion #endregion
@ -56,7 +60,9 @@ namespace CodeImp.DoomBuilder.Controls
public virtual bool ExplicitSave { get { return true; } } public virtual bool ExplicitSave { get { return true; } }
public virtual bool IsSaveAsRequired { get { return true; } } public virtual bool IsSaveAsRequired { get { return true; } }
public virtual bool IsClosable { get { return true; } } public virtual bool IsClosable { get { return true; } }
public virtual bool IsReconfigurable { get { return true; } }
public bool IsChanged { get { return editor.IsChanged; } } public bool IsChanged { get { return editor.IsChanged; } }
public ScriptConfiguration Config { get { return config; } }
#endregion #endregion
@ -100,11 +106,46 @@ namespace CodeImp.DoomBuilder.Controls
return false; return false;
} }
// This changes the script configurations
public virtual void ChangeScriptConfig(ScriptConfiguration newconfig)
{
}
// Call this to set the tab title // Call this to set the tab title
protected void SetTitle(string title) protected void SetTitle(string title)
{ {
this.Text = title; this.Text = title;
} }
// Perform undo
public void Undo()
{
editor.Undo();
}
// Perform redo
public void Redo()
{
editor.Redo();
}
// Perform cut
public void Cut()
{
editor.Cut();
}
// Perform copy
public void Copy()
{
editor.Copy();
}
// Perform paste
public void Paste()
{
editor.Paste();
}
#endregion #endregion

View file

@ -62,7 +62,7 @@ namespace CodeImp.DoomBuilder.Controls
#region ================== Properties #region ================== Properties
public string Text { get { return scriptedit.Text; } set { scriptedit.Text = value; } } public string Text { get { return scriptedit.Text; } set { scriptedit.Text = value; } }
public bool IsChanged { get { return ischanged; } set { ischanged = value; } } public bool IsChanged { get { return scriptedit.CanUndo; } }
#endregion #endregion
@ -82,9 +82,6 @@ namespace CodeImp.DoomBuilder.Controls
private int curargumentindex = 0; private int curargumentindex = 0;
private int curfunctionstartpos = 0; private int curfunctionstartpos = 0;
// Text has changed?
private bool ischanged;
#endregion #endregion
#region ================== Contructor / Disposer #region ================== Contructor / Disposer
@ -118,7 +115,7 @@ namespace CodeImp.DoomBuilder.Controls
scriptedit.IsViewEOL = false; scriptedit.IsViewEOL = false;
scriptedit.IsVScrollBar = true; scriptedit.IsVScrollBar = true;
scriptedit.SetFoldFlags((int)ScriptFoldFlag.Box); scriptedit.SetFoldFlags((int)ScriptFoldFlag.Box);
// Symbol margin // Symbol margin
scriptedit.SetMarginTypeN(0, (int)ScriptMarginType.Symbol); scriptedit.SetMarginTypeN(0, (int)ScriptMarginType.Symbol);
scriptedit.SetMarginWidthN(0, 20); scriptedit.SetMarginWidthN(0, 20);
@ -134,9 +131,6 @@ namespace CodeImp.DoomBuilder.Controls
scriptedit.SetMarginWidthN(2, 5); scriptedit.SetMarginWidthN(2, 5);
scriptedit.SetMarginMaskN(2, 0); // none scriptedit.SetMarginMaskN(2, 0); // none
// Events
scriptedit.TextChanged += new EventHandler(scriptedit_TextChanged);
// Setup with default script config // Setup with default script config
// Disabled, the form designer doesn't like this // Disabled, the form designer doesn't like this
//SetupStyles(new ScriptConfiguration()); //SetupStyles(new ScriptConfiguration());
@ -290,6 +284,8 @@ namespace CodeImp.DoomBuilder.Controls
functionbar.Visible = (scriptconfig.FunctionRegEx.Length > 0); functionbar.Visible = (scriptconfig.FunctionRegEx.Length > 0);
// Rearrange the layout // Rearrange the layout
scriptedit.ClearDocumentStyle();
scriptedit.Text = scriptedit.Text;
this.PerformLayout(); this.PerformLayout();
} }
@ -465,17 +461,41 @@ namespace CodeImp.DoomBuilder.Controls
// Register image // Register image
scriptedit.MarkerDefinePixmap((int)index, bigstring); scriptedit.MarkerDefinePixmap((int)index, bigstring);
} }
// Perform undo
public void Undo()
{
scriptedit.Undo();
}
// Perform redo
public void Redo()
{
scriptedit.Redo();
}
// Perform cut
public void Cut()
{
scriptedit.Cut();
}
// Perform copy
public void Copy()
{
scriptedit.Copy();
}
// Perform paste
public void Paste()
{
scriptedit.Paste();
}
#endregion #endregion
#region ================== Events #region ================== Events
// Text changes
private void scriptedit_TextChanged(object sender, EventArgs e)
{
ischanged = true;
}
// Layout needs to be re-organized // Layout needs to be re-organized
protected override void OnLayout(LayoutEventArgs e) protected override void OnLayout(LayoutEventArgs e)
{ {
@ -500,8 +520,6 @@ namespace CodeImp.DoomBuilder.Controls
// CTRL+Space to autocomplete // CTRL+Space to autocomplete
if((e.KeyCode == Keys.Space) && (e.Modifiers == Keys.Control)) if((e.KeyCode == Keys.Space) && (e.Modifiers == Keys.Control))
{ {
scriptedit.MarkerAdd(scriptedit.LineFromPosition(scriptedit.CurrentPos), (int)ImageIndex.ScriptError);
// Hide call tip if any // Hide call tip if any
scriptedit.CallTipCancel(); scriptedit.CallTipCancel();

View file

@ -30,22 +30,23 @@ namespace CodeImp.DoomBuilder.Controls
{ {
this.tabs = new System.Windows.Forms.TabControl(); this.tabs = new System.Windows.Forms.TabControl();
this.toolbar = new System.Windows.Forms.ToolStrip(); this.toolbar = new System.Windows.Forms.ToolStrip();
this.openfile = new System.Windows.Forms.OpenFileDialog();
this.savefile = new System.Windows.Forms.SaveFileDialog();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.buttonnew = new System.Windows.Forms.ToolStripDropDownButton(); this.buttonnew = new System.Windows.Forms.ToolStripDropDownButton();
this.buttonopen = new System.Windows.Forms.ToolStripButton(); this.buttonopen = new System.Windows.Forms.ToolStripButton();
this.buttonsave = new System.Windows.Forms.ToolStripButton(); this.buttonsave = new System.Windows.Forms.ToolStripButton();
this.buttonsaveall = new System.Windows.Forms.ToolStripButton(); this.buttonsaveall = new System.Windows.Forms.ToolStripButton();
this.buttonscriptconfig = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.buttoncompile = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.buttonundo = new System.Windows.Forms.ToolStripButton(); this.buttonundo = new System.Windows.Forms.ToolStripButton();
this.buttonredo = new System.Windows.Forms.ToolStripButton(); this.buttonredo = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.buttoncut = new System.Windows.Forms.ToolStripButton(); this.buttoncut = new System.Windows.Forms.ToolStripButton();
this.buttoncopy = new System.Windows.Forms.ToolStripButton(); this.buttoncopy = new System.Windows.Forms.ToolStripButton();
this.buttonpaste = new System.Windows.Forms.ToolStripButton(); this.buttonpaste = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.buttonscriptconfig = new System.Windows.Forms.ToolStripDropDownButton();
this.buttoncompile = new System.Windows.Forms.ToolStripButton();
this.buttonclose = new System.Windows.Forms.ToolStripButton();
this.openfile = new System.Windows.Forms.OpenFileDialog();
this.savefile = new System.Windows.Forms.SaveFileDialog();
this.toolbar.SuspendLayout(); this.toolbar.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -61,6 +62,7 @@ namespace CodeImp.DoomBuilder.Controls
this.tabs.SelectedIndex = 0; this.tabs.SelectedIndex = 0;
this.tabs.Size = new System.Drawing.Size(691, 435); this.tabs.Size = new System.Drawing.Size(691, 435);
this.tabs.TabIndex = 0; this.tabs.TabIndex = 0;
this.tabs.Selecting += new System.Windows.Forms.TabControlCancelEventHandler(this.tabs_Selecting);
// //
// toolbar // toolbar
// //
@ -80,26 +82,13 @@ namespace CodeImp.DoomBuilder.Controls
this.buttonpaste, this.buttonpaste,
this.toolStripSeparator3, this.toolStripSeparator3,
this.buttonscriptconfig, this.buttonscriptconfig,
this.buttoncompile}); this.buttoncompile,
this.buttonclose});
this.toolbar.Location = new System.Drawing.Point(0, 0); this.toolbar.Location = new System.Drawing.Point(0, 0);
this.toolbar.Name = "toolbar"; this.toolbar.Name = "toolbar";
this.toolbar.Size = new System.Drawing.Size(697, 25); this.toolbar.Size = new System.Drawing.Size(697, 25);
this.toolbar.TabIndex = 1; this.toolbar.TabIndex = 1;
// //
// openfile
//
this.openfile.Title = "Open Script";
//
// savefile
//
this.savefile.Title = "Save Script As";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
//
// buttonnew // buttonnew
// //
this.buttonnew.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.buttonnew.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
@ -132,6 +121,7 @@ namespace CodeImp.DoomBuilder.Controls
this.buttonsave.Name = "buttonsave"; this.buttonsave.Name = "buttonsave";
this.buttonsave.Size = new System.Drawing.Size(23, 22); this.buttonsave.Size = new System.Drawing.Size(23, 22);
this.buttonsave.Text = "Save File"; this.buttonsave.Text = "Save File";
this.buttonsave.Click += new System.EventHandler(this.buttonsave_Click);
// //
// buttonsaveall // buttonsaveall
// //
@ -142,31 +132,13 @@ namespace CodeImp.DoomBuilder.Controls
this.buttonsaveall.Name = "buttonsaveall"; this.buttonsaveall.Name = "buttonsaveall";
this.buttonsaveall.Size = new System.Drawing.Size(23, 22); this.buttonsaveall.Size = new System.Drawing.Size(23, 22);
this.buttonsaveall.Text = "Save All Files"; this.buttonsaveall.Text = "Save All Files";
this.buttonsaveall.Click += new System.EventHandler(this.buttonsaveall_Click);
// //
// buttonscriptconfig // toolStripSeparator1
// //
this.buttonscriptconfig.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.toolStripSeparator1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.buttonscriptconfig.Enabled = false; this.toolStripSeparator1.Name = "toolStripSeparator1";
this.buttonscriptconfig.Image = global::CodeImp.DoomBuilder.Properties.Resources.ScriptPalette; this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
this.buttonscriptconfig.ImageTransparentColor = System.Drawing.Color.Magenta;
this.buttonscriptconfig.Name = "buttonscriptconfig";
this.buttonscriptconfig.Size = new System.Drawing.Size(23, 22);
this.buttonscriptconfig.Text = "Change Script Type";
//
// buttoncompile
//
this.buttoncompile.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.buttoncompile.Image = global::CodeImp.DoomBuilder.Properties.Resources.ScriptCompile;
this.buttoncompile.ImageTransparentColor = System.Drawing.Color.Magenta;
this.buttoncompile.Name = "buttoncompile";
this.buttoncompile.Size = new System.Drawing.Size(23, 22);
this.buttoncompile.Text = "Compile Script";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
// //
// buttonundo // buttonundo
// //
@ -176,6 +148,7 @@ namespace CodeImp.DoomBuilder.Controls
this.buttonundo.Name = "buttonundo"; this.buttonundo.Name = "buttonundo";
this.buttonundo.Size = new System.Drawing.Size(23, 22); this.buttonundo.Size = new System.Drawing.Size(23, 22);
this.buttonundo.Text = "Undo"; this.buttonundo.Text = "Undo";
this.buttonundo.Click += new System.EventHandler(this.buttonundo_Click);
// //
// buttonredo // buttonredo
// //
@ -185,12 +158,13 @@ namespace CodeImp.DoomBuilder.Controls
this.buttonredo.Name = "buttonredo"; this.buttonredo.Name = "buttonredo";
this.buttonredo.Size = new System.Drawing.Size(23, 22); this.buttonredo.Size = new System.Drawing.Size(23, 22);
this.buttonredo.Text = "Redo"; this.buttonredo.Text = "Redo";
this.buttonredo.Click += new System.EventHandler(this.buttonredo_Click);
// //
// toolStripSeparator3 // toolStripSeparator2
// //
this.toolStripSeparator3.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); this.toolStripSeparator2.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.toolStripSeparator3.Name = "toolStripSeparator3"; this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25); this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
// //
// buttoncut // buttoncut
// //
@ -200,6 +174,7 @@ namespace CodeImp.DoomBuilder.Controls
this.buttoncut.Name = "buttoncut"; this.buttoncut.Name = "buttoncut";
this.buttoncut.Size = new System.Drawing.Size(23, 22); this.buttoncut.Size = new System.Drawing.Size(23, 22);
this.buttoncut.Text = "Cut Selection"; this.buttoncut.Text = "Cut Selection";
this.buttoncut.Click += new System.EventHandler(this.buttoncut_Click);
// //
// buttoncopy // buttoncopy
// //
@ -209,6 +184,7 @@ namespace CodeImp.DoomBuilder.Controls
this.buttoncopy.Name = "buttoncopy"; this.buttoncopy.Name = "buttoncopy";
this.buttoncopy.Size = new System.Drawing.Size(23, 22); this.buttoncopy.Size = new System.Drawing.Size(23, 22);
this.buttoncopy.Text = "Copy Selection"; this.buttoncopy.Text = "Copy Selection";
this.buttoncopy.Click += new System.EventHandler(this.buttoncopy_Click);
// //
// buttonpaste // buttonpaste
// //
@ -218,6 +194,53 @@ namespace CodeImp.DoomBuilder.Controls
this.buttonpaste.Name = "buttonpaste"; this.buttonpaste.Name = "buttonpaste";
this.buttonpaste.Size = new System.Drawing.Size(23, 22); this.buttonpaste.Size = new System.Drawing.Size(23, 22);
this.buttonpaste.Text = "Paste"; this.buttonpaste.Text = "Paste";
this.buttonpaste.Click += new System.EventHandler(this.buttonpaste_Click);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
//
// buttonscriptconfig
//
this.buttonscriptconfig.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.buttonscriptconfig.Enabled = false;
this.buttonscriptconfig.Image = global::CodeImp.DoomBuilder.Properties.Resources.ScriptPalette;
this.buttonscriptconfig.ImageTransparentColor = System.Drawing.Color.Magenta;
this.buttonscriptconfig.Name = "buttonscriptconfig";
this.buttonscriptconfig.Size = new System.Drawing.Size(29, 22);
this.buttonscriptconfig.Text = "Change Script Type";
//
// buttoncompile
//
this.buttoncompile.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.buttoncompile.Image = global::CodeImp.DoomBuilder.Properties.Resources.ScriptCompile;
this.buttoncompile.ImageTransparentColor = System.Drawing.Color.Magenta;
this.buttoncompile.Margin = new System.Windows.Forms.Padding(3, 1, 0, 2);
this.buttoncompile.Name = "buttoncompile";
this.buttoncompile.Size = new System.Drawing.Size(23, 22);
this.buttoncompile.Text = "Compile Script";
//
// buttonclose
//
this.buttonclose.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
this.buttonclose.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.buttonclose.Image = global::CodeImp.DoomBuilder.Properties.Resources.Close;
this.buttonclose.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
this.buttonclose.ImageTransparentColor = System.Drawing.Color.Magenta;
this.buttonclose.Name = "buttonclose";
this.buttonclose.Size = new System.Drawing.Size(23, 22);
this.buttonclose.Text = "Close File";
this.buttonclose.Click += new System.EventHandler(this.buttonclose_Click);
//
// openfile
//
this.openfile.Title = "Open Script";
//
// savefile
//
this.savefile.Title = "Save Script As";
// //
// ScriptEditorPanel // ScriptEditorPanel
// //
@ -245,7 +268,6 @@ namespace CodeImp.DoomBuilder.Controls
private System.Windows.Forms.ToolStripButton buttonsave; private System.Windows.Forms.ToolStripButton buttonsave;
private System.Windows.Forms.ToolStripButton buttonsaveall; private System.Windows.Forms.ToolStripButton buttonsaveall;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripButton buttonscriptconfig;
private System.Windows.Forms.ToolStripButton buttoncompile; private System.Windows.Forms.ToolStripButton buttoncompile;
private System.Windows.Forms.ToolStripButton buttonundo; private System.Windows.Forms.ToolStripButton buttonundo;
private System.Windows.Forms.ToolStripButton buttonredo; private System.Windows.Forms.ToolStripButton buttonredo;
@ -254,5 +276,7 @@ namespace CodeImp.DoomBuilder.Controls
private System.Windows.Forms.ToolStripButton buttoncopy; private System.Windows.Forms.ToolStripButton buttoncopy;
private System.Windows.Forms.ToolStripButton buttonpaste; private System.Windows.Forms.ToolStripButton buttonpaste;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.ToolStripDropDownButton buttonscriptconfig;
private System.Windows.Forms.ToolStripButton buttonclose;
} }
} }

View file

@ -68,11 +68,19 @@ namespace CodeImp.DoomBuilder.Controls
// Fill the list of new document types // Fill the list of new document types
foreach(ScriptConfiguration cfg in scriptconfigs) foreach(ScriptConfiguration cfg in scriptconfigs)
{ {
// Button for new script menu
item = new ToolStripMenuItem(cfg.Description); item = new ToolStripMenuItem(cfg.Description);
//item.Image = buttonnew.Image; //item.Image = buttonnew.Image;
item.Tag = cfg; item.Tag = cfg;
item.Click += new EventHandler(buttonnew_Click); item.Click += new EventHandler(buttonnew_Click);
buttonnew.DropDownItems.Add(item); buttonnew.DropDownItems.Add(item);
// Button for script type menu
item = new ToolStripMenuItem(cfg.Description);
//item.Image = buttonnew.Image;
item.Tag = cfg;
item.Click += new EventHandler(buttonscriptconfig_Click);
buttonscriptconfig.DropDownItems.Add(item);
} }
// Setup supported extensions // Setup supported extensions
@ -89,16 +97,67 @@ namespace CodeImp.DoomBuilder.Controls
filterall += exts; filterall += exts;
} }
} }
openfile.Filter = "Script files|" + filterall + "|" + filterseperate; openfile.Filter = "Script files|" + filterall + "|" + filterseperate + "|All files|*.*";
// Done
UpdateToolbar();
} }
#endregion #endregion
#region ================== Methods #region ================== Methods
// This updates the toolbar for the current status
private void UpdateToolbar()
{
int numscriptsopen = tabs.TabPages.Count;
ScriptDocumentTab t = null;
// Get current script, if any are open
if(numscriptsopen > 0)
t = (tabs.SelectedTab as ScriptDocumentTab);
// Enable/disable buttons
buttonsave.Enabled = (t != null) && t.ExplicitSave;
buttonsaveall.Enabled = (numscriptsopen > 0);
buttoncompile.Enabled = (t != null) && (t.Config.Compiler != null);
buttonscriptconfig.Enabled = (t != null) && t.IsReconfigurable;
buttonundo.Enabled = (t != null);
buttonredo.Enabled = (t != null);
buttoncopy.Enabled = (t != null);
buttoncut.Enabled = (t != null);
buttonpaste.Enabled = (t != null);
buttonclose.Enabled = (t != null) && t.IsClosable;
if(t != null)
{
// Check the according script config in menu
foreach(ToolStripMenuItem item in buttonscriptconfig.DropDownItems)
{
ScriptConfiguration config = (item.Tag as ScriptConfiguration);
item.Checked = (config == t.Config);
}
}
}
#endregion #endregion
#region ================== Events #region ================== Events
// When the user changes the script configuration
private void buttonscriptconfig_Click(object sender, EventArgs e)
{
// Get the tab and new script config
ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab);
ScriptConfiguration scriptconfig = ((sender as ToolStripMenuItem).Tag as ScriptConfiguration);
// Change script config
t.ChangeScriptConfig(scriptconfig);
// Done
UpdateToolbar();
t.Focus();
}
// When new script is clicked // When new script is clicked
private void buttonnew_Click(object sender, EventArgs e) private void buttonnew_Click(object sender, EventArgs e)
@ -111,7 +170,8 @@ namespace CodeImp.DoomBuilder.Controls
tabs.TabPages.Add(t); tabs.TabPages.Add(t);
tabs.SelectedTab = t; tabs.SelectedTab = t;
// Focus to script editor // Done
UpdateToolbar();
t.Focus(); t.Focus();
} }
@ -145,11 +205,126 @@ namespace CodeImp.DoomBuilder.Controls
tabs.TabPages.Add(t); tabs.TabPages.Add(t);
tabs.SelectedTab = t; tabs.SelectedTab = t;
// Focus to script editor // Done
UpdateToolbar();
t.Focus(); t.Focus();
} }
} }
} }
// Save script clicked
private void buttonsave_Click(object sender, EventArgs e)
{
// Save the current script
ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab);
SaveScript(t);
}
// Save All clicked
private void buttonsaveall_Click(object sender, EventArgs e)
{
// Save all scripts
foreach(ScriptDocumentTab t in tabs.TabPages)
{
if(!SaveScript(t)) break;
}
}
// This is called by Save and Save All to save a script
// Returns false when cancelled by the user
private bool SaveScript(ScriptDocumentTab t)
{
// Do we have to do a save as?
if(t.IsSaveAsRequired)
{
// Setup save dialog
string scriptfilter = t.Config.Description + "|*." + string.Join(";*.", t.Config.Extensions);
savefile.Filter = scriptfilter + "|All files|*.*";
if(savefile.ShowDialog(this.ParentForm) == DialogResult.OK)
{
// Save to new filename
t.SaveAs(savefile.FileName);
return true;
}
else
{
// Cancelled
return false;
}
}
else
{
// Save to same filename
t.Save();
return true;
}
}
// A tab is selected
private void tabs_Selecting(object sender, TabControlCancelEventArgs e)
{
UpdateToolbar();
}
// This closes the current file
private void buttonclose_Click(object sender, EventArgs e)
{
ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab);
if(t.IsChanged)
{
// Ask to save
DialogResult result = MessageBox.Show(this.ParentForm, "Do you want to save changes to " + t.Text + "?", "Close File", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if(result == DialogResult.Yes)
{
// Save file
if(!SaveScript(t)) return;
}
else if(result == DialogResult.Cancel)
{
// Cancel
return;
}
}
// Close file
tabs.TabPages.Remove(t);
t.Dispose();
}
// Undo clicked
private void buttonundo_Click(object sender, EventArgs e)
{
ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab);
t.Undo();
}
// Redo clicked
private void buttonredo_Click(object sender, EventArgs e)
{
ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab);
t.Redo();
}
// Cut clicked
private void buttoncut_Click(object sender, EventArgs e)
{
ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab);
t.Cut();
}
// Copy clicked
private void buttoncopy_Click(object sender, EventArgs e)
{
ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab);
t.Copy();
}
// Paste clicked
private void buttonpaste_Click(object sender, EventArgs e)
{
ScriptDocumentTab t = (tabs.SelectedTab as ScriptDocumentTab);
t.Paste();
}
#endregion #endregion
} }

View file

@ -62,10 +62,10 @@ namespace CodeImp.DoomBuilder.Controls
// Initialize // Initialize
this.filepathname = ""; this.filepathname = "";
this.config = config;
editor.SetupStyles(config); editor.SetupStyles(config);
if(config.Extensions.Length > 0) ext = "." + config.Extensions[0]; if(config.Extensions.Length > 0) ext = "." + config.Extensions[0];
SetTitle("Untitled" + ext); SetTitle("Untitled" + ext);
editor.IsChanged = false;
editor.ClearUndoRedo(); editor.ClearUndoRedo();
} }
@ -98,7 +98,7 @@ namespace CodeImp.DoomBuilder.Controls
} }
// Done // Done
editor.IsChanged = false; editor.ClearUndoRedo();
return true; return true;
} }
@ -110,6 +110,7 @@ namespace CodeImp.DoomBuilder.Controls
filepathname = filename; filepathname = filename;
if(this.Save()) if(this.Save())
{ {
SetTitle(Path.GetFileName(filepathname));
return true; return true;
} }
else else
@ -139,10 +140,24 @@ namespace CodeImp.DoomBuilder.Controls
// Setup // Setup
this.filepathname = filepathname; this.filepathname = filepathname;
SetTitle(Path.GetFileName(filepathname)); SetTitle(Path.GetFileName(filepathname));
editor.IsChanged = false;
editor.ClearUndoRedo(); editor.ClearUndoRedo();
return true; return true;
} }
// This changes the script configurations
public override void ChangeScriptConfig(ScriptConfiguration newconfig)
{
string ext = "";
this.config = newconfig;
editor.SetupStyles(config);
if(filepathname.Length == 0)
{
if(config.Extensions.Length > 0) ext = "." + config.Extensions[0];
SetTitle("Untitled" + ext);
}
}
#endregion #endregion

View file

@ -50,6 +50,7 @@ namespace CodeImp.DoomBuilder.Controls
public override bool ExplicitSave { get { return false; } } public override bool ExplicitSave { get { return false; } }
public override bool IsClosable { get { return false; } } public override bool IsClosable { get { return false; } }
public override bool IsReconfigurable { get { return false; } }
#endregion #endregion
@ -60,6 +61,7 @@ namespace CodeImp.DoomBuilder.Controls
{ {
// Initialize // Initialize
this.lumpname = lumpname; this.lumpname = lumpname;
this.config = new ScriptConfiguration(); // TODO: Figure out script config
SetTitle(lumpname.ToUpper()); SetTitle(lumpname.ToUpper());
} }

View file

@ -60,6 +60,13 @@ namespace CodeImp.DoomBuilder.Properties {
} }
} }
internal static System.Drawing.Bitmap Close {
get {
object obj = ResourceManager.GetObject("Close", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
internal static System.Drawing.Bitmap ColorPick { internal static System.Drawing.Bitmap ColorPick {
get { get {
object obj = ResourceManager.GetObject("ColorPick", resourceCulture); object obj = ResourceManager.GetObject("ColorPick", resourceCulture);

View file

@ -121,17 +121,26 @@
<data name="Grid2" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Grid2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Grid2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Grid2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="Grid2_arrowup" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Grid2_arrowup.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Status0" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Status0" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Status0.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Status0.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="ScriptError" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ScriptError.xpm;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="UnknownImage" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="UnknownImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnknownImage.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\UnknownImage.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="Hourglass" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Copy" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Hourglass.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Copy.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="ViewNormal" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="NewScript" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ViewNormal.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\NewScript.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ScriptConstant" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ScriptConstant.xpm;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="Status1" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Status1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Status1.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Status1.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
@ -151,9 +160,6 @@
<data name="mergegeometry2" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="mergegeometry2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\mergegeometry2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\mergegeometry2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="OpenMap" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\OpenMap.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ViewTextureFloor" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="ViewTextureFloor" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ViewTextureFloor.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\ViewTextureFloor.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
@ -166,20 +172,20 @@
<data name="Monster2" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Monster2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Monster2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Monster2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="Hourglass" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Hourglass.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="File" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="File" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NewMap.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\NewMap.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="Copy" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Copy.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="mergegeometry" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="mergegeometry" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\mergegeometry.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\mergegeometry.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="NewMap" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="NewMap" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NewMap2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\NewMap2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="Grid2_arrowup" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="ViewNormal" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Grid2_arrowup.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\ViewNormal.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="SaveMap" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="SaveMap" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SaveMap.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\SaveMap.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
@ -190,6 +196,9 @@
<data name="Failed" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Failed" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Failed.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Failed.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="MissingTexture" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MissingTexture.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Zoom" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Zoom" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Zoom.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Zoom.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
@ -229,8 +238,11 @@
<data name="Filter" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Filter" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Filter.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Filter.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="SaveScript" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="ScriptKeyword" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SaveScript.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\ScriptKeyword.xpm;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="ScriptCompile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ScriptCompile.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="OpenScript" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="OpenScript" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\OpenScript.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\OpenScript.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
@ -244,25 +256,16 @@
<data name="Splash3_trans" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Splash3_trans" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Splash3_trans.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Splash3_trans.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="MissingTexture" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="OpenMap" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MissingTexture.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\OpenMap.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="Warning" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Warning" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Warning.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Warning.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="NewScript" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="SaveScript" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NewScript.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\SaveScript.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="ScriptCompile" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Close" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ScriptCompile.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Close.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ScriptConstant" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ScriptConstant.xpm;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="ScriptError" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ScriptError.xpm;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="ScriptKeyword" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ScriptKeyword.xpm;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
</root> </root>

BIN
Source/Resources/Close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B