fix for #10872. remember last selected message feature (4xp)

plus some code cleanup.  r/sr=bienvenu
This commit is contained in:
sspitzer%netscape.com 2002-12-13 19:57:27 +00:00
Родитель 5dc23aadf0
Коммит f19f9b7a6a
11 изменённых файлов: 91 добавлений и 51 удалений

Просмотреть файл

@ -40,8 +40,8 @@ Contributor(s):
var _elementIDs = ["mailnewsConfirmMoveFoldersToTrash",
"mailnewsStartPageEnabled", "mailnewsStartPageUrl",
"fileButton", "nextButton",
"printButton", "stopButton", "junkMailButton"];
//"mailRememberLastMsg"
"printButton", "stopButton",
"mailRememberLastMsg", "junkMailButton"];
]]>
</script>
@ -56,13 +56,12 @@ Contributor(s):
<hbox align="start" id="mapi"/>
<!-- not ready yet
<hbox align="center">
<checkbox id="mailRememberLastMsg" label="&rememberLastMsg.label;"
prefstring="mailnews.remember_selected_message"
accesskey="&rememberLastMsg.accesskey;" />
</hbox>
-->
<separator class="thin"/>
</groupbox>

Просмотреть файл

@ -290,6 +290,8 @@ interface nsIMsgDBView : nsISupports
readonly attribute nsMsgViewIndex currentlyDisplayedMessage;
// used by "go to folder" feature
// and "remember last selected message" feature
// if key is not found, we don't select.
void selectMsgByKey(in nsMsgKey key);
// we'll suppress displaying messages if the message pane is collapsed
@ -306,6 +308,8 @@ interface nsIMsgDBView : nsISupports
readonly attribute boolean supportsThreading;
attribute nsIMsgSearchSession searchSession;
nsMsgViewIndex findIndexFromKey(in nsMsgKey aMsgKey, in boolean aExpand);
};
/* this interface is rapidly morphing from a command updater interface into a more generic

Просмотреть файл

@ -419,4 +419,6 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne
string getStringProperty(in string propertyName);
void setStringProperty(in string propertyName, in string propertyValue);
/* does not persist across sessions */
attribute nsMsgKey lastMessageLoaded;
};

Просмотреть файл

@ -20,6 +20,10 @@
/* This is where functions related to the standalone message window are kept */
// from MailNewsTypes.h
const nsMsgKey_None = 0xFFFFFFFF;
const nsMsgViewIndex_None = 0xFFFFFFFF;
/* globals for a particular window */
var compositeDataSourceContractID = datasourceContractIDPrefix + "composite-datasource";
@ -184,9 +188,6 @@ nsMsgDBViewCommandUpdater.prototype =
}
}
// from MailNewsTypes.h
const nsMsgKey_None = 0xFFFFFFFF;
function HandleDeleteOrMoveMsgCompleted(folder)
{
var folderResource = folder.QueryInterface(Components.interfaces.nsIRDFResource);
@ -198,7 +199,7 @@ function HandleDeleteOrMoveMsgCompleted(folder)
{
gDBView.onDeleteCompleted(true);
gCurrentMessageIsDeleted = false;
if (gNextMessageViewIndexAfterDelete != nsMsgKey_None)
if (gNextMessageViewIndexAfterDelete != nsMsgViewIndex_None)
{
var nextMstKey = gDBView.getKeyAt(gNextMessageViewIndexAfterDelete);
if (nextMstKey != nsMsgKey_None) {

Просмотреть файл

@ -27,8 +27,9 @@
/* This is where functions related to the 3 pane window are kept */
// from MailNewsTypes.h
const nsMsgKey_None = 0xFFFFFFFF;
const nsMsgViewIndex_None = 0xFFFFFFFF;
const kMailCheckOncePrefName = "mail.startup.enabledMailCheckOnce";
var gFolderTree;
var gMessagePane;
@ -52,7 +53,7 @@ var gNextMessageAfterLoad = null;
var gNextMessageViewIndexAfterDelete = -2;
var gCurrentlyDisplayedMessage=nsMsgViewIndex_None;
var gStartFolderUri = null;
var gStartMsgKey = -1;
var gStartMsgKey = nsMsgKey_None;
var gSearchEmailAddress = null;
var gRightMouseButtonDown = false;
// Global var to keep track of which row in the thread pane has been selected
@ -72,6 +73,23 @@ var gDisplayStartupPage = false;
var gNotifyDefaultInboxLoadedOnStartup = false;
function SelectAndScrollToKey(aMsgKey)
{
// select the desired message
// if the key isn't found, we won't select anything
gDBView.selectMsgByKey(aMsgKey);
// is there a selection?
// if not, bail out.
var indicies = GetSelectedIndices(gDBView);
if (!indicies || !indicies.length)
return false;
// now scroll to it
EnsureRowInThreadTreeIsVisible(indicies[0]);
return true;
}
// the folderListener object
var folderListener = {
OnItemAdded: function(parentItem, item, view) { },
@ -152,16 +170,11 @@ var folderListener = {
LoadCurrentlyDisplayedMessage(); //used for rename folder msg loading after folder is loaded.
if (gStartMsgKey != -1) {
// select the desired message
gDBView.selectMsgByKey(gStartMsgKey);
gStartMsgKey = -1;
// now scroll to it
var indicies = GetSelectedIndices(gDBView);
EnsureRowInThreadTreeIsVisible(indicies[0]);
scrolled = true;
if (gStartMsgKey != nsMsgKey_None) {
scrolled = SelectAndScrollToKey(gStartMsgKey);
gStartMsgKey = nsMsgKey_None;
}
if (gNextMessageAfterLoad) {
var type = gNextMessageAfterLoad;
gNextMessageAfterLoad = null;
@ -173,7 +186,16 @@ var folderListener = {
}
if (uri == gCurrentLoadingFolderURI) {
gCurrentLoadingFolderURI = "";
//Now let's select the first new message if there is one
if (!scrolled && pref.getBoolPref("mailnews.remember_selected_message")) {
var lastMessageLoaded = msgFolder.lastMessageLoaded;
if (lastMessageLoaded != nsMsgKey_None) {
scrolled = SelectAndScrollToKey(lastMessageLoaded);
}
}
// Now let's select the first new message if there is one
if (!scrolled) {
// if we didn't just scroll, scroll to the first new message
// don't select it though
@ -618,7 +640,7 @@ function OnLoadMessenger()
else
{
gStartFolderUri = null;
gStartMsgKey = -1;
gStartMsgKey = nsMsgKey_None;
gSearchEmailAddress = null;
}
@ -698,8 +720,6 @@ function loadStartFolder(initialUri)
var defaultServer = null;
var startFolderResource = null;
var isLoginAtStartUpEnabled = false;
var enabledNewMailCheckOnce = false;
var mailCheckOncePref = "mail.startup.enabledMailCheckOnce";
//First get default account
try
@ -715,14 +735,12 @@ function loadStartFolder(initialUri)
startFolderResource = rootMsgFolder.QueryInterface(Components.interfaces.nsIRDFResource);
enabledNewMailCheckOnce = pref.getBoolPref(mailCheckOncePref);
// Enable checknew mail once by turning checkmail pref 'on' to bring
// all users to one plane. This allows all users to go to Inbox. User can
// always go to server settings panel and turn off "Check for new mail at startup"
if (!enabledNewMailCheckOnce)
if (!pref.getBoolPref(kMailCheckOncePrefName))
{
pref.setBoolPref(mailCheckOncePref, true);
pref.setBoolPref(kMailCheckOncePrefName, true);
defaultServer.loginAtStartUp = true;
}

Просмотреть файл

@ -929,6 +929,11 @@ nsresult nsMsgDBView::UpdateDisplayMessage(nsMsgKey aMsgKey)
NS_ENSURE_SUCCESS(rv,rv);
mCommandUpdater->DisplayMessageChanged(m_folder, subject, keywords);
if (m_folder) {
rv = m_folder->SetLastMessageLoaded(aMsgKey);
NS_ENSURE_SUCCESS(rv,rv);
}
} // if view position is valid
} // if we have an updater
return NS_OK;
@ -5221,7 +5226,7 @@ nsMsgDBView::GetMsgToSelectAfterDelete(nsMsgViewIndex *msgToSelectAfterDelete)
NS_IMETHODIMP
nsMsgDBView::GetCurrentlyDisplayedMessage (nsMsgViewIndex *currentlyDisplayedMessage)
nsMsgDBView::GetCurrentlyDisplayedMessage(nsMsgViewIndex *currentlyDisplayedMessage)
{
NS_ENSURE_ARG_POINTER(currentlyDisplayedMessage);
*currentlyDisplayedMessage = FindViewIndex(m_currentlyDisplayedMsgKey);
@ -5444,6 +5449,10 @@ NS_IMETHODIMP nsMsgDBView::IsSorted(PRBool *_retval)
NS_IMETHODIMP nsMsgDBView::SelectMsgByKey(nsMsgKey aKey)
{
NS_ASSERTION(aKey != nsMsgKey_None, "bad key");
if (aKey == nsMsgKey_None)
return NS_OK;
// use SaveAndClearSelection()
// and RestoreSelection() so that we'll clear the current selection
// but pass in a different key array so that we'll
@ -5457,6 +5466,9 @@ NS_IMETHODIMP nsMsgDBView::SelectMsgByKey(nsMsgKey aKey)
nsMsgKeyArray keyArray;
keyArray.Add(aKey);
// if the key was not found
// (this can happen with "remember last selected message")
// nothing will be selected
rv = RestoreSelection(&keyArray);
NS_ENSURE_SUCCESS(rv,rv);
return NS_OK;
@ -5524,6 +5536,15 @@ nsMsgDBView::GetSupportsThreading(PRBool *aResult)
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsMsgDBView::FindIndexFromKey(nsMsgKey aMsgKey, PRBool aExpand, nsMsgViewIndex *aIndex)
{
NS_ENSURE_ARG_POINTER(aIndex);
*aIndex = FindKey(aMsgKey, aExpand);
return NS_OK;
}
static void getDateFormatPref( const nsCOMPtr<nsIPrefBranch>& _prefBranch, const char* _prefLocalName, nsDateFormatSelector& _format )
{

Просмотреть файл

@ -89,7 +89,7 @@ NS_IMPL_ISUPPORTS_INHERITED2(nsMsgDBFolder, nsMsgFolder,
nsMsgDBFolder::nsMsgDBFolder(void)
: mAddListener(PR_TRUE), mNewMessages(PR_FALSE), mGettingNewMessages(PR_FALSE)
: mAddListener(PR_TRUE), mNewMessages(PR_FALSE), mGettingNewMessages(PR_FALSE), mLastMessageLoaded(nsMsgKey_None)
{
if (mInstanceCount++ <=0) {
mFolderLoadedAtom = NS_NewAtom("FolderLoaded");
@ -1829,3 +1829,17 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgWindow *aMsgWindow)
return rv;
}
NS_IMETHODIMP
nsMsgDBFolder::GetLastMessageLoaded(nsMsgKey *aMsgKey)
{
NS_ENSURE_ARG_POINTER(aMsgKey);
*aMsgKey = mLastMessageLoaded;
return NS_OK;
}
NS_IMETHODIMP
nsMsgDBFolder::SetLastMessageLoaded(nsMsgKey aMsgKey)
{
mLastMessageLoaded = aMsgKey;
return NS_OK;
}

Просмотреть файл

@ -123,7 +123,8 @@ public:
NS_IMETHOD GetStringProperty(const char *propertyName, char **propertyValue);
NS_IMETHOD SetStringProperty(const char *propertyName, const char *propertyValue);
NS_IMETHOD CallFilterPlugins(nsIMsgWindow *aMsgWindow);
NS_IMETHOD GetLastMessageLoaded(nsMsgKey *aMsgKey);
NS_IMETHOD SetLastMessageLoaded(nsMsgKey aMsgKey);
protected:
virtual nsresult ReadDBFolderInfo(PRBool force);
@ -160,6 +161,7 @@ protected:
PRBool mAddListener;
PRBool mNewMessages;
PRBool mGettingNewMessages;
nsMsgKey mLastMessageLoaded;
nsCOMPtr <nsIMsgDBHdr> m_offlineHeader;
PRInt32 m_numOfflineMsgLines;

Просмотреть файл

@ -116,7 +116,6 @@ protected:
PRInt32 m_flags; // folder specific flags. This holds things like re-use thread pane,
// configured for off-line use, use default retrieval, purge article/header options
nsMsgKey m_lastMessageLoaded; // set by the FE's to remember the last loaded message
PRUint16 m_version; // for upgrading...
PRInt16 m_IMAPHierarchySeparator; // imap path separator
@ -148,7 +147,6 @@ protected:
mdb_token m_numMessagesColumnToken;
mdb_token m_numNewMessagesColumnToken;
mdb_token m_flagsColumnToken;
mdb_token m_lastMessageLoadedColumnToken;
mdb_token m_folderSizeColumnToken;
mdb_token m_expungedBytesColumnToken;
mdb_token m_folderDateColumnToken;

Просмотреть файл

@ -44,7 +44,6 @@
%}
[scriptable, uuid(5cb11c00-cb8b-11d2-8d67-00805f8a6617)]
interface nsIDBFolderInfo : nsISupports {
attribute long Flags;
long OrFlags(in long flags);
@ -53,7 +52,6 @@ interface nsIDBFolderInfo : nsISupports {
attribute nsMsgKey HighWater;
attribute nsMsgKey ExpiredMark;
attribute unsigned long FolderSize;
attribute nsMsgKey LastMessageLoaded;
attribute unsigned long FolderDate;
void ChangeNumNewMessages(in long delta);
void ChangeNumMessages(in long delta);

Просмотреть файл

@ -59,7 +59,6 @@ static const char * kNumVisibleMessagesColumnName = "numVisMsgs";
static const char * kNumMessagesColumnName ="numMsgs";
static const char * kNumNewMessagesColumnName = "numNewMsgs";
static const char * kFlagsColumnName = "flags";
static const char * kLastMessageLoadedColumnName = "lastMsgLoaded";
static const char * kFolderSizeColumnName = "folderSize";
static const char * kExpungedBytesColumnName = "expungedBytes";
static const char * kFolderDateColumnName = "folderDate";
@ -166,7 +165,6 @@ nsDBFolderInfo::QueryInterface(REFNSIID iid, void** result)
nsDBFolderInfo::nsDBFolderInfo(nsMsgDatabase *mdb)
: m_flags(0),
m_lastMessageLoaded(0),
m_expiredMark(0),
m_numVisibleMessagesColumnToken(0),
m_expiredMarkColumnToken(0)
@ -376,7 +374,6 @@ nsresult nsDBFolderInfo::InitMDBInfo()
store->StringToToken(env, kNumMessagesColumnName, &m_numMessagesColumnToken);
store->StringToToken(env, kNumNewMessagesColumnName, &m_numNewMessagesColumnToken);
store->StringToToken(env, kFlagsColumnName, &m_flagsColumnToken);
store->StringToToken(env, kLastMessageLoadedColumnName, &m_lastMessageLoadedColumnToken);
store->StringToToken(env, kFolderSizeColumnName, &m_folderSizeColumnToken);
store->StringToToken(env, kExpungedBytesColumnName, &m_expungedBytesColumnToken);
store->StringToToken(env, kFolderDateColumnName, &m_folderDateColumnToken);
@ -678,20 +675,6 @@ NS_IMETHODIMP nsDBFolderInfo::SetImapUidValidity(PRInt32 uidValidity)
return SetUint32PropertyWithToken(m_imapUidValidityColumnToken, m_ImapUidValidity);
}
NS_IMETHODIMP nsDBFolderInfo::GetLastMessageLoaded(nsMsgKey *lastLoaded)
{
*lastLoaded = m_lastMessageLoaded;
return NS_OK;
}
NS_IMETHODIMP nsDBFolderInfo::SetLastMessageLoaded(nsMsgKey lastLoaded)
{
m_lastMessageLoaded = lastLoaded;
return SetUint32PropertyWithToken(m_lastMessageLoadedColumnToken, m_lastMessageLoaded);
}
PRBool nsDBFolderInfo::TestFlag(PRInt32 flags)
{
return (m_flags & flags) != 0;