26#include <osl/diagnose.h>
38#define PATH_CASE_SENSITIVE 0x01
39#define PATH_READONLY 0x02
41#define RENAME_TOKEN_DELIM u'\x0001'
46 "EditCategoriesDialog")
49 , m_xNameED(m_xBuilder->weld_entry(
"name"))
50 , m_xPathLB(m_xBuilder->weld_combo_box(
"pathlb"))
51 , m_xGroupTLB(m_xBuilder->weld_tree_view(
"group"))
52 , m_xNewPB(m_xBuilder->weld_button(
"new"))
53 , m_xDelPB(m_xBuilder->weld_button(
"delete"))
54 , m_xRenamePB(m_xBuilder->weld_button(
"rename"))
56 int nWidth =
m_xGroupTLB->get_approximate_digit_width() * 34;
74 for (
size_t i = 0;
i < rPathArr.size(); ++
i)
78 sal_uInt32 nCaseReadonly = 0;
85 m_xPathLB->append(OUString::number(nCaseReadonly), sPath);
93 static constexpr OUStringLiteral sMyAutoTextEnglish(
u"My AutoText");
101 pData->sGroupName = sGroup;
102 if ( sTitle == sMyAutoTextEnglish )
105 pData->sGroupTitle = sTitle;
128 short nRet = SfxDialogController::run();
144 const OUString sDelGroup = removedStr.getToken(0,
'\t', nIdx);
145 if( sDelGroup == aActGroup )
154 const OUString sMsg(
SwResId(STR_QUERY_DELETE_GROUP1)
156 +
SwResId(STR_QUERY_DELETE_GROUP2));
159 VclMessageType::Question, VclButtonsType::YesNo, sMsg));
160 xQueryBox->set_default_response(
RET_NO);
161 if (
RET_YES == xQueryBox->run())
180 OUString sNewTitle = sNewGroup.getToken(0,
GLOS_DELIM);
181 if( sNewGroup != aActGroup )
192 m_xNewPB->set_sensitive(
false);
193 int nFirstEntry = m_xGroupTLB->get_selected_index();
194 if (nFirstEntry == -1)
197 GlosBibUserData* pUserData = weld::fromId<GlosBibUserData*>(m_xGroupTLB->get_id(nFirstEntry));
199 const OUString
sName(m_xNameED->get_text());
200 bool bExists =
false;
201 int nPos = m_xGroupTLB->find_text(
sName);
208 m_xRenamePB->set_sensitive(!bExists && !
sName.isEmpty());
209 m_xDelPB->set_sensitive(IsDeleteAllowed(sEntry));
214 OUString sGroup = m_xNameED->get_text()
216 + OUString::number(m_xPathLB->get_active());
217 OSL_ENSURE(!m_pGlosHdl->FindGroupName(sGroup),
"group already available!");
218 m_InsertedArr.push_back(sGroup);
220 pData->sPath = m_xPathLB->get_active_text();
221 pData->sGroupName = sGroup;
222 pData->sGroupTitle = m_xNameED->get_text();
224 m_xGroupTLB->append(
sId, m_xNameED->get_text());
225 int nEntry = m_xGroupTLB->find_id(
sId);
226 m_xGroupTLB->set_text(nEntry,
pData->sPath, 1);
227 m_xGroupTLB->select(nEntry);
228 SelectHdl(*m_xGroupTLB);
229 m_xGroupTLB->scroll_to_row(nEntry);
234 std::vector<int> aWidths;
235 int x,
y, width, height;
236 if (m_xPathLB->get_extents_relative_to(*m_xGroupTLB,
x,
y, width, height))
238 aWidths.push_back(
x);
239 m_xGroupTLB->set_column_fixed_widths(aWidths);
245 int nEntry = m_xGroupTLB->get_selected_index();
248 rButton.set_sensitive(
false);
251 GlosBibUserData* pUserData = weld::fromId<GlosBibUserData*>(m_xGroupTLB->get_id(nEntry));
255 auto it = std::find(m_InsertedArr.begin(), m_InsertedArr.end(), sEntry);
256 if (it != m_InsertedArr.end())
258 m_InsertedArr.erase(it);
264 it = std::find_if(m_RenamedArr.begin(), m_RenamedArr.end(),
265 [&sEntry](OUString& s) { return o3tl::getToken(s, 0, RENAME_TOKEN_DELIM) == sEntry; });
266 if (it != m_RenamedArr.end())
268 m_RenamedArr.erase(it);
277 m_xGroupTLB->remove(nEntry);
278 if (!m_xGroupTLB->n_children())
279 rButton.set_sensitive(
false);
281 m_xNameED->set_text(OUString());
282 ModifyHdl(*m_xNameED);
287 int nEntry = m_xGroupTLB->get_selected_index();
288 GlosBibUserData* pUserData = weld::fromId<GlosBibUserData*>(m_xGroupTLB->get_id(nEntry));
291 const OUString sNewTitle(m_xNameED->get_text());
292 OUString sNewName = sNewTitle
294 + OUString::number(m_xPathLB->get_active());
295 OSL_ENSURE(!m_pGlosHdl->FindGroupName(sNewName),
"group already available!");
299 auto it = std::find(m_InsertedArr.begin(), m_InsertedArr.end(), sEntry);
300 if (it != m_InsertedArr.end())
302 m_InsertedArr.erase(it);
303 m_InsertedArr.push_back(sNewName);
310 m_RenamedArr.push_back(sEntry);
313 m_xGroupTLB->remove(nEntry);
316 pData->sPath = m_xPathLB->get_active_text();
317 pData->sGroupName = sNewName;
318 pData->sGroupTitle = sNewTitle;
321 m_xGroupTLB->append(
sId, m_xNameED->get_text());
322 nEntry = m_xGroupTLB->find_id(
sId);
323 m_xGroupTLB->set_text(nEntry, m_xPathLB->get_active_text(), 1);
324 m_xGroupTLB->select(nEntry);
325 SelectHdl(*m_xGroupTLB);
326 m_xGroupTLB->scroll_to_row(nEntry);
331 ModifyHdl(*m_xNameED);
336 const OUString sEntry(m_xNameED->get_text());
337 bool bEnableNew =
true;
338 bool bEnableDel =
false;
339 sal_uInt32 nCaseReadonly = m_xPathLB->get_active_id().toUInt32();
342 if (sEntry.isEmpty() || bDirReadonly)
344 else if(!sEntry.isEmpty())
346 int nPos = m_xGroupTLB->find_text(sEntry);
351 for (
int i = 0, nEntryCount = m_xGroupTLB->n_children();
i < nEntryCount; ++
i)
353 const OUString sTemp = m_xGroupTLB->get_text(
i, 0);
354 nCaseReadonly = m_xPathLB->get_id(m_xPathLB->find_text(m_xGroupTLB->get_text(
i,1))).toUInt32();
357 if( !bCase && rSCmp.isEqual( sTemp, sEntry ))
367 m_xGroupTLB->select(
nPos);
368 m_xGroupTLB->scroll_to_row(
nPos);
369 SelectHdl(*m_xGroupTLB);
372 int nEntry = m_xGroupTLB->get_selected_index();
375 GlosBibUserData* pUserData = weld::fromId<GlosBibUserData*>(m_xGroupTLB->get_id(nEntry));
376 bEnableDel = IsDeleteAllowed(pUserData->
sGroupName);
379 m_xDelPB->set_sensitive(bEnableDel);
380 m_xNewPB->set_sensitive(bEnableNew);
381 m_xRenamePB->set_sensitive(bEnableNew && nEntry != -1);
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static OUString GetCurrGroup()
virtual short run() override
SwGlossaryGroupDlg(weld::Window *pParent, std::vector< OUString > const &rPathArr, SwGlossaryHdl *pGlosHdl)
std::unique_ptr< weld::Button > m_xDelPB
std::unique_ptr< weld::Button > m_xRenamePB
std::vector< OUString > m_InsertedArr
SwGlossaryHdl * m_pGlosHdl
std::vector< OUString > m_RemovedArr
std::unique_ptr< weld::TreeView > m_xGroupTLB
std::unique_ptr< weld::Entry > m_xNameED
std::unique_ptr< weld::Button > m_xNewPB
virtual ~SwGlossaryGroupDlg() override
std::unique_ptr< weld::ComboBox > m_xPathLB
std::vector< OUString > m_RenamedArr
bool IsDeleteAllowed(const OUString &rGroup)
bool DelGroup(const OUString &)
bool IsReadOnly(const OUString *=nullptr) const
void SetCurGroup(const OUString &aGrp, bool bApi=false, bool bAlwaysCreateNew=false)
OUString GetGroupName(size_t, OUString *pTitle)
size_t GetGroupCnt() const
void RenameGroup(const OUString &rOld, OUString &rNew, const OUString &rNewTitle)
void NewGroup(OUString &rGroupName, const OUString &rTitle)
void EnableKillingFile(bool bEnable=true)
OUString const & GetURL() const
IMPL_LINK_NOARG(SwGlossaryGroupDlg, SelectHdl, weld::TreeView &, void)
#define RENAME_TOKEN_DELIM
IMPL_LINK(SwGlossaryGroupDlg, DeleteHdl, weld::Button &, rButton, void)
#define PATH_CASE_SENSITIVE
IMPL_STATIC_LINK(SwGlossaryGroupDlg, EditInsertTextHdl, OUString &, rText, bool)
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
#define LINK(Instance, Class, Member)
std::unique_ptr< sal_Int32[]> pData
bool UCB_IsCaseSensitiveFileName(std::u16string_view rURL)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OUString toId(const void *pValue)
#define SVT_SEARCHPATH_DELIMITER
OUString SwResId(TranslateId aId)