Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change exit dialog to ask for confirmation to apply previewed background... #33

Merged
merged 2 commits into from
Oct 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions src/NWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,34 @@ void NWindow::sighandle_dblclick_item (const Gtk::TreeModel::Path& path) {
}

/**
* Handles the user pressing the apply button. Grabs the selected items and
* Handles the user pressing the apply button.
*/
void NWindow::sighandle_click_apply (void) {
this->apply_bg();
}

/**
* Performs the apply action
* Grabs the selected items and
* calls set_bg on it. It also saves the bg and closes the application if
* the app is not multiheaded, or the full xin desktop is selected.
*/
void NWindow::sighandle_click_apply (void) {
// find out which image is currently selected
Gtk::TreeModel::iterator iter = view.get_selected ();
Gtk::TreeModel::Row row = *iter;
void NWindow::apply_bg () {

// find out which image is currently selected
Gtk::TreeModel::iterator iter = view.get_selected ();
Gtk::TreeModel::Row row = *iter;
Glib::ustring file = row[view.record.Filename];
this->set_bg(file);
this->set_bg(file);

// apply - remove dirty flag
m_dirty = false;

SetBG::SetMode mode = SetBG::string_to_mode( this->select_mode.get_active_data() );
Glib::ustring thedisp = this->select_display.get_active_data();
Gdk::Color bgcolor = this->button_bgcolor.get_color();
Glib::ustring thedisp = this->select_display.get_active_data();
Gdk::Color bgcolor = this->button_bgcolor.get_color();

// save
// save
Config::get_instance()->set_bg(thedisp, file, mode, bgcolor);

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

}

bool NWindow::on_delete_event(GdkEventAny *event)
{
if (m_dirty)
{
Gtk::MessageDialog dialog(*this, _("You previewed an image without applying it, exit anyway?"), false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, true);
int result;
Gtk::MessageDialog dialog(*this,
_("You previewed an image without applying it, apply?"), false,
Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true);

dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dialog.add_button(Gtk::Stock::NO, Gtk::RESPONSE_NO);
dialog.add_button(Gtk::Stock::YES, Gtk::RESPONSE_YES);

dialog.set_default_response(Gtk::RESPONSE_YES);
result = dialog.run();

int result = dialog.run();
switch (result)
{
case Gtk::RESPONSE_YES:

this->apply_bg();
break;
case Gtk::RESPONSE_NO:
return true;
Util::program_log("restoring backgrounds from config file");
Util::restore_saved_bgs();
break;
case Gtk::RESPONSE_CANCEL:
case Gtk::RESPONSE_DELETE_EVENT:
return true;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/NWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class NWindow : public Gtk::Window {
void sighandle_togb_list_toggled();
void sighandle_togb_icon_toggled();
void sighandle_btn_prefs();
void apply_bg();

virtual bool on_delete_event(GdkEventAny *event);

Expand Down