Rip out the really terrible Gtk Console.
This commit is contained in:
parent
535ff18f71
commit
e0537b7a68
7 changed files with 9 additions and 267 deletions
|
@ -23,202 +23,25 @@
|
|||
|
||||
#include <time.h>
|
||||
#include <uilib/uilib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "gtkutil/accelerator.h"
|
||||
#include "gtkutil/messagebox.h"
|
||||
#include "gtkutil/container.h"
|
||||
#include "gtkutil/menu.h"
|
||||
#include "gtkutil/nonmodal.h"
|
||||
#include "stream/stringstream.h"
|
||||
#include "convert.h"
|
||||
|
||||
#include "version.h"
|
||||
#include "aboutmsg.h"
|
||||
#include "gtkmisc.h"
|
||||
#include "mainframe.h"
|
||||
|
||||
// handle to the console log file
|
||||
namespace {
|
||||
FILE *g_hLogFile;
|
||||
}
|
||||
|
||||
bool g_Console_enableLogging = false;
|
||||
|
||||
// called whenever we need to open/close/check the console log file
|
||||
void Sys_LogFile(bool enable)
|
||||
{
|
||||
if (enable && !g_hLogFile) {
|
||||
// settings say we should be logging and we don't have a log file .. so create it
|
||||
if (!SettingsPath_get()[0]) {
|
||||
return; // cannot open a log file yet
|
||||
}
|
||||
// open a file to log the console (if user prefs say so)
|
||||
// the file handle is g_hLogFile
|
||||
// the log file is erased
|
||||
StringOutputStream name(256);
|
||||
name << SettingsPath_get() << "vedit.log";
|
||||
g_hLogFile = fopen(name.c_str(), "w");
|
||||
if (g_hLogFile != 0) {
|
||||
globalOutputStream() << "Started logging to " << name.c_str() << "\n";
|
||||
time_t localtime;
|
||||
time(&localtime);
|
||||
globalOutputStream() << "Today is: " << ctime(&localtime)
|
||||
<< "This is WorldSpawn '" WorldSpawn_VERSION "' compiled " __DATE__ "\n" WorldSpawn_ABOUTMSG "\n";
|
||||
} else {
|
||||
ui::alert(ui::root, "Failed to create log file, check write permissions in WorldSpawn directory.\n",
|
||||
"Console logging", ui::alert_type::OK, ui::alert_icon::Error);
|
||||
}
|
||||
} else if (!enable && g_hLogFile != 0) {
|
||||
// settings say we should not be logging but still we have an active logfile .. close it
|
||||
time_t localtime;
|
||||
time(&localtime);
|
||||
globalOutputStream() << "Closing log file at " << ctime(&localtime) << "\n";
|
||||
fclose(g_hLogFile);
|
||||
g_hLogFile = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ui::TextView g_console{ui::null};
|
||||
|
||||
void console_clear()
|
||||
{
|
||||
g_console.text("");
|
||||
}
|
||||
|
||||
void console_populate_popup(ui::TextView textview, ui::Menu menu, gpointer user_data)
|
||||
{
|
||||
menu_separator(menu);
|
||||
|
||||
ui::Widget item(ui::MenuItem("Clear"));
|
||||
item.connect("activate", G_CALLBACK(console_clear), 0);
|
||||
item.show();
|
||||
menu.add(item);
|
||||
}
|
||||
|
||||
gboolean destroy_set_null(ui::Window widget, ui::Widget *p)
|
||||
{
|
||||
*p = ui::Widget{ui::null};
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
WidgetFocusPrinter g_consoleWidgetFocusPrinter("console");
|
||||
|
||||
ui::Widget Console_constructWindow(ui::Window toplevel)
|
||||
{
|
||||
auto scr = ui::ScrolledWindow(ui::New);
|
||||
scr.overflow(ui::Policy::AUTOMATIC, ui::Policy::AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
|
||||
scr.show();
|
||||
|
||||
{
|
||||
auto text = ui::TextView(ui::New);
|
||||
text.dimensions(0, -1); // allow shrinking
|
||||
gtk_text_view_set_wrap_mode(text, GTK_WRAP_WORD);
|
||||
gtk_text_view_set_editable(text, FALSE);
|
||||
scr.add(text);
|
||||
text.show();
|
||||
g_console = text;
|
||||
|
||||
//globalExtendedASCIICharacterSet().print();
|
||||
|
||||
widget_connect_escape_clear_focus_widget(g_console);
|
||||
|
||||
//g_consoleWidgetFocusPrinter.connect(g_console);
|
||||
|
||||
g_console.connect("populate-popup", G_CALLBACK(console_populate_popup), 0);
|
||||
g_console.connect("destroy", G_CALLBACK(destroy_set_null), &g_console);
|
||||
}
|
||||
|
||||
gtk_container_set_focus_chain(GTK_CONTAINER(scr), NULL);
|
||||
|
||||
return scr;
|
||||
}
|
||||
|
||||
class GtkTextBufferOutputStream : public TextOutputStream {
|
||||
GtkTextBuffer *textBuffer;
|
||||
GtkTextIter *iter;
|
||||
GtkTextTag *tag;
|
||||
public:
|
||||
GtkTextBufferOutputStream(GtkTextBuffer *textBuffer, GtkTextIter *iter, GtkTextTag *tag) : textBuffer(textBuffer),
|
||||
iter(iter), tag(tag)
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t write(const char *buffer, std::size_t length)
|
||||
{
|
||||
gtk_text_buffer_insert_with_tags(textBuffer, iter, buffer, gint(length), tag, NULL);
|
||||
return length;
|
||||
}
|
||||
};
|
||||
|
||||
std::size_t Sys_Print(int level, const char *buf, std::size_t length)
|
||||
{
|
||||
bool contains_newline = std::find(buf, buf + length, '\n') != buf + length;
|
||||
|
||||
if (level == SYS_ERR) {
|
||||
Sys_LogFile(true);
|
||||
if (SYS_STD) {
|
||||
if (contains_newline)
|
||||
printf("%s", buf);
|
||||
else
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
|
||||
if (g_hLogFile != 0) {
|
||||
fwrite(buf, 1, length, g_hLogFile);
|
||||
if (contains_newline) {
|
||||
fflush(g_hLogFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (level != SYS_NOCON) {
|
||||
if (g_console) {
|
||||
auto buffer = gtk_text_view_get_buffer(g_console);
|
||||
|
||||
GtkTextIter iter;
|
||||
gtk_text_buffer_get_end_iter(buffer, &iter);
|
||||
|
||||
static auto end = gtk_text_buffer_create_mark(buffer, "end", &iter, FALSE);
|
||||
|
||||
const GdkColor yellow = {0, 0xb0ff, 0xb0ff, 0x0000};
|
||||
const GdkColor red = {0, 0xffff, 0x0000, 0x0000};
|
||||
|
||||
static auto error_tag = gtk_text_buffer_create_tag(buffer, "red_foreground", "foreground-gdk", &red, NULL);
|
||||
static auto warning_tag = gtk_text_buffer_create_tag(buffer, "yellow_foreground", "foreground-gdk", &yellow,
|
||||
NULL);
|
||||
static auto standard_tag = gtk_text_buffer_create_tag(buffer, "black_foreground", NULL);
|
||||
GtkTextTag *tag;
|
||||
switch (level) {
|
||||
case SYS_WRN:
|
||||
tag = warning_tag;
|
||||
break;
|
||||
case SYS_ERR:
|
||||
tag = error_tag;
|
||||
break;
|
||||
case SYS_STD:
|
||||
case SYS_VRB:
|
||||
default:
|
||||
tag = standard_tag;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
GtkTextBufferOutputStream textBuffer(buffer, &iter, tag);
|
||||
if (!globalCharacterSet().isUTF8()) {
|
||||
BufferedTextOutputStream<GtkTextBufferOutputStream> buffered(textBuffer);
|
||||
buffered << StringRange(buf, buf + length);
|
||||
} else {
|
||||
textBuffer << StringRange(buf, buf + length);
|
||||
}
|
||||
}
|
||||
|
||||
// update console widget immediatly if we're doing something time-consuming
|
||||
if (contains_newline) {
|
||||
gtk_text_view_scroll_mark_onscreen(g_console, end);
|
||||
|
||||
if (!ScreenUpdates_Enabled() && gtk_widget_get_realized(g_console)) {
|
||||
ScreenUpdates_process();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,4 @@ TextOutputStream &getSysPrintOutputStream();
|
|||
|
||||
TextOutputStream &getSysPrintErrorStream();
|
||||
|
||||
ui::Widget Console_constructWindow(ui::Window toplevel);
|
||||
|
||||
// will open/close the log file based on the parameter
|
||||
void Sys_LogFile(bool enable);
|
||||
|
||||
extern bool g_Console_enableLogging;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -132,8 +132,5 @@ void Error(const char *error, ...)
|
|||
|
||||
ERROR_MESSAGE(text);
|
||||
|
||||
// force close logging if necessary
|
||||
Sys_LogFile(false);
|
||||
|
||||
_exit(1);
|
||||
}
|
||||
|
|
|
@ -447,11 +447,6 @@ void create_global_pid()
|
|||
|
||||
ui::alert(ui::root, msg.c_str(), "Radiant - Console Log", ui::alert_type::OK);
|
||||
}
|
||||
|
||||
// set without saving, the class is not in a coherent state yet
|
||||
// just do the value change and call to start logging, CGamesDialog will pickup when relevant
|
||||
g_GamesDialog.m_bForceLogConsole = true;
|
||||
Sys_LogFile(true);
|
||||
}
|
||||
|
||||
// create a primary .pid for global init run
|
||||
|
@ -510,10 +505,6 @@ void create_local_pid()
|
|||
|
||||
ui::alert(ui::root, msg.c_str(), "Radiant - Console Log", ui::alert_type::OK);
|
||||
}
|
||||
|
||||
// force console logging on! (will go in prefs too)
|
||||
g_GamesDialog.m_bForceLogConsole = true;
|
||||
Sys_LogFile(true);
|
||||
} else {
|
||||
// create one, will remove right after entering message loop
|
||||
pid = fopen(g_pidGameFile.c_str(), "w");
|
||||
|
@ -640,16 +631,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
create_local_pid();
|
||||
|
||||
// in a very particular post-.pid startup
|
||||
// we may have the console turned on and want to keep it that way
|
||||
// so we use a latching system
|
||||
if (g_GamesDialog.m_bForceLogConsole) {
|
||||
Sys_LogFile(true);
|
||||
g_Console_enableLogging = true;
|
||||
g_GamesDialog.m_bForceLogConsole = false;
|
||||
}
|
||||
|
||||
|
||||
Radiant_Initialise();
|
||||
|
||||
user_shortcuts_init();
|
||||
|
@ -694,8 +675,5 @@ int main(int argc, char *argv[])
|
|||
|
||||
Radiant_Shutdown();
|
||||
|
||||
// close the log file if any
|
||||
Sys_LogFile(false);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@
|
|||
#include "camwindow.h"
|
||||
#include "csg.h"
|
||||
#include "commands.h"
|
||||
#include "console.h"
|
||||
#include "entity.h"
|
||||
#include "entityinspector.h"
|
||||
#include "entitylist.h"
|
||||
|
@ -1240,13 +1239,6 @@ void OpenBugReportURL()
|
|||
}
|
||||
|
||||
|
||||
ui::Widget g_page_console{ui::null};
|
||||
|
||||
void Console_ToggleShow()
|
||||
{
|
||||
GroupDialog_showPage(g_page_console);
|
||||
}
|
||||
|
||||
ui::Widget g_page_entity{ui::null};
|
||||
|
||||
void EntityInspector_ToggleShow()
|
||||
|
@ -2297,7 +2289,6 @@ void fill_view_xz_front_menu(ui::Menu menu)
|
|||
|
||||
|
||||
ui::Widget g_toggle_z_item{ui::null};
|
||||
ui::Widget g_toggle_console_item{ui::null};
|
||||
ui::Widget g_toggle_entity_item{ui::null};
|
||||
ui::Widget g_toggle_entitylist_item{ui::null};
|
||||
|
||||
|
@ -2314,7 +2305,6 @@ ui::MenuItem create_view_menu()
|
|||
fill_view_xz_front_menu(menu);*/
|
||||
|
||||
create_menu_item_with_mnemonic(menu, "Map Info", "MapInfo");
|
||||
create_menu_item_with_mnemonic(menu, "Console View", "ToggleConsole");
|
||||
create_menu_item_with_mnemonic(menu, "Texture Browser", "ToggleTextures");
|
||||
create_menu_item_with_mnemonic(menu, "Entity Inspector", "ToggleEntityInspector");
|
||||
|
||||
|
@ -2779,8 +2769,6 @@ ui::Toolbar create_main_toolbar()
|
|||
space();
|
||||
toolbar_append_toggle_button(toolbar, "Texture Lock (SHIFT +T)", "texture_lock.xpm", "TogTexLock");
|
||||
space();
|
||||
toolbar_append_button(toolbar, "Console (O)", "console.xpm", "ToggleConsole");
|
||||
space();
|
||||
toolbar_append_button(toolbar, "Refresh Assets", "refresh_models.xpm",
|
||||
"RefreshReferences");
|
||||
|
||||
|
@ -3207,11 +3195,6 @@ void MainFrame::Create()
|
|||
g_page_entity = GroupDialog_addPage("Entities", EntityInspector_constructWindow(GroupDialog_getWindow()),
|
||||
RawStringExportCaller("Entities"));
|
||||
|
||||
/*if (FloatingGroupDialog()) {*/
|
||||
g_page_console = GroupDialog_addPage("Console", Console_constructWindow(GroupDialog_getWindow()),
|
||||
RawStringExportCaller("Console"));
|
||||
/*}
|
||||
*/
|
||||
m_window = window;
|
||||
|
||||
window.show();
|
||||
|
@ -3493,7 +3476,6 @@ void MainFrame_Construct()
|
|||
Accelerator('E', (GdkModifierType) (GDK_MOD1_MASK | GDK_CONTROL_MASK)));
|
||||
GlobalCommands_insert("Preferences", makeCallbackF(PreferencesDialog_showDialog));
|
||||
|
||||
GlobalCommands_insert("ToggleConsole", makeCallbackF(Console_ToggleShow), Accelerator('O'));
|
||||
GlobalCommands_insert("ToggleEntityInspector", makeCallbackF(EntityInspector_ToggleShow), Accelerator('N'));
|
||||
GlobalCommands_insert("EntityList", makeCallbackF(EntityList_toggleShown), Accelerator('L'));
|
||||
|
||||
|
|
|
@ -52,12 +52,6 @@
|
|||
#include "qe3.h"
|
||||
#include "gtkdlgs.h"
|
||||
|
||||
|
||||
void Global_constructPreferences(PreferencesPage &page)
|
||||
{
|
||||
page.appendCheckBox("Console", "Enable Logging", g_Console_enableLogging);
|
||||
}
|
||||
|
||||
void Interface_constructPreferences(PreferencesPage &page)
|
||||
{
|
||||
#if GDEF_OS_WINDOWS
|
||||
|
@ -225,26 +219,10 @@ bool Preferences_Save_Safe(PreferenceDictionary &preferences, const char *filena
|
|||
&& file_move(tmpName.data(), filename);
|
||||
}
|
||||
|
||||
|
||||
struct LogConsole {
|
||||
static void Export(const Callback<void(bool)> &returnz)
|
||||
{
|
||||
returnz(g_Console_enableLogging);
|
||||
}
|
||||
|
||||
static void Import(bool value)
|
||||
{
|
||||
g_Console_enableLogging = value;
|
||||
Sys_LogFile(g_Console_enableLogging);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void RegisterGlobalPreferences(PreferenceSystem &preferences)
|
||||
{
|
||||
preferences.registerPreference("gamefile", make_property_string(g_GamesDialog.m_sGameFile));
|
||||
preferences.registerPreference("gamePrompt", make_property_string(g_GamesDialog.m_bGamePrompt));
|
||||
preferences.registerPreference("log console", make_property_string<LogConsole>());
|
||||
}
|
||||
|
||||
|
||||
|
@ -357,7 +335,6 @@ ui::Window CGameDialog::BuildDialog()
|
|||
vbox.pack_start(frame, FALSE, FALSE, 0);
|
||||
|
||||
PreferencesPage preferencesPage(*this, vbox2);
|
||||
Global_constructPreferences(preferencesPage);
|
||||
CreateGlobalFrame(preferencesPage);
|
||||
|
||||
return create_simple_modal_dialog_window("Global Preferences", m_modal, vbox);
|
||||
|
@ -816,7 +793,6 @@ ui::Window PrefsDlg::BuildDialog()
|
|||
auto global = PreferencePages_addPage(m_notebook, "Global Preferences");
|
||||
{
|
||||
PreferencesPage preferencesPage(*this, getVBox(global));
|
||||
Global_constructPreferences(preferencesPage);
|
||||
}
|
||||
auto group = PreferenceTree_appendPage(store, 0, "Global", global);
|
||||
{
|
||||
|
|
|
@ -290,11 +290,6 @@ public:
|
|||
prompt which game to load on startup
|
||||
*/
|
||||
bool m_bGamePrompt;
|
||||
/*!
|
||||
log console to radiant.log
|
||||
m_bForceLogConsole is an obscure forced latching situation
|
||||
*/
|
||||
bool m_bForceLogConsole;
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
|
@ -304,8 +299,7 @@ public:
|
|||
|
||||
CGameDialog() :
|
||||
m_sGameFile(""),
|
||||
m_bGamePrompt(true),
|
||||
m_bForceLogConsole(false)
|
||||
m_bGamePrompt(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue