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


Hi,

       Shows a number of likely candidates; connecting to the 'ModifyHdl'
and running the validator on the name, removing characters if it not valid
might work; but of course.

       git grep SetModifyHdl

       for some instances of that; possibly we don't want to stop user input,
but have a FixedLine that says "invalid entry, last valid name was
'foo'" or whatever (?).


Ok, it was that easy. I was sure you needed some black magic to get
that working. Thanks Michael for your help.

I have now a new patch with all the changes Kohei suggested earlier.
Could someone have a look at it and then maybe push it to master?

Thanks.

/Albert
From 29215c285e5f58419fd4ddcf11bef258f216603c Mon Sep 17 00:00:00 2001
From: Albert Thuswaldner <albert.thuswaldner@gmail.com>
Date: Sat, 28 Jan 2012 00:28:18 +0100
Subject: [PATCH] Option to set tab prefix for new worksheets

---
 .../registry/schema/org/openoffice/Office/Calc.xcs |   13 ++++-
 sc/inc/docoptio.hxx                                |    7 +++-
 sc/source/core/data/document.cxx                   |   16 ++++++-
 sc/source/core/tool/docoptio.cxx                   |   17 ++++++-
 sc/source/ui/inc/optdlg.hrc                        |    2 +
 sc/source/ui/inc/tpdefaults.hxx                    |    7 +++-
 sc/source/ui/optdlg/tpdefaults.cxx                 |   46 ++++++++++++++++---
 sc/source/ui/src/optdlg.src                        |   13 ++++++
 8 files changed, 103 insertions(+), 18 deletions(-)

diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
index 79ebc2e..bfb3686 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
@@ -1610,11 +1610,11 @@
          <info>
                <desc>Contains various defaults settings.</desc>
          </info>
-         <group oor:name="Other">
+         <group oor:name="Sheet">
                <info>
-                         <desc>Other Program defaults</desc>
+                         <desc>Sheet defaults</desc>
                </info>
-               <prop oor:name="TabCount" oor:type="xs:int">
+               <prop oor:name="SheetCount" oor:type="xs:int">
                          <!-- UIHints: Tools - Options - Spreadsheet - Defaults -->
                          <info>
                                <author>Albert Thuswaldner</author>
@@ -1622,6 +1622,13 @@
                          </info>
                  <value>3</value>
                </prop>
+               <prop oor:name="SheetPrefix" oor:type="xs:string">
+                         <!-- UIHints: Tools - Options - Spreadsheet - Defaults -->
+                         <info>
+                               <author>Albert Thuswaldner</author>
+                               <desc>Option to set the prefix name for new sheet tabs</desc>
+                         </info>
+               </prop>
          </group>
        </group>
       </component>
diff --git a/sc/inc/docoptio.hxx b/sc/inc/docoptio.hxx
index 8557a82..a960ec0 100644
--- a/sc/inc/docoptio.hxx
+++ b/sc/inc/docoptio.hxx
@@ -42,7 +42,8 @@ class SC_DLLPUBLIC ScDocOptions
 {
     double fIterEps;                // epsilon value dazu
     sal_uInt16 nIterCount;              // number
-    SCTAB nInitTabCount;            // number of Tabs for new Spreadssheet doc
+    SCTAB nInitTabCount;            // number of Tabs for new Spreadsheet doc
+    ::rtl::OUString aInitTabPrefix;   // The Tab prefix name 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 bool 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/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index dbc4cec..c18a8f5 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -95,6 +95,7 @@
 #include "tabprotection.hxx"
 #include "clipparam.hxx"
 #include "stlalgorithm.hxx"
+#include "docoptio.hxx"
 
 #include <map>
 #include <limits>
@@ -142,7 +143,10 @@ void ScDocument::MakeTable( SCTAB nTab,bool _bNeedsNameCheck )
 {
     if ( ValidTab(nTab) && ( nTab >= static_cast<SCTAB>(maTabs.size()) ||!maTabs[nTab]) )
     {
-        rtl::OUString aString = ScGlobal::GetRscString(STR_TABLE_DEF); //"Table"
+        // Get Custom prefix
+        const ScDocOptions& rDocOpt = SC_MOD()->GetDocOptions();
+        rtl::OUString aString = static_cast<String>(rDocOpt.GetInitTabPrefix());
+
         aString += rtl::OUString::valueOf(static_cast<sal_Int32>(nTab+1));
         if ( _bNeedsNameCheck )
             CreateValidTabName( aString );  // no doubles
@@ -331,7 +335,10 @@ void ScDocument::CreateValidTabName(rtl::OUString& rName) const
     {
         // Find new one
 
-        const rtl::OUString aStrTable( ResId::toString(ScResId(SCSTR_TABLE)) );
+        // Get Custom prefix
+        const ScDocOptions& rDocOpt = SC_MOD()->GetDocOptions();
+        rtl::OUString aStrTable = static_cast<String>(rDocOpt.GetInitTabPrefix());
+
         bool         bOk   = false;
 
         // First test if the prefix is valid, if so only avoid doubles
@@ -376,7 +383,10 @@ void ScDocument::CreateValidTabNames(std::vector<rtl::OUString>& aNames, SCTAB 
n
 {
     aNames.clear();//ensure that the vector is empty
 
-    const rtl::OUString aStrTable( ResId::toString(ScResId(SCSTR_TABLE)) );
+    // Get Custom prefix
+    const ScDocOptions& rDocOpt = SC_MOD()->GetDocOptions();
+    rtl::OUString aStrTable = static_cast<String>(rDocOpt.GetInitTabPrefix());
+
     rtl::OUStringBuffer rName;
     bool         bOk   = false;
 
diff --git a/sc/source/core/tool/docoptio.cxx b/sc/source/core/tool/docoptio.cxx
index 3247eca..56b8871 100644
--- a/sc/source/core/tool/docoptio.cxx
+++ b/sc/source/core/tool/docoptio.cxx
@@ -44,6 +44,7 @@
 #include "sc.hrc"
 #include "miscuno.hxx"
 #include "global.hxx"
+#include "globstr.hrc"
 
 using namespace utl;
 using namespace com::sun::star::uno;
@@ -88,6 +89,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 ),
@@ -124,6 +126,7 @@ void ScDocOptions::ResetDocOptions()
     bIsIter             = false;
     nIterCount          = 100;
     nInitTabCount       = 3;
+    aInitTabPrefix      = ScGlobal::GetRscString(STR_TABLE_DEF); // Default Prefix "Sheet"
     fIterEps            = 1.0E-3;
     nPrecStandardFormat = SvNumberFormatter::UNLIMITED_PRECISION;
     eKeyBindingType     = ScOptionsUtil::KEY_DEFAULT;
@@ -290,7 +293,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()
@@ -372,7 +376,8 @@ Sequence<OUString> ScDocCfg::GetDefaultsPropertyNames()
 {
     static const char* aPropNames[] =
     {
-        "Other/TabCount"             // SCDEFAULTSOPT_COUNT_TAB_COUNT
+        "Sheet/SheetCount",            // SCDEFAULTSOPT_TAB_COUNT
+        "Sheet/SheetPrefix"            // SCDEFAULTSOPT_TAB_PREFIX
     };
     Sequence<OUString> aNames(SCDEFAULTSOPT_COUNT);
     OUString* pNames = aNames.getArray();
@@ -595,6 +600,11 @@ 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;
             }
         }
     }
@@ -756,6 +766,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 15c32cf..5245bc6 100644
--- a/sc/source/ui/inc/optdlg.hrc
+++ b/sc/source/ui/inc/optdlg.hrc
@@ -198,3 +198,5 @@
 #define FL_INIT_SPREADSHEET  1
 #define FT_NSHEETS           2
 #define ED_NSHEETS           3
+#define FT_SHEETPREFIX       4
+#define ED_SHEETPREFIX       5
diff --git a/sc/source/ui/inc/tpdefaults.hxx b/sc/source/ui/inc/tpdefaults.hxx
index 374d0bc..606d174 100644
--- a/sc/source/ui/inc/tpdefaults.hxx
+++ b/sc/source/ui/inc/tpdefaults.hxx
@@ -53,15 +53,20 @@ private:
     virtual ~ScTpDefaultsOptions();
 
     void CheckNumSheets();
+    void CheckPrefix();
 
     DECL_LINK( NumModifiedHdl, NumericField* );
+    DECL_LINK( PrefixModifiedHdl, Edit* );
 
 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 bd1cc68..70f0f63 100644
--- a/sc/source/ui/optdlg/tpdefaults.cxx
+++ b/sc/source/ui/optdlg/tpdefaults.cxx
@@ -29,28 +29,39 @@
 
 #undef SC_DLLIMPLEMENTATION
 
+#include <vcl/msgbox.hxx>
+
 #include "tpdefaults.hxx"
 #include "optdlg.hrc"
 #include "scresid.hxx"
 #include "scmod.hxx"
 #include "docoptio.hxx"
+#include "document.hxx"
+#include "global.hxx"
+#include "globstr.hrc"
 
 #define INIT_SHEETS_MIN 1
 #define INIT_SHEETS_MAX 1024
 
+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()));
 
     aEdNSheets.SetModifyHdl( LINK(this, ScTpDefaultsOptions, NumModifiedHdl) );
+    aEdSheetPrefix.SetModifyHdl( LINK(this, ScTpDefaultsOptions, PrefixModifiedHdl) );
 }
 
 ScTpDefaultsOptions::~ScTpDefaultsOptions()
@@ -65,12 +76,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
@@ -79,8 +92,8 @@ sal_Bool ScTpDefaultsOptions::FillItemSet(SfxItemSet &rCoreAttrs)
 
 void ScTpDefaultsOptions::Reset(const SfxItemSet& /*rCoreAttrs*/)
 {
-    aEdNSheets.SetValue( static_cast<sal_uInt16>(mpLocalOptions->GetInitTabCount()) );
-    CheckNumSheets();
+    aEdNSheets.SetValue( static_cast<sal_uInt16>(mpOldOptions->GetInitTabCount()) );
+    aEdSheetPrefix.SetText( mpOldOptions->GetInitTabPrefix() );
 }
 
 int ScTpDefaultsOptions::DeactivatePage(SfxItemSet* /*pSet*/)
@@ -97,10 +110,27 @@ void ScTpDefaultsOptions::CheckNumSheets()
         aEdNSheets.SetValue(INIT_SHEETS_MIN);
 }
 
+void ScTpDefaultsOptions::CheckPrefix()
+{
+    OUString aSheetPrefix = aEdSheetPrefix.GetText();
+
+    if ( !ScDocument::ValidTabName( aSheetPrefix ) )
+    {
+         ErrorBox(this,WinBits(WB_OK|WB_DEF_OK), ScGlobal::GetRscString(STR_INVALIDTABNAME) 
).Execute();
+    }
+}
+
+
 IMPL_LINK( ScTpDefaultsOptions, NumModifiedHdl, NumericField*, EMPTYARG )
 {
     CheckNumSheets();
     return 0;
 }
 
+IMPL_LINK( ScTpDefaultsOptions, PrefixModifiedHdl, Edit*, EMPTYARG )
+{
+    CheckPrefix();
+    return 0;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/src/optdlg.src b/sc/source/ui/src/optdlg.src
index 93378d1..147bdee 100644
--- a/sc/source/ui/src/optdlg.src
+++ b/sc/source/ui/src/optdlg.src
@@ -940,4 +940,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


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.