Kaydet (Commit) b48025af authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

add "Style Presets" sidebar panel (experimental) to writer

Style presets is a list of bundled & user defined styles presets
that can be applied to the current document. The styles are taken
from tempalte files that are in "styles" template folder. This is
for now only added as an experimental feature.

Change-Id: If6d1128ca7e2f61efd13bb8ae3baee5cb357d286
üst cb09f4da
......@@ -1002,7 +1002,31 @@
<value>100</value>
</prop>
</node>
<node oor:name="StylePresetsPanel" oor:op="replace">
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">Style Presets</value>
</prop>
<prop oor:name="Id" oor:type="xs:string">
<value>StylePresetsPanel</value>
</prop>
<prop oor:name="DeckId" oor:type="xs:string">
<value>DesignDeck</value>
</prop>
<prop oor:name="ContextList">
<value oor:separator=";">
WriterVariants, any, visible ;
</value>
</prop>
<prop oor:name="ImplementationURL" oor:type="xs:string">
<value>private:resource/toolpanel/SwPanelFactory/StylePresetsPanel</value>
</prop>
<prop oor:name="OrderIndex" oor:type="xs:int">
<value>1</value>
</prop>
<prop oor:name="IsExperimental" oor:type="xs:boolean">
<value>true</value>
</prop>
</node>
</node>
</node>
</oor:component-data>
......@@ -675,6 +675,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
sw/source/uibase/shells/txtattr \
sw/source/uibase/shells/txtcrsr \
sw/source/uibase/shells/txtnum \
sw/source/uibase/sidebar/StylePresetsPanel \
sw/source/uibase/sidebar/PageOrientationControl \
sw/source/uibase/sidebar/PageMarginControl \
sw/source/uibase/sidebar/PageSizeControl \
......
......@@ -205,6 +205,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
sw/uiconfig/swriter/ui/selecttabledialog \
sw/uiconfig/swriter/ui/sidebarpage \
sw/uiconfig/swriter/ui/sidebarwrap \
sw/uiconfig/swriter/ui/sidebarstylepresets \
sw/uiconfig/swriter/ui/sortdialog \
sw/uiconfig/swriter/ui/splittable \
sw/uiconfig/swriter/ui/statisticsinfopage \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <sal/config.h>
#include "StylePresetsPanel.hxx"
#include <swtypes.hxx>
#include <cmdid.h>
#include <svl/intitem.hxx>
#include <svx/svxids.hrc>
#include <svx/dlgutil.hxx>
#include <svx/rulritem.hxx>
#include <sfx2/sidebar/ControlFactory.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/objsh.hxx>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/DocumentTemplates.hpp>
#include <com/sun/star/frame/XDocumentTemplates.hpp>
#include <com/sun/star/document/XUndoManagerSupplier.hpp>
#include <sfx2/doctempl.hxx>
#include "shellio.hxx"
#include "docsh.hxx"
#include <comphelper/processfactory.hxx>
#include <comphelper/documentconstants.hxx>
#include <comphelper/string.hxx>
namespace sw { namespace sidebar {
StylePresetsPanel* StylePresetsPanel::Create (vcl::Window* pParent,
const css::uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings)
{
if (pParent == NULL)
throw css::lang::IllegalArgumentException("no parent Window given to PagePropertyPanel::Create", NULL, 0);
if (!rxFrame.is())
throw css::lang::IllegalArgumentException("no XFrame given to PagePropertyPanel::Create", NULL, 1);
if (pBindings == NULL)
throw css::lang::IllegalArgumentException("no SfxBindings given to PagePropertyPanel::Create", NULL, 2);
return new StylePresetsPanel(pParent, rxFrame, pBindings);
}
StylePresetsPanel::StylePresetsPanel(vcl::Window* pParent,
const css::uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings)
: PanelLayout(pParent, "StylePresetsPanel", "modules/swriter/ui/sidebarstylepresets.ui", rxFrame)
, mpBindings(pBindings)
{
get(mpListBox, "listbox");
mpListBox->SetDoubleClickHdl(LINK(this, StylePresetsPanel, DoubleClickHdl));
SfxDocumentTemplates aTemplates;
sal_uInt16 nCount = aTemplates.GetRegionCount();
for (sal_uInt16 i = 0; i < nCount; ++i)
{
OUString aRegionName(aTemplates.GetFullRegionName(i));
if (aRegionName == "styles")
{
for (sal_uInt16 j = 0; j < aTemplates.GetCount(i); ++j)
{
OUString aName = aTemplates.GetName(i,j);
OUString aURL = aTemplates.GetPath(i,j);
sal_Int32 nIndex = mpListBox->InsertEntry(aName);
maTemplateEntries.push_back(std::unique_ptr<TemplateEntry>(new TemplateEntry(aName, aURL)));
mpListBox->SetEntryData(nIndex, maTemplateEntries.back().get());
}
}
}
}
StylePresetsPanel::~StylePresetsPanel()
{
}
IMPL_LINK_NOARG(StylePresetsPanel, DoubleClickHdl)
{
sal_Int32 nIndex = mpListBox->GetSelectEntryPos();
TemplateEntry* pEntry = static_cast<TemplateEntry*>(mpListBox->GetEntryData(nIndex));
SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
if (pDocSh)
{
SwgReaderOption aOption;
aOption.SetTxtFmts(true);
aOption.SetNumRules(true);
pDocSh->LoadStylesFromFile(pEntry->maURL, aOption, false);
}
return 1;
}
void StylePresetsPanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/,
const SfxItemState /*eState*/,
const SfxPoolItem* /*pState*/,
const bool /*bIsEnabled*/)
{
}
}} // end of namespace ::sw::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_STYLEPRESETSPANEL_HXX
#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_STYLEPRESETSPANEL_HXX
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/document/XUndoManager.hpp>
#include <svx/sidebar/Popup.hxx>
#include <svx/sidebar/PanelLayout.hxx>
#include <sfx2/sidebar/ControllerItem.hxx>
#include <svx/pageitem.hxx>
#include <svx/rulritem.hxx>
#include <editeng/sizeitem.hxx>
#include <vcl/ctrl.hxx>
#include <vcl/fixed.hxx>
#include <vcl/button.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/field.hxx>
#include <svl/intitem.hxx>
#include <svl/lstner.hxx>
#include <svx/fntctrl.hxx>
#include "docstyle.hxx"
namespace sw { namespace sidebar {
class StylePresetsPanel : public PanelLayout,
public sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface
{
public:
static StylePresetsPanel* Create(vcl::Window* pParent,
const css::uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings);
virtual void NotifyItemUpdate(const sal_uInt16 nSId,
const SfxItemState eState,
const SfxPoolItem* pState,
const bool bIsEnabled) SAL_OVERRIDE;
SfxBindings* GetBindings() const
{
return mpBindings;
}
private:
struct TemplateEntry
{
TemplateEntry(OUString& rName, OUString& rURL)
: maName(rName)
, maURL(rURL)
{}
OUString maName;
OUString maURL;
};
StylePresetsPanel(vcl::Window* pParent,
const css::uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings);
virtual ~StylePresetsPanel();
SfxBindings* mpBindings;
ListBox* mpListBox;
std::vector<std::unique_ptr<TemplateEntry>> maTemplateEntries;
DECL_LINK(DoubleClickHdl, void*);
};
}} // end of namespace sw::sidebar
#endif // INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_STYLEPRESETSPANEL_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -19,6 +19,7 @@
#include <com/sun/star/ui/XUIElementFactory.hpp>
#include <StylePresetsPanel.hxx>
#include <PagePropertyPanel.hxx>
#include <WrapPropertyPanel.hxx>
#include <navipi.hxx>
......@@ -153,6 +154,12 @@ Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement (
pPanel,
ui::LayoutSize(-1,-1,-1));
}
else if (rsResourceURL.endsWith("/StylePresetsPanel"))
{
sw::sidebar::StylePresetsPanel* pPanel = sw::sidebar::StylePresetsPanel::Create(pParentWindow, xFrame, pBindings);
xElement = sfx2::sidebar::SidebarPanelBase::Create(
rsResourceURL, xFrame, pPanel, ui::LayoutSize(-1,-1,-1));
}
return xElement;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkGrid" id="StylePresetsPanel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_homogeneous">True</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkTreeView" id="listbox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</interface>
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