Commits

Anonymous committed fbc91b2

+ Multiple Shortcuts per Node
* Code Cleanups
** NOT WORKING **

  • Participants
  • Parent commits a617f05

Comments (0)

Files changed (6)

File Source/CPP/CPP.cs

 
 		public FindResult Script_Find( FindResult _scope, String _search, Boolean _useRegEx )
 		{
-			if( _scope.file.get_IsOpen( Constants.vsDocumentKindText ) )
+			TextDocument doc = _scope.file.Document != null ? (TextDocument)_scope.file.Document.Object( "TextDocument" ) : null;
+
+			if ( doc != null )
 			{
-				TextDocument doc = (TextDocument)_scope.file.Document.Object("TextDocument");
 				doc.Selection.MoveToAbsoluteOffset( _scope.start, false );
 				doc.Selection.MoveToAbsoluteOffset( _scope.end, true );
 				TextRanges textRanges = null;
 		public FindResult Script_Replace( FindResult _scope, String _search, String _replace, ref Boolean _useRegEx, out FindResult _returnScope )
 		{
 			String file;
-			TextDocument doc = null;
+			TextDocument doc = _scope.file.Document != null ? (TextDocument)_scope.file.Document.Object( "TextDocument" ) : null;
 
-			if ( _scope.file.get_IsOpen( Constants.vsDocumentKindText ) )
+			if ( doc != null )
 			{
-				doc = (TextDocument)_scope.file.Document.Object( "TextDocument" );
-				doc.Selection.SelectAll();
+				doc.Selection.SelectAll( );
 				file = doc.Selection.Text;
 			}
 			else
 				_returnScope.text = file.Substring( _returnScope.start, _returnScope.end - _returnScope.start );
 				file = file.Replace( scopeEndTag, "" );
 
-				if ( _scope.file.get_IsOpen( Constants.vsDocumentKindText ) )
+				if ( doc != null )
 				{
 					doc.Selection.Text = file;
 				}
 			{
 				if ( _section.Length > 0 )
 				{
-					if ( !file.get_IsOpen( Constants.vsDocumentKindText ) )
+					TextDocument doc1 = (TextDocument)file.Document.Object( "TextDocument" );
+					TextDocument doc = (TextDocument)file.Document.Object( Constants.vsDocumentKindText );
+
+					if ( doc == null )
 					{
 						Regex regEx = new Regex( _section, RegexOptions.Multiline );
 
 					}
 					else
 					{
-						if ( file.Document.Kind == Constants.vsDocumentKindText )
+						doc.Selection.SelectAll( );
+						if ( _section.Length > 0 )
 						{
-							TextDocument doc1 = (TextDocument)file.Document.Object( "TextDocument" );
-							TextDocument doc = (TextDocument)file.Document.Object( Constants.vsDocumentKindText );
-
-							doc.Selection.SelectAll( );
-							if ( _section.Length > 0 )
+							TextRanges textRanges = null;
+							if ( doc.Selection.FindPattern( _section, (int)( vsFindOptions.vsFindOptionsFromStart | vsFindOptions.vsFindOptionsRegularExpression ), ref textRanges ) )
 							{
-								TextRanges textRanges = null;
-								if ( doc.Selection.FindPattern( _section, (int)( vsFindOptions.vsFindOptionsFromStart | vsFindOptions.vsFindOptionsRegularExpression ), ref textRanges ) )
-								{
-									return new FindResult( file, textRanges.Item( 0 ) );
-								}
+								return new FindResult( file, textRanges.Item( 0 ) );
 							}
 						}
 					}

File Source/CodeFast/AssemblyInfo.cs

Binary file modified.

File Source/CodeFastLibrary/CFExceptions.cs

 
 namespace CodeFastLibrary
 {
-	public class CFExceptions
+	public static class CFExceptions
 	{
-		public static System.Exception SetException(String _errorMsg, params Object[] _args )
+		public static System.Exception SetException( String _errorMsg, params Object[] _args )
 		{
 			String errorMsg;
 

File Source/CodeFastLibrary/CodeDefinitions/CPP.xml

 		</Properties>
 	</Node>
 	<Node key="Package" onInitialised="this['Object'] = this['Class']:Create( this )">
-		<Shortcut key="Package" text="namespace" />
+		<Shortcut key="Package" text="package" />
+		<Shortcut key="Namespace" text="namespace" />
 		<MenuItem key="Package" name="Add Package" visible="true" />
 		<Properties>
 			<Property key="Name" codetag="Namespace" name="Namespace" type="String" visible="true" default="&lt;Package&gt;" />

File Source/CodeFastLibrary/CodeFastControl.cs

 		private String language = "CPP";
 		private Dictionary<String, ToolStripItem> codeContextMenuItems = new Dictionary<string, ToolStripItem>( );
 		private List<ICodeDefinitionsFunction> codeDefinitionsInstances = new List<ICodeDefinitionsFunction>( );
-		ValidateIdentifier validateIdentifierFunc = null;
+		ValidateIdentifier validateIdentifierFunc;
 
 		public CodeFastControl( )
 		{
 		#region CodeContextMenu
 		private void CodeContextMenu_Opening( object sender, CancelEventArgs e )
 		{
-			if ( CodeContextMenu.Tag == null || ( CodeContextMenu.Tag is String && ( (String)CodeContextMenu.Tag ).Trim( ) == "" ) )
+			if ( CodeContextMenu.Tag == null || ( CodeContextMenu.Tag is String && String.IsNullOrEmpty( ( (String)CodeContextMenu.Tag ).Trim( ) ) ) )
 			{
 				e.Cancel = true;
 				return;
 			{
 				XMLParser.Row row = db.GetTable( "Node" ).GetRow( (String)e.ClickedItem.Tag );
 
-				CodeNode cn = CodeNode.CreateCodeNode( row, (CodeNode)OutlineTreeView.SelectedNode.Tag );
+				/*CodeNode cn = */CodeNode.CreateCodeNode( row, (CodeNode)OutlineTreeView.SelectedNode.Tag );
 
 				//OutlineTreeView.SelectedNode.Nodes.Add( cn.outlineTreeNode );
 			}
 						break;
 					}
 
+					// Guess best child
+					{
+						CodeNode parent = (CodeNode)treeNode.Parent.Tag;
+						String bestGuess = lastCreatedNodeType;
+
+						// find the node for the last shortcut entered
+						XMLParser.Row row = db.GetTable( "Shortcut", "text" ).TryGetRow( bestGuess );
+						if ( row != null )
+						{
+							bestGuess = row.GetParentRow( "Node" ).GetField( "key" );
+						}
+
+						// find the node in parents children list
+						String children = parent.GetXMLProperty( "Children" ).GetField( "default" );
+						if ( !children.Contains( bestGuess ) )
+						{
+							// find the node in parents hidden children children list
+							children += ",";
+							foreach ( CodeNode child in parent.children )
+							{
+								if ( child.GetXMLProperty( "Name" ).GetField( "visible" ) == "false" )
+								{
+									children += child.GetXMLProperty( "Children" ).GetField( "default" ) + ",";
+								}
+							}
+
+							if ( !children.Contains( bestGuess ) )
+							{
+								// Last shortcut doesn't work here, Try to find the first allowed shortcut
+								foreach ( String child in children.Split( new char[] { ',' }, 2, StringSplitOptions.RemoveEmptyEntries ) )
+								{
+									row = db.GetTable( "Node" ).GetRow( child );
+									if ( row != null )
+									{
+										Dictionary<String, XMLParser.Row> rows = row.GetChildRows( "Shortcut" );
+										if ( rows.Count != 0 )
+										{
+											XMLParser.Row[] rowArray = new XMLParser.Row[rows.Count];
+											rows.Values.CopyTo( rowArray, 0 );
+											lastCreatedNodeType = rowArray[0].GetField( "text" );
+											break;
+										}
+									}
+								}
+							}
+						}
+					}
+
 					e.Handled = true;
 
+					treeNode.Text = lastCreatedNodeType;
 					treeNode.EnsureVisible( );
 					treeNode.BeginEdit( );
 				}
 		{
 			String nodeText = e.Label != null ? e.Label : e.Node.Text;
 
+			// TODO: split this between identifier and shortcut func
 			String nodeType = validateIdentifierFunc( nodeText );
 
 			if ( nodeType == nodeText )
 
 					if ( row != null )
 					{
-						XMLParser.Row node = db.GetTable( "Shortcut", "text" ).GetRow( nodeType ).GetParentRow( "Node" );
+						XMLParser.Row node = row.GetParentRow( "Node" );
 
 						CodeNode parent = (CodeNode)e.Node.Parent.Tag;
 						CodeNode youngerBrother = e.Node.NextNode != null ? (CodeNode)e.Node.NextNode.Tag : null;
 
 						// Checking if the parent has this as a allowed child type
-						if ( parent.GetXMLProperty( "Children" ).GetField( "default" ).Contains( node.GetField( "key" ) ) )
+						if ( !parent.GetXMLProperty( "Children" ).GetField( "default" ).Contains( node.GetField( "key" ) ) )
+						{
+							foreach ( CodeNode child in parent.children )
+							{
+								if ( ( child.GetXMLProperty( "Name" ).GetField( "visible" ) == "false" ) && child.GetXMLProperty( "Children" ).GetField( "default" ).Contains( node.GetField( "key" ) ) )
+								{
+									parent = child;
+									break;
+								}
+							}
+							parent = null;
+						}
+
+						if ( parent != null )
 						{
 							lastCreatedNodeType = nodeType;
 							BeginInvoke( new MethodInvoker( delegate
 							{
-								CodeNode cn = CodeNode.CreateCodeNode( node, parent, youngerBrother );
+								/*CodeNode cn = */CodeNode.CreateCodeNode( node, parent, youngerBrother );
 								Debug.Print( "Created a CodeNode" );
 								UpdateCode( );
 							} ) );

File Source/CodeFastLibrary/CodeNode.cs

 			mParent = _parent;
 			mChildren = new List<CodeNode>( );
 			mCodeTags = new CodeTags( this );
-			mInitialized = false;
-			mIsDirty = false;
-			mIsChildDirty = false;
+			//mInitialized = false;
+			//mIsDirty = false;
+			//mIsChildDirty = false;
 			//mOpeningLength = mClosingLength = 0;
 
 			// Create property class
 
 		}
 
-		private void InitializeProperties( ref Object _properties, IEnumerable<XMLParser.Row> _rows )
+		private static void InitializeProperties( ref Object _properties, IEnumerable<XMLParser.Row> _rows )
 		{
 			foreach ( XMLParser.Row row in _rows )
 			{
 				{
 					mInitialized = true;
 
-					if ( GetXMLProperties( ).ContainsKey( "AutoChildren" ) && GetXMLProperty( "AutoChildren" ).GetField( "default" ).Trim( ) != "" )
+					if ( GetXMLProperties( ).ContainsKey( "AutoChildren" ) && !String.IsNullOrEmpty( GetXMLProperty( "AutoChildren" ).GetField( "default" ).Trim( ) ) )
 					{
 						String[] autoChildren = GetXMLProperty( "AutoChildren" ).GetField( "default" ).Trim( ).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries );
 
 						foreach ( String autoChild in autoChildren )
 						{
-							new CodeNode( mDataRow.GetTable( ).GetRow( autoChild ), this );
+							/*CodeNode cn = */CreateCodeNode( mDataRow.GetTable( ).GetRow( autoChild ), this );
 						}
 					}
 					TriggerEvent( "onInitialised" );
 		private void UpdateProjectItem( ProjectItem _file, System.Text.StringBuilder _text )
 		{
 			String file;
-			TextDocument doc = null;
+			TextDocument doc = _file.Document != null ? (TextDocument)_file.Document.Object( "TextDocument" ) : null;
 
-			if ( _file.get_IsOpen( Constants.vsDocumentKindText ) )
+			if ( doc != null )
 			{
-				doc = (TextDocument)_file.Document.Object( "TextDocument" );
 				doc.Selection.SelectAll( );
 				file = doc.Selection.Text;
 			}
 				file = System.IO.File.ReadAllText( _file.get_FileNames( 0 ) );
 			}
 
-			if ( _file.get_IsOpen( Constants.vsDocumentKindText ) )
+			if ( doc != null )
 			{
 				doc.Selection.Text = _text.ToString();
 			}