Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi
Submitting a patch for review. This one enables the user to set the
default tab prefix name in calc.
The new option is located in Menu -> Tools -> Options -> LibreOffice
Calc -> Defaults

- I think this Is a useful feature for some at least,  a few LO/OOo
users i've talked to seem to agree.
- it is unobtrusive to the user, it does not change the default behavior.
- also code-wise it does not come with any radical changes.

As always please let me know if you want me to improve it.

Once you are happy with it you can commit the patch under the terms of
MPL 1.1 / GPLv3+ / LGPLv3+ triple license.

/Albert
From f40c43a184fb07cafb3dea87cc929221c3284d78 Mon Sep 17 00:00:00 2001
From: Albert Thuswaldner <albert.thuswaldner@gmail.com>
Date: Sat, 2 Jul 2011 11:34:55 +0200
Subject: [PATCH] option to set tab prefix for new worksheets

---
 sc/inc/docoptio.hxx                |    5 +++++
 sc/inc/document.hxx                |    1 +
 sc/source/core/data/document.cxx   |   32 +++++++++++++++++++++++++-------
 sc/source/core/tool/docoptio.cxx   |   18 ++++++++++++++++--
 sc/source/ui/inc/optdlg.hrc        |    2 ++
 sc/source/ui/inc/tpdefaults.hxx    |    5 ++++-
 sc/source/ui/optdlg/tpdefaults.cxx |   24 +++++++++++++++++-------
 sc/source/ui/src/optdlg.src        |   13 +++++++++++++
 8 files changed, 83 insertions(+), 17 deletions(-)

diff --git a/sc/inc/docoptio.hxx b/sc/inc/docoptio.hxx
index de6b970..65feaa8 100644
--- a/sc/inc/docoptio.hxx
+++ b/sc/inc/docoptio.hxx
@@ -43,6 +43,7 @@ class SC_DLLPUBLIC ScDocOptions
     double fIterEps;                           // epsilon value dazu
     sal_uInt16 nIterCount;                             // number
     SCTAB nInitTabCount;                       // number of Tabs for new Spreadssheet doc
+    ::rtl::OUString aInitTabPrefix;   // The Tab names in new Spreadsheet doc
     sal_uInt16 nPrecStandardFormat; // precision for standard format
     ScOptionsUtil::KeyBindingType eKeyBindingType;
     sal_uInt16 nDay;                                   // Null date:
@@ -83,6 +84,8 @@ public:
     void   SetIterCount( sal_uInt16 nCount) { nIterCount = nCount; }
     SCTAB GetInitTabCount() const                      { return nInitTabCount; }
     void   SetInitTabCount( SCTAB nTabs) { nInitTabCount = nTabs; }
+    void   SetInitTabPrefix( ::rtl::OUString& aPrefix) { aInitTabPrefix = aPrefix; }
+    ::rtl::OUString GetInitTabPrefix() const                   { return aInitTabPrefix; }
     double GetIterEps() const                  { return fIterEps; }
     void   SetIterEps( double fEps )   { fIterEps = fEps; }
 
@@ -139,6 +142,7 @@ inline const ScDocOptions& ScDocOptions::operator=( const ScDocOptions& rCpy )
     bIsIter                            = rCpy.bIsIter;
     nIterCount                 = rCpy.nIterCount;
     nInitTabCount       = rCpy.nInitTabCount;
+    aInitTabPrefix      = rCpy.aInitTabPrefix;
     fIterEps                   = rCpy.fIterEps;
     nPrecStandardFormat = rCpy.nPrecStandardFormat;
     eKeyBindingType     = rCpy.eKeyBindingType;
@@ -168,6 +172,7 @@ inline int ScDocOptions::operator==( const ScDocOptions& rOpt ) const
             && rOpt.bIsIter                            == bIsIter
             && rOpt.nIterCount                         == nIterCount
             &&  rOpt.nInitTabCount          == nInitTabCount
+            &&  rOpt.aInitTabPrefix         == aInitTabPrefix
             && rOpt.fIterEps                           == fIterEps
             && rOpt.nPrecStandardFormat        == nPrecStandardFormat
             &&  rOpt.eKeyBindingType        == eKeyBindingType
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index b547bc2..ebfc27d 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -572,6 +572,7 @@ public:
 
     SC_DLLPUBLIC sal_Bool                      ValidNewTabName( const String& rName ) const;
     SC_DLLPUBLIC bool                      ValidNewTabName( const std::vector<String>& rName ) 
const;
+    SC_DLLPUBLIC sal_Bool       GetFallBackPrefix(String& aStrPrefix) const;
     SC_DLLPUBLIC void                  CreateValidTabName(String& rName) const;
     SC_DLLPUBLIC void                  CreateValidTabNames(std::vector<rtl::OUString>& aNames, 
SCTAB nCount) const;
     SC_DLLPUBLIC sal_Bool                      InsertTab( SCTAB nPos, const String& rName,
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 1822f00..f42dda5 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -94,6 +94,7 @@
 #include "externalrefmgr.hxx"
 #include "tabprotection.hxx"
 #include "clipparam.hxx"
+#include "docoptio.hxx"
 
 #include <map>
 #include <limits>
@@ -141,7 +142,8 @@ void ScDocument::MakeTable( SCTAB nTab,bool _bNeedsNameCheck )
 {
     if ( ValidTab(nTab) && ( nTab >= static_cast<SCTAB>(maTabs.size()) ||!maTabs[nTab]) )
     {
-        String aString = ScGlobal::GetRscString(STR_TABLE_DEF); //"Table"
+        String aString;
+        GetFallBackPrefix( aString );
         aString += String::CreateFromInt32(nTab+1);
         if ( _bNeedsNameCheck )
             CreateValidTabName( aString );     // no doubles
@@ -324,6 +326,24 @@ bool ScDocument::ValidNewTabName( const std::vector<String>& rNames ) 
const//TOD
     return bValid;
 }
 
+sal_Bool ScDocument::GetFallBackPrefix(String& aStrPrefix) const
+{
+    // Get Custom prefix, used as primary fall-back
+    const ScDocOptions& rDocOpt = SC_MOD()->GetDocOptions();
+    aStrPrefix = static_cast<String>(rDocOpt.GetInitTabPrefix());
+
+    // Get Default prefix, used as secondary fall-back
+    const String aStrPrefix2( ScResId(SCSTR_TABLE) );
+
+    // Test if prefix is valid
+    sal_Bool bPrefix = ValidTabName( aStrPrefix );
+    if ( !bPrefix )
+        {
+            bPrefix = ValidTabName( aStrPrefix );
+            aStrPrefix = aStrPrefix2;
+        }
+    return bPrefix;
+}
 
 void ScDocument::CreateValidTabName(String& rName) const
 {
@@ -331,11 +351,11 @@ void ScDocument::CreateValidTabName(String& rName) const
     {
         // Find new one
 
-        const String aStrTable( ScResId(SCSTR_TABLE) );
+        String aStrTable;
         sal_Bool                bOk   = false;
 
         // First test if the prefix is valid, if so only avoid doubles
-        sal_Bool bPrefix = ValidTabName( aStrTable );
+        sal_Bool bPrefix = GetFallBackPrefix( aStrTable );
         OSL_ENSURE(bPrefix, "Invalid Table Name");
         SCTAB nDummy;
 
@@ -371,17 +391,15 @@ void ScDocument::CreateValidTabName(String& rName) const
     }
 }
 
-
 void ScDocument::CreateValidTabNames(std::vector<rtl::OUString>& aNames, SCTAB nCount) const
 {
     aNames.clear();//ensure that the vector is empty
-
-    const String aStrTable( ScResId(SCSTR_TABLE) );
+    String aStrTable;
     String rName;
     bool                bOk   = false;
 
     // First test if the prefix is valid, if so only avoid doubles
-    sal_Bool bPrefix = ValidTabName( aStrTable );
+    sal_Bool bPrefix = GetFallBackPrefix( aStrTable );
     OSL_ENSURE(bPrefix, "Invalid Table Name");
     SCTAB nDummy;
     SCTAB i = static_cast<SCTAB>(maTabs.size())+1;
diff --git a/sc/source/core/tool/docoptio.cxx b/sc/source/core/tool/docoptio.cxx
index 662d59c..693f7f6 100644
--- a/sc/source/core/tool/docoptio.cxx
+++ b/sc/source/core/tool/docoptio.cxx
@@ -46,6 +46,7 @@
 #include "sc.hrc"
 #include "miscuno.hxx"
 #include "global.hxx"
+#include "globstr.hrc"
 
 using namespace utl;
 using namespace com::sun::star::uno;
@@ -92,6 +93,7 @@ ScDocOptions::ScDocOptions( const ScDocOptions& rCpy )
         :   fIterEps( rCpy.fIterEps ),
             nIterCount( rCpy.nIterCount ),
             nInitTabCount( rCpy.nInitTabCount ),
+            aInitTabPrefix( rCpy.aInitTabPrefix ),
             nPrecStandardFormat( rCpy.nPrecStandardFormat ),
             eKeyBindingType( rCpy.eKeyBindingType ),
             nDay( rCpy.nDay ),
@@ -128,6 +130,7 @@ void ScDocOptions::ResetDocOptions()
     bIsIter                            = false;
     nIterCount                 = 100;
     nInitTabCount       = 3;
+    aInitTabPrefix      = ScGlobal::GetRscString(STR_TABLE_DEF); //"Sheet"
     fIterEps                   = 1.0E-3;
     nPrecStandardFormat = SvNumberFormatter::UNLIMITED_PRECISION;
     eKeyBindingType     = ScOptionsUtil::KEY_DEFAULT;
@@ -294,7 +297,8 @@ SfxPoolItem* ScTpCalcItem::Clone( SfxItemPool * ) const
 
 #define CFGPATH_DEFAULTS    "Office.Calc/Defaults"
 #define SCDEFAULTSOPT_TAB_COUNT     0
-#define SCDEFAULTSOPT_COUNT         1
+#define SCDEFAULTSOPT_TAB_PREFIX    1
+#define SCDEFAULTSOPT_COUNT         2
 
 
 Sequence<OUString> ScDocCfg::GetCalcPropertyNames()
@@ -376,7 +380,8 @@ Sequence<OUString> ScDocCfg::GetDefaultsPropertyNames()
 {
     static const char* aPropNames[] =
     {
-        "Other/TabCount"             // SCDEFAULTSOPT_COUNT_TAB_COUNT
+        "Other/TabCount",            // SCDEFAULTSOPT_TAB_COUNT
+        "Other/TabPrefix"            // SCDEFAULTSOPT_TAB_PREFIX
     };
     Sequence<OUString> aNames(SCDEFAULTSOPT_COUNT);
     OUString* pNames = aNames.getArray();
@@ -599,6 +604,12 @@ ScDocCfg::ScDocCfg() :
                 if (pValues[nProp] >>= nIntVal)
                     SetInitTabCount( static_cast<SCTAB>(nIntVal) );
                 break;
+            case SCDEFAULTSOPT_TAB_PREFIX:
+                OUString aPrefix;
+                if (pValues[nProp] >>= aPrefix)
+                    SetInitTabPrefix(aPrefix);
+                break;
+
             }
         }
     }
@@ -760,6 +771,9 @@ IMPL_LINK( ScDocCfg, DefaultsCommitHdl, void *, EMPTYARG )
         case SCDEFAULTSOPT_TAB_COUNT:
             pValues[nProp] <<= static_cast<sal_Int32>(GetInitTabCount());
         break;
+        case SCDEFAULTSOPT_TAB_PREFIX:
+            pValues[nProp] <<= GetInitTabPrefix();
+        break;
         }
     }
     aDefaultsItem.PutProperties(aNames, aValues);
diff --git a/sc/source/ui/inc/optdlg.hrc b/sc/source/ui/inc/optdlg.hrc
index 4cdb0a5..8b38f99 100644
--- a/sc/source/ui/inc/optdlg.hrc
+++ b/sc/source/ui/inc/optdlg.hrc
@@ -199,3 +199,5 @@
 #define FL_INIT_SPREADSHEET  1
 #define FT_NSHEETS           2
 #define ED_NSHEETS           3
+#define FT_SHEETPREFIX       4
+#define ED_SHEETPREFIX       4
\ No newline at end of file
diff --git a/sc/source/ui/inc/tpdefaults.hxx b/sc/source/ui/inc/tpdefaults.hxx
index 622a310..b139165 100644
--- a/sc/source/ui/inc/tpdefaults.hxx
+++ b/sc/source/ui/inc/tpdefaults.hxx
@@ -56,8 +56,11 @@ private:
     FixedLine     aFLInitSpreadSheet;
     FixedText     aFtNSheets;
     NumericField  aEdNSheets;
+    FixedText     aFtSheetPrefix;
+    Edit          aEdSheetPrefix;
 
-    ::boost::shared_ptr<ScDocOptions> mpLocalOptions;
+    ::boost::shared_ptr<ScDocOptions> mpOldOptions;
+    ::boost::shared_ptr<ScDocOptions> mpNewOptions;
 };
 
 #endif
diff --git a/sc/source/ui/optdlg/tpdefaults.cxx b/sc/source/ui/optdlg/tpdefaults.cxx
index 2436507..24c874e 100644
--- a/sc/source/ui/optdlg/tpdefaults.cxx
+++ b/sc/source/ui/optdlg/tpdefaults.cxx
@@ -37,17 +37,22 @@
 #include "scmod.hxx"
 #include "docoptio.hxx"
 
+using ::rtl::OUString;
+
 ScTpDefaultsOptions::ScTpDefaultsOptions(Window *pParent, const SfxItemSet &rCoreAttrs) :
     SfxTabPage(pParent, ScResId(RID_SCPAGE_DEFAULTS), rCoreAttrs),
     aFLInitSpreadSheet ( this, ScResId( FL_INIT_SPREADSHEET ) ),
     aFtNSheets         ( this, ScResId( FT_NSHEETS ) ),
-    aEdNSheets                    ( this, ScResId( ED_NSHEETS ) )
+    aEdNSheets                    ( this, ScResId( ED_NSHEETS ) ),
+    aFtSheetPrefix        ( this, ScResId( FT_SHEETPREFIX ) ),
+    aEdSheetPrefix        ( this, ScResId( ED_SHEETPREFIX ) )
 {
     FreeResource();
 
     const ScTpCalcItem& rItem = static_cast<const ScTpCalcItem&>(
         rCoreAttrs.Get(GetWhich(SID_SCDOCOPTIONS)));
-    mpLocalOptions.reset(new ScDocOptions(rItem.GetDocOptions()));
+    mpOldOptions.reset(new ScDocOptions(rItem.GetDocOptions()));
+    mpNewOptions.reset(new ScDocOptions(rItem.GetDocOptions()));
 }
 
 ScTpDefaultsOptions::~ScTpDefaultsOptions()
@@ -62,12 +67,14 @@ SfxTabPage* ScTpDefaultsOptions::Create(Window *pParent, const SfxItemSet &rCore
 sal_Bool ScTpDefaultsOptions::FillItemSet(SfxItemSet &rCoreAttrs)
 {
     SCTAB nTabCount = static_cast<SCTAB>(aEdNSheets.GetValue());
+    OUString aSheetPrefix = aEdSheetPrefix.GetText();
 
-    if (mpLocalOptions->GetInitTabCount() != nTabCount)
-    {
-        mpLocalOptions->SetInitTabCount( nTabCount );
+    mpNewOptions->SetInitTabCount( nTabCount );
+    mpNewOptions->SetInitTabPrefix( aSheetPrefix );
 
-        rCoreAttrs.Put(ScTpCalcItem(GetWhich(SID_SCDOCOPTIONS), *mpLocalOptions));
+    if (*mpNewOptions != *mpOldOptions)
+    {
+        rCoreAttrs.Put(ScTpCalcItem(GetWhich(SID_SCDOCOPTIONS), *mpNewOptions));
         return sal_True;
     }
     else
@@ -76,7 +83,8 @@ sal_Bool ScTpDefaultsOptions::FillItemSet(SfxItemSet &rCoreAttrs)
 
 void ScTpDefaultsOptions::Reset(const SfxItemSet& /*rCoreAttrs*/)
 {
-    aEdNSheets.SetValue( static_cast<sal_uInt16>(mpLocalOptions->GetInitTabCount()) );
+    aEdNSheets.SetValue( static_cast<sal_uInt16>(mpOldOptions->GetInitTabCount()) );
+    aEdSheetPrefix.SetText( mpOldOptions->GetInitTabPrefix() );
 }
 
 int ScTpDefaultsOptions::DeactivatePage(SfxItemSet* /*pSet*/)
@@ -84,4 +92,6 @@ int ScTpDefaultsOptions::DeactivatePage(SfxItemSet* /*pSet*/)
     return KEEP_PAGE;
 }
 
+//ScGlobal::GetRscString(STR_TABLE_DEF); //"Table"
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/src/optdlg.src b/sc/source/ui/src/optdlg.src
index b6f9fe3..fa4ae65 100644
--- a/sc/source/ui/src/optdlg.src
+++ b/sc/source/ui/src/optdlg.src
@@ -939,4 +939,17 @@ TabPage RID_SCPAGE_DEFAULTS
         Spin = TRUE ;
         Repeat = TRUE ;
     };
+    FixedText FT_SHEETPREFIX
+    {
+        Pos = MAP_APPFONT ( 12 , 32 ) ;
+        Size = MAP_APPFONT ( 120 , 8 ) ;
+        Text [ en-US ] = "Prefix name for new worksheet";
+    };
+    Edit ED_SHEETPREFIX
+    {
+        HelpID = "sc:Edit:RID_SCPAGE_CALC:ED_SHEETPREFIX";
+        Border = TRUE ;
+        Pos = MAP_APPFONT ( 130 , 32 ) ;
+        Size = MAP_APPFONT ( 45 , 12 ) ;
+    };
 };
-- 
1.7.3.4

From c7bcfb6c43fb03bdea04b1379f6da21dcc09ef2b Mon Sep 17 00:00:00 2001
From: Albert Thuswaldner <albert.thuswaldner@gmail.com>
Date: Sat, 2 Jul 2011 11:35:40 +0200
Subject: [PATCH] added option to set tab prefix

---
 .../registry/schema/org/openoffice/Office/Calc.xcs |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
index a5528eb..f205a34 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
@@ -1587,6 +1587,13 @@
                          </info>
                  <value>3</value>
                </prop>
+               <prop oor:name="TabPrefix" oor:type="xs:string">
+                         <!-- UIHints: Tools - Options - Spreadsheet - Defaults -->
+                         <info>
+                               <author>Albert Thuswaldner</author>
+                               <desc>Option to set the prefix name for new tabs</desc>
+                         </info>
+               </prop>
          </group>
        </group>
       </component>
-- 
1.7.3.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.