/src/libreoffice/sc/source/ui/dbgui/dbnamdlg.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <memory> |
21 | | #include <sal/config.h> |
22 | | |
23 | | #include <cassert> |
24 | | |
25 | | #include <comphelper/string.hxx> |
26 | | #include <unotools/charclass.hxx> |
27 | | #include <vcl/svapp.hxx> |
28 | | #include <vcl/weld/Dialog.hxx> |
29 | | #include <vcl/weld/EntryTreeView.hxx> |
30 | | #include <vcl/weld/MessageDialog.hxx> |
31 | | #include <o3tl/string_view.hxx> |
32 | | |
33 | | #include <reffact.hxx> |
34 | | #include <document.hxx> |
35 | | #include <globstr.hrc> |
36 | | #include <scresid.hxx> |
37 | | #include <rangenam.hxx> |
38 | | #include <globalnames.hxx> |
39 | | #include <dbnamdlg.hxx> |
40 | | #include <dbdocfun.hxx> |
41 | | |
42 | | namespace |
43 | | { |
44 | | void ERRORBOX(weld::Window* pParent, const OUString& rString) |
45 | 0 | { |
46 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, |
47 | 0 | VclMessageType::Warning, VclButtonsType::Ok, |
48 | 0 | rString)); |
49 | 0 | xBox->run(); |
50 | 0 | } |
51 | | |
52 | | |
53 | | class DBSaveData |
54 | | { |
55 | | public: |
56 | | DBSaveData( formula::RefEdit& rEd, weld::CheckButton& rHdr, weld::CheckButton& rTot, weld::CheckButton& rSize, weld::CheckButton& rFmt, |
57 | | weld::CheckButton& rStrip, ScRange& rArea ) |
58 | 0 | : rEdAssign(rEd) |
59 | 0 | , rBtnHeader(rHdr) |
60 | 0 | , rBtnTotals(rTot) |
61 | 0 | , rBtnSize(rSize) |
62 | 0 | , rBtnFormat(rFmt) |
63 | 0 | , rBtnStrip(rStrip) |
64 | 0 | , rCurArea(rArea) |
65 | 0 | , bHeader(false) |
66 | 0 | , bTotals(false) |
67 | 0 | , bSize(false) |
68 | 0 | , bFormat(false) |
69 | 0 | , bStrip(false) |
70 | 0 | , bDirty(false) |
71 | 0 | { |
72 | 0 | } |
73 | | void Save(); |
74 | | void Restore(); |
75 | | |
76 | | private: |
77 | | formula::RefEdit& rEdAssign; |
78 | | weld::CheckButton& rBtnHeader; |
79 | | weld::CheckButton& rBtnTotals; |
80 | | weld::CheckButton& rBtnSize; |
81 | | weld::CheckButton& rBtnFormat; |
82 | | weld::CheckButton& rBtnStrip; |
83 | | ScRange& rCurArea; |
84 | | OUString aStr; |
85 | | ScRange aArea; |
86 | | bool bHeader:1; |
87 | | bool bTotals:1; |
88 | | bool bSize:1; |
89 | | bool bFormat:1; |
90 | | bool bStrip:1; |
91 | | bool bDirty:1; |
92 | | }; |
93 | | |
94 | | } |
95 | | |
96 | | void DBSaveData::Save() |
97 | 0 | { |
98 | 0 | aArea = rCurArea; |
99 | 0 | aStr = rEdAssign.GetText(); |
100 | 0 | bHeader = rBtnHeader.get_active(); |
101 | 0 | bTotals = rBtnTotals.get_active(); |
102 | 0 | bSize = rBtnSize.get_active(); |
103 | 0 | bFormat = rBtnFormat.get_active(); |
104 | 0 | bStrip = rBtnStrip.get_active(); |
105 | 0 | bDirty = true; |
106 | 0 | } |
107 | | |
108 | | void DBSaveData::Restore() |
109 | 0 | { |
110 | 0 | if ( bDirty ) |
111 | 0 | { |
112 | 0 | rCurArea = aArea; |
113 | 0 | rEdAssign.SetText( aStr ); |
114 | 0 | rBtnHeader.set_active ( bHeader ); |
115 | 0 | rBtnTotals.set_active ( bTotals ); |
116 | 0 | rBtnSize.set_active ( bSize ); |
117 | 0 | rBtnFormat.set_active ( bFormat ); |
118 | 0 | rBtnStrip.set_active ( bStrip ); |
119 | 0 | bDirty = false; |
120 | 0 | } |
121 | 0 | } |
122 | | |
123 | | static std::unique_ptr<DBSaveData> xSaveObj; |
124 | | |
125 | | ScDbNameDlg::ScDbNameDlg(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent, |
126 | | ScViewData& rViewData) |
127 | 0 | : ScAnyRefDlgController(pB, pCW, pParent, |
128 | 0 | u"modules/scalc/ui/definedatabaserangedialog.ui"_ustr, u"DefineDatabaseRangeDialog"_ustr) |
129 | 0 | , m_rViewData(rViewData) |
130 | 0 | , rDoc(rViewData.GetDocument()) |
131 | 0 | , bRefInputMode(false) |
132 | 0 | , aAddrDetails(rDoc.GetAddressConvention(), 0, 0) |
133 | 0 | , aLocalDbCol(*(rDoc.GetDBCollection())) |
134 | 0 | , m_xEdName(m_xBuilder->weld_entry_tree_view(u"entrygrid"_ustr, u"entry"_ustr, u"entry-list"_ustr)) |
135 | 0 | , m_xAssignFrame(m_xBuilder->weld_frame(u"RangeFrame"_ustr)) |
136 | 0 | , m_xEdAssign(new formula::RefEdit(m_xBuilder->weld_entry(u"assign"_ustr))) |
137 | 0 | , m_xRbAssign(new formula::RefButton(m_xBuilder->weld_button(u"assignrb"_ustr))) |
138 | 0 | , m_xOptions(m_xBuilder->weld_widget(u"Options"_ustr)) |
139 | 0 | , m_xBtnHeader(m_xBuilder->weld_check_button(u"ContainsColumnLabels"_ustr)) |
140 | 0 | , m_xBtnTotals(m_xBuilder->weld_check_button(u"ContainsTotalsRow"_ustr)) |
141 | 0 | , m_xBtnDoSize(m_xBuilder->weld_check_button(u"InsertOrDeleteCells"_ustr)) |
142 | 0 | , m_xBtnKeepFmt(m_xBuilder->weld_check_button(u"KeepFormatting"_ustr)) |
143 | 0 | , m_xBtnStripData(m_xBuilder->weld_check_button(u"DontSaveImportedData"_ustr)) |
144 | 0 | , m_xFTSource(m_xBuilder->weld_label(u"Source"_ustr)) |
145 | 0 | , m_xFTOperations(m_xBuilder->weld_label(u"Operations"_ustr)) |
146 | 0 | , m_xBtnOk(m_xBuilder->weld_button(u"ok"_ustr)) |
147 | 0 | , m_xBtnCancel(m_xBuilder->weld_button(u"cancel"_ustr)) |
148 | 0 | , m_xBtnAdd(m_xBuilder->weld_button(u"add"_ustr)) |
149 | 0 | , m_xBtnRemove(m_xBuilder->weld_button(u"delete"_ustr)) |
150 | 0 | , m_xModifyPB(m_xBuilder->weld_button(u"modify"_ustr)) |
151 | 0 | , m_xInvalidFT(m_xBuilder->weld_label(u"invalid"_ustr)) |
152 | 0 | , m_xExpander(m_xBuilder->weld_expander(u"more"_ustr)) |
153 | 0 | { |
154 | 0 | m_xEdName->set_height_request_by_rows(4); |
155 | 0 | m_xEdAssign->SetReferences(this, m_xAssignFrame.get()); |
156 | 0 | m_xRbAssign->SetReferences(this, m_xEdAssign.get()); |
157 | 0 | aStrAdd = m_xBtnAdd->get_label(); |
158 | 0 | aStrModify = m_xModifyPB->get_label(); |
159 | 0 | aStrInvalid = m_xInvalidFT->get_label(); |
160 | | |
161 | | // so that the strings in the resource can stay with fixed texts: |
162 | 0 | aStrSource = m_xFTSource->get_label(); |
163 | 0 | aStrOperations = m_xFTOperations->get_label(); |
164 | |
|
165 | 0 | xSaveObj.reset(new DBSaveData( *m_xEdAssign, *m_xBtnHeader, *m_xBtnTotals, |
166 | 0 | *m_xBtnDoSize, *m_xBtnKeepFmt, *m_xBtnStripData, theCurArea )); |
167 | 0 | Init(); |
168 | 0 | } |
169 | | |
170 | | ScDbNameDlg::~ScDbNameDlg() |
171 | 0 | { |
172 | 0 | xSaveObj.reset(); |
173 | 0 | } |
174 | | |
175 | | void ScDbNameDlg::Init() |
176 | 0 | { |
177 | 0 | m_xBtnHeader->set_active(true); // Default: with column headers |
178 | 0 | m_xBtnTotals->set_active( false ); // Default: without totals row |
179 | 0 | m_xBtnDoSize->set_active(true); |
180 | 0 | m_xBtnKeepFmt->set_active(true); |
181 | |
|
182 | 0 | m_xBtnOk->connect_clicked ( LINK( this, ScDbNameDlg, OkBtnHdl ) ); |
183 | 0 | m_xBtnCancel->connect_clicked ( LINK( this, ScDbNameDlg, CancelBtnHdl ) ); |
184 | 0 | m_xBtnAdd->connect_clicked ( LINK( this, ScDbNameDlg, AddBtnHdl ) ); |
185 | 0 | m_xBtnRemove->connect_clicked ( LINK( this, ScDbNameDlg, RemoveBtnHdl ) ); |
186 | 0 | m_xEdName->connect_changed( LINK( this, ScDbNameDlg, NameModifyHdl ) ); |
187 | 0 | m_xEdAssign->SetModifyHdl ( LINK( this, ScDbNameDlg, AssModifyHdl ) ); |
188 | 0 | UpdateNames(); |
189 | |
|
190 | 0 | OUString theAreaStr; |
191 | |
|
192 | 0 | SCCOL nStartCol = 0; |
193 | 0 | SCROW nStartRow = 0; |
194 | 0 | SCTAB nStartTab = 0; |
195 | 0 | SCCOL nEndCol = 0; |
196 | 0 | SCROW nEndRow = 0; |
197 | 0 | SCTAB nEndTab = 0; |
198 | |
|
199 | 0 | ScDBCollection* pDBColl = rDoc.GetDBCollection(); |
200 | |
|
201 | 0 | m_rViewData.GetSimpleArea( nStartCol, nStartRow, nStartTab, |
202 | 0 | nEndCol, nEndRow, nEndTab ); |
203 | |
|
204 | 0 | theCurArea = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab); |
205 | |
|
206 | 0 | theAreaStr = theCurArea.Format(rDoc, ScRefFlags::RANGE_ABS_3D, aAddrDetails); |
207 | |
|
208 | 0 | if ( pDBColl ) |
209 | 0 | { |
210 | | // determine if the defined DB area has been marked: |
211 | 0 | ScDBData* pDBData = pDBColl->GetDBAtCursor( nStartCol, nStartRow, nStartTab, ScDBDataPortion::TOP_LEFT ); |
212 | 0 | if ( pDBData ) |
213 | 0 | { |
214 | 0 | ScAddress& rStart = theCurArea.aStart; |
215 | 0 | ScAddress& rEnd = theCurArea.aEnd; |
216 | 0 | SCCOL nCol1; |
217 | 0 | SCCOL nCol2; |
218 | 0 | SCROW nRow1; |
219 | 0 | SCROW nRow2; |
220 | 0 | SCTAB nTab; |
221 | |
|
222 | 0 | pDBData->GetArea( nTab, nCol1, nRow1, nCol2, nRow2 ); |
223 | |
|
224 | 0 | if ( (rStart.Tab() == nTab) |
225 | 0 | && (rStart.Col() == nCol1) && (rStart.Row() == nRow1) |
226 | 0 | && (rEnd.Col() == nCol2) && (rEnd.Row() == nRow2 ) ) |
227 | 0 | { |
228 | 0 | OUString aDBName = pDBData->GetName(); |
229 | 0 | if ( aDBName != STR_DB_LOCAL_NONAME ) |
230 | 0 | m_xEdName->set_entry_text(aDBName); |
231 | |
|
232 | 0 | m_xBtnHeader->set_active( pDBData->HasHeader() ); |
233 | 0 | m_xBtnTotals->set_active( pDBData->HasTotals() ); |
234 | 0 | m_xBtnDoSize->set_active( pDBData->IsDoSize() ); |
235 | 0 | m_xBtnKeepFmt->set_active( pDBData->IsKeepFmt() ); |
236 | 0 | m_xBtnStripData->set_active( pDBData->IsStripData() ); |
237 | 0 | SetInfoStrings( pDBData ); |
238 | 0 | } |
239 | 0 | } |
240 | 0 | } |
241 | |
|
242 | 0 | m_xEdAssign->SetText( theAreaStr ); |
243 | 0 | m_xEdName->grab_focus(); |
244 | 0 | bSaved = true; |
245 | 0 | xSaveObj->Save(); |
246 | 0 | NameModifyHdl( *m_xEdName ); |
247 | 0 | bInvalid = false; |
248 | 0 | } |
249 | | |
250 | | void ScDbNameDlg::SetInfoStrings( const ScDBData* pDBData ) |
251 | 0 | { |
252 | 0 | OUStringBuffer aBuf(aStrSource); |
253 | 0 | if (pDBData) |
254 | 0 | { |
255 | 0 | aBuf.append(" " + pDBData->GetSourceString()); |
256 | 0 | } |
257 | 0 | m_xFTSource->set_label(aBuf.makeStringAndClear()); |
258 | |
|
259 | 0 | aBuf.append(aStrOperations); |
260 | 0 | if (pDBData) |
261 | 0 | { |
262 | 0 | aBuf.append(" " + pDBData->GetOperations()); |
263 | 0 | } |
264 | 0 | m_xFTOperations->set_label(aBuf.makeStringAndClear()); |
265 | 0 | } |
266 | | |
267 | | // Transfer of a table area selected with the mouse, which is then displayed |
268 | | // as a new selection in the reference window. |
269 | | |
270 | | void ScDbNameDlg::SetReference( const ScRange& rRef, ScDocument& rDocP ) |
271 | 0 | { |
272 | 0 | if (!m_xEdAssign->GetWidget()->get_sensitive()) |
273 | 0 | return; |
274 | | |
275 | 0 | if ( rRef.aStart != rRef.aEnd ) |
276 | 0 | RefInputStart(m_xEdAssign.get()); |
277 | |
|
278 | 0 | theCurArea = rRef; |
279 | |
|
280 | 0 | OUString aRefStr(theCurArea.Format(rDocP, ScRefFlags::RANGE_ABS_3D, aAddrDetails)); |
281 | 0 | m_xEdAssign->SetRefString( aRefStr ); |
282 | 0 | m_xOptions->set_sensitive(true); |
283 | 0 | m_xBtnAdd->set_sensitive(true); |
284 | 0 | bSaved = true; |
285 | 0 | xSaveObj->Save(); |
286 | 0 | } |
287 | | |
288 | | void ScDbNameDlg::Close() |
289 | 0 | { |
290 | 0 | DoClose( ScDbNameDlgWrapper::GetChildWindowId() ); |
291 | 0 | } |
292 | | |
293 | | void ScDbNameDlg::SetActive() |
294 | 0 | { |
295 | 0 | m_xEdAssign->GrabFocus(); |
296 | | |
297 | | // No NameModifyHdl, because otherwise areas can not be changed |
298 | | // (the old content would be displayed again after the reference selection is pulled) |
299 | | // (the selected DB name has not changed either) |
300 | |
|
301 | 0 | RefInputDone(); |
302 | 0 | } |
303 | | |
304 | | void ScDbNameDlg::UpdateNames() |
305 | 0 | { |
306 | 0 | typedef ScDBCollection::NamedDBs DBsType; |
307 | |
|
308 | 0 | const DBsType& rDBs = aLocalDbCol.getNamedDBs(); |
309 | |
|
310 | 0 | m_xEdName->freeze(); |
311 | |
|
312 | 0 | m_xEdName->clear(); |
313 | 0 | m_xEdAssign->SetText( OUString() ); |
314 | |
|
315 | 0 | if (!rDBs.empty()) |
316 | 0 | { |
317 | 0 | for (const auto& rxDB : rDBs) |
318 | 0 | m_xEdName->append_text(rxDB->GetName()); |
319 | 0 | } |
320 | 0 | else |
321 | 0 | { |
322 | 0 | m_xBtnAdd->set_label( aStrAdd ); |
323 | 0 | m_xBtnAdd->set_sensitive(false); |
324 | 0 | m_xBtnRemove->set_sensitive(false); |
325 | 0 | } |
326 | |
|
327 | 0 | m_xEdName->thaw(); |
328 | 0 | } |
329 | | |
330 | | void ScDbNameDlg::UpdateDBData( const OUString& rStrName ) |
331 | 0 | { |
332 | |
|
333 | 0 | const ScDBData* pData = aLocalDbCol.getNamedDBs().findByUpperName(ScGlobal::getCharClass().uppercase(rStrName)); |
334 | |
|
335 | 0 | if ( pData ) |
336 | 0 | { |
337 | 0 | SCCOL nColStart = 0; |
338 | 0 | SCROW nRowStart = 0; |
339 | 0 | SCCOL nColEnd = 0; |
340 | 0 | SCROW nRowEnd = 0; |
341 | 0 | SCTAB nTab = 0; |
342 | |
|
343 | 0 | pData->GetArea( nTab, nColStart, nRowStart, nColEnd, nRowEnd ); |
344 | 0 | theCurArea = ScRange( ScAddress( nColStart, nRowStart, nTab ), |
345 | 0 | ScAddress( nColEnd, nRowEnd, nTab ) ); |
346 | 0 | OUString theArea(theCurArea.Format(rDoc, ScRefFlags::RANGE_ABS_3D, aAddrDetails)); |
347 | 0 | m_xEdAssign->SetText( theArea ); |
348 | 0 | m_xBtnAdd->set_label( aStrModify ); |
349 | 0 | m_xBtnHeader->set_active( pData->HasHeader() ); |
350 | 0 | m_xBtnTotals->set_active( pData->HasTotals() ); |
351 | 0 | m_xBtnDoSize->set_active( pData->IsDoSize() ); |
352 | 0 | m_xBtnKeepFmt->set_active( pData->IsKeepFmt() ); |
353 | 0 | m_xBtnStripData->set_active( pData->IsStripData() ); |
354 | 0 | SetInfoStrings( pData ); |
355 | 0 | } |
356 | |
|
357 | 0 | m_xBtnAdd->set_label( aStrModify ); |
358 | 0 | if (pData && !pData->GetTableStyleInfo()) |
359 | 0 | { |
360 | 0 | m_xOptions->set_sensitive(true); |
361 | 0 | m_xBtnAdd->set_sensitive(true); |
362 | 0 | m_xBtnRemove->set_sensitive(true); |
363 | 0 | } |
364 | 0 | else |
365 | 0 | { |
366 | 0 | m_xBtnAdd->set_sensitive(false); |
367 | 0 | m_xBtnRemove->set_sensitive(false); |
368 | 0 | m_xOptions->set_sensitive(false); |
369 | 0 | } |
370 | 0 | } |
371 | | |
372 | | bool ScDbNameDlg::IsRefInputMode() const |
373 | 0 | { |
374 | 0 | return bRefInputMode; |
375 | 0 | } |
376 | | |
377 | | // Handler: |
378 | | |
379 | | IMPL_LINK_NOARG(ScDbNameDlg, OkBtnHdl, weld::Button&, void) |
380 | 0 | { |
381 | 0 | bInvalid = false; |
382 | 0 | AddBtnHdl(*m_xBtnAdd); |
383 | | |
384 | | // Pass the changes and the remove list to the view: both are |
385 | | // transferred as a reference only, so that no dead memory can |
386 | | // be created at this point: |
387 | 0 | if (!bInvalid) |
388 | 0 | { |
389 | 0 | ScDBDocFunc aFunc(*m_rViewData.GetDocShell()); |
390 | 0 | aFunc.ModifyAllDBData(aLocalDbCol, aRemoveList); |
391 | 0 | response(RET_OK); |
392 | 0 | } |
393 | 0 | } |
394 | | |
395 | | IMPL_LINK_NOARG(ScDbNameDlg, CancelBtnHdl, weld::Button&, void) |
396 | 0 | { |
397 | 0 | response(RET_CANCEL); |
398 | 0 | } |
399 | | |
400 | | IMPL_LINK_NOARG(ScDbNameDlg, AddBtnHdl, weld::Button&, void) |
401 | 0 | { |
402 | 0 | OUString aNewName = comphelper::string::strip(m_xEdName->get_active_text(), ' '); |
403 | 0 | OUString aNewArea = m_xEdAssign->GetText(); |
404 | |
|
405 | 0 | if ( aNewName.isEmpty() || aNewArea.isEmpty() ) |
406 | 0 | return; |
407 | | |
408 | 0 | if (ScRangeData::IsNameValid(aNewName, rDoc) == ScRangeData::IsNameValidType::NAME_VALID |
409 | 0 | && aNewName != STR_DB_LOCAL_NONAME) |
410 | 0 | { |
411 | | // because editing can be done now, parsing is needed first |
412 | 0 | ScRange aTmpRange; |
413 | 0 | OUString aText = m_xEdAssign->GetText(); |
414 | 0 | if ( aTmpRange.ParseAny( aText, rDoc, aAddrDetails ) & ScRefFlags::VALID ) |
415 | 0 | { |
416 | 0 | theCurArea = aTmpRange; |
417 | 0 | ScAddress aStart = theCurArea.aStart; |
418 | 0 | ScAddress aEnd = theCurArea.aEnd; |
419 | |
|
420 | 0 | ScDBData* pOldEntry = aLocalDbCol.getNamedDBs().findByUpperName(ScGlobal::getCharClass().uppercase(aNewName)); |
421 | 0 | if (pOldEntry) |
422 | 0 | { |
423 | | // modify area |
424 | |
|
425 | 0 | pOldEntry->MoveTo( aStart.Tab(), aStart.Col(), aStart.Row(), |
426 | 0 | aEnd.Col(), aEnd.Row() ); |
427 | 0 | pOldEntry->SetByRow( true ); |
428 | 0 | pOldEntry->SetHeader( m_xBtnHeader->get_active() ); |
429 | 0 | pOldEntry->SetTotals( m_xBtnTotals->get_active() ); |
430 | 0 | pOldEntry->SetDoSize( m_xBtnDoSize->get_active() ); |
431 | 0 | pOldEntry->SetKeepFmt( m_xBtnKeepFmt->get_active() ); |
432 | 0 | pOldEntry->SetStripData( m_xBtnStripData->get_active() ); |
433 | 0 | } |
434 | 0 | else |
435 | 0 | { |
436 | | // insert new area |
437 | |
|
438 | 0 | std::unique_ptr<ScDBData> pNewEntry(new ScDBData( aNewName, aStart.Tab(), |
439 | 0 | aStart.Col(), aStart.Row(), |
440 | 0 | aEnd.Col(), aEnd.Row(), |
441 | 0 | true, m_xBtnHeader->get_active(), |
442 | 0 | m_xBtnTotals->get_active() )); |
443 | 0 | pNewEntry->SetDoSize( m_xBtnDoSize->get_active() ); |
444 | 0 | pNewEntry->SetKeepFmt( m_xBtnKeepFmt->get_active() ); |
445 | 0 | pNewEntry->SetStripData( m_xBtnStripData->get_active() ); |
446 | |
|
447 | 0 | bool ins = aLocalDbCol.getNamedDBs().insert(std::move(pNewEntry)); |
448 | 0 | assert(ins); (void)ins; |
449 | 0 | } |
450 | |
|
451 | 0 | UpdateNames(); |
452 | |
|
453 | 0 | m_xEdName->set_entry_text( OUString() ); |
454 | 0 | m_xEdName->grab_focus(); |
455 | 0 | m_xBtnAdd->set_label( aStrAdd ); |
456 | 0 | m_xBtnAdd->set_sensitive(false); |
457 | 0 | m_xBtnRemove->set_sensitive(false); |
458 | 0 | m_xEdAssign->SetText( OUString() ); |
459 | 0 | m_xBtnHeader->set_active(true); // Default: with column headers |
460 | 0 | m_xBtnTotals->set_active( false ); // Default: without totals row |
461 | 0 | m_xBtnDoSize->set_active( false ); |
462 | 0 | m_xBtnKeepFmt->set_active( false ); |
463 | 0 | m_xBtnStripData->set_active( false ); |
464 | 0 | SetInfoStrings( nullptr ); // empty |
465 | 0 | theCurArea = ScRange(); |
466 | 0 | bSaved = true; |
467 | 0 | xSaveObj->Save(); |
468 | 0 | NameModifyHdl( *m_xEdName ); |
469 | 0 | } |
470 | 0 | else |
471 | 0 | { |
472 | 0 | ERRORBOX(m_xDialog.get(), aStrInvalid); |
473 | 0 | m_xEdAssign->SelectAll(); |
474 | 0 | m_xEdAssign->GrabFocus(); |
475 | 0 | bInvalid = true; |
476 | 0 | } |
477 | 0 | } |
478 | 0 | else |
479 | 0 | { |
480 | 0 | ERRORBOX(m_xDialog.get(), ScResId(STR_INVALIDNAME)); |
481 | 0 | m_xEdName->select_entry_region(0, -1); |
482 | 0 | m_xEdName->grab_focus(); |
483 | 0 | bInvalid = true; |
484 | 0 | } |
485 | 0 | } |
486 | | |
487 | | namespace { |
488 | | |
489 | | class FindByName |
490 | | { |
491 | | const OUString& mrName; |
492 | | public: |
493 | 0 | explicit FindByName(const OUString& rName) : mrName(rName) {} |
494 | | bool operator() (std::unique_ptr<ScDBData> const& p) const |
495 | 0 | { |
496 | 0 | return p->GetName() == mrName; |
497 | 0 | } |
498 | | }; |
499 | | |
500 | | } |
501 | | |
502 | | IMPL_LINK_NOARG(ScDbNameDlg, RemoveBtnHdl, weld::Button&, void) |
503 | 0 | { |
504 | 0 | OUString aStrEntry = m_xEdName->get_active_text(); |
505 | 0 | ScDBCollection::NamedDBs& rDBs = aLocalDbCol.getNamedDBs(); |
506 | 0 | ScDBCollection::NamedDBs::iterator itr = |
507 | 0 | ::std::find_if(rDBs.begin(), rDBs.end(), FindByName(aStrEntry)); |
508 | |
|
509 | 0 | if (itr == rDBs.end()) |
510 | 0 | return; |
511 | | |
512 | 0 | OUString aStrDelMsg = ScResId( STR_QUERY_DELENTRY ); |
513 | 0 | OUString sMsg{ o3tl::getToken(aStrDelMsg, 0, '#') + aStrEntry + o3tl::getToken(aStrDelMsg, 1, '#') }; |
514 | 0 | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_xDialog.get(), |
515 | 0 | VclMessageType::Question, VclButtonsType::YesNo, |
516 | 0 | sMsg)); |
517 | 0 | xQueryBox->set_default_response(RET_YES); |
518 | 0 | if (RET_YES != xQueryBox->run()) |
519 | 0 | return; |
520 | | |
521 | 0 | SCTAB nTab; |
522 | 0 | SCCOL nColStart, nColEnd; |
523 | 0 | SCROW nRowStart, nRowEnd; |
524 | 0 | (*itr)->GetArea( nTab, nColStart, nRowStart, nColEnd, nRowEnd ); |
525 | 0 | aRemoveList.emplace_back( ScAddress( nColStart, nRowStart, nTab ), |
526 | 0 | ScAddress( nColEnd, nRowEnd, nTab ) ); |
527 | |
|
528 | 0 | rDBs.erase(itr); |
529 | |
|
530 | 0 | UpdateNames(); |
531 | |
|
532 | 0 | m_xEdName->set_entry_text( OUString() ); |
533 | 0 | m_xEdName->grab_focus(); |
534 | 0 | m_xBtnAdd->set_label( aStrAdd ); |
535 | 0 | m_xBtnAdd->set_sensitive(false); |
536 | 0 | m_xBtnRemove->set_sensitive(false); |
537 | 0 | m_xEdAssign->SetText( OUString() ); |
538 | 0 | theCurArea = ScRange(); |
539 | 0 | m_xBtnHeader->set_active(true); // Default: with column headers |
540 | 0 | m_xBtnTotals->set_active( false ); // Default: without totals row |
541 | 0 | m_xBtnDoSize->set_active( false ); |
542 | 0 | m_xBtnKeepFmt->set_active( false ); |
543 | 0 | m_xBtnStripData->set_active( false ); |
544 | 0 | SetInfoStrings( nullptr ); // empty |
545 | 0 | bSaved=false; |
546 | 0 | xSaveObj->Restore(); |
547 | 0 | NameModifyHdl( *m_xEdName ); |
548 | 0 | } |
549 | | |
550 | | IMPL_LINK_NOARG(ScDbNameDlg, NameModifyHdl, weld::ComboBox&, void) |
551 | 0 | { |
552 | 0 | OUString theName = m_xEdName->get_active_text(); |
553 | 0 | bool bNameFound = m_xEdName->find_text(theName) != -1; |
554 | |
|
555 | 0 | if ( theName.isEmpty() ) |
556 | 0 | { |
557 | 0 | if (m_xBtnAdd->get_label() != aStrAdd) |
558 | 0 | m_xBtnAdd->set_label( aStrAdd ); |
559 | 0 | m_xBtnAdd->set_sensitive(false); |
560 | 0 | m_xBtnRemove->set_sensitive(false); |
561 | 0 | m_xAssignFrame->set_sensitive(false); |
562 | 0 | m_xOptions->set_sensitive(false); |
563 | | //bSaved=sal_False; |
564 | | //xSaveObj->Restore(); |
565 | | //@BugID 54702 enable/disable in the base class only |
566 | | //SFX_APPWINDOW->Disable(sal_False); //! general method in ScAnyRefDlg |
567 | 0 | bRefInputMode = false; |
568 | 0 | } |
569 | 0 | else |
570 | 0 | { |
571 | 0 | if ( bNameFound ) |
572 | 0 | { |
573 | 0 | if (m_xBtnAdd->get_label() != aStrModify) |
574 | 0 | m_xBtnAdd->set_label( aStrModify ); |
575 | |
|
576 | 0 | if(!bSaved) |
577 | 0 | { |
578 | 0 | bSaved = true; |
579 | 0 | xSaveObj->Save(); |
580 | 0 | } |
581 | 0 | UpdateDBData( theName ); |
582 | 0 | } |
583 | 0 | else |
584 | 0 | { |
585 | 0 | if (m_xBtnAdd->get_label() != aStrAdd) |
586 | 0 | m_xBtnAdd->set_label( aStrAdd ); |
587 | |
|
588 | 0 | bSaved=false; |
589 | 0 | xSaveObj->Restore(); |
590 | |
|
591 | 0 | if ( !m_xEdAssign->GetText().isEmpty() ) |
592 | 0 | { |
593 | 0 | m_xBtnAdd->set_sensitive(true); |
594 | 0 | m_xOptions->set_sensitive(true); |
595 | 0 | } |
596 | 0 | else |
597 | 0 | { |
598 | 0 | m_xBtnAdd->set_sensitive(false); |
599 | 0 | m_xOptions->set_sensitive(false); |
600 | 0 | } |
601 | 0 | m_xBtnRemove->set_sensitive(false); |
602 | 0 | } |
603 | |
|
604 | 0 | const ScDBData* pData = aLocalDbCol.getNamedDBs().findByUpperName( |
605 | 0 | ScGlobal::getCharClass().uppercase(theName)); |
606 | 0 | if (pData && pData->GetTableStyleInfo()) |
607 | 0 | m_xAssignFrame->set_sensitive(false); |
608 | 0 | else |
609 | 0 | m_xAssignFrame->set_sensitive(true); |
610 | | |
611 | | //@BugID 54702 enable/disable in the base class only |
612 | | //SFX_APPWINDOW->set_sensitive(true); |
613 | 0 | bRefInputMode = true; |
614 | 0 | } |
615 | 0 | } |
616 | | |
617 | | IMPL_LINK_NOARG(ScDbNameDlg, AssModifyHdl, formula::RefEdit&, void) |
618 | 0 | { |
619 | | // parse here for Save(), etc. |
620 | |
|
621 | 0 | ScRange aTmpRange; |
622 | 0 | OUString aText = m_xEdAssign->GetText(); |
623 | 0 | if ( aTmpRange.ParseAny( aText, rDoc, aAddrDetails ) & ScRefFlags::VALID ) |
624 | 0 | theCurArea = aTmpRange; |
625 | |
|
626 | 0 | if (!aText.isEmpty() && !m_xEdName->get_active_text().isEmpty()) |
627 | 0 | { |
628 | 0 | m_xBtnAdd->set_sensitive(true); |
629 | 0 | m_xBtnHeader->set_sensitive(true); |
630 | 0 | m_xBtnTotals->set_sensitive(true); |
631 | 0 | m_xBtnDoSize->set_sensitive(true); |
632 | 0 | m_xBtnKeepFmt->set_sensitive(true); |
633 | 0 | m_xBtnStripData->set_sensitive(true); |
634 | 0 | m_xFTSource->set_sensitive(true); |
635 | 0 | m_xFTOperations->set_sensitive(true); |
636 | 0 | } |
637 | 0 | else |
638 | 0 | { |
639 | 0 | m_xBtnAdd->set_sensitive(false); |
640 | 0 | m_xBtnHeader->set_sensitive(false); |
641 | 0 | m_xBtnTotals->set_sensitive(false); |
642 | 0 | m_xBtnDoSize->set_sensitive(false); |
643 | 0 | m_xBtnKeepFmt->set_sensitive(false); |
644 | 0 | m_xBtnStripData->set_sensitive(false); |
645 | 0 | m_xFTSource->set_sensitive(false); |
646 | 0 | m_xFTOperations->set_sensitive(false); |
647 | 0 | } |
648 | 0 | } |
649 | | |
650 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |