diff options
author | Gulsah Kose <gulsah.1004@gmail.com> | 2017-04-19 16:29:43 +0300 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-05-11 16:12:11 +0200 |
commit | 198f5a16fd4c5bf691a3450bbf16e88c000f9baa (patch) | |
tree | 347f5ca8aab1e0ebb4e720b03d62989b7dd86bd1 /sc | |
parent | 0496587f1bf271ef0540f3cd8155889311480d70 (diff) |
tdf#107258 Create show/hide all comments toggle button.
Created new show/hide all comments button for calc by
ShowAnnotations command. Unifyied writer, calc and impress's
ShowAnnotations slot.
Change-Id: I27149d09ee1763b84258c5e0c890a9628c8874c0
Signed-off-by: Gulsah Kose <gulsah.1004@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/36697
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/document.hxx | 12 | ||||
-rw-r--r-- | sc/inc/table.hxx | 2 | ||||
-rw-r--r-- | sc/sdi/cellsh.sdi | 1 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 30 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 33 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh.cxx | 26 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 35 | ||||
-rw-r--r-- | sc/uiconfig/scalc/menubar/menubar.xml | 1 |
8 files changed, 138 insertions, 2 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 26547d24ced4..29f8af4d849d 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -238,6 +238,13 @@ enum ScDocumentMode SCDOCMODE_UNDO }; +enum CommentCaptionState +{ + ALLSHOWN, // All comments captions are shown + ALLHIDDEN, // All comments captions are hidden + MIXED // There are comments in shown and hidden. +}; + struct ScDocStat { OUString aDocName; @@ -1103,8 +1110,9 @@ public: * Ensure that all note objects have an associated sdr object. The export * code uses sdr objects to export note data. */ - void CreateAllNoteCaptions(); - void ForgetNoteCaptions( const ScRangeList& rRanges, bool bPreserveData ); + void CreateAllNoteCaptions(); + void ForgetNoteCaptions( const ScRangeList& rRanges, bool bPreserveData ); + CommentCaptionState GetAllNoteCaptionsState( const ScRangeList& rRanges); ScAddress GetNotePosition( size_t nIndex ) const; ScAddress GetNotePosition( size_t nIndex, SCTAB nTab ) const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 66ded63e9472..87ba9c6df206 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -36,6 +36,7 @@ #include <formula/types.hxx> #include "calcmacros.hxx" #include "formula/errorcodes.hxx" +#include "document.hxx" #include <set> #include <map> @@ -432,6 +433,7 @@ public: void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const; void GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) const; + CommentCaptionState GetAllNoteCaptionsState( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ); bool ContainsNotesInRange( const ScRange& rRange ) const; bool TestInsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize ) const; diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi index 8e80db555901..6812a2d4bd89 100644 --- a/sc/sdi/cellsh.sdi +++ b/sc/sdi/cellsh.sdi @@ -209,6 +209,7 @@ interface CellSelection FID_NOTE_VISIBLE [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] FID_HIDE_NOTE [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] FID_SHOW_NOTE [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] + SID_TOGGLE_NOTES [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] FID_HIDE_ALL_NOTES [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] FID_SHOW_ALL_NOTES [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] FID_DELETE_ALL_NOTES [ ExecMethod = ExecuteEdit; StateMethod = GetState; ] diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 918cce784866..d96451afacad 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -6501,6 +6501,36 @@ void ScDocument::ForgetNoteCaptions( const ScRangeList& rRanges, bool bPreserveD } } +CommentCaptionState ScDocument::GetAllNoteCaptionsState( const ScRangeList& rRanges ) +{ + CommentCaptionState aOldState, aState = CommentCaptionState::ALLHIDDEN; //because of Werror=maybe-uninitialized + std::vector<sc::NoteEntry> aNotes; + + for (size_t i = 0, n = rRanges.size(); i < n; ++i) + { + const ScRange* pRange = rRanges[i]; + + for( SCTAB nTab = pRange->aStart.Tab(); nTab <= pRange->aEnd.Tab(); ++nTab ) + { + aState = maTabs[nTab]->GetAllNoteCaptionsState( *pRange, aNotes ); + if (aState == CommentCaptionState::MIXED) + return aState; + + if (nTab - 1 >= 0) // it is possible that a range is ALLSHOWN, another range is ALLHIDDEN, + { // we have to detect that situation as mixed. + aOldState = maTabs[nTab-1]->GetAllNoteCaptionsState( *pRange, aNotes ); + + if (aState != aOldState) + { + aState = CommentCaptionState::MIXED; + return aState; + } + } + } + } + return aState; +} + ScAddress ScDocument::GetNotePosition( size_t nIndex ) const { for (size_t nTab = 0; nTab < maTabs.size(); ++nTab) diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index edd9378bd200..6c770797f44c 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1614,6 +1614,39 @@ void ScTable::GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry> } } +CommentCaptionState ScTable::GetAllNoteCaptionsState(const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) +{ + SCROW nStartRow = rRange.aStart.Row(); + SCROW nEndRow = rRange.aEnd.Row(); + bool bIsFirstNoteShownState = true; // because of error: -Werror=maybe-uninitialized + bool bFirstControl = true; + + for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol) + { + if (bFirstControl && pDocument->HasColNotes(nCol, nTab)) // detect status of first note caption + { + aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes); + bIsFirstNoteShownState = rNotes.begin()->mpNote->IsCaptionShown(); + bFirstControl = false; + } + + if (pDocument->HasColNotes(nCol, nTab)) + { + aCol[nCol].GetNotesInRange(nStartRow, nEndRow, rNotes); + + for(std::vector<sc::NoteEntry>::const_iterator itr = rNotes.begin(), + itrEnd = rNotes.end(); itr != itrEnd; ++itr) + { + if ( bIsFirstNoteShownState != itr->mpNote->IsCaptionShown()) // compare the first note caption with others + { + return CommentCaptionState::MIXED; + } + } + } + } + return (bIsFirstNoteShownState) ? CommentCaptionState::ALLSHOWN : CommentCaptionState::ALLHIDDEN; +} + bool ScTable::ContainsNotesInRange( const ScRange& rRange ) const { SCROW nStartRow = rRange.aStart.Row(); diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index cd65b89645e1..79d356e1a86f 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -1041,6 +1041,7 @@ void ScCellShell::GetState(SfxItemSet &rSet) case FID_DELETE_ALL_NOTES: { bool bHasNotes = false; + for (auto const& rTab : rMark.GetSelectedTabs()) { if (pDoc->HasTabNotes( rTab )) @@ -1055,6 +1056,31 @@ void ScCellShell::GetState(SfxItemSet &rSet) } break; + case SID_TOGGLE_NOTES: + { + bool bHasNotes = false; + ScRangeList aRanges; + + for (auto const& rTab : rMark.GetSelectedTabs()) + { + if (pDoc->HasTabNotes( rTab )) + { + bHasNotes = true; + aRanges.Append(ScRange(0,0,rTab,MAXCOL,MAXROW,rTab)); + } + } + + if ( !bHasNotes ) + rSet.DisableItem( nWhich ); + else + { + CommentCaptionState eState = pDoc->GetAllNoteCaptionsState( aRanges ); + bool bAllNotesInShown = !(eState == ALLHIDDEN || eState == MIXED); + rSet.Put( SfxBoolItem( SID_TOGGLE_NOTES, bAllNotesInShown) ); + } + } + break; + case SID_DELETE_NOTE: { bool bEnable = false; diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 05f6397a4ed3..ce3fe707a663 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -2356,6 +2356,41 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) } break; + case SID_TOGGLE_NOTES: + { + ScViewData* pData = GetViewData(); + ScMarkData& rMark = pData->GetMarkData(); + ScDocument* pDoc = pData->GetDocument(); + ScRangeList aRanges; + std::vector<sc::NoteEntry> aNotes; + + for (auto const& rTab : rMark.GetSelectedTabs()) + aRanges.Append(ScRange(0,0,rTab,MAXCOL,MAXROW,rTab)); + + CommentCaptionState eState = pDoc->GetAllNoteCaptionsState( aRanges ); + pDoc->GetNotesInRange(aRanges, aNotes); + bool bShowNote = (eState == ALLHIDDEN || eState == MIXED); + + OUString aUndo = ScGlobal::GetRscString( bShowNote ? STR_UNDO_SHOWALLNOTES : STR_UNDO_HIDEALLNOTES ); + pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pData->GetViewShell()->GetViewShellId() ); + + for(std::vector<sc::NoteEntry>::const_iterator itr = aNotes.begin(), + itrEnd = aNotes.end(); itr != itrEnd; ++itr) + { + const ScAddress& rAdr = itr->maPos; + pData->GetDocShell()->GetDocFunc().ShowNote( rAdr, bShowNote ); + } + + pData->GetDocShell()->GetUndoManager()->LeaveListAction(); + + if (!pReqArgs) + rReq.AppendItem( SfxBoolItem( SID_TOGGLE_NOTES, bShowNote ) ); + + rReq.Done(); + rBindings.Invalidate( SID_TOGGLE_NOTES ); + } + break; + case SID_DELETE_NOTE: { const SfxPoolItem* pId; diff --git a/sc/uiconfig/scalc/menubar/menubar.xml b/sc/uiconfig/scalc/menubar/menubar.xml index 3f61a0220218..a6acb537dc79 100644 --- a/sc/uiconfig/scalc/menubar/menubar.xml +++ b/sc/uiconfig/scalc/menubar/menubar.xml @@ -147,6 +147,7 @@ <menu:menuitem menu:id=".uno:ViewRowColumnHeaders"/> <menu:menuitem menu:id=".uno:ViewValueHighlighting"/> <menu:menuitem menu:id=".uno:ToggleFormula"/> + <menu:menuitem menu:id=".uno:ShowAnnotations"/> <menu:menu menu:id=".uno:GridMenu"> <menu:menupopup> <menu:menuitem menu:id=".uno:GridVisible"/> |