Skip to content

Commit

Permalink
Fix Freeseer#501 Warn user about losing new talk info
Browse files Browse the repository at this point in the history
When the user switches from one talk to another or creates a new talk
when the currently selected talk has unsaved changes, a window comes up
asking the user if they wish to save their changes, with the options
"Yes", "No", and "Cancel". "Yes" saves the changes and selects the new
talk; "No" selects the new talk without saving the changes; and
"Cancel" keeps the current talk selected without discarding or saving
any changes made.

Fix Freeseer#501
Close Freeseer#605
  • Loading branch information
benbuckley committed Oct 7, 2014
1 parent 19f959d commit 4765e79
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions src/freeseer/frontend/talkeditor/talkeditor.py
Expand Up @@ -26,6 +26,7 @@

# PyQt modules
from PyQt4.QtCore import SIGNAL
from PyQt4.QtCore import QPersistentModelIndex
from PyQt4.QtCore import QStringList
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QAbstractItemView
Expand Down Expand Up @@ -93,6 +94,9 @@ def __init__(self, config, db):
self.mainLayout.addWidget(self.importTalksWidget)
# --- End Layout

# Keep track of index of the most recently selected talk
self.currentTalkIndex = QPersistentModelIndex()

# Initialize geometry, to be used for restoring window positioning.
self.geometry = None

Expand All @@ -112,9 +116,9 @@ def __init__(self, config, db):
#
# TableView Connections
#
self.connect(self.tableView, SIGNAL('activated(const QModelIndex)'), self.talk_selected)
self.connect(self.tableView, SIGNAL('selected(const QModelIndex)'), self.talk_selected)
self.connect(self.tableView, SIGNAL('clicked(const QModelIndex)'), self.talk_selected)
self.connect(self.tableView, SIGNAL('activated(const QModelIndex)'), self.click_talk)
self.connect(self.tableView, SIGNAL('selected(const QModelIndex)'), self.click_talk)
self.connect(self.tableView, SIGNAL('clicked(const QModelIndex)'), self.click_talk)

# Import Widget
self.connect(self.importTalksWidget.csvRadioButton, SIGNAL('toggled(bool)'), self.toggle_import)
Expand All @@ -130,7 +134,7 @@ def __init__(self, config, db):
self.connect(self.actionRemoveAll, SIGNAL('triggered()'), self.confirm_reset)

# Command Buttons
self.connect(self.commandButtons.addButton, SIGNAL('clicked()'), self.show_new_talk_popup)
self.connect(self.commandButtons.addButton, SIGNAL('clicked()'), self.click_add_button)
self.connect(self.commandButtons.removeButton, SIGNAL('clicked()'), self.remove_talk)
self.connect(self.commandButtons.removeAllButton, SIGNAL('clicked()'), self.confirm_reset)
self.connect(self.commandButtons.importButton, SIGNAL('clicked()'), self.show_import_talks_widget)
Expand Down Expand Up @@ -283,10 +287,54 @@ def search_talks(self):
self.proxy.setFilterKeyColumn(-1)
self.proxy.setFilterFixedString(self.commandButtons.searchLineEdit.text())

def show_save_prompt(self):
confirm = QMessageBox.question(self,
"Unsaved Changes Exist",
"Save changes to current talk?",
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
QMessageBox.Yes)
return confirm

def click_talk(self, model):
log.info("User selected row %d", model.row())
modelRow = model.row()
if self.unsaved_details_exist():
confirm = self.show_save_prompt()
if confirm == QMessageBox.Yes:
log.info("User chose to SAVE")
self.tableView.selectRow(self.currentTalkIndex.row())
self.update_talk()
newModel = self.tableView.currentIndex().sibling(modelRow, 0)
self.select_talk(newModel)
elif confirm == QMessageBox.No:
log.info("User chose to DISCARD")
self.talk_selected(model)
else:
log.info("User chose to CANCEL")
self.tableView.selectRow(self.currentTalkIndex.row())
else:
self.talk_selected(model)

def click_add_button(self):
if self.unsaved_details_exist():
confirm = self.show_save_prompt()
if confirm == QMessageBox.Yes:
log.info("User chose to SAVE")
self.update_talk()
self.show_new_talk_popup()
elif confirm == QMessageBox.No:
log.info("User chose to DISCARD")
self.show_new_talk_popup()
else:
log.info("User chose to CANCEL")
else:
self.show_new_talk_popup()

def talk_selected(self, model):
self.mapper.setCurrentIndex(model.row())
self.talkDetailsWidget.enable_input_fields()
self.talkDetailsWidget.saveButton.setEnabled(False)
self.currentTalkIndex = QPersistentModelIndex(model)

def toggle_import(self):
if self.importTalksWidget.csvRadioButton.isChecked():
Expand Down

0 comments on commit 4765e79

Please sign in to comment.