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

C#: Move build button to EditorRunBar #79357

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion editor/gui/editor_run_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ bool EditorRunBar::is_movie_maker_enabled() const {
return write_movie_button->is_pressed();
}

HBoxContainer *EditorRunBar::get_buttons_container() {
return main_hbox;
}

void EditorRunBar::_bind_methods() {
ADD_SIGNAL(MethodInfo("play_pressed"));
ADD_SIGNAL(MethodInfo("stop_pressed"));
Expand All @@ -359,7 +363,7 @@ EditorRunBar::EditorRunBar() {
main_panel = memnew(PanelContainer);
add_child(main_panel);

HBoxContainer *main_hbox = memnew(HBoxContainer);
main_hbox = memnew(HBoxContainer);
main_panel->add_child(main_hbox);

play_button = memnew(Button);
Expand Down
4 changes: 4 additions & 0 deletions editor/gui/editor_run_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Button;
class EditorRunNative;
class EditorQuickOpen;
class PanelContainer;
class HBoxContainer;

class EditorRunBar : public MarginContainer {
GDCLASS(EditorRunBar, MarginContainer);
Expand All @@ -53,6 +54,7 @@ class EditorRunBar : public MarginContainer {
};

PanelContainer *main_panel = nullptr;
HBoxContainer *main_hbox = nullptr;

Button *play_button = nullptr;
Button *pause_button = nullptr;
Expand Down Expand Up @@ -109,6 +111,8 @@ class EditorRunBar : public MarginContainer {

Button *get_pause_button() { return pause_button; }

HBoxContainer *get_buttons_container();

EditorRunBar();
};

Expand Down
2 changes: 0 additions & 2 deletions modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,6 @@ void CSharpLanguage::_editor_init_callback() {

// Add plugin to EditorNode and enable it
EditorNode::add_editor_plugin(godotsharp_editor);
ED_SHORTCUT("mono/build_solution", TTR("Build Solution"), KeyModifierMask::ALT | Key::B);
ED_SHORTCUT_OVERRIDE("mono/build_solution", "macos", KeyModifierMask::META | KeyModifierMask::CTRL | Key::B);
godotsharp_editor->enable_plugin();

get_singleton()->godotsharp_editor = godotsharp_editor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override void _Ready()
var toolBarHBox = new HBoxContainer { SizeFlagsHorizontal = SizeFlags.ExpandFill };
AddChild(toolBarHBox);

_buildMenuBtn = new MenuButton { Text = "Build", Icon = GetThemeIcon("Play", "EditorIcons") };
_buildMenuBtn = new MenuButton { Text = "Build", Icon = GetThemeIcon("BuildCSharp", "EditorIcons") };
toolBarHBox.AddChild(_buildMenuBtn);

var buildMenu = _buildMenuBtn.GetPopup();
Expand Down Expand Up @@ -184,7 +184,7 @@ public override void _Notification(int what)
if (what == NotificationThemeChanged)
{
if (_buildMenuBtn != null)
_buildMenuBtn.Icon = GetThemeIcon("Play", "EditorIcons");
_buildMenuBtn.Icon = GetThemeIcon("BuildCSharp", "EditorIcons");
if (_errorsBtn != null)
_errorsBtn.Icon = GetThemeIcon("StatusError", "EditorIcons");
if (_warningsBtn != null)
Expand Down
16 changes: 9 additions & 7 deletions modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,18 +497,20 @@ public override void _EnablePlugin()

AddToolSubmenuItem("C#", _menuPopup);

var buildSolutionShortcut = (Shortcut)EditorShortcut("mono/build_solution");

_toolBarBuildButton = new Button
{
Text = "Build",
TooltipText = "Build Solution".TTR(),
Flat = true,
Icon = editorBaseControl.GetThemeIcon("BuildCSharp", "EditorIcons"),
FocusMode = Control.FocusModeEnum.None,
Shortcut = buildSolutionShortcut,
ShortcutInTooltip = true
Shortcut = EditorDefShortcut("mono/build_solution", "Build Project".TTR(), (Key)KeyModifierMask.MaskAlt | Key.B),
ShortcutInTooltip = true,
};
EditorShortcutOverride("mono/build_solution", "macos", (Key)KeyModifierMask.MaskMeta | (Key)KeyModifierMask.MaskCtrl | Key.B);

_toolBarBuildButton.Pressed += BuildProjectPressed;
AddControlToContainer(CustomControlContainer.Toolbar, _toolBarBuildButton);
Internal.EditorPlugin_AddControlToEditorRunBar(_toolBarBuildButton);
// Move Build button so it appears to the left of the Play button.
_toolBarBuildButton.GetParent().MoveChild(_toolBarBuildButton, 0);

if (File.Exists(GodotSharpDirs.ProjectCsProjPath))
{
Expand Down
21 changes: 18 additions & 3 deletions modules/mono/editor/GodotTools/GodotTools/Internals/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,26 @@ public static Variant EditorDef(string setting, Variant defaultValue, bool resta
return Variant.CreateTakingOwnershipOfDisposableValue(result);
}

public static Variant EditorShortcut(string setting)
public static Shortcut EditorDefShortcut(string setting, string name, Key keycode = Key.None, bool physical = false)
{
using godot_string settingIn = Marshaling.ConvertStringToNative(setting);
Internal.godot_icall_Globals_EditorShortcut(settingIn, out godot_variant result);
return Variant.CreateTakingOwnershipOfDisposableValue(result);
using godot_string nameIn = Marshaling.ConvertStringToNative(name);
Internal.godot_icall_Globals_EditorDefShortcut(settingIn, nameIn, keycode, physical.ToGodotBool(), out godot_variant result);
return (Shortcut)Variant.CreateTakingOwnershipOfDisposableValue(result);
}

public static Shortcut EditorGetShortcut(string setting)
{
using godot_string settingIn = Marshaling.ConvertStringToNative(setting);
Internal.godot_icall_Globals_EditorGetShortcut(settingIn, out godot_variant result);
return (Shortcut)Variant.CreateTakingOwnershipOfDisposableValue(result);
}

public static void EditorShortcutOverride(string setting, string feature, Key keycode = Key.None, bool physical = false)
{
using godot_string settingIn = Marshaling.ConvertStringToNative(setting);
using godot_string featureIn = Marshaling.ConvertStringToNative(feature);
Internal.godot_icall_Globals_EditorShortcutOverride(settingIn, featureIn, keycode, physical.ToGodotBool());
}

[SuppressMessage("ReSharper", "InconsistentNaming")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public static bool ScriptEditorEdit(Resource resource, int line, int col, bool g

public static void EditorRunStop() => godot_icall_Internal_EditorRunStop();

public static void EditorPlugin_AddControlToEditorRunBar(Control control) =>
godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar(control.NativeInstance);

public static void ScriptEditorDebugger_ReloadScripts() =>
godot_icall_Internal_ScriptEditorDebugger_ReloadScripts();

Expand Down Expand Up @@ -137,6 +140,8 @@ private static partial bool godot_icall_Internal_ScriptEditorEdit(IntPtr resourc

private static partial void godot_icall_Internal_EditorRunStop();

private static partial void godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar(IntPtr p_control);

private static partial void godot_icall_Internal_ScriptEditorDebugger_ReloadScripts();

private static partial void godot_icall_Internal_CodeCompletionRequest(int kind, in godot_string scriptFile,
Expand All @@ -151,7 +156,13 @@ public static partial void godot_icall_Globals_EditorDef(in godot_string setting
bool restartIfChanged, out godot_variant result);

public static partial void
godot_icall_Globals_EditorShortcut(in godot_string setting, out godot_variant result);
godot_icall_Globals_EditorDefShortcut(in godot_string setting, in godot_string name, Key keycode, godot_bool physical, out godot_variant result);

public static partial void
godot_icall_Globals_EditorGetShortcut(in godot_string setting, out godot_variant result);

public static partial void
godot_icall_Globals_EditorShortcutOverride(in godot_string setting, in godot_string feature, Key keycode, godot_bool physical);

public static partial void godot_icall_Globals_TTR(in godot_string text, out godot_string dest);

Expand Down
24 changes: 22 additions & 2 deletions modules/mono/editor/editor_internal_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ void godot_icall_Internal_EditorRunStop() {
EditorRunBar::get_singleton()->stop_playing();
}

void godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar(Control *p_control) {
EditorRunBar::get_singleton()->get_buttons_container()->add_child(p_control);
}

void godot_icall_Internal_ScriptEditorDebugger_ReloadScripts() {
EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton();
if (ed) {
Expand Down Expand Up @@ -199,12 +203,25 @@ void godot_icall_Globals_EditorDef(const godot_string *p_setting, const godot_va
memnew_placement(r_result, Variant(result));
}

void godot_icall_Globals_EditorShortcut(const godot_string *p_setting, godot_variant *r_result) {
void godot_icall_Globals_EditorDefShortcut(const godot_string *p_setting, const godot_string *p_name, Key p_keycode, bool p_physical, godot_variant *r_result) {
String setting = *reinterpret_cast<const String *>(p_setting);
String name = *reinterpret_cast<const String *>(p_name);
Ref<Shortcut> result = ED_SHORTCUT(setting, name, p_keycode, p_physical);
memnew_placement(r_result, Variant(result));
}

void godot_icall_Globals_EditorGetShortcut(const godot_string *p_setting, Ref<Shortcut> *r_result) {
String setting = *reinterpret_cast<const String *>(p_setting);
Ref<Shortcut> result = ED_GET_SHORTCUT(setting);
memnew_placement(r_result, Variant(result));
}

void godot_icall_Globals_EditorShortcutOverride(const godot_string *p_setting, const godot_string *p_feature, Key p_keycode, bool p_physical) {
String setting = *reinterpret_cast<const String *>(p_setting);
String feature = *reinterpret_cast<const String *>(p_feature);
ED_SHORTCUT_OVERRIDE(setting, feature, p_keycode, p_physical);
}

void godot_icall_Globals_TTR(const godot_string *p_text, godot_string *r_dest) {
String text = *reinterpret_cast<const String *>(p_text);
memnew_placement(r_dest, String(TTR(text)));
Expand Down Expand Up @@ -251,12 +268,15 @@ static const void *unmanaged_callbacks[]{
(void *)godot_icall_Internal_EditorNodeShowScriptScreen,
(void *)godot_icall_Internal_EditorRunPlay,
(void *)godot_icall_Internal_EditorRunStop,
(void *)godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar,
(void *)godot_icall_Internal_ScriptEditorDebugger_ReloadScripts,
(void *)godot_icall_Internal_CodeCompletionRequest,
(void *)godot_icall_Globals_EditorScale,
(void *)godot_icall_Globals_GlobalDef,
(void *)godot_icall_Globals_EditorDef,
(void *)godot_icall_Globals_EditorShortcut,
(void *)godot_icall_Globals_EditorDefShortcut,
(void *)godot_icall_Globals_EditorGetShortcut,
(void *)godot_icall_Globals_EditorShortcutOverride,
(void *)godot_icall_Globals_TTR,
(void *)godot_icall_Utils_OS_GetPlatformName,
(void *)godot_icall_Utils_OS_UnixFileHasExecutableAccess,
Expand Down
1 change: 1 addition & 0 deletions modules/mono/icons/BuildCSharp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.