Skip to content

Commit

Permalink
Starting to wire up "Add Else/Else If" buttons, but need to look at a…
Browse files Browse the repository at this point in the history
…gain at design of notification. Add unit test project.

git-svn-id: https://quest.svn.codeplex.com/svn/trunk@3933 4a90e977-6436-4932-9605-20e10c2b6fb3
  • Loading branch information
alexwarren committed Dec 4, 2010
1 parent 7fbc666 commit 41fc73a
Show file tree
Hide file tree
Showing 19 changed files with 359 additions and 49 deletions.
44 changes: 22 additions & 22 deletions Editor/IfEditor.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 29 additions & 6 deletions Editor/IfEditor.vb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
Implements ICommandEditor

Private m_controller As EditorController
Private m_data As IEditorData
Private m_data As EditableIfScript
Private m_children As New List(Of IfEditorChild)
Private m_lastEditorChild As IfEditorChild
Private m_hasElse As Boolean

Public Event Dirty(ByVal sender As Object, ByVal args As DataModifiedEventArgs) Implements ICommandEditor.Dirty

Expand All @@ -19,7 +20,17 @@
End Sub

Private Sub AddChild(ByVal child As IfEditorChild)
m_children.Add(child)
If Not m_hasElse Then
m_children.Add(child)
Else
' if we have an "else" then we want to insert a new "else if" before the "else"
m_children.Insert(m_children.Count - 2, child)
End If

If child.ElseIfMode = IfEditorChild.IfEditorChildMode.ElseMode Then
m_hasElse = True
End If

AddHandler child.ChangeHeight, AddressOf IfEditorChild_HeightChanged
AddHandler child.Dirty, AddressOf ctlChild_Dirty
m_lastEditorChild = child
Expand Down Expand Up @@ -52,19 +63,19 @@
RaiseEvent Dirty(sender, args)
End Sub

Private Sub AddElseIf()
Private Sub AddElseChildControl(ByVal addElseIf As Boolean)
ctlChild.Dock = DockStyle.None
Dim newIfEditorChild As New IfEditorChild
newIfEditorChild.Parent = pnlContainer
newIfEditorChild.Controller = m_controller
newIfEditorChild.Top = m_lastEditorChild.Top + m_lastEditorChild.Height
newIfEditorChild.Top = m_lastEditorChild.Top + m_lastEditorChild.Height ' not necessarily....
newIfEditorChild.Width = pnlContainer.Width
newIfEditorChild.Anchor = newIfEditorChild.Anchor Or AnchorStyles.Right
newIfEditorChild.ElseIfMode = If(addElseIf, IfEditorChild.IfEditorChildMode.ElseIfMode, IfEditorChild.IfEditorChildMode.ElseMode)
newIfEditorChild.Visible = True
AddChild(newIfEditorChild)

' also need to populate newchild?
' also need to hook up Dirty event
End Sub

Private Sub IfEditorChild_HeightChanged(ByVal sender As IfEditorChild, ByVal newHeight As Integer)
Expand All @@ -82,8 +93,20 @@
' "else" should appear at the bottom so have a separate parent splitter

Private Sub cmdAddElse_ButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddElse.ButtonClick
AddElseIf()
'AddElse(False)
AddElse()
End Sub

Private Sub mnuAddElse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAddElse.Click
'AddElse(False)
AddElse()
End Sub

Private Sub mnuAddElseIf_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAddElseIf.Click
'AddElse(True)
End Sub

Private Sub AddElse()
m_data.AddElse()
End Sub
End Class
36 changes: 25 additions & 11 deletions Editor/IfEditorChild.vb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
Public Class IfEditorChild

Public Enum IfEditorChildMode
IfMode
ElseIfMode
ElseMode
End Enum

Private m_controller As EditorController
Private m_elseIfMode As Boolean
Private m_mode As IfEditorChildMode
Private m_expanded As Boolean

Public Event Dirty(ByVal sender As Object, ByVal args As DataModifiedEventArgs)
Expand All @@ -13,7 +19,7 @@
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
ElseIfMode = False
ElseIfMode = IfEditorChildMode.IfMode
Expanded = True
cmdExpand.Font = New Font("Marlett", cmdExpand.Font.Size * 1.1F)
End Sub
Expand Down Expand Up @@ -63,18 +69,26 @@
End If
End Sub

Public Property ElseIfMode As Boolean
Public Property ElseIfMode As IfEditorChildMode
Get
Return m_elseIfMode
Return m_mode
End Get
Set(ByVal value As Boolean)
m_elseIfMode = value
Set(ByVal value As IfEditorChildMode)
m_mode = value

Select Case value
Case IfEditorChildMode.IfMode
lblIf.Text = "If:"
Case IfEditorChildMode.ElseIfMode
lblIf.Text = "Else If:"
Case IfEditorChildMode.ElseMode
lblIf.Text = "Else:"
ctlThenScript.Height += ctlThenScript.Top - ctlExpression.Top
ctlThenScript.Top = ctlExpression.Top
lblThen.Visible = False
ctlExpression.Visible = False
End Select

