2015-05-07 17:05:27 -04:00
|
|
|
/**
|
|
|
|
* The editor widget
|
|
|
|
*/
|
|
|
|
|
2015-07-07 10:01:17 -04:00
|
|
|
#include "src/widgets/EditPane.h"
|
2015-04-02 18:00:50 -04:00
|
|
|
|
2015-05-13 16:55:44 -04:00
|
|
|
extern StringConstMap Glob_lexer_map;
|
2015-07-15 17:03:00 -04:00
|
|
|
static wxConfig *Glob_config = nullptr;
|
2015-05-13 16:55:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param wxWindow* parent
|
|
|
|
* @param wxWindowID id
|
|
|
|
* @param const wxPoint& pos
|
|
|
|
* @param const wxSize& size
|
|
|
|
*/
|
2015-04-02 18:00:50 -04:00
|
|
|
EditPane::EditPane(
|
2015-04-24 16:55:10 -04:00
|
|
|
wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size
|
|
|
|
) : wxStyledTextCtrl (parent, id, pos, size, wxBORDER_NONE)
|
2015-04-21 14:07:04 -04:00
|
|
|
{
|
2015-07-15 17:03:00 -04:00
|
|
|
Glob_config = (wxConfig *) wxConfigBase::Get();
|
2019-05-31 16:34:31 -04:00
|
|
|
this->lang_config = new LangConfig();
|
|
|
|
this->theme_config = new ThemeConfig();
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-16 17:03:27 -04:00
|
|
|
this->BindEvents();
|
2015-05-04 16:27:21 -04:00
|
|
|
|
|
|
|
// Some basic properties to set
|
|
|
|
this->SetStyleBits(8);
|
|
|
|
this->SetScrollWidthTracking(true);// Set scroll width by longest line
|
|
|
|
this->SetProperty("technology", "2");
|
|
|
|
this->SetProperty("error.inline", "0");
|
|
|
|
this->SetProperty("styling.within.preprocessor", "1");
|
|
|
|
this->SetProperty("lexer.cpp.track.preprocessor", "1");
|
|
|
|
this->SetProperty("font.quality", "3"); // LCD Optimized
|
2015-05-27 11:37:02 -04:00
|
|
|
|
2015-05-13 16:55:44 -04:00
|
|
|
//this->SetLayoutCache (wxSTC_CACHE_DOCUMENT);
|
2015-05-04 16:27:21 -04:00
|
|
|
|
|
|
|
// set spaces and indention
|
|
|
|
this->SetTabWidth(4);
|
|
|
|
|
|
|
|
// Blank highlight
|
|
|
|
this->Highlight("");
|
2015-04-02 18:00:50 -04:00
|
|
|
}
|
|
|
|
|
2015-05-13 16:55:44 -04:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
2015-04-21 14:07:04 -04:00
|
|
|
EditPane::~EditPane()
|
2015-04-14 15:58:43 -04:00
|
|
|
{
|
2015-05-08 16:01:36 -04:00
|
|
|
wxLogDebug("Called EditPane Destructor");
|
2019-05-31 16:34:31 -04:00
|
|
|
delete this->lang_config;
|
|
|
|
delete this->theme_config;
|
2015-04-14 15:58:43 -04:00
|
|
|
}
|
2015-04-10 15:11:15 -04:00
|
|
|
|
|
|
|
/**
|
2015-04-17 16:55:48 -04:00
|
|
|
* Handle the highlighting config for the
|
|
|
|
* selected file
|
2015-04-21 14:07:04 -04:00
|
|
|
*
|
2015-04-10 15:11:15 -04:00
|
|
|
* @param wxString filePath
|
2015-04-17 16:55:48 -04:00
|
|
|
* @return void
|
2015-04-10 15:11:15 -04:00
|
|
|
*/
|
2019-05-30 15:09:42 -04:00
|
|
|
void EditPane::Highlight(const wxString &filePath)
|
2015-04-10 15:11:15 -04:00
|
|
|
{
|
2015-04-17 16:55:48 -04:00
|
|
|
this->fileName.Assign(filePath);
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
// Get the configuration name for the selected language
|
2019-05-31 16:34:31 -04:00
|
|
|
string lang = this->lang_config->GetLangByFile(this->fileName);
|
2015-04-17 16:55:48 -04:00
|
|
|
|
2015-04-21 14:07:04 -04:00
|
|
|
// Apply the theme
|
|
|
|
this->ApplyTheme(lang);
|
|
|
|
|
|
|
|
bool use_tabs = (lang != "yaml");
|
|
|
|
|
2015-04-23 11:03:50 -04:00
|
|
|
this->SetUseTabs(use_tabs);
|
|
|
|
this->SetTabIndents(true);
|
|
|
|
this->SetBackSpaceUnIndents(true);
|
2015-04-21 14:07:04 -04:00
|
|
|
}
|
|
|
|
|
2015-04-21 17:06:21 -04:00
|
|
|
/**
|
|
|
|
* Set the current theme for the current language
|
|
|
|
*
|
|
|
|
* @param string lang
|
|
|
|
* @param string theme
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-05-17 16:19:42 -04:00
|
|
|
void EditPane::ApplyTheme(const string &lang, const string &theme)
|
2015-05-13 16:55:44 -04:00
|
|
|
{
|
|
|
|
this->StyleClearAll();
|
|
|
|
|
|
|
|
if (Glob_lexer_map.count(lang) > 0)
|
|
|
|
{
|
|
|
|
this->SetLexer(Glob_lexer_map[lang]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->SetLexer(wxSTC_LEX_NULL);
|
|
|
|
}
|
|
|
|
|
2019-03-20 16:49:25 -04:00
|
|
|
if ( ! theme.empty())
|
2015-05-07 17:05:27 -04:00
|
|
|
{
|
2019-05-31 16:34:31 -04:00
|
|
|
this->theme_config->SetTheme(theme);
|
2015-05-07 17:05:27 -04:00
|
|
|
}
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-29 17:03:15 -04:00
|
|
|
// Get the keywords and mapping for the selected language
|
2019-05-31 16:34:31 -04:00
|
|
|
JsonValue lexer_map = this->lang_config->GetLexerMap(lang);
|
|
|
|
JsonValue keywords_array = this->lang_config->GetKeywordList(lang);
|
2015-04-29 17:03:15 -04:00
|
|
|
|
2015-04-15 09:47:20 -04:00
|
|
|
if (keywords_array.isArray())
|
|
|
|
{
|
2015-04-22 21:06:35 -04:00
|
|
|
for(unsigned int i = 0; i < keywords_array.size(); i++)
|
2015-04-15 12:17:25 -04:00
|
|
|
{
|
|
|
|
this->SetKeyWords(i, keywords_array[i].asString());
|
|
|
|
}
|
2015-04-15 09:47:20 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-20 16:49:25 -04:00
|
|
|
if ( ! lang.empty())
|
2015-05-08 16:01:36 -04:00
|
|
|
{
|
|
|
|
string typeMap[] = {"null", "int", "unsigned int", "double", "string", "boolean", "array", "object"};
|
|
|
|
stringstream output;
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-05-08 16:01:36 -04:00
|
|
|
output << "current lang is:" << lang << endl;
|
|
|
|
output << "keywords array is not an array" << endl;
|
|
|
|
output << "keyword array is a " << typeMap[keywords_array.type()] << endl;
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-05-08 16:01:36 -04:00
|
|
|
wxLogDebug(output.str().c_str());
|
|
|
|
}
|
2015-04-15 09:47:20 -04:00
|
|
|
}
|
2015-04-21 14:07:04 -04:00
|
|
|
|
|
|
|
// Do the appropriate mappings to load the selected theme
|
2015-04-29 17:03:15 -04:00
|
|
|
this->_ApplyTheme(lexer_map);
|
2015-04-17 16:55:48 -04:00
|
|
|
}
|
2015-04-10 15:11:15 -04:00
|
|
|
|
2015-05-27 11:37:02 -04:00
|
|
|
/**
|
|
|
|
* Re-style the control based on changed preferences
|
|
|
|
*
|
|
|
|
* @param string [theme]
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-05-17 16:19:42 -04:00
|
|
|
void EditPane::ReApplyTheme(const string &theme)
|
2015-05-27 11:37:02 -04:00
|
|
|
{
|
2019-05-31 16:34:31 -04:00
|
|
|
this->ApplyTheme(this->lang_config->GetLangByName(this->GetCurrentLang()), theme);
|
2015-05-27 11:37:02 -04:00
|
|
|
}
|
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
/**
|
|
|
|
* Check file path and open the selected file
|
|
|
|
*
|
|
|
|
* @param wxString filePath
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-05-30 15:09:42 -04:00
|
|
|
bool EditPane::Load(const wxString &filePath)
|
2015-04-17 16:55:48 -04:00
|
|
|
{
|
|
|
|
this->fileName.Assign(filePath);
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
if (this->FileReadable())
|
2015-04-21 14:07:04 -04:00
|
|
|
{
|
2015-04-17 16:55:48 -04:00
|
|
|
this->Highlight(filePath);
|
|
|
|
bool didLoad = this->LoadFile(filePath);
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
// @TODO Toggle controls based on write permission
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
return didLoad;
|
|
|
|
}
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
return false;
|
2015-04-10 15:11:15 -04:00
|
|
|
}
|
2015-04-16 17:03:27 -04:00
|
|
|
|
2015-05-13 16:55:44 -04:00
|
|
|
/**
|
|
|
|
* Save the current file
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-04-16 17:03:27 -04:00
|
|
|
bool EditPane::SaveFile()
|
|
|
|
{
|
2015-05-27 11:37:02 -04:00
|
|
|
wxString fname = this->fileName.GetFullPath();
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2019-05-16 15:21:32 -04:00
|
|
|
return this->SaveFile(fname);
|
2015-04-16 17:03:27 -04:00
|
|
|
}
|
|
|
|
|
2015-05-13 16:55:44 -04:00
|
|
|
/**
|
|
|
|
* Save the current file with the specified filename
|
|
|
|
*
|
|
|
|
* @param const wxString filename
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-04-16 17:03:27 -04:00
|
|
|
bool EditPane::SaveFile(const wxString &filename)
|
|
|
|
{
|
|
|
|
if ( ! this->IsModified()) return true;
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
this->fileName.Assign(filename);
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
// Check file permissions
|
|
|
|
if (this->FileWritable())
|
|
|
|
{
|
|
|
|
this->SetSavePoint();
|
|
|
|
return wxStyledTextCtrl::SaveFile(filename);
|
|
|
|
}
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
return false;
|
2015-04-16 17:03:27 -04:00
|
|
|
}
|
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
/**
|
|
|
|
* Check that the current file can be opened
|
2015-04-21 14:07:04 -04:00
|
|
|
*
|
|
|
|
* @return bool
|
2015-04-17 16:55:48 -04:00
|
|
|
*/
|
|
|
|
bool EditPane::FileReadable()
|
2015-04-21 14:07:04 -04:00
|
|
|
{
|
2015-04-17 16:55:48 -04:00
|
|
|
if (
|
|
|
|
this->fileName.IsOk() &&
|
|
|
|
this->fileName.Exists() &&
|
|
|
|
this->fileName.IsFileReadable()
|
|
|
|
) return true;
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
// Hmm...well, let's give an error
|
|
|
|
wxMessageDialog errDlg(
|
2015-04-21 14:07:04 -04:00
|
|
|
this,
|
|
|
|
TYRO_OPEN_ERROR,
|
2015-04-17 16:55:48 -04:00
|
|
|
TYRO_OPEN_ERROR_CAPTION,
|
|
|
|
wxOK | wxICON_ERROR | wxCENTER
|
|
|
|
);
|
|
|
|
errDlg.ShowModal();
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the current file can be saved
|
2015-04-21 14:07:04 -04:00
|
|
|
*
|
|
|
|
* @return bool
|
2015-04-17 16:55:48 -04:00
|
|
|
*/
|
|
|
|
bool EditPane::FileWritable()
|
|
|
|
{
|
|
|
|
// Lets see...can we write somewhere?
|
|
|
|
if (
|
|
|
|
this->fileName.IsOk() &&
|
|
|
|
((this->fileName.Exists() && this->fileName.IsFileWritable()) ||
|
|
|
|
(( ! this->fileName.Exists()) && this->fileName.IsDirWritable()))
|
|
|
|
) return true;
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-04-17 16:55:48 -04:00
|
|
|
// Hmm...well, let's give an error
|
|
|
|
wxMessageDialog errDlg(
|
2015-04-21 14:07:04 -04:00
|
|
|
this,
|
|
|
|
TYRO_SAVE_ERROR,
|
2015-04-17 16:55:48 -04:00
|
|
|
TYRO_SAVE_ERROR_CAPTION,
|
|
|
|
wxOK | wxICON_ERROR | wxCENTER
|
|
|
|
);
|
|
|
|
errDlg.ShowModal();
|
|
|
|
|
|
|
|
return false;
|
2015-04-16 17:03:27 -04:00
|
|
|
}
|
|
|
|
|
2015-05-13 16:55:44 -04:00
|
|
|
/**
|
|
|
|
* Wire Event handlers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-04-16 17:03:27 -04:00
|
|
|
void EditPane::BindEvents()
|
|
|
|
{
|
2015-06-05 16:50:52 -04:00
|
|
|
// Code folding event handler
|
|
|
|
this->Bind(wxEVT_STC_MARGINCLICK, [=](wxStyledTextEvent& event) {
|
|
|
|
if (event.GetMargin() == MARGIN_FOLD)
|
|
|
|
{
|
|
|
|
int lineClick = this->LineFromPosition (event.GetPosition());
|
|
|
|
int levelClick = this->GetFoldLevel (lineClick);
|
|
|
|
if ((levelClick & wxSTC_FOLDLEVELHEADERFLAG) > 0) {
|
|
|
|
this->ToggleFold (lineClick);
|
|
|
|
}
|
2015-04-23 11:03:50 -04:00
|
|
|
}
|
2015-06-05 16:50:52 -04:00
|
|
|
}, wxID_ANY);
|
|
|
|
|
2019-03-20 16:49:25 -04:00
|
|
|
// this->Bind(wxEVT_STC_CHARADDED, &EditPane::OnCharAdded, this, wxID_ANY);
|
2015-04-16 17:03:27 -04:00
|
|
|
}
|
2015-04-21 09:55:28 -04:00
|
|
|
|
2015-04-28 14:58:52 -04:00
|
|
|
/**
|
|
|
|
* Look at characters added to help with indentation
|
|
|
|
*
|
|
|
|
* @param wxStyledTextEvent& event
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
void EditPane::OnCharAdded(wxStyledTextEvent& event)
|
|
|
|
{
|
|
|
|
char chr = (char) event.GetKey();
|
|
|
|
int currentLine = this->GetCurrentLine();
|
|
|
|
|
|
|
|
if (chr == '\n')
|
|
|
|
{
|
|
|
|
int lineInd = 0;
|
|
|
|
if (currentLine > 0)
|
|
|
|
{
|
|
|
|
lineInd = this->GetLineIndentation(currentLine - 1);
|
|
|
|
}
|
|
|
|
if (lineInd == 0) return;
|
|
|
|
|
|
|
|
this->SetLineIndentation(currentLine, lineInd);
|
|
|
|
this->GotoPos(this->PositionFromLine(currentLine) + (lineInd / 4));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 14:07:04 -04:00
|
|
|
/**
|
|
|
|
* Iterate through the theme settings and apply them
|
|
|
|
*
|
|
|
|
* @param JsonValue lexer_map - Maps token types to theme colors
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-04-29 17:03:15 -04:00
|
|
|
void EditPane::_ApplyTheme(JsonValue &lexer_map)
|
2015-04-21 14:07:04 -04:00
|
|
|
{
|
2019-05-31 14:17:30 -04:00
|
|
|
// Make sure to have a default font, especially for Linux
|
|
|
|
wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2019-03-20 16:49:25 -04:00
|
|
|
static const wxColor default_background = this->theme_config->GetThemeColor("background", "default");
|
|
|
|
static const wxColor default_foreground = this->theme_config->GetThemeColor("foreground", "default");
|
|
|
|
wxColor line_number_background = ( ! this->theme_config->GetThemeValue("line_numbers", "background").isNull())
|
|
|
|
? (this->theme_config->GetThemeColor("line_numbers", "background"))
|
2015-04-21 17:06:21 -04:00
|
|
|
: default_background;
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2019-03-20 16:49:25 -04:00
|
|
|
wxColor line_number_foreground = ( ! this->theme_config->GetThemeValue("line_numbers", "foreground").isNull())
|
|
|
|
? (this->theme_config->GetThemeColor("line_numbers", "foreground"))
|
2015-04-21 17:06:21 -04:00
|
|
|
: default_foreground;
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2019-05-31 14:17:30 -04:00
|
|
|
// Attempt to set the font according to config
|
|
|
|
Glob_config->Read("global_font", &globalFont);
|
|
|
|
|
2015-04-21 14:07:04 -04:00
|
|
|
// Set default colors/ fonts
|
|
|
|
for(int i = 0; i <= wxSTC_STYLE_MAX; i++)
|
|
|
|
{
|
|
|
|
this->StyleSetBackground(i, default_background);
|
2015-04-21 17:06:21 -04:00
|
|
|
this->StyleSetForeground(i, default_foreground);
|
2019-05-31 14:17:30 -04:00
|
|
|
|
|
|
|
this->StyleSetFont(i, globalFont);
|
2015-04-21 14:07:04 -04:00
|
|
|
}
|
2019-05-16 15:21:32 -04:00
|
|
|
|
2015-05-27 11:37:02 -04:00
|
|
|
// Set up Code folding
|
|
|
|
if (Glob_config->ReadBool("show_code_folding", false))
|
|
|
|
{
|
|
|
|
this->SetProperty("fold", "1");
|
|
|
|
this->SetProperty("fold.comment", "1");
|
|
|
|
this->SetProperty("fold.compact", "1");
|
|
|
|
this->SetProperty("fold.html", "1");
|
|
|
|
this->SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
|
|
|
|
|
|
|
|
this->SetMarginType(MARGIN_FOLD, wxSTC_MARGIN_SYMBOL);
|
|
|
|
this->SetMarginWidth(MARGIN_FOLD, 16);
|
|
|
|
this->SetMarginSensitive(MARGIN_FOLD, true);
|
|
|
|
this->SetMarginMask(MARGIN_FOLD, wxSTC_MASK_FOLDERS);
|
|
|
|
|
|
|
|
this->MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, "WHITE", "BLACK");
|
|
|
|
this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, "WHITE", "BLACK");
|
2019-05-17 16:19:42 -04:00
|
|
|
this->MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "BLACK", "BLACK");
|
2015-05-27 11:37:02 -04:00
|
|
|
this->MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, "WHITE", "BLACK");
|
|
|
|
this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, "WHITE", "BLACK");
|
2019-05-17 16:19:42 -04:00
|
|
|
this->MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "BLACK", "BLACK");
|
|
|
|
this->MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK");
|
2015-05-27 11:37:02 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->SetProperty("fold", "0");
|
|
|
|
this->SetProperty("fold.comment", "0");
|
|
|
|
this->SetProperty("fold.compact", "0");
|
|
|
|
this->SetProperty("fold.html", "0");
|
|
|
|
this->SetMarginWidth(MARGIN_FOLD, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup indent guides
|
|
|
|
if (Glob_config->ReadBool("show_indent_guides", false))
|
|
|
|
{
|
|
|
|
this->StyleSetForeground(wxSTC_STYLE_DEFAULT, default_foreground);
|
|
|
|
this->StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, default_foreground);
|
|
|
|
this->SetIndentationGuides(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->SetIndentationGuides(0);
|
|
|
|
}
|
2015-04-21 14:07:04 -04:00
|
|
|
|
2015-05-27 11:37:02 -04:00
|
|
|
// Setup line numbers
|
|
|
|
if (Glob_config->ReadBool("show_line_numbers", true))
|
|
|
|
{
|
|
|
|
this->SetMarginWidth (MARGIN_LINE_NUMBERS, TextWidth(wxSTC_STYLE_LINENUMBER, "_999"));
|
|
|
|
this->StyleSetForeground (wxSTC_STYLE_LINENUMBER, line_number_foreground);
|
|
|
|
this->StyleSetBackground (wxSTC_STYLE_LINENUMBER, line_number_background);
|
|
|
|
this->SetMarginType (MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->SetMarginWidth (MARGIN_LINE_NUMBERS, 0);
|
|
|
|
}
|
2015-04-22 16:57:10 -04:00
|
|
|
|
2015-05-28 16:25:16 -04:00
|
|
|
int max = lexer_map.size();
|
2015-04-29 17:03:15 -04:00
|
|
|
for (int i = 0; i < max; i++)
|
2015-04-21 14:07:04 -04:00
|
|
|
{
|
2015-04-29 17:03:15 -04:00
|
|
|
string key = lexer_map[i].asString();
|
2015-04-21 14:07:04 -04:00
|
|
|
|
|
|
|
// Set the foreground color, if it exists
|
2019-05-31 16:34:31 -04:00
|
|
|
if ( ! this->theme_config->GetThemeValue("foreground", key).isNull())
|
2015-04-21 14:07:04 -04:00
|
|
|
{
|
2019-05-31 16:34:31 -04:00
|
|
|
this->StyleSetForeground(i, this->theme_config->GetThemeColor("foreground", key));
|
2015-04-21 14:07:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the background color, if it exists
|
2019-05-31 16:34:31 -04:00
|
|
|
if ( ! this->theme_config->GetThemeValue("background", key).isNull())
|
2015-04-21 14:07:04 -04:00
|
|
|
{
|
2019-05-31 16:34:31 -04:00
|
|
|
this->StyleSetBackground(i, this->theme_config->GetThemeColor("background", key));
|
2015-04-21 14:07:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set bold, if it applies
|
2019-05-31 16:34:31 -04:00
|
|
|
if this->theme_config->GetThemeValue("bold", key).isBool())
|
2015-04-21 14:07:04 -04:00
|
|
|
{
|
2019-05-31 16:34:31 -04:00
|
|
|
this->StyleSetBold(i, this->theme_config->GetThemeValue("bold", key).asBool());
|
2015-04-21 14:07:04 -04:00
|
|
|
}
|
2015-04-21 17:06:21 -04:00
|
|
|
|
|
|
|
// Italic
|
2019-05-31 16:34:31 -04:00
|
|
|
if this->theme_config->GetThemeValue("italic", key).isBool())
|
2015-04-21 17:06:21 -04:00
|
|
|
{
|
2019-05-31 16:34:31 -04:00
|
|
|
this->StyleSetItalic(i, this->theme_config->GetThemeValue("italic", key).asBool());
|
2015-04-21 17:06:21 -04:00
|
|
|
}
|
2015-04-29 10:18:44 -04:00
|
|
|
|
|
|
|
// Underline
|
2019-05-31 16:34:31 -04:00
|
|
|
if this->theme_config->GetThemeValue("underline", key).isBool())
|
2015-04-29 10:18:44 -04:00
|
|
|
{
|
2019-05-31 16:34:31 -04:00
|
|
|
this->StyleSetUnderline(i, this->theme_config->GetThemeValue("underline", key).asBool());
|
2015-04-29 10:18:44 -04:00
|
|
|
}
|
2015-04-21 14:07:04 -04:00
|
|
|
}
|
|
|
|
}
|
2015-05-12 16:30:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the display name of the currently selected
|
|
|
|
* language used for highlighting
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
string EditPane::GetCurrentLang()
|
|
|
|
{
|
2019-03-20 16:49:25 -04:00
|
|
|
return this->lang_config->GetCurrentLangName();
|
2015-05-12 16:30:22 -04:00
|
|
|
}
|
2015-05-13 16:55:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the highlighting language
|
|
|
|
*
|
|
|
|
* @param string name
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-05-17 16:19:42 -04:00
|
|
|
void EditPane::SetCurrentLang(const string &name)
|
2015-05-13 16:55:44 -04:00
|
|
|
{
|
|
|
|
// Update the current lang in the config
|
2019-03-20 16:49:25 -04:00
|
|
|
string langKey = this->lang_config->GetLangByName(name);
|
|
|
|
this->lang_config->SetLang(langKey);
|
2015-05-13 16:55:44 -04:00
|
|
|
|
|
|
|
// Re-highlight the page with the new langauge
|
|
|
|
this->ApplyTheme(langKey);
|
|
|
|
}
|