diff --git a/cui/source/dialogs/pastedlg.cxx b/cui/source/dialogs/pastedlg.cxx index f9d9a76318ab..375a966c7786 100644 --- a/cui/source/dialogs/pastedlg.cxx +++ b/cui/source/dialogs/pastedlg.cxx @@ -26,6 +26,8 @@ #include #include #include +#include +#include SvPasteObjectDialog::SvPasteObjectDialog(weld::Window* pParent) : GenericDialogController(pParent, "cui/ui/pastespecial.ui", "PasteSpecialDialog") @@ -70,6 +72,13 @@ void SvPasteObjectDialog::Insert( SotClipboardFormatId nFormat, const OUString& aSupplementMap.insert( std::make_pair( nFormat, rFormatName ) ); } +void SvPasteObjectDialog::InsertUno(const OUString& sCmd, const OUString& sLabel) +{ + aExtraCommand.first = sCmd; + aExtraCommand.second = sLabel; +} + + void SvPasteObjectDialog::PreGetFormat( const TransferableDataHelper &rHelper ) { //TODO/LATER: why is the Descriptor never used?! @@ -286,6 +295,11 @@ SotClipboardFormatId SvPasteObjectDialog::GetFormat( const TransferableDataHelpe } } + if (!aExtraCommand.first.isEmpty()) + { + ObjectLB().append(aExtraCommand.first, aExtraCommand.second); + } + ObjectLB().thaw(); SelectObject(); @@ -302,7 +316,15 @@ SotClipboardFormatId SvPasteObjectDialog::GetFormat( const TransferableDataHelpe if (run() == RET_OK) { - nSelFormat = static_cast(ObjectLB().get_selected_id().toUInt32()); + if (ObjectLB().get_selected_id().startsWithIgnoreAsciiCase(".uno")) + { + comphelper::dispatchCommand(aExtraCommand.first, {}); + nSelFormat = SotClipboardFormatId::NONE; + } + else + { + nSelFormat = static_cast(ObjectLB().get_selected_id().toUInt32()); + } } return nSelFormat; diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx index 600882742427..d7868049d4c7 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -533,6 +533,11 @@ void AbstractPasteDialog_Impl::Insert(SotClipboardFormatId nFormat, const OUStri m_xDlg->Insert(nFormat, rFormatName); } +void AbstractPasteDialog_Impl::InsertUno(const OUString& sCmd, const OUString& sLabel) +{ + m_xDlg->InsertUno(sCmd, sLabel); +} + void AbstractPasteDialog_Impl::SetObjName(const SvGlobalName & rClass, const OUString& rObjName) { m_xDlg->SetObjName(rClass, rObjName); diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx index 0181e293f49d..cd4b4d36a9dd 100644 --- a/cui/source/factory/dlgfact.hxx +++ b/cui/source/factory/dlgfact.hxx @@ -609,6 +609,7 @@ public: virtual bool StartExecuteAsync(AsyncContext &rCtx) override; public: virtual void Insert( SotClipboardFormatId nFormat, const OUString & rFormatName ) override; + virtual void InsertUno( const OUString & sCmd, const OUString& sLabel ) override; virtual void SetObjName( const SvGlobalName & rClass, const OUString & rObjName ) override; virtual void PreGetFormat( const TransferableDataHelper& aHelper ) override; virtual SotClipboardFormatId GetFormatOnly() override; diff --git a/cui/source/inc/pastedlg.hxx b/cui/source/inc/pastedlg.hxx index 565101d7fe19..a9a691b4f8f8 100644 --- a/cui/source/inc/pastedlg.hxx +++ b/cui/source/inc/pastedlg.hxx @@ -32,6 +32,8 @@ class TransferableDataHelper; class SvPasteObjectDialog : public weld::GenericDialogController { std::map< SotClipboardFormatId, OUString > aSupplementMap; + // Additional UNO command to be displayed along the supported paste formats + std::pair aExtraCommand; SvGlobalName aObjClassName; OUString aObjName; @@ -49,6 +51,7 @@ public: SvPasteObjectDialog(weld::Window* pParent); void Insert( SotClipboardFormatId nFormat, const OUString & rFormatName ); + void InsertUno( const OUString& sUnoCmd, const OUString& sLabel); void SetObjName( const SvGlobalName & rClass, const OUString & rObjName ); /** * @brief PreGetFormat Prepares the dialog for running to get format of paste as a SotClipboardFormatId value by calling GetFormatOnly() diff --git a/include/sfx2/sfxdlg.hxx b/include/sfx2/sfxdlg.hxx index b82db9001359..4515dc9266ca 100644 --- a/include/sfx2/sfxdlg.hxx +++ b/include/sfx2/sfxdlg.hxx @@ -91,6 +91,7 @@ protected: virtual ~SfxAbstractPasteDialog() override = default; public: virtual void Insert( SotClipboardFormatId nFormat, const OUString & rFormatName ) = 0; + virtual void InsertUno( const OUString& sCmd, const OUString& sLabel ) = 0; virtual void SetObjName( const SvGlobalName & rClass, const OUString & rObjName ) = 0; virtual void PreGetFormat( const TransferableDataHelper& aHelper ) = 0; virtual SotClipboardFormatId GetFormatOnly() = 0; diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index d7367587db1d..ff2854861930 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -428,6 +428,7 @@ class SvxSearchItem; #define SID_PASTE_ONLY_TEXT (SID_SFX_START + 802) #define SID_PASTE_ONLY_FORMULA (SID_SFX_START + 803) #define SID_PASTE_ONLY_VALUE (SID_SFX_START + 804) +#define SID_PASTE_TEXTIMPORT_DIALOG (SID_SFX_START + 805) // Used for redaction #define SID_SHAPE_NAME (SID_SFX_START + 808) diff --git a/include/vcl/commandinfoprovider.hxx b/include/vcl/commandinfoprovider.hxx index d4ae3a008bd2..da79c18b7ced 100644 --- a/include/vcl/commandinfoprovider.hxx +++ b/include/vcl/commandinfoprovider.hxx @@ -53,6 +53,8 @@ namespace vcl { namespace CommandInfoProvider { VCL_DLLPUBLIC OUString GetPopupLabelForCommand(const css::uno::Sequence& rProperties); + VCL_DLLPUBLIC OUString GetTooltipLabelForCommand(const css::uno::Sequence& rProperties); + /** Return a tooltip for the given command. Falls back to label if command has no tooltip. @param rsCommandName The command name is expected to start with .uno: diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu index 099c1f249d21..b83a5362535b 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu @@ -2564,6 +2564,17 @@ 1 + + + Use Text Import Dialog + + + Use text import dialog + + + 1 + + Column diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi index 4f2cd4d234b4..d5e936b06cf0 100644 --- a/sc/sdi/cellsh.sdi +++ b/sc/sdi/cellsh.sdi @@ -177,6 +177,7 @@ interface CellSelection SID_PASTE_ONLY_TEXT [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ] SID_PASTE_ONLY_FORMULA [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ] SID_PASTE_ONLY_VALUE [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ] + SID_PASTE_TEXTIMPORT_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ] SID_CLIPBOARD_FORMAT_ITEMS [ ExecMethod = ExecuteEdit; StateMethod = GetClipState; ] SID_EXTERNAL_SOURCE [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ] FID_MERGE_ON [ ExecMethod = Execute; StateMethod = GetState; ] diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index 493f3473c4db..ea7b3364d159 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -223,6 +223,7 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet ) case SID_PASTE_ONLY_VALUE: case SID_PASTE_ONLY_TEXT: case SID_PASTE_ONLY_FORMULA: + case SID_PASTE_TEXTIMPORT_DIALOG: bDisable = GetViewData()->SelectionForbidsCellFill(); break; @@ -528,6 +529,7 @@ IMPL_LINK( ScCellShell, ClipboardChanged, TransferableDataHelper*, pDataHelper, rBindings.Invalidate( SID_PASTE_ONLY_VALUE ); rBindings.Invalidate( SID_PASTE_ONLY_TEXT ); rBindings.Invalidate( SID_PASTE_ONLY_FORMULA ); + rBindings.Invalidate( SID_PASTE_TEXTIMPORT_DIALOG ); rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS ); } @@ -621,6 +623,7 @@ void ScCellShell::GetClipState( SfxItemSet& rSet ) rSet.DisableItem( SID_PASTE_ONLY_VALUE ); rSet.DisableItem( SID_PASTE_ONLY_TEXT ); rSet.DisableItem( SID_PASTE_ONLY_FORMULA ); + rSet.DisableItem( SID_PASTE_TEXTIMPORT_DIALOG ); rSet.DisableItem( SID_CLIPBOARD_FORMAT_ITEMS ); } else if ( rSet.GetItemState( SID_CLIPBOARD_FORMAT_ITEMS ) != SfxItemState::UNKNOWN ) diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 483f2e5f2d8c..547015996923 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,7 @@ #include #include #include +#include #include #include @@ -1493,6 +1495,56 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail break; } + case SID_PASTE_TEXTIMPORT_DIALOG: + { + vcl::Window* pWin = GetViewData()->GetActiveWin(); + TransferableDataHelper aDataHelper( + TransferableDataHelper::CreateFromSystemClipboard(pWin)); + const uno::Reference& xTransferable + = aDataHelper.GetTransferable(); + SotClipboardFormatId format = SotClipboardFormatId::STRING; + if (xTransferable.is() && HasClipboardFormat(format)) + { + auto pStrBuffer = std::make_shared(); + aDataHelper.GetString(format, *pStrBuffer); + auto pStrm = std::make_shared(*pStrBuffer); + ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + VclPtr pDlg(pFact->CreateScImportAsciiDlg( + pWin ? pWin->GetFrameWeld() : nullptr, OUString(), pStrm.get(), SC_PASTETEXT)); + ScRange aRange; + SCCOL nPosX = 0; + SCROW nPosY = 0; + if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE) + { + nPosX = aRange.aStart.Col(); + nPosY = aRange.aStart.Row(); + } + else + { + nPosX = GetViewData()->GetCurX(); + nPosY = GetViewData()->GetCurY(); + } + ScAddress aCellPos(nPosX, nPosY, GetViewData()->GetTabNo()); + auto pObj = std::make_shared(GetViewData()->GetDocument(), aCellPos); + pObj->SetOverwriting(true); + if (pDlg->Execute()) { + ScAsciiOptions aOptions; + pDlg->GetOptions(aOptions); + pDlg->SaveParameters(); + pObj->SetExtOptions(aOptions); + pObj->ImportString(*pStrBuffer, format); + } + pDlg->disposeOnce(); + rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success, 0 = fail + rReq.Done(); + } + else + { + rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail + rReq.Ignore(); + } + } + break; case SID_PASTE_SPECIAL: // differentiate between own cell data and draw objects/external data // this makes FID_INS_CELL_CONTENTS superfluous @@ -1557,6 +1609,13 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) pDlg->Insert( nFormatId, aName ); } + SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame(); + auto xFrame = pViewFrame->GetFrame().GetFrameInterface(); + const OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(xFrame)); + auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(".uno:PasteTextImportDialog", aModuleName); + OUString sLabel(vcl::CommandInfoProvider::GetTooltipLabelForCommand(aProperties)); + pDlg->InsertUno(".uno:PasteTextImportDialog", sLabel); + TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) ); SotClipboardFormatId nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() ); diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index 624abe196661..a7d68e7d0a55 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -3143,6 +3143,22 @@ SfxVoidItem PasteOnlyValue SID_PASTE_ONLY_VALUE GroupId = SfxGroupId::Edit; ] +SfxVoidItem PasteTextImportDialog SID_PASTE_TEXTIMPORT_DIALOG + +[ + AutoUpdate = FALSE, + FastCall = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + + AccelConfig = TRUE, + MenuConfig = TRUE, + ToolBoxConfig = TRUE, + GroupId = SfxGroupId::Edit; +] SfxStringItem DocPath SID_DOCPATH diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx index 1b010a9d50fc..805aa7ad693f 100644 --- a/vcl/source/helper/commandinfoprovider.cxx +++ b/vcl/source/helper/commandinfoprovider.cxx @@ -262,6 +262,14 @@ OUString GetPopupLabelForCommand(const css::uno::Sequence& rProperties) +{ + OUString sLabel(GetCommandProperty("TooltipLabel", rProperties)); + if (!sLabel.isEmpty()) + return sLabel; + return GetCommandProperty("Label", rProperties); +} + OUString GetTooltipForCommand( const OUString& rsCommandName, const css::uno::Sequence& rProperties,