summaryrefslogtreecommitdiff
path: root/basctl/source/basicide/baside2.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'basctl/source/basicide/baside2.cxx')
-rw-r--r--basctl/source/basicide/baside2.cxx242
1 files changed, 165 insertions, 77 deletions
diff --git a/basctl/source/basicide/baside2.cxx b/basctl/source/basicide/baside2.cxx
index c7f99e8b8e03..62bbaa799815 100644
--- a/basctl/source/basicide/baside2.cxx
+++ b/basctl/source/basicide/baside2.cxx
@@ -25,7 +25,9 @@
#include <iderdll.hxx>
#include <iderid.hxx>
#include "moduldlg.hxx"
+#include <sfx2/dispatch.hxx>
#include <docsignature.hxx>
+#include <colorscheme.hxx>
#include <officecfg/Office/BasicIDE.hxx>
#include <helpids.h>
@@ -38,7 +40,7 @@
#include <com/sun/star/script/ModuleType.hpp>
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
-#include <com/sun/star/ui/dialogs/FilePicker.hpp>
+#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#include <comphelper/SetFlagContextHelper.hxx>
#include <comphelper/string.hxx>
@@ -56,6 +58,7 @@
#include <svl/whiter.hxx>
#include <svx/svxids.hrc>
#include <tools/debug.hxx>
+#include <utility>
#include <vcl/locktoplevels.hxx>
#include <vcl/errinf.hxx>
#include <vcl/event.hxx>
@@ -68,6 +71,7 @@
#include <cassert>
#include <osl/diagnose.h>
#include <officecfg/Office/Common.hxx>
+#include <BasicColorConfig.hxx>
namespace basctl
{
@@ -94,7 +98,7 @@ short const ValidWindow = 0x1234;
#if defined(OW) || defined(MTF)
char const FilterMask_All[] = "*";
#else
-constexpr OUStringLiteral FilterMask_All = u"*.*";
+constexpr OUString FilterMask_All = u"*.*"_ustr;
#endif
} // end anonymous namespace
@@ -182,7 +186,7 @@ void lcl_ConvertTabsToSpaces( OUString& rLine )
OUStringBuffer aBlanker;
string::padToLength(aBlanker, ( 4 - ( nPos % 4 ) ), ' ');
aResult.remove( nPos, 1 );
- aResult.insert( nPos, aBlanker.makeStringAndClear() );
+ aResult.insert( nPos, aBlanker );
nMax = aResult.getLength();
}
++nPos;
@@ -193,13 +197,16 @@ void lcl_ConvertTabsToSpaces( OUString& rLine )
} // namespace
ModulWindow::ModulWindow (ModulWindowLayout* pParent, ScriptDocument const& rDocument,
- const OUString& aLibName, const OUString& aName, OUString const & aModule)
+ const OUString& aLibName, const OUString& aName, OUString aModule)
: BaseWindow(pParent, rDocument, aLibName, aName)
, m_rLayout(*pParent)
, m_nValid(ValidWindow)
, m_aXEditorWindow(VclPtr<ComplexEditorWindow>::Create(this))
- , m_aModule(aModule)
+ , m_aModule(std::move(aModule))
{
+ // Active editor color scheme
+ m_sWinColorScheme = GetShell()->GetColorConfig()->GetCurrentColorSchemeName();
+
m_aXEditorWindow->Show();
SetBackground();
}
@@ -254,9 +261,6 @@ void ModulWindow::GetFocus()
void ModulWindow::DoInit()
{
- if (GetVScrollBar())
- GetVScrollBar()->Hide();
- GetHScrollBar()->Show();
GetEditorWindow().InitScrollBars();
}
@@ -284,7 +288,7 @@ void ModulWindow::CheckCompileBasic()
bool bDone = false;
- GetShell()->GetViewFrame()->GetWindow().EnterWait();
+ GetShell()->GetViewFrame().GetWindow().EnterWait();
AssertValidEditEngine();
GetEditorWindow().SetSourceInBasic();
@@ -304,7 +308,7 @@ void ModulWindow::CheckCompileBasic()
GetBreakPoints().SetBreakPointsInBasic( m_xModule.get() );
}
- GetShell()->GetViewFrame()->GetWindow().LeaveWait();
+ GetShell()->GetViewFrame().GetWindow().LeaveWait();
m_aStatus.bError = !bDone;
m_aStatus.bIsRunning = false;
@@ -444,7 +448,7 @@ void ModulWindow::LoadBasic()
GetEditorWindow().PaintImmediately();
GetEditorWindow().ForceSyntaxTimeout();
GetEditorWindow().DestroyProgress();
- ErrCode nError = aMedium.GetError();
+ ErrCodeMsg nError = aMedium.GetErrorIgnoreWarning();
if ( nError )
ErrorHandler::HandleError( nError );
}
@@ -459,17 +463,12 @@ void ModulWindow::LoadBasic()
void ModulWindow::SaveBasicSource()
{
- Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
- sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD,
+ sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
FileDialogFlags::NONE, this->GetFrameWeld());
aDlg.SetContext(sfx2::FileDialogHelper::BasicExportSource);
const Reference<XFilePicker3>& xFP = aDlg.GetFilePicker();
- Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
- xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false);
- Any aValue;
- aValue <<= true;
- xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
+ xFP.queryThrow<XFilePickerControlAccess>()->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, Any(true));
xFP->appendFilter( "BASIC", "*.bas" );
xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All );
@@ -491,7 +490,7 @@ void ModulWindow::SaveBasicSource()
GetEditEngine()->Write( *pStream );
aMedium.Commit();
LeaveWait();
- ErrCode nError = aMedium.GetError();
+ ErrCodeMsg nError = aMedium.GetErrorIgnoreWarning();
if ( nError )
ErrorHandler::HandleError( nError );
}
@@ -615,7 +614,7 @@ void ModulWindow::ManageBreakPoints()
void ModulWindow::BasicErrorHdl( StarBASIC const * pBasic )
{
- GetShell()->GetViewFrame()->ToTop();
+ GetShell()->GetViewFrame().ToTop();
// Return value: BOOL
// FALSE: cancel
@@ -1029,12 +1028,15 @@ void ModulWindow::ExecuteCommand (SfxRequest& rReq)
break;
case SID_GOTOLINE:
{
- GotoLineDialog aGotoDlg(GetFrameWeld());
+ sal_uInt32 nCurLine = GetEditView()->GetSelection().GetStart().GetPara() + 1;
+ sal_uInt32 nLineCount = GetEditEngine()->GetParagraphCount();
+ GotoLineDialog aGotoDlg(GetFrameWeld(), nCurLine, nLineCount);
if (aGotoDlg.run() == RET_OK)
{
if (sal_Int32 const nLine = aGotoDlg.GetLineNumber())
{
TextSelection const aSel(TextPaM(nLine - 1, 0), TextPaM(nLine - 1, 0));
+ GrabFocus();
GetEditView()->SetSelection(aSel);
}
}
@@ -1058,6 +1060,18 @@ void ModulWindow::ExecuteGlobal (SfxRequest& rReq)
}
}
break;
+
+ case SID_BASICIDE_STAT_POS:
+ {
+ GetDispatcher()->Execute(SID_GOTOLINE);
+ }
+ break;
+
+ case SID_TOGGLE_COMMENT:
+ {
+ GetEditView()->ToggleComment();
+ }
+ break;
}
}
@@ -1133,6 +1147,9 @@ void ModulWindow::GetState( SfxItemSet &rSet )
if (!sProcName.isEmpty())
aTitle += "." + sProcName;
+ if (IsReadOnly())
+ aTitle += " (" + IDEResId(RID_STR_READONLY) + ")";
+
SfxStringItem aTitleItem( SID_BASICIDE_STAT_TITLE, aTitle );
rSet.Put( aTitleItem );
}
@@ -1164,7 +1181,7 @@ void ModulWindow::GetState( SfxItemSet &rSet )
}
}
-void ModulWindow::DoScroll( ScrollBar* pCurScrollBar )
+void ModulWindow::DoScroll( Scrollable* pCurScrollBar )
{
if ( ( pCurScrollBar == GetHScrollBar() ) && GetEditView() )
{
@@ -1381,12 +1398,7 @@ bool ModulWindow::IsPasteAllowed()
if ( xClipboard.is() )
{
- Reference< datatransfer::XTransferable > xTransf;
- {
- SolarMutexReleaser aReleaser;
- // get clipboard content
- xTransf = xClipboard->getContents();
- }
+ Reference< datatransfer::XTransferable > xTransf = xClipboard->getContents();
if ( xTransf.is() )
{
datatransfer::DataFlavor aFlavor;
@@ -1405,7 +1417,7 @@ void ModulWindow::OnNewDocument ()
m_aXEditorWindow->SetLineNumberDisplay(bLineNumbers);
}
-OString ModulWindow::GetHid () const
+OUString ModulWindow::GetHid () const
{
return HID_BASICIDE_MODULWINDOW;
}
@@ -1437,13 +1449,43 @@ void ModulWindow::UpdateModule ()
MarkDocumentModified(m_aDocument);
}
+void ModulWindow::SetEditorColorScheme(const OUString& rColorScheme)
+{
+ m_sWinColorScheme = rColorScheme;
+ EditorWindow& rEditWindow = GetEditorWindow();
+ Wallpaper aBackgroundColor(GetLayout().GetSyntaxBackgroundColor());
+ rEditWindow.SetBackground(aBackgroundColor);
+ rEditWindow.GetWindow(GetWindowType::Border)->SetBackground(aBackgroundColor);
+ rEditWindow.SetLineHighlightColor(GetShell()->GetColorConfig()->GetColorScheme(rColorScheme).m_aLineHighlightColor);
+
+ // 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<WatchWindow>::Create(this)),
aStackWindow(VclPtr<StackWindow>::Create(this)),
rObjectCatalog(rObjectCatalog_)
-{ }
+{
+ // Get active color scheme from the registry
+ m_sColorSchemeId = GetShell()->GetColorConfig()->GetCurrentColorSchemeName();
+ aSyntaxColors.ApplyColorScheme(m_sColorSchemeId, true);
+
+ // Initialize the visibility of the Stack Window
+ bool bStackVisible = ::officecfg::Office::BasicIDE::EditorSettings::StackWindow::get();
+ if (!bStackVisible)
+ aStackWindow->Show(bStackVisible);
+
+ // Initialize the visibility of the Watched Expressions window
+ bool bWatchVisible = ::officecfg::Office::BasicIDE::EditorSettings::WatchWindow::get();
+ if (!bWatchVisible)
+ aWatchWindow->Show(bWatchVisible);
+}
ModulWindowLayout::~ModulWindowLayout()
{
@@ -1480,6 +1522,7 @@ void ModulWindowLayout::Activating (BaseWindow& rChild)
rObjectCatalog.UpdateEntries();
Layout::Activating(rChild);
aSyntaxColors.SetActiveEditor(&pChild->GetEditorWindow());
+ aSyntaxColors.SetActiveColorSchemeId(m_sColorSchemeId);
}
void ModulWindowLayout::Deactivating ()
@@ -1516,6 +1559,18 @@ void ModulWindowLayout::BasicRemoveWatch ()
aWatchWindow->RemoveSelectedWatch();
}
+void ModulWindowLayout::ShowWatchWindow(bool bVisible)
+{
+ aWatchWindow->Show(bVisible);
+ ArrangeWindows();
+}
+
+void ModulWindowLayout::ShowStackWindow(bool bVisible)
+{
+ aStackWindow->Show(bVisible);
+ ArrangeWindows();
+}
+
void ModulWindowLayout::OnFirstSize (tools::Long const nWidth, tools::Long const nHeight)
{
AddToLeft(&rObjectCatalog, Size(nWidth * 0.20, nHeight * 0.75));
@@ -1523,12 +1578,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(const OUString& rSchemeId)
{
- aConfig.AddListener(this);
+ // Apply new color scheme to the UI
+ m_sColorSchemeId = rSchemeId;
+ aSyntaxColors.ApplyColorScheme(m_sColorSchemeId, false);
+}
- NewConfig(true);
+ModulWindowLayout::SyntaxColors::SyntaxColors ()
+ : pEditor(nullptr)
+{
+ aConfig.AddListener(this);
}
ModulWindowLayout::SyntaxColors::~SyntaxColors ()
@@ -1539,62 +1601,88 @@ 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::DOCCOLOR).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->SetLineHighlightColor(aColorScheme.m_aLineHighlightColor);
+ 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);
- }
-
- bool bChanged = false;
- for (unsigned i = 0; i != SAL_N_ELEMENTS(vIds); ++i)
- {
- Color const aColor = aConfig.GetColorValue(vIds[i].eEntry).nColor;
- Color& rMyColor = aColors[vIds[i].eTokenType];
- if (bFirst || aColor != rMyColor)
+ // Retrieves the new color to be set from the color scheme
+ Color aNewColor;
+ switch (aToken)
{
- rMyColor = aColor;
- bChanged = true;
+ 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;
}
- 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();
}