Skip to content

Commit 682dab4

Browse files
committed
Merge branch 'development' of https://github.com/fdorg/flashdevelop into StringComparison_Ordinal
# Conflicts: # FlashDevelop/Managers/ShortcutManager.cs
2 parents 3c91307 + 3c50d51 commit 682dab4

File tree

40 files changed

+1568
-1490
lines changed

40 files changed

+1568
-1490
lines changed

External/Plugins/AS3Context/PluginMain.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,23 +265,25 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
265265
else if (inMXML)
266266
{
267267
DataEvent de = e as DataEvent;
268-
switch (de.Action)
268+
if (de.Action == "XMLCompletion.Element")
269269
{
270-
case "XMLCompletion.Element":
271-
de.Handled = MxmlComplete.HandleElement(de.Data);
272-
break;
273-
case "XMLCompletion.Namespace":
274-
de.Handled = MxmlComplete.HandleNamespace(de.Data);
275-
break;
276-
case "XMLCompletion.CloseElement":
277-
de.Handled = MxmlComplete.HandleElementClose(de.Data);
278-
break;
279-
case "XMLCompletion.Attribute":
280-
de.Handled = MxmlComplete.HandleAttribute(de.Data);
281-
break;
282-
case "XMLCompletion.AttributeValue":
283-
de.Handled = MxmlComplete.HandleAttributeValue(de.Data);
284-
break;
270+
de.Handled = MxmlComplete.HandleElement(de.Data);
271+
}
272+
if (de.Action == "XMLCompletion.Namespace")
273+
{
274+
de.Handled = MxmlComplete.HandleNamespace(de.Data);
275+
}
276+
else if (de.Action == "XMLCompletion.CloseElement")
277+
{
278+
de.Handled = MxmlComplete.HandleElementClose(de.Data);
279+
}
280+
else if (de.Action == "XMLCompletion.Attribute")
281+
{
282+
de.Handled = MxmlComplete.HandleAttribute(de.Data);
283+
}
284+
else if (de.Action == "XMLCompletion.AttributeValue")
285+
{
286+
de.Handled = MxmlComplete.HandleAttributeValue(de.Data);
285287
}
286288
}
287289
}

External/Plugins/CodeRefactor/CodeRefactor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
<Compile Include="Provider\DocumentHelper.cs" />
115115
<Compile Include="Provider\MovingHelper.cs" />
116116
<Compile Include="Provider\RefactoringHelper.cs" />
117+
<Compile Include="Provider\RenamingHelper.cs" />
117118
<Compile Include="Provider\UserInterfaceManager.cs" />
118119
<Compile Include="RefactorItem.cs" />
119120
<Compile Include="Settings.cs" />

External/Plugins/CodeRefactor/Commands/Rename.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,8 @@ public Rename(ASResult target, Boolean outputResults, String newName, Boolean ig
111111
}
112112
return;
113113
}
114-
Boolean isEnum = target.Type.IsEnum();
115-
Boolean isVoid = target.Type.IsVoid();
116-
Boolean isClass = !isVoid && target.IsStatic && (target.Member == null || RefactoringHelper.CheckFlag(target.Member.Flags, FlagType.Constructor));
117114

118-
if (!string.IsNullOrEmpty(newName))
119-
this.newName = newName;
120-
else if (isEnum || isClass)
121-
this.newName = GetNewName(target.Type.Name);
122-
else
123-
this.newName = GetNewName(target.Member.Name);
115+
this.newName = !string.IsNullOrEmpty(newName) ? newName : GetNewName(RefactoringHelper.GetRefactorTargetName(target));
124116

125117
if (string.IsNullOrEmpty(this.newName)) return;
126118

@@ -372,10 +364,10 @@ private String GetNewName(String originalName)
372364
String label = TextHelper.GetString("Label.NewName");
373365
String title = String.Format(TextHelper.GetString("Title.RenameDialog"), originalName);
374366
LineEntryDialog askName = new LineEntryDialog(title, label, originalName);
375-
DialogResult choice = askName.ShowDialog();
376-
if (choice == DialogResult.OK && askName.Line.Trim().Length > 0 && askName.Line.Trim() != originalName)
367+
if (askName.ShowDialog() == DialogResult.OK)
377368
{
378-
return askName.Line.Trim();
369+
string newName = askName.Line.Trim();
370+
if(newName.Length > 0 && newName != originalName) return newName;
379371
}
380372
return null;
381373
}

External/Plugins/CodeRefactor/PluginMain.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ private void RenameClicked(Object sender, EventArgs e)
423423
{
424424
try
425425
{
426-
Rename command = new Rename(true);
427-
command.Execute();
426+
RenamingHelper.AddToQueue(RefactoringHelper.GetDefaultRefactorTarget());
428427
}
429428
catch (Exception ex)
430429
{

External/Plugins/CodeRefactor/Provider/MovingHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public static void AddToQueue(Dictionary<string, string> oldPathToNewPath, bool
2626
public static void AddToQueue(Dictionary<string, string> oldPathToNewPath, bool outputResults, bool renaming)
2727
{
2828
queue.Add(new QueueItem(oldPathToNewPath, outputResults, renaming));
29-
if (currentCommand == null) MoveFirst();
29+
if (currentCommand == null) ExecuteFirst();
3030
}
3131

32-
private static void MoveFirst()
32+
private static void ExecuteFirst()
3333
{
3434
try
3535
{
@@ -60,7 +60,7 @@ private static void OnRefactorComplete(object sender, RefactorCompleteEventArgs<
6060
results[path].AddRange(entry.Value);
6161
}
6262
}
63-
if (queue.Count > 0) MoveFirst();
63+
if (queue.Count > 0) ExecuteFirst();
6464
else
6565
{
6666
if (results.Count > 0) ReportResults();

External/Plugins/CodeRefactor/Provider/RefactoringHelper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ public static ASResult GetDefaultRefactorTarget()
102102
return DeclarationLookupResult(sci, position);
103103
}
104104

105+
public static string GetRefactorTargetName(ASResult target)
106+
{
107+
ClassModel type = target.Type;
108+
MemberModel member = target.Member;
109+
if (type.IsEnum() || !type.IsVoid() && target.IsStatic && (member == null || (member.Flags & FlagType.Constructor) > 0))
110+
return type.Name;
111+
return member.Name;
112+
}
113+
105114
/// <summary>
106115
/// Retrieves the refactoring target based on the file.
107116
/// </summary>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using CodeRefactor.Commands;
2+
using PluginCore.FRService;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Windows.Forms;
7+
using ASCompletion.Completion;
8+
using ASCompletion.Context;
9+
using ASCompletion.Model;
10+
using PluginCore.Localization;
11+
using PluginCore.Managers;
12+
using ProjectManager.Helpers;
13+
14+
namespace CodeRefactor.Provider
15+
{
16+
class RenamingHelper
17+
{
18+
static readonly List<Rename> queue = new List<Rename>();
19+
static Rename currentCommand;
20+
21+
public static void AddToQueue(ASResult target)
22+
{
23+
AddToQueue(target, true);
24+
}
25+
public static void AddToQueue(ASResult target, bool outputResults)
26+
{
27+
string originalName = RefactoringHelper.GetRefactorTargetName(target);
28+
string label = TextHelper.GetString("Label.NewName");
29+
string title = string.Format(TextHelper.GetString("Title.RenameDialog"), originalName);
30+
LineEntryDialog askName = new LineEntryDialog(title, label, originalName);
31+
if (askName.ShowDialog() == DialogResult.OK)
32+
{
33+
string newName = askName.Line.Trim();
34+
if (newName.Length == 0 || newName == originalName) return;
35+
queue.Add(new Rename(target, outputResults, newName));
36+
if (ASContext.Context.CurrentModel.haXe && target.Member != null &&
37+
(target.Member.Flags & (FlagType.Getter | FlagType.Setter)) > 0)
38+
{
39+
List<MemberModel> list = target.Member.Parameters;
40+
if (list[0].Name == "get") RenameMember(target.InClass, "get_" + originalName, "get_" + newName, outputResults);
41+
if (list[1].Name == "set") RenameMember(target.InClass, "set_" + originalName, "set_" + newName, outputResults);
42+
}
43+
if (currentCommand == null) ExecuteFirst();
44+
}
45+
}
46+
47+
static void RenameMember(ClassModel inClass, string name, string newName, bool outputResults)
48+
{
49+
MemberModel m = inClass.Members.Items.FirstOrDefault(it => it.Name == name);
50+
if (m == null) return;
51+
ASResult result = new ASResult();
52+
ASComplete.FindMember(name, inClass, result, FlagType.Dynamic | FlagType.Function, 0);
53+
if (result.Member == null) return;
54+
queue.Add(new Rename(result, outputResults, newName));
55+
}
56+
57+
static void ExecuteFirst()
58+
{
59+
try
60+
{
61+
currentCommand = queue[0];
62+
queue.Remove(currentCommand);
63+
currentCommand.OnRefactorComplete += OnRefactorComplete;
64+
currentCommand.Execute();
65+
}
66+
catch (Exception ex)
67+
{
68+
queue.Clear();
69+
currentCommand = null;
70+
ErrorManager.ShowError(ex);
71+
}
72+
}
73+
74+
static void OnRefactorComplete(object sender, RefactorCompleteEventArgs<IDictionary<string, List<SearchMatch>>> e)
75+
{
76+
if (queue.Count > 0) ExecuteFirst();
77+
else currentCommand = null;
78+
}
79+
}
80+
}

External/Plugins/ProjectManager/Helpers/LineEntryDialog.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Drawing;
33
using System.Collections;
4-
using System.Collections.Generic;
54
using System.ComponentModel;
65
using System.Windows.Forms;
76
using PluginCore;
@@ -14,12 +13,13 @@ namespace ProjectManager.Helpers
1413
/// </summary>
1514
public class LineEntryDialog : Form
1615
{
16+
readonly Keys shortcutToLowercase;
17+
readonly Keys shortcutToUppercase;
1718
string line;
18-
readonly Dictionary<Keys, string> shortcuts;
1919

2020
#region Form Designer Components
2121

22-
private System.Windows.Forms.TextBox lineBox;
22+
protected System.Windows.Forms.TextBox lineBox;
2323
private System.Windows.Forms.Button btnOK;
2424
private System.Windows.Forms.Button btnCancel;
2525
/// <summary>
@@ -40,15 +40,17 @@ public string Line
4040

4141
public LineEntryDialog(string captionText, string labelText, string defaultLine)
4242
{
43+
shortcutToLowercase = PluginBase.MainForm.GetShortcutItemKeys("EditMenu.ToLowercase");
44+
shortcutToUppercase = PluginBase.MainForm.GetShortcutItemKeys("EditMenu.ToUppercase");
4345
InitializeComponent();
4446
InititalizeLocalization();
4547
this.Font = PluginBase.Settings.DefaultFont;
4648
this.Text = " " + captionText;
4749
titleLabel.Text = labelText;
48-
lineBox.Text = defaultLine ?? string.Empty;
50+
lineBox.KeyDown += OnLineBoxOnKeyDown;
51+
lineBox.Text = (defaultLine != null) ? defaultLine : string.Empty;
4952
lineBox.SelectAll();
5053
lineBox.Focus();
51-
shortcuts = PluginBase.MainForm.GetShortcutItemsByKeys();
5254
}
5355

5456
#region Dispose
@@ -98,7 +100,6 @@ private void InitializeComponent()
98100
this.lineBox.Name = "lineBox";
99101
this.lineBox.Size = new System.Drawing.Size(260, 20);
100102
this.lineBox.TabIndex = 0;
101-
this.lineBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.LineBox_KeyDown);
102103
//
103104
// btnOK
104105
//
@@ -171,22 +172,18 @@ private void btnCancel_Click(object sender, System.EventArgs e)
171172
this.Close();
172173
}
173174

174-
void LineBox_KeyDown(object sender, KeyEventArgs e)
175+
void OnLineBoxOnKeyDown(object sender, KeyEventArgs args)
175176
{
176-
string shortcutId;
177-
if (!shortcuts.TryGetValue(e.KeyData, out shortcutId)) return;
178-
switch (shortcutId)
179-
{
180-
case "EditMenu.ToLowercase":
181-
case "EditMenu.ToUppercase":
182-
string text = lineBox.SelectedText;
183-
if (string.IsNullOrEmpty(text)) break;
184-
text = shortcutId == "EditMenu.ToLowercase" ? text.ToLower() : text.ToUpper();
185-
int selectionStart = lineBox.SelectionStart;
186-
lineBox.Paste(text);
187-
SelectRange(selectionStart, text.Length);
188-
break;
189-
}
177+
string selectedText = lineBox.SelectedText;
178+
if (string.IsNullOrEmpty(selectedText)) return;
179+
Keys keys = args.KeyData;
180+
if (keys == shortcutToLowercase) selectedText = selectedText.ToLower();
181+
else if (keys == shortcutToUppercase) selectedText = selectedText.ToUpper();
182+
else return;
183+
int selectionStart = lineBox.SelectionStart;
184+
int selectionLength = lineBox.SelectionLength;
185+
lineBox.Paste(selectedText);
186+
SelectRange(selectionStart, selectionLength);
190187
}
191188

192189
public void SelectRange(int start, int length)

External/Plugins/ProjectManager/PluginMain.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -561,38 +561,38 @@ private bool HandleKeyEvent(KeyEvent ke)
561561
{
562562
if (activeProject == null) return false;
563563

564-
switch (PluginBase.MainForm.GetShortcutItemId(ke.Value))
564+
if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.ConfigurationSelector"))
565565
{
566-
case "ProjectMenu.ConfigurationSelector":
567-
pluginUI.menus.ConfigurationSelector.Focus();
568-
break;
569-
case "ProjectMenu.ConfigurationSelectorToggle":
570-
pluginUI.menus.ToggleDebugRelease();
571-
break;
572-
case "ProjectMenu.TargetBuildSelector":
573-
pluginUI.menus.TargetBuildSelector.Focus();
574-
break;
575-
case "ProjectTree.LocateActiveFile":
576-
ToggleTrackActiveDocument();
577-
break;
578-
default:
579-
if (Tree.Focused && !pluginUI.IsEditingLabel)
580-
{
581-
if (ke.Value == (Keys.Control | Keys.C) && pluginUI.Menu.Contains(pluginUI.Menu.Copy)) TreeCopyItems();
582-
else if (ke.Value == (Keys.Control | Keys.X) && pluginUI.Menu.Contains(pluginUI.Menu.Cut)) TreeCutItems();
583-
else if (ke.Value == (Keys.Control | Keys.V) && pluginUI.Menu.Contains(pluginUI.Menu.Paste)) TreePasteItems();
584-
else if (ke.Value == Keys.Delete && pluginUI.Menu.Contains(pluginUI.Menu.Delete)) TreeDeleteItems();
585-
else if (ke.Value == Keys.Enter && pluginUI.Menu.Contains(pluginUI.Menu.Open)) TreeOpenItems();
586-
else if (ke.Value == Keys.Enter && pluginUI.Menu.Contains(pluginUI.Menu.Insert)) TreeInsertItem();
587-
else return false;
588-
}
589-
else return false;
590-
break;
566+
pluginUI.menus.ConfigurationSelector.Focus();
567+
}
568+
else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.ConfigurationSelectorToggle"))
569+
{
570+
pluginUI.menus.ToggleDebugRelease();
571+
}
572+
else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.TargetBuildSelector"))
573+
{
574+
pluginUI.menus.TargetBuildSelector.Focus();
575+
}
576+
else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectTree.LocateActiveFile"))
577+
{
578+
ToggleTrackActiveDocument();
591579
}
592580

581+
// Handle tree-level simple shortcuts like copy/paste/del
582+
else if (Tree.Focused && !pluginUI.IsEditingLabel && ke != null)
583+
{
584+
if (ke.Value == (Keys.Control | Keys.C) && pluginUI.Menu.Contains(pluginUI.Menu.Copy)) TreeCopyItems();
585+
else if (ke.Value == (Keys.Control | Keys.X) && pluginUI.Menu.Contains(pluginUI.Menu.Cut)) TreeCutItems();
586+
else if (ke.Value == (Keys.Control | Keys.V) && pluginUI.Menu.Contains(pluginUI.Menu.Paste)) TreePasteItems();
587+
else if (ke.Value == Keys.Delete && pluginUI.Menu.Contains(pluginUI.Menu.Delete)) TreeDeleteItems();
588+
else if (ke.Value == Keys.Enter && pluginUI.Menu.Contains(pluginUI.Menu.Open)) TreeOpenItems();
589+
else if (ke.Value == Keys.Enter && pluginUI.Menu.Contains(pluginUI.Menu.Insert)) TreeInsertItem();
590+
else return false;
591+
}
592+
else return false;
593593
return true;
594594
}
595-
595+
596596
#endregion
597597

598598
#region Custom Methods

0 commit comments

Comments
 (0)