CloseAllAction.cpp 2.46 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * $CAMITK_LICENCE_BEGIN$
 *
 * CamiTK - Computer Assisted Medical Intervention ToolKit
promayon's avatar
promayon committed
5
 * (c) 2001-2013 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6
 *
7
8
 * Visit http://camitk.imag.fr for more information
 *
9
10
11
12
13
 * This file is part of CamiTK.
 *
 * CamiTK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
14
 *
15
 * CamiTK is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details.
19
 *
20
21
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with CamiTK.  If not, see <http://www.gnu.org/licenses/>.
22
23
 *
 * $CAMITK_LICENCE_END$
24
 ****************************************************************************/
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "CloseAllAction.h"

#include <Application.h>

using namespace camitk;

// --------------- constructor -------------------
CloseAllAction::CloseAllAction(ActionExtension * extension) : Action(extension) {
  // Setting name, description and input component
  setName("Close All");
  setEmbedded(false);
  setDescription("Close all components, prompting for additional information if needed");
  setComponent("");
  setIcon(QPixmap(":/fileClose"));

  // Setting classification family and tags
  setFamily("Application");
  addTag("Close");

}

// --------------- destructor -------------------
CloseAllAction::~CloseAllAction() {
  // do not delete the widget has it might have been used in the ActionViewer (i.e. the ownership might have been taken by the stacked widget)
}

// --------------- getWidget --------------
QWidget * CloseAllAction::getWidget() {
  return NULL;
}

// --------------- apply -------------------
Action::ApplyStatus CloseAllAction::apply() {
  
    Application::showStatusBarMessage( tr ( "Closing all the documents..." ) );

    // clear the selection
    Application::clearSelectedComponents();

    // close 'em all
    bool continueClosing = true;
    while (continueClosing && Application::getTopLevelComponents().size() > 0) {
        Component * comp = Application::getTopLevelComponents().first();
        continueClosing = Application::close(comp);
    }

    if (continueClosing)
      return SUCCESS;
    else
      return ABORTED;
}