| 110 | } |
| 111 | |
| 112 | bool OktetaDocument::close( IDocument::DocumentSaveMode mode ) |
| 113 | { |
| 114 | bool isCanceled = false; |
| 115 | if( !(mode & Discard) ) |
| 116 | { |
| 117 | if (mode & Silent) |
| 118 | { |
| 119 | if (!save(mode)) |
| 120 | isCanceled = true; |
| 121 | |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | if( state() == IDocument::Modified ) |
| 126 | { |
| 127 | // TODO: use Kasten::*Manager |
| 128 | int code = KMessageBox::warningTwoActionsCancel( |
| 129 | qApp->activeWindow(), |
| 130 | i18n("The document \"%1\" has unsaved changes. Would you like to save them?", url().toLocalFile()), |
| 131 | i18nc("@title:window", "Close Document"), KStandardGuiItem::save(), KStandardGuiItem::cancel()); |
| 132 | |
| 133 | if (code == KMessageBox::PrimaryAction) { |
| 134 | if (!save(mode)) |
| 135 | isCanceled = true; |
| 136 | |
| 137 | } else if (code == KMessageBox::Cancel) |
| 138 | isCanceled = true; |
| 139 | |
| 140 | } |
| 141 | else if( state() == IDocument::DirtyAndModified ) |
| 142 | { |
| 143 | if( !save(mode) ) |
| 144 | isCanceled = true; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if( isCanceled ) |
| 150 | return false; |
| 151 | |
| 152 | //close all views and then delete ourself |
| 153 | ///@todo test this |
| 154 | const QList<Sublime::Area*>& allAreas = |
| 155 | ICore::self()->uiController()->controller()->allAreas(); |
| 156 | for (Sublime::Area* area : allAreas ) { |
| 157 | const QList<Sublime::View*> areaViews = area->views(); |
| 158 | for (Sublime::View* view : areaViews) { |
| 159 | if (views().contains(view)) |
| 160 | { |
| 161 | area->removeView(view); |
| 162 | delete view; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // The document is deleted automatically when there are no views left |
| 168 | |
| 169 | return true; |