Skip to content

Commit

Permalink
fixes #3428 (Sessions: опция "сохранять X сессий" недоступна для ручн…
Browse files Browse the repository at this point in the history
…ого редактирования)

fixes #3422 (Sessions: падение при удалении несуществующей сессии)
  • Loading branch information
georgehazan committed Mar 15, 2023
1 parent e4f25e2 commit d5320ae
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 48 deletions.
19 changes: 9 additions & 10 deletions plugins/Sessions/Src/LoadSessions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ class CLoadSessionDlg : public CDlgBase
m_list.SetCurSel(0);
pSession = (CSession *)m_list.GetItemData(0);

int iDelay = g_plugin.getWord("StartupModeDelay", 1500);
if (g_bDontShow == TRUE)
timerLoad.Start(iDelay);
timerLoad.Start(g_plugin.iStartupDelay);
else {
LoadPosition(m_hwnd, "LoadDlg");
if (g_bStartup)
timerShow.Start(iDelay);
timerShow.Start(g_plugin.iStartupDelay);
else
Show();
}
Expand Down Expand Up @@ -137,7 +136,7 @@ INT_PTR OpenSessionsManagerWindow(WPARAM, LPARAM)
return 0;
}

if (g_bOtherWarnings)
if (g_plugin.bOtherWarnings)
MessageBox(nullptr, TranslateT("No sessions to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
Expand All @@ -163,7 +162,7 @@ INT_PTR LoadLastSession(WPARAM, LPARAM)
if (g_bLastSessionPresent && cnt)
return LoadSession(&g_arDateSessions[cnt-1]);

if (g_bOtherWarnings)
if (g_plugin.bOtherWarnings)
MessageBox(nullptr, TranslateT("Last Sessions is empty"), TranslateT("Sessions Manager"), MB_OK);
return 0;
}
Expand All @@ -190,7 +189,7 @@ int LoadSession(CSession *pSession)
while (session_list_t[i] != 0) {
if (CheckForDuplicate(session_list, session_list_t[i]) == -1)
Clist_ContactDoubleClicked(session_list_t[i]);
else if (g_bWarnOnHidden) {
else if (g_plugin.bWarnOnHidden) {
if (!CheckContactVisibility(session_list_t[i])) {
hidden[j] = i + 1;
j++;
Expand All @@ -201,22 +200,22 @@ int LoadSession(CSession *pSession)
}

if (i == 0) {
if (g_bOtherWarnings)
if (g_plugin.bOtherWarnings)
MessageBox(nullptr, TranslateT("No contacts to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}

if (dup == i) {
if (!hidden[i]) {
if (g_bOtherWarnings)
if (g_plugin.bOtherWarnings)
MessageBox(nullptr, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
if (!g_bWarnOnHidden && g_bOtherWarnings) {
if (!g_plugin.bWarnOnHidden && g_plugin.bOtherWarnings) {
MessageBox(nullptr, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
if (g_bWarnOnHidden) {
if (g_plugin.bWarnOnHidden) {
if (IDYES == MessageBox(nullptr, TranslateT("This Session already opened (but probably hidden).\nDo you want to show hidden contacts?"), TranslateT("Sessions Manager"), MB_YESNO | MB_ICONQUESTION))
for (j = 0; hidden[j] != 0; j++)
Clist_ContactDoubleClicked(session_list_t[hidden[j] - 1]);
Expand Down
12 changes: 8 additions & 4 deletions plugins/Sessions/Src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ OBJLIST<CSession> g_arUserSessions(1, NumericKeySortT), g_arDateSessions(1, Nume

HANDLE hmTBButton[2], hiTBbutton[2], iTBbutton[2];

int g_ses_limit;
int g_lastUserId, g_lastDateId;

bool g_bExclHidden;
Expand Down Expand Up @@ -64,7 +63,13 @@ PLUGININFOEX pluginInfoEx =
CMPlugin::CMPlugin() :
PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx),
g_lastUserId(MODULENAME, "LastUserId", 0),
g_lastDateId(MODULENAME, "LastDateId", 0)
g_lastDateId(MODULENAME, "LastDateId", 0),
bExclHidden(MODULENAME, "ExclHidden", false),
bWarnOnHidden(MODULENAME, "WarnOnHidden", false),
bOtherWarnings(MODULENAME, "OtherWarnings", true),
bCrashRecovery(MODULENAME, "CrashRecovery", false),
iTrackCount(MODULENAME, "TrackCount", 10),
iStartupDelay(MODULENAME, "StartupModeDelay", 1500)
{}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -116,7 +121,7 @@ static void SaveDateSession()
mir_snprintf(szSetting, "%s_%d", "SessionDate", int(g_plugin.g_lastDateId));
g_plugin.setUString(szSetting, data.toString().c_str());

while (g_arDateSessions.getCount() >= g_ses_limit) {
while (g_arDateSessions.getCount() >= g_plugin.iTrackCount) {
mir_snprintf(szSetting, "%s_%d", "SessionDate", g_arDateSessions[0].id);
g_plugin.delSetting(szSetting);
g_arDateSessions.remove(int(0));
Expand Down Expand Up @@ -389,7 +394,6 @@ int CMPlugin::Load()
Miranda_WaitOnHandle(LaunchSessions);

// Settimgs
g_ses_limit = g_plugin.getByte("TrackCount", 10);
g_bExclHidden = g_plugin.getByte("ExclHidden", 0) != 0;
g_bWarnOnHidden = g_plugin.getByte("WarnOnHidden", 0) != 0;
g_bOtherWarnings = g_plugin.getByte("OtherWarnings", 1) != 0;
Expand Down
50 changes: 25 additions & 25 deletions plugins/Sessions/Src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class COptionsDlg : public CDlgBase
CCtrlCombo m_list;
CCtrlListBox m_opclist;

CCtrlEdit edtDelay;
CCtrlSpin spinCount;
CCtrlCheck chkExclHidden, chkWarnOnHidden, chkOtherWarnings, chkCrashRecovery;
CCtrlCheck chkStartDialog, chkLoadLast, chkLast, chkNothing;
CCtrlCheck chkExitAsk, chkExitSave, chkExitNothing;
CCtrlButton btnSave, btnEdit, btnDel;
Expand All @@ -152,14 +155,28 @@ class COptionsDlg : public CDlgBase
btnDel(this, IDC_DEL),
btnEdit(this, IDC_EDIT),
btnSave(this, IDC_SAVE),
edtDelay(this, IDC_STARTDELAY),
spinCount(this, IDC_SPIN1, 10, 1),
chkLast(this, IDC_CHECKLAST),
chkExitAsk(this, IDC_REXASK),
chkNothing(this, IDC_RNOTHING),
chkExitSave(this, IDC_REXSAVE),
chkLoadLast(this, IDC_RLOADLAST),
chkExitNothing(this, IDC_REXDSAVE),
chkStartDialog(this, IDC_STARTDIALOG)
chkStartDialog(this, IDC_STARTDIALOG),
chkExclHidden(this, IDC_EXCLHIDDEN),
chkWarnOnHidden(this, IDC_LASTHIDDENWARN),
chkOtherWarnings(this, IDC_WARNINGS),
chkCrashRecovery(this, IDC_CRASHRECOVERY)
{
CreateLink(edtDelay, g_plugin.iStartupDelay);
CreateLink(spinCount, g_plugin.iTrackCount);

CreateLink(chkExclHidden, g_plugin.bExclHidden);
CreateLink(chkWarnOnHidden, g_plugin.bWarnOnHidden);
CreateLink(chkOtherWarnings, g_plugin.bOtherWarnings);
CreateLink(chkCrashRecovery, g_plugin.bCrashRecovery);

btnDel.OnClick = Callback(this, &COptionsDlg::onClick_Del);
btnEdit.OnClick = Callback(this, &COptionsDlg::onClick_Edit);
btnSave.OnClick = Callback(this, &COptionsDlg::onClick_Save);
Expand Down Expand Up @@ -194,25 +211,9 @@ class COptionsDlg : public CDlgBase
m_clist.SetExStyle(CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT);
m_clist.AutoRebuild();

SetDlgItemInt(m_hwnd, IDC_TRACK, g_ses_limit = g_plugin.getByte("TrackCount", 10), FALSE);
SendDlgItemMessage(m_hwnd, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(10, 1));
SendDlgItemMessage(m_hwnd, IDC_SPIN1, UDM_SETPOS, 0, GetDlgItemInt(m_hwnd, IDC_TRACK, nullptr, FALSE));

m_opclist.ResetContent();
SetDlgItemInt(m_hwnd, IDC_STARTDELAY, g_plugin.getWord("StartupModeDelay", 1500), FALSE);
int startupmode = g_plugin.getByte("StartupMode", 3);
int exitmode = g_plugin.getByte("ShutdownMode", 2);

g_bExclHidden = g_plugin.getByte("ExclHidden", 0) != 0;
g_bWarnOnHidden = g_plugin.getByte("WarnOnHidden", 0) != 0;
g_bOtherWarnings = g_plugin.getByte("OtherWarnings", 1) != 0;
g_bCrashRecovery = g_plugin.getByte("CrashRecovery", 0) != 0;

CheckDlgButton(m_hwnd, IDC_EXCLHIDDEN, g_bExclHidden ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(m_hwnd, IDC_LASTHIDDENWARN, g_bWarnOnHidden ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(m_hwnd, IDC_WARNINGS, g_bOtherWarnings ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(m_hwnd, IDC_CRASHRECOVERY, g_bCrashRecovery ? BST_CHECKED : BST_UNCHECKED);

int startupmode = g_plugin.getByte("StartupMode", 3);
if (startupmode == 1)
chkStartDialog.SetState(true);
else if (startupmode == 3)
Expand All @@ -222,6 +223,7 @@ class COptionsDlg : public CDlgBase
else if (startupmode == 0)
chkNothing.SetState(true);

int exitmode = g_plugin.getByte("ShutdownMode", 2);
if (exitmode == 0)
chkExitNothing.SetState(true);
else if (exitmode == 1)
Expand All @@ -237,7 +239,10 @@ class COptionsDlg : public CDlgBase
if (!LoadSessionContacts())
btnDel.Disable();
}
else btnDel.Disable();
else {
m_list.Disable();
btnDel.Disable();
}

GetComboBoxInfo(m_list.GetHwnd(), &cbi);
mir_subclassWindow(cbi.hwndItem, ComboBoxSubclassProc);
Expand All @@ -253,7 +258,7 @@ class COptionsDlg : public CDlgBase
{
int iDelay = GetDlgItemInt(m_hwnd, IDC_STARTDELAY, nullptr, FALSE);
g_plugin.setWord("StartupModeDelay", (uint16_t)iDelay);
g_plugin.setByte("TrackCount", (uint8_t)(g_ses_limit = GetDlgItemInt(m_hwnd, IDC_TRACK, nullptr, FALSE)));

if (chkExitSave.IsChecked())
g_plugin.setByte("ShutdownMode", 2);
else if (IsDlgButtonChecked(m_hwnd, IDC_REXDSAVE))
Expand All @@ -269,11 +274,6 @@ class COptionsDlg : public CDlgBase
g_plugin.setByte("StartupMode", 2);
else if (chkNothing.IsChecked())
g_plugin.setByte("StartupMode", 0);

g_plugin.setByte("ExclHidden", (uint8_t)(IsDlgButtonChecked(m_hwnd, IDC_EXCLHIDDEN) ? (g_bExclHidden = 1) : (g_bExclHidden = 0)));
g_plugin.setByte("WarnOnHidden", (uint8_t)(IsDlgButtonChecked(m_hwnd, IDC_LASTHIDDENWARN) ? (g_bWarnOnHidden = 1) : (g_bWarnOnHidden = 0)));
g_plugin.setByte("OtherWarnings", (uint8_t)(IsDlgButtonChecked(m_hwnd, IDC_WARNINGS) ? (g_bOtherWarnings = 1) : (g_bOtherWarnings = 0)));
g_plugin.setByte("CrashRecovery", (uint8_t)(IsDlgButtonChecked(m_hwnd, IDC_CRASHRECOVERY) ? (g_bCrashRecovery = 1) : (g_bCrashRecovery = 0)));
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/Sessions/Src/SaveSessions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int SaveUserSessionName(MCONTACT *contacts, wchar_t *szUSessionName)

pSession->save();

while (g_arUserSessions.getCount() > g_ses_limit) {
while (g_arUserSessions.getCount() > g_plugin.iTrackCount) {
g_arUserSessions[0].remove();
g_arUserSessions.remove(int(0));
}
Expand Down
10 changes: 3 additions & 7 deletions plugins/Sessions/Src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
struct CMPlugin : public PLUGIN<CMPlugin>
{
CMOption<int> g_lastUserId, g_lastDateId;
CMOption<bool> bExclHidden, bWarnOnHidden, bOtherWarnings, bCrashRecovery;
CMOption<uint16_t> iTrackCount, iStartupDelay;

CMPlugin();

Expand Down Expand Up @@ -83,25 +85,19 @@ extern OBJLIST<CSession> g_arUserSessions, g_arDateSessions;
/////////////////////////////////////////////////////////////////////////////////////////

int LoadSession(CSession *pSession);
int SaveSessionHandles(MCONTACT *pSession, bool bNewSession);

void CALLBACK LaunchSessions();

INT_PTR CloseCurrentSession(WPARAM, LPARAM);
INT_PTR LoadLastSession(WPARAM wparam, LPARAM lparam);
INT_PTR LoadLastSession(WPARAM, LPARAM);
INT_PTR OpenSessionsManagerWindow(WPARAM, LPARAM);
INT_PTR SaveUserSessionHandles(WPARAM, LPARAM);

extern MCONTACT session_list_recovered[255];
extern MCONTACT session_list[255];

extern HWND g_hDlg, g_hSDlg;
extern int g_ses_limit;
extern bool g_bLastSessionPresent;
extern bool g_bExclHidden;
extern bool g_bWarnOnHidden;
extern bool g_bOtherWarnings;
extern bool g_bCrashRecovery;
extern bool g_bIncompletedSave;

#define TIMERID_SHOW 11
Expand Down
2 changes: 1 addition & 1 deletion plugins/Sessions/res/Sessions.rc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ BEGIN
CONTROL "Ask",IDC_REXASK,"Button",BS_AUTORADIOBUTTON | WS_GROUP,173,23,122,10
CONTROL "Save Current Session",IDC_REXSAVE,"Button",BS_AUTORADIOBUTTON,173,37,122,10
CONTROL "Do nothing",IDC_REXDSAVE,"Button",BS_AUTORADIOBUTTON,173,50,122,10
EDITTEXT IDC_TRACK,224,70,27,12,ES_AUTOHSCROLL | ES_READONLY | ES_NUMBER
EDITTEXT IDC_TRACK,224,70,27,12,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_SPIN1,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_TABSTOP,246,69,10,14
LTEXT "Save only last",IDC_EXSTATIC1,173,72,48,8
LTEXT "sessions",IDC_EXSTATIC2,253,72,28,8
Expand Down

0 comments on commit d5320ae

Please sign in to comment.