If value Then
lblIf.Text = "Else If:"
Else
lblIf.Text = "If:"
End If
End Set
End Property

Expand Down
10 changes: 5 additions & 5 deletions Editor/ScriptEditor.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Editor/ScriptEditor.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAH5SURBVDhPY2AAAi8vLwM3L889np6eTvX19UwgMaJBaGgo
s5OTa7qjo8t/J2fnb97e3oEgMWwG2NvbswQFBSm5u7vmweVBgo6Ozkm29g7bzC1t/xsamf1xd/esQjdE
Xt6ew9LW0cnby+u7vb3jHBQLbG3dJe3tXSwcHFy2WdnY/7ezd/jv7+O50dXVlRuk0MLCgtPd3X2FvqHT
b1NT824tLS0erF4E2srm5ORSYOjg/NvOzuk/0DvLzM1t9Cwt7Sbb2tj81zMwmaykZMxPKHwY7excNG1t
s5OTa7qjo8t/J2fnb97e3oEgMWwG2NvbswQFBSm5u7vmweVBgo6Ozkm29g7bzC1t/+voGv5xd/esQjdE
Xt6ew9LW0cnby+u7vb3jHBQLbG3dJe3tXSwcHFy2WdnY/7ezd/jv7+O50dXVlRuk0MLCgtPd3X2Flo7T
b1NT824tLS0erF4E2srm5ORSoOPg/NvOzuk/0DvLzM1t9Cwt7Sbb2tj81zMwmaykZMxPKHwY7excNG1t
nc6bmVv/19fX/25obPReTUt3nYyMBSchzXB5fX1jBz19k5+WVrb/tfSN7snIaAkRr9ncXEFFReuSrp7h
P30Dk/8mphb/tbR1bhFlgKGhobyauvZVNXWtPxqammuEhSVMZGVVthkYGv9XUdPOxGsIMHQlZOWVT8kp
qv7X1jM4JCMjIyQuLs4NwnKKatMNDIy/KGtry2I1RN7enkNGUXWRhLT0Ry0twydaWgZacIXy8hwMDEJ8
2voGZyWk5CcBxTETmrScnLeYhMJ/VTVtoFM1WhkYxMFpAAkwKStrqSgrK98XEBCQB4qjJHk2YWHRViFh
8f/y8sq72Nh41dAVQA1iNjW1nMzJx2mKIS8pp2zEyso+EShhB8S8eAKLBSjHRVSM0EURACLodd2hL0+T
8f/y8sq72Nh41dAVQA1iNjW1nMzJx2mKIS8pp2zEyso+EShhB8S8eAKLBSjHRVSM0EURAMCHdb/BikvE
AAAAAElFTkSuQmCC
</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions Editor/ScriptEditor.vb
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,5 @@
cmdMoveUp.Enabled = enabled
cmdMoveDown.Enabled = enabled
End Sub

End Class
21 changes: 21 additions & 0 deletions EditorController/EditableIfScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,26 @@ public void SetAttribute(string attribute, object value)
throw new ArgumentOutOfRangeException("attribute", "Unrecognised 'if' attribute");
}
}

public void AddElse()
{
m_ifScript.SetElse(null);
}

public void AddElseIf()
{
// expects an IfScript with an expression and just a "then" script
//m_ifScript.AddElseIf(null);
}

public void RemoveElseIf()
{

}

public void RemoveElse()
{
m_ifScript.SetElse(null);
}
}
}
2 changes: 2 additions & 0 deletions EditorController/EditableScriptBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ internal IScript Script

private void ScriptUpdated(object sender, ScriptUpdatedEventArgs e)
{
// this hasn't been designed to cope with things like "adding else"...

if (Updated != null)
{
if (e != null && e.IsParameterUpdate)
Expand Down
49 changes: 49 additions & 0 deletions EditorControllerTests/EditableScriptTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AxeSoftware.Quest;

namespace EditorControllerTests
{
[TestClass]
public class EditableScriptTests
{
private EditorController m_controller;

[TestInitialize]
public void Init()
{
m_controller = new EditorController();
m_controller.ClearTree += new EditorController.VoidHandler(m_controller_ClearTree);
m_controller.BeginTreeUpdate += new EditorController.VoidHandler(m_controller_BeginTreeUpdate);
m_controller.EndTreeUpdate += new EditorController.VoidHandler(m_controller_EndTreeUpdate);
m_controller.AddedNode += new EditorController.AddedNodeHandler(m_controller_AddedNode);
m_controller.Initialise(@"..\..\..\EditorControllerTests\test.aslx");
}

void m_controller_ClearTree()
{
}

void m_controller_BeginTreeUpdate()
{
}

void m_controller_EndTreeUpdate()
{
}

void m_controller_AddedNode(string key, string text, string parent, System.Drawing.Color? foreColor, System.Drawing.Color? backColor)
{
}

[TestMethod]
public void CreateScript()
{
EditableScripts newScripts = m_controller.CreateNewEditableScripts("game", "somescript", "msg (\"\")");
Assert.IsTrue(newScripts.Scripts.Count() == 1);
}
}
}
Loading

0 comments on commit 41fc73a

Please sign in to comment.