fdo#56456 fdo#75578 fdo#63271 fdo#75805 Improve hyperlink dialog

Changes made:

* Rename "Back" to "Reset" like in other dialogs (eg. Writer - Format - Character).
* Apply-Button, which reflects the old behavior of the dialog, and doesn't
  close it automatically.
* Added an OK-Button, which applies the changes made and automatically closes the
  dialog.

With this both use cases should be handled:

* Inserting one single URI with simple close.
* Modifying multiple URIs without closing the dialog.

Hopefully all users are happy with this ;)

Change-Id: I1881dee083945cd165fbb8f8444395c1b04a0607
Reviewed-on: https://gerrit.libreoffice.org/10946
Reviewed-by: Samuel Mehrbrodt <s.mehrbrodt@gmail.com>
Reviewed-by: Thomas Arnhold <thomas@arnhold.org>
Tested-by: Thomas Arnhold <thomas@arnhold.org>
diff --git a/cui/AllLangResTarget_cui.mk b/cui/AllLangResTarget_cui.mk
index 2023160..5e8f673 100644
--- a/cui/AllLangResTarget_cui.mk
+++ b/cui/AllLangResTarget_cui.mk
@@ -30,7 +30,6 @@ $(eval $(call gb_SrsTarget_add_files,cui/res,\
    cui/source/dialogs/fmsearch.src \
    cui/source/dialogs/gallery.src \
    cui/source/dialogs/hyperdlg.src \
    cui/source/dialogs/iconcdlg.src \
    cui/source/dialogs/multipat.src \
    cui/source/dialogs/passwdomdlg.src \
    cui/source/dialogs/scriptdlg.src \
diff --git a/cui/source/dialogs/cuihyperdlg.cxx b/cui/source/dialogs/cuihyperdlg.cxx
index 5bf73b9..ede512f 100644
--- a/cui/source/dialogs/cuihyperdlg.cxx
+++ b/cui/source/dialogs/cuihyperdlg.cxx
@@ -113,7 +113,6 @@ SvxHpLinkDlg::SvxHpLinkDlg (Window* pParent, SfxBindings* pBindings)
    pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP_HELP ) );

    // set OK/Cancel - button
    GetOKButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_APPLYBUT) );
    GetCancelButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_CLOSEBUT) );

    // create itemset for tabpages
@@ -151,7 +150,8 @@ SvxHpLinkDlg::SvxHpLinkDlg (Window* pParent, SfxBindings* pBindings)

    pBindings->Update( SID_READONLY_MODE );

    GetOKButton().SetClickHdl    ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
    GetOKButton().SetClickHdl    ( LINK ( this, SvxHpLinkDlg, ClickOkHdl_Impl ) );
    GetApplyButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
    GetCancelButton().SetClickHdl( LINK ( this, SvxHpLinkDlg, ClickCloseHdl_Impl ) );
}

@@ -178,6 +178,29 @@ bool SvxHpLinkDlg::Close()
    return true;
}

void SvxHpLinkDlg::Apply()
{
    SfxItemSet aItemSet( SfxGetpApp()->GetPool(), SID_HYPERLINK_GETLINK,
                         SID_HYPERLINK_SETLINK );

    SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)
                                            GetTabPage ( GetCurPageId() );

    if ( pCurrentPage->AskApply() )
    {
        pCurrentPage->FillItemSet( &aItemSet );

        SvxHyperlinkItem *aItem = (SvxHyperlinkItem *)
                                  aItemSet.GetItem (SID_HYPERLINK_SETLINK);
        OUString aStrEmpty;
        if ( aItem->GetURL() != aStrEmpty )
            GetDispatcher()->Execute( SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON |
                                      SFX_CALLMODE_RECORD, aItem, 0L);

        ( (SvxHyperlinkTabPageBase*)GetTabPage ( GetCurPageId() ) )->DoApply();
    }
}

/*************************************************************************
|*
|* When extrawindow is visible and its never moved by user, then move that
@@ -231,6 +254,15 @@ void SvxHpLinkDlg::Move()
    Window::Move();
}

/// Click on OK button
IMPL_LINK_NOARG(SvxHpLinkDlg, ClickOkHdl_Impl)
{
    Apply();
    Close();

    return ( 0L );
}

/*************************************************************************
|*
|* Click on Apply-button
@@ -239,25 +271,7 @@ void SvxHpLinkDlg::Move()

IMPL_LINK_NOARG(SvxHpLinkDlg, ClickApplyHdl_Impl)
{
    SfxItemSet aItemSet( SfxGetpApp()->GetPool(), SID_HYPERLINK_GETLINK,
                         SID_HYPERLINK_SETLINK );

    SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)
                                            GetTabPage ( GetCurPageId() );

    if ( pCurrentPage->AskApply() )
    {
        pCurrentPage->FillItemSet( &aItemSet );

        SvxHyperlinkItem *aItem = (SvxHyperlinkItem *)
                                  aItemSet.GetItem (SID_HYPERLINK_SETLINK);
        OUString aStrEmpty;
        if ( aItem->GetURL() != aStrEmpty )
            GetDispatcher()->Execute( SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON |
                                      SFX_CALLMODE_RECORD, aItem, 0L);

        ( (SvxHyperlinkTabPageBase*)GetTabPage ( GetCurPageId() ) )->DoApply();
    }
    Apply();

    return( 0L );
}
diff --git a/cui/source/dialogs/iconcdlg.cxx b/cui/source/dialogs/iconcdlg.cxx
index eed1d13..4b1e480 100644
--- a/cui/source/dialogs/iconcdlg.cxx
+++ b/cui/source/dialogs/iconcdlg.cxx
@@ -190,9 +190,10 @@ IconChoiceDialog::IconChoiceDialog ( Window* pParent, const OString& rID,
    bItemsReset     ( false )
{
    get(m_pOKBtn, "ok");
    get(m_pApplyBtn, "apply");
    get(m_pCancelBtn, "cancel");
    get(m_pHelpBtn, "help");
    get(m_pResetBtn, "back");
    get(m_pResetBtn, "reset");
    get(m_pIconCtrl, "icon_control");
    get(m_pTabContainer, "tab");

@@ -213,11 +214,13 @@ IconChoiceDialog::IconChoiceDialog ( Window* pParent, const OString& rID,
    // Buttons
    m_pOKBtn->SetClickHdl   ( LINK( this, IconChoiceDialog, OkHdl ) );
    m_pOKBtn->SetHelpId( HID_ICCDIALOG_OK_BTN );
    m_pApplyBtn->SetClickHdl   ( LINK( this, IconChoiceDialog, ApplyHdl ) );
    //m_pApplyBtn->SetHelpId( HID_ICCDIALOG_APPLY_BTN );
    m_pCancelBtn->SetHelpId( HID_ICCDIALOG_CANCEL_BTN );
    m_pResetBtn->SetClickHdl( LINK( this, IconChoiceDialog, ResetHdl ) );
    m_pResetBtn->SetText( CUI_RESSTR(RID_SVXSTR_ICONCHOICEDLG_RESETBUT) );
    m_pResetBtn->SetHelpId( HID_ICCDIALOG_RESET_BTN );
    m_pOKBtn->Show();
    m_pApplyBtn->Show();
    m_pCancelBtn->Show();
    m_pHelpBtn->Show();
    m_pResetBtn->Show();
@@ -392,6 +395,22 @@ IMPL_LINK_NOARG(IconChoiceDialog, OkHdl)
}


IMPL_LINK_NOARG(IconChoiceDialog, ApplyHdl)
{
    bInOK = true;

    if ( OK_Impl() )
    {
        if ( bModal )
            EndDialog( Ok() );
        else
        {
            Ok();
            Close();
        }
    }
    return 0;
}

IMPL_LINK_NOARG(IconChoiceDialog, ResetHdl)
{
diff --git a/cui/source/dialogs/iconcdlg.src b/cui/source/dialogs/iconcdlg.src
deleted file mode 100644
index 4bcb786..0000000
--- a/cui/source/dialogs/iconcdlg.src
+++ /dev/null
@@ -1,26 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#include <cuires.hrc>

String RID_SVXSTR_ICONCHOICEDLG_RESETBUT
{
    Text [ en-US ] = "~Back" ;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/inc/cuihyperdlg.hxx b/cui/source/inc/cuihyperdlg.hxx
index f32bc71..244c195 100644
--- a/cui/source/inc/cuihyperdlg.hxx
+++ b/cui/source/inc/cuihyperdlg.hxx
@@ -68,12 +68,14 @@ private:
    bool            mbReadOnly  : 1;
    bool            mbIsHTMLDoc : 1;

    DECL_LINK (ClickOkHdl_Impl, void * );
    DECL_LINK (ClickApplyHdl_Impl, void * );
    DECL_LINK (ClickCloseHdl_Impl, void * );

protected:
    virtual bool            Close() SAL_OVERRIDE;
    virtual void            Move() SAL_OVERRIDE;
    void Apply();

public:
    SvxHpLinkDlg (Window* pParent, SfxBindings* pBindings );
diff --git a/cui/source/inc/cuires.hrc b/cui/source/inc/cuires.hrc
index 18bd651..d307d68 100644
--- a/cui/source/inc/cuires.hrc
+++ b/cui/source/inc/cuires.hrc
@@ -181,9 +181,6 @@
#define RID_SVXSTR_HYPERDLG_FROM_TEXT       (RID_SVX_START +  814)
#define RID_SVXSTR_MNUCFG_ALREADY_INCLUDED  (RID_SVX_START +  816)

// icon choice
#define RID_SVXSTR_ICONCHOICEDLG_RESETBUT   (RID_SVX_START + 580)

// multi path dialog
#define RID_MULTIPATH_DBL_ERR               (RID_SVX_START + 207)
#define RID_SVXSTR_ARCHIVE_TITLE            (RID_SVX_START + 484)
diff --git a/cui/source/inc/iconcdlg.hxx b/cui/source/inc/iconcdlg.hxx
index ceb2f19..8248a72 100644
--- a/cui/source/inc/iconcdlg.hxx
+++ b/cui/source/inc/iconcdlg.hxx
@@ -134,6 +134,7 @@ private :

    // Buttons
    OKButton                *m_pOKBtn;
    PushButton              *m_pApplyBtn;
    CancelButton            *m_pCancelBtn;
    HelpButton              *m_pHelpBtn;
    PushButton              *m_pResetBtn;
@@ -151,6 +152,7 @@ private :

    DECL_LINK ( ChosePageHdl_Impl, void * );
    DECL_LINK(OkHdl, void *);
    DECL_LINK(ApplyHdl, void *);
    DECL_LINK(ResetHdl, void *);
    DECL_LINK(CancelHdl, void *);

@@ -201,6 +203,8 @@ public :

    const OKButton&     GetOKButton() const { return *m_pOKBtn; }
    OKButton&           GetOKButton() { return *m_pOKBtn; }
    const PushButton&   GetApplyButton() const { return *m_pApplyBtn; }
    PushButton&         GetApplyButton() { return *m_pApplyBtn; }
    const CancelButton& GetCancelButton() const { return *m_pCancelBtn; }
    CancelButton&       GetCancelButton() { return *m_pCancelBtn; }
    const HelpButton&   GetHelpButton() const { return *m_pHelpBtn; }
diff --git a/cui/uiconfig/ui/hyperlinkdialog.ui b/cui/uiconfig/ui/hyperlinkdialog.ui
index 5a55417..551a024 100644
--- a/cui/uiconfig/ui/hyperlinkdialog.ui
+++ b/cui/uiconfig/ui/hyperlinkdialog.ui
@@ -24,12 +24,12 @@
            <child>
              <object class="GtkButton" id="ok">
                <property name="label">gtk-ok</property>
                <property name="use_action_appearance">False</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="can_default">True</property>
                <property name="has_default">True</property>
                <property name="receives_default">True</property>
                <property name="tooltip_text" translatable="yes">Apply changes and close dialog</property>
                <property name="use_stock">True</property>
              </object>
              <packing>
@@ -39,13 +39,12 @@
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="cancel">
                <property name="label">gtk-cancel</property>
                <property name="use_action_appearance">False</property>
              <object class="GtkButton" id="apply">
                <property name="label" translatable="yes">Apply</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
                <property name="tooltip_text" translatable="yes">Apply changes</property>
              </object>
              <packing>
                <property name="expand">False</property>
@@ -54,9 +53,8 @@
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="help">
                <property name="label">gtk-help</property>
                <property name="use_action_appearance">False</property>
              <object class="GtkButton" id="cancel">
                <property name="label">gtk-cancel</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
@@ -69,12 +67,12 @@
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="back">
                <property name="label" translatable="yes">back</property>
                <property name="use_action_appearance">False</property>
              <object class="GtkButton" id="help">
                <property name="label">gtk-help</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
@@ -82,6 +80,20 @@
                <property name="position">3</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="reset">
                <property name="label" translatable="yes">Reset</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="tooltip_text" translatable="yes">Reset changes</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">4</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
@@ -103,7 +115,6 @@
                <property name="height_request">400</property>
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin">0</property>
                <property name="vexpand">True</property>
              </object>
              <packing>
@@ -140,9 +151,10 @@
    </child>
    <action-widgets>
      <action-widget response="0">ok</action-widget>
      <action-widget response="0">apply</action-widget>
      <action-widget response="0">cancel</action-widget>
      <action-widget response="0">help</action-widget>
      <action-widget response="0">back</action-widget>
      <action-widget response="0">reset</action-widget>
    </action-widgets>
  </object>
</interface>