From ff66ea025cf2a4da14a542cbd2eda3dba770d90f Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 22 Feb 2015 21:18:53 -0300 Subject: [PATCH] Add support to close Home tab with middle mouse button or right-click popup menu --- data/gui.xml | 4 + src/app/app_menus.cpp | 1 + src/app/app_menus.h | 2 + src/app/commands/cmd_close_file.cpp | 130 +++++----------------------- src/app/ui/devconsole_view.cpp | 14 ++- src/app/ui/devconsole_view.h | 3 +- src/app/ui/document_view.cpp | 75 ++++++++++++++-- src/app/ui/document_view.h | 3 +- src/app/ui/home_view.cpp | 14 ++- src/app/ui/home_view.h | 3 +- src/app/ui/main_window.cpp | 44 ++++------ src/app/ui/main_window.h | 9 +- src/app/ui/tabs.cpp | 26 +++--- src/app/ui/tabs.h | 15 ++-- src/app/ui/workspace.cpp | 5 ++ src/app/ui/workspace.h | 4 + src/app/ui/workspace_part.cpp | 5 +- src/app/ui/workspace_view.h | 6 +- src/app/ui_context.cpp | 8 +- 19 files changed, 195 insertions(+), 176 deletions(-) diff --git a/data/gui.xml b/data/gui.xml index 9d5e071ed..42d9475ab 100644 --- a/data/gui.xml +++ b/data/gui.xml @@ -615,6 +615,10 @@ + + + + diff --git a/src/app/app_menus.cpp b/src/app/app_menus.cpp index 3b3af4167..99472e982 100644 --- a/src/app/app_menus.cpp +++ b/src/app/app_menus.cpp @@ -78,6 +78,7 @@ void AppMenus::reload() PRINTF("Main menu loaded.\n"); + m_tabPopupMenu.reset(loadMenuById(handle, "tab_popup")); m_documentTabPopupMenu.reset(loadMenuById(handle, "document_tab_popup")); m_layerPopupMenu.reset(loadMenuById(handle, "layer_popup")); m_framePopupMenu.reset(loadMenuById(handle, "frame_popup")); diff --git a/src/app/app_menus.h b/src/app/app_menus.h index 5b23c6e77..757c001a3 100644 --- a/src/app/app_menus.h +++ b/src/app/app_menus.h @@ -39,6 +39,7 @@ namespace app { Menu* getRootMenu() { return m_rootMenu; } MenuItem* getRecentListMenuitem() { return m_recentListMenuitem; } + Menu* getTabPopupMenu() { return m_tabPopupMenu; } Menu* getDocumentTabPopupMenu() { return m_documentTabPopupMenu; } Menu* getLayerPopupMenu() { return m_layerPopupMenu; } Menu* getFramePopupMenu() { return m_framePopupMenu; } @@ -56,6 +57,7 @@ namespace app { base::UniquePtr m_rootMenu; MenuItem* m_recentListMenuitem; + base::UniquePtr m_tabPopupMenu; base::UniquePtr m_documentTabPopupMenu; base::UniquePtr m_layerPopupMenu; base::UniquePtr m_framePopupMenu; diff --git a/src/app/commands/cmd_close_file.cpp b/src/app/commands/cmd_close_file.cpp index 7047593ca..90ef38a13 100644 --- a/src/app/commands/cmd_close_file.cpp +++ b/src/app/commands/cmd_close_file.cpp @@ -29,53 +29,30 @@ namespace app { using namespace ui; -static bool close_active_document(Context* context); - class CloseFileCommand : public Command { public: CloseFileCommand() : Command("CloseFile", "Close File", - CmdUIOnlyFlag) - { + CmdUIOnlyFlag) { } Command* clone() const override { return new CloseFileCommand(*this); } protected: - bool onEnabled(Context* context) - { - const ContextReader reader(context); - const Sprite* sprite(reader.sprite()); - return sprite != NULL; - } - - void onExecute(Context* context) - { + bool onEnabled(Context* context) override { Workspace* workspace = App::instance()->getMainWindow()->getWorkspace(); - - if (workspace->activeView() == NULL) - return; - - if (DocumentView* docView = - dynamic_cast(workspace->activeView())) { - Document* document = docView->getDocument(); - if (static_cast(context)->countViewsOf(document) == 1) { - // If we have only one view for this document, close the file. - close_active_document(context); - return; - } - } - - // Close the active view. WorkspaceView* view = workspace->activeView(); - workspace->removeView(view); - delete view; + return (view != nullptr); } -private: - static char* read_authors_txt(const char *filename); + void onExecute(Context* context) override { + Workspace* workspace = App::instance()->getMainWindow()->getWorkspace(); + WorkspaceView* view = workspace->activeView(); + if (view) + workspace->closeView(view); + } }; class CloseAllFilesCommand : public Command { @@ -83,96 +60,31 @@ public: CloseAllFilesCommand() : Command("CloseAllFiles", "Close All Files", - CmdRecordableFlag) - { + CmdRecordableFlag) { } Command* clone() const override { return new CloseAllFilesCommand(*this); } protected: - bool onEnabled(Context* context) - { - return !context->documents().empty(); - } + void onExecute(Context* context) override { + Workspace* workspace = App::instance()->getMainWindow()->getWorkspace(); - void onExecute(Context* context) - { - while (true) { - if (context->activeDocument() != NULL) { - if (!close_active_document(context)) - break; - } - else + std::vector docViews; + for (auto view : *workspace) { + DocumentView* docView = dynamic_cast(view); + if (docView) + docViews.push_back(docView); + } + + for (auto docView : docViews) { + if (!workspace->closeView(docView)) break; } } }; -// Closes the active document, asking to the user to save it if it is -// modified. -static bool close_active_document(Context* context) -{ - Document* closedDocument = NULL; - bool save_it; - bool try_again = true; - - while (try_again) { - // This flag indicates if we have to sabe the sprite before to destroy it - save_it = false; - { - // The sprite is locked as reader temporaly - const ContextReader reader(context); - const Document* document = reader.document(); - closedDocument = const_cast(document); - - // see if the sprite has changes - while (document->isModified()) { - // ask what want to do the user with the changes in the sprite - int ret = Alert::show("Warning<name().c_str()); - - if (ret == 1) { - // "save": save the changes - save_it = true; - break; - } - else if (ret != 2) { - // "cancel" or "ESC" */ - return false; // we back doing nothing - } - else { - // "discard" - break; - } - } - } - - // Does we need to save the sprite? - if (save_it) { - Command* save_command = - CommandsModule::instance()->getCommandByName(CommandId::SaveFile); - context->executeCommand(save_command); - - try_again = true; - } - else - try_again = false; - } - - // Destroy the sprite (locking it as writer) - { - DocumentDestroyer document(context, closedDocument); - StatusBar::instance() - ->setStatusText(0, "Sprite '%s' closed.", - document->name().c_str()); - document.destroyDocument(); - } - - return true; -} - Command* CommandFactory::createCloseFileCommand() { return new CloseFileCommand; diff --git a/src/app/ui/devconsole_view.cpp b/src/app/ui/devconsole_view.cpp index 84300073d..1a2aa8c51 100644 --- a/src/app/ui/devconsole_view.cpp +++ b/src/app/ui/devconsole_view.cpp @@ -11,9 +11,11 @@ #include "app/ui/devconsole_view.h" +#include "app/app_menus.h" #include "app/ui/workspace.h" #include "ui/entry.h" #include "ui/message.h" +#include "ui/system.h" #include "ui/textbox.h" #include "ui/view.h" @@ -103,9 +105,19 @@ void DevConsoleView::onClonedFrom(WorkspaceView* from) { } -void DevConsoleView::onCloseView(Workspace* workspace) +bool DevConsoleView::onCloseView(Workspace* workspace) { workspace->removeView(this); + return true; +} + +void DevConsoleView::onTabPopup(Workspace* workspace) +{ + Menu* menu = AppMenus::instance()->getTabPopupMenu(); + if (!menu) + return; + + menu->showPopup(ui::get_mouse_position()); } bool DevConsoleView::onProcessMessage(Message* msg) diff --git a/src/app/ui/devconsole_view.h b/src/app/ui/devconsole_view.h index 7d486c24c..5f84feb6b 100644 --- a/src/app/ui/devconsole_view.h +++ b/src/app/ui/devconsole_view.h @@ -33,7 +33,8 @@ namespace app { WorkspaceView* cloneWorkspaceView() override; void onWorkspaceViewSelected() override; void onClonedFrom(WorkspaceView* from) override; - void onCloseView(Workspace* workspace) override; + bool onCloseView(Workspace* workspace) override; + void onTabPopup(Workspace* workspace) override; protected: bool onProcessMessage(ui::Message* msg) override; diff --git a/src/app/ui/document_view.cpp b/src/app/ui/document_view.cpp index c7e1b8652..c10166726 100644 --- a/src/app/ui/document_view.cpp +++ b/src/app/ui/document_view.cpp @@ -12,7 +12,9 @@ #include "app/ui/document_view.h" #include "app/app.h" +#include "app/app_menus.h" #include "app/commands/commands.h" +#include "app/document_access.h" #include "app/modules/editors.h" #include "app/modules/palettes.h" #include "app/ui/editor/editor.h" @@ -21,6 +23,7 @@ #include "app/ui/keyboard_shortcuts.h" #include "app/ui/main_window.h" #include "app/ui/preview_editor.h" +#include "app/ui/status_bar.h" #include "app/ui/workspace.h" #include "app/ui_context.h" #include "base/path.h" @@ -28,6 +31,8 @@ #include "doc/layer.h" #include "doc/sprite.h" #include "ui/accelerator.h" +#include "ui/alert.h" +#include "ui/menu.h" #include "ui/message.h" #include "ui/system.h" #include "ui/view.h" @@ -224,16 +229,76 @@ void DocumentView::onClonedFrom(WorkspaceView* from) ->setViewScroll(View::getView(srcEditor)->getViewScroll()); } -void DocumentView::onCloseView(Workspace* workspace) +bool DocumentView::onCloseView(Workspace* workspace) { + Context* ctx = UIContext::instance(); + bool save_it; + bool try_again = true; + + while (try_again) { + // This flag indicates if we have to sabe the sprite before to destroy it + save_it = false; + { + // see if the sprite has changes + while (m_document->isModified()) { + // ask what want to do the user with the changes in the sprite + int ret = Alert::show("Warning<name().c_str()); + + if (ret == 1) { + // "save": save the changes + save_it = true; + break; + } + else if (ret != 2) { + // "cancel" or "ESC" */ + return false; // we back doing nothing + } + else { + // "discard" + break; + } + } + } + + // Does we need to save the sprite? + if (save_it) { + Command* save_command = + CommandsModule::instance()->getCommandByName(CommandId::SaveFile); + ctx->executeCommand(save_command); + + try_again = true; + } + else + try_again = false; + } + + // Destroy the sprite (locking it as writer) + DocumentDestroyer destroyer( + static_cast(m_document->context()), m_document); + + StatusBar::instance() + ->setStatusText(0, "Sprite '%s' closed.", + m_document->name().c_str()); + + destroyer.destroyDocument(); + + // At this point the view is already destroyed + + return true; +} + +void DocumentView::onTabPopup(Workspace* workspace) +{ + Menu* menu = AppMenus::instance()->getDocumentTabPopupMenu(); + if (!menu) + return; + UIContext* context = UIContext::instance(); context->setActiveView(this); context->updateFlags(); - Command* close_file_cmd = - CommandsModule::instance()->getCommandByName(CommandId::CloseFile); - - context->executeCommand(close_file_cmd, NULL); + menu->showPopup(ui::get_mouse_position()); } bool DocumentView::onProcessMessage(Message* msg) diff --git a/src/app/ui/document_view.h b/src/app/ui/document_view.h index 17fddc6c0..f0ec892c4 100644 --- a/src/app/ui/document_view.h +++ b/src/app/ui/document_view.h @@ -49,7 +49,8 @@ namespace app { WorkspaceView* cloneWorkspaceView() override; void onWorkspaceViewSelected() override; void onClonedFrom(WorkspaceView* from) override; - void onCloseView(Workspace* workspace) override; + bool onCloseView(Workspace* workspace) override; + void onTabPopup(Workspace* workspace) override; // DocumentObserver implementation void onGeneralUpdate(doc::DocumentEvent& ev) override; diff --git a/src/app/ui/home_view.cpp b/src/app/ui/home_view.cpp index e9190b768..5538fcd0d 100644 --- a/src/app/ui/home_view.cpp +++ b/src/app/ui/home_view.cpp @@ -11,9 +11,11 @@ #include "app/ui/home_view.h" +#include "app/app_menus.h" #include "app/ui/skin/skin_theme.h" #include "app/ui/workspace.h" #include "ui/label.h" +#include "ui/system.h" #include "ui/textbox.h" #include "ui/view.h" @@ -59,9 +61,19 @@ void HomeView::onClonedFrom(WorkspaceView* from) ASSERT(false); // Never called } -void HomeView::onCloseView(Workspace* workspace) +bool HomeView::onCloseView(Workspace* workspace) { workspace->removeView(this); + return true; +} + +void HomeView::onTabPopup(Workspace* workspace) +{ + Menu* menu = AppMenus::instance()->getTabPopupMenu(); + if (!menu) + return; + + menu->showPopup(ui::get_mouse_position()); } void HomeView::onWorkspaceViewSelected() diff --git a/src/app/ui/home_view.h b/src/app/ui/home_view.h index e87edfbbd..b3fab4c01 100644 --- a/src/app/ui/home_view.h +++ b/src/app/ui/home_view.h @@ -33,7 +33,8 @@ namespace app { ui::Widget* getContentWidget() override { return this; } WorkspaceView* cloneWorkspaceView() override; void onClonedFrom(WorkspaceView* from) override; - void onCloseView(Workspace* workspace) override; + bool onCloseView(Workspace* workspace) override; + void onTabPopup(Workspace* workspace) override; void onWorkspaceViewSelected() override; }; diff --git a/src/app/ui/main_window.cpp b/src/app/ui/main_window.cpp index 01d80a99e..d50bfd44c 100644 --- a/src/app/ui/main_window.cpp +++ b/src/app/ui/main_window.cpp @@ -288,45 +288,33 @@ void MainWindow::onActiveViewChange() layout(); } -void MainWindow::clickTab(Tabs* tabs, TabView* tabView, ui::MouseButtons buttons) +void MainWindow::onSelectTab(Tabs* tabs, TabView* tabView) { if (!tabView) return; - WorkspaceView* workspaceView = dynamic_cast(tabView); - if (m_workspace->activeView() != workspaceView) - m_workspace->setActiveView(workspaceView); - - DocumentView* docView = dynamic_cast(workspaceView); - if (!docView) - return; - - UIContext* context = UIContext::instance(); - context->setActiveView(docView); - context->updateFlags(); - - // Right-button: popup-menu - if (buttons & kButtonRight) { - Menu* popup_menu = AppMenus::instance()->getDocumentTabPopupMenu(); - if (popup_menu != NULL) { - popup_menu->showPopup(ui::get_mouse_position()); - } - } - // Middle-button: close the sprite - else if (buttons & kButtonMiddle) { - docView->onCloseView(m_workspace); - } + WorkspaceView* view = dynamic_cast(tabView); + if (m_workspace->activeView() != view) + m_workspace->setActiveView(view); } -void MainWindow::clickClose(Tabs* tabs, TabView* tabView) +void MainWindow::onCloseTab(Tabs* tabs, TabView* tabView) { WorkspaceView* view = dynamic_cast(tabView); ASSERT(view); if (view) - view->onCloseView(m_workspace); + m_workspace->closeView(view); } -void MainWindow::mouseOverTab(Tabs* tabs, TabView* tabView) +void MainWindow::onContextMenuTab(Tabs* tabs, TabView* tabView) +{ + WorkspaceView* view = dynamic_cast(tabView); + ASSERT(view); + if (view) + view->onTabPopup(m_workspace); +} + +void MainWindow::onMouseOverTab(Tabs* tabs, TabView* tabView) { // Note: tabView can be NULL if (DocumentView* docView = dynamic_cast(tabView)) { @@ -339,7 +327,7 @@ void MainWindow::mouseOverTab(Tabs* tabs, TabView* tabView) } } -bool MainWindow::isModified(Tabs* tabs, TabView* tabView) +bool MainWindow::onIsModified(Tabs* tabs, TabView* tabView) { if (DocumentView* docView = dynamic_cast(tabView)) { Document* document = docView->getDocument(); diff --git a/src/app/ui/main_window.h b/src/app/ui/main_window.h index e8a99c545..f053cf1de 100644 --- a/src/app/ui/main_window.h +++ b/src/app/ui/main_window.h @@ -64,10 +64,11 @@ namespace app { void popTimeline(); // TabsDelegate implementation. - void clickTab(Tabs* tabs, TabView* tabView, ui::MouseButtons buttons) override; - void clickClose(Tabs* tabs, TabView* tabView) override; - void mouseOverTab(Tabs* tabs, TabView* tabView) override; - bool isModified(Tabs* tabs, TabView* tabView) override; + void onSelectTab(Tabs* tabs, TabView* tabView) override; + void onCloseTab(Tabs* tabs, TabView* tabView) override; + void onContextMenuTab(Tabs* tabs, TabView* tabView) override; + void onMouseOverTab(Tabs* tabs, TabView* tabView) override; + bool onIsModified(Tabs* tabs, TabView* tabView) override; protected: bool onProcessMessage(ui::Message* msg) override; diff --git a/src/app/ui/tabs.cpp b/src/app/ui/tabs.cpp index 0574b0d55..74ad882d1 100644 --- a/src/app/ui/tabs.cpp +++ b/src/app/ui/tabs.cpp @@ -105,7 +105,11 @@ void Tabs::removeTab(TabView* tabView) m_hot = nullptr; if (m_selected == tab) { - selectNextTab(); + if (tab == m_list.back()) + selectPreviousTab(); + else + selectNextTab(); + if (m_selected == tab) m_selected = nullptr; } @@ -119,7 +123,7 @@ void Tabs::removeTab(TabView* tabView) m_removedTab = tab; if (m_delegate) - tab->modified = m_delegate->isModified(this, tabView); + tab->modified = m_delegate->onIsModified(this, tabView); tab->view = nullptr; // The view will be destroyed after Tabs::removeTab() anyway // Next tab in the list @@ -185,7 +189,7 @@ void Tabs::selectNextTab() if (it != currentTabIt) { selectTabInternal(*it); if (m_delegate) - m_delegate->clickTab(this, m_selected->view, kButtonLeft); + m_delegate->onSelectTab(this, m_selected->view); } } } @@ -205,7 +209,7 @@ void Tabs::selectPreviousTab() if (it != currentTabIt) { selectTabInternal(*it); if (m_delegate) - m_delegate->clickTab(this, m_selected->view, kButtonLeft); + m_delegate->onSelectTab(this, m_selected->view); } } } @@ -255,7 +259,7 @@ bool Tabs::onProcessMessage(Message* msg) if (m_selected && m_delegate && !m_clickedCloseButton && mouseMsg->left()) { - m_delegate->clickTab(this, m_selected->view, mouseMsg->buttons()); + m_delegate->onSelectTab(this, m_selected->view); } captureMouse(); @@ -267,11 +271,11 @@ bool Tabs::onProcessMessage(Message* msg) MouseMessage* mouseMsg = static_cast(msg); if (m_delegate && m_selected && m_selected == m_hot) { - if (m_hotCloseButton && m_clickedCloseButton) { - m_delegate->clickClose(this, m_selected->view); + if (mouseMsg->middle() || (m_hotCloseButton && m_clickedCloseButton)) { + m_delegate->onCloseTab(this, m_selected->view); } - else if (!mouseMsg->left()) { - m_delegate->clickTab(this, m_selected->view, mouseMsg->buttons()); + else if (mouseMsg->right()) { + m_delegate->onContextMenuTab(this, m_selected->view); } } @@ -511,7 +515,7 @@ void Tabs::drawTab(Graphics* g, const gfx::Rect& _box, Tab* tab, int dy, if (m_delegate) { if (tab->view) - tab->modified = m_delegate->isModified(this, tab->view); + tab->modified = m_delegate->onIsModified(this, tab->view); if (tab->modified && (!hover || !m_hotCloseButton)) { @@ -588,7 +592,7 @@ void Tabs::calculateHot() m_hotCloseButton = hotCloseButton; if (m_delegate) - m_delegate->mouseOverTab(this, m_hot ? m_hot->view: NULL); + m_delegate->onMouseOverTab(this, m_hot ? m_hot->view: NULL); invalidate(); } diff --git a/src/app/ui/tabs.h b/src/app/ui/tabs.h index 6d55f97b3..93f1b3dca 100644 --- a/src/app/ui/tabs.h +++ b/src/app/ui/tabs.h @@ -45,17 +45,20 @@ namespace app { public: virtual ~TabsDelegate() { } - // Called when the user presses a mouse button over a tab. - virtual void clickTab(Tabs* tabs, TabView* tabView, ui::MouseButtons buttons) = 0; + // Called when the user selected the tab with the left mouse button. + virtual void onSelectTab(Tabs* tabs, TabView* tabView) = 0; - // When the tab close button is pressed. - virtual void clickClose(Tabs* tabs, TabView* tabView) = 0; + // When the tab close button is pressed (or middle mouse button is used to close it). + virtual void onCloseTab(Tabs* tabs, TabView* tabView) = 0; + + // When the right-click is pressed in the tab. + virtual void onContextMenuTab(Tabs* tabs, TabView* tabView) = 0; // Called when the mouse is over a tab (the data can be null if the // mouse just leave all tabs) - virtual void mouseOverTab(Tabs* tabs, TabView* tabView) = 0; + virtual void onMouseOverTab(Tabs* tabs, TabView* tabView) = 0; - virtual bool isModified(Tabs* tabs, TabView* tabView) = 0; + virtual bool onIsModified(Tabs* tabs, TabView* tabView) = 0; }; // Tabs control. Used to show opened documents. diff --git a/src/app/ui/workspace.cpp b/src/app/ui/workspace.cpp index 1f7baeca9..58157c0b8 100644 --- a/src/app/ui/workspace.cpp +++ b/src/app/ui/workspace.cpp @@ -78,6 +78,11 @@ void Workspace::removeView(WorkspaceView* view) ActiveViewChanged(); // Fire ActiveViewChanged event } +bool Workspace::closeView(WorkspaceView* view) +{ + return view->onCloseView(this); +} + WorkspaceView* Workspace::activeView() { ASSERT(m_activePart != NULL); diff --git a/src/app/ui/workspace.h b/src/app/ui/workspace.h index 4bf807c9e..2053349da 100644 --- a/src/app/ui/workspace.h +++ b/src/app/ui/workspace.h @@ -30,6 +30,10 @@ namespace app { void addView(WorkspaceView* view); void removeView(WorkspaceView* view); + // Closes the given view. Returns false if the user cancels the + // operation. + bool closeView(WorkspaceView* view); + WorkspaceView* activeView(); void setActiveView(WorkspaceView* view); diff --git a/src/app/ui/workspace_part.cpp b/src/app/ui/workspace_part.cpp index 1d137c82b..e49e8054b 100644 --- a/src/app/ui/workspace_part.cpp +++ b/src/app/ui/workspace_part.cpp @@ -52,8 +52,9 @@ void WorkspacePart::removeView(WorkspaceView* view) removeChild(view->getContentWidget()); - setActiveView((it != m_views.end() ? - *it : (!m_views.empty() ? m_views.front(): NULL))); + setActiveView( + (it != m_views.end() ? + *it : (!m_views.empty() ? m_views.back(): nullptr))); } void WorkspacePart::setActiveView(WorkspaceView* view) diff --git a/src/app/ui/workspace_view.h b/src/app/ui/workspace_view.h index d6b4af1d8..ebfe23cb7 100644 --- a/src/app/ui/workspace_view.h +++ b/src/app/ui/workspace_view.h @@ -29,7 +29,11 @@ namespace app { // from the original view. virtual void onClonedFrom(WorkspaceView* from) = 0; - virtual void onCloseView(Workspace* workspace) = 0; + // Returns true if the view was closed successfully or false if + // the user cancels the operation. + virtual bool onCloseView(Workspace* workspace) = 0; + + virtual void onTabPopup(Workspace* workspace) = 0; }; } // namespace app diff --git a/src/app/ui_context.cpp b/src/app/ui_context.cpp index c1bff0f47..f46d1109c 100644 --- a/src/app/ui_context.cpp +++ b/src/app/ui_context.cpp @@ -127,7 +127,7 @@ DocumentView* UIContext::getFirstDocumentView(Document* document) const { Workspace* workspace = App::instance()->getMainWindow()->getWorkspace(); - for (auto view : *workspace) { + for (WorkspaceView* view : *workspace) { if (DocumentView* docView = dynamic_cast(view)) { if (docView->getDocument() == document) { return docView; @@ -177,8 +177,7 @@ void UIContext::onRemoveDocument(doc::Document* doc) DocumentViews docViews; // Collect all views related to the document. - for (Workspace::iterator it=workspace->begin(); it != workspace->end(); ++it) { - WorkspaceView* view = *it; + for (WorkspaceView* view : *workspace) { if (DocumentView* docView = dynamic_cast(view)) { if (docView->getDocument() == doc) { docViews.push_back(docView); @@ -186,8 +185,7 @@ void UIContext::onRemoveDocument(doc::Document* doc) } } - for (DocumentViews::iterator it=docViews.begin(); it != docViews.end(); ++it) { - DocumentView* docView = *it; + for (DocumentView* docView : docViews) { workspace->removeView(docView); delete docView; }