2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#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.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Controls;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Windows
|
|
|
|
{
|
2021-11-28 13:00:24 +00:00
|
|
|
public partial class ScriptEditorForm : DelayedForm
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Closing?
|
|
|
|
private bool appclose;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public ScriptEditorPanel Editor { get { return editor; } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public ScriptEditorForm()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
2016-11-24 11:55:11 +00:00
|
|
|
editor.Initialize(this);
|
2019-12-31 12:57:29 +00:00
|
|
|
KeyPreview = true;
|
|
|
|
PreviewKeyDown += new PreviewKeyDownEventHandler(ScriptEditorForm_PreviewKeyDown);
|
|
|
|
KeyDown += new KeyEventHandler(ScriptEditorForm_KeyDown);
|
2019-12-31 13:32:57 +00:00
|
|
|
KeyUp += new KeyEventHandler(ScriptEditorForm_KeyDown);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2019-12-31 12:57:29 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
2019-12-31 12:57:29 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#region ================== Methods
|
2019-12-31 12:57:29 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This asks to save files and returns the result
|
|
|
|
// Also does implicit saves
|
|
|
|
// Returns false when cancelled by the user
|
|
|
|
public bool AskSaveAll()
|
|
|
|
{
|
|
|
|
// Implicit-save the script lumps
|
|
|
|
editor.ImplicitSave();
|
|
|
|
|
|
|
|
// Save other scripts
|
|
|
|
return editor.AskSaveAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close the window
|
|
|
|
new public void Close()
|
|
|
|
{
|
|
|
|
appclose = true;
|
|
|
|
base.Close();
|
|
|
|
}
|
|
|
|
|
2016-11-26 00:02:56 +00:00
|
|
|
//mxd
|
|
|
|
internal void DisplayError(TextResourceErrorItem error)
|
|
|
|
{
|
|
|
|
editor.ShowError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
|
|
|
/*internal void DisplayError(TextFileErrorItem error)
|
|
|
|
{
|
|
|
|
editor.ShowError(error);
|
|
|
|
}*/
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
2019-12-31 12:57:29 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#region ================== Events
|
|
|
|
|
2019-12-31 12:57:29 +00:00
|
|
|
private void ScriptEditorForm_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.KeyCode == Keys.F10)
|
|
|
|
e.IsInputKey = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ScriptEditorForm_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.KeyCode == Keys.F10)
|
|
|
|
{
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Window is loaded
|
|
|
|
private void ScriptEditorForm_Load(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Apply panel settings
|
|
|
|
editor.ApplySettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window is shown
|
|
|
|
private void ScriptEditorForm_Shown(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Focus to script editor
|
|
|
|
editor.ForceFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window is closing
|
|
|
|
private void ScriptEditorForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
{
|
|
|
|
editor.SaveSettings();
|
|
|
|
|
|
|
|
// Only when closed by the user
|
2016-09-10 20:45:41 +00:00
|
|
|
if(!appclose && (e.CloseReason == CloseReason.UserClosing || e.CloseReason == CloseReason.FormOwnerClosing))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2009-05-10 19:04:47 +00:00
|
|
|
// Remember if scipts are changed
|
|
|
|
General.Map.ApplyScriptChanged();
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Ask to save scripts
|
|
|
|
if(AskSaveAll())
|
|
|
|
{
|
|
|
|
// Let the general call close the editor
|
|
|
|
General.Map.CloseScriptEditor(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Cancel
|
|
|
|
e.Cancel = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not cancelling?
|
|
|
|
if(!e.Cancel) editor.OnClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Help
|
|
|
|
private void ScriptEditorForm_HelpRequested(object sender, HelpEventArgs hlpevent)
|
|
|
|
{
|
2013-08-08 11:04:13 +00:00
|
|
|
if(!editor.LaunchKeywordHelp()) General.ShowHelp("w_scripteditor.html"); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
hlpevent.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|