2023-01-05 13:25:55 +01:00
/**************************************************************************/
/* editor_log.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2018-01-05 00:50:27 +01:00
2014-02-10 02:10:30 +01:00
# ifndef EDITOR_LOG_H
# define EDITOR_LOG_H
2018-09-11 18:13:45 +02:00
# include "core/os/thread.h"
2014-02-10 02:10:30 +01:00
# include "scene/gui/box_container.h"
2020-06-19 20:49:04 +02:00
# include "scene/gui/button.h"
# include "scene/gui/label.h"
2020-08-16 09:30:52 +02:00
# include "scene/gui/line_edit.h"
2014-02-10 02:10:30 +01:00
# include "scene/gui/panel_container.h"
2020-06-19 20:49:04 +02:00
# include "scene/gui/rich_text_label.h"
# include "scene/gui/texture_button.h"
2017-01-14 10:52:54 +01:00
# include "scene/gui/texture_rect.h"
2018-08-13 17:04:38 +02:00
2022-03-25 18:06:46 +01:00
class UndoRedo ;
2020-08-16 09:30:52 +02:00
class EditorLog : public HBoxContainer {
GDCLASS ( EditorLog , HBoxContainer ) ;
public :
enum MessageType {
MSG_TYPE_STD ,
MSG_TYPE_ERROR ,
2022-05-03 01:29:38 +02:00
MSG_TYPE_STD_RICH ,
2020-08-16 09:30:52 +02:00
MSG_TYPE_WARNING ,
MSG_TYPE_EDITOR ,
} ;
private :
struct LogMessage {
String text ;
MessageType type ;
int count = 1 ;
2023-08-10 08:48:53 +02:00
bool clear = true ;
2020-08-16 09:30:52 +02:00
LogMessage ( ) { }
2024-02-15 17:25:58 +01:00
LogMessage ( const String & p_text , MessageType p_type , bool p_clear ) :
2020-08-16 09:30:52 +02:00
text ( p_text ) ,
2023-08-10 08:48:53 +02:00
type ( p_type ) ,
clear ( p_clear ) {
2020-08-16 09:30:52 +02:00
}
} ;
2022-08-11 12:48:43 +02:00
struct {
Color error_color ;
Ref < Texture2D > error_icon ;
Color warning_color ;
Ref < Texture2D > warning_icon ;
Color message_color ;
} theme_cache ;
2020-08-16 09:30:52 +02:00
// Encapsulates all data and functionality regarding filters.
struct LogFilter {
private :
// Force usage of set method since it has functionality built-in.
int message_count = 0 ;
2021-05-05 03:05:09 +02:00
bool active = true ;
2020-08-16 09:30:52 +02:00
public :
MessageType type ;
Button * toggle_button = nullptr ;
void initialize_button ( const String & p_tooltip , Callable p_toggled_callback ) {
toggle_button = memnew ( Button ) ;
toggle_button - > set_toggle_mode ( true ) ;
toggle_button - > set_pressed ( true ) ;
toggle_button - > set_text ( itos ( message_count ) ) ;
2022-08-25 12:42:17 +02:00
toggle_button - > set_tooltip_text ( TTR ( p_tooltip ) ) ;
2020-08-16 09:30:52 +02:00
// Don't tint the icon even when in "pressed" state.
2022-02-08 10:14:58 +01:00
toggle_button - > add_theme_color_override ( " icon_color_pressed " , Color ( 1 , 1 , 1 , 1 ) ) ;
2020-08-16 09:30:52 +02:00
toggle_button - > set_focus_mode ( FOCUS_NONE ) ;
// When toggled call the callback and pass the MessageType this button is for.
2022-07-28 22:56:41 +02:00
toggle_button - > connect ( " toggled " , p_toggled_callback . bind ( type ) ) ;
2020-08-16 09:30:52 +02:00
}
int get_message_count ( ) {
return message_count ;
}
void set_message_count ( int p_count ) {
message_count = p_count ;
toggle_button - > set_text ( itos ( message_count ) ) ;
}
2021-05-05 03:05:09 +02:00
bool is_active ( ) {
return active ;
}
void set_active ( bool p_active ) {
toggle_button - > set_pressed ( p_active ) ;
active = p_active ;
}
2020-08-16 09:30:52 +02:00
LogFilter ( MessageType p_type ) :
type ( p_type ) {
}
} ;
Vector < LogMessage > messages ;
// Maps MessageTypes to LogFilters for convenient access and storage (don't need 1 member per filter).
2022-05-13 15:04:37 +02:00
HashMap < MessageType , LogFilter * > type_filter_map ;
2014-02-10 02:10:30 +01:00
2022-04-04 15:06:57 +02:00
RichTextLabel * log = nullptr ;
2020-08-16 09:30:52 +02:00
2022-04-04 15:06:57 +02:00
Button * clear_button = nullptr ;
Button * copy_button = nullptr ;
2020-08-16 09:30:52 +02:00
2022-04-04 15:06:57 +02:00
Button * collapse_button = nullptr ;
2020-08-16 09:30:52 +02:00
bool collapse = false ;
2022-04-04 15:06:57 +02:00
Button * show_search_button = nullptr ;
LineEdit * search_box = nullptr ;
2020-08-16 09:30:52 +02:00
// Reference to the "Output" button on the toolbar so we can update it's icon when
// Warnings or Errors are encounetered.
2022-04-04 15:06:57 +02:00
Button * tool_button = nullptr ;
2014-02-10 02:10:30 +01:00
2021-05-05 03:05:09 +02:00
bool is_loading_state = false ; // Used to disable saving requests while loading (some signals from buttons will try trigger a save, which happens during loading).
2022-04-04 15:06:57 +02:00
Timer * save_state_timer = nullptr ;
2021-05-05 03:05:09 +02:00
2021-09-22 17:36:40 +02:00
static void _error_handler ( void * p_self , const char * p_func , const char * p_file , int p_line , const char * p_error , const char * p_errorexp , bool p_editor_notify , ErrorHandlerType p_type ) ;
2014-02-10 02:10:30 +01:00
ErrorHandlerList eh ;
Thread : : ID current ;
2017-01-14 12:26:56 +01:00
//void _dragged(const Point2& p_ofs);
2024-01-15 14:29:52 +01:00
void _meta_clicked ( const String & p_meta ) ;
2015-07-29 00:41:24 +02:00
void _clear_request ( ) ;
2019-04-14 10:55:31 +02:00
void _copy_request ( ) ;
2017-03-05 16:44:50 +01:00
static void _undo_redo_cbk ( void * p_self , const String & p_name ) ;
2014-02-10 02:10:30 +01:00
2020-08-16 09:30:52 +02:00
void _rebuild_log ( ) ;
void _add_log_line ( LogMessage & p_message , bool p_replace_previous = false ) ;
void _set_filter_active ( bool p_active , MessageType p_message_type ) ;
void _set_search_visible ( bool p_visible ) ;
void _search_changed ( const String & p_text ) ;
2023-08-10 08:48:53 +02:00
void _process_message ( const String & p_msg , MessageType p_type , bool p_clear ) ;
2020-08-16 09:30:52 +02:00
void _reset_message_counts ( ) ;
void _set_collapse ( bool p_collapse ) ;
2021-05-05 03:05:09 +02:00
void _start_state_save_timer ( ) ;
void _save_state ( ) ;
void _load_state ( ) ;
2022-08-29 11:04:31 +02:00
void _update_theme ( ) ;
2017-03-05 16:44:50 +01:00
protected :
2014-02-10 02:10:30 +01:00
void _notification ( int p_what ) ;
2017-03-05 16:44:50 +01:00
public :
2018-08-13 17:04:38 +02:00
void add_message ( const String & p_msg , MessageType p_type = MSG_TYPE_STD ) ;
2020-06-19 20:49:04 +02:00
void set_tool_button ( Button * p_tool_button ) ;
2022-03-25 18:06:46 +01:00
void register_undo_redo ( UndoRedo * p_undo_redo ) ;
2014-02-10 02:10:30 +01:00
void deinit ( ) ;
2015-07-30 00:03:25 +02:00
void clear ( ) ;
2020-08-16 09:30:52 +02:00
2014-02-10 02:10:30 +01:00
EditorLog ( ) ;
~ EditorLog ( ) ;
} ;
2020-08-16 09:30:52 +02:00
VARIANT_ENUM_CAST ( EditorLog : : MessageType ) ;
2014-02-10 02:10:30 +01:00
# endif // EDITOR_LOG_H