Skip to content

Commit abde46f

Browse files
committed
Merge pull request #995 from SlavaRa/feature/issue182
Rename project from Project Manger
2 parents 4d52a5f + 872f231 commit abde46f

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

External/Plugins/ProjectManager/Controls/TreeView/OtherNodes.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public ProjectNode(Project project) : base(project.Directory)
1919
{
2020
this.project = project;
2121
isDraggable = false;
22-
isRenamable = false;
2322
}
2423

2524
public override void Refresh(bool recursive)

External/Plugins/ProjectManager/Controls/TreeView/ProjectContextMenu.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
using System.IO;
33
using System.Collections;
44
using System.Collections.Generic;
5-
using System.Diagnostics;
65
using System.Drawing;
76
using System.Windows.Forms;
87
using System.ComponentModel;
98
using ProjectManager.Projects;
10-
using ProjectManager.Projects.AS2;
119
using PluginCore.Localization;
1210
using PluginCore.Helpers;
1311
using PluginCore;
@@ -23,7 +21,7 @@ namespace ProjectManager.Controls.TreeView
2321
public class ProjectContextMenu : ContextMenuStrip
2422
{
2523
Project project;
26-
ProjectTreeView projectTree;
24+
ProjectTreeView projectTree;
2725
static Image newFolderImg = Icons.Overlay(Icons.Folder.Img, Icons.BulletAdd.Img, 5, -3);
2826
public ToolStripMenuItem AddMenu = new ToolStripMenuItem(TextHelper.GetString("Label.Add"));
2927
public ToolStripMenuItem AddNewFolder = new ToolStripMenuItem(TextHelper.GetString("Label.NewFolder"), newFolderImg);
@@ -69,7 +67,7 @@ public class ProjectContextMenu : ContextMenuStrip
6967
public ProjectContextMenu()
7068
{
7169
this.Renderer = new DockPanelStripRenderer();
72-
this.Font = PluginCore.PluginBase.Settings.DefaultFont;
70+
this.Font = PluginBase.Settings.DefaultFont;
7371
this.ImageScalingSize = ScaleHelper.Scale(new Size(16, 16));
7472
NothingToDo.Enabled = false;
7573
NoProjectOutput.Enabled = false;
@@ -325,6 +323,7 @@ private void AddProjectItems(MergableMenu menu)
325323
menu.Add(CommandPrompt, 1);
326324
if (Win32.ShouldUseWin32()) menu.Add(ShellMenu, 1);
327325
menu.Add(Paste, 2);
326+
menu.Add(Rename, 1);
328327
menu.Add(ShowHidden, 3, showHidden);
329328
menu.Add(Properties, 4);
330329
}
@@ -480,7 +479,7 @@ private void AddFileItems(MergableMenu menu, string path, bool addPaste)
480479
AddHideItems(menu, path, 3);
481480
}
482481

483-
private void AddHideItems(MergableMenu menu, string path,int group)
482+
private void AddHideItems(MergableMenu menu, string path, int group)
484483
{
485484
bool hidden = project.IsPathHidden(path);
486485
bool showHidden = project.ShowHiddenPaths;

External/Plugins/ProjectManager/PluginMain.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,8 @@ public class PluginMain : IPlugin
7676
private ProjectActions projectActions;
7777
private FlashDevelopActions flashDevelopActions;
7878
private Queue<String> openFileQueue;
79-
private Boolean showProjectClasspaths;
80-
private Boolean showGlobalClasspaths;
8179
private DockContent pluginPanel;
8280
private PluginUI pluginUI;
83-
private Image pluginImage;
8481
private Project activeProject;
8582
private OpenResourceForm projectResources;
8683
private Boolean runOutput;
@@ -102,7 +99,6 @@ public class PluginMain : IPlugin
10299

103100
static string SettingsDir { get { return Path.Combine(PathHelper.DataDir, pluginName); } }
104101
static string SettingsPath { get { return Path.Combine(SettingsDir, "Settings.fdb"); } }
105-
static string FDBuildHints { get { return Path.Combine(SettingsDir, "FDBuildHints.txt"); } }
106102

107103
public void LoadSettings()
108104
{
@@ -170,16 +166,12 @@ public void SaveSettings()
170166
public void Initialize()
171167
{
172168
LoadSettings();
173-
pluginImage = MainForm.FindImage("100");
174169
pluginDesc = TextHelper.GetString("Info.Description");
175170
openFileQueue = new Queue<String>();
176171

177172
Icons.Initialize(MainForm);
178173
EventManager.AddEventHandler(this, eventMask);
179174

180-
showProjectClasspaths = Settings.ShowProjectClasspaths;
181-
showGlobalClasspaths = Settings.ShowGlobalClasspaths;
182-
183175
#region Actions and Event Listeners
184176

185177
menus = new FDMenus(MainForm);

External/Plugins/ProjectManager/PluginUI.cs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class PluginUI : DockPanelControl
1818
public FDMenus menus;
1919
TreeBar treeBar;
2020
Project project;
21-
PluginMain plugin;
2221
LinkLabel help;
2322
ProjectTreeView tree;
2423
ProjectContextMenu menu;
@@ -32,7 +31,6 @@ public class PluginUI : DockPanelControl
3231
public PluginUI(PluginMain plugin, FDMenus menus, FileActions fileActions, ProjectActions projectActions)
3332
{
3433
this.menus = menus;
35-
this.plugin = plugin;
3634
this.AutoKeyHandling = true;
3735
this.Text = TextHelper.GetString("Title.PluginPanel");
3836

@@ -129,7 +127,6 @@ public void SetProject(Project project)
129127
List<Project> projects = tree.Projects;
130128
projects.Clear(); // only one project active
131129
if (project != null) projects.Add(project);
132-
else projects.Clear();
133130
tree.Projects = projects;
134131
tree.Project = project;
135132
tree_AfterSelect(tree, null);
@@ -218,12 +215,47 @@ private void tree_BeforeLabelEdit(Object sender, NodeLabelEditEventArgs e)
218215
/// </summary>
219216
private void tree_AfterLabelEdit(Object sender, NodeLabelEditEventArgs e)
220217
{
218+
string languageDisplayName = "(" + project.LanguageDisplayName + ")";
221219
if (!string.IsNullOrEmpty(e.Label) && Rename != null)
222220
{
223-
if (!Rename((e.Node as GenericNode).BackingPath, e.Label))
221+
if (e.Node is ProjectNode)
222+
{
223+
var oldName = project.ProjectPath;
224+
string label = e.Label;
225+
int index = label.IndexOf(languageDisplayName);
226+
if (index != -1) label = label.Remove(index).Trim();
227+
string newName = string.Empty;
228+
try
229+
{
230+
newName = Path.Combine(project.Directory, label);
231+
newName = Path.ChangeExtension(newName, Path.GetExtension(oldName));
232+
}
233+
catch (Exception)
234+
{
235+
e.CancelEdit = true;
236+
isEditingLabel = false;
237+
return;
238+
}
239+
if (Rename(oldName, newName))
240+
{
241+
PluginBase.MainForm.OpenEditableDocument(newName);
242+
try
243+
{
244+
File.Delete(oldName);
245+
}
246+
catch (Exception)
247+
{
248+
// ignored
249+
}
250+
}
251+
else e.CancelEdit = true;
252+
}
253+
else if (!Rename(((GenericNode) e.Node).BackingPath, e.Label))
224254
e.CancelEdit = true;
225255
}
226256
else e.CancelEdit = true;
257+
if (e.Node is ProjectNode && !e.Node.Text.Contains(languageDisplayName))
258+
e.Node.Text += " " + languageDisplayName;
227259
isEditingLabel = false;
228260
}
229261

@@ -264,6 +296,12 @@ private void NewFileCreated(String path)
264296
/// </summary>
265297
private void RenameNode(Object sender, EventArgs e)
266298
{
299+
if (tree.SelectedNode is ProjectNode)
300+
{
301+
string label = tree.SelectedNode.Text;
302+
int index = label.IndexOf("(" + project.LanguageDisplayName + ")");
303+
if (index != -1) tree.SelectedNode.Text = label.Remove(index).Trim();
304+
}
267305
tree.ForceLabelEdit();
268306
}
269307

0 commit comments

Comments
 (0)