UltimateZoneBuilder/Source/Controls/ScriptDocumentTab.cs

227 lines
5.2 KiB
C#
Raw Normal View History

#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Config;
using CodeImp.DoomBuilder.Types;
using CodeImp.DoomBuilder.IO;
2008-11-15 13:12:09 +00:00
using CodeImp.DoomBuilder.Compilers;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
internal abstract class ScriptDocumentTab : TabPage
{
#region ================== Constants
2008-11-06 15:00:01 +00:00
private const int EDITOR_BORDER_TOP = 8;
private const int EDITOR_BORDER_BOTTOM = 4;
private const int EDITOR_BORDER_LEFT = 4;
private const int EDITOR_BORDER_RIGHT = 4;
2008-11-06 15:00:01 +00:00
#endregion
2008-11-06 15:00:01 +00:00
#region ================== Variables
2008-11-06 15:00:01 +00:00
2008-11-09 17:59:13 +00:00
// The script edit control
2008-11-06 08:32:21 +00:00
protected ScriptEditorControl editor;
2008-11-09 17:59:13 +00:00
// Derived classes must set this!
protected ScriptConfiguration config;
2008-11-06 15:00:01 +00:00
2008-11-15 13:12:09 +00:00
// The panel we're on
protected ScriptEditorPanel panel;
#endregion
2008-11-06 15:00:01 +00:00
#region ================== Properties
2008-11-06 15:00:01 +00:00
public virtual bool ExplicitSave { get { return true; } }
public virtual bool IsSaveAsRequired { get { return true; } }
public virtual bool IsClosable { get { return true; } }
2008-11-09 17:59:13 +00:00
public virtual bool IsReconfigurable { get { return true; } }
2008-11-11 06:43:33 +00:00
public virtual string Filename { get { return null; } }
2008-11-15 13:12:09 +00:00
public ScriptEditorPanel Panel { get { return panel; } }
2008-11-06 15:00:01 +00:00
public bool IsChanged { get { return editor.IsChanged; } }
2008-11-09 17:59:13 +00:00
public ScriptConfiguration Config { get { return config; } }
2008-11-06 15:00:01 +00:00
#endregion
2008-11-06 15:00:01 +00:00
#region ================== Constructor
2008-11-06 15:00:01 +00:00
// Constructor
2008-11-15 13:12:09 +00:00
public ScriptDocumentTab(ScriptEditorPanel panel)
{
2008-11-15 13:12:09 +00:00
// Keep panel
this.panel = panel;
// Make the script control
2008-11-06 08:32:21 +00:00
editor = new ScriptEditorControl();
editor.Location = new Point(EDITOR_BORDER_LEFT, EDITOR_BORDER_TOP);
editor.Size = new Size(this.ClientSize.Width - EDITOR_BORDER_LEFT - EDITOR_BORDER_RIGHT,
this.ClientSize.Height - EDITOR_BORDER_TOP - EDITOR_BORDER_BOTTOM);
editor.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
editor.Name = "editor";
2008-11-10 16:11:44 +00:00
editor.TabStop = true;
editor.TabIndex = 0;
this.Controls.Add(editor);
}
2008-11-06 15:00:01 +00:00
// Disposer
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
#endregion
#region ================== Methods
2008-11-15 13:12:09 +00:00
// This moves the caret to the given line
public virtual void MoveToLine(int linenumber)
{
editor.MoveToLine(linenumber);
}
// This clears all marks
public virtual void ClearMarks()
{
editor.ClearMarks();
}
// This creates error marks for errors that apply to this file
public virtual void MarkScriptErrors(IEnumerable<CompilerError> errors)
{
// Clear all marks
ClearMarks();
// Go for all errors that apply to this script
foreach(CompilerError e in errors)
{
if(VerifyErrorForScript(e))
{
// Add a mark on the line where this error occurred
editor.AddMark(e.linenumber);
}
}
}
// This verifies if the specified error applies to this script
public virtual bool VerifyErrorForScript(CompilerError e)
{
return false;
}
// This compiles the script
public virtual void Compile()
{
}
2008-11-06 15:00:01 +00:00
// This saves the document (used for both explicit and implicit)
// Return true when successfully saved
public virtual bool Save()
{
return false;
}
// This saves the document to a new file
// Return true when successfully saved
public virtual bool SaveAs(string filename)
{
return false;
}
2008-11-09 17:59:13 +00:00
// This changes the script configurations
public virtual void ChangeScriptConfig(ScriptConfiguration newconfig)
{
}
2008-11-06 15:00:01 +00:00
// Call this to set the tab title
protected void SetTitle(string title)
{
this.Text = title;
}
2008-11-09 17:59:13 +00:00
// 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();
}
2008-11-06 15:00:01 +00:00
#endregion
2008-11-06 15:00:01 +00:00
#region ================== Events
2008-11-06 15:00:01 +00:00
2008-11-10 16:11:44 +00:00
// Mouse released
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
// Focus to the editor!
editor.Focus();
editor.GrabFocus();
}
// Receiving focus?
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
// Focus to the editor!
editor.Focus();
editor.GrabFocus();
}
#endregion
}
}