2 * Copyright (C) 2000 Matthias Elter <elter@kde.org>
3 * Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "kmenuedit.h"
25 #include <kactioncollection.h>
26 #include <kapplication.h>
29 #include <kedittoolbar.h>
33 #include <kmessagebox.h>
35 #include <kstandardaction.h>
36 #include <kstandardshortcut.h>
37 #include <kxmlguifactory.h>
38 #include <sonnet/configdialog.h>
41 #include "preferencesdlg.h"
42 #include "kmenueditadaptor.h"
44 #include "kmenuedit.moc"
46 KMenuEdit::KMenuEdit ()
47 : KXmlGuiWindow (0), m_tree(0), m_basicTab(0), m_splitter(0)
49 ( void )new KmenueditAdaptor(this);
50 QDBusConnection::sessionBus().registerObject("/KMenuEdit", this);
51 KConfigGroup
grp( KGlobal::config(), "General" );
52 m_showHidden
= grp
.readEntry("ShowHidden", false);
59 KMenuEdit::~KMenuEdit()
61 KConfigGroup
config(KGlobal::config(), "General");
62 config
.writeEntry("SplitterSizes", m_splitter
->sizes());
67 void KMenuEdit::setupActions()
69 KAction
*action
= actionCollection()->addAction("newsubmenu");
70 action
->setIcon(KIcon("menu_new"));
71 action
->setText(i18n("&New Submenu..."));
72 action
= actionCollection()->addAction("newitem");
73 action
->setIcon(KIcon("document-new")) ;
74 action
->setText(i18n("New &Item..."));
75 action
->setShortcuts(KStandardShortcut::openNew());
76 action
= actionCollection()->addAction("newsep");
77 action
->setIcon(KIcon("menu_new_sep"));
78 action
->setText(i18n("New S&eparator"));
82 actionCollection()->addAction(KStandardAction::Save
, this, SLOT( slotSave() ));
83 actionCollection()->addAction(KStandardAction::Quit
, this, SLOT( close() ));
84 actionCollection()->addAction(KStandardAction::Cut
);
85 actionCollection()->addAction(KStandardAction::Copy
);
86 actionCollection()->addAction(KStandardAction::Paste
);
88 action
= new KAction( i18n("Restore to System Menu"), this );
89 actionCollection()->addAction( "restore_system_menu", action
);
90 connect( action
, SIGNAL(triggered(bool) ), SLOT(slotRestoreMenu()) );
91 KStandardAction::preferences( this, SLOT( slotConfigure() ), actionCollection() );
94 void KMenuEdit::slotConfigure()
96 PreferencesDialog
dlg( this );
99 KConfigGroup
grp( KGlobal::config(), "General" );
100 bool newShowHiddenValue
= grp
.readEntry("ShowHidden", false);
101 if ( newShowHiddenValue
!= m_showHidden
)
103 m_showHidden
= newShowHiddenValue
;
104 m_tree
->updateTreeView(m_showHidden
);
105 m_basicTab
->updateHiddenEntry( m_showHidden
);
110 void KMenuEdit::setupView()
112 m_splitter
= new QSplitter
;
113 m_splitter
->setOrientation(Qt::Horizontal
);
114 m_tree
= new TreeView(actionCollection());
115 m_splitter
->addWidget(m_tree
);
116 m_basicTab
= new BasicTab
;
117 m_splitter
->addWidget(m_basicTab
);
119 connect(m_tree
, SIGNAL(entrySelected(MenuFolderInfo
*)),
120 m_basicTab
, SLOT(setFolderInfo(MenuFolderInfo
*)));
121 connect(m_tree
, SIGNAL(entrySelected(MenuEntryInfo
*)),
122 m_basicTab
, SLOT(setEntryInfo(MenuEntryInfo
*)));
123 connect(m_tree
, SIGNAL(disableAction()),
124 m_basicTab
, SLOT(slotDisableAction() ) );
126 connect(m_basicTab
, SIGNAL(changed(MenuFolderInfo
*)),
127 m_tree
, SLOT(currentChanged(MenuFolderInfo
*)));
129 connect(m_basicTab
, SIGNAL(changed(MenuEntryInfo
*)),
130 m_tree
, SLOT(currentChanged(MenuEntryInfo
*)));
132 connect(m_basicTab
, SIGNAL(findServiceShortcut(const KShortcut
&, KService::Ptr
&)),
133 m_tree
, SLOT(findServiceShortcut(const KShortcut
&, KService::Ptr
&)));
135 // restore splitter sizes
136 KSharedConfig::Ptr config
= KGlobal::config();
137 KConfigGroup
generalGroup(config
, "General");
138 QList
<int> sizes
= generalGroup
.readEntry("SplitterSizes",QList
<int>());
142 m_splitter
->setSizes(sizes
);
145 setCentralWidget(m_splitter
);
148 void KMenuEdit::slotChangeView()
152 #warning "kde4: comment setUpdatesEnabled otherwise we can't see layout"
154 // disabling the updates prevents unnecessary redraws
155 //setUpdatesEnabled( false );
156 guiFactory()->removeClient( this );
158 delete m_actionDelete
;
160 m_actionDelete
= actionCollection()->addAction("delete");
161 m_actionDelete
->setIcon(KIcon("edit-delete"));
162 m_actionDelete
->setText(i18n("&Delete"));
163 m_actionDelete
->setShortcut(QKeySequence(Qt::Key_Delete
));
167 setupGUI(KXmlGuiWindow::ToolBar
|Keys
|Save
|Create
, "kmenueditui.rc");
169 m_tree
->setViewMode(m_showHidden
);
170 m_basicTab
->updateHiddenEntry( m_showHidden
);
173 void KMenuEdit::slotSave()
179 bool KMenuEdit::queryClose()
181 if (!m_tree
->dirty()) return true;
185 result
= KMessageBox::warningYesNoCancel(this,
186 i18n("You have made changes to the menu.\n"
187 "Do you want to save the changes or discard them?"),
188 i18n("Save Menu Changes?"),
189 KStandardGuiItem::save(), KStandardGuiItem::discard() );
193 case KMessageBox::Yes
:
194 return m_tree
->save();
196 case KMessageBox::No
:
205 void KMenuEdit::slotConfigureToolbars()
207 KEditToolBar
dlg( factory() );
211 void KMenuEdit::slotRestoreMenu()
213 m_tree
->restoreMenuSystem();
216 void KMenuEdit::restoreSystemMenu()
218 m_tree
->restoreMenuSystem();