diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2015-12-04 00:17:05 +0100 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2015-12-05 09:23:09 +0000 |
commit | 82b0bf45d0527db84e11689dc8a15eefaa699409 (patch) | |
tree | 35c10b16323359104f74c13ac77fce2229274bd4 | |
parent | tdf#94739 use GetScanlineSize instead of calculating it (diff) | |
download | core-82b0bf45d0527db84e11689dc8a15eefaa699409.tar.gz core-82b0bf45d0527db84e11689dc8a15eefaa699409.zip |
tdf#96234: Type Formatting, Primary key checkbox may be checked
Right click on a field in Type Formatting (Base, paste a table from Calc for eg)
makes a popup which takes into account now if the field is a primary key or not.
Handles multi-fields primary key, too: the selected fields must be exactly
those in the primary key, no more, no less.
Change-Id: I545b946bccd3fc02f4f6c3bdb99f914d181a3d40
(cherry picked from commit b0658929bea09386f524879228b35996375537f4)
Reviewed-on: https://gerrit.libreoffice.org/20409
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
-rw-r--r-- | dbaccess/source/ui/misc/WTypeSelect.cxx | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/dbaccess/source/ui/misc/WTypeSelect.cxx b/dbaccess/source/ui/misc/WTypeSelect.cxx index ba9e35ebb0b3..e16e00f73143 100644 --- a/dbaccess/source/ui/misc/WTypeSelect.cxx +++ b/dbaccess/source/ui/misc/WTypeSelect.cxx @@ -424,23 +424,45 @@ bool OWizTypeSelectList::PreNotify( NotifyEvent& rEvt ) ptWhere = pComEvt->GetMousePosPixel(); PopupMenu aContextMenu(ModuleRes(RID_SBA_RTF_PKEYPOPUP)); + // Should primary key checkbox be checked? + const sal_Int32 nCount = GetEntryCount(); + bool bCheckOk = false; + for(sal_Int32 j = 0 ; j < nCount ; ++j) + { + OFieldDescription* pFieldDescr = static_cast<OFieldDescription*>(GetEntryData(j)); + // if at least one of the fields is selected but not in the primary key, + // or is in the primary key but not selected, then don't check the + // primary key checkbox. + if( pFieldDescr && pFieldDescr->IsPrimaryKey() != IsEntryPosSelected(j) ) + { + bCheckOk = false; + break; + } + if (!bCheckOk && IsEntryPosSelected(j)) + bCheckOk = true; + } + + if (bCheckOk) + aContextMenu.CheckItem( SID_TABLEDESIGN_TABED_PRIMARYKEY, true ); + switch( aContextMenu.Execute( this, ptWhere ) ) { case SID_TABLEDESIGN_TABED_PRIMARYKEY: { - const sal_Int32 nCount = GetEntryCount(); for(sal_Int32 j = 0 ; j < nCount ; ++j) { OFieldDescription* pFieldDescr = static_cast<OFieldDescription*>(GetEntryData(j)); if( pFieldDescr ) { - if(pFieldDescr->IsPrimaryKey() && !IsEntryPosSelected(j)) - setPrimaryKey(pFieldDescr,j); - else if(IsEntryPosSelected(j)) + if(!bCheckOk && IsEntryPosSelected(j)) { - setPrimaryKey(pFieldDescr,j,!pFieldDescr->IsPrimaryKey()); + setPrimaryKey(pFieldDescr,j,true); SelectEntryPos(j); } + else + { + setPrimaryKey(pFieldDescr,j); + } } } GetSelectHdl().Call(*this); |