Skip to content

Commit b3a1062

Browse files
authored
Merge pull request bruderstein#66 from ClaudiaFrank/feature_request_54
make menu command Show Console toggling
2 parents a1025b1 + 0a6d253 commit b3a1062

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

PythonScript/src/ConsoleDialog.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "PluginInterface.h"
99
#include "Docking.h"
1010
#include "WcharMbcsConverter.h"
11+
#include "MenuManager.h"
1112

1213

1314
namespace NppPythonScript
@@ -625,12 +626,13 @@ void ConsoleDialog::doDialog()
625626
callScintilla(SCI_COLOURISE, 0, -1);
626627
}
627628
}
628-
629+
MenuManager::getInstance()->checkShowConsole(true);
629630
display(true);
630631
}
631632

632633
void ConsoleDialog::hide()
633634
{
635+
MenuManager::getInstance()->checkShowConsole(false);
634636
display(false);
635637
}
636638

PythonScript/src/MenuManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,3 +1132,8 @@ bool MenuManager::inFixedRange(idx_t commandID)
11321132
assert(m_originalDynamicMenuManager != NULL);
11331133
return m_originalDynamicMenuManager && m_originalDynamicMenuManager->inRange(commandID);
11341134
}
1135+
1136+
void MenuManager::checkShowConsole(bool checked)
1137+
{
1138+
::SendMessage(m_hNotepad, NPPM_SETMENUITEMCHECK, (WPARAM)m_funcItems[1]._cmdID, (LPARAM)checked);
1139+
}

PythonScript/src/MenuManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class MenuManager
8181
static bool s_menuItemClicked;
8282
static WNDPROC s_origWndProc;
8383

84+
void checkShowConsole(bool checked);
8485

8586

8687
private:

PythonScript/src/PythonConsole.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void PythonConsole::pythonShowDialog()
136136
else
137137
{
138138
mp_consoleDlg->doDialog();
139+
consoleVisible = true;
139140
}
140141
}
141142
}
@@ -147,6 +148,7 @@ void PythonConsole::showDialog()
147148
{
148149
GILRelease release;
149150
mp_consoleDlg->doDialog();
151+
consoleVisible = true;
150152
}
151153
}
152154

@@ -157,6 +159,7 @@ void PythonConsole::hideDialog()
157159
{
158160
GILRelease release;
159161
mp_consoleDlg->hide();
162+
consoleVisible = false;
160163
}
161164
}
162165

PythonScript/src/PythonConsole.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class PythonConsole : public PyProducerConsumer<std::string>, public ConsoleInte
7272
boost::shared_ptr<ScintillaWrapper> mp_scintillaWrapper;
7373

7474
static boost::python::str getEncoding() { return boost::python::str("utf-8"); }
75+
76+
bool consoleVisible = false;
7577

7678
protected:
7779
virtual void consume(std::shared_ptr<std::string> statement);

PythonScript/src/PythonScript.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static std::vector< std::pair<std::string*, HICON>* > g_toolbarScripts;
5858
static void doAbout();
5959

6060
static void newScript();
61-
static void showConsole();
61+
static void toggleConsole();
6262
static void showShortcutDlg();
6363
static void stopScript();
6464
static void runScript(idx_t number);
@@ -70,8 +70,6 @@ static void previousScript();
7070

7171
static FuncItem* getGeneratedFuncItemArray(int *nbF);
7272

73-
74-
7573
// Run script functions
7674

7775

@@ -171,7 +169,7 @@ static FuncItem* getGeneratedFuncItemArray(int *nbF)
171169
idx_t runPreviousIndex;
172170

173171
items.push_back(std::pair<tstring, void(*)()>(_T("New Script"), newScript));
174-
items.push_back(std::pair<tstring, void(*)()>(_T("Show Console"), showConsole));
172+
items.push_back(std::pair<tstring, void(*)()>(_T("Show Console"), toggleConsole));
175173

176174
items.push_back(std::pair<tstring, void(*)()>(_T("--"), reinterpret_cast<void(*)()>(NULL)));
177175

@@ -570,12 +568,19 @@ static void showShortcutDlg()
570568
}
571569
}
572570

573-
static void showConsole()
571+
static void toggleConsole()
574572
{
575573
if (g_console)
576574
{
577575
CHECK_INITIALISED();
578-
g_console->showDialog();
576+
if (g_console->consoleVisible)
577+
{
578+
g_console->hideDialog();
579+
}
580+
else
581+
{
582+
g_console->showDialog();
583+
}
579584
}
580585
}
581586

0 commit comments

Comments
 (0)