tdf#125440 Allow raising text import dialog for paste
This adds an entry to the "Paste special" dialog to raise the Text Import Dialog. This way, users can correctly import CSV/TSV, even when pasting just one line of formatted input. Change-Id: Ic09d7d60a05b14906f166668b38ec0eb8ead2d19 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89886 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
#include <svtools/strings.hrc>
|
||||
#include <svtools/svtresid.hxx>
|
||||
#include <tools/lineend.hxx>
|
||||
#include <comphelper/propertysequence.hxx>
|
||||
#include <comphelper/dispatchcommand.hxx>
|
||||
|
||||
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<SotClipboardFormatId>(ObjectLB().get_selected_id().toUInt32());
|
||||
if (ObjectLB().get_selected_id().startsWithIgnoreAsciiCase(".uno"))
|
||||
{
|
||||
comphelper::dispatchCommand(aExtraCommand.first, {});
|
||||
nSelFormat = SotClipboardFormatId::NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
nSelFormat = static_cast<SotClipboardFormatId>(ObjectLB().get_selected_id().toUInt32());
|
||||
}
|
||||
}
|
||||
|
||||
return nSelFormat;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<OUString, OUString> 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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -53,6 +53,8 @@ namespace vcl { namespace CommandInfoProvider {
|
||||
|
||||
VCL_DLLPUBLIC OUString GetPopupLabelForCommand(const css::uno::Sequence<css::beans::PropertyValue>& rProperties);
|
||||
|
||||
VCL_DLLPUBLIC OUString GetTooltipLabelForCommand(const css::uno::Sequence<css::beans::PropertyValue>& 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:
|
||||
|
||||
@@ -2564,6 +2564,17 @@
|
||||
<value>1</value>
|
||||
</prop>
|
||||
</node>
|
||||
<node oor:name=".uno:PasteTextImportDialog" oor:op="replace">
|
||||
<prop oor:name="Label" oor:type="xs:string">
|
||||
<value xml:lang="en-US">Use Text Import Dialog</value>
|
||||
</prop>
|
||||
<prop oor:name="TooltipLabel" oor:type="xs:string">
|
||||
<value xml:lang="en-US">Use text import dialog</value>
|
||||
</prop>
|
||||
<prop oor:name="Properties" oor:type="xs:int">
|
||||
<value>1</value>
|
||||
</prop>
|
||||
</node>
|
||||
<node oor:name=".uno:ColumnOperations" oor:op="replace">
|
||||
<prop oor:name="Label" oor:type="xs:string">
|
||||
<value xml:lang="en-US">Column</value>
|
||||
|
||||
@@ -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; ]
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <svl/zformat.hxx>
|
||||
#include <sfx2/dispatch.hxx>
|
||||
#include <sfx2/request.hxx>
|
||||
#include <vcl/commandinfoprovider.hxx>
|
||||
#include <vcl/svapp.hxx>
|
||||
#include <vcl/weld.hxx>
|
||||
#include <svx/svxdlg.hxx>
|
||||
@@ -74,6 +75,7 @@
|
||||
#include <condformatdlg.hxx>
|
||||
#include <attrib.hxx>
|
||||
#include <condformatdlgitem.hxx>
|
||||
#include <impex.hxx>
|
||||
|
||||
#include <globstr.hrc>
|
||||
#include <scresid.hxx>
|
||||
@@ -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<datatransfer::XTransferable>& xTransferable
|
||||
= aDataHelper.GetTransferable();
|
||||
SotClipboardFormatId format = SotClipboardFormatId::STRING;
|
||||
if (xTransferable.is() && HasClipboardFormat(format))
|
||||
{
|
||||
auto pStrBuffer = std::make_shared<OUString>();
|
||||
aDataHelper.GetString(format, *pStrBuffer);
|
||||
auto pStrm = std::make_shared<ScImportStringStream>(*pStrBuffer);
|
||||
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
|
||||
VclPtr<AbstractScImportAsciiDlg> 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<ScImportExport>(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() );
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -262,6 +262,14 @@ OUString GetPopupLabelForCommand(const css::uno::Sequence<css::beans::PropertyVa
|
||||
return GetCommandProperty("Label", rProperties);
|
||||
}
|
||||
|
||||
OUString GetTooltipLabelForCommand(const css::uno::Sequence<css::beans::PropertyValue>& rProperties)
|
||||
{
|
||||
OUString sLabel(GetCommandProperty("TooltipLabel", rProperties));
|
||||
if (!sLabel.isEmpty())
|
||||
return sLabel;
|
||||
return GetCommandProperty("Label", rProperties);
|
||||
}
|
||||
|
||||
OUString GetTooltipForCommand(
|
||||
const OUString& rsCommandName,
|
||||
const css::uno::Sequence<css::beans::PropertyValue>& rProperties,
|
||||
|
||||
Reference in New Issue
Block a user