Skip to content

Commit

Permalink
Add ability to move console to a new window
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Nov 1, 2024
1 parent 0f16637 commit 1ed7a79
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 15 deletions.
17 changes: 16 additions & 1 deletion Source/UI/DataViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,22 @@ void DraggableTabComponent::popupMenuClickOnTab (int tabIndex, const String& tab

// don't allow renaming of info or graph tabs
if (nodeId < 100)
return;
{
if (nodeId == 2)
{
PopupMenu m;

m.addItem ("Move to New Window", [this]()
{ AccessClass::getUIComponent()->openConsoleWindow(); });

m.showMenuAsync (PopupMenu::Options().withStandardItemHeight (20));
return;
}
else
{
return;
}
}

auto* tabButton = getTabbedButtonBar().getTabButton (tabIndex);

Expand Down
82 changes: 76 additions & 6 deletions Source/UI/UIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ UIComponent::~UIComponent()
delete pluginInstaller;
}

if (consoleWindow)
{
consoleWindow->removeListener (this);
}

// setLookAndFeel(nullptr);
}

Expand Down Expand Up @@ -417,13 +422,42 @@ void UIComponent::addGraphTab()

void UIComponent::addConsoleTab()
{
if (consoleViewer != nullptr && ! consoleViewerIsOpen)
if (consoleViewer != nullptr && ! consoleOpenInTab)
{
if (consoleOpenInWindow)
{
consoleWindow->closeButtonPressed();
}

dataViewport->addTab ("Console", consoleViewer.get(), 2);
consoleViewerIsOpen = true;
consoleOpenInTab = true;
}
}

void UIComponent::openConsoleWindow()
{
if (consoleWindow == nullptr)
{
consoleWindow = std::make_unique<DataWindow> (nullptr, "Console");
consoleWindow->addListener (this);
consoleWindow->setLookAndFeel (customLookAndFeel);
consoleWindow->setBackgroundColour (findColour (ThemeColours::windowBackground));
consoleWindow->setTitle ("Open Ephys GUI Console");
consoleWindow->setSize (600, 800);
}

if (consoleOpenInTab)
{
dataViewport->removeTab (2);
consoleOpenInTab = false;
}

consoleWindow->setContentNonOwned (consoleViewer.get(), false);
consoleWindow->setVisible (true);
consoleWindow->toFront (true);
consoleOpenInWindow = true;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// MENU BAR METHODS
Expand Down Expand Up @@ -701,7 +735,7 @@ void UIComponent::getCommandInfo (CommandID commandID, ApplicationCommandInfo& r
case toggleConsoleViewer:
result.setInfo ("Console", "Show/hide built-in console.", "General", 0);
result.addDefaultKeypress ('C', ModifierKeys::shiftModifier);
result.setTicked (consoleViewerIsOpen);
result.setTicked (consoleOpenInTab || consoleOpenInWindow);
#ifdef DEBUG
result.setActive (false);
#endif
Expand Down Expand Up @@ -1015,12 +1049,15 @@ bool UIComponent::perform (const InvocationInfo& info)
if (consoleViewer == nullptr)
break;

if (consoleViewerIsOpen)
if (consoleOpenInTab)
dataViewport->removeTab (2);
else if (consoleOpenInWindow)
{
consoleWindow->closeButtonPressed();
}
else
{
dataViewport->addTab ("Console", consoleViewer.get(), 2);
consoleViewerIsOpen = true;
addConsoleTab();
}

break;
Expand Down Expand Up @@ -1117,6 +1154,7 @@ void UIComponent::saveStateToXml (XmlElement* xml)
XmlElement* uiComponentState = xml->createNewChildElement ("UICOMPONENT");
uiComponentState->setAttribute ("isProcessorListOpen", processorList->isOpen());
uiComponentState->setAttribute ("isEditorViewportOpen", showHideEditorViewportButton->getToggleState());
uiComponentState->setAttribute ("consoleOpenState", consoleOpenInTab ? 1 : (consoleOpenInWindow ? 2 : 0));
}

void UIComponent::loadStateFromXml (XmlElement* xml)
Expand All @@ -1132,6 +1170,30 @@ void UIComponent::loadStateFromXml (XmlElement* xml)
}

showHideEditorViewportButton->setToggleState (isEditorViewportOpen, sendNotification);

int consoleOpenState = xmlNode->getIntAttribute ("consoleOpenState", -1);

if (consoleOpenState == 1 || consoleOpenState == -1)
{
addConsoleTab();
}
else if (consoleOpenState == 2)
{
openConsoleWindow();
}
else
{
if (consoleOpenInTab)
{
dataViewport->removeTab (2);
consoleOpenInTab = false;
}

if (consoleOpenInWindow)
{
consoleWindow->closeButtonPressed();
}
}
}
}

Expand All @@ -1145,6 +1207,14 @@ void UIComponent::setRecentlyUsedFilenames (const Array<String>& filenames)
controlPanel->setRecentlyUsedFilenames (filenames);
}

void UIComponent::windowClosed (const String& windowName)
{
if (windowName == "Console")
{
consoleOpenInWindow = false;
}
}

Component* UIComponent::findComponentByIDRecursive (Component* parent, const String& componentID)
{
if (! parent)
Expand Down
25 changes: 17 additions & 8 deletions Source/UI/UIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
#include "../../JuceLibraryCode/JuceHeader.h"

#include "../Processors/MessageCenter/MessageCenterEditor.h"
#include "../Processors/Visualization/DataWindow.h"
#include "CustomArrowButton.h"
#include "DefaultConfig.h"
#include "MessageWindow.h"
#include "LookAndFeel/CustomLookAndFeel.h"
#include "MessageCenterButton.h"
#include "MessageWindow.h"
#include "PluginInstaller.h"

class MainWindow;
Expand All @@ -48,6 +49,7 @@ class EditorViewport;
class SignalChainTabComponent;
class DefaultConfigWindow;
class PopupManager;
class DataWindow;

/**
Expand All @@ -66,9 +68,8 @@ class UIComponent : public Component,
public MenuBarModel,
public ApplicationCommandTarget,
public Button::Listener,
public DragAndDropContainer // required for
// drag-and-drop
// internal components
public DragAndDropContainer,
public DataWindow::Listener

{
public:
Expand Down Expand Up @@ -115,7 +116,7 @@ class UIComponent : public Component,

/** Called by the MessageCenterButton */
void buttonClicked (Button* button);

/** Stops the callbacks to the ProcessorGraph which drive data acquisition. */
void disableCallbacks();

Expand Down Expand Up @@ -175,14 +176,20 @@ class UIComponent : public Component,
// Adds the console viewer to the DataViewport if it is not already open
void addConsoleTab();

// Opens the console viewer in a separate window
void openConsoleWindow();

/** Notifies the UI component when the graph viewer is closed */
void closeGraphViewer() { graphViewerIsOpen = false; }

/** Notifies the UI component when the info tab is closed */
void closeInfoTab() { infoTabIsOpen = false; }

/** Notifies the UI component when the console viewer is closed */
void closeConsoleViewer() { consoleViewerIsOpen = false; }
/** Notifies the UI component when the console viewer tab is closed */
void closeConsoleViewer() { consoleOpenInTab = false; }

/** Notifies the UI component when the console viewer window is closed */
void windowClosed (const String& windowName) override;

/** Finds a child component based on a unique component ID */
Component* findComponentByIDRecursive (Component* parent, const String& id);
Expand All @@ -199,10 +206,12 @@ class UIComponent : public Component,
ScopedPointer<InfoLabel> infoLabel;
ScopedPointer<GraphViewer> graphViewer;
std::unique_ptr<ConsoleViewer> consoleViewer;
std::unique_ptr<DataWindow> consoleWindow;

bool infoTabIsOpen = false;
bool graphViewerIsOpen = false;
bool consoleViewerIsOpen = false;
bool consoleOpenInTab = false;
bool consoleOpenInWindow = false;

EditorViewport* editorViewport;

Expand Down

0 comments on commit 1ed7a79

Please sign in to comment.