diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-11-20 08:22:02 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-11-23 06:25:32 +0100 |
commit | 42bb6baae411dcef47fbe8555412960be2c0dfad (patch) | |
tree | 547f04e789bc2b9ad9eef903ab6ba7ffd2c411d2 /sc | |
parent | b5a509e21704e6dba31eabac689c35efd8dda973 (diff) |
ManageNames: make Multiselection work in the table
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/namemgrtable.hxx | 8 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namedlg.cxx | 126 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namemgrtable.cxx | 55 |
3 files changed, 125 insertions, 64 deletions
diff --git a/sc/source/ui/inc/namemgrtable.hxx b/sc/source/ui/inc/namemgrtable.hxx index efe7bc297f49..8331a731dc80 100644 --- a/sc/source/ui/inc/namemgrtable.hxx +++ b/sc/source/ui/inc/namemgrtable.hxx @@ -28,6 +28,8 @@ #include <svtools/headbar.hxx> #include <svtools/svtabbx.hxx> +#include <vector> + struct ScRangeNameLine { rtl::OUString aName; @@ -46,14 +48,20 @@ private: ScRangeName* mpGlobalRangeName; std::map<rtl::OUString, ScRangeName*> maTabRangeNames; rtl::OUString maGlobalString; + + void GetLine(ScRangeNameLine& aLine, SvLBoxEntry* pEntry); + public: ScRangeManagerTable( Window* pParent, ScRangeName* pGlobalRangeName, std::map<rtl::OUString, ScRangeName*> aTabRangeNames ); ~ScRangeManagerTable() {}; void addEntry( const ScRangeNameLine& rLine ); + void DeleteSelectedEntries(); void GetCurrentLine(ScRangeNameLine& rLine); void UpdateEntries(); + bool IsMultiSelection(); + std::vector<ScRangeNameLine> GetSelectedEntries(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/namedlg/namedlg.cxx b/sc/source/ui/namedlg/namedlg.cxx index 26237b94f66c..11d9ba2cc28e 100644 --- a/sc/source/ui/namedlg/namedlg.cxx +++ b/sc/source/ui/namedlg/namedlg.cxx @@ -53,6 +53,7 @@ #include <map> #include <memory> +#include <iostream> using ::std::auto_ptr; @@ -282,6 +283,11 @@ bool ScNameDlg::IsNameValid() return true; } +bool ScNameDlg::IsFormulaValid() +{ + return true; +} + //updates the table and the buttons void ScNameDlg::UpdateNames() { @@ -376,69 +382,93 @@ bool ScNameDlg::AddPushed() void ScNameDlg::RemovePushed() { - ScRangeNameLine aLine; - mpRangeManagerTable->GetCurrentLine(aLine); - rtl::OUString aName = aLine.aName; - rtl::OUString aScope = aLine.aScope; - rtl::OUString aExpr = aLine.aExpression; - ScRangeName* pRangeName = GetRangeName(aScope, mpDoc); - - ScRangeData* pData = pRangeName->findByName(aName); - if (pData) + std::vector<ScRangeNameLine> maEntries = mpRangeManagerTable->GetSelectedEntries(); + mpRangeManagerTable->DeleteSelectedEntries(); + for (std::vector<ScRangeNameLine>::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr) { - sal_Int32 nIndex = 0; - rtl::OUString aStrDelMsg = ScGlobal::GetRscString( STR_QUERY_DELENTRY ); - rtl::OUStringBuffer aMsg = aStrDelMsg.getToken( 0, '#', nIndex ); - aMsg.append(aName); - aMsg.append(aStrDelMsg.getToken( 1, '#', nIndex)); - - if (RET_YES == - QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg.makeStringAndClear() ).Execute() ) - { + ScRangeName* pRangeName = GetRangeName( itr->aScope, mpDoc ); + std::cout << rtl::OUStringToOString(itr->aName, RTL_TEXTENCODING_UTF8).getStr() << std::endl; + std::cout << rtl::OUStringToOString(ScGlobal::pCharClass->upper(itr->aName), RTL_TEXTENCODING_UTF8).getStr() << std::endl;; + ScRangeData* pData = pRangeName->findByUpperName(ScGlobal::pCharClass->upper(itr->aName)); + OSL_ENSURE(pData, "table and model should be in sync"); + // be safe and check for possible problems + if (pData) pRangeName->erase(*pData); - UpdateNames(); - SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) ); - } } } void ScNameDlg::NameModified() { - IsNameValid(); - rtl::OUString aName = maEdName.GetText(); - aName = aName.trim(); - rtl::OUString aExpr = maEdAssign.GetText(); - rtl::OUString aScope = maLbScope.GetSelectEntry(); - - if (!aName.getLength() || !ScRangeData::IsNameValid(aName, mpDoc)) + if (IsNameValid() && IsFormulaValid()) { - maBtnAdd.Disable(); - } - else - { - ScRangeName* pRangeName = GetRangeName(aScope, mpDoc); - if (pRangeName->findByName(aName)) - { - maBtnAdd.Disable(); - } - else - { - maBtnAdd.Enable(); - } ScRangeNameLine aLine; mpRangeManagerTable->GetCurrentLine(aLine); + + rtl::OUString aOldName = aLine.aName; + rtl::OUString aOldScope = aLine.aScope; + rtl::OUString aNewName = maEdName.GetText(); + aNewName = aNewName.trim(); + rtl::OUString aExpr = maEdAssign.GetText(); + rtl::OUString aNewScope = maLbScope.GetSelectEntry(); + + ScRangeName* pOldRangeName = GetRangeName( aOldScope, mpDoc ); + ScRangeData* pData = pOldRangeName->findByUpperName( ScGlobals::pCharClass->upper(aOldName) ); + ScRangeName* pNewRangeName = GetRangeName( aNewScope, mpDoc ); + OSL_ENSURE(pData, "model and table should be in sync"); + // be safe and check for range data + if (pData) + { + pOldRangeName->erase(*pData); + mpRangeManagerTable->DeleteSelectedEntries(); + RangeType nType = RT_NAME | + (maBtnRowHeader.IsChecked() ? RT_ROWHEADER : RangeType(0)) + |(maBtnColHeader.IsChecked() ? RT_COLHEADER : RangeType(0)) + |(maBtnPrintArea.IsChecked() ? RT_PRINTAREA : RangeType(0)) + |(maBtnCriteria.IsChecked() ? RT_CRITERIA : RangeType(0)); + + ScRangeData* pNewEntry = new ScRangeData( mpDoc, aNewName, aExpr, + maCursorPos, nType); + pNewRangeName->insert(pNewEntry); + ScRangeNameLine aLine; + aLine.aName = aNewName; + aLine.aExpression = aExpr; + aLine.aScope = aNewScope; + mpRangeManagerTable->addEntry(aLine); + } } } void ScNameDlg::SelectionChanged() { - ScRangeNameLine aLine; - mpRangeManagerTable->GetCurrentLine(aLine); - maEdAssign.SetText(aLine.aExpression); - maEdName.SetText(aLine.aName); - maLbScope.SelectEntry(aLine.aScope); - ShowOptions(aLine); - maBtnDelete.Enable(); + if (mpRangeManagerTable->IsMultiSelection()) + { + maEdName.Disable(); + maEdAssign.Disable(); + maLbScope.Disable(); + maBtnSelect.Disable(); + maBtnRowHeader.Disable(); + maBtnColHeader.Disable(); + maBtnPrintArea.Disable(); + maBtnCriteria.Disable(); + } + else + { + ScRangeNameLine aLine; + mpRangeManagerTable->GetCurrentLine(aLine); + maEdAssign.SetText(aLine.aExpression); + maEdName.SetText(aLine.aName); + maLbScope.SelectEntry(aLine.aScope); + ShowOptions(aLine); + maBtnDelete.Enable(); + maEdName.Enable(); + maEdAssign.Enable(); + maLbScope.Enable(); + maBtnSelect.Enable(); + maBtnRowHeader.Enable(); + maBtnColHeader.Enable(); + maBtnPrintArea.Enable(); + maBtnCriteria.Enable(); + } } void ScNameDlg::ScopeChanged() diff --git a/sc/source/ui/namedlg/namemgrtable.cxx b/sc/source/ui/namedlg/namemgrtable.cxx index 40309d8f4ed7..5528efb2b168 100644 --- a/sc/source/ui/namedlg/namemgrtable.cxx +++ b/sc/source/ui/namedlg/namemgrtable.cxx @@ -35,6 +35,7 @@ #include "namedlg.hrc" #include "namedlg.hxx" #include "viewdata.hxx" +#include "globalnames.hxx" #include "sfx2/app.hxx" @@ -83,6 +84,7 @@ ScRangeManagerTable::ScRangeManagerTable( Window* pWindow, ScRangeName* pGlobalR Show(); maHeaderBar.Show(); + SetSelectionMode(MULTIPLE_SELECTION); } void ScRangeManagerTable::addEntry(const ScRangeNameLine& rLine) @@ -94,32 +96,28 @@ void ScRangeManagerTable::addEntry(const ScRangeNameLine& rLine) void ScRangeManagerTable::GetCurrentLine(ScRangeNameLine& rLine) { SvLBoxEntry* pCurrentEntry = GetCurEntry(); - rLine.aName = GetEntryText( pCurrentEntry, 0); - rLine.aExpression = GetEntryText(pCurrentEntry, 1); - rLine.aScope = GetEntryText(pCurrentEntry, 2); + GetLine(rLine, pCurrentEntry); +} + +void ScRangeManagerTable::GetLine(ScRangeNameLine& rLine, SvLBoxEntry* pEntry) +{ + rLine.aName = GetEntryText( pEntry, 0); + rLine.aExpression = GetEntryText(pEntry, 1); + rLine.aScope = GetEntryText(pEntry, 2); } void ScRangeManagerTable::UpdateEntries() { Clear(); - for (ScRangeName::iterator itr = mpGlobalRangeName->begin(); - itr != mpGlobalRangeName->end(); ++itr) - { - if (!itr->HasType(RT_DATABASE) && !itr->HasType(RT_SHARED)) - { - ScRangeNameLine aLine; - aLine.aName = itr->GetName(); - aLine.aScope = maGlobalString; - itr->GetSymbol(aLine.aExpression); - addEntry(aLine); - } - } for (std::map<rtl::OUString, ScRangeName*>::iterator itr = maTabRangeNames.begin(); itr != maTabRangeNames.end(); ++itr) { ScRangeName* pLocalRangeName = itr->second; ScRangeNameLine aLine; - aLine.aScope = itr->first; + if (itr->first == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_GLOBAL_RANGE_NAME))) + aLine.aScope = maGlobalString; + else + aLine.aScope = itr->first; for (ScRangeName::iterator it = pLocalRangeName->begin(); it != pLocalRangeName->end(); ++it) { @@ -133,6 +131,31 @@ void ScRangeManagerTable::UpdateEntries() } } +void ScRangeManagerTable::DeleteSelectedEntries() +{ + RemoveSelection(); +} + +bool ScRangeManagerTable::IsMultiSelection() +{ + return GetSelectionCount() > 1; +} + +std::vector<ScRangeNameLine> ScRangeManagerTable::GetSelectedEntries() +{ + std::vector<ScRangeNameLine> aSelectedEntries; + for (SvLBoxEntry* pEntry = FirstSelected(); pEntry != LastSelected(); pEntry = NextSelected(pEntry)) + { + ScRangeNameLine aLine; + GetLine( aLine, pEntry ); + aSelectedEntries.push_back(aLine); + } + SvLBoxEntry* pEntry = LastSelected(); + ScRangeNameLine aLine; + GetLine( aLine, pEntry ); + aSelectedEntries.push_back(aLine); + return aSelectedEntries; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |