1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
|
/* This file is part of the KDE project
Copyright (C) 2002, 2003 Lucijan Busch <[email protected]>
Copyright (C) 2003-2006 Jaroslaw Staniek <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kexibrowser.h"
#include "kexibrowser_p.h"
#include "kexibrowseritem.h"
#include <tqheader.h>
#include <tqpoint.h>
#include <tqpixmapcache.h>
#include <tqtoolbutton.h>
#include <tqtooltip.h>
#include <tqwhatsthis.h>
#include <tdeapplication.h>
#include <kiconloader.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <tdepopupmenu.h>
#include <tdelistview.h>
#include <tdemessagebox.h>
#include <klineedit.h>
#include <kimageeffect.h>
#include <tdeconfig.h>
#include <kexi.h>
#include <kexipart.h>
#include <kexipartinfo.h>
#include <kexipartitem.h>
#include <kexiproject.h>
#include <kexidialogbase.h>
#include <keximainwindow.h>
#include <kexiutils/identifier.h>
#include <widget/utils/kexiflowlayout.h>
#include <widget/kexismalltoolbutton.h>
#include <kexidb/utils.h>
/*
class KexiBrowserView : public TQWidget
{
KexiBrowserView*(
};
KexiBrowserView::KexiBrowserView(KexiMainWindow *mainWin)
: TQWidget(mainWin, "KexiBrowserView")
{
TQVBoxLayout *lyr = new TQVBoxLayout(this);
KexiFlowLayout *buttons_flyr = new KexiFlowLayout(lyr);
m_browser = KexiBrowser(this, mainWin);
lyr->addWidget(m_browser);
setFocusProxy(m_browser);
}*/
KexiBrowser::KexiBrowser(TQWidget* parent, KexiMainWindow *mainWin, int features)
: TQWidget(parent, "KexiBrowser")
, m_mainWin(mainWin)
, m_features(features)
, m_actions( new TDEActionCollection(this) )
, m_baseItems(199, false)
, m_normalItems(199)
, m_prevSelectedPart(0)
, m_singleClick(false)
// , m_nameEndsWithAsterisk(false)
, m_readOnly(false)
// , m_enableExecuteArea(true)
{
setCaption(i18n("Project Navigator"));
setIcon(*m_mainWin->icon());
TQVBoxLayout *lyr = new TQVBoxLayout(this);
KexiFlowLayout *buttons_flyr = new KexiFlowLayout(lyr);
m_list = new KexiBrowserListView(this);
lyr->addWidget(m_list);
m_list->installEventFilter(this);
m_list->renameLineEdit()->installEventFilter(this);
connect( kapp, TQT_SIGNAL( settingsChanged(int) ), TQT_SLOT( slotSettingsChanged(int) ) );
slotSettingsChanged(0);
m_list->header()->hide();
m_list->addColumn("");
m_list->setShowToolTips(true);
m_list->setSorting(0);
m_list->sort();
m_list->setAllColumnsShowFocus(true);
m_list->setTooltipColumn(0);
m_list->renameLineEdit()->setValidator( new KexiUtils::IdentifierValidator(TQT_TQOBJECT(this)) );
m_list->setResizeMode(TQListView::LastColumn);
connect(m_list, TQT_SIGNAL(contextMenu(TDEListView *, TQListViewItem *, const TQPoint &)),
TQT_TQOBJECT(this), TQT_SLOT(slotContextMenu(TDEListView*, TQListViewItem *, const TQPoint&)));
connect(m_list, TQT_SIGNAL(selectionChanged(TQListViewItem*)), this,
TQT_SLOT(slotSelectionChanged(TQListViewItem*)));
TDEConfig *config = kapp->config();
config->setGroup("MainWindow");
if ((m_features & SingleClickOpensItemOptionEnabled)
&& config->readBoolEntry("SingleClickOpensItem", false))
{
connect(m_list, TQT_SIGNAL(executed(TQListViewItem*)), this,
TQT_SLOT(slotExecuteItem(TQListViewItem*)));
}
else {
connect(m_list, TQT_SIGNAL(doubleClicked(TQListViewItem*)), this,
TQT_SLOT(slotExecuteItem(TQListViewItem*)));
m_list->enableExecuteArea = false;
}
// actions
m_openAction = new TDEAction(i18n("&Open"), "document-open", 0/*TQt::Key_Enter conflict!*/, TQT_TQOBJECT(this),
TQT_SLOT(slotOpenObject()), TQT_TQOBJECT(this), "open_object");
m_openAction->setToolTip(i18n("Open object"));
m_openAction->setWhatsThis(i18n("Opens object selected in the list"));
// m_openAction->plug(m_toolbar);
KexiSmallToolButton *btn;
if (m_features & Toolbar) {
btn = new KexiSmallToolButton(this, m_openAction);
buttons_flyr->add(btn);
}
if (m_mainWin->userMode()) {
//! @todo some of these actions can be supported once we deliver ACLs...
m_deleteAction = 0;
m_renameAction = 0;
m_designAction = 0;
m_editTextAction = 0;
m_newObjectAction = 0;
m_newObjectPopup = 0;
}
else {
m_deleteAction = new TDEAction(i18n("&Delete"), "edit-delete", 0/*TQt::Key_Delete*/,
TQT_TQOBJECT(this), TQT_SLOT(slotRemove()), m_actions, "edit_delete");
//! @todo 1.1: just add "Delete" tooltip and what's this
m_deleteAction->setToolTip(i18n("&Delete").replace("&",""));
m_renameAction = new TDEAction(i18n("&Rename"), "", 0,
TQT_TQOBJECT(this), TQT_SLOT(slotRename()), m_actions, "edit_rename");
#ifdef KEXI_SHOW_UNIMPLEMENTED
//todo plugSharedAction("edit_cut",TQT_SLOT(slotCut()));
//todo plugSharedAction("edit_copy",TQT_SLOT(slotCopy()));
//todo plugSharedAction("edit_paste",TQT_SLOT(slotPaste()));
#endif
m_designAction = new TDEAction(i18n("&Design"), "edit", 0/*TQt::CTRL + TQt::Key_Enter conflict!*/, TQT_TQOBJECT(this),
TQT_SLOT(slotDesignObject()), TQT_TQOBJECT(this), "design_object");
m_designAction->setToolTip(i18n("Design object"));
m_designAction->setWhatsThis(i18n("Starts designing of the object selected in the list"));
if (m_features & Toolbar) {
btn = new KexiSmallToolButton(this, m_designAction);
buttons_flyr->add(btn);
}
m_editTextAction = new TDEAction(i18n("Open in &Text View"), "", 0, TQT_TQOBJECT(this),
TQT_SLOT(slotEditTextObject()), TQT_TQOBJECT(this), "editText_object");
m_editTextAction->setToolTip(i18n("Open object in text view"));
m_editTextAction->setWhatsThis(i18n("Opens selected object in the list in text view"));
m_newObjectAction = new TDEAction("", "document-new", 0, TQT_TQOBJECT(this), TQT_SLOT(slotNewObject()), TQT_TQOBJECT(this), "new_object");
if (m_features & Toolbar) {
m_newObjectToolButton = new KexiSmallToolButton(this, "", TQIconSet(), "new_object");
m_newObjectPopup = new TDEPopupMenu(this, "newObjectPopup");
connect(m_newObjectPopup, TQT_SIGNAL(aboutToShow()), TQT_TQOBJECT(this), TQT_SLOT(slotNewObjectPopupAboutToShow()));
// KexiPart::Part* part = Kexi::partManager().part("kexi/table");
// m_newObjectPopup->insertItem( SmallIconSet(part->info()->createItemIcon()), part->instanceName() );
m_newObjectToolButton->setPopup(m_newObjectPopup);
m_newObjectToolButton->setPopupDelay(TQApplication::startDragTime());
connect(m_newObjectToolButton, TQT_SIGNAL(clicked()), TQT_TQOBJECT(this), TQT_SLOT(slotNewObject()));
buttons_flyr->add(m_newObjectToolButton);
m_deleteObjectToolButton = new KexiSmallToolButton(this, m_deleteAction);
m_deleteObjectToolButton->setTextLabel("");
buttons_flyr->add(m_deleteObjectToolButton);
}
}
m_executeAction = new TDEAction(i18n("Execute"), "media-playback-start", 0, TQT_TQOBJECT(this),
TQT_SLOT(slotExecuteObject()), TQT_TQOBJECT(this), "data_execute");
m_exportActionMenu = new TDEActionMenu(i18n("Export"));
m_dataExportAction = new TDEAction(i18n("Export->To File as Data &Table... ", "To &File as Data Table..."),
"table", 0, TQT_TQOBJECT(this), TQT_SLOT(slotExportAsDataTable()), TQT_TQOBJECT(this), "exportAsDataTable");
m_dataExportAction->setWhatsThis(
i18n("Exports data from the currently selected table or query data to a file."));
m_exportActionMenu->insert( m_dataExportAction );
m_printAction = new TDEAction(i18n("&Print..."), "document-print", 0, TQT_TQOBJECT(this),
TQT_SLOT(slotPrintItem()), TQT_TQOBJECT(this), "printItem");
m_printAction->setWhatsThis(
i18n("Prints data from the currently selected table or query."));
m_pageSetupAction = new TDEAction(i18n("Page Setup..."), "", 0, TQT_TQOBJECT(this),
TQT_SLOT(slotPageSetupForItem()), TQT_TQOBJECT(this), "pageSetupForItem");
m_pageSetupAction->setWhatsThis(
i18n("Shows page setup for printing the active table or query."));
if (m_mainWin->userMode()) {
//! @todo some of these actions can be supported once we deliver ACLs...
m_partPopup = 0;
}
else {
m_partPopup = new TDEPopupMenu(this, "partPopup");
m_partPopupTitle_id = m_partPopup->insertTitle("");
m_newObjectAction->plug(m_partPopup);
#ifdef KEXI_SHOW_UNIMPLEMENTED
m_partPopup->insertSeparator();
plugSharedAction("edit_paste", m_partPopup);
#endif
}
if (m_features & ContextMenus) {
//init popups
m_itemPopup = new TDEPopupMenu(this, "itemPopup");
m_itemPopupTitle_id = m_itemPopup->insertTitle("");
m_openAction->plug(m_itemPopup);
m_openAction_id = m_itemPopup->idAt(m_itemPopup->count()-1);
if (m_designAction) {
m_designAction->plug(m_itemPopup);
m_designAction_id = m_itemPopup->idAt(m_itemPopup->count()-1);
}
if (m_editTextAction) {
m_editTextAction->plug(m_itemPopup);
m_editTextAction_id = m_itemPopup->idAt(m_itemPopup->count()-1);
}
if (m_newObjectAction) {
m_newObjectAction->plug(m_itemPopup);
m_itemPopup->insertSeparator();
}
#ifdef KEXI_SHOW_UNIMPLEMENTED
//todo plugSharedAction("edit_cut", m_itemPopup);
//todo plugSharedAction("edit_copy", m_itemPopup);
//todo m_itemPopup->insertSeparator();
#endif
m_executeAction->plug(m_itemPopup);
m_executeAction_id = m_itemPopup->idAt(m_itemPopup->count()-1);
m_exportActionMenu->plug(m_itemPopup);
m_exportActionMenu_id = m_exportActionMenu->menuId(0);
m_itemPopup->insertSeparator();
m_exportActionMenu_id_sep = m_itemPopup->idAt(m_itemPopup->count()-1);
m_printAction->plug(m_itemPopup);
m_printAction_id = m_itemPopup->idAt(m_itemPopup->count()-1);
m_pageSetupAction->plug(m_itemPopup);
m_pageSetupAction_id = m_itemPopup->idAt(m_itemPopup->count()-1);
if (m_renameAction || m_deleteAction) {
m_itemPopup->insertSeparator();
m_pageSetupAction_id_sep = m_itemPopup->idAt(m_itemPopup->count()-1);
}
else {
m_pageSetupAction_id_sep = -1;
}
if (m_renameAction)
m_renameAction->plug(m_itemPopup);
if (m_deleteAction)
m_deleteAction->plug(m_itemPopup);
}
else {
m_itemPopup = 0;
}
if (!(m_features & Writable)) {
setReadOnly(true);
}
}
KexiBrowser::~KexiBrowser()
{
}
void KexiBrowser::setProject(KexiProject* prj, const TQString& itemsMimeType,
TQString* partManagerErrorMessages)
{
clear();
m_itemsMimeType = itemsMimeType;
m_list->setRootIsDecorated(m_itemsMimeType.isEmpty());
KexiPart::PartInfoList *pl = Kexi::partManager().partInfoList();
for (KexiPart::Info *info = pl->first(); info; info = pl->next()) {
if (!info->isVisibleInNavigator())
continue;
if (!m_itemsMimeType.isEmpty() && info->mimeType()!=m_itemsMimeType.latin1())
continue;
// kdDebug() << "KexiMainWindowImpl::initNavigator(): adding " << it->groupName() << endl;
/* KexiPart::Part *p=Kexi::partManager().part(it);
if (!p) {
//TODO: js - OPTIONALLY: show error
continue;
}
p->createGUIClient(this);*/
//load part - we need this to have GUI merged with part's actions
//! @todo FUTURE - don't do that when DESIGN MODE is OFF
KexiPart::Part *p=Kexi::partManager().part(info);
if (p) {
KexiBrowserItem *groupItem = 0;
if (m_itemsMimeType.isEmpty()) {
groupItem = addGroup(*info);
if (!groupItem)
continue;
}
//lookup project's objects (part items)
//! @todo FUTURE - don't do that when DESIGN MODE is OFF
KexiPart::ItemDict *item_dict = prj->items(info);
if (!item_dict)
continue;
for (KexiPart::ItemDictIterator item_it( *item_dict ); item_it.current(); ++item_it)
addItem(*item_it.current(), groupItem, info);
if (!m_itemsMimeType.isEmpty())
break; //the only group added, so our work is completed
}
else {
//add this error to the list that will be displayed later
TQString msg, details;
KexiDB::getHTMLErrorMesage(&Kexi::partManager(), msg, details);
if (!msg.isEmpty() && partManagerErrorMessages) {
if (partManagerErrorMessages->isEmpty()) {
*partManagerErrorMessages = TQString("<qt><p>")
+i18n("Errors encountered during loading plugins:")+"<ul>";
}
partManagerErrorMessages->append( TQString("<li>") + msg );
if (!details.isEmpty())
partManagerErrorMessages->append(TQString("<br>")+details);
partManagerErrorMessages->append("</li>");
}
}
}
if (partManagerErrorMessages && !partManagerErrorMessages->isEmpty())
partManagerErrorMessages->append("</ul></p>");
}
TQString KexiBrowser::itemsMimeType() const
{
return m_itemsMimeType;
}
KexiBrowserItem *KexiBrowser::addGroup(KexiPart::Info& info)
{
if(!info.isVisibleInNavigator())
return 0;
KexiBrowserItem *item = new KexiBrowserItem(m_list, &info);
m_baseItems.insert(info.mimeType().lower(), item);
return item;
// kdDebug() << "KexiBrowser::addGroup()" << endl;
}
KexiBrowserItem* KexiBrowser::addItem(KexiPart::Item& item)
{
//part object for this item
KexiBrowserItem *parent = item.mimeType().isEmpty() ? 0 : m_baseItems.find(item.mimeType().lower());
return addItem(item, parent, parent->info());
}
KexiBrowserItem* KexiBrowser::addItem(KexiPart::Item& item, KexiBrowserItem *parent, KexiPart::Info* info)
{
// if (!parent) //TODO: add "Other" part group for that
// return 0;
// kdDebug() << "KexiBrowser::addItem() found parent:" << parent << endl;
KexiBrowserItem *bitem;
if (parent)
bitem = new KexiBrowserItem(parent, info, &item);
else
bitem = new KexiBrowserItem(m_list, info, &item);
m_normalItems.insert(item.identifier(), bitem);
return bitem;
}
void
KexiBrowser::slotRemoveItem(const KexiPart::Item &item)
{
KexiBrowserItem *to_remove=m_normalItems.take(item.identifier());
if (!to_remove)
return;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
TQListViewItem *new_item_to_select = 0;
if (it==to_remove) {//compute item to select if current one will be removed
new_item_to_select = it->itemBelow();//nearest item to select
if (!new_item_to_select || new_item_to_select->parent()!=it->parent()) {
new_item_to_select = it->itemAbove();
}
}
delete to_remove;
if (new_item_to_select)
m_list->setSelected(new_item_to_select, true);
}
void
KexiBrowser::slotContextMenu(TDEListView* /*list*/, TQListViewItem *item, const TQPoint &pos)
{
if(!item || !(m_features & ContextMenus))
return;
KexiBrowserItem *bit = static_cast<KexiBrowserItem*>(item);
TDEPopupMenu *pm = 0;
if (bit->item()) {
pm = m_itemPopup;
//update popup title
TQString title_text = bit->text(0).stripWhiteSpace();
KexiBrowserItem *par_it = static_cast<KexiBrowserItem*>(bit->parent());
KexiPart::Part* par_part = 0;
if (par_it && par_it->info() && ((par_part = Kexi::partManager().part(par_it->info()))) && !par_part->instanceCaption().isEmpty()) {
//add part type name
title_text += (" : " + par_part->instanceCaption());
}
pm->changeTitle(m_itemPopupTitle_id, *bit->pixmap(0), title_text);
}
else if (m_partPopup) {
pm = m_partPopup;
TQString title_text = bit->text(0).stripWhiteSpace();
pm->changeTitle(m_partPopupTitle_id, *bit->pixmap(0), title_text);
/* KexiPart::Part* part = Kexi::partManager().part(bit->info());
if (part)
m_newObjectAction->setText(i18n("&Create Object: %1...").arg( part->instanceName() ));
else
m_newObjectAction->setText(i18n("&Create Object..."));
m_newObjectAction->setIconSet( SmallIconSet(bit->info()->itemIcon()) );*/
m_list->setCurrentItem(item);
m_list->repaintItem(item);
}
if (pm)
pm->exec(pos);
}
void
KexiBrowser::slotExecuteItem(TQListViewItem *vitem)
{
// kdDebug() << "KexiBrowser::slotExecuteItem()" << endl;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(vitem);
if (!it)
return;
if (!it->item() && !m_singleClick /*annoying when in single click mode*/) {
m_list->setOpen( vitem, !vitem->isOpen() );
return;
}
if (it->info()->isExecuteSupported())
emit executeItem( it->item() );
else
emit openOrActivateItem( it->item(), Kexi::DataViewMode );
}
void
KexiBrowser::slotSelectionChanged(TQListViewItem* i)
{
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(i);
if (!it)
return;
KexiPart::Part* part = Kexi::partManager().part(it->info());
if (!part) {
it = static_cast<KexiBrowserItem*>(it->parent());
if (it) {
part = Kexi::partManager().part(it->info());
}
}
const bool gotitem = it && it->item();
//bool gotgroup = it && !it->item();
//TODO: also check if the item is not read only
if (m_deleteAction) {
m_deleteAction->setEnabled(gotitem && !m_readOnly);
if (m_features & Toolbar) {
m_deleteObjectToolButton->setEnabled(gotitem && !m_readOnly);
}
}
#ifdef KEXI_SHOW_UNIMPLEMENTED
//todo setAvailable("edit_cut",gotitem);
//todo setAvailable("edit_copy",gotitem);
//todo setAvailable("edit_edititem",gotitem);
#endif
m_openAction->setEnabled(gotitem && part && (part->supportedViewModes() & Kexi::DataViewMode));
if (m_designAction)
m_designAction->setEnabled(gotitem && part && (part->supportedViewModes() & Kexi::DesignViewMode));
if (m_editTextAction)
m_editTextAction->setEnabled(gotitem && part && (part->supportedViewModes() & Kexi::TextViewMode));
if (m_features & ContextMenus) {
m_itemPopup->setItemVisible(m_openAction_id, m_openAction->isEnabled());
if (m_designAction)
m_itemPopup->setItemVisible(m_designAction_id, m_designAction->isEnabled());
if (m_editTextAction)
m_itemPopup->setItemVisible(m_editTextAction_id, part && m_editTextAction->isEnabled());
if (m_executeAction)
m_itemPopup->setItemVisible(m_executeAction_id, gotitem && it->info()->isExecuteSupported());
if (m_exportActionMenu) {
m_itemPopup->setItemVisible(m_exportActionMenu_id, gotitem && it->info()->isDataExportSupported());
m_itemPopup->setItemVisible(m_exportActionMenu_id_sep, gotitem && it->info()->isDataExportSupported());
}
if (m_printAction)
m_itemPopup->setItemVisible(m_printAction_id, gotitem && it->info()->isPrintingSupported());
if (m_pageSetupAction) {
m_itemPopup->setItemVisible(m_pageSetupAction_id, gotitem && it->info()->isPrintingSupported());
if (m_pageSetupAction_id_sep!=-1)
m_itemPopup->setItemVisible(m_pageSetupAction_id_sep, gotitem && it->info()->isPrintingSupported());
}
}
if (m_prevSelectedPart != part) {
m_prevSelectedPart = part;
if (part) {
if (m_newObjectAction) {
m_newObjectAction->setText(i18n("&Create Object: %1...").arg( part->instanceCaption() ));
m_newObjectAction->setIcon( part->info()->createItemIcon() );
if (m_features & Toolbar) {
m_newObjectToolButton->setIconSet( part->info()->createItemIcon() );
TQToolTip::add(m_newObjectToolButton,
i18n("Create object: %1").arg( part->instanceCaption().lower() ));
TQWhatsThis::add(m_newObjectToolButton,
i18n("Creates a new object: %1").arg( part->instanceCaption().lower() ));
}
}
} else {
if (m_newObjectAction) {
m_newObjectAction->setText(i18n("&Create Object..."));
// m_newObjectToolbarAction->setIconSet( SmallIconSet("document-new") );
// m_newObjectToolbarAction->setText(m_newObjectAction->text());
if (m_features & Toolbar) {
m_newObjectToolButton->setIconSet( "document-new" );
TQToolTip::add(m_newObjectToolButton, i18n("Create object"));
TQWhatsThis::add(m_newObjectToolButton, i18n("Creates a new object"));
}
}
}
}
emit selectionChanged(it ? it->item() : 0);
}
void KexiBrowser::installEventFilter ( const TQObject * filterObj )
{
if (!filterObj)
return;
m_list->installEventFilter ( filterObj );
TQWidget::installEventFilter ( filterObj );
}
bool KexiBrowser::eventFilter ( TQObject *o, TQEvent * e )
{
if (o==m_list && e->type()==TQEvent::Resize) {
kdDebug() << "resize!" << endl;
}
if (o==m_list->renameLineEdit()) {
if (e->type()==TQEvent::Hide)
itemRenameDone();
}
else if (e->type()==TQEvent::KeyPress) {
TQKeyEvent *ke = TQT_TQKEYEVENT(e);
if (ke->key()==TQt::Key_Enter || ke->key()==TQt::Key_Return) {
if (0==(ke->state() & (TQt::ShiftButton|TQt::ControlButton|TQt::AltButton))) {
TQListViewItem *it = m_list->selectedItem();
if (it)
slotExecuteItem(it);
}
else if (TQt::ControlButton==(ke->state() & (TQt::ShiftButton|TQt::ControlButton|TQt::AltButton))) {
slotDesignObject();
}
}
}
else if (e->type()==TQEvent::AccelOverride) {
TQKeyEvent *ke = TQT_TQKEYEVENT(e);
//override delete action
if (ke->key()==TQt::Key_Delete && ke->state()==Qt::NoButton) {
slotRemove();
ke->accept();
return true;
}
//override rename action
if (ke->key()==TQt::Key_F2 && ke->state()==Qt::NoButton) {
slotRename();
ke->accept();
return true;
}
/* else if (ke->key()==TQt::Key_Enter || ke->key()==TQt::Key_Return) {
if (ke->state()==ControlButton) {
slotDesignObject();
}
else if (ke->state()==0 && !m_list->renameLineEdit()->isVisible()) {
TQListViewItem *it = m_list->selectedItem();
if (it)
slotExecuteItem(it);
}
ke->accept();
return true;
}*/
}
return false;
}
void KexiBrowser::slotRemove()
{
if (!m_deleteAction || !m_deleteAction->isEnabled() || !(m_features & Writable))
return;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
if (!it || !it->item())
return;
emit removeItem( it->item() );
}
void KexiBrowser::slotNewObject()
{
if (!m_newObjectAction || !(m_features & Writable))
return;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
if (!it || !it->info())
return;
emit newItem( it->info() );
}
void KexiBrowser::slotOpenObject()
{
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
if (!it || !it->item())
return;
emit openItem( it->item(), Kexi::DataViewMode );
}
void KexiBrowser::slotDesignObject()
{
if (!m_designAction)
return;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
if (!it || !it->item())
return;
emit openItem( it->item(), Kexi::DesignViewMode );
}
void KexiBrowser::slotEditTextObject()
{
if (!m_editTextAction)
return;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
if (!it || !it->item())
return;
emit openItem( it->item(), Kexi::TextViewMode );
}
void KexiBrowser::slotCut()
{
if (!(m_features & Writable))
return;
// KEXI_UNFINISHED_SHARED_ACTION("edit_cut");
//TODO
}
void KexiBrowser::slotCopy()
{
// KEXI_UNFINISHED_SHARED_ACTION("edit_copy");
//TODO
}
void KexiBrowser::slotPaste()
{
if (!(m_features & Writable))
return;
// KEXI_UNFINISHED_SHARED_ACTION("edit_paste");
//TODO
}
void KexiBrowser::slotRename()
{
if (!m_renameAction || !(m_features & Writable))
return;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
if (it)
m_list->rename(it, 0);
}
void KexiBrowser::itemRenameDone()
{
if (!(m_features & Writable))
return;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
if (!it)
return;
TQString txt = it->text(0).stripWhiteSpace();
bool ok = it->item()->name().lower()!=txt.lower(); //the new name must be different
if (ok) {
/* TODO */
emit renameItem(it->item(), txt, ok);
}
if (!ok) {
txt = it->item()->name(); //revert
}
//"modified" flag has been removed before editing: readd it
if (m_list->nameEndsWithAsterisk) {
txt += "*";
m_list->nameEndsWithAsterisk = false;
}
it->setText(0, txt);
it->parent()->sort();
setFocus();
}
void KexiBrowser::setFocus()
{
if (!m_list->selectedItem() && m_list->firstChild())//select first
m_list->setSelected(m_list->firstChild(), true);
m_list->setFocus();
}
void KexiBrowser::updateItemName( KexiPart::Item& item, bool dirty )
{
if (!(m_features & Writable))
return;
KexiBrowserItem *bitem = m_normalItems[item.identifier()];
if (!bitem)
return;
bitem->setText( 0, item.name() + (dirty ? "*" : "") );
}
void KexiBrowser::slotSettingsChanged(int)
{
m_singleClick = TDEGlobalSettings::singleClick();
}
void KexiBrowser::selectItem(KexiPart::Item& item)
{
KexiBrowserItem *bitem = m_normalItems[item.identifier()];
if (!bitem)
return;
m_list->setSelected(bitem, true);
m_list->ensureItemVisible(bitem);
m_list->setCurrentItem(bitem);
}
void KexiBrowser::clearSelection()
{
m_list->clearSelection();
TQListViewItem *item = m_list->firstChild();
if (item) {
m_list->ensureItemVisible(item);
}
}
void KexiBrowser::slotNewObjectPopupAboutToShow()
{
if ((m_features & Toolbar) && m_newObjectPopup && m_newObjectPopup->count()==0) {
//preload items
KexiPart::PartInfoList *list = Kexi::partManager().partInfoList(); //this list is properly sorted
for (KexiPart::PartInfoListIterator it(*list); it.current(); ++it) {
//add an item to "New object" toolbar popup
TDEAction *action = m_mainWin->actionCollection()->action(
TQString(KexiPart::nameForCreateAction(*it.current())).ascii() );
if (action) {
action->plug(m_newObjectPopup);
}
else {
//! @todo err
}
}
}
}
void KexiBrowser::slotExecuteObject()
{
if (!m_executeAction)
return;
KexiPart::Item* item = selectedPartItem();
if (item)
emit executeItem( item );
}
void KexiBrowser::slotExportAsDataTable()
{
if (!m_dataExportAction)
return;
KexiPart::Item* item = selectedPartItem();
if (item)
emit exportItemAsDataTable( item );
}
KexiPart::Item* KexiBrowser::selectedPartItem() const
{
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(m_list->selectedItem());
return it ? it->item() : 0;
}
bool KexiBrowser::actionEnabled(const TQCString& actionName) const
{
if (actionName=="project_export_data_table" && (m_features & ContextMenus))
return m_itemPopup->isItemVisible(m_exportActionMenu_id);
kdWarning() << "KexiBrowser::actionEnabled() no such action: " << actionName << endl;
return false;
}
void KexiBrowser::slotPrintItem()
{
if (!m_printAction)
return;
KexiPart::Item* item = selectedPartItem();
if (item)
emit printItem( item );
}
void KexiBrowser::slotPageSetupForItem()
{
if (!m_pageSetupAction)
return;
KexiPart::Item* item = selectedPartItem();
if (item)
emit pageSetupForItem( item );
}
void KexiBrowser::setReadOnly(bool set)
{
m_readOnly = set;
if (m_deleteAction)
m_deleteAction->setEnabled(!m_readOnly);
if (m_renameAction)
m_renameAction->setEnabled(!m_readOnly);
if (m_newObjectAction) {
m_newObjectAction->setEnabled(!m_readOnly);
if (m_features & Toolbar) {
m_newObjectPopup->setEnabled(!m_readOnly);
m_newObjectToolButton->setEnabled(!m_readOnly);
}
}
}
bool KexiBrowser::isReadOnly() const
{
return m_readOnly;
}
void KexiBrowser::clear()
{
m_list->clear();
}
//--------------------------------------------
KexiBrowserListView::KexiBrowserListView(TQWidget *parent)
: TDEListView(parent, "KexiBrowserListView")
, nameEndsWithAsterisk(false)
, enableExecuteArea(true)
{
}
KexiBrowserListView::~KexiBrowserListView()
{
}
void KexiBrowserListView::rename(TQListViewItem *item, int c)
{
if (renameLineEdit()->isVisible())
return;
KexiBrowserItem *it = static_cast<KexiBrowserItem*>(item);
if (it->item() && c==0) {
//only edit 1st column for items, not item groups
//TODO: also check it this item is not read-only
// item->setText(0, item->text(0).mid(1,item->text(0).length()-2));
//remove "modified" flag for editing
nameEndsWithAsterisk = item->text(0).endsWith("*");
if (nameEndsWithAsterisk)
item->setText(0, item->text(0).left(item->text(0).length()-1));
TDEListView::rename(item, c);
adjustColumn(0);
}
}
bool KexiBrowserListView::isExecuteArea( const TQPoint& point )
{
return enableExecuteArea && TDEListView::isExecuteArea(point);
}
#include "kexibrowser.moc"
#include "kexibrowser_p.moc"
|