Skip to content

Commit 39e869c

Browse files
author
SlavaRa
committed
Merge branch 'development' of https://github.com/fdorg/flashdevelop into feature/888
# Conflicts: # External/Plugins/CodeRefactor/Provider/RenamingHelper.cs
2 parents cc84a8f + fac848a commit 39e869c

File tree

80 files changed

+27174
-396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+27174
-396
lines changed

External/Plugins/ASCompletion/CustomControls/ModelsExplorer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using ASCompletion.Completion;
1515
using System.Collections;
1616
using PluginCore.Helpers;
17+
using PluginCore.Controls;
1718

1819
namespace ASCompletion
1920
{
@@ -123,6 +124,7 @@ public ModelsExplorer()
123124
refreshButton.Image = PluginBase.MainForm.FindImage("24");
124125
rebuildButton.Image = PluginBase.MainForm.FindImage("153");
125126
toolStrip.ImageScalingSize = ScaleHelper.Scale(new Size(16, 16));
127+
ScrollBarEx.Attach(outlineTreeView);
126128
}
127129

128130
private void outlineContextMenuStrip_Opening(object sender, CancelEventArgs e)

External/Plugins/ASCompletion/PluginMain.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,6 @@ private void AddEventHandlers()
756756
PluginBase.MainForm.IgnoredKeys.Add(Keys.Control | Keys.Enter);
757757
PluginBase.MainForm.IgnoredKeys.Add(Keys.Space | Keys.Control | Keys.Alt); // complete project types
758758
PluginBase.MainForm.RegisterShortcutItem("Completion.ShowHelp", Keys.F1);
759-
PluginBase.MainForm.RegisterShortcutItem("Completion.Delete", Keys.Back);
760759

761760
// application events
762761
EventManager.AddEventHandler(this, eventMask);

External/Plugins/BookmarkPanel/PluginUI.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public PluginUI(PluginMain pluginMain)
4545
this.InitializeLayout();
4646
this.InitializeTexts();
4747
this.UpdateSettings();
48+
ScrollBarEx.Attach(listView);
4849
}
4950

5051
#region Windows Forms Designer Generated Code

External/Plugins/CodeAnalyzer/PluginMain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void CreateMenuItem()
164164
/// </summary>
165165
private void OpenCreator(Object sender, EventArgs e)
166166
{
167-
String url = "http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-ruleset-creator.html";
167+
String url = "http://www.flashdevelop.org/flexpmd/index.html";
168168
PluginBase.MainForm.CallCommand("Browse", url);
169169
}
170170

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using PluginCore.Managers;
4+
5+
namespace CodeFormatter
6+
{
7+
public class AStyleInterface
8+
{
9+
#region Imports
10+
11+
/// http://astyle.sourceforge.net/astyle.html
12+
/// Cannot use String as a return value because Mono runtime will attempt to free the returned pointer resulting in a runtime crash.
13+
14+
[DllImport("AStyle.dll", EntryPoint = "AStyleGetVersion")]
15+
private static extern IntPtr AStyleGetVersion_32();
16+
17+
[DllImport("AStyle64.dll", EntryPoint = "AStyleGetVersion")]
18+
private static extern IntPtr AStyleGetVersion_64();
19+
20+
[DllImport("AStyle.dll", EntryPoint = "AStyleMainUtf16", CharSet = CharSet.Unicode)]
21+
private static extern IntPtr AStyleMainUtf16_32([MarshalAs(UnmanagedType.LPWStr)] String sIn, [MarshalAs(UnmanagedType.LPWStr)] String sOptions, AStyleErrorDelgate errorFunc, AStyleMemAllocDelgate memAllocFunc);
22+
23+
[DllImport("AStyle64.dll", EntryPoint = "AStyleMainUtf16", CharSet = CharSet.Unicode)]
24+
private static extern IntPtr AStyleMainUtf16_64([MarshalAs(UnmanagedType.LPWStr)] String sIn, [MarshalAs(UnmanagedType.LPWStr)] String sOptions, AStyleErrorDelgate errorFunc, AStyleMemAllocDelgate memAllocFunc);
25+
26+
private static IntPtr AStyleMainUtf16(String textIn, String options, AStyleErrorDelgate AStyleError, AStyleMemAllocDelgate AStyleMemAlloc)
27+
{
28+
return (IntPtr.Size == 4 ? AStyleMainUtf16_32(textIn, options, AStyleError, AStyleMemAlloc) : AStyleMainUtf16_64(textIn, options, AStyleError, AStyleMemAlloc));
29+
}
30+
31+
private static IntPtr AStyleGetVersion()
32+
{
33+
return (IntPtr.Size == 4 ? AStyleGetVersion_32() : AStyleGetVersion_64());
34+
}
35+
36+
#endregion
37+
38+
/// AStyleMainUtf16 callbacks.
39+
private delegate IntPtr AStyleMemAllocDelgate(int size);
40+
private delegate void AStyleErrorDelgate(int errorNum, [MarshalAs(UnmanagedType.LPStr)]String error);
41+
42+
/// AStyleMainUtf16 Delegates.
43+
private AStyleMemAllocDelgate AStyleMemAlloc;
44+
private AStyleErrorDelgate AStyleError;
45+
46+
/// AStyleMainUtf16 Constants.
47+
public const String DefaultOptions = "--indent-namespaces --indent-preproc-block --indent-preproc-cond --indent-switches --indent-cases --delete-empty-lines --pad-header --keep-one-line-blocks --keep-one-line-statements --close-templates";
48+
49+
/// <summary>
50+
/// Declare callback functions.
51+
/// </summary>
52+
public AStyleInterface()
53+
{
54+
AStyleMemAlloc = new AStyleMemAllocDelgate(OnAStyleMemAlloc);
55+
AStyleError = new AStyleErrorDelgate(OnAStyleError);
56+
}
57+
58+
/// <summary>
59+
/// Call the AStyleMainUtf16 function in Artistic Style. An empty string is returned on error.
60+
/// </summary>
61+
public String FormatSource(String textIn, String options)
62+
{
63+
// Memory space is allocated by OnAStyleMemAlloc, a callback function
64+
String sTextOut = String.Empty;
65+
try
66+
{
67+
IntPtr pText = AStyleMainUtf16(textIn, options, AStyleError, AStyleMemAlloc);
68+
if (pText != IntPtr.Zero)
69+
{
70+
sTextOut = Marshal.PtrToStringUni(pText);
71+
Marshal.FreeHGlobal(pText);
72+
}
73+
}
74+
catch (Exception e)
75+
{
76+
Console.WriteLine(e.ToString());
77+
}
78+
return sTextOut;
79+
}
80+
81+
/// <summary>
82+
/// Get the Artistic Style version number.
83+
/// </summary>
84+
public String GetVersion()
85+
{
86+
String sVersion = String.Empty;
87+
try
88+
{
89+
IntPtr pVersion = AStyleGetVersion();
90+
if (pVersion != IntPtr.Zero) sVersion = Marshal.PtrToStringAnsi(pVersion);
91+
}
92+
catch (Exception ex)
93+
{
94+
ErrorManager.ShowError(ex);
95+
}
96+
return sVersion;
97+
}
98+
99+
/// <summary>
100+
/// Allocate the memory for the Artistic Style return string.
101+
/// </summary>
102+
private IntPtr OnAStyleMemAlloc(int size)
103+
{
104+
return Marshal.AllocHGlobal(size);
105+
}
106+
107+
/// <summary>
108+
/// Display errors from Artistic Style.
109+
/// </summary>
110+
private void OnAStyleError(int errorNumber, String errorMessage)
111+
{
112+
ErrorManager.ShowError(errorMessage, null);
113+
}
114+
115+
}
116+
117+
}

External/Plugins/CodeFormatter/CodeFormatter.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<Reference Include="System.Windows.Forms" />
7777
</ItemGroup>
7878
<ItemGroup>
79+
<Compile Include="AStyle\AStyleInterface.cs" />
7980
<Compile Include="Properties\AssemblyInfo.cs" />
8081
<Compile Include="InfoCollector\Utilities.cs" />
8182
<Compile Include="Handlers\AS3_exLexer.cs" />

External/Plugins/CodeFormatter/PluginMain.cs

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.IO;
5+
using System.Text.RegularExpressions;
56
using System.Windows.Forms;
67
using ASCompletion.Context;
78
using CodeFormatter.Handlers;
@@ -19,7 +20,7 @@ public class PluginMain : IPlugin
1920
{
2021
private String pluginName = "CodeFormatter";
2122
private String pluginGuid = "f7f1e15b-282a-4e55-ba58-5f2c02765247";
22-
private String pluginDesc = "Adds an MXML and ActionScript code formatter to FlashDevelop.";
23+
private String pluginDesc = "Adds multiple code formatters to FlashDevelop.";
2324
private String pluginHelp = "www.flashdevelop.org/community/";
2425
private String pluginAuth = "FlashDevelop Team";
2526
private ToolStripMenuItem contextMenuItem;
@@ -167,7 +168,7 @@ private void UpdateMenuItems()
167168
{
168169
if (this.mainMenuItem == null || this.contextMenuItem == null) return;
169170
ITabbedDocument doc = PluginBase.MainForm.CurrentDocument;
170-
Boolean isValid = doc != null && doc.IsEditable && this.IsSupportedLanguage(doc.FileName);
171+
Boolean isValid = doc != null && doc.IsEditable && this.DocumentType != TYPE_UNKNOWN;
171172
this.mainMenuItem.Enabled = this.contextMenuItem.Enabled = isValid;
172173
}
173174

@@ -199,15 +200,6 @@ public void AttachContextMenuItem(ToolStripMenuItem contextMenu)
199200
contextMenu.DropDownItems.Insert(6, this.contextMenuItem);
200201
}
201202

202-
/// <summary>
203-
/// Checks if the language is supported
204-
/// </summary>
205-
public Boolean IsSupportedLanguage(String file)
206-
{
207-
String lang = ScintillaControl.Configuration.GetLanguageFromFile(file);
208-
return (lang == "as2" || lang == "as3" || lang == "xml");
209-
}
210-
211203
/// <summary>
212204
/// Loads the plugin settings
213205
/// </summary>
@@ -241,7 +233,8 @@ public void SaveSettings()
241233
private const int TYPE_AS3 = 0;
242234
private const int TYPE_MXML = 1;
243235
private const int TYPE_XML = 2;
244-
private const int TYPE_UNKNOWN = 3;
236+
private const int TYPE_CPP = 3;
237+
private const int TYPE_UNKNOWN = 4;
245238

246239
/// <summary>
247240
/// Formats the current document
@@ -267,7 +260,7 @@ private void DoFormat(ITabbedDocument doc)
267260
{
268261
case TYPE_AS3:
269262
ASPrettyPrinter asPrinter = new ASPrettyPrinter(true, source);
270-
FormatUtility.configureASPrinter(asPrinter, this.settingObject, PluginBase.Settings.TabWidth);
263+
FormatUtility.configureASPrinter(asPrinter, this.settingObject);
271264
String asResultData = asPrinter.print(0);
272265
if (asResultData == null)
273266
{
@@ -284,7 +277,7 @@ private void DoFormat(ITabbedDocument doc)
284277
case TYPE_MXML:
285278
case TYPE_XML:
286279
MXMLPrettyPrinter mxmlPrinter = new MXMLPrettyPrinter(source);
287-
FormatUtility.configureMXMLPrinter(mxmlPrinter, this.settingObject, PluginBase.Settings.TabWidth);
280+
FormatUtility.configureMXMLPrinter(mxmlPrinter, this.settingObject);
288281
String mxmlResultData = mxmlPrinter.print(0);
289282
if (mxmlResultData == null)
290283
{
@@ -297,6 +290,27 @@ private void DoFormat(ITabbedDocument doc)
297290
doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode);
298291
}
299292
break;
293+
294+
case TYPE_CPP:
295+
AStyleInterface asi = new AStyleInterface();
296+
String optionData = this.GetOptionData(doc.SciControl.ConfigurationLanguage.ToLower());
297+
String resultData = asi.FormatSource(source, optionData);
298+
if (String.IsNullOrEmpty(resultData))
299+
{
300+
TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3);
301+
PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults");
302+
}
303+
else
304+
{
305+
// Remove all empty lines if specified
306+
if (optionData.Contains("--delete-empty-lines"))
307+
{
308+
resultData = Regex.Replace(resultData, @"(\r?\n){3,}", "$1");
309+
}
310+
doc.SciControl.Text = resultData;
311+
doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode);
312+
}
313+
break;
300314
}
301315
}
302316
catch (Exception)
@@ -310,7 +324,31 @@ private void DoFormat(ITabbedDocument doc)
310324
}
311325

312326
/// <summary>
313-
///
327+
/// Get the options for the formatter based on FD settings or manual command
328+
/// </summary>
329+
private String GetOptionData(String language)
330+
{
331+
String optionData;
332+
if (language == "cpp") optionData = this.settingObject.Pref_AStyle_CPP;
333+
else optionData = this.settingObject.Pref_AStyle_Others;
334+
if (String.IsNullOrEmpty(optionData))
335+
{
336+
Int32 tabSize = PluginBase.Settings.TabWidth;
337+
Boolean useTabs = PluginBase.Settings.UseTabs;
338+
Int32 spaceSize = PluginBase.Settings.IndentSize;
339+
CodingStyle codingStyle = PluginBase.Settings.CodingStyle;
340+
optionData = AStyleInterface.DefaultOptions + " --mode=c";
341+
if (language != "cpp") optionData += "s"; // --mode=cs
342+
if (useTabs) optionData += " --indent=force-tab=" + tabSize.ToString();
343+
else optionData += " --indent=spaces=" + spaceSize.ToString();
344+
if (codingStyle == CodingStyle.BracesAfterLine) optionData += " --style=allman";
345+
else optionData += " --style=attach";
346+
}
347+
return optionData;
348+
}
349+
350+
/// <summary>
351+
/// Gets or sets the current position, ignoring whitespace
314352
/// </summary>
315353
public int CurrentPos
316354
{
@@ -348,28 +386,29 @@ public int CurrentPos
348386
}
349387

350388
/// <summary>
351-
///
389+
/// Gets the formatting type of the document
352390
/// </summary>
353391
public Int32 DocumentType
354392
{
355393
get
356394
{
357-
var xmls = new List<String> { ".xml" };
358395
ITabbedDocument document = PluginBase.MainForm.CurrentDocument;
359396
if (!document.IsEditable) return TYPE_UNKNOWN;
360397
String ext = Path.GetExtension(document.FileName).ToLower();
398+
String lang = document.SciControl.ConfigurationLanguage.ToLower();
361399
if (ASContext.Context.CurrentModel.Context != null && ASContext.Context.CurrentModel.Context.GetType().ToString().Equals("AS3Context.Context"))
362400
{
363401
if (ext == ".as") return TYPE_AS3;
364402
else if (ext == ".mxml") return TYPE_MXML;
365403
}
366-
else if (xmls.Contains(ext)) return TYPE_XML;
404+
else if (lang == "xml") return TYPE_XML;
405+
else if (document.SciControl.Lexer == 3) return TYPE_CPP;
367406
return TYPE_UNKNOWN;
368407
}
369408
}
370409

371410
/// <summary>
372-
///
411+
/// Compress text for finding correct restore position
373412
/// </summary>
374413
public String CompressText(String originalText)
375414
{
@@ -380,14 +419,6 @@ public String CompressText(String originalText)
380419
return compressedText;
381420
}
382421

383-
/// <summary>
384-
///
385-
/// </summary>
386-
public bool IsBlankChar(Char ch)
387-
{
388-
return (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
389-
}
390-
391422
#endregion
392423

393424
}

0 commit comments

Comments
 (0)