Fixed #6342: Asking if user want to save change when in dict list widget
authorBartosz Szatkowski <bulislaw@linux.com>
Wed, 1 Sep 2010 13:12:47 +0000 (15:12 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Wed, 1 Sep 2010 13:12:47 +0000 (15:12 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/gui/DictManagerWidget.cpp

index 9662984..b2c5fb4 100644 (file)
@@ -214,9 +214,9 @@ void Backbone::search(QString word){
     bookmarkFin = !_searchBookmarks;
 
     if(!_searchDicts && !_searchBookmarks) {
+        Q_EMIT ready();
         Q_EMIT notify(Notify::Warning, tr("You have to specify where You want "
                 "to look for translations"));
-        Q_EMIT ready();
     }
 
     if (_searchDicts) {
index c718908..5ff23fe 100644 (file)
@@ -127,7 +127,7 @@ void DictManagerWidget::refreshDictsList() {
 void DictManagerWidget::showEvent(QShowEvent *e) {
     _changed = false;
     #ifndef Q_WS_MAEMO_5
-        _save = false;
+      _save = false;
     #endif
     refreshDictsList();
     QWidget::showEvent(e);
@@ -150,32 +150,39 @@ void DictManagerWidget::saveChanges() {
                 checkedDicts.push_back(dictsHash[item]);
             }
         }
+        _changed = false;
         emit selectedDictionaries(checkedDicts);
     }
-    _changed = false;
 }
 
 void DictManagerWidget::hideEvent(QHideEvent *e)
 {
-    qDebug()<<"hide";
     saveChanges();
     QWidget::hideEvent(e);
 }
 
 
 void DictManagerWidget::addNewDictButtonClicked() {
-    CommonDictInterface* selectedPlugin =
-            DictTypeSelectDialog::addNewDict(guiInterface->getPlugins(),this);
-    if(selectedPlugin != NULL) {
-        Settings* settings =
-                selectedPlugin->dictDialog()->addNewDictionary(this);
-
-        if(settings != NULL) {
-            CommonDictInterface* newDict = selectedPlugin->getNew(settings);
-            Q_EMIT addDictionary(newDict);
-            refreshDictsList();
-        }
+    if(!_changed || QMessageBox::question(this,
+            "Save", "Do you want to save changes?",
+            QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+        _save = true;
+        saveChanges();
+        _save = false;
     }
+
+   CommonDictInterface* selectedPlugin =
+           DictTypeSelectDialog::addNewDict(guiInterface->getPlugins(),this);
+   if(selectedPlugin != NULL) {
+       Settings* settings =
+               selectedPlugin->dictDialog()->addNewDictionary(this);
+
+       if(settings != NULL) {
+           CommonDictInterface* newDict = selectedPlugin->getNew(settings);
+           Q_EMIT addDictionary(newDict);
+       }
+   }
+   refreshDictsList();
 }
 
 void DictManagerWidget::itemSelected(QListWidgetItem *) {
@@ -189,18 +196,25 @@ void DictManagerWidget::removeButtonClicked() {
             QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) {
         QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
         if(selected.count() > 0) {
-            emit removeDictionary(dictsHash[selected[0]]);
             refreshDictsList();
+            emit removeDictionary(dictsHash[selected[0]]);
         }
    }
 }
 
 void DictManagerWidget::settingsButtonClicked() {
-    QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
-    if(selected.count() > 0) {
-        dictsHash[selected[0]]->dictDialog()->changeSettings(this);
-        refreshDictsList();
+    if(!_changed || QMessageBox::question(this,
+            "Save", "Do you want to save changes?",
+            QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+        _save = true;
+        saveChanges();
+        _save = false;
     }
+   QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
+   if(selected.count() > 0) {
+       dictsHash[selected[0]]->dictDialog()->changeSettings(this);
+   }
+   refreshDictsList();
 }