Move rich editing into SyntaxRichEditCtrl.

- get Decl Editor improvements for free!
This commit is contained in:
Artyom Shalkhakov 2025-02-15 07:47:13 -07:00
parent 644d64e195
commit e8d48cc6e0
7 changed files with 2191 additions and 505 deletions

View file

@ -837,6 +837,8 @@ set(src_imgui ${src_imgui}
tools/imgui/ImGuiTools.cpp
tools/imgui/util/ImGui_IdWidgets.h
tools/imgui/util/ImGui_IdWidgets.cpp
tools/imgui/util/SyntaxRichEditCtrl.h
tools/imgui/util/SyntaxRichEditCtrl.cpp
tools/imgui/afeditor/AfEditor.h
tools/imgui/afeditor/AfEditor.cpp

View file

@ -29,24 +29,12 @@ If you have questions concerning this license or the applicable additional terms
#include "../util/ImGui_IdWidgets.h"
#include "PathTreeCtrl.h"
#include "DeclEditor.h"
#include "DeclBrowser.h"
namespace ImGuiTools {
static const int TAB_SIZE = 4;
// DeclEditor dialog
/*
toolTip_t DialogDeclEditor::toolTips[] = {
{ IDC_DECLEDITOR_BUTTON_TEST, "test decl" },
{ IDOK, "save decl" },
{ IDCANCEL, "cancel" },
{ 0, NULL }
};
*/
/*
================
DeclEditor::DeclEditor
@ -61,14 +49,10 @@ DeclEditor::DeclEditor()
, okButtonEnabled(false)
, cancelButtonEnabled(true)
, errorText()
, findStr()
, replaceStr()
, matchCase(false)
, matchWholeWords(false)
, searchForward(true)
, decl(NULL)
, firstLine(0)
{
declEdit.Init();
}
/*
@ -111,12 +95,12 @@ DeclEditor::UpdateStatusBar
================
*/
void DeclEditor::UpdateStatusBar( void ) {
/*int line, column, character;
int line, column, character;
if ( decl ) {
declEdit.GetCursorPos( line, column, character );
statusBar.SetWindowText( va( "Line: %d, Column: %d, Character: %d", decl->GetLineNum() + line, column, character ) );
}*/
statusBarText = va( "Line: %d, Column: %d", decl->GetLineNum() + line, column );
}
}
/*
@ -126,9 +110,7 @@ DeclEditor::Reset
*/
void DeclEditor::Reset() {
//declEdit.Init();
windowText.Clear();
declEdit.Clear();
testButtonEnabled = false;
okButtonEnabled = false;
@ -146,7 +128,6 @@ void DeclEditor::Start( idDecl *decl ) {
int numCharsPerLine = 0;
int maxCharsPerLine = 0;
idStr declText;
//CRect rect;
this->decl = decl;
@ -155,34 +136,34 @@ void DeclEditor::Start( idDecl *decl ) {
switch( decl->GetType() ) {
case DECL_ENTITYDEF:
//declEdit.SetStringColor( SRE_COLOR_BLUE, SRE_COLOR_DARK_CYAN );
//declEdit.LoadKeyWordsFromFile( "editors/entity.def" );
declEdit.LoadKeyWordsFromFile( "editors/entity.def" );
break;
case DECL_MATERIAL:
//declEdit.LoadKeyWordsFromFile( "editors/material.def" );
declEdit.LoadKeyWordsFromFile( "editors/material.def" );
break;
case DECL_SKIN:
//declEdit.LoadKeyWordsFromFile( "editors/skin.def" );
declEdit.LoadKeyWordsFromFile( "editors/skin.def" );
break;
case DECL_SOUND:
//declEdit.LoadKeyWordsFromFile( "editors/sound.def" );
declEdit.LoadKeyWordsFromFile( "editors/sound.def" );
break;
case DECL_FX:
//declEdit.LoadKeyWordsFromFile( "editors/fx.def" );
declEdit.LoadKeyWordsFromFile( "editors/fx.def" );
break;
case DECL_PARTICLE:
//declEdit.LoadKeyWordsFromFile( "editors/particle.def" );
declEdit.LoadKeyWordsFromFile( "editors/particle.def" );
break;
case DECL_AF:
//declEdit.LoadKeyWordsFromFile( "editors/af.def" );
declEdit.LoadKeyWordsFromFile( "editors/af.def" );
break;
case DECL_TABLE:
//declEdit.LoadKeyWordsFromFile( "editors/table.def" );
declEdit.LoadKeyWordsFromFile( "editors/table.def" );
break;
case DECL_MODELDEF:
//declEdit.LoadKeyWordsFromFile( "editors/model.def" );
declEdit.LoadKeyWordsFromFile( "editors/model.def" );
break;
default:
//declEdit.LoadKeyWordsFromFile( va( "editors/%s.def", declManager->GetDeclNameFromType( decl->GetType() ) ) );
declEdit.LoadKeyWordsFromFile( va( "editors/%s.def", declManager->GetDeclNameFromType( decl->GetType() ) ) );
break;
}
@ -192,7 +173,7 @@ void DeclEditor::Start( idDecl *decl ) {
decl->GetText( localDeclText );
declText = localDeclText;
declEdit = declText;
declEdit.SetText( declText );
for( const char *ptr = declText.c_str(); *ptr; ptr++ ) {
if ( *ptr == '\r' ) {
@ -209,26 +190,6 @@ void DeclEditor::Start( idDecl *decl ) {
}
windowText = va( "Declaration Editor (%s, line %d)", decl->GetFileName(), decl->GetLineNum() );
/*
float scaling_factor = Win_GetWindowScalingFactor(GetSafeHwnd());
rect.left = initialRect.left;
rect.right = rect.left + (maxCharsPerLine * FONT_WIDTH + 32) *scaling_factor;
rect.top = initialRect.top;
rect.bottom = rect.top + (numLines * (FONT_HEIGHT+8) + 24 + 56)* scaling_factor;
if ( rect.right < initialRect.right ) {
rect.right = initialRect.right;
} else if ( rect.right - rect.left > (1024 * scaling_factor) ) {
rect.right = rect.left + (1024 * scaling_factor);
}
if ( rect.bottom < initialRect.bottom ) {
rect.bottom = initialRect.bottom;
} else if ( rect.bottom - rect.top > (768 * scaling_factor) ) {
rect.bottom = rect.top + (768 * scaling_factor);
}
MoveWindow( rect );
*/
testButtonEnabled = false;
okButtonEnabled = false;
@ -249,7 +210,8 @@ bool DeclEditor::Draw() {
if ( ImGui::BeginPopup( "Declaration Editor" ) ) {
if ( ImGui::InputTextMultilineStr( "Text", &declEdit, ImVec2( 500, 500 ) ) ) {
declEdit.Draw();
if ( declEdit.IsEdited() ) {
testButtonEnabled = true;
okButtonEnabled = true;
}
@ -308,144 +270,6 @@ bool DeclEditor::Draw() {
// DeclEditor message handlers
/*
================
DeclEditor::OnEditGoToLine
================
*/
void DeclEditor::OnEditGoToLine() {
/*
DialogGoToLine goToLineDlg;
goToLineDlg.SetRange( firstLine, firstLine + declEdit.GetLineCount() - 1 );
if ( goToLineDlg.DoModal() != IDOK ) {
return;
}
declEdit.GoToLine( goToLineDlg.GetLine() - firstLine );
*/
}
/*
================
DeclEditor::OnEditFind
================
*/
void DeclEditor::OnEditFind() {
/*
idStr selText = declEdit.GetSelText();
if ( selText.GetLength() ) {
findStr = selText;
}
if ( !findDlg ) {
// create find/replace dialog
findDlg = new CFindReplaceDialog(); // Must be created on the heap
findDlg->Create( TRUE, findStr, "", FR_DOWN, this );
}*/
}
/*
================
DeclEditor::OnEditFindNext
================
*/
void DeclEditor::OnEditFindNext() {
/*
if ( declEdit.FindNext( findStr, matchCase, matchWholeWords, searchForward ) ) {
declEdit.SetFocus();
} else {
AfxMessageBox( "The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
}
*/
}
/*
================
DeclEditor::OnEditReplace
================
*/
void DeclEditor::OnEditReplace() {
/*
idStr selText = declEdit.GetSelText();
if ( selText.GetLength() ) {
findStr = selText;
}
// create find/replace dialog
if ( !findDlg ) {
findDlg = new CFindReplaceDialog(); // Must be created on the heap
findDlg->Create( FALSE, findStr, "", FR_DOWN, this );
}
*/
}
/*
================
DeclEditor::OnFindDialogMessage
================
*//*
LRESULT DeclEditor::OnFindDialogMessage( WPARAM wParam, LPARAM lParam ) {
if ( findDlg == NULL ) {
return 0;
}
if ( findDlg->IsTerminating() ) {
findDlg = NULL;
return 0;
}
if( findDlg->FindNext() ) {
findStr = findDlg->GetFindString();
matchCase = findDlg->MatchCase() != FALSE;
matchWholeWords = findDlg->MatchWholeWord() != FALSE;
searchForward = findDlg->SearchDown() != FALSE;
OnEditFindNext();
}
if ( findDlg->ReplaceCurrent() ) {
long selStart, selEnd;
replaceStr = findDlg->GetReplaceString();
declEdit.GetSel( selStart, selEnd );
if ( selEnd > selStart ) {
declEdit.ReplaceSel( replaceStr, TRUE );
}
}
if ( findDlg->ReplaceAll() ) {
replaceStr = findDlg->GetReplaceString();
findStr = findDlg->GetFindString();
matchCase = findDlg->MatchCase() != FALSE;
matchWholeWords = findDlg->MatchWholeWord() != FALSE;
int numReplaces = declEdit.ReplaceAll( findStr, replaceStr, matchCase, matchWholeWords );
if ( numReplaces == 0 ) {
AfxMessageBox( "The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
} else {
AfxMessageBox( va( "Replaced %d occurances.", numReplaces ), MB_OK | MB_ICONINFORMATION, 0 );
}
}
return 0;
}*/
/*
================
DeclEditor::OnEnInputEdit
================
*//*
void DeclEditor::OnEnInputEdit( NMHDR *pNMHDR, LRESULT *pResult ) {
MSGFILTER* msgFilter = (MSGFILTER*)pNMHDR;
if ( msgFilter->msg != 512 && msgFilter->msg != 33 ) {
UpdateStatusBar();
}
*pResult = 0;
}*/
/*
================
DeclEditor::OnBnClickedTest
@ -456,7 +280,7 @@ void DeclEditor::OnBnClickedTest() {
if ( decl ) {
declText = declEdit; //declEdit.GetText( declText );
declEdit.GetText( declText );
if ( !TestDecl( declText ) ) {
return;
@ -485,7 +309,7 @@ bool DeclEditor::OnBnClickedOk() {
if ( decl ) {
declText = declEdit; // declEdit.GetText( declText );
declEdit.GetText( declText );
if ( !TestDecl( declText ) ) {
return false;
@ -513,7 +337,7 @@ void DeclEditor::OnBnClickedOkAccepted() {
if ( decl ) {
declText = declEdit; // declEdit.GetText( declText );
declEdit.GetText( declText );
declManager->Reload( false );
DeclBrowser::Instance().ReloadDeclarations();

View file

@ -29,6 +29,8 @@ If you have questions concerning this license or the applicable additional terms
#ifndef __DECLEDITOR_H__
#define __DECLEDITOR_H__
#include "../util/SyntaxRichEditCtrl.h"
namespace ImGuiTools {
// DeclEditor dialog
@ -38,7 +40,7 @@ public:
DeclEditor(); // standard constructor
void Reset();
void Start(idDecl* decl);
void Start( idDecl* decl );
bool Draw();
@ -50,12 +52,6 @@ public:
}
private:
void OnEditGoToLine();
void OnEditFind();
void OnEditFindNext();
void OnEditReplace();
//void OnFindDialogMessage( WPARAM wParam, LPARAM lParam );
//void OnEnInputEdit( NMHDR *pNMHDR, LRESULT *pResult );
void OnBnClickedTest();
bool OnBnClickedOk();
void OnBnClickedOkAccepted();
@ -65,19 +61,12 @@ private:
bool isShown;
idStr windowText;
idStr statusBarText;
idStr declEdit;
SyntaxRichEditCtrl declEdit;
bool testButtonEnabled;
bool okButtonEnabled;
bool cancelButtonEnabled;
idStr errorText;
//CFindReplaceDialog *findDlg;
idStr findStr;
idStr replaceStr;
bool matchCase;
bool matchWholeWords;
bool searchForward;
idDecl * decl;
int firstLine;

View file

@ -38,8 +38,6 @@ If you have questions concerning this license or the applicable additional terms
namespace ImGuiTools {
static const int TAB_SIZE = 4;
typedef struct scriptEventInfo_s {
idStr name;
idStr parms;
@ -48,19 +46,7 @@ typedef struct scriptEventInfo_s {
static idList<scriptEventInfo_t> scriptEvents;
// DialogScriptEditor dialog
/*
static UINT FindDialogMessage = ::RegisterWindowMessage( FINDMSGSTRING );
toolTip_t DialogScriptEditor::toolTips[] = {
{ IDOK, "save" },
{ IDCANCEL, "cancel" },
{ 0, NULL }
};
IMPLEMENT_DYNAMIC(DialogScriptEditor, CDialog)
*/
// ScriptEditor dialog
ScriptEditor& ScriptEditor::Instance()
{
@ -71,39 +57,25 @@ ScriptEditor& ScriptEditor::Instance()
ScriptEditor::ScriptEditor()
: isShown( false )
, windowText()
, errorText()
, statusBarText( "Script Editor" )
, scriptEdit( NULL )
, scriptEditPos( 0.0f, 0.0f )
, scriptEditSize( 400.0f, 400.0f )
, scriptEdit()
, okButtonEnabled( false )
, cancelButtonEnabled( true )
, errorText()
, findDlg()
, gotoDlg()
, findStr()
, replaceStr()
, matchCase( false )
, matchWholeWords( false )
, searchForward( true )
, fileName()
, firstLine( 0 )
{
scriptEdit = new TextEditor();
scriptEdit.Init();
}
void ScriptEditor::Reset() {
windowText = "Script Editor###ScriptEditor";
errorText.Clear();
statusBarText.Clear();
scriptEdit->SetText( std::string( "" ) );
scriptEdit->SetTabSize( TAB_SIZE );
scriptEdit.SetText( "" );
//scriptEdit.SetTabSize( TAB_SIZE );
okButtonEnabled = false;
cancelButtonEnabled = true;
errorText.Clear();
findStr.Clear();
replaceStr.Clear();
matchCase = false;
matchWholeWords = false;
searchForward = true;
fileName.Clear();
firstLine = 0;
@ -146,13 +118,14 @@ void ScriptEditor::Draw()
ImGui::EndMenu();
}
/*
if ( ImGui::BeginMenu( "Edit" ) ) {
if ( ImGui::MenuItem( "Go To...", "Ctrl+G" ) ) {
OnEditGoToLine();
}
ImGui::EndMenu();
}
}*/
ImGui::EndMenuBar();
}
@ -161,13 +134,10 @@ void ScriptEditor::Draw()
if (clickedSelect) {
}
scriptEditPos = ImGui::GetCursorPos();
scriptEditSize = ImVec2( 800, 600 );
scriptEdit.Draw();
okButtonEnabled = scriptEdit.IsEdited();
scriptEdit->Render( "Text", scriptEditSize, false );
if ( !scriptEdit->IsSaved() ) {
okButtonEnabled = true;
}
UpdateStatusBar();
ImGui::BeginDisabled( !okButtonEnabled );
@ -181,28 +151,6 @@ void ScriptEditor::Draw()
showTool = false;
}
ImGui::EndDisabled();
ImGui::SameLine();
if ( ImGui::Button( "Go to" ) ) {
OnEditGoToLine();
}
if ( ImGui::Button( "Find" ) ) {
idStr selText = scriptEdit->GetSelectedText().c_str();
findDlg.Start( selText, false );
}
if ( ImGui::Button( "Replace" ) ) {
idStr selText = scriptEdit->GetSelectedText().c_str();
findDlg.Start( selText, true );
}
if ( gotoDlg.Draw( scriptEditPos, scriptEditSize ) ) {
TextEditor::Coordinates coords( gotoDlg.GetLine() - 1 - firstLine, 0 );
scriptEdit->SetCursorPosition( coords );
}
FindReplaceDialog::command_t findReplaceResult = findDlg.Draw( scriptEditPos, scriptEditSize );
OnFindDialogMessage( findReplaceResult );
ImGui::TextColored( ImVec4( 1, 0, 0, 1 ), "%s", errorText.c_str() );
ImGui::TextUnformatted( statusBarText.c_str() );
@ -217,28 +165,17 @@ void ScriptEditor::Draw()
}
}
/*
================
DialogScriptEditor::PreTranslateMessage
================
*//*
BOOL DialogScriptEditor::PreTranslateMessage( MSG* pMsg ) {
if ( WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST ) {
if ( m_hAccel && ::TranslateAccelerator( m_hWnd, m_hAccel, pMsg ) ) {
return TRUE;
}
}
return CWnd::PreTranslateMessage(pMsg);
}*/
/*
================
ScriptEditor::UpdateStatusBar
================
*/
void ScriptEditor::UpdateStatusBar( void ) {
TextEditor::Coordinates coords = scriptEdit->GetCursorPosition();
statusBarText = idStr::Format( "Line: %d, Column: %d", coords.mLine + 1, coords.mColumn + 1 );
int line, column, character;
scriptEdit.GetCursorPos( line, column, character );
statusBarText = idStr::Format( "Line: %d, Column: %d", line + 1, column + 1 );
}
/*
@ -344,31 +281,30 @@ void ScriptEditor::OpenFile( const char *fileName ) {
int numCharsPerLine = 0;
int maxCharsPerLine = 0;
idStr scriptText, extension;
//CRect rect;
void *buffer;
//scriptEdit.Init();
//scriptEdit.AllowPathNames( false );
scriptEdit->SetText(std::string(""));
scriptEdit.AllowPathNames( false );
scriptEdit.SetText( "" );
idStr( fileName ).ExtractFileExtension( extension );
if ( extension.Icmp( "script" ) == 0 ) {
InitScriptEvents();
scriptEdit->SetLanguageDefinition( TextEditor::LanguageDefinition::CPlusPlus() );
/*
scriptEdit.SetCaseSensitive( true );
scriptEdit.LoadKeyWordsFromFile( "editors/script.def" );
scriptEdit.SetObjectMemberCallback( GetScriptEvents );
scriptEdit.SetFunctionParmCallback( GetFunctionParms );
scriptEdit.SetToolTipCallback( GetToolTip );
*/
} else if ( extension.Icmp( "gui" ) == 0 ) {
/*
scriptEdit.SetStringColor(SRE_COLOR_DARK_CYAN, SRE_COLOR_LIGHT_BROWN);
//scriptEdit.SetStringColor(SRE_COLOR_DARK_CYAN, SRE_COLOR_LIGHT_BROWN);
scriptEdit.SetCaseSensitive( false );
scriptEdit.LoadKeyWordsFromFile( "editors/gui.def" );
*/
scriptEdit->SetLanguageDefinition( TextEditor::LanguageDefinition::C() );
scriptEdit.SetObjectMemberCallback( NULL );
scriptEdit.SetFunctionParmCallback( NULL );
scriptEdit.SetToolTipCallback( NULL );
}
if ( fileSystem->ReadFile( fileName, &buffer ) == -1 ) {
@ -380,7 +316,7 @@ void ScriptEditor::OpenFile( const char *fileName ) {
this->fileName = fileName;
scriptEdit->SetText( scriptText.c_str() );
scriptEdit.SetText( scriptText.c_str() );
for( const char *ptr = scriptText.c_str(); *ptr; ptr++ ) {
if ( *ptr == '\r' ) {
@ -397,23 +333,7 @@ void ScriptEditor::OpenFile( const char *fileName ) {
}
windowText = va( "Script Editor (%s)###ScriptEditor", fileName );
/*
rect.left = initialRect.left;
rect.right = rect.left + maxCharsPerLine * FONT_WIDTH + 32;
rect.top = initialRect.top;
rect.bottom = rect.top + numLines * (FONT_HEIGHT+8) + 24 + 56;
if ( rect.right < initialRect.right ) {
rect.right = initialRect.right;
} else if ( rect.right - rect.left > 1024 ) {
rect.right = rect.left + 1024;
}
if ( rect.bottom < initialRect.bottom ) {
rect.bottom = initialRect.bottom;
} else if ( rect.bottom - rect.top > 768 ) {
rect.bottom = rect.top + 768;
}
MoveWindow( rect );
*/
okButtonEnabled = false;
cancelButtonEnabled = true;
@ -424,161 +344,6 @@ void ScriptEditor::OpenFile( const char *fileName ) {
// ScriptEditor message handlers
#define BORDER_SIZE 0
#define BUTTON_SPACE 4
#define TOOLBAR_HEIGHT 24
/*
================
ScriptEditor::OnEditGoToLine
================
*/
void ScriptEditor::OnEditGoToLine() {
TextEditor::Coordinates coords = scriptEdit->GetCursorPosition();
gotoDlg.Start( firstLine + 1, firstLine + scriptEdit->GetTotalLines(), coords.mLine + 1 );
/*DialogGoToLine goToLineDlg;
goToLineDlg.SetRange( firstLine, firstLine + scriptEdit.GetLineCount() - 1 );
if ( goToLineDlg.DoModal() != IDOK ) {
return;
}
scriptEdit.GoToLine( goToLineDlg.GetLine() - firstLine );
*/
}
/*
================
ScriptEditor::OnEditFind
================
*/
void ScriptEditor::OnEditFind() {
idStr selText = scriptEdit->GetSelectedText().c_str();
if ( selText.Length() ) {
findStr = selText;
}
/*
// create find/replace dialog
if ( !findDlg ) {
findDlg = new CFindReplaceDialog(); // Must be created on the heap
findDlg->Create( TRUE, findStr, "", FR_DOWN, this );
}
*/
}
/*
================
ScriptEditor::OnEditFindNext
================
*/
void ScriptEditor::OnEditFindNext() {
scriptEdit->FindNext( findStr.c_str(), matchCase, matchWholeWords, searchForward );
}
/*
================
ScriptEditor::OnEditReplace
================
*/
void ScriptEditor::OnEditReplace() {
/*
idStr selText = scriptEdit->GetSelectedText().c_str();
if ( selText.Length() ) {
findStr = selText;
}
// create find/replace dialog
if ( !findDlg ) {
findDlg = new CFindReplaceDialog(); // Must be created on the heap
findDlg->Create( FALSE, findStr, "", FR_DOWN, this );
}
*/
}
/*
================
ScriptEditor::OnFindDialogMessage
================
*/
void ScriptEditor::OnFindDialogMessage( FindReplaceDialog::command_t command ) {
switch ( command ) {
case FindReplaceDialog::command_t::FIND_NEXT:
case FindReplaceDialog::command_t::FIND_PREV:
{
findStr = findDlg.GetFindString();
matchCase = findDlg.MatchCase();
matchWholeWords = findDlg.MatchWholeWord();
searchForward = ( command == FindReplaceDialog::command_t::FIND_NEXT );
OnEditFindNext();
break;
}
case FindReplaceDialog::command_t::FIND_ALL:
break;
case FindReplaceDialog::command_t::REPLACE_NEXT:
{
replaceStr = findDlg.GetReplaceString();
idStr selection = scriptEdit->GetSelectedText().c_str();
if ( selection.Length() && selection == findStr ) {
scriptEdit->DeleteSelection();
scriptEdit->InsertText( replaceStr.c_str() );
}
findStr = findDlg.GetFindString();
matchCase = findDlg.MatchCase();
matchWholeWords = findDlg.MatchWholeWord();
searchForward = true;
OnEditFindNext();
break;
}
case FindReplaceDialog::command_t::REPLACE_ALL:
{
replaceStr = findDlg.GetReplaceString();
findStr = findDlg.GetFindString();
matchCase = findDlg.MatchCase();
matchWholeWords = findDlg.MatchWholeWord();
/*int numReplaces = scriptEdit->ReplaceAll(findStr, replaceStr, matchCase, matchWholeWords);
if (numReplaces == 0) {
AfxMessageBox("The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0);
}
else {
AfxMessageBox(va("Replaced %d occurances.", numReplaces), MB_OK | MB_ICONINFORMATION, 0);
}*/
break;
}
case FindReplaceDialog::command_t::NONE:
case FindReplaceDialog::command_t::DONE:
default:
break;
}
}
/*
================
DialogScriptEditor::OnEnChangeEdit
================
*//*
void ScriptEditor::OnEnChangeEdit( NMHDR *pNMHDR, LRESULT *pResult ) {
okButtonEnabled = true;
}*/
/*
================
ScriptEditor::OnEnInputEdit
================
*//*
void ScriptEditor::OnEnInputEdit( NMHDR *pNMHDR, LRESULT *pResult ) {
MSGFILTER *msgFilter = (MSGFILTER *)pNMHDR;
if ( msgFilter->msg != 512 && msgFilter->msg != 33 ) {
UpdateStatusBar();
}
*pResult = 0;
}*/
/*
================
ScriptEditor::OnBnClickedOk
@ -589,7 +354,7 @@ void ScriptEditor::OnBnClickedOk() {
common->Printf( "Writing \'%s\'...\n", fileName.c_str() );
scriptText = scriptEdit->GetText().c_str();
scriptEdit.GetText( scriptText );
if ( fileSystem->WriteFile( fileName, scriptText, scriptText.Length(), "fs_devpath" ) == -1 ) {
errorText = va( "Couldn't save: %s", fileName.c_str() );

View file

@ -30,12 +30,13 @@ If you have questions concerning this license or the applicable additional terms
#define __SCRIPTEDITOR_H__
#include "../../edit_public.h"
class TextEditor;
#include "../util/SyntaxRichEditCtrl.h"
namespace ImGuiTools
{
class SyntaxRichEditCtrl;
class ScriptEditor {
public:
@ -56,35 +57,19 @@ public:
}
protected:
void OnEditGoToLine();
void OnEditFind();
void OnEditFindNext();
void OnEditReplace();
void OnFindDialogMessage( FindReplaceDialog::command_t command );
//void OnEnChangeEdit( NMHDR *pNMHDR, LRESULT *pResult );
//void OnEnInputEdit( NMHDR *pNMHDR, LRESULT *pResult );
void OnBnClickedOk();
void OnBnClickedCancel();
void OnBnClickedOk();
void OnBnClickedCancel();
private:
bool isShown;
idStr windowText;
idStr statusBarText;
TextEditor * scriptEdit;
ImVec2 scriptEditPos;
ImVec2 scriptEditSize;
bool okButtonEnabled;
bool cancelButtonEnabled;
idStr errorText;
FindReplaceDialog findDlg;
GoToLineDialog gotoDlg;
idStr findStr;
idStr replaceStr;
bool matchCase;
bool matchWholeWords;
bool searchForward;
idStr fileName;
int firstLine;
bool isShown;
idStr windowText;
idStr errorText;
idStr statusBarText;
SyntaxRichEditCtrl scriptEdit;
bool okButtonEnabled;
bool cancelButtonEnabled;
idStr fileName;
int firstLine;
private:
void InitScriptEvents( void );

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,255 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __SYNTAXRICHEDITCTR_H__
#define __SYNTAXRICHEDITCTR_H__
/*
===============================================================================
Rich Edit Control with:
- syntax highlighting
- braced section highlighting
- braced section auto-indentation
- multi-line tabs
- keyword auto-completion
- object member auto-completion
- keyword tool tip
- function parameter tool tip
===============================================================================
*/
#include "../../edit_public.h"
#include "idlib/containers/StrList.h"
class TextEditor;
namespace ImGuiTools {
static const char* FONT_NAME = "Courier";
static const int FONT_HEIGHT = 10;
static const int FONT_WIDTH = 8;
static const int TAB_SIZE = 4;
/*
static const COLORREF SRE_COLOR_BLACK = RGB(0, 0, 0);
static const COLORREF SRE_COLOR_WHITE = RGB(255, 255, 255);
static const COLORREF SRE_COLOR_RED = RGB(255, 0, 0);
static const COLORREF SRE_COLOR_GREEN = RGB(0, 255, 0);
static const COLORREF SRE_COLOR_BLUE = RGB(0, 0, 255);
static const COLORREF SRE_COLOR_YELLOW = RGB(255, 255, 0);
static const COLORREF SRE_COLOR_MAGENTA = RGB(255, 0, 255);
static const COLORREF SRE_COLOR_CYAN = RGB(0, 255, 255);
static const COLORREF SRE_COLOR_ORANGE = RGB(255, 128, 0);
static const COLORREF SRE_COLOR_PURPLE = RGB(150, 0, 150);
static const COLORREF SRE_COLOR_PINK = RGB(186, 102, 123);
static const COLORREF SRE_COLOR_GREY = RGB(85, 85, 85);
static const COLORREF SRE_COLOR_BROWN = RGB(100, 90, 20);
static const COLORREF SRE_COLOR_LIGHT_GREY = RGB(170, 170, 170);
static const COLORREF SRE_COLOR_LIGHT_BROWN = RGB(170, 150, 20);
static const COLORREF SRE_COLOR_DARK_GREEN = RGB(0, 128, 0);
static const COLORREF SRE_COLOR_DARK_CYAN = RGB(0, 150, 150);
static const COLORREF SRE_COLOR_DARK_YELLOW = RGB(220, 200, 20);
*/
typedef struct {
const char * keyWord;
idVec3 color;
const char * description;
} keyWord_t;
typedef bool (*objectMemberCallback_t)(const char* objectName, idStrList& listBox);
typedef bool (*toolTipCallback_t)(const char* name, idStr& string);
class SyntaxRichEditCtrl {
public:
SyntaxRichEditCtrl( void );
~SyntaxRichEditCtrl( void );
void Init( void );
void Draw( void );
void SetCaseSensitive( bool caseSensitive );
void AllowPathNames( bool allow );
void EnableKeyWordAutoCompletion( bool enable );
void SetKeyWords( const keyWord_t kws[] );
bool LoadKeyWordsFromFile( const char *fileName );
void SetObjectMemberCallback( objectMemberCallback_t callback );
void SetFunctionParmCallback( toolTipCallback_t callback );
void SetToolTipCallback( toolTipCallback_t callback );
void SetDefaultColor( const idVec3 &color );
void SetCommentColor( const idVec3 &color );
void SetStringColor( const idVec3 &color, const idVec3 &altColor = vec3_origin );
void SetLiteralColor( const idVec3 &color );
idVec3 GetForeColor( int charIndex ) const;
idVec3 GetBackColor( int charIndex ) const;
void GetCursorPos( int &line, int &column, int &character ) const;
//CHARRANGE GetVisibleRange(void) const;
void GetText( idStr &text ) const;
//void GetText( idStr &text, int startCharIndex, int endCharIndex ) const;
void SetText( const char *text );
bool IsEdited() const;
private:
//virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
bool OnToolTipNotify();
//afx_msg UINT OnGetDlgCode();
//afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
//afx_msg void OnKeyDown(UINT nKey, UINT nRepCnt, UINT nFlags);
//afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
//afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
//afx_msg void OnSize(UINT nType, int cx, int cy);
//afx_msg void OnProtected(NMHDR* pNMHDR, LRESULT* pResult);
//afx_msg void OnChange();
//afx_msg void OnAutoCompleteListBoxChange();
//afx_msg void OnAutoCompleteListBoxDblClk();
void OnEditGoToLine();
void OnEditFindNext();
void OnFindDialogMessage( FindReplaceDialog::command_t command );
private:
TextEditor * scriptEdit;
ImVec2 scriptEditPos;
ImVec2 scriptEditSize;
bool okButtonEnabled;
bool cancelButtonEnabled;
idStr errorText;
FindReplaceDialog findDlg;
GoToLineDialog gotoDlg;
idStr findStr;
idStr replaceStr;
bool matchCase;
bool matchWholeWords;
bool searchForward;
int firstLine;
// settings
//CHARFORMAT2 defaultCharFormat;
idVec3 defaultColor;
idVec3 singleLineCommentColor;
idVec3 multiLineCommentColor;
idVec3 stringColor[2];
idVec3 literalColor;
idVec3 braceHighlightColor;
typedef enum {
CT_WHITESPACE,
CT_COMMENT,
CT_STRING,
CT_LITERAL,
CT_NUMBER,
CT_NAME,
CT_PUNCTUATION
} charType_t;
int charType[256];
idList<keyWord_t> keyWordsFromFile;
const keyWord_t * keyWords;
int * keyWordLengths;
idVec3 * keyWordColors;
idHashIndex keyWordHash;
bool caseSensitive;
bool allowPathNames;
bool keyWordAutoCompletion;
objectMemberCallback_t GetObjectMembers;
toolTipCallback_t GetFunctionParms;
toolTipCallback_t GetToolTip;
// run-time variables
//tom::ITextDocument* m_TextDoc;
//tom::ITextFont* m_DefaultFont;
//CHARRANGE updateRange;
bool updateSyntaxHighlighting;
int stringColorIndex;
int stringColorLine;
int autoCompleteStart;
idStrList autoCompleteListBox;
int autoCompleteListBoxSel;
int funcParmToolTipStart;
idStr funcParmToolTip;
int bracedSection[2];
/*
CPoint mousePoint;
CToolTipCtrl* keyWordToolTip;
TCHAR* m_pchTip;
WCHAR* m_pwchTip;
*/
private:
void InitSyntaxHighlighting( void );
void SetCharType( int first, int last, int type );
void SetDefaultFont( int startCharIndex, int endCharIndex );
void SetColor( int startCharIndex, int endCharIndex, const idVec3 &foreColor, const idVec3 &backColor, bool bold );
void FreeKeyWordsFromFile( void );
int FindKeyWord( const char *keyWord, int length ) const;
void HighlightSyntax( int startCharIndex, int endCharIndex );
void UpdateVisibleRange( void );
bool GetNameBeforeCurrentSelection( idStr &name, int &charIndex ) const;
bool GetNameForMousePosition( idStr &name ) const;
void AutoCompleteInsertText( void );
void AutoCompleteUpdate( void );
void AutoCompleteShow( int charIndex );
void AutoCompleteHide( void );
void ToolTipShow( int charIndex, const char *string );
void ToolTipHide( void );
bool BracedSectionStart( char braceStartChar, char braceEndChar );
bool BracedSectionEnd( char braceStartChar, char braceEndChar );
void BracedSectionAdjustEndTabs( void );
void BracedSectionShow( void );
void BracedSectionHide( void );
};
}
#endif /* !__SYNTAXRICHEDITCTR_H__ */