45
45
#include " scene/gui/item_list.h"
46
46
#include " scene/gui/texture_rect.h"
47
47
48
+ Ref<Resource> ShaderEditorPlugin::_get_current_shader () {
49
+ int index = shader_tabs->get_current_tab ();
50
+ ERR_FAIL_INDEX_V (index , shader_tabs->get_tab_count (), Ref<Resource>());
51
+ if (edited_shaders[index ].shader .is_valid ()) {
52
+ return edited_shaders[index ].shader ;
53
+ } else {
54
+ return edited_shaders[index ].shader_inc ;
55
+ }
56
+ }
57
+
48
58
void ShaderEditorPlugin::_update_shader_list () {
49
59
shader_list->clear ();
50
60
for (EditedShader &edited_shader : edited_shaders) {
@@ -93,9 +103,7 @@ void ShaderEditorPlugin::_update_shader_list() {
93
103
shader_list->select (shader_tabs->get_current_tab ());
94
104
}
95
105
96
- for (int i = FILE_SAVE; i < FILE_MAX; i++) {
97
- file_menu->get_popup ()->set_item_disabled (file_menu->get_popup ()->get_item_index (i), edited_shaders.is_empty ());
98
- }
106
+ _set_file_specific_items_disabled (edited_shaders.is_empty ());
99
107
100
108
_update_shader_list_status ();
101
109
}
@@ -362,6 +370,61 @@ void ShaderEditorPlugin::_shader_list_clicked(int p_item, Vector2 p_local_mouse_
362
370
if (p_mouse_button_index == MouseButton::MIDDLE) {
363
371
_close_shader (p_item);
364
372
}
373
+ if (p_mouse_button_index == MouseButton::RIGHT) {
374
+ _make_script_list_context_menu ();
375
+ }
376
+ }
377
+
378
+ void ShaderEditorPlugin::_setup_popup_menu (PopupMenuType p_type, PopupMenu *p_menu) {
379
+ if (p_type == FILE) {
380
+ p_menu->add_shortcut (ED_SHORTCUT (" shader_editor/new" , TTR (" New Shader..." ), KeyModifierMask::CMD_OR_CTRL | Key::N), FILE_NEW);
381
+ p_menu->add_shortcut (ED_SHORTCUT (" shader_editor/new_include" , TTR (" New Shader Include..." ), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::N), FILE_NEW_INCLUDE);
382
+ p_menu->add_separator ();
383
+ p_menu->add_shortcut (ED_SHORTCUT (" shader_editor/open" , TTR (" Load Shader File..." ), KeyModifierMask::CMD_OR_CTRL | Key::O), FILE_OPEN);
384
+ p_menu->add_shortcut (ED_SHORTCUT (" shader_editor/open_include" , TTR (" Load Shader Include File..." ), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::O), FILE_OPEN_INCLUDE);
385
+ }
386
+
387
+ if (p_type == FILE || p_type == CONTEXT_VALID_ITEM) {
388
+ p_menu->add_shortcut (ED_SHORTCUT (" shader_editor/save" , TTR (" Save File" ), KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL | Key::S), FILE_SAVE);
389
+ p_menu->add_shortcut (ED_SHORTCUT (" shader_editor/save_as" , TTR (" Save File As..." )), FILE_SAVE_AS);
390
+ }
391
+
392
+ if (p_type == FILE) {
393
+ p_menu->add_separator ();
394
+ p_menu->add_item (TTR (" Open File in Inspector" ), FILE_INSPECT);
395
+ p_menu->add_separator ();
396
+ p_menu->add_shortcut (ED_SHORTCUT (" shader_editor/close_file" , TTR (" Close File" ), KeyModifierMask::CMD_OR_CTRL | Key::W), FILE_CLOSE);
397
+ } else {
398
+ p_menu->add_shortcut (ED_SHORTCUT (" shader_editor/close_file" , TTR (" Close File" ), KeyModifierMask::CMD_OR_CTRL | Key::W), FILE_CLOSE);
399
+ p_menu->add_item (TTR (" Close All" ), CLOSE_ALL);
400
+ p_menu->add_item (TTR (" Close Other Tabs" ), CLOSE_OTHER_TABS);
401
+ if (p_type == CONTEXT_VALID_ITEM) {
402
+ p_menu->add_separator ();
403
+ p_menu->add_item (TTR (" Copy Script Path" ), COPY_PATH);
404
+ p_menu->add_item (TTR (" Show in File System" ), SHOW_IN_FILE_SYSTEM);
405
+ }
406
+ }
407
+ }
408
+
409
+ void ShaderEditorPlugin::_make_script_list_context_menu () {
410
+ context_menu->clear ();
411
+
412
+ int selected = shader_tabs->get_current_tab ();
413
+ if (selected < 0 || selected >= shader_tabs->get_tab_count ()) {
414
+ return ;
415
+ }
416
+
417
+ Control *control = shader_tabs->get_tab_control (selected);
418
+ bool is_valid_editor_control = Object::cast_to<TextShaderEditor>(control) || Object::cast_to<VisualShaderEditor>(control);
419
+
420
+ _setup_popup_menu (is_valid_editor_control ? CONTEXT_VALID_ITEM : CONTEXT, context_menu);
421
+
422
+ context_menu->set_item_disabled (context_menu->get_item_index (CLOSE_ALL), shader_tabs->get_tab_count () <= 0 );
423
+ context_menu->set_item_disabled (context_menu->get_item_index (CLOSE_OTHER_TABS), shader_tabs->get_tab_count () <= 1 );
424
+
425
+ context_menu->set_position (main_split->get_screen_position () + main_split->get_local_mouse_position ());
426
+ context_menu->reset_size ();
427
+ context_menu->popup ();
365
428
}
366
429
367
430
void ShaderEditorPlugin::_close_shader (int p_index) {
@@ -486,6 +549,31 @@ void ShaderEditorPlugin::_menu_item_pressed(int p_index) {
486
549
case FILE_CLOSE: {
487
550
_close_shader (shader_tabs->get_current_tab ());
488
551
} break ;
552
+ case CLOSE_ALL: {
553
+ while (shader_tabs->get_tab_count () > 0 ) {
554
+ _close_shader (0 );
555
+ }
556
+ } break ;
557
+ case CLOSE_OTHER_TABS: {
558
+ int index = shader_tabs->get_current_tab ();
559
+ for (int i = 0 ; i < index ; i++) {
560
+ _close_shader (0 );
561
+ }
562
+ while (shader_tabs->get_tab_count () > 1 ) {
563
+ _close_shader (1 );
564
+ }
565
+ } break ;
566
+ case SHOW_IN_FILE_SYSTEM: {
567
+ Ref<Resource> shader = _get_current_shader ();
568
+ String path = shader->get_path ();
569
+ if (!path.is_empty ()) {
570
+ FileSystemDock::get_singleton ()->navigate_to_path (path);
571
+ }
572
+ } break ;
573
+ case COPY_PATH: {
574
+ Ref<Resource> shader = _get_current_shader ();
575
+ DisplayServer::get_singleton ()->clipboard_set (shader->get_path ());
576
+ } break ;
489
577
}
490
578
}
491
579
@@ -652,6 +740,14 @@ void ShaderEditorPlugin::_res_saved_callback(const Ref<Resource> &p_res) {
652
740
}
653
741
}
654
742
743
+ void ShaderEditorPlugin::_set_file_specific_items_disabled (bool p_disabled) {
744
+ PopupMenu *file_popup_menu = file_menu->get_popup ();
745
+ file_popup_menu->set_item_disabled (file_popup_menu->get_item_index (FILE_SAVE), p_disabled);
746
+ file_popup_menu->set_item_disabled (file_popup_menu->get_item_index (FILE_SAVE_AS), p_disabled);
747
+ file_popup_menu->set_item_disabled (file_popup_menu->get_item_index (FILE_INSPECT), p_disabled);
748
+ file_popup_menu->set_item_disabled (file_popup_menu->get_item_index (FILE_CLOSE), p_disabled);
749
+ }
750
+
655
751
void ShaderEditorPlugin::_notification (int p_what) {
656
752
switch (p_what) {
657
753
case NOTIFICATION_READY: {
@@ -679,23 +775,15 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
679
775
file_menu = memnew (MenuButton);
680
776
file_menu->set_text (TTR (" File" ));
681
777
file_menu->set_shortcut_context (main_split);
682
- file_menu->get_popup ()->add_shortcut (ED_SHORTCUT (" shader_editor/new" , TTR (" New Shader..." ), KeyModifierMask::CMD_OR_CTRL | Key::N), FILE_NEW);
683
- file_menu->get_popup ()->add_shortcut (ED_SHORTCUT (" shader_editor/new_include" , TTR (" New Shader Include..." ), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::N), FILE_NEW_INCLUDE);
684
- file_menu->get_popup ()->add_separator ();
685
- file_menu->get_popup ()->add_shortcut (ED_SHORTCUT (" shader_editor/open" , TTR (" Load Shader File..." ), KeyModifierMask::CMD_OR_CTRL | Key::O), FILE_OPEN);
686
- file_menu->get_popup ()->add_shortcut (ED_SHORTCUT (" shader_editor/open_include" , TTR (" Load Shader Include File..." ), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::O), FILE_OPEN_INCLUDE);
687
- file_menu->get_popup ()->add_shortcut (ED_SHORTCUT (" shader_editor/save" , TTR (" Save File" ), KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL | Key::S), FILE_SAVE);
688
- file_menu->get_popup ()->add_shortcut (ED_SHORTCUT (" shader_editor/save_as" , TTR (" Save File As..." )), FILE_SAVE_AS);
689
- file_menu->get_popup ()->add_separator ();
690
- file_menu->get_popup ()->add_item (TTR (" Open File in Inspector" ), FILE_INSPECT);
691
- file_menu->get_popup ()->add_separator ();
692
- file_menu->get_popup ()->add_shortcut (ED_SHORTCUT (" shader_editor/close_file" , TTR (" Close File" ), KeyModifierMask::CMD_OR_CTRL | Key::W), FILE_CLOSE);
778
+ _setup_popup_menu (FILE, file_menu->get_popup ());
693
779
file_menu->get_popup ()->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
694
780
menu_hb->add_child (file_menu);
695
781
696
- for (int i = FILE_SAVE; i < FILE_MAX; i++) {
697
- file_menu->get_popup ()->set_item_disabled (file_menu->get_popup ()->get_item_index (i), true );
698
- }
782
+ _set_file_specific_items_disabled (true );
783
+
784
+ context_menu = memnew (PopupMenu);
785
+ add_child (context_menu);
786
+ context_menu->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
699
787
700
788
Control *padding = memnew (Control);
701
789
padding->set_h_size_flags (Control::SIZE_EXPAND_FILL);
@@ -718,6 +806,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
718
806
vb->add_child (shader_list);
719
807
shader_list->connect (SceneStringName (item_selected), callable_mp (this , &ShaderEditorPlugin::_shader_selected));
720
808
shader_list->connect (" item_clicked" , callable_mp (this , &ShaderEditorPlugin::_shader_list_clicked));
809
+ shader_list->set_allow_rmb_select (true );
721
810
SET_DRAG_FORWARDING_GCD (shader_list, ShaderEditorPlugin);
722
811
723
812
main_split->add_child (vb);
0 commit comments