Skip to content

Commit 81d3ca1

Browse files
committed
Added ability to shift+tab choose from recent command history
1 parent aaab995 commit 81d3ca1

File tree

3 files changed

+88
-8
lines changed

3 files changed

+88
-8
lines changed

dialogs/CompleteWordDlg.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CCompleteWordDlg::CCompleteWordDlg(CWnd* pParent /*=NULL*/)
2727
m_bLua = false;
2828
m_bFunctions = true;
2929
m_extraItems = NULL;
30+
m_commandHistoryItems = NULL;
3031
}
3132

3233

@@ -49,7 +50,7 @@ END_MESSAGE_MAP()
4950
// CCompleteWordDlg message handlers
5051

5152

52-
static const char * sNoMatches = "(no matches)";
53+
CString strNoMatches = "(no matches)";
5354

5455
extern tInternalFunctionsTable InternalFunctionsTable [1];
5556

@@ -58,6 +59,31 @@ void CCompleteWordDlg::ReloadList ()
5859

5960
m_ctlFunctions.ResetContent ();
6061

62+
if (m_commandHistoryItems)
63+
{
64+
strNoMatches = "(no matching commands)";
65+
if (m_commandHistoryItems->empty ())
66+
{
67+
m_ctlFunctions.AddString (strNoMatches);
68+
m_ctlFunctions.EnableWindow (FALSE);
69+
return;
70+
}
71+
72+
string sLastOne;
73+
74+
for (vector<string>::const_iterator it = m_commandHistoryItems->begin ();
75+
it != m_commandHistoryItems->end ();
76+
it++)
77+
{
78+
m_ctlFunctions.AddString (it->c_str ());
79+
sLastOne = *it;
80+
}
81+
82+
// m_ctlFunctions.SelectString (-1, sLastOne.c_str ());
83+
84+
return;
85+
}
86+
6187
m_strFilter.MakeLower ();
6288
m_strFilter.TrimLeft ();
6389
m_strFilter.TrimRight ();
@@ -156,7 +182,7 @@ void CCompleteWordDlg::ReloadList ()
156182

157183
if (iCount == 0)
158184
{
159-
m_ctlFunctions.AddString (sNoMatches);
185+
m_ctlFunctions.AddString (strNoMatches);
160186
m_ctlFunctions.EnableWindow (FALSE);
161187
}
162188

@@ -193,7 +219,7 @@ void CCompleteWordDlg::OnOK()
193219
m_ctlFunctions.GetText (iWhich, m_strResult);
194220

195221
// can't return our "no matches" string
196-
if (m_strResult == sNoMatches)
222+
if (m_strResult == strNoMatches)
197223
m_strResult.Empty ();
198224
else
199225
{

dialogs/CompleteWordDlg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CCompleteWordDlg : public CDialog
3131
bool m_bLua;
3232
bool m_bFunctions;
3333
set<string> * m_extraItems;
34+
vector<string> * m_commandHistoryItems;
3435

3536
// Overrides
3637
// ClassWizard generated virtual function overrides

sendvw.cpp

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ActivityView.h"
2424

2525
#include "dialogs\cmdhist.h"
26+
#include "dialogs\CompleteWordDlg.h"
2627

2728
#include "ActivityDoc.h"
2829

@@ -2727,12 +2728,64 @@ void CSendView::OnCompleteFunction()
27272728
CMUSHclientDoc* pDoc = GetDocument();
27282729
ASSERT_VALID(pDoc);
27292730

2730-
bool bLua = false;
2731-
2732-
if (pDoc->GetScriptEngine () && pDoc->GetScriptEngine ()->L)
2733-
bLua = true;
2731+
CString strText;
2732+
GetEditCtrl().GetWindowText(strText);
2733+
2734+
// if line starts with scripting prefix, do a function-completion
2735+
if (pDoc->m_bEnableScripts && // providing scripting active
2736+
!pDoc->m_strScriptPrefix.IsEmpty () && // and we *have* a script prefix
2737+
strText.Left (pDoc->m_strScriptPrefix.GetLength ()) == pDoc->m_strScriptPrefix // and it matches
2738+
)
2739+
{
2740+
bool bLua = false;
2741+
2742+
if (pDoc->GetScriptEngine () && pDoc->GetScriptEngine ()->L)
2743+
bLua = true;
2744+
2745+
FunctionMenu (GetEditCtrl(), bLua, &pDoc->m_ExtraShiftTabCompleteItems, pDoc->m_bTabCompleteFunctions);
2746+
return;
2747+
}
2748+
2749+
// otherwise look up old command in command history
2750+
2751+
vector<string> vWantedHistory;
2752+
2753+
// top
2754+
2755+
strText.MakeUpper ();
2756+
2757+
for (POSITION pos = m_msgList.GetHeadPosition (); pos; )
2758+
{
2759+
CString strLine = m_msgList.GetNext (pos);
2760+
// add providing matches start of what they typed
2761+
if (strText.IsEmpty () || strLine.Left (strText.GetLength ()).CompareNoCase (strText) == 0)
2762+
vWantedHistory.push_back ((LPCTSTR) strLine);
2763+
}
2764+
2765+
2766+
CCompleteWordDlg dlg;
2767+
2768+
int nStartChar,
2769+
nEndChar;
2770+
2771+
// find the selection range
2772+
GetEditCtrl().GetSel(nStartChar, nEndChar);
2773+
2774+
dlg.m_bFunctions = false;
2775+
dlg.m_commandHistoryItems = &vWantedHistory;
2776+
dlg.m_pt = GetEditCtrl().PosFromChar (nEndChar - 1); // strangely doesn't work at end of line
2777+
2778+
dlg.m_pt.x += 10; // small gap
2779+
dlg.m_pt.y += 10; // small adjustment lalala
2780+
2781+
GetEditCtrl().ClientToScreen(&dlg.m_pt);
2782+
2783+
if (dlg.DoModal () == IDCANCEL || dlg.m_strResult.IsEmpty ())
2784+
return;
2785+
2786+
GetEditCtrl().SetSel (0, -1); // select all
2787+
GetEditCtrl().ReplaceSel (dlg.m_strResult, TRUE);
27342788

2735-
FunctionMenu (GetEditCtrl(), bLua, &pDoc->m_ExtraShiftTabCompleteItems, pDoc->m_bTabCompleteFunctions);
27362789
}
27372790

27382791
void CSendView::OnUpdateCompleteFunction(CCmdUI* pCmdUI)

0 commit comments

Comments
 (0)