Skip to content

Commit

Permalink
Re #4282. More checks on validity of active window pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jan 12, 2012
1 parent c9a8c4f commit 808a62d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
33 changes: 31 additions & 2 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ void ApplicationWindow::plotMenuAboutToShow()

void ApplicationWindow::customMenu(MdiSubWindow* w)
{
if (!existsWindow(w)) return;
myMenuBar()->clear();
myMenuBar()->insertItem(tr("&File"), fileMenu);
fileMenuAboutToShow();
Expand Down Expand Up @@ -8481,18 +8482,46 @@ void ApplicationWindow::setWindowGeometry(int x, int y, int w, int h)
activeWindow()->setGeometry(x, y, w, h);
}

/**
* Checks if a mdi sub-window exists.
*/
bool ApplicationWindow::existsWindow(MdiSubWindow* w) const
{
if (!w) return false;
FloatingWindow* fw = w->getFloatingWindow();
if (fw && m_floatingWindows.contains(fw))
{
return true;
}
QMdiSubWindow* sw = w->getDockedWindow();
return sw && d_workspace->subWindowList().contains(sw);
}

/**
* Returns the active sub-window
*/
MdiSubWindow* ApplicationWindow::getActiveWindow() const
{
//m_active_window_mutex.lock();
MdiSubWindow* w = d_active_window;
if (!existsWindow(d_active_window))
{
d_active_window = NULL;
}
return d_active_window;
//m_active_window_mutex.unlock();
return w;
}

/**
* Sets internal pointer to a new active sub-window.
*/
void ApplicationWindow::setActiveWindow(MdiSubWindow* w)
{
//m_active_window_mutex.lock();
d_active_window = w;
if (!existsWindow(d_active_window))
{
d_active_window = NULL;
}
//m_active_window_mutex.unlock();
}

Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class MantidMatrix;
class FloatingWindow;

// On Mac (and Ubuntu 11 Unity) the menubar must be shared between the main window and other floating windows.
#ifdef Q_OS_MAC
//#ifdef Q_OS_MAC
#define SHARED_MENUBAR
#endif
//#endif

namespace MantidQt
{
Expand Down Expand Up @@ -537,6 +537,7 @@ public slots:
void activateWindow();
void activateWindow(MdiSubWindow *, bool activateOuterWindow = true);
void repaintWindows();
bool existsWindow(MdiSubWindow* w) const;
//@}

//! Show about dialog
Expand Down Expand Up @@ -1321,7 +1322,7 @@ public slots:
QString defaultScriptingLang;

private:
MdiSubWindow *d_active_window;
mutable MdiSubWindow *d_active_window;
MdiSubWindow* getActiveWindow() const;
void setActiveWindow(MdiSubWindow* w);
TextEditor *d_text_editor;
Expand Down

0 comments on commit 808a62d

Please sign in to comment.