213c929
From 05579aa8b26f593af650d8434ff1c25c0a2702a6 Mon Sep 17 00:00:00 2001
213c929
Message-Id: <05579aa8b26f593af650d8434ff1c25c0a2702a6.1334752453.git.erack@redhat.com>
213c929
From: Eike Rathke <erack@redhat.com>
213c929
Date: Tue, 17 Apr 2012 20:57:34 +0200
213c929
Subject: [PATCH] resolved rhbz#813280 the current document is not always the
213c929
 first in list
213c929
213c929
i.e. if more than one document open and dialog invoked on any but the first
213c929
document.
213c929
213c929
Signed-off-by: Kohei Yoshida <kohei.yoshida@gmail.com>
213c929
---
213c929
 sc/source/ui/inc/mvtabdlg.hxx      |    2 ++
213c929
 sc/source/ui/miscdlgs/mvtabdlg.cxx |   27 +++++++++++++++++----------
213c929
 2 files changed, 19 insertions(+), 10 deletions(-)
213c929
213c929
diff --git a/sc/source/ui/inc/mvtabdlg.hxx b/sc/source/ui/inc/mvtabdlg.hxx
213c929
index c53a59f..f9c63a3 100644
213c929
--- a/sc/source/ui/inc/mvtabdlg.hxx
213c929
+++ b/sc/source/ui/inc/mvtabdlg.hxx
213c929
@@ -58,6 +58,7 @@ private:
213c929
     void ResetRenameInput();
213c929
     void CheckNewTabName();
213c929
     ScDocument* GetSelectedDoc();
213c929
+    bool IsCurrentDocSelected() const;
213c929
 
213c929
 private:
213c929
     FixedLine       aFlAction;
213c929
@@ -82,6 +83,7 @@ private:
213c929
 
213c929
     const rtl::OUString maDefaultName;
213c929
 
213c929
+    sal_uInt16      mnCurrentDocPos;
213c929
     sal_uInt16      nDocument;
213c929
     SCTAB           nTable;
213c929
     bool            bCopyTable:1;
213c929
diff --git a/sc/source/ui/miscdlgs/mvtabdlg.cxx b/sc/source/ui/miscdlgs/mvtabdlg.cxx
213c929
index 831905d..ffe96af 100644
213c929
--- a/sc/source/ui/miscdlgs/mvtabdlg.cxx
213c929
+++ b/sc/source/ui/miscdlgs/mvtabdlg.cxx
213c929
@@ -70,6 +70,7 @@ ScMoveTableDlg::ScMoveTableDlg(Window* pParent, const rtl::OUString& rDefault)
213c929
         maStrTabNameInvalid( ResId::toString(ScResId(STR_TABNAME_WARN_INVALID)) ),
213c929
         //
213c929
         maDefaultName( rDefault ),
213c929
+        mnCurrentDocPos( 0 ),
213c929
         nDocument   ( 0 ),
213c929
         nTable      ( 0 ),
213c929
         bCopyTable  ( false ),
213c929
@@ -127,8 +128,13 @@ void ScMoveTableDlg::EnableRenameTable(sal_Bool bFlag)
213c929
 void ScMoveTableDlg::ResetRenameInput()
213c929
 {
213c929
     if (mbEverEdited)
213c929
+    {
213c929
         // Don't reset the name when the sheet name has ever been edited.
213c929
+        // But check the name, as this is also called for change of copy/move
213c929
+        // buttons and document listbox selection.
213c929
+        CheckNewTabName();
213c929
         return;
213c929
+    }
213c929
 
213c929
     if (!aEdTabName.IsEnabled())
213c929
     {
213c929
@@ -178,19 +184,15 @@ void ScMoveTableDlg::CheckNewTabName()
213c929
         return;
213c929
     }
213c929
 
213c929
-    bool   bFound = false;
213c929
+    bool bMoveInCurrentDoc = (aBtnMove.IsChecked() && IsCurrentDocSelected());
213c929
+    bool bFound = false;
213c929
     sal_uInt16 nLast  = aLbTable.GetEntryCount() - 1;
213c929
-    for ( sal_uInt16 i=0; i<=nLast; ++i )
213c929
+    for ( sal_uInt16 i=0; i<=nLast && !bFound; ++i )
213c929
     {
213c929
         if ( aNewName.equals(aLbTable.GetEntry(i)) )
213c929
         {
213c929
-            if (aBtnMove.IsChecked() &&
213c929
-                aLbDoc.GetSelectEntryPos() == 0 &&
213c929
-                maDefaultName.equals(aEdTabName.GetText()))
213c929
-
213c929
-                // Move inside same document, thus same name is allowed.
213c929
-                bFound = false;
213c929
-            else
213c929
+            // Only for move within same document the same name is allowed.
213c929
+            if (!bMoveInCurrentDoc || !maDefaultName.equals( aEdTabName.GetText()))
213c929
                 bFound = true;
213c929
         }
213c929
     }
213c929
@@ -214,6 +216,11 @@ ScDocument* ScMoveTableDlg::GetSelectedDoc()
213c929
     return static_cast<ScDocument*>(aLbDoc.GetEntryData(nPos));
213c929
 }
213c929
 
213c929
+bool ScMoveTableDlg::IsCurrentDocSelected() const
213c929
+{
213c929
+    return aLbDoc.GetSelectEntryPos() == mnCurrentDocPos;
213c929
+}
213c929
+
213c929
 //------------------------------------------------------------------------
213c929
 
213c929
 void ScMoveTableDlg::Init()
213c929
@@ -254,7 +261,7 @@ void ScMoveTableDlg::InitDocListBox()
213c929
 
213c929
             if ( pScSh == SfxObjectShell::Current() )
213c929
             {
213c929
-                nSelPos = i;
213c929
+                mnCurrentDocPos = nSelPos = i;
213c929
                 aEntryName += sal_Unicode( ' ' );
213c929
                 aEntryName += String( ScResId( STR_CURRENTDOC ) );
213c929
             }
213c929
-- 
213c929
1.7.7.6
213c929