Skip to content

Commit

Permalink
- refactored: ApplicationCommandManager has moved from LDocumentWindo…
Browse files Browse the repository at this point in the history
…w to

LJUCEApplication, in order to be able to handle multiple DocumentWindows

- LPopupMenu is impacted by this refactoring in addCommandItem

- for the same reason, added a new method to LDocumentWindow:
  closeWindow, maybe temporarilly if something equivalent were to be
  found in JUCE

- attached to closeWindow is LJUCEApplication::deleteWindow,
  LJUCEApplication now storing references of LDocumentWindow
  in an Array of ScopedPointers

- in LJUCEApplication, refactored initialise as general method
  to be used by all possible initialisation callbacks, depending
  on OS

- in LJUCEApplication, added a Luce specific (static) method getInstance
  • Loading branch information
Christophe Berbizier (dbdl) committed Mar 14, 2014
1 parent d47be3f commit fa5bfeb
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 181 deletions.
123 changes: 8 additions & 115 deletions Source/LDocumentWindow.cpp
Expand Up @@ -29,6 +29,7 @@ const Luna<LDocumentWindow>::PropertyType LDocumentWindow::properties[] = {

const Luna<LDocumentWindow>::FunctionType LDocumentWindow::methods[] = {
method( LDocumentWindow, closeButtonPressed ),
method( LDocumentWindow, closeWindow ),
method( LDocumentWindow, setVisible ),
method( LDocumentWindow, addChildComponent ),
method( LDocumentWindow, addAndMakeVisible ),
Expand Down Expand Up @@ -67,31 +68,27 @@ const Luna<LDocumentWindow>::StaticType LDocumentWindow::statics[] = {
{0,0}
};

static ScopedPointer<ApplicationCommandManager> commandManager;
//static ScopedPointer<ApplicationCommandManager> commandManager;
LDocumentWindow::LDocumentWindow(lua_State *L)
: LComponent(L, this),
DocumentWindow( "DocumentWindow", Colours::lightgrey, DocumentWindow::allButtons )
{
REGISTER_CLASS(LDocumentWindow);

DocumentWindow::setName( myName() );
commandManager = new ApplicationCommandManager();

DocumentWindow::addKeyListener (commandManager->getKeyMappings());
triggerAsyncUpdate();

DocumentWindow::setResizable( true, false );
}

LDocumentWindow::~LDocumentWindow() {
if(commandManager)
commandManager = nullptr;
}

ApplicationCommandManager& LDocumentWindow::getApplicationCommandManager() {
if (!commandManager)
commandManager = new ApplicationCommandManager();
return *commandManager;
int LDocumentWindow::closeWindow(lua_State*) {
if(DocumentWindow::isOnDesktop())
DocumentWindow::removeFromDesktop();

LJUCEApplication::getInstance()->deleteWindow(this);
return 0;
}

int LDocumentWindow::s_Displays(lua_State *L) {
Expand Down Expand Up @@ -122,10 +119,6 @@ int LDocumentWindow::s_Displays(lua_State *L) {
return 1;
}

void LDocumentWindow::handleAsyncUpdate() {
commandManager->registerAllCommandsForTarget (JUCEApplication::getInstance());
}

int LDocumentWindow::setContentOwned(lua_State*) {
DocumentWindow::setContentOwned( LUA::from_luce<LComponent,Component>(2), LUA::checkAndGetBoolean(2, true) );
return 0;
Expand Down Expand Up @@ -186,7 +179,6 @@ bool LDocumentWindow::keyStateChanged(bool d) {
return DocumentWindow::keyStateChanged(d);
}


//==============================================================================
/////// getters/setters
int LDocumentWindow::getConstrainer ( lua_State *L ) {
Expand Down Expand Up @@ -334,102 +326,3 @@ int LDocumentWindow::setContentComponentSize ( lua_State* ) {
DocumentWindow::setContentComponentSize( width, height );
return 0;
}


//==============================================================================

int LDocumentWindow::clearCommands(lua_State*) {
commandManager->clearCommands();
return 0;
}

int LDocumentWindow::registerCommand(lua_State*) {
//TODO
return 0;
}

int LDocumentWindow::registerAllCommandsForTarget(lua_State*) {
//TODO
return 0;
}

int LDocumentWindow::removeCommand(lua_State*) {
//TODO commandid
return 0;
}

int LDocumentWindow::commandStatusChanged(lua_State*) {
commandManager->commandStatusChanged();
return 0;
}

int LDocumentWindow::getNumCommands(lua_State*) {
return LUA::getNumber( commandManager->getNumCommands() );
return 0;
}

int LDocumentWindow::getCommandForIndex(lua_State*) {
// TODO
//return LUA::returnUserdata<LApplicationCommandInfo>( commandManager->getCommandForIndex() );
return 0;
}

int LDocumentWindow::getCommandForID(lua_State*) {
// TODO
//return LUA::returnUserdata<LApplicationCommandInfo>(
// commandManager->getCommandForIndex(LUA::getNumber<int>(2)) );
return 0;
}

int LDocumentWindow::getNameOfCommand(lua_State*) {
return LUA::returnString( commandManager->getNameOfCommand( (CommandID)LUA::getNumber<int>(2) ) );
}

int LDocumentWindow::getDescriptionOfCommand(lua_State*) {
return LUA::returnString( commandManager->getDescriptionOfCommand( (CommandID)LUA::getNumber<int>(2) ) );
}

int LDocumentWindow::getCommandCategories(lua_State*) {
return LUCE::luce_pushtable( commandManager->getCommandCategories() );
}

int LDocumentWindow::getCommandsInCategory(lua_State*) {
return LUCE::luce_pushtable( commandManager->getCommandsInCategory( LUA::getString(2) ) );
}

int LDocumentWindow::getKeyMappings(lua_State*) {
//return LUA::returnUserdata<LKeyPressMappingSet>( commandManager->getKeyMappings() );
return 0;
}

int LDocumentWindow::invokeDirectly(lua_State*) {
commandManager->invokeDirectly( (CommandID)LUA::getNumber<int>(2), LUA::getBoolean(3) );
return 0;
}

int LDocumentWindow::invoke(lua_State *L) {
// TODO
return 0;
}

int LDocumentWindow::getFirstCommandTarget(lua_State*) {
return 0;
}

int LDocumentWindow::setFirstCommandTarget(lua_State*) {
return 0;
}

int LDocumentWindow::getTargetForCommand(lua_State*) {
return 0;
}


// statics
int LDocumentWindow::findDefaultComponentTarget(lua_State*) {
return 0;
}

int LDocumentWindow::findTargetForComponent(lua_State*) {
return 0;
}
32 changes: 3 additions & 29 deletions Source/LDocumentWindow.h
Expand Up @@ -2,8 +2,7 @@
#define __LJUCE_DOCUMENT_WINDOW_H

class LDocumentWindow : public LComponent,
public DocumentWindow,
private AsyncUpdater
public DocumentWindow
{
public:
LDocumentWindow(lua_State*);
Expand All @@ -14,6 +13,8 @@ class LDocumentWindow : public LComponent,
int closeButtonPressed(lua_State*);
void closeButtonPressed();

int closeWindow(lua_State*);

int setContentOwned(lua_State*);
int addChildComponent(lua_State*);
int addAndMakeVisible(lua_State*);
Expand Down Expand Up @@ -49,31 +50,6 @@ class LDocumentWindow : public LComponent,
int clearContentComponent(lua_State*);
int setContentComponentSize(lua_State*);


//==============================================================================
static ApplicationCommandManager& getApplicationCommandManager();

int clearCommands(lua_State*);
int registerCommand(lua_State*);
int registerAllCommandsForTarget(lua_State*);
int removeCommand(lua_State*);
int commandStatusChanged(lua_State*);
int getNumCommands(lua_State*);
int getCommandForIndex(lua_State*);
int getCommandForID(lua_State*);
int getNameOfCommand(lua_State*);
int getDescriptionOfCommand(lua_State*);
int getCommandCategories(lua_State*);
int getCommandsInCategory(lua_State*);
int getKeyMappings(lua_State*);
int invokeDirectly(lua_State*);
int invoke(lua_State*);
int getFirstCommandTarget(lua_State*);
int setFirstCommandTarget(lua_State*);
int getTargetForCommand(lua_State*);
int findDefaultComponentTarget(lua_State*);
int findTargetForComponent(lua_State*);

//==============================================================================
static const char className[];
static const Luna<LDocumentWindow>::Inheritence inherits[];
Expand All @@ -86,8 +62,6 @@ class LDocumentWindow : public LComponent,
private:
//==============================================================================

virtual void handleAsyncUpdate() override;

virtual bool keyPressed(const KeyPress&) override;
virtual bool keyStateChanged(bool) override;

Expand Down

0 comments on commit fa5bfeb

Please sign in to comment.