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.
24 #include <kactioncollection.h>
25 #include <kapplication.h>
28 #include <kedittoolbar.h>
32 #include <kmessagebox.h>
34 #include <kstandardaction.h>
35 #include <kstandardshortcut.h>
36 #include <kxmlguifactory.h>
39 #include "kmenuedit.h"
40 #include "kmenuedit.moc"
42 KMenuEdit::KMenuEdit (bool controlCenter
)
43 : KXmlGuiWindow (0), m_tree(0), m_basicTab(0), m_splitter(0), m_controlCenter(controlCenter
)
46 m_showHidden
= config
->readEntry("ShowHidden", QVariant(false)).toBool();
56 KMenuEdit::~KMenuEdit()
58 KConfigGroup
config(KGlobal::config(), "General");
59 config
.writeEntry("SplitterSizes", m_splitter
->sizes());
64 void KMenuEdit::setupActions()
66 QAction
*action
= actionCollection()->addAction("newsubmenu");
67 action
->setIcon(KIcon("menu_new"));
68 action
->setText(i18n("&New Submenu..."));
69 action
= actionCollection()->addAction("newitem");
70 action
->setIcon(KIcon("document-new")) ;
71 action
->setText(i18n("New &Item..."));
72 action
->setShortcuts(KStandardShortcut::openNew());
75 QAction
*action
= actionCollection()->addAction("newsep");
76 action
->setIcon(KIcon("menu_new_sep"));
77 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
);
89 void KMenuEdit::setupView()
91 m_splitter
= new QSplitter
;
92 m_splitter
->setOrientation(Qt::Horizontal
);
93 m_tree
= new TreeView(m_controlCenter
, actionCollection());
94 m_splitter
->addWidget(m_tree
);
95 m_basicTab
= new BasicTab
;
96 m_splitter
->addWidget(m_basicTab
);
98 connect(m_tree
, SIGNAL(entrySelected(MenuFolderInfo
*)),
99 m_basicTab
, SLOT(setFolderInfo(MenuFolderInfo
*)));
100 connect(m_tree
, SIGNAL(entrySelected(MenuEntryInfo
*)),
101 m_basicTab
, SLOT(setEntryInfo(MenuEntryInfo
*)));
102 connect(m_tree
, SIGNAL(disableAction()),
103 m_basicTab
, SLOT(slotDisableAction() ) );
105 connect(m_basicTab
, SIGNAL(changed(MenuFolderInfo
*)),
106 m_tree
, SLOT(currentChanged(MenuFolderInfo
*)));
108 connect(m_basicTab
, SIGNAL(changed(MenuEntryInfo
*)),
109 m_tree
, SLOT(currentChanged(MenuEntryInfo
*)));
111 connect(m_basicTab
, SIGNAL(findServiceShortcut(const KShortcut
&, KService::Ptr
&)),
112 m_tree
, SLOT(findServiceShortcut(const KShortcut
&, KService::Ptr
&)));
114 // restore splitter sizes
115 KSharedConfig::Ptr config
= KGlobal::config();
116 KConfigGroup
generalGroup(config
, "General");
117 QList
<int> sizes
= generalGroup
.readEntry("SplitterSizes",QList
<int>());
121 m_splitter
->setSizes(sizes
);
124 setCentralWidget(m_splitter
);
127 void KMenuEdit::slotChangeView()
130 m_showHidden
= m_actionShowHidden
->isChecked();
132 m_showHidden
= false;
135 #warning "kde4: comment setUpdatesEnabled otherwise we can't see layout"
137 // disabling the updates prevents unnecessary redraws
138 //setUpdatesEnabled( false );
139 guiFactory()->removeClient( this );
141 delete m_actionDelete
;
143 m_actionDelete
= actionCollection()->addAction("delete");
144 m_actionDelete
->setIcon(KIcon("edit-delete"));
145 m_actionDelete
->setText(i18n("&Delete"));
146 m_actionDelete
->setShortcut(QKeySequence(Qt::Key_Delete
));
151 setupGUI(KXmlGuiWindow::ToolBar
|Keys
|Save
|Create
, "kcontroleditui.rc");
153 setupGUI(KXmlGuiWindow::ToolBar
|Keys
|Save
|Create
, "kmenueditui.rc");
155 m_tree
->setViewMode(m_showHidden
);
158 void KMenuEdit::slotSave()
163 bool KMenuEdit::queryClose()
165 if (!m_tree
->dirty()) return true;
171 result
= KMessageBox::warningYesNoCancel(this,
172 i18n("You have made changes to the Control Center.\n"
173 "Do you want to save the changes or discard them?"),
174 i18n("Save Control Center Changes?"),
175 KStandardGuiItem::save(), KStandardGuiItem::discard() );
179 result
= KMessageBox::warningYesNoCancel(this,
180 i18n("You have made changes to the menu.\n"
181 "Do you want to save the changes or discard them?"),
182 i18n("Save Menu Changes?"),
183 KStandardGuiItem::save(), KStandardGuiItem::discard() );
188 case KMessageBox::Yes
:
189 return m_tree
->save();
191 case KMessageBox::No
:
200 void KMenuEdit::slotConfigureToolbars()
202 KEditToolBar
dlg( factory() );