Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace obsolete PreferenceItem with SettingsProvider #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 91 additions & 83 deletions Plugins/Editor/VSCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -840,118 +840,126 @@ static bool ValidateMenuOpenProject()
}

/// <summary>
/// VS Code Integration Preferences Item
/// VS Code Integration Settings Provider
/// </summary>
/// <remarks>
/// Contains all 3 toggles: Enable/Disable; Debug On/Off; Writing Launch File On/Off
/// </remarks>
[PreferenceItem("VSCode")]
static void VSCodePreferencesItem()
[SettingsProvider]
static SettingsProvider VSCodeSettingsProvider()
{
if (EditorApplication.isCompiling)
var provider = new SettingsProvider("VSCode", SettingsScope.User)
{
EditorGUILayout.HelpBox("Please wait for Unity to finish compiling. \nIf the window doesn't refresh, simply click on the window or move it around to cause a repaint to happen.", MessageType.Warning);
return;
}
EditorGUILayout.BeginVertical();
label = "VSCode",
guiHandler = (searchContext) =>
{
if (EditorApplication.isCompiling)
{
EditorGUILayout.HelpBox("Please wait for Unity to finish compiling. \nIf the window doesn't refresh, simply click on the window or move it around to cause a repaint to happen.", MessageType.Warning);
return;
}
EditorGUILayout.BeginVertical();

var developmentInfo = "Support development of this plugin, follow @reapazor and @dotbunny on Twitter.";
var versionInfo = string.Format("{0:0.00}", Version) + VersionCode + ", GitHub version @ " + string.Format("{0:0.00}", GitHubVersion);
EditorGUILayout.HelpBox(developmentInfo + " --- [ " + versionInfo + " ]", MessageType.None);
var developmentInfo = "Support development of this plugin, follow @reapazor and @dotbunny on Twitter.";
var versionInfo = string.Format("{0:0.00}", Version) + VersionCode + ", GitHub version @ " + string.Format("{0:0.00}", GitHubVersion);
EditorGUILayout.HelpBox(developmentInfo + " --- [ " + versionInfo + " ]", MessageType.None);

EditorGUI.BeginChangeCheck();
// Need the VS Code executable
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("VS Code Path", GUILayout.Width(75));
#if UNITY_5_3_OR_NEWER
CodePath = EditorGUILayout.DelayedTextField(CodePath, GUILayout.ExpandWidth(true));
EditorGUI.BeginChangeCheck();

// Need the VS Code executable
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("VS Code Path", GUILayout.Width(75));
#if UNITY_5_3_OR_NEWER
CodePath = EditorGUILayout.DelayedTextField(CodePath, GUILayout.ExpandWidth(true));
#else
CodePath = EditorGUILayout.TextField(CodePath, GUILayout.ExpandWidth(true));
#endif
GUI.SetNextControlName("PathSetButton");
if(GUILayout.Button("...", GUILayout.Height(14), GUILayout.Width(20)))
{
GUI.FocusControl("PathSetButton");
string path = EditorUtility.OpenFilePanel( "Visual Studio Code Executable", "", "" );
if( path.Length != 0 && File.Exists(path) || Directory.Exists(path))
{
CodePath = path;
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
CodePath = EditorGUILayout.TextField(CodePath, GUILayout.ExpandWidth(true));
#endif
GUI.SetNextControlName("PathSetButton");
if (GUILayout.Button("...", GUILayout.Height(14), GUILayout.Width(20)))
{
GUI.FocusControl("PathSetButton");
string path = EditorUtility.OpenFilePanel("Visual Studio Code Executable", "", "");
if (path.Length != 0 && File.Exists(path) || Directory.Exists(path))
{
CodePath = path;
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();

Enabled = EditorGUILayout.Toggle(new GUIContent("Enable Integration", "Should the integration work its magic for you?"), Enabled);
Enabled = EditorGUILayout.Toggle(new GUIContent("Enable Integration", "Should the integration work its magic for you?"), Enabled);

UseUnityDebugger = EditorGUILayout.Toggle(new GUIContent("Use Unity Debugger", "Should the integration integrate with Unity's VSCode Extension (must be installed)."), UseUnityDebugger);
UseUnityDebugger = EditorGUILayout.Toggle(new GUIContent("Use Unity Debugger", "Should the integration integrate with Unity's VSCode Extension (must be installed)."), UseUnityDebugger);

AutoOpenEnabled = EditorGUILayout.Toggle(new GUIContent("Enable Auto Open", "When opening a project in Unity, should it automatically open in VS Code?"), AutoOpenEnabled);
AutoOpenEnabled = EditorGUILayout.Toggle(new GUIContent("Enable Auto Open", "When opening a project in Unity, should it automatically open in VS Code?"), AutoOpenEnabled);

EditorGUILayout.Space();
RevertExternalScriptEditorOnExit = EditorGUILayout.Toggle(new GUIContent("Revert Script Editor On Unload", "Should the external script editor setting be reverted to its previous setting on project unload? This is useful if you do not use Code with all your projects."),RevertExternalScriptEditorOnExit);

EditorGUILayout.Space();
UseParentWorkspace = EditorGUILayout.Toggle(new GUIContent("Parent as workspace", "Should the parent of the project be used as the workspace directory? Usefull if you have the Unity project in a subdirectory."),UseParentWorkspace);
EditorGUILayout.Space();
RevertExternalScriptEditorOnExit = EditorGUILayout.Toggle(new GUIContent("Revert Script Editor On Unload", "Should the external script editor setting be reverted to its previous setting on project unload? This is useful if you do not use Code with all your projects."), RevertExternalScriptEditorOnExit);

Debug = EditorGUILayout.Toggle(new GUIContent("Output Messages To Console", "Should informational messages be sent to Unity's Console?"), Debug);
EditorGUILayout.Space();
UseParentWorkspace = EditorGUILayout.Toggle(new GUIContent("Parent as workspace", "Should the parent of the project be used as the workspace directory? Usefull if you have the Unity project in a subdirectory."), UseParentWorkspace);

WriteLaunchFile = EditorGUILayout.Toggle(new GUIContent("Always Write Launch File", "Always write the launch.json settings when entering play mode?"), WriteLaunchFile);
Debug = EditorGUILayout.Toggle(new GUIContent("Output Messages To Console", "Should informational messages be sent to Unity's Console?"), Debug);

EditorGUILayout.Space();
WriteLaunchFile = EditorGUILayout.Toggle(new GUIContent("Always Write Launch File", "Always write the launch.json settings when entering play mode?"), WriteLaunchFile);

AutomaticUpdates = EditorGUILayout.Toggle(new GUIContent("Automatic Updates", "Should the plugin automatically update itself?"), AutomaticUpdates);
EditorGUILayout.Space();

UpdateTime = EditorGUILayout.IntSlider(new GUIContent("Update Timer (Days)", "After how many days should updates be checked for?"), UpdateTime, 1, 31);
AutomaticUpdates = EditorGUILayout.Toggle(new GUIContent("Automatic Updates", "Should the plugin automatically update itself?"), AutomaticUpdates);

EditorGUILayout.Space();
EditorGUILayout.Space();
UpdateTime = EditorGUILayout.IntSlider(new GUIContent("Update Timer (Days)", "After how many days should updates be checked for?"), UpdateTime, 1, 31);

if (EditorGUI.EndChangeCheck())
{
UpdateUnityPreferences(Enabled);
EditorGUILayout.Space();
EditorGUILayout.Space();

// TODO: Force Unity To Reload Preferences
// This seems to be a hick up / issue
if (VSCode.Debug)
{
if (Enabled)
if (EditorGUI.EndChangeCheck())
{
UnityEngine.Debug.Log("[VSCode] Integration Enabled");
UpdateUnityPreferences(Enabled);

// TODO: Force Unity To Reload Preferences
// This seems to be a hick up / issue
if (VSCode.Debug)
{
if (Enabled)
{
UnityEngine.Debug.Log("[VSCode] Integration Enabled");
}
else
{
UnityEngine.Debug.Log("[VSCode] Integration Disabled");
}
}
}
else

if (GUILayout.Button(new GUIContent("Force Update", "Check for updates to the plugin, right NOW!")))
{
UnityEngine.Debug.Log("[VSCode] Integration Disabled");
CheckForUpdate();
EditorGUILayout.EndVertical();
return;
}
}
}
if (GUILayout.Button(new GUIContent("Write Workspace Settings", "Output a default set of workspace settings for VSCode to use, ignoring many different types of files.")))
{
WriteWorkspaceSettings();
EditorGUILayout.EndVertical();
return;
}
EditorGUILayout.Space();

if (GUILayout.Button(new GUIContent("Force Update", "Check for updates to the plugin, right NOW!")))
{
CheckForUpdate();
EditorGUILayout.EndVertical();
return;
}
if (GUILayout.Button(new GUIContent("Write Workspace Settings", "Output a default set of workspace settings for VSCode to use, ignoring many different types of files.")))
{
WriteWorkspaceSettings();
EditorGUILayout.EndVertical();
return;
}
EditorGUILayout.Space();
if (UseUnityDebugger)
{
EditorGUILayout.HelpBox("In order for the \"Use Unity Debuggger\" option to function above, you need to have installed the Unity Debugger Extension for Visual Studio Code.", MessageType.Warning);
if (GUILayout.Button(new GUIContent("Install Unity Debugger", "Install the Unity Debugger Extension into Code")))
{
InstallUnityDebugger();
EditorGUILayout.EndVertical();
return;
}
}

if (UseUnityDebugger)
{
EditorGUILayout.HelpBox("In order for the \"Use Unity Debuggger\" option to function above, you need to have installed the Unity Debugger Extension for Visual Studio Code.", MessageType.Warning);
if (GUILayout.Button(new GUIContent("Install Unity Debugger", "Install the Unity Debugger Extension into Code")))
{
InstallUnityDebugger();
EditorGUILayout.EndVertical();
return;
}
}

EditorGUILayout.EndVertical();
};
return provider;
}

/// <summary>
Expand Down