diff --git a/basctl/Library_basctl.mk b/basctl/Library_basctl.mk index bbd9a0047578..13d3bce29e41 100644 --- a/basctl/Library_basctl.mk +++ b/basctl/Library_basctl.mk @@ -99,6 +99,8 @@ $(eval $(call gb_Library_add_exception_objects,basctl,\ basctl/source/basicide/macrodlg \ basctl/source/basicide/moduldl2 \ basctl/source/basicide/moduldlg \ + basctl/source/basicide/BasicColorConfig \ + basctl/source/basicide/ColorSchemeDialog \ basctl/source/basicide/ObjectCatalog \ basctl/source/basicide/sbxitem \ basctl/source/basicide/scriptdocument \ diff --git a/basctl/UIConfig_basicide.mk b/basctl/UIConfig_basicide.mk index 2c23fbfb58af..217ea6c01708 100644 --- a/basctl/UIConfig_basicide.mk +++ b/basctl/UIConfig_basicide.mk @@ -37,6 +37,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/BasicIDE,\ basctl/uiconfig/basicide/ui/basicmacrodialog \ basctl/uiconfig/basicide/ui/breakpointmenus \ basctl/uiconfig/basicide/ui/codecomplete \ + basctl/uiconfig/basicide/ui/colorscheme \ basctl/uiconfig/basicide/ui/combobox \ basctl/uiconfig/basicide/ui/defaultlanguage \ basctl/uiconfig/basicide/ui/deletelangdialog \ diff --git a/basctl/inc/strings.hrc b/basctl/inc/strings.hrc index 324b6ba1d44b..44efc2f52ed8 100644 --- a/basctl/inc/strings.hrc +++ b/basctl/inc/strings.hrc @@ -114,6 +114,15 @@ #define RID_STR_MODULE_READONLY NC_("RID_STR_READONLY_WARNING", "This module is read-only and cannot be edited.") #define RID_STR_DIALOG_READONLY NC_("RID_STR_READONLY_WARNING", "This dialog is read-only and cannot be edited.") +// Color scheme names +#define RID_STR_COLORSCHEME_DEFAULT NC_("RID_STR_COLORSCHEME_DEFAULT", "Default") +#define RID_STR_COLORSCHEME_LIGHT NC_("RID_STR_COLORSCHEME_LIGHT", "%PRODUCTNAME Light") +#define RID_STR_COLORSCHEME_DARK NC_("RID_STR_COLORSCHEME_DARK", "%PRODUCTNAME Dark") +#define RID_STR_COLORSCHEME_BREEZE_LIGHT NC_("RID_STR_COLORSCHEME_BREEZE_LIGHT", "Breeze Light") +#define RID_STR_COLORSCHEME_BREEZE_DARK NC_("RID_STR_COLORSCHEME_BREEZE_DARK", "Breeze Dark") +#define RID_STR_COLORSCHEME_SOLARIZED_DARK NC_("RID_STR_COLORSCHEME_SOLARIZED_DARK", "Solarized Dark") +#define RID_STR_COLORSCHEME_SOLARIZED_LIGHT NC_("RID_STR_COLORSCHEME_SOLARIZED_LIGHT", "Solarized Light") + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basctl/sdi/baside.sdi b/basctl/sdi/baside.sdi index 9e7229ca9712..40ddd8b3bfd7 100644 --- a/basctl/sdi/baside.sdi +++ b/basctl/sdi/baside.sdi @@ -343,6 +343,12 @@ shell basctl_Shell StateMethod = GetState; ] + SID_BASICIDE_COLOR_SCHEME_DLG + [ + ExecMethod = ExecuteGlobal; + StateMethod = GetState; + ] + SID_ATTR_ZOOMSLIDER [ ExecMethod = ExecuteGlobal; diff --git a/basctl/source/basicide/BasicColorConfig.cxx b/basctl/source/basicide/BasicColorConfig.cxx new file mode 100644 index 000000000000..1a650fd8c433 --- /dev/null +++ b/basctl/source/basicide/BasicColorConfig.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include + +#include + +namespace basctl +{ +BasicColorConfig::BasicColorConfig() + : ConfigItem("Office.BasicIDE/IDEColorSchemes") +{ + // Innitially the active color scheme is the one defined in the registry + m_sCurrentColorScheme = officecfg::Office::BasicIDE::EditorSettings::ColorScheme::get(); + + // Initialize all available scheme names + m_aSchemeNames = GetNodeNames(""); +} + +BasicColorConfig::~BasicColorConfig() {} + +void BasicColorConfig::Notify(const css::uno::Sequence&) {} + +void BasicColorConfig::ImplCommit() {} + +ColorScheme BasicColorConfig::GetColorScheme(const OUString& rScheme) +{ + // If the default scheme is being requested or the scheme does not exist, return the Application Colors scheme + if (rScheme == DEFAULT_SCHEME || comphelper::findValue(m_aSchemeNames, rScheme) == -1) + { + return GetAutomaticColorScheme(); + } + + std::vector aVecPropNames = { + OUString(rScheme + "/GenericColor/Color"), OUString(rScheme + "/IdentifierColor/Color"), + OUString(rScheme + "/NumberColor/Color"), OUString(rScheme + "/StringColor/Color"), + OUString(rScheme + "/CommentColor/Color"), OUString(rScheme + "/ErrorColor/Color"), + OUString(rScheme + "/OperatorColor/Color"), OUString(rScheme + "/KeywordColor/Color"), + OUString(rScheme + "/BackgroundColor/Color") + }; + + css::uno::Sequence aPropNames(aVecPropNames.size()); + OUString* pPropNames = aPropNames.getArray(); + for (sal_uLong i = 0; i < aVecPropNames.size(); i++) + { + pPropNames[i] = aVecPropNames[i]; + } + css::uno::Sequence aColors = GetProperties(aPropNames); + + ColorScheme aColorScheme; + aColorScheme.m_sSchemeName = rScheme; + aColorScheme.m_bIsDefault = comphelper::findValue(m_aDefaultSchemes, rScheme) != -1; + aColors[0] >>= aColorScheme.m_aGenericFontColor; + aColors[1] >>= aColorScheme.m_aIdentifierColor; + aColors[2] >>= aColorScheme.m_aNumberColor; + aColors[3] >>= aColorScheme.m_aStringColor; + aColors[4] >>= aColorScheme.m_aCommentColor; + aColors[5] >>= aColorScheme.m_aErrorColor; + aColors[6] >>= aColorScheme.m_aOperatorColor; + aColors[7] >>= aColorScheme.m_aKeywordColor; + aColors[8] >>= aColorScheme.m_aBackgroundColor; + + return aColorScheme; +} + +ColorScheme BasicColorConfig::GetAutomaticColorScheme() +{ + ColorScheme aScheme = { DEFAULT_SCHEME, + false, + aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor, + aColorConfig.GetColorValue(svtools::BASICIDENTIFIER).nColor, + aColorConfig.GetColorValue(svtools::BASICNUMBER).nColor, + aColorConfig.GetColorValue(svtools::BASICSTRING).nColor, + aColorConfig.GetColorValue(svtools::BASICCOMMENT).nColor, + aColorConfig.GetColorValue(svtools::BASICERROR).nColor, + aColorConfig.GetColorValue(svtools::BASICOPERATOR).nColor, + aColorConfig.GetColorValue(svtools::BASICKEYWORD).nColor, + aColorConfig.GetColorValue(svtools::BASICEDITOR).nColor }; + return aScheme; +} + +OUString& BasicColorConfig::GetCurrentColorSchemeName() +{ + // Always return from the registry to get the most up-to-date value + m_sCurrentColorScheme = officecfg::Office::BasicIDE::EditorSettings::ColorScheme::get(); + return m_sCurrentColorScheme; +} + +TranslateId BasicColorConfig::GetSchemeTranslateId(const OUString& rScheme) +{ + return m_aTranslateIdsMap.find(rScheme)->second; +} + +} // namespace basctl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basctl/source/basicide/ColorSchemeDialog.cxx b/basctl/source/basicide/ColorSchemeDialog.cxx new file mode 100644 index 000000000000..7ae4cf3ccf5f --- /dev/null +++ b/basctl/source/basicide/ColorSchemeDialog.cxx @@ -0,0 +1,148 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include "baside2.hxx" +#include +#include +#include + +namespace basctl +{ +ColorSchemeDialog::ColorSchemeDialog(weld::Window* pParent, + VclPtr pModulWinLayout) + : GenericDialogController(pParent, "modules/BasicIDE/ui/colorscheme.ui", "ColorSchemeDialog") + , m_pModulWinLayout(pModulWinLayout) + , m_xSchemeList(m_xBuilder->weld_tree_view("schemelist")) + , m_xUseAppCollors(m_xBuilder->weld_radio_button("opt_appcolors")) + , m_xUseScheme(m_xBuilder->weld_radio_button("opt_usescheme")) + , m_xOk(m_xBuilder->weld_button("btn_ok")) +{ + m_pColorConfig = GetShell()->GetColorConfig(); + m_sSelectedSchemeId = m_pColorConfig->GetCurrentColorSchemeName(); + + m_xSchemeList->set_size_request(m_xSchemeList->get_approximate_digit_width() * 30, + m_xSchemeList->get_height_rows(10)); + m_xSchemeList->set_selection_mode(SelectionMode::Single); + + Init(); +} + +ColorSchemeDialog::~ColorSchemeDialog() {} + +void ColorSchemeDialog::Init() +{ + m_xOk->connect_clicked(LINK(this, ColorSchemeDialog, BtnOkHdl)); + m_xUseAppCollors->connect_toggled(LINK(this, ColorSchemeDialog, OptionHdl)); + m_xUseScheme->connect_toggled(LINK(this, ColorSchemeDialog, OptionHdl)); + m_xSchemeList->connect_changed(LINK(this, ColorSchemeDialog, SelectHdl)); + + // Populate the list with available color schemes + for (auto const& rName : m_pColorConfig->GetColorSchemeNames()) + { + // Default schemes (preinstalled with LO) have TranslateIds + if (m_pColorConfig->IsDefaultScheme(rName)) + { + m_xSchemeList->append(rName, IDEResId(m_pColorConfig->GetSchemeTranslateId(rName))); + } + else + { + m_xSchemeList->append(rName, rName); + } + } + m_xSchemeList->make_sorted(); + + // Set initial selection in the dialog + m_xUseAppCollors->set_active(true); + if (m_sSelectedSchemeId == DEFAULT_SCHEME) + { + // The "Application Colors" theme is being used + m_xSchemeList->set_sensitive(false); + } + else + { + // Check if the scheme exists + if (comphelper::findValue(m_pColorConfig->GetColorSchemeNames(), m_sSelectedSchemeId) != -1) + { + m_xUseScheme->set_active(true); + m_xSchemeList->select_id(m_sSelectedSchemeId); + } + else + { + m_xSchemeList->set_sensitive(false); + } + } +} + +IMPL_LINK_NOARG(ColorSchemeDialog, BtnOkHdl, weld::Button&, void) +{ + // Collect selected theme + if (m_xUseAppCollors->get_active()) + m_sSelectedSchemeId = DEFAULT_SCHEME; + else + m_sSelectedSchemeId = m_xSchemeList->get_selected_id(); + + m_xDialog->response(RET_OK); +} + +IMPL_LINK_NOARG(ColorSchemeDialog, OptionHdl, weld::Toggleable&, void) +{ + if (m_xUseAppCollors->get_active()) + { + m_xSchemeList->set_sensitive(false); + m_pModulWinLayout->ApplyColorSchemeToCurrentWindow(DEFAULT_SCHEME); + m_sSelectedSchemeId = DEFAULT_SCHEME; + } + + if (m_xUseScheme->get_active()) + { + m_xSchemeList->set_sensitive(true); + // Always select a item to avoid having nothing selected + if (m_sSelectedSchemeId == DEFAULT_SCHEME) + { + // If the default color scheme was selected, then choose first entry in the list + m_xSchemeList->select_id(m_xSchemeList->get_id(0)); + m_pModulWinLayout->ApplyColorSchemeToCurrentWindow(m_xSchemeList->get_id(0)); + } + else + { + // If a color scheme was active, select it in the list + m_xSchemeList->select_id(m_sSelectedSchemeId); + m_pModulWinLayout->ApplyColorSchemeToCurrentWindow(m_sSelectedSchemeId); + } + } +} + +IMPL_LINK_NOARG(ColorSchemeDialog, SelectHdl, weld::TreeView&, void) +{ + // Apply the selected scheme only for the current ModulWinLayout for preview + // Only if the user presses OK the scheme will be applied to all ModulWinLayout(s) + m_sSelectedSchemeId = m_xSchemeList->get_selected_id(); + m_pModulWinLayout->ApplyColorSchemeToCurrentWindow(m_sSelectedSchemeId); +} + +} // namespace basctl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basctl/source/basicide/baside2.cxx b/basctl/source/basicide/baside2.cxx index b01e5c238a6c..0f892d5683bf 100644 --- a/basctl/source/basicide/baside2.cxx +++ b/basctl/source/basicide/baside2.cxx @@ -26,6 +26,7 @@ #include #include "moduldlg.hxx" #include +#include #include #include @@ -69,6 +70,7 @@ #include #include #include +#include namespace basctl { @@ -201,6 +203,9 @@ ModulWindow::ModulWindow (ModulWindowLayout* pParent, ScriptDocument const& rDoc , m_aXEditorWindow(VclPtr::Create(this)) , m_aModule(std::move(aModule)) { + // Active editor color scheme + m_sWinColorScheme = GetShell()->GetColorConfig()->GetCurrentColorSchemeName(); + m_aXEditorWindow->Show(); SetBackground(); } @@ -1428,13 +1433,32 @@ void ModulWindow::UpdateModule () MarkDocumentModified(m_aDocument); } +void ModulWindow::SetEditorColorScheme(OUString aColorScheme) +{ + m_sWinColorScheme = aColorScheme; + EditorWindow& rEditWindow = GetEditorWindow(); + Wallpaper aBackgroundColor(GetLayout().GetSyntaxBackgroundColor()); + rEditWindow.SetBackground(aBackgroundColor); + rEditWindow.GetWindow(GetWindowType::Border)->SetBackground(aBackgroundColor); + + // The EditEngine is created only when the module is actually opened for the first time, + // therefore we need to check if it actually exists before updating its syntax highlighting + ExtTextEngine* pEditEngine = GetEditEngine(); + if (pEditEngine) + rEditWindow.UpdateSyntaxHighlighting(); +} + ModulWindowLayout::ModulWindowLayout (vcl::Window* pParent, ObjectCatalog& rObjectCatalog_) : Layout(pParent), pChild(nullptr), aWatchWindow(VclPtr::Create(this)), aStackWindow(VclPtr::Create(this)), rObjectCatalog(rObjectCatalog_) -{ } +{ + // Get active color scheme from the registry + m_sColorSchemeId = GetShell()->GetColorConfig()->GetCurrentColorSchemeName(); + aSyntaxColors.ApplyColorScheme(m_sColorSchemeId, true); +} ModulWindowLayout::~ModulWindowLayout() { @@ -1471,6 +1495,7 @@ void ModulWindowLayout::Activating (BaseWindow& rChild) rObjectCatalog.UpdateEntries(); Layout::Activating(rChild); aSyntaxColors.SetActiveEditor(&pChild->GetEditorWindow()); + aSyntaxColors.SetActiveColorSchemeId(m_sColorSchemeId); } void ModulWindowLayout::Deactivating () @@ -1526,12 +1551,19 @@ void ModulWindowLayout::OnFirstSize (tools::Long const nWidth, tools::Long const AddToBottom(aStackWindow.get(), Size(nWidth * 0.33, nHeight * 0.25)); } -ModulWindowLayout::SyntaxColors::SyntaxColors () : - pEditor(nullptr) +// Applies the color scheme to the current window and updates color definitions; +// note that other ModulWindow instances are not affected by calling this method +void ModulWindowLayout::ApplyColorSchemeToCurrentWindow(OUString aSchemeId) +{ + // Apply new color scheme to the UI + m_sColorSchemeId = aSchemeId; + aSyntaxColors.ApplyColorScheme(m_sColorSchemeId, false); +} + +ModulWindowLayout::SyntaxColors::SyntaxColors () + : pEditor(nullptr) { aConfig.AddListener(this); - - NewConfig(true); } ModulWindowLayout::SyntaxColors::~SyntaxColors () @@ -1542,62 +1574,87 @@ ModulWindowLayout::SyntaxColors::~SyntaxColors () // virtual void ModulWindowLayout::SyntaxColors::ConfigurationChanged (utl::ConfigurationBroadcaster*, ConfigurationHints) { - NewConfig(false); + // The color scheme only needs to be applied when configuration changed if the "default" color + // scheme (based on Application Colors) is being used + if (m_sActiveSchemeId == DEFAULT_SCHEME) + ApplyColorScheme(DEFAULT_SCHEME, false); } -// when a new configuration has to be set -void ModulWindowLayout::SyntaxColors::NewConfig (bool bFirst) +// Applies an entire new color scheme; when bFirst is true, then the checks to see if the color scheme +// has changed are ignored to make sure the color scheme is applied +void ModulWindowLayout::SyntaxColors::ApplyColorScheme(OUString aSchemeId, bool bFirst) { - static struct + const TokenType vTokenTypes[] = { - TokenType eTokenType; - svtools::ColorConfigEntry eEntry; - } - const vIds[] = - { - { TokenType::Unknown, svtools::FONTCOLOR }, - { TokenType::Identifier, svtools::BASICIDENTIFIER }, - { TokenType::Whitespace, svtools::FONTCOLOR }, - { TokenType::Number, svtools::BASICNUMBER }, - { TokenType::String, svtools::BASICSTRING }, - { TokenType::EOL, svtools::FONTCOLOR }, - { TokenType::Comment, svtools::BASICCOMMENT }, - { TokenType::Error, svtools::BASICERROR }, - { TokenType::Operator, svtools::BASICOPERATOR }, - { TokenType::Keywords, svtools::BASICKEYWORD }, + TokenType::Unknown, + TokenType::Identifier, + TokenType::Whitespace, + TokenType::Number, + TokenType::String, + TokenType::EOL, + TokenType::Comment, + TokenType::Error, + TokenType::Operator, + TokenType::Keywords }; - Color aDocColor = aConfig.GetColorValue(svtools::BASICEDITOR).nColor; - if (bFirst || aDocColor != m_aBackgroundColor) + m_sActiveSchemeId = aSchemeId; + ColorScheme aColorScheme = GetShell()->GetColorConfig()->GetColorScheme(aSchemeId); + Color aFontColor = aColorScheme.m_aGenericFontColor; + m_aFontColor = aFontColor; + Color aDocColor = aColorScheme.m_aBackgroundColor; + m_aBackgroundColor = aDocColor; + if (!bFirst && pEditor) { - m_aBackgroundColor = aDocColor; - if (!bFirst && pEditor) - { - pEditor->SetBackground(Wallpaper(m_aBackgroundColor)); - pEditor->Invalidate(); - } + pEditor->ChangeFontColor(aFontColor); + pEditor->SetBackground(Wallpaper(aDocColor)); + pEditor->Invalidate(); } - Color aFontColor = aConfig.GetColorValue(svtools::FONTCOLOR).nColor; - if (bFirst || aFontColor != m_aFontColor) + for (const auto& aToken: vTokenTypes) { - m_aFontColor = aFontColor; - if (!bFirst && pEditor) - pEditor->ChangeFontColor(m_aFontColor); + // Retrieves the new color to be set from the color scheme + Color aNewColor; + switch (aToken) + { + case TokenType::EOL: + case TokenType::Whitespace: + case TokenType::Unknown: + aNewColor = aColorScheme.m_aGenericFontColor; + break; + case TokenType::Identifier: + aNewColor = aColorScheme.m_aIdentifierColor; + break; + case TokenType::Number: + aNewColor = aColorScheme.m_aNumberColor; + break; + case TokenType::String: + aNewColor = aColorScheme.m_aStringColor; + break; + case TokenType::Comment: + aNewColor = aColorScheme.m_aCommentColor; + break; + case TokenType::Error: + aNewColor = aColorScheme.m_aErrorColor; + break; + case TokenType::Operator: + aNewColor = aColorScheme.m_aOperatorColor; + break; + case TokenType::Keywords: + aNewColor = aColorScheme.m_aKeywordColor; + break; + default: + SAL_WARN("basctl.basicide", "Unexpected token type for color scheme"); + aNewColor = aColorScheme.m_aGenericFontColor; + } + + Color& rCurrentColor = aColors[aToken]; + rCurrentColor = aNewColor; } - bool bChanged = false; - for (const auto& vId: vIds) - { - Color const aColor = aConfig.GetColorValue(vId.eEntry).nColor; - Color& rMyColor = aColors[vId.eTokenType]; - if (bFirst || aColor != rMyColor) - { - rMyColor = aColor; - bChanged = true; - } - } - if (bChanged && !bFirst && pEditor) + // This check is needed because the EditEngine will only exist in the EditorWindow when the + // module is actually opened + if (!bFirst && pEditor) pEditor->UpdateSyntaxHighlighting(); } diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx index 116dab2bb905..bb8380bbdcc5 100644 --- a/basctl/source/basicide/baside2.hxx +++ b/basctl/source/basicide/baside2.hxx @@ -24,6 +24,7 @@ #include #include "breakpoint.hxx" #include "linenumberwindow.hxx" +#include #include #include @@ -37,6 +38,7 @@ #include #include +#include #include #include @@ -290,6 +292,7 @@ private: BasicStatus m_aStatus; SbModuleRef m_xModule; OUString m_aModule; + OUString m_sWinColorScheme; void CheckCompileBasic(); void BasicExecute(); @@ -392,6 +395,8 @@ public: virtual bool HasActiveEditor () const override; void UpdateModule (); + OUString GetEditorColorScheme() { return m_sWinColorScheme; } + void SetEditorColorScheme(OUString aColorScheme); }; class ModulWindowLayout: public Layout @@ -416,6 +421,8 @@ public: Color const & GetSyntaxBackgroundColor () const { return aSyntaxColors.GetBackgroundColor(); } Color const & GetFontColor () const { return aSyntaxColors.GetFontColor(); } Color const & GetSyntaxColor (TokenType eType) const { return aSyntaxColors.GetColor(eType); } + OUString GetActiveColorSchemeId() { return m_sColorSchemeId; } + void ApplyColorSchemeToCurrentWindow (OUString aSchemeId); protected: // Window: @@ -430,6 +437,8 @@ private: VclPtr aWatchWindow; VclPtr aStackWindow; ObjectCatalog& rObjectCatalog; + // Active color scheme ID + OUString m_sColorSchemeId; // SyntaxColors -- stores Basic syntax highlighting colors class SyntaxColors : public utl::ConfigurationListener @@ -439,25 +448,26 @@ private: virtual ~SyntaxColors () override; public: void SetActiveEditor (EditorWindow* pEditor_) { pEditor = pEditor_; } + void SetActiveColorSchemeId(OUString aColorSchemeId) { m_sActiveSchemeId = aColorSchemeId; } public: Color const & GetBackgroundColor () const { return m_aBackgroundColor; }; Color const & GetFontColor () const { return m_aFontColor; } Color const & GetColor(TokenType eType) const { return aColors[eType]; } + void ApplyColorScheme(OUString aSchemeId, bool bFirst); private: virtual void ConfigurationChanged (utl::ConfigurationBroadcaster*, ConfigurationHints) override; - void NewConfig (bool bFirst); private: Color m_aBackgroundColor; Color m_aFontColor; + OUString m_sActiveSchemeId; // the color values (the indexes are TokenType, see comphelper/syntaxhighlight.hxx) o3tl::enumarray aColors; // the configuration svtools::ColorConfig aConfig; // the active editor VclPtr pEditor; - } aSyntaxColors; }; diff --git a/basctl/source/basicide/basides1.cxx b/basctl/source/basicide/basides1.cxx index 4f2918dcc6d9..507902a34d0a 100644 --- a/basctl/source/basicide/basides1.cxx +++ b/basctl/source/basicide/basides1.cxx @@ -31,6 +31,7 @@ #include "iderdll2.hxx" #include #include +#include #include #include @@ -59,6 +60,7 @@ #include #include #include +#include constexpr sal_Int32 TAB_HEIGHT_MARGIN = 10; @@ -789,6 +791,50 @@ void Shell::ExecuteGlobal( SfxRequest& rReq ) } break; + case SID_BASICIDE_COLOR_SCHEME_DLG: + { + ModulWindowLayout* pMyLayout = dynamic_cast(pLayout.get()); + if (!pMyLayout) + return; + + OUString curScheme = pMyLayout->GetActiveColorSchemeId(); + auto xDlg = std::make_shared(pCurWin ? pCurWin->GetFrameWeld() : nullptr, + pMyLayout); + weld::DialogController::runAsync(xDlg, [xDlg, pMyLayout, curScheme](sal_Int32 nResult){ + OUString sNewScheme(xDlg->GetColorSchemeId()); + // If the user canceled the dialog, restores the original color scheme + if (nResult != RET_OK) + { + if (curScheme != sNewScheme) + pMyLayout->ApplyColorSchemeToCurrentWindow(curScheme); + } + + // If the user selects OK, apply the color scheme to all open ModulWindow + if (nResult == RET_OK) + { + // Set the global color scheme in ModulWindowLayout and update definitions in SyntaxColors + pMyLayout->ApplyColorSchemeToCurrentWindow(sNewScheme); + + // Update color scheme for all windows + for (auto const& window : GetShell()->GetWindowTable()) + { + ModulWindow* pModuleWindow = dynamic_cast(window.second.get()); + if (pModuleWindow) + { + // We need to set the current scheme for each window + pModuleWindow->SetEditorColorScheme(sNewScheme); + } + } + + // Update registry with the new color scheme ID + std::shared_ptr batch(comphelper::ConfigurationChanges::create()); + officecfg::Office::BasicIDE::EditorSettings::ColorScheme::set(sNewScheme, batch); + batch->commit(); + } + }); + } + break; + case SID_BASICIDE_MANAGE_LANG: { auto xRequest = std::make_shared(rReq); @@ -1231,6 +1277,13 @@ void Shell::GetState(SfxItemSet &rSet) } break; + case SID_BASICIDE_COLOR_SCHEME_DLG: + { + if (!dynamic_cast(pLayout.get())) + rSet.DisableItem(nWh); + } + break; + case SID_ATTR_ZOOMSLIDER: { // The zoom slider is only visible in a module window diff --git a/basctl/source/basicide/basidesh.cxx b/basctl/source/basicide/basidesh.cxx index d23da94d268f..e64e34e0ff59 100644 --- a/basctl/source/basicide/basidesh.cxx +++ b/basctl/source/basicide/basidesh.cxx @@ -74,6 +74,7 @@ #include #include #include +#include namespace basctl { @@ -196,6 +197,9 @@ void Shell::Init() GetViewFrame().GetWindow().GetSettings().GetStyleSettings().GetWindowColor() ); + // Used to access color settings of the Basic code editor + m_aColorConfig = std::make_shared(); + pCurWin = nullptr; m_aCurDocument = ScriptDocument::getApplicationScriptDocument(); bCreatingWindow = false; diff --git a/basctl/source/inc/BasicColorConfig.hxx b/basctl/source/inc/BasicColorConfig.hxx new file mode 100644 index 000000000000..9d66925e952a --- /dev/null +++ b/basctl/source/inc/BasicColorConfig.hxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include "colorscheme.hxx" +#include "iderid.hxx" +#include + +namespace basctl +{ +// Name used to refer to the application color scheme (the one defined in Application Colors) +inline constexpr OUString DEFAULT_SCHEME = u"COLORSCHEME_DEFAULT"_ustr; + +typedef std::map SchemeTranslateIdMap; + +class BasicColorConfig : public utl::ConfigItem +{ +private: + // Name of the color scheme that is currently active + OUString m_sCurrentColorScheme; + + // Names of all available scheme names + css::uno::Sequence m_aSchemeNames; + + // Names of default color schemes shipped with LibreOffice + css::uno::Sequence m_aDefaultSchemes + = { "COLORSCHEME_LIBREOFFICE_LIGHT", "COLORSCHEME_LIBREOFFICE_DARK", + "COLORSCHEME_BREEZE_LIGHT", "COLORSCHEME_BREEZE_DARK", + "COLORSCHEME_SOLARIZED_LIGHT", "COLORSCHEME_SOLARIZED_DARK" }; + + // Maps the scheme names to their TranslateId + SchemeTranslateIdMap m_aTranslateIdsMap = { + { "COLORSCHEME_LIBREOFFICE_LIGHT", RID_STR_COLORSCHEME_LIGHT }, + { "COLORSCHEME_LIBREOFFICE_DARK", RID_STR_COLORSCHEME_DARK }, + { "COLORSCHEME_BREEZE_LIGHT", RID_STR_COLORSCHEME_BREEZE_LIGHT }, + { "COLORSCHEME_BREEZE_DARK", RID_STR_COLORSCHEME_BREEZE_DARK }, + { "COLORSCHEME_SOLARIZED_LIGHT", RID_STR_COLORSCHEME_SOLARIZED_LIGHT }, + { "COLORSCHEME_SOLARIZED_DARK", RID_STR_COLORSCHEME_SOLARIZED_DARK }, + }; + + // Used to get colors defined in the Appliation Colors dialog + const svtools::ColorConfig aColorConfig; + + virtual void ImplCommit() override; + +public: + BasicColorConfig(); + virtual ~BasicColorConfig() override; + + virtual void Notify(const css::uno::Sequence& aPropertyNames) override; + + ColorScheme GetColorScheme(const OUString& rScheme); + css::uno::Sequence GetColorSchemeNames() { return m_aSchemeNames; } + + // Returns the color scheme defined by the current Application Colors + ColorScheme GetAutomaticColorScheme(); + + // Returns the name of the currently active color scheme + OUString& GetCurrentColorSchemeName(); + + // Returns the current color scheme + ColorScheme GetCurrentColorScheme() { return GetColorScheme(GetCurrentColorSchemeName()); } + + // Returns true if the scheme is a scheme preinstalled with LO + bool IsDefaultScheme(const OUString& rScheme) + { + return comphelper::findValue(m_aDefaultSchemes, rScheme) != -1; + } + + // Returns the TranslateId of the scheme name + TranslateId GetSchemeTranslateId(const OUString& rScheme); +}; + +} // namespace basctl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basctl/source/inc/ColorSchemeDialog.hxx b/basctl/source/inc/ColorSchemeDialog.hxx new file mode 100644 index 000000000000..617121206e9c --- /dev/null +++ b/basctl/source/inc/ColorSchemeDialog.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include +#include + +namespace basctl +{ +class ModulWindowLayout; +class BasicColorConfig; + +class ColorSchemeDialog : public weld::GenericDialogController +{ +private: + VclPtr m_pModulWinLayout; + OUString m_sSelectedSchemeId; + + std::unique_ptr m_xSchemeList; + std::unique_ptr m_xUseAppCollors; + std::unique_ptr m_xUseScheme; + std::unique_ptr m_xOk; + std::shared_ptr m_pColorConfig; + + void Init(); + + DECL_LINK(BtnOkHdl, weld::Button&, void); + DECL_LINK(OptionHdl, weld::Toggleable&, void); + DECL_LINK(SelectHdl, weld::TreeView&, void); + +public: + ColorSchemeDialog(weld::Window* pParent, VclPtr pModulWinLayout); + virtual ~ColorSchemeDialog() override; + + const OUString& GetColorSchemeId() { return m_sSelectedSchemeId; } +}; + +} // namespace basctl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basctl/source/inc/basidesh.hxx b/basctl/source/inc/basidesh.hxx index f907abe6f214..afaa47c88ff4 100644 --- a/basctl/source/inc/basidesh.hxx +++ b/basctl/source/inc/basidesh.hxx @@ -54,6 +54,7 @@ class DialogWindowLayout; class TabBar; class BaseWindow; class LocalizationMgr; +class BasicColorConfig; class Shell : public SfxViewShell, @@ -81,6 +82,9 @@ private: VclPtr pTabBar; // basctl::TabBar bool bCreatingWindow; + // Basic editor color configuration + std::shared_ptr m_aColorConfig; + // layout windows VclPtr pModulLayout; VclPtr pDialogLayout; @@ -220,6 +224,8 @@ public: void UpdateObjectCatalog () { aObjectCatalog->UpdateEntries(); } void RemoveWindow (BaseWindow* pWindow, bool bDestroy, bool bAllowChangeCurWindow = true); + + const std::shared_ptr& GetColorConfig() const { return m_aColorConfig; } }; } // namespace basctl diff --git a/basctl/source/inc/colorscheme.hxx b/basctl/source/inc/colorscheme.hxx new file mode 100644 index 000000000000..5f7514febe3c --- /dev/null +++ b/basctl/source/inc/colorscheme.hxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include + +namespace basctl +{ +// Defines a single color scheme +typedef struct +{ + OUString m_sSchemeName; + bool m_bIsDefault; + Color m_aGenericFontColor; + Color m_aIdentifierColor; + Color m_aNumberColor; + Color m_aStringColor; + Color m_aCommentColor; + Color m_aErrorColor; + Color m_aOperatorColor; + Color m_aKeywordColor; + Color m_aBackgroundColor; +} ColorScheme; + +} // namespace basctl + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basctl/uiconfig/basicide/menubar/menubar.xml b/basctl/uiconfig/basicide/menubar/menubar.xml index fc510571e2fe..d649f968c8d9 100644 --- a/basctl/uiconfig/basicide/menubar/menubar.xml +++ b/basctl/uiconfig/basicide/menubar/menubar.xml @@ -65,6 +65,7 @@ + diff --git a/basctl/uiconfig/basicide/ui/colorscheme.ui b/basctl/uiconfig/basicide/ui/colorscheme.ui new file mode 100644 index 000000000000..709f946d854a --- /dev/null +++ b/basctl/uiconfig/basicide/ui/colorscheme.ui @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + False + 6 + Color Scheme + False + dialog + + + False + vertical + 12 + + + False + end + + + _Help + True + True + True + True + + + True + True + 0 + + + + + _OK + True + True + True + True + + + True + True + 1 + + + + + _Cancel + True + True + True + True + + + True + True + 2 + + + + + False + False + 2 + + + + + True + False + 0 + none + + + True + False + 12 + + + True + False + vertical + + + Use Application Colors + True + True + False + True + True + + + False + True + 0 + + + + + Choose Color Scheme + True + True + False + True + True + opt_appcolors + + + False + True + 1 + + + + + + + + + True + False + Basic IDE Color Options + + + + + False + True + 0 + + + + + True + False + 6 + 6 + 6 + 6 + 0 + none + + + True + False + 12 + + + True + True + True + True + in + + + True + True + True + True + liststore1 + False + False + 0 + False + + + + + + + + + + + + + + + + + + + True + False + 6 + Color Schemes + + + + + False + True + 1 + + + + + + btn_help + btn_ok + btn_cancel + + + diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index 3e1775788dc2..4748ff139e75 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -669,6 +669,7 @@ class SvxZoomItem; #define SID_BASICIDE_CURRENT_ZOOM TypedWhichId( SID_BASICIDE_START + 54 ) #define SID_BASICIDE_WATCH TypedWhichId( SID_BASICIDE_START + 55 ) #define SID_BASICIDE_STACK TypedWhichId( SID_BASICIDE_START + 56 ) +#define SID_BASICIDE_COLOR_SCHEME_DLG ( SID_BASICIDE_START + 57 ) #define SID_OPTIONS_TREEDIALOG ( SID_BASICIDE_START + 862) // SlotIds for Apps -------------------------------------------------------- diff --git a/officecfg/registry/data/org/openoffice/Office/BasicIDE.xcu b/officecfg/registry/data/org/openoffice/Office/BasicIDE.xcu index fc401938cbcc..0448b5570987 100644 --- a/officecfg/registry/data/org/openoffice/Office/BasicIDE.xcu +++ b/officecfg/registry/data/org/openoffice/Office/BasicIDE.xcu @@ -18,4 +18,288 @@ --> + + + + + 0 + + + + + 32768 + + + + + 16711680 + + + + + 16711680 + + + + + 8421504 + + + + + 16711680 + + + + + 128 + + + + + 128 + + + + + 16777215 + + + + + + + 16777215 + + + + + 14543051 + + + + + 16754342 + + + + + 16754342 + + + + + 15658734 + + + + + 16726072 + + + + + 11847644 + + + + + 11847644 + + + + + 0 + + + + + + + 2038811 + + + + + 2038811 + + + + + 11567104 + + + + + 12518147 + + + + + 9144455 + + + + + 12518147 + + + + + 13263050 + + + + + 22446 + + + + + 16777215 + + + + + + + 11974316 + + + + + 13619134 + + + + + 15822859 + + + + + 15814479 + + + + + 8358783 + + + + + 15814479 + + + + + 4161624 + + + + + 2719383 + + + + + 2303529 + + + + + + + 6650755 + + + + + 6650755 + + + + + 3252632 + + + + + 3252632 + + + + + 9675169 + + + + + 14430772 + + + + + 8755456 + + + + + 8755456 + + + + + 16643811 + + + + + + + 8623254 + + + + + 8623254 + + + + + 2793880 + + + + + 2793880 + + + + + 5664373 + + + + + 14430767 + + + + + 8755456 + + + + + 8755456 + + + + + 11062 + + + + diff --git a/officecfg/registry/data/org/openoffice/Office/UI/BasicIDECommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/BasicIDECommands.xcu index 739ad7bc1921..97832553e20f 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/BasicIDECommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/BasicIDECommands.xcu @@ -99,6 +99,14 @@ Hide + + + Color Scheme... + + + 1 + + diff --git a/officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs b/officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs index 94f108c179bf..0a17b5f2d75b 100644 --- a/officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/BasicIDE.xcs @@ -21,6 +21,103 @@ Contains configuration for the BASIC IDE. + + + + Defines the templates for color schemes used in the Basic IDE code editor. + + + + Specifies the formatting used for unknown tokens. + + + + Specifies the color used for unknown tokens. + + + + + + Specifies the formatting used for identifier tokens. + + + + Specifies the color used for identifier tokens. + + + + + + Specifies the formatting used for numbers. + + + + Specifies the color used for numbers. + + + + + + Specifies the formatting used for strings. + + + + Specifies the color used for strings. + + + + + + Specifies the formatting used for comments. + + + + Specifies the color used for comments. + + + + + + Specifies the formatting used for errors. + + + + Specifies the color used for errors. + + + + + + Specifies the formatting used for operators. + + + + Specifies the color used for operators. + + + + + + Specifies the formatting used for keywords. + + + + Specifies the color used for keywords. + + + + + + Specifies the settings for the editor's background color. + + + + Specifies the color used for the editor's background. + + + + + @@ -64,15 +161,26 @@ + + Contains user configuration. + + - Contains user configuration. + Sets the line numbering on/off. Default is true. - - - Sets the line numbering on/off. Default is true. - - true - + true + + + + Name of the selected color scheme used in the Basic IDE. + + COLORSCHEME_DEFAULT + + + + Lists entries with color settings. + + diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi index fad6109d6add..4b52f73fb9fa 100644 --- a/svx/sdi/svx.sdi +++ b/svx/sdi/svx.sdi @@ -11197,6 +11197,23 @@ SfxVoidItem InsertNarrowNobreakSpace FN_INSERT_NNBSP GroupId = SfxGroupId::Insert; ] +SfxVoidItem BasicColorSchemeDialog SID_BASICIDE_COLOR_SCHEME_DLG +() +[ + AutoUpdate = FALSE, + FastCall = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + + AccelConfig = TRUE, + MenuConfig = TRUE, + ToolBoxConfig = TRUE, + GroupId = SfxGroupId::Controls; +] + SfxVoidItem ManageLanguage SID_BASICIDE_MANAGE_LANG () [