Skip to content

Commit 86ea08b

Browse files
committed
Change exit dialog to ask for confirmation to apply previewed background.
1 parent 2c9e273 commit 86ea08b

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

src/NWindow.cc

+34-16
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,34 @@ void NWindow::sighandle_dblclick_item (const Gtk::TreeModel::Path& path) {
146146
}
147147

148148
/**
149-
* Handles the user pressing the apply button. Grabs the selected items and
149+
* Handles the user pressing the apply button.
150+
*/
151+
void NWindow::sighandle_click_apply (void) {
152+
this->apply_bg();
153+
}
154+
155+
/**
156+
* Performs the apply action
157+
* Grabs the selected items and
150158
* calls set_bg on it. It also saves the bg and closes the application if
151159
* the app is not multiheaded, or the full xin desktop is selected.
152160
*/
153-
void NWindow::sighandle_click_apply (void) {
154-
155-
// find out which image is currently selected
156-
Gtk::TreeModel::iterator iter = view.get_selected ();
157-
Gtk::TreeModel::Row row = *iter;
161+
void NWindow::apply_bg () {
162+
163+
// find out which image is currently selected
164+
Gtk::TreeModel::iterator iter = view.get_selected ();
165+
Gtk::TreeModel::Row row = *iter;
158166
Glib::ustring file = row[view.record.Filename];
159-
this->set_bg(file);
167+
this->set_bg(file);
160168

161169
// apply - remove dirty flag
162170
m_dirty = false;
163171

164172
SetBG::SetMode mode = SetBG::string_to_mode( this->select_mode.get_active_data() );
165-
Glib::ustring thedisp = this->select_display.get_active_data();
166-
Gdk::Color bgcolor = this->button_bgcolor.get_color();
173+
Glib::ustring thedisp = this->select_display.get_active_data();
174+
Gdk::Color bgcolor = this->button_bgcolor.get_color();
167175

168-
// save
176+
// save
169177
Config::get_instance()->set_bg(thedisp, file, mode, bgcolor);
170178

171179
// tell the row that he's now on thedisp
@@ -178,7 +186,7 @@ void NWindow::sighandle_click_apply (void) {
178186
// old background on thedisp, but could be 2 items if xinerama individual bgs
179187
// are replaced by the fullscreen xinerama.
180188
for (Gtk::TreeIter i = view.store->children().begin(); i != view.store->children().end(); i++)
181-
{
189+
{
182190
Glib::ustring curbgondisp = (*i)[view.record.CurBGOnDisp];
183191
if (curbgondisp == "")
184192
continue;
@@ -199,24 +207,34 @@ void NWindow::sighandle_click_apply (void) {
199207
else
200208
(*i)[view.record.Description] = Util::make_current_set_string(this, filename, (*mapiter).first);
201209
}
202-
203210
}
204211

205212
bool NWindow::on_delete_event(GdkEventAny *event)
206213
{
207214
if (m_dirty)
208215
{
209-
Gtk::MessageDialog dialog(*this, _("You previewed an image without applying it, exit anyway?"), false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, true);
216+
int result;
217+
Gtk::MessageDialog dialog(*this,
218+
_("You previewed an image without applying it, apply?"), false,
219+
Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true);
220+
221+
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
222+
dialog.add_button(Gtk::Stock::NO, Gtk::RESPONSE_NO);
223+
dialog.add_button(Gtk::Stock::YES, Gtk::RESPONSE_YES);
224+
225+
dialog.set_default_response(Gtk::RESPONSE_YES);
226+
result = dialog.run();
210227

211-
int result = dialog.run();
212228
switch (result)
213229
{
214230
case Gtk::RESPONSE_YES:
215-
231+
this->apply_bg();
216232
break;
217233
case Gtk::RESPONSE_NO:
218-
return true;
219234
break;
235+
case Gtk::RESPONSE_CANCEL:
236+
case Gtk::RESPONSE_DELETE_EVENT:
237+
return true;
220238
};
221239
}
222240

src/NWindow.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class NWindow : public Gtk::Window {
6868
void sighandle_togb_list_toggled();
6969
void sighandle_togb_icon_toggled();
7070
void sighandle_btn_prefs();
71+
void apply_bg();
7172

7273
virtual bool on_delete_event(GdkEventAny *event);
7374

0 commit comments

Comments
 (0)