Skip to content
Snippets Groups Projects
Commit 7e0890b1 authored by Reeves, David E's avatar Reeves, David E
Browse files

* inserting code snippets

parent ab8310a1
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -28,23 +28,23 @@ ...@@ -28,23 +28,23 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.listBox1 = new System.Windows.Forms.ListBox(); this.ccListBox = new System.Windows.Forms.ListBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// listBox1 // ccListBox
// //
this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.ccListBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox1.FormattingEnabled = true; this.ccListBox.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(0, 0); this.ccListBox.Location = new System.Drawing.Point(0, 0);
this.listBox1.Name = "listBox1"; this.ccListBox.Name = "ccListBox";
this.listBox1.Size = new System.Drawing.Size(203, 97); this.ccListBox.Size = new System.Drawing.Size(203, 97);
this.listBox1.TabIndex = 1; this.ccListBox.TabIndex = 1;
// //
// CodeCompleteControl // CodeCompleteControl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.listBox1); this.Controls.Add(this.ccListBox);
this.Name = "CodeCompleteControl"; this.Name = "CodeCompleteControl";
this.Size = new System.Drawing.Size(203, 97); this.Size = new System.Drawing.Size(203, 97);
this.Load += new System.EventHandler(this.CodeCompleteControl_Load); this.Load += new System.EventHandler(this.CodeCompleteControl_Load);
...@@ -54,6 +54,6 @@ ...@@ -54,6 +54,6 @@
#endregion #endregion
private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.ListBox ccListBox;
} }
} }
...@@ -28,13 +28,13 @@ namespace CodeCompleteTool ...@@ -28,13 +28,13 @@ namespace CodeCompleteTool
private void CodeCompleteControl_Load(object sender, EventArgs e) private void CodeCompleteControl_Load(object sender, EventArgs e)
{ {
listBox1.SelectedIndexChanged += ListBox1_SelectedIndexChanged; ccListBox.SelectedIndexChanged += ListBox1_SelectedIndexChanged;
} }
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e) private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{ {
CodeCompleteForm ccf = (CodeCompleteForm)ParentForm; CodeCompleteForm ccf = (CodeCompleteForm)ParentForm;
string str = (string)listBox1.Items[listBox1.SelectedIndex]; string str = (string)ccListBox.Items[ccListBox.SelectedIndex];
Point loc = new Point(0, 0); Point loc = new Point(0, 0);
loc = ccf.PointToScreen(loc); loc = ccf.PointToScreen(loc);
...@@ -54,7 +54,7 @@ namespace CodeCompleteTool ...@@ -54,7 +54,7 @@ namespace CodeCompleteTool
} }
public ListBox ListBox { get { return listBox1; } } public ListBox ListBox { get { return ccListBox; } }
public string Selecting { get; protected set; } public string Selecting { get; protected set; }
public string[] Keywords { get; protected set; } public string[] Keywords { get; protected set; }
...@@ -65,7 +65,10 @@ namespace CodeCompleteTool ...@@ -65,7 +65,10 @@ namespace CodeCompleteTool
return Selecting; return Selecting;
} }
return (string)ListBox.SelectedItem; string selStr = (string)ListBox.SelectedItem;
string codeSnippet = CodeSnippet.GetCodeSnippet(selStr);
return codeSnippet != null ? codeSnippet : selStr;
} }
public void RemoveText(int selStar, int selLen, string valRemoved) public void RemoveText(int selStar, int selLen, string valRemoved)
...@@ -182,6 +185,64 @@ namespace CodeCompleteTool ...@@ -182,6 +185,64 @@ namespace CodeCompleteTool
return stream; return stream;
} }
public List<Stream> GetSnippetStreamsFromResources(bool debugAssembly)
{
Assembly assembly = Assembly.GetExecutingAssembly();
List<Stream> snippetResources = new List<Stream>();
foreach (string str in assembly.GetManifestResourceNames())
{
if (debugAssembly)
Console.WriteLine("Res: " + str);
if (str.EndsWith(".snp"))
snippetResources.Add(assembly.GetManifestResourceStream(str));
}
return snippetResources;
}
public string[] GetSnippets(bool debugAssembly)
{
if (CodeSnippet.IsLoaded)
{
foreach(CodeSnippet cs in CodeSnippet.snippets.Values)
{
keywordMap[cs.SnippetName] = cs.SnippetHelp;
}
return CodeSnippet.GetAllSnippets();
}
return LoadSnippetsFromResources(debugAssembly);
}
public string[] LoadSnippetsFromResources(bool debugAssembly)
{
List<Stream> snippetStreams = GetSnippetStreamsFromResources(debugAssembly);
foreach (Stream resFile in snippetStreams)
{
List<string> lines = new List<string>();
string str = null;
using (StreamReader readtext = new StreamReader(resFile))
{
while ((str = readtext.ReadLine()) != null)
{
if (str == null || str.Length == 0 || str.StartsWith("#") || str.StartsWith("//")
|| str.Trim().Length==0)
continue;
lines.Add(str);
}
if (lines.Count > 0)
{
CodeSnippet cs = new CodeSnippet(lines.ToArray());
keywordMap[cs.SnippetName] = cs.SnippetHelp;
}
}
}
return CodeSnippet.GetAllSnippets();
}
public string[] LoadKeywordsFromFile(string filename) public string[] LoadKeywordsFromFile(string filename)
{ {
List<string> keywords = new List<string>(); List<string> keywords = new List<string>();
...@@ -191,6 +252,9 @@ namespace CodeCompleteTool ...@@ -191,6 +252,9 @@ namespace CodeCompleteTool
{ {
while ((str = readtext.ReadLine()) != null) while ((str = readtext.ReadLine()) != null)
{ {
str = str.Trim();
if (str == null || str.Length == 0 || str.StartsWith("#") || str.StartsWith("//"))
continue;
string[] items = str.Split('|'); string[] items = str.Split('|');
keywords.Add(items[0]); keywords.Add(items[0]);
keywordMap[items[0]] = items[1]; keywordMap[items[0]] = items[1];
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
<DependentUpon>CodeCompleteControl.cs</DependentUpon> <DependentUpon>CodeCompleteControl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="CodeCompleteTools.cs" /> <Compile Include="CodeCompleteTools.cs" />
<Compile Include="CodeSnippet.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" /> <Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
</ItemGroup> </ItemGroup>
...@@ -62,6 +63,9 @@ ...@@ -62,6 +63,9 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="res\keywords.txt" /> <EmbeddedResource Include="res\keywords.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="res\add_goal.snp" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeCompleteTool
{
public class CodeSnippet
{
public static Dictionary<string, CodeSnippet> snippets;
public string SnippetName { get; protected set; }
public string SnippetHelp { get; protected set; }
public string[] RawData { get; protected set; }
public static bool IsLoaded { get { return snippets != null && snippets.Count > 0; } }
public CodeSnippet(string[] data)
{
string[] descs = data[0].Split('|');
SnippetName = descs[0];
SnippetHelp = descs[1];
List<string> rd = new List<string>();
for (int i = 1; i < data.Length; i++)
{
rd.Add(data[i]);
}
RawData = rd.ToArray();
if (snippets == null)
{
snippets = new Dictionary<string, CodeSnippet>();
}
snippets[SnippetName] = this;
}
public static string GetCodeSnippet(string key)
{
if (!snippets.ContainsKey(key))
return null;
string desc = "";
CodeSnippet cs = snippets[key];
foreach(string str in cs.RawData)
{
desc += str + Environment.NewLine;
}
return desc;
}
public static string[] GetAllSnippets()
{
if (snippets == null || snippets.Count == 0)
return null;
List<string> allSnips = new List<string>();
allSnips.AddRange(snippets.Keys);
return allSnips.ToArray();
}
}
}
add_goal|Add a goal to an entity
UtilityFuncsExp.%NAME(
%NAME, # entity name string
%DELAY, # delay double
%GOALPATH, # goal path string
%ARGS, # arguments to tree hashable list
%VARS) # variables to pass to the tree usually None
...@@ -21,9 +21,11 @@ is|is used in Python for testing object identity. While the == operator is used ...@@ -21,9 +21,11 @@ is|is used in Python for testing object identity. While the == operator is used
lambda|is used to create an anonymous function (function with no name). It is an inline function that does not contain a return statement. It consists of an expression that is evaluated and returned lambda|is used to create an anonymous function (function with no name). It is an inline function that does not contain a return statement. It consists of an expression that is evaluated and returned
None|is a special constant in Python that represents the absence of a value or a null value None|is a special constant in Python that represents the absence of a value or a null value
nonlocal|The use of nonlocal keyword is very much similar to the global keyword. nonlocal is used to declare that a variable inside a nested function (function inside a function) is not local to it, meaning it lies in the outer inclosing function. If we need to modify the value of a non-local variable inside a nested function, then we must declare it with nonlocal. Otherwise a local variable with that name is created inside the nested function nonlocal|The use of nonlocal keyword is very much similar to the global keyword. nonlocal is used to declare that a variable inside a nested function (function inside a function) is not local to it, meaning it lies in the outer inclosing function. If we need to modify the value of a non-local variable inside a nested function, then we must declare it with nonlocal. Otherwise a local variable with that name is created inside the nested function
# this is a comment
not|and, or, not are the logical operators in Python. not|and, or, not are the logical operators in Python.
or|and, or, not are the logical operators in Python. or|and, or, not are the logical operators in Python.
pass|is a null statement in Python. Nothing happens when it is executed. It is used as a placeholder pass|is a null statement in Python. Nothing happens when it is executed. It is used as a placeholder
// this is another comment
raise|except, raise, try are used with exceptions in Python raise|except, raise, try are used with exceptions in Python
return|statement is used inside a function to exit it and return a value return|statement is used inside a function to exit it and return a value
True|True and False are truth values in Python. They are the results of comparison operations or logical (Boolean) operations in Python True|True and False are truth values in Python. They are the results of comparison operations or logical (Boolean) operations in Python
...@@ -31,3 +33,4 @@ try|except, raise, try are used with exceptions in Python ...@@ -31,3 +33,4 @@ try|except, raise, try are used with exceptions in Python
while|is used for looping in Python while|is used for looping in Python
with|statement is used to wrap the execution of a block of code within methods defined by the context manager with|statement is used to wrap the execution of a block of code within methods defined by the context manager
yield|is used inside a function like a return statement. But yield returns a generator yield|is used inside a function like a return statement. But yield returns a generator
...@@ -5,6 +5,7 @@ using CodeCompleteTool; ...@@ -5,6 +5,7 @@ using CodeCompleteTool;
using ScintillaNET; using ScintillaNET;
using DevExpress.XtraBars.Docking2010.Views; using DevExpress.XtraBars.Docking2010.Views;
using System.IO; using System.IO;
using System.Collections.Generic;
namespace ScintillaPythonControl namespace ScintillaPythonControl
{ {
...@@ -220,8 +221,10 @@ namespace ScintillaPythonControl ...@@ -220,8 +221,10 @@ namespace ScintillaPythonControl
// initialize the code complete form // initialize the code complete form
//string[] keywords = codeTextArea.GetKeywordList(); //string[] keywords = codeTextArea.GetKeywordList();
string[] keywords = codeCompleteForm.CodeControl.LoadKeywordsFromFile("keywords.txt"); List<string> keywords = new List<string>();
codeCompleteForm.CodeControl.Initialize(ParentForm, keywords, p - 1); keywords.AddRange(codeCompleteForm.CodeControl.LoadKeywordsFromFile("keywords.txt"));
keywords.AddRange(codeCompleteForm.CodeControl.GetSnippets(true));
codeCompleteForm.CodeControl.Initialize(ParentForm, keywords.ToArray(), p - 1);
codeCompleteForm.Show(pos); codeCompleteForm.Show(pos);
// pump the code complete form to make sure we've selected correctly // pump the code complete form to make sure we've selected correctly
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment