mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 14:46:02 +00:00
Adding CommandState Observer interface
This commit is contained in:
parent
9f82cfff38
commit
30f6445ec9
@ -42,6 +42,7 @@ public:
|
||||
NS_IMETHOD Unregister(nsISupports * aSubjectObserver);
|
||||
NS_IMETHOD Unregister(nsIXPFCSubject * aSubject, nsIXPFCObserver * aObserver);
|
||||
NS_IMETHOD Notify(nsIXPFCSubject * aSubject, nsIXPFCCommand * aCommand);
|
||||
NS_IMETHOD RegisterForCommandState(nsIXPFCCommandStateObserver * aCommandStateObserver, nsCommandState aCommandState);
|
||||
|
||||
protected:
|
||||
~nsXPFCObserverManager();
|
||||
@ -51,7 +52,7 @@ public:
|
||||
|
||||
public:
|
||||
nsIVector * mList ;
|
||||
nsIXPFCSubject * mCurrentSubject;
|
||||
nsIVector * mState ;
|
||||
|
||||
};
|
||||
|
||||
|
@ -12,6 +12,7 @@ DEPTH = ../../..
|
||||
|
||||
EXPORTS = \
|
||||
nsIXPFCObserver.h \
|
||||
nsIXPFCCommandStateObserver.h \
|
||||
nsIXPFCSubject.h \
|
||||
nsIXPFCObserverManager.h \
|
||||
$(NULL)
|
||||
|
43
xpfc/observer/public/nsIXPFCCommandStateObserver.h
Normal file
43
xpfc/observer/public/nsIXPFCCommandStateObserver.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIXPFCCommandStateObserver_h___
|
||||
#define nsIXPFCCommandStateObserver_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
//2e8e55f0-621b-11d2-924c-00805f8a7ab6
|
||||
#define NS_IXPFC_COMMAND_STATE_OBSERVER_IID \
|
||||
{ 0x2e8e55f0, 0x621b, 0x11d2, \
|
||||
{ 0x92, 0x4c, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6 } }
|
||||
|
||||
enum nsCommandState {
|
||||
nsCommandState_eNone,
|
||||
nsCommandState_eComplete
|
||||
};
|
||||
|
||||
class nsIXPFCCommandStateObserver : public nsISupports
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD Init() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsIXPFCCommandStateObserver_h___ */
|
@ -20,6 +20,7 @@
|
||||
#define nsIXPFCObserverManager_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIXPFCCommandStateObserver.h"
|
||||
|
||||
class nsIXPFCSubject;
|
||||
class nsIXPFCObserver;
|
||||
@ -42,6 +43,8 @@ public:
|
||||
NS_IMETHOD Unregister(nsIXPFCSubject * aSubject, nsIXPFCObserver * aObserver) = 0;
|
||||
NS_IMETHOD Notify(nsIXPFCSubject * aSubject, nsIXPFCCommand * aCommand) = 0;
|
||||
|
||||
NS_IMETHOD RegisterForCommandState(nsIXPFCCommandStateObserver * aCommandStateObserver, nsCommandState aCommandState) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsIXPFCObserverManager_h___ */
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "nsIXPFCObserver.h"
|
||||
#include "nsIXPFCSubject.h"
|
||||
#include "nsIXPFCCommand.h"
|
||||
#include "nsIXPFCCommandStateObserver.h"
|
||||
#include "nsxpfcCIID.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
@ -41,11 +42,27 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class StateEntry {
|
||||
public:
|
||||
nsCommandState state;
|
||||
nsIXPFCCommandStateObserver * observer;
|
||||
|
||||
StateEntry(nsCommandState aState,
|
||||
nsIXPFCCommandStateObserver * aObserver) {
|
||||
state = aState;
|
||||
observer = aObserver;
|
||||
}
|
||||
~StateEntry() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
nsXPFCObserverManager :: nsXPFCObserverManager()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mList = nsnull;
|
||||
mState = nsnull;
|
||||
monitor = nsnull;
|
||||
|
||||
Init();
|
||||
@ -54,6 +71,7 @@ nsXPFCObserverManager :: nsXPFCObserverManager()
|
||||
nsXPFCObserverManager :: ~nsXPFCObserverManager()
|
||||
{
|
||||
NS_IF_RELEASE(mList);
|
||||
NS_IF_RELEASE(mState);
|
||||
PR_DestroyMonitor(monitor);
|
||||
}
|
||||
|
||||
@ -79,6 +97,22 @@ nsresult nsXPFCObserverManager::Init()
|
||||
mList->Init();
|
||||
}
|
||||
|
||||
if (mState == nsnull) {
|
||||
|
||||
static NS_DEFINE_IID(kCVectorIteratorCID, NS_VECTOR_ITERATOR_CID);
|
||||
static NS_DEFINE_IID(kCVectorCID, NS_VECTOR_CID);
|
||||
|
||||
nsresult res = nsRepository::CreateInstance(kCVectorCID,
|
||||
nsnull,
|
||||
kCVectorCID,
|
||||
(void **)&mState);
|
||||
|
||||
if (NS_OK != res)
|
||||
return res ;
|
||||
|
||||
mState->Init();
|
||||
}
|
||||
|
||||
if (monitor == nsnull) {
|
||||
monitor = PR_NewMonitor();
|
||||
}
|
||||
@ -228,3 +262,13 @@ nsresult nsXPFCObserverManager::Notify(nsIXPFCSubject * aSubject, nsIXPFCCommand
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsXPFCObserverManager::RegisterForCommandState(nsIXPFCCommandStateObserver * aCommandStateObserver, nsCommandState aCommandState)
|
||||
{
|
||||
PR_EnterMonitor(monitor);
|
||||
|
||||
mState->Append(new StateEntry(aCommandState, aCommandStateObserver));
|
||||
|
||||
PR_ExitMonitor(monitor);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user