tdf#84837 Add Show/Hide all comments commands to Calc.

Change-Id: I1e38335ff1269d0d464f03d23bfc5eba6e3b1532
Signed-off-by: Gulsah Kose <gulsah.1004@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/35020
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index 6c16833..80cedf0 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -951,6 +951,16 @@
          <value xml:lang="en-US">Hide Comment</value>
        </prop>
      </node>
      <node oor:name=".uno:ShowAllNotes" oor:op="replace">
        <prop oor:name="Label" oor:type="xs:string">
          <value xml:lang="en-US">Show All Comments</value>
        </prop>
      </node>
      <node oor:name=".uno:HideAllNotes" oor:op="replace">
        <prop oor:name="Label" oor:type="xs:string">
          <value xml:lang="en-US">Hide All Comments</value>
        </prop>
      </node>
      <node oor:name=".uno:InsertAnnotation" oor:op="replace">
        <prop oor:name="Label" oor:type="xs:string">
          <value xml:lang="en-US">Comm~ent</value>
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index bb28fb5..2751c6a 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1104,6 +1104,7 @@ public:
    SCROW     GetNotePosition( SCTAB nTab, SCCOL nCol, size_t nIndex ) const;

    SC_DLLPUBLIC void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const;
    SC_DLLPUBLIC void GetAllNoteEntries( SCTAB nTab, std::vector<sc::NoteEntry>& rNotes ) const;
    void              GetNotesInRange( const ScRangeList& rRange, std::vector<sc::NoteEntry>& rNotes ) const;
    bool              ContainsNotesInRange( const ScRangeList& rRange ) const;

diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 6696945..eadfc9f 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -232,6 +232,8 @@
#define STR_UNDO_SHOWNOTE           176
#define STR_UNDO_HIDENOTE           177
#define STR_UNDO_DRAGDROP           178
#define STR_UNDO_SHOWALLNOTES       179
#define STR_UNDO_HIDEALLNOTES       180

#define STR_IMPORT_LOTUS            182
#define STR_IMPORT_DBF              183
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 1fed694..b6f24ae 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -643,6 +643,8 @@

#define FID_SHOW_NOTE           (SID_NEW_SLOTS+100)
#define FID_HIDE_NOTE           (SID_NEW_SLOTS+101)
#define FID_SHOW_ALL_NOTES      (SID_NEW_SLOTS+102)
#define FID_HIDE_ALL_NOTES      (SID_NEW_SLOTS+103)

// idl parameter

diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 1daea78..0ec5226 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -210,6 +210,8 @@ interface CellSelection
    FID_NOTE_VISIBLE        [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
    FID_HIDE_NOTE           [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
    FID_SHOW_NOTE           [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
    FID_HIDE_ALL_NOTES      [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
    FID_SHOW_ALL_NOTES      [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
    SID_DELETE_NOTE         [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
    SID_DEC_INDENT          [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
    SID_INC_INDENT          [ ExecMethod = ExecuteEdit; StateMethod = GetState; ]
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index e95b747..e57338f 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -3616,6 +3616,41 @@ SfxBoolItem HideNote FID_HIDE_NOTE
    GroupId = GID_VIEW;
]

SfxVoidItem ShowAllNotes FID_SHOW_ALL_NOTES

[
    AutoUpdate = FALSE,
    FastCall = FALSE,
    ReadOnlyDoc = TRUE,
    Toggle = FALSE,
    Container = FALSE,
    RecordAbsolute = FALSE,
    RecordPerSet;


    AccelConfig = TRUE,
    MenuConfig = TRUE,
    ToolBoxConfig = TRUE,
    GroupId = GID_VIEW;
]

SfxVoidItem HideAllNotes FID_HIDE_ALL_NOTES

[
    AutoUpdate = FALSE,
    FastCall = FALSE,
    ReadOnlyDoc = TRUE,
    Toggle = FALSE,
    Container = FALSE,
    RecordAbsolute = FALSE,
    RecordPerSet;


    AccelConfig = TRUE,
    MenuConfig = TRUE,
    ToolBoxConfig = TRUE,
    GroupId = GID_VIEW;
]

SfxVoidItem DeleteNote SID_DELETE_NOTE
(SvxPostItIdItem Id SID_ATTR_POSTIT_ID)
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 0c680fe..92c9645 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6577,6 +6577,15 @@ void ScDocument::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
    }
}

void ScDocument::GetAllNoteEntries( SCTAB nTab, std::vector<sc::NoteEntry>& rNotes ) const
{
    const ScTable* pTab = FetchTable(nTab);
    if (!pTab)
        return;

    return pTab->GetAllNoteEntries( rNotes );
}

void ScDocument::GetNotesInRange( const ScRangeList& rRange, std::vector<sc::NoteEntry>& rNotes ) const
{
    for( size_t i = 0; i < rRange.size(); ++i)
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 7936525..56b44ec 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -299,6 +299,14 @@ String STR_UNDO_HIDENOTE+RID_GLOBSTR_OFFSET
{
    Text [ en-US ] = "Hide Comment" ;
};
String STR_UNDO_SHOWALLNOTES+RID_GLOBSTR_OFFSET
{
    Text [ en-US ] = "Show All Comments" ;
};
String STR_UNDO_HIDEALLNOTES+RID_GLOBSTR_OFFSET
{
    Text [ en-US ] = "Hide All Comments" ;
};
String STR_UNDO_EDITNOTE+RID_GLOBSTR_OFFSET
{
    Text [ en-US ] = "Edit Comment" ;
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index 6dda629..ed5389b 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -1043,6 +1043,33 @@ void ScCellShell::GetState(SfxItemSet &rSet)
                }
                break;

            case FID_SHOW_ALL_NOTES:
            case FID_HIDE_ALL_NOTES:
                {
                    bool bHasNotes = false;
                    SCTAB nFirstSelected = rMark.GetFirstSelected();
                    SCTAB nLastSelected = rMark.GetLastSelected();

                    for( SCTAB aTab = nFirstSelected; aTab<=nLastSelected; aTab++ )
                    {
                        if (rMark.GetTableSelect(aTab) )
                        {
                            if (pDoc->HasTabNotes( aTab ))
                            {
                                bHasNotes = true;
                                break;
                            }
                        }

                        if( bHasNotes ) //for break nested loop
                            break;
                    }

                    if ( !bHasNotes )
                        rSet.DisableItem( nWhich );
                }
                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 81b63f6..1903df9 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2324,6 +2324,39 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                    else
                         rReq.Ignore();
                }

            }
            break;

        case FID_SHOW_ALL_NOTES:
        case FID_HIDE_ALL_NOTES:
            {
                 bool bShowNote     = nSlot == FID_SHOW_ALL_NOTES;
                 ScViewData* pData  = GetViewData();
                 ScMarkData& rMark  = pData->GetMarkData();
                 ScDocument* pDoc   = pData->GetDocument();
                 std::vector<sc::NoteEntry> aNotes;

                 OUString aUndo = ScGlobal::GetRscString( bShowNote ? STR_UNDO_SHOWALLNOTES : STR_UNDO_HIDEALLNOTES );
                 pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pData->GetViewShell()->GetViewShellId() );

                 SCTAB nFirstSelected = rMark.GetFirstSelected();
                 SCTAB nLastSelected = rMark.GetLastSelected();

                 for( SCTAB aTab = nFirstSelected; aTab<=nLastSelected; aTab++ )
                 {
                     if (rMark.GetTableSelect(aTab))
                         pDoc->GetAllNoteEntries(aTab, aNotes);
                 }

                 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();
            }
            break;

diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index 7120412..e60dbbd 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -482,6 +482,8 @@ void ScTabView::SelectionChanged()
    rBindings.Invalidate( FID_NOTE_VISIBLE );
    rBindings.Invalidate( FID_SHOW_NOTE );
    rBindings.Invalidate( FID_HIDE_NOTE );
    rBindings.Invalidate( FID_SHOW_ALL_NOTES );
    rBindings.Invalidate( FID_HIDE_ALL_NOTES );
    rBindings.Invalidate( SID_DELETE_NOTE );
    rBindings.Invalidate( SID_ROWCOL_SELCOUNT );

diff --git a/sc/uiconfig/scalc/menubar/menubar.xml b/sc/uiconfig/scalc/menubar/menubar.xml
index bbac5a0..e2405cc 100644
--- a/sc/uiconfig/scalc/menubar/menubar.xml
+++ b/sc/uiconfig/scalc/menubar/menubar.xml
@@ -544,6 +544,8 @@
                    <menu:menuitem menu:id=".uno:EditAnnotation"/>
                    <menu:menuitem menu:id=".uno:HideNote"/>
                    <menu:menuitem menu:id=".uno:ShowNote"/>
                    <menu:menuitem menu:id=".uno:HideAllNotes"/>
                    <menu:menuitem menu:id=".uno:ShowAllNotes"/>
                    <menu:menuitem menu:id=".uno:DeleteNote"/>
                </menu:menupopup>
            </menu:menu>