Resolves tdf#132253 - Remove hyperlink tab from character dialog
Change-Id: Idb7fa74dbe196262cea64946452043f7de6fa20c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166553
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
diff --git a/sw/qa/uitest/writer_tests2/formatCharacter.py b/sw/qa/uitest/writer_tests2/formatCharacter.py
index 265f7b4..724b881 100644
--- a/sw/qa/uitest/writer_tests2/formatCharacter.py
+++ b/sw/qa/uitest/writer_tests2/formatCharacter.py
@@ -65,8 +65,6 @@ class formatCharacter(UITestCase):
xLangFontCTL = xDialog.getChild("cbCTLLanguage")
self.assertEqual(get_state_as_dict(xLangFontCTL)["Text"], "[None]")
def test_format_character_tab_font_effects(self):
with self.ui_test.create_doc_in_start_center("writer"):
@@ -115,47 +113,6 @@ class formatCharacter(UITestCase):
self.assertEqual(get_state_as_dict(xEmphasis)["SelectEntryText"], "Dot")
self.assertEqual(get_state_as_dict(xPosition)["SelectEntryText"], "Below text")
def test_format_character_tab_hyperlink(self):
with self.ui_test.create_doc_in_start_center("writer") as document:
with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog:
xTabs = xDialog.getChild("tabcontrol")
select_pos(xTabs, "4")
xURL = xDialog.getChild("urled")
xURL.executeAction("TYPE", mkPropertyValues({"TEXT":"libreoffice.org"}))
xTexted = xDialog.getChild("texted")
xTexted.executeAction("TYPE", mkPropertyValues({"TEXT":"LibreOffice"}))
xName = xDialog.getChild("nameed")
xName.executeAction("TYPE", mkPropertyValues({"TEXT":"hyperlink"}))
xVisited = xDialog.getChild("visitedlb")
select_by_text(xVisited, "Bullets")
xUnVisited = xDialog.getChild("unvisitedlb")
select_by_text(xUnVisited, "Bullets")
self.xUITest.executeCommand(".uno:GoLeft")
self.assertEqual(document.Text.String[0:11], "LibreOffice")
with self.ui_test.execute_dialog_through_command(".uno:FontDialog", close_button="cancel") as xDialog:
xTabs = xDialog.getChild("tabcontrol")
select_pos(xTabs, "4")
xURL = xDialog.getChild("urled")
xTexted = xDialog.getChild("texted")
xName = xDialog.getChild("nameed")
xVisited = xDialog.getChild("visitedlb")
xUnVisited = xDialog.getChild("unvisitedlb")
self.assertEqual(get_state_as_dict(xURL)["Text"], "http://libreoffice.org/")
self.assertEqual(get_state_as_dict(xTexted)["Text"], "LibreOffice")
self.assertEqual(get_state_as_dict(xName)["Text"], "hyperlink")
self.assertEqual(get_state_as_dict(xVisited)["SelectEntryText"], "Bullets")
self.assertEqual(get_state_as_dict(xUnVisited)["SelectEntryText"], "Bullets")
def test_format_character_tab_asian_layout(self):
with self.ui_test.create_doc_in_start_center("writer"):
@@ -221,8 +178,6 @@ class formatCharacter(UITestCase):
self.assertEqual(get_state_as_dict(xFitToLine)["Selected"], "true")
self.assertEqual(get_state_as_dict(xNoHyphenation)["Selected"], "true")
def test_format_character_tab_position_scalewidthsb(self):
with self.ui_test.create_doc_in_start_center("writer"):
@@ -240,6 +195,4 @@ class formatCharacter(UITestCase):
xScalewidth = xDialog.getChild("scalewidthsb")
self.assertEqual(get_state_as_dict(xScalewidth)["Text"], "101%")
# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/chrdlg/chardlg.cxx b/sw/source/ui/chrdlg/chardlg.cxx
index 14833d7..f57a78d 100644
--- a/sw/source/ui/chrdlg/chardlg.cxx
+++ b/sw/source/ui/chrdlg/chardlg.cxx
@@ -17,37 +17,18 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <memory>
#include <hintids.hxx>
#include <comphelper/fileurl.hxx>
#include <svl/urihelper.hxx>
#include <svl/stritem.hxx>
#include <editeng/flstitem.hxx>
#include <sfx2/htmlmode.hxx>
#include <svl/cjkoptions.hxx>
#include <svl/macitem.hxx>
#include <osl/diagnose.h>
#include <cmdid.h>
#include <swtypes.hxx>
#include <view.hxx>
#include <docsh.hxx>
#include <uitool.hxx>
#include <fmtinfmt.hxx>
#include <macassgn.hxx>
#include <chrdlg.hxx>
#include <swmodule.hxx>
#include <poolfmt.hxx>
#include <strings.hrc>
#include <chrdlgmodes.hxx>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
#include <SwStyleNameMapper.hxx>
#include <sfx2/filedlghelper.hxx>
#include <sfx2/frame.hxx>
#include <comphelper/lok.hxx>
#include <svx/svxdlg.hxx>
#include <svx/flagsdef.hxx>
@@ -73,13 +54,11 @@ SwCharDlg::SwCharDlg(weld::Window* pParent, SwView& rVw, const SfxItemSet& rCore
AddTabPage("fonteffects", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_EFFECTS), nullptr);
AddTabPage("position", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_POSITION ), nullptr );
AddTabPage("asianlayout", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_TWOLINES ), nullptr );
AddTabPage("hyperlink", SwCharURLPage::Create, nullptr);
AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BKG ), nullptr );
AddTabPage("borders", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), nullptr );
if (m_nDialogMode == SwCharDlgMode::Draw || m_nDialogMode == SwCharDlgMode::Ann)
{
RemoveTabPage("hyperlink");
RemoveTabPage("asianlayout");
}
else
@@ -135,194 +114,4 @@ void SwCharDlg::PageCreated(const OUString& rId, SfxTabPage &rPage)
}
}
SwCharURLPage::SwCharURLPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet)
: SfxTabPage(pPage, pController, "modules/swriter/ui/charurlpage.ui", "CharURLPage", &rCoreSet)
, m_bModified(false)
, m_xURLED(m_xBuilder->weld_entry("urled"))
, m_xTextFT(m_xBuilder->weld_label("textft"))
, m_xTextED(m_xBuilder->weld_entry("texted"))
, m_xNameED(m_xBuilder->weld_entry("nameed"))
, m_xTargetFrameLB(m_xBuilder->weld_combo_box("targetfrmlb"))
, m_xURLPB(m_xBuilder->weld_button("urlpb"))
, m_xEventPB(m_xBuilder->weld_button("eventpb"))
, m_xVisitedLB(m_xBuilder->weld_combo_box("visitedlb"))
, m_xNotVisitedLB(m_xBuilder->weld_combo_box("unvisitedlb"))
, m_xCharStyleContainer(m_xBuilder->weld_widget("charstyle"))
{
// tdf#120188 like SfxManageStyleSheetPage limit the width of the style combos
const int nMaxWidth(m_xVisitedLB->get_approximate_digit_width() * 50);
m_xVisitedLB->set_size_request(nMaxWidth , -1);
m_xNotVisitedLB->set_size_request(nMaxWidth , -1);
const SfxUInt16Item* pItem = rCoreSet.GetItemIfSet(SID_HTML_MODE, false);
if (!pItem)
{
if (SfxObjectShell* pShell = SfxObjectShell::Current())
pItem = pShell->GetItem(SID_HTML_MODE);
}
if (pItem)
{
sal_uInt16 nHtmlMode = pItem->GetValue();
if (HTMLMODE_ON & nHtmlMode)
m_xCharStyleContainer->hide();
}
if(comphelper::LibreOfficeKit::isActive())
m_xURLPB->hide(); // Hide browse button in online (not supported yet)
else
m_xURLPB->connect_clicked(LINK( this, SwCharURLPage, InsertFileHdl));
m_xEventPB->connect_clicked(LINK( this, SwCharURLPage, EventHdl));
if (SwView* pView = GetActiveView())
{
::FillCharStyleListBox(*m_xVisitedLB, pView->GetDocShell());
::FillCharStyleListBox(*m_xNotVisitedLB, pView->GetDocShell());
}
m_xVisitedLB->set_active_id(OUString::number(RES_POOLCHR_INET_VISIT));
m_xVisitedLB->save_value();
m_xNotVisitedLB->set_active_id(OUString::number(RES_POOLCHR_INET_NORMAL));
m_xNotVisitedLB->save_value();
TargetList aList;
SfxFrame::GetDefaultTargetList(aList);
m_xTargetFrameLB->freeze();
size_t nCount = aList.size();
for (size_t i = 0; i < nCount; ++i)
{
m_xTargetFrameLB->append_text(aList.at(i));
}
m_xTargetFrameLB->thaw();
}
SwCharURLPage::~SwCharURLPage()
{
}
void SwCharURLPage::Reset(const SfxItemSet* rSet)
{
if (const SwFormatINetFormat* pINetFormat = rSet->GetItemIfSet(RES_TXTATR_INETFMT, false))
{
m_xURLED->set_text(INetURLObject::decode(pINetFormat->GetValue(),
INetURLObject::DecodeMechanism::Unambiguous));
m_xURLED->save_value();
m_xNameED->set_text(pINetFormat->GetName());
m_xNameED->save_value();
OUString sEntry = pINetFormat->GetVisitedFormat();
if (sEntry.isEmpty())
{
OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing visited character format at hyperlink attribute" );
SwStyleNameMapper::FillUIName(RES_POOLCHR_INET_VISIT, sEntry);
}
m_xVisitedLB->set_active_text(sEntry);
sEntry = pINetFormat->GetINetFormat();
if (sEntry.isEmpty())
{
OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing unvisited character format at hyperlink attribute" );
SwStyleNameMapper::FillUIName(RES_POOLCHR_INET_NORMAL, sEntry);
}
m_xNotVisitedLB->set_active_text(sEntry);
m_xTargetFrameLB->set_entry_text(pINetFormat->GetTargetFrame());
m_xVisitedLB->save_value();
m_xNotVisitedLB->save_value();
m_xTargetFrameLB->save_value();
m_oINetMacroTable.emplace();
if( pINetFormat->GetMacroTable() )
m_oINetMacroTable = *pINetFormat->GetMacroTable();
}
if (const SfxStringItem* pItem = rSet->GetItemIfSet(FN_PARAM_SELECTION, false))
{
m_xTextED->set_text(pItem->GetValue());
m_xTextFT->set_sensitive(false);
m_xTextED->set_sensitive(false);
}
}
bool SwCharURLPage::FillItemSet(SfxItemSet* rSet)
{
OUString sURL = m_xURLED->get_text();
if (!sURL.isEmpty())
{
sURL = URIHelper::SmartRel2Abs(INetURLObject(), sURL, Link<OUString *, bool>(), false );
// #i100683# file URLs should be normalized in the UI
if ( comphelper::isFileUrl(sURL) )
sURL = URIHelper::simpleNormalizedMakeRelative(OUString(), sURL);
}
SwFormatINetFormat aINetFormat(sURL, m_xTargetFrameLB->get_active_text());
aINetFormat.SetName(m_xNameED->get_text());
bool bURLModified = m_xURLED->get_value_changed_from_saved();
bool bNameModified = m_xNameED->get_value_changed_from_saved();
bool bTargetModified = m_xTargetFrameLB->get_value_changed_from_saved();
m_bModified = bURLModified || bNameModified || bTargetModified;
// set valid settings first
OUString sEntry = m_xVisitedLB->get_active_text();
sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, SwGetPoolIdFromName::ChrFmt);
aINetFormat.SetVisitedFormatAndId( sEntry, nId );
sEntry = m_xNotVisitedLB->get_active_text();
nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, SwGetPoolIdFromName::ChrFmt);
aINetFormat.SetINetFormatAndId( sEntry, nId );
if (m_oINetMacroTable && !m_oINetMacroTable->empty())
aINetFormat.SetMacroTable(&*m_oINetMacroTable);
if (m_xVisitedLB->get_value_changed_from_saved())
m_bModified = true;
if (m_xNotVisitedLB->get_value_changed_from_saved())
m_bModified = true;
if (bNameModified)
{
m_bModified = true;
rSet->Put(SfxStringItem(FN_PARAM_SELECTION, m_xTextED->get_text()));
}
if(m_bModified)
rSet->Put(aINetFormat);
return m_bModified;
}
std::unique_ptr<SfxTabPage> SwCharURLPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
{
return std::make_unique<SwCharURLPage>(pPage, pController, *rAttrSet);
}
IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, weld::Button&, void)
{
FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
FileDialogFlags::NONE, GetFrameWeld());
aDlgHelper.SetContext(FileDialogHelper::WriterInsertHyperlink);
if( aDlgHelper.Execute() == ERRCODE_NONE )
{
const Reference<XFilePicker3>& xFP = aDlgHelper.GetFilePicker();
m_xURLED->set_text(xFP->getSelectedFiles().getConstArray()[0]);
}
}
IMPL_LINK_NOARG(SwCharURLPage, EventHdl, weld::Button&, void)
{
SwView* pView = GetActiveView();
if (!pView)
return;
SvxMacroItem aItem( RES_FRMMACRO );
if( !m_oINetMacroTable )
m_oINetMacroTable.emplace();
else
aItem.SetMacroTable( *m_oINetMacroTable );
SwMacroAssignDlg::INetFormatDlg(GetFrameWeld(), pView->GetWrtShell(), aItem,
[this] (const SvxMacroItem& rItem)
{
m_oINetMacroTable.emplace(rItem.GetMacroTable());
m_bModified = true;
});
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/chrdlg.hxx b/sw/source/uibase/inc/chrdlg.hxx
index cf37a94..532b62d 100644
--- a/sw/source/uibase/inc/chrdlg.hxx
+++ b/sw/source/uibase/inc/chrdlg.hxx
@@ -40,36 +40,6 @@ public:
virtual void PageCreated(const OUString& rId, SfxTabPage &rPage) override;
};
class SwCharURLPage final : public SfxTabPage
{
std::optional<SvxMacroTableDtor> m_oINetMacroTable;
bool m_bModified;
std::unique_ptr<weld::Entry> m_xURLED;
std::unique_ptr<weld::Label> m_xTextFT;
std::unique_ptr<weld::Entry> m_xTextED;
std::unique_ptr<weld::Entry> m_xNameED;
std::unique_ptr<weld::ComboBox> m_xTargetFrameLB;
std::unique_ptr<weld::Button> m_xURLPB;
std::unique_ptr<weld::Button> m_xEventPB;
std::unique_ptr<weld::ComboBox> m_xVisitedLB;
std::unique_ptr<weld::ComboBox> m_xNotVisitedLB;
std::unique_ptr<weld::Widget> m_xCharStyleContainer;
DECL_LINK(InsertFileHdl, weld::Button&, void);
DECL_LINK(EventHdl, weld::Button&, void);
public:
SwCharURLPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet);
virtual ~SwCharURLPage() override;
static std::unique_ptr<SfxTabPage> Create(weld::Container* pPage, weld::DialogController* pController,
const SfxItemSet* rAttrSet);
virtual bool FillItemSet( SfxItemSet* rSet ) override;
virtual void Reset( const SfxItemSet* rSet ) override;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/uiconfig/swriter/ui/characterproperties.ui b/sw/uiconfig/swriter/ui/characterproperties.ui
index 414edb7..1f13c9b 100644
--- a/sw/uiconfig/swriter/ui/characterproperties.ui
+++ b/sw/uiconfig/swriter/ui/characterproperties.ui
@@ -221,10 +221,10 @@
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="hyperlink">
<object class="GtkLabel" id="background">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" context="characterproperties|hyperlink">Hyperlink</property>
<property name="label" translatable="yes" context="characterproperties|background">Highlighting</property>
</object>
<packing>
<property name="position">4</property>
@@ -245,37 +245,13 @@
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="background">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" context="characterproperties|background">Highlighting</property>
</object>
<packing>
<property name="position">5</property>
<property name="tab-fill">False</property>
</packing>
</child>
<child>
<!-- n-columns=1 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">6</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="borders">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" context="characterproperties|borders">Borders</property>
</object>
<packing>
<property name="position">6</property>
<property name="position">5</property>
<property name="tab-fill">False</property>
</packing>
</child>