Files
libreoffice/sw/source/ui/misc/glosbib.cxx

461 lines
15 KiB
C++
Raw Normal View History

/* -*- 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 .
*/
2012-01-21 18:58:54 +01:00
#include <comphelper/string.hxx>
2000-09-18 16:15:01 +00:00
#include <tools/urlobj.hxx>
#include <tools/stream.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/help.hxx>
#include <unotools/transliterationwrapper.hxx>
#include <unotools/tempfile.hxx>
#include <unotools/pathoptions.hxx>
#include "svtools/treelistentry.hxx"
2000-09-18 16:15:01 +00:00
#include <swtypes.hxx>
#include <glosbib.hxx>
#include <gloshdl.hxx>
#include <actctrl.hxx>
2000-09-18 16:15:01 +00:00
#include <glossary.hxx>
#include <glosdoc.hxx>
#include <swunohelper.hxx>
2000-09-18 16:15:01 +00:00
#include <glosbib.hrc>
#include <misc.hrc>
#include <helpid.h>
#define PATH_CASE_SENSITIVE 0x01
#define PATH_READONLY 0x02
#define RENAME_TOKEN_DELIM (sal_Unicode)1
SwGlossaryGroupDlg::SwGlossaryGroupDlg(Window * pParent,
2012-01-21 20:19:32 +01:00
std::vector<String> const& rPathArr,
2000-09-18 16:15:01 +00:00
SwGlossaryHdl *pHdl) :
SvxStandardDialog(pParent, SW_RES(DLG_BIB_BASE)),
2011-02-21 18:43:22 +01:00
aBibFT( this, SW_RES(FT_BIB)),
2000-09-18 16:15:01 +00:00
aNameED( this, SW_RES(ED_NAME)),
2011-02-21 18:43:22 +01:00
aPathFT( this, SW_RES(FT_PATH)),
2000-09-18 16:15:01 +00:00
aPathLB( this, SW_RES(LB_PATH)),
2011-02-21 18:43:22 +01:00
aSelectFT( this, SW_RES(FT_SELECT)),
aGroupTLB( this, SW_RES(TLB_GROUPS)),
2000-09-18 16:15:01 +00:00
aOkPB( this, SW_RES(BT_OK)),
aCancelPB( this, SW_RES(BT_CANCEL)),
aHelpPB( this, SW_RES(BT_HELP)),
aNewPB( this, SW_RES(PB_NEW)),
aDelPB( this, SW_RES(PB_DELETE)),
aRenamePB( this, SW_RES(PB_RENAME)),
2000-09-18 16:15:01 +00:00
pGlosHdl(pHdl)
{
FreeResource();
long nTabs[] =
{ 2, // Number of Tabs
0, 160
};
aGroupTLB.SetHelpId(HID_GLOS_GROUP_TREE);
aGroupTLB.SetTabs( &nTabs[0], MAP_APPFONT );
aGroupTLB.SetStyle(aGroupTLB.GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN|WB_SORT);
2000-09-18 16:15:01 +00:00
aGroupTLB.SetSelectHdl(LINK(this, SwGlossaryGroupDlg, SelectHdl));
aGroupTLB.GetModel()->SetSortMode(SortAscending);
aNewPB.SetClickHdl(LINK(this, SwGlossaryGroupDlg, NewHdl));
aDelPB.SetClickHdl(LINK(this, SwGlossaryGroupDlg, DeleteHdl));
aNameED.SetModifyHdl(LINK(this, SwGlossaryGroupDlg, ModifyHdl));
aPathLB.SetSelectHdl(LINK(this, SwGlossaryGroupDlg, ModifyHdl));
aRenamePB.SetClickHdl(LINK(this, SwGlossaryGroupDlg, RenameHdl));
2012-01-21 20:19:32 +01:00
for (size_t i = 0; i < rPathArr.size(); ++i)
2000-09-18 16:15:01 +00:00
{
2012-01-21 20:19:32 +01:00
String sPath(rPathArr[i]);
INetURLObject aTempURL(sPath);
sPath = aTempURL.GetMainURL(INetURLObject::DECODE_WITH_CHARSET );
2000-09-18 16:15:01 +00:00
aPathLB.InsertEntry(sPath);
sal_uLong nCaseReadonly = 0;
2000-11-06 08:30:33 +00:00
utl::TempFile aTempFile(&sPath);
2000-09-18 16:15:01 +00:00
aTempFile.EnableKillingFile();
if(!aTempFile.IsValid())
nCaseReadonly |= PATH_READONLY;
else if( SWUnoHelper::UCB_IsCaseSensitiveFileName( aTempFile.GetURL()))
nCaseReadonly |= PATH_CASE_SENSITIVE;
2000-09-18 16:15:01 +00:00
aPathLB.SetEntryData(i, (void*)nCaseReadonly);
}
aPathLB.SelectEntryPos(0);
aPathLB.Enable(sal_True);
2000-09-18 16:15:01 +00:00
const sal_uInt16 nCount = pHdl->GetGroupCnt();
for( sal_uInt16 i = 0; i < nCount; ++i)
2000-09-18 16:15:01 +00:00
{
String sTitle;
String sGroup = pHdl->GetGroupName(i, &sTitle);
2001-03-08 14:39:01 +00:00
if(!sGroup.Len())
continue;
GlosBibUserData* pData = new GlosBibUserData;
2000-09-18 16:15:01 +00:00
pData->sGroupName = sGroup;
pData->sGroupTitle = sTitle;
String sTemp(sTitle);
sTemp += '\t';
pData->sPath = aPathLB.GetEntry((sal_uInt16)sGroup.GetToken(1, GLOS_DELIM).ToInt32());
2000-09-18 16:15:01 +00:00
sTemp += pData->sPath;
SvTreeListEntry* pEntry = aGroupTLB.InsertEntry(sTemp);
2000-09-18 16:15:01 +00:00
pEntry->SetUserData(pData);
}
aGroupTLB.GetModel()->Resort();
}
SwGlossaryGroupDlg::~SwGlossaryGroupDlg()
{
}
2010-12-11 15:42:15 +01:00
void SwGlossaryGroupDlg::Apply()
2000-09-18 16:15:01 +00:00
{
if(aNewPB.IsEnabled())
NewHdl(&aNewPB);
String aActGroup = SwGlossaryDlg::GetCurrGroup();
for (OUVector_t::const_iterator it(m_RemovedArr.begin());
it != m_RemovedArr.end(); ++it)
2000-09-18 16:15:01 +00:00
{
const String sDelGroup =
::comphelper::string::getToken(*it, 0, '\t');
if( sDelGroup == aActGroup )
2000-09-18 16:15:01 +00:00
{
//when the current group is deleted, the current group has to be relocated
if(aGroupTLB.GetEntryCount())
2000-09-18 16:15:01 +00:00
{
SvTreeListEntry* pFirst = aGroupTLB.First();
GlosBibUserData* pUserData = (GlosBibUserData*)pFirst->GetUserData();
pGlosHdl->SetCurGroup(pUserData->sGroupName);
2000-09-18 16:15:01 +00:00
}
}
String sMsg(SW_RES(STR_QUERY_DELETE_GROUP1));
String sTitle( ::comphelper::string::getToken(*it, 1, '\t') );
if(sTitle.Len())
sMsg += sTitle;
else
sDelGroup.GetToken(1, GLOS_DELIM);
sMsg += SW_RESSTR(STR_QUERY_DELETE_GROUP2);
QueryBox aQuery(this->GetParent(), WB_YES_NO|WB_DEF_NO, sMsg );
if(RET_YES == aQuery.Execute())
pGlosHdl->DelGroup( sDelGroup );
2000-09-18 16:15:01 +00:00
}
//don't rename before there was one
for (OUVector_t::const_iterator it(m_RenamedArr.begin());
it != m_RenamedArr.end(); ++it)
2000-09-18 16:15:01 +00:00
{
::rtl::OUString const sOld(
::comphelper::string::getToken(*it, 0, RENAME_TOKEN_DELIM));
String sNew(
::comphelper::string::getToken(*it, 1, RENAME_TOKEN_DELIM));
::rtl::OUString const sTitle(
::comphelper::string::getToken(*it, 2, RENAME_TOKEN_DELIM));
pGlosHdl->RenameGroup(sOld, sNew, sTitle);
if (it == m_RenamedArr.begin())
2000-09-18 16:15:01 +00:00
{
sCreatedGroup = sNew;
2000-09-18 16:15:01 +00:00
}
}
for (OUVector_t::const_iterator it(m_InsertedArr.begin());
it != m_InsertedArr.end(); ++it)
2000-09-18 16:15:01 +00:00
{
String sNewGroup = *it;
String sNewTitle = sNewGroup.GetToken(0, GLOS_DELIM);
if( sNewGroup != aActGroup )
2000-09-18 16:15:01 +00:00
{
pGlosHdl->NewGroup(sNewGroup, sNewTitle);
if(!sCreatedGroup.Len())
sCreatedGroup = sNewGroup;
2000-09-18 16:15:01 +00:00
}
}
}
IMPL_LINK( SwGlossaryGroupDlg, SelectHdl, SvTabListBox*, EMPTYARG )
{
aNewPB.Enable(sal_False);
SvTreeListEntry* pFirstEntry = aGroupTLB.FirstSelected();
if(pFirstEntry)
2000-09-18 16:15:01 +00:00
{
GlosBibUserData* pUserData = (GlosBibUserData*)pFirstEntry->GetUserData();
2000-09-18 16:15:01 +00:00
String sEntry(pUserData->sGroupName);
String sName(aNameED.GetText());
sal_Bool bExists = sal_False;
sal_uLong nPos = aGroupTLB.GetEntryPos(sName, 0);
2000-09-18 16:15:01 +00:00
if( 0xffffffff > nPos)
{
SvTreeListEntry* pEntry = aGroupTLB.GetEntry(nPos);
2000-09-18 16:15:01 +00:00
GlosBibUserData* pFoundData = (GlosBibUserData*)pEntry->GetUserData();
String sGroup = pFoundData->sGroupName;
bExists = sGroup == sEntry;
}
aRenamePB.Enable(!bExists && sName.Len());
aDelPB.Enable(IsDeleteAllowed(sEntry));
}
return 0;
}
IMPL_LINK_NOARG(SwGlossaryGroupDlg, NewHdl)
2000-09-18 16:15:01 +00:00
{
String sGroup(aNameED.GetText());
sGroup += GLOS_DELIM;
sGroup += String::CreateFromInt32(aPathLB.GetSelectEntryPos());
OSL_ENSURE(!pGlosHdl->FindGroupName(sGroup), "group already available!");
2012-01-21 18:23:20 +01:00
m_InsertedArr.push_back(sGroup);
2000-09-18 16:15:01 +00:00
String sTemp(aNameED.GetText());
sTemp += '\t';
sTemp += aPathLB.GetSelectEntry();
SvTreeListEntry* pEntry = aGroupTLB.InsertEntry(sTemp);
2000-09-18 16:15:01 +00:00
GlosBibUserData* pData = new GlosBibUserData;
pData->sPath = aPathLB.GetSelectEntry();
pData->sGroupName = sGroup;
pData->sGroupTitle = aNameED.GetText();
pEntry->SetUserData(pData);
aGroupTLB.Select(pEntry);
aGroupTLB.MakeVisible(pEntry);
aGroupTLB.GetModel()->Resort();
return 0;
}
IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, Button*, pButton )
{
SvTreeListEntry* pEntry = aGroupTLB.FirstSelected();
2000-09-18 16:15:01 +00:00
if(!pEntry)
{
pButton->Enable(sal_False);
2000-09-18 16:15:01 +00:00
return 0;
}
GlosBibUserData* pUserData = (GlosBibUserData*)pEntry->GetUserData();
2012-01-21 18:58:54 +01:00
::rtl::OUString const sEntry(pUserData->sGroupName);
// if the name to be deleted is among the new ones - get rid of it
sal_Bool bDelete = sal_True;
for (OUVector_t::iterator it(m_InsertedArr.begin());
it != m_InsertedArr.end(); ++it)
2000-09-18 16:15:01 +00:00
{
if (*it == sEntry)
2000-09-18 16:15:01 +00:00
{
m_InsertedArr.erase(it);
bDelete = sal_False;
break;
2000-09-18 16:15:01 +00:00
}
2000-09-18 16:15:01 +00:00
}
// it should probably be renamed?
2000-09-18 16:15:01 +00:00
if(bDelete)
{
for (OUVector_t::iterator it(m_RenamedArr.begin());
it != m_RenamedArr.end(); ++it)
2000-09-18 16:15:01 +00:00
{
if (::comphelper::string::getToken(*it, 0, RENAME_TOKEN_DELIM)
== sEntry)
2000-09-18 16:15:01 +00:00
{
m_RenamedArr.erase(it);
bDelete = sal_False;
break;
2000-09-18 16:15:01 +00:00
}
}
}
if(bDelete)
{
String sGroupEntry(pUserData->sGroupName);
sGroupEntry += '\t';
sGroupEntry += pUserData->sGroupTitle;
2012-01-21 18:23:20 +01:00
m_RemovedArr.push_back(sGroupEntry);
2000-09-18 16:15:01 +00:00
}
delete pUserData;
aGroupTLB.GetModel()->Remove(pEntry);
if(!aGroupTLB.First())
pButton->Enable(sal_False);
2000-09-18 16:15:01 +00:00
//the content must be deleted - otherwise the new handler would be called in Apply()
aNameED.SetText(aEmptyStr);
return 0;
}
IMPL_LINK_NOARG(SwGlossaryGroupDlg, RenameHdl)
2000-09-18 16:15:01 +00:00
{
SvTreeListEntry* pEntry = aGroupTLB.FirstSelected();
2000-09-18 16:15:01 +00:00
GlosBibUserData* pUserData = (GlosBibUserData*)pEntry->GetUserData();
String sEntry(pUserData->sGroupName);
String sNewName(aNameED.GetText());
String sNewTitle(sNewName);
sNewName += GLOS_DELIM;
sNewName += String::CreateFromInt32(aPathLB.GetSelectEntryPos());
OSL_ENSURE(!pGlosHdl->FindGroupName(sNewName), "group already available!");
2000-09-18 16:15:01 +00:00
// if the name to be renamed is among the new ones - replace
sal_Bool bDone = sal_False;
for (OUVector_t::iterator it(m_InsertedArr.begin());
it != m_InsertedArr.end(); ++it)
2000-09-18 16:15:01 +00:00
{
if (String(*it) == sEntry)
2000-09-18 16:15:01 +00:00
{
m_InsertedArr.erase(it);
m_InsertedArr.push_back(sNewName);
bDone = sal_True;
break;
2000-09-18 16:15:01 +00:00
}
}
if(!bDone)
{
sEntry += RENAME_TOKEN_DELIM;
sEntry += sNewName;
sEntry += RENAME_TOKEN_DELIM;
sEntry += sNewTitle;
2012-01-21 18:23:20 +01:00
m_RenamedArr.push_back(sEntry);
2000-09-18 16:15:01 +00:00
}
delete (GlosBibUserData*)pEntry->GetUserData();
aGroupTLB.GetModel()->Remove(pEntry);
String sTemp(aNameED.GetText());
sTemp += '\t';
sTemp += aPathLB.GetSelectEntry();
pEntry = aGroupTLB.InsertEntry(sTemp);
GlosBibUserData* pData = new GlosBibUserData;
pData->sPath = aPathLB.GetSelectEntry();
pData->sGroupName = sNewName;
pData->sGroupTitle = sNewTitle;
pEntry->SetUserData(pData);
aGroupTLB.Select(pEntry);
aGroupTLB.MakeVisible(pEntry);
aGroupTLB.GetModel()->Resort();
return 0;
}
IMPL_LINK_NOARG(SwGlossaryGroupDlg, ModifyHdl)
2000-09-18 16:15:01 +00:00
{
String sEntry(aNameED.GetText());
sal_Bool bEnableNew = sal_True;
sal_Bool bEnableDel = sal_False;
sal_uLong nCaseReadonly =
(sal_uLong)aPathLB.GetEntryData(aPathLB.GetSelectEntryPos());
sal_Bool bDirReadonly = 0 != (nCaseReadonly&PATH_READONLY);
2000-09-18 16:15:01 +00:00
if(!sEntry.Len() || bDirReadonly)
bEnableNew = sal_False;
2000-09-18 16:15:01 +00:00
else if(sEntry.Len())
{
sal_uLong nPos = aGroupTLB.GetEntryPos(sEntry, 0);
//if it's not case sensitive you have to search for yourself
2000-09-18 16:15:01 +00:00
if( 0xffffffff == nPos)
{
const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
for(sal_uInt16 i = 0; i < aGroupTLB.GetEntryCount(); i++)
2000-09-18 16:15:01 +00:00
{
String sTemp = aGroupTLB.GetEntryText( i, 0 );
nCaseReadonly = (sal_uLong)aPathLB.GetEntryData(
2000-09-18 16:15:01 +00:00
aPathLB.GetEntryPos(aGroupTLB.GetEntryText(i,1)));
sal_Bool bCase = 0 != (nCaseReadonly & PATH_CASE_SENSITIVE);
if( !bCase && rSCmp.isEqual( sTemp, sEntry ))
2000-09-18 16:15:01 +00:00
{
nPos = i;
break;
}
}
}
if( 0xffffffff > nPos)
{
bEnableNew = sal_False;
2000-09-18 16:15:01 +00:00
aGroupTLB.Select(aGroupTLB.GetEntry( nPos ));
aGroupTLB.MakeVisible(aGroupTLB.GetEntry( nPos ));
}
}
SvTreeListEntry* pEntry = aGroupTLB.FirstSelected();
2000-09-18 16:15:01 +00:00
if(pEntry)
{
2001-10-17 15:58:33 +00:00
GlosBibUserData* pUserData = (GlosBibUserData*)pEntry->GetUserData();
bEnableDel = IsDeleteAllowed(pUserData->sGroupName);
2000-09-18 16:15:01 +00:00
}
aDelPB.Enable(bEnableDel);
aNewPB.Enable(bEnableNew);
aRenamePB.Enable(bEnableNew && pEntry);
return 0;
}
sal_Bool SwGlossaryGroupDlg::IsDeleteAllowed(const String &rGroup)
2000-09-18 16:15:01 +00:00
{
sal_Bool bDel = (!pGlosHdl->IsReadOnly(&rGroup));
2000-09-18 16:15:01 +00:00
// OM: if the name is among the new region name, it is deletable
// as well! Because for non existing region names ReadOnly issues
// sal_True.
2000-09-18 16:15:01 +00:00
for (OUVector_t::const_iterator it(m_InsertedArr.begin());
it != m_InsertedArr.end(); ++it)
2000-09-18 16:15:01 +00:00
{
if (String(*it) == rGroup)
2000-09-18 16:15:01 +00:00
{
bDel = sal_True;
break;
2000-09-18 16:15:01 +00:00
}
}
return bDel;
}
void FEdit::KeyInput( const KeyEvent& rKEvent )
{
KeyCode aCode = rKEvent.GetKeyCode();
2001-10-17 15:58:33 +00:00
if( KEYGROUP_CURSOR == aCode.GetGroup() ||
( KEYGROUP_MISC == aCode.GetGroup() &&
KEY_DELETE >= aCode.GetCode() ) ||
SVT_SEARCHPATH_DELIMITER != rKEvent.GetCharCode() )
2000-09-18 16:15:01 +00:00
Edit::KeyInput( rKEvent );
}
void SwGlossaryGroupTLB::RequestHelp( const HelpEvent& rHEvt )
{
Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
SvTreeListEntry* pEntry = GetEntry( aPos );
2000-09-18 16:15:01 +00:00
if(pEntry)
{
SvLBoxTab* pTab;
SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
if(pItem)
{
aPos = GetEntryPosition( pEntry );
2000-09-18 16:15:01 +00:00
Size aSize(pItem->GetSize( this, pEntry ));
aPos.X() = GetTabPos( pEntry, pTab );
if((aPos.X() + aSize.Width()) > GetSizePixel().Width())
aSize.Width() = GetSizePixel().Width() - aPos.X();
aPos = OutputToScreenPixel(aPos);
Rectangle aItemRect( aPos, aSize );
String sMsg;
GlosBibUserData* pData = (GlosBibUserData*)pEntry->GetUserData();
sMsg = pData->sPath;
sMsg += INET_PATH_TOKEN;
sMsg += pData->sGroupName.GetToken(0, GLOS_DELIM);
sMsg += SwGlossaries::GetExtension();
Help::ShowQuickHelp( this, aItemRect, sMsg,
QUICKHELP_LEFT|QUICKHELP_VCENTER );
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */