Kaydet (Commit) 33226614 authored tarafından tagezi's avatar tagezi Kaydeden (comit) Mike Kaganski

tdf#94498 add repeat search in Basic IDE by shortcut

additionally deduplicate code and remove unnecessary abstraction

Change-Id: Ib826b5cac74e95ce4ae8d02368b0983eb4942b29
Reviewed-on: https://gerrit.libreoffice.org/52027Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst e82eeca6
......@@ -99,30 +99,45 @@ shell basctl_Shell
StateMethod = GetState;
]
SID_SEARCH_OPTIONS
SID_GOTOLINE
[
ExecMethod = ExecuteCurrent;
StateMethod = GetState;
]
SID_SEARCH_ITEM
// Search in IDE Basic
SID_SEARCH_OPTIONS
[
ExecMethod = ExecuteCurrent;
ExecMethod = ExecuteSearch;
StateMethod = GetState;
]
SID_GOTOLINE
SID_SEARCH_ITEM
[
ExecMethod = ExecuteCurrent;
ExecMethod = ExecuteSearch;
StateMethod = GetState;
]
FID_SEARCH_NOW
[
ExecMethod = ExecuteCurrent;
ExecMethod = ExecuteSearch;
StateMethod = GetState;
]
SID_BASICIDE_REPEAT_SEARCH
[
ExecMethod = ExecuteSearch;
StateMethod = GetState;
]
FID_SEARCH_ON // status()
[
ExecMethod = ExecuteSearch;
Export = FALSE;
]
FID_SEARCH_OFF
[
ExecMethod = ExecuteCurrent;
......
......@@ -44,7 +44,6 @@
#include <svx/svxids.hrc>
#include <svl/aeitem.hxx>
#include <svl/intitem.hxx>
#include <svl/srchitem.hxx>
#include <svl/visitem.hxx>
#include <svl/whiter.hxx>
#include <vcl/xtextedt.hxx>
......@@ -58,40 +57,56 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::frame;
void Shell::ExecuteCurrent( SfxRequest& rReq )
void Shell::ExecuteSearch( SfxRequest& rReq )
{
if ( !pCurWin )
return;
switch ( rReq.GetSlot() )
const SfxItemSet* pArgs = rReq.GetArgs();
sal_uInt16 nSlot = rReq.GetSlot();
// if searching has not been done before this time
if (nSlot == SID_BASICIDE_REPEAT_SEARCH && !mpSearchItem)
{
case SID_BASICIDE_HIDECURPAGE:
{
pCurWin->StoreData();
RemoveWindow( pCurWin, false );
}
break;
case SID_BASICIDE_RENAMECURRENT:
{
pTabBar->StartEditMode( pTabBar->GetCurPageId() );
}
break;
rReq.SetReturnValue(SfxBoolItem(nSlot, false));
nSlot = 0;
}
switch ( nSlot )
{
case SID_SEARCH_OPTIONS:
break;
case SID_SEARCH_ITEM:
mpSearchItem.reset( static_cast<SvxSearchItem*>( pArgs->Get(SID_SEARCH_ITEM).Clone() ));
break;
case FID_SEARCH_ON:
mbJustOpened = true;
GetViewFrame()->GetBindings().Invalidate(SID_SEARCH_ITEM);
break;
case SID_BASICIDE_REPEAT_SEARCH:
case FID_SEARCH_NOW:
{
if (!pCurWin->HasActiveEditor())
break;
DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
SfxItemSet const& rArgs = *rReq.GetArgs();
// unfortunately I don't know the ID:
sal_uInt16 nWhich = rArgs.GetWhichByPos( 0 );
DBG_ASSERT( nWhich, "Which for SearchItem?" );
SfxPoolItem const& rItem = rArgs.Get(nWhich);
DBG_ASSERT(dynamic_cast<SvxSearchItem const*>(&rItem), "no searchitem!");
SvxSearchItem const& rSearchItem = static_cast<SvxSearchItem const&>(rItem);
// memorize item because of the adjustments...
GetExtraData()->SetSearchItem(rSearchItem);
// If it is a repeat searching
if ( nSlot == SID_BASICIDE_REPEAT_SEARCH )
{
if( !mpSearchItem )
mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEM ));
}
else
{
// Get SearchItem from request if it is the first searching
if ( pArgs )
{
mpSearchItem.reset( static_cast<SvxSearchItem*>( pArgs->Get( SID_SEARCH_ITEM ).Clone() ));
}
}
sal_Int32 nFound = 0;
if (rSearchItem.GetCommand() == SvxSearchCmd::REPLACE_ALL)
if ( mpSearchItem->GetCommand() == SvxSearchCmd::REPLACE_ALL )
{
sal_uInt16 nActModWindows = 0;
for (auto const& window : aWindowTable)
......@@ -116,11 +131,11 @@ void Shell::ExecuteCurrent( SfxRequest& rReq )
for (auto const& window : aWindowTable)
{
BaseWindow* pWin = window.second;
nFound += pWin->StartSearchAndReplace(rSearchItem);
nFound += pWin->StartSearchAndReplace( *mpSearchItem );
}
}
else
nFound = pCurWin->StartSearchAndReplace(rSearchItem);
nFound = pCurWin->StartSearchAndReplace( *mpSearchItem );
OUString aReplStr(IDEResId(RID_STR_SEARCHREPLACES));
aReplStr = aReplStr.replaceAll("XX", OUString::number(nFound));
......@@ -133,8 +148,8 @@ void Shell::ExecuteCurrent( SfxRequest& rReq )
else
{
bool bCanceled = false;
nFound = pCurWin->StartSearchAndReplace(rSearchItem);
if ( !nFound && !rSearchItem.GetSelection() )
nFound = pCurWin->StartSearchAndReplace( *mpSearchItem );
if ( !nFound && !mpSearchItem->GetSelection() )
{
// search other modules...
bool bChangeCurWindow = false;
......@@ -176,7 +191,7 @@ void Shell::ExecuteCurrent( SfxRequest& rReq )
{
if ( pCurWin )
pWin->SetSizePixel( pCurWin->GetSizePixel() );
nFound = pWin->StartSearchAndReplace(rSearchItem, true);
nFound = pWin->StartSearchAndReplace( *mpSearchItem, true );
}
if ( nFound )
{
......@@ -194,7 +209,7 @@ void Shell::ExecuteCurrent( SfxRequest& rReq )
pWin = nullptr;
}
if ( !nFound && bSearchedFromStart )
nFound = pCurWin->StartSearchAndReplace(rSearchItem, true);
nFound = pCurWin->StartSearchAndReplace( *mpSearchItem, true );
if ( bChangeCurWindow )
SetCurWindow( pWin, true );
}
......@@ -208,6 +223,29 @@ void Shell::ExecuteCurrent( SfxRequest& rReq )
}
rReq.Done();
break;
}
default:
pCurWin->ExecuteCommand( rReq );
}
}
void Shell::ExecuteCurrent( SfxRequest& rReq )
{
if ( !pCurWin )
return;
switch ( rReq.GetSlot() )
{
case SID_BASICIDE_HIDECURPAGE:
{
pCurWin->StoreData();
RemoveWindow( pCurWin, false );
}
break;
case SID_BASICIDE_RENAMECURRENT:
{
pTabBar->StartEditMode( pTabBar->GetCurPageId() );
}
break;
case SID_UNDO:
......@@ -889,10 +927,27 @@ void Shell::GetState(SfxItemSet &rSet)
break;
case SID_SEARCH_ITEM:
{
OUString aSelected = GetSelectionText(true);
SvxSearchItem& rItem = GetExtraData()->GetSearchItem();
rItem.SetSearchString( aSelected );
rSet.Put( rItem );
if ( !mpSearchItem )
{
mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEM ));
mpSearchItem->SetSearchString( GetSelectionText( true ));
}
if ( mbJustOpened && HasSelection() )
{
OUString aText = GetSelectionText( true );
if ( !aText.isEmpty() )
{
mpSearchItem->SetSearchString( aText );
mpSearchItem->SetSelection( false );
}
else
mpSearchItem->SetSelection( true );
}
mbJustOpened = false;
rSet.Put( *mpSearchItem );
}
break;
case SID_BASICIDE_STAT_DATE:
......
......@@ -145,7 +145,6 @@ ExtraData* Dll::GetExtraData ()
ExtraData::ExtraData () :
pSearchItem(new SvxSearchItem(SID_SEARCH_ITEM)),
bChoosingMacro(false),
bShellInCriticalSection(false)
{
......@@ -163,11 +162,6 @@ ExtraData::~ExtraData ()
// StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() );
}
void ExtraData::SetSearchItem (const SvxSearchItem& rItem)
{
pSearchItem.reset(static_cast<SvxSearchItem*>(rItem.Clone()));
}
IMPL_STATIC_LINK(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic, BasicDebugFlags)
{
BasicDebugFlags nRet = BasicDebugFlags::NONE;
......
......@@ -34,8 +34,6 @@ namespace basctl
class ExtraData final
{
std::unique_ptr<SvxSearchItem> pSearchItem;
LibInfo aLibInfo;
EntryDescriptor m_aLastEntryDesc;
......@@ -60,9 +58,6 @@ public:
bool& ChoosingMacro() { return bChoosingMacro; }
bool& ShellInCriticalSection() { return bShellInCriticalSection; }
SvxSearchItem& GetSearchItem() const { return *pSearchItem; }
void SetSearchItem( const SvxSearchItem& rItem );
const OUString& GetAddLibPath() const { return aAddLibPath; }
void SetAddLibPath( const OUString& rPath ) { aAddLibPath = rPath; }
......
......@@ -26,6 +26,7 @@
#include <com/sun/star/container/XContainerListener.hpp>
#include <sfx2/viewsh.hxx>
#include <svx/ifaceids.hxx>
#include <svl/srchitem.hxx>
#include <vcl/scrbar.hxx>
#include <map>
#include <memory>
......@@ -61,30 +62,34 @@ private:
friend class LocalizationMgr;
friend bool implImportDialog(weld::Window* pWin, const OUString& rCurPath, const ScriptDocument& rDocument, const OUString& rLibName); // defined in baside3.cxx
WindowTable aWindowTable;
WindowTable aWindowTable;
sal_uInt16 nCurKey;
VclPtr<BaseWindow> pCurWin;
VclPtr<BaseWindow> pCurWin;
ScriptDocument m_aCurDocument;
OUString m_aCurLibName;
std::shared_ptr<LocalizationMgr> m_pCurLocalizationMgr;
VclPtr<ScrollBar> aHScrollBar;
VclPtr<ScrollBar> aVScrollBar;
VclPtr<ScrollBarBox> aScrollBarBox;
VclPtr<TabBar> pTabBar; // basctl::TabBar
bool bCreatingWindow;
VclPtr<ScrollBar> aHScrollBar;
VclPtr<ScrollBar> aVScrollBar;
VclPtr<ScrollBarBox> aScrollBarBox;
VclPtr<TabBar> pTabBar; // basctl::TabBar
bool bCreatingWindow;
// layout windows
VclPtr<ModulWindowLayout> pModulLayout;
VclPtr<DialogWindowLayout> pDialogLayout;
// the active layout window
VclPtr<Layout> pLayout;
VclPtr<ModulWindowLayout> pModulLayout;
VclPtr<DialogWindowLayout> pDialogLayout;
VclPtr<Layout> pLayout; // the active layout window
// common object catalog window
VclPtr<ObjectCatalog> aObjectCatalog;
VclPtr<ObjectCatalog> aObjectCatalog;
bool m_bAppBasicModified;
bool mbJustOpened = false;
bool m_bAppBasicModified;
DocumentEventNotifier m_aNotifier;
friend class ContainerListenerImpl;
css::uno::Reference< css::container::XContainerListener > m_xLibListener;
std::unique_ptr<SvxSearchItem> mpSearchItem;
void Init();
void InitTabBar();
......@@ -170,6 +175,7 @@ public:
void GetState( SfxItemSet& );
void ExecuteGlobal( SfxRequest& rReq );
void ExecuteSearch( SfxRequest& rReq );
void ExecuteCurrent( SfxRequest& rReq );
void ExecuteBasic( SfxRequest& rReq );
void ExecuteDialog( SfxRequest& rReq );
......
......@@ -554,6 +554,7 @@ class SfxDocumentInfoItem;
#define FID_SVX_START (SID_LIB_START + 500)
#define FID_SEARCH_NOW (FID_SVX_START + 2)
#define SID_BASICIDE_REPEAT_SEARCH (FID_SVX_START + 3)
// SlotIds for Basic -------------------------------------------------------
#define SID_BASICIDE_TOGGLEBRKPNT ( SID_BASICIDE_START + 0 )
......
......@@ -8,6 +8,11 @@
<value xml:lang="en-US">Go to Line...</value>
</prop>
</node>
<node oor:name=".uno:RepeatSearch" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Repeat Search</value>
</prop>
</node>
<node oor:name=".uno:ShowLines" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Line Numbers</value>
......
......@@ -1160,6 +1160,24 @@ SfxVoidItem ExecuteSearch FID_SEARCH_NOW
]
SfxVoidItem RepeatSearch SID_BASICIDE_REPEAT_SEARCH
(SvxSearchItem SearchItem SID_SEARCH_ITEM, SfxBoolItem Quiet SID_SEARCH_QUIET)
[
AutoUpdate = FALSE,
FastCall = TRUE,
ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
Asynchron;
AccelConfig = TRUE,
MenuConfig = TRUE,
ToolBoxConfig = TRUE,
GroupId = SfxGroupId::Edit;
]
SfxBoolItem ExtendedHelp SID_EXTENDEDHELP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment