Skip to content

Commit 74ed6c1

Browse files
committed
Added function 'Bookmark' to let scripts bookmark lines
1 parent 2045747 commit 74ed6c1

File tree

11 files changed

+97
-20
lines changed

11 files changed

+97
-20
lines changed

doc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ BEGIN_DISPATCH_MAP(CMUSHclientDoc, CDocument)
610610
DISP_FUNCTION(CMUSHclientDoc, "DatabaseGetField", DatabaseGetField, VT_VARIANT, VTS_BSTR VTS_BSTR)
611611
DISP_FUNCTION(CMUSHclientDoc, "WindowSetZOrder", WindowSetZOrder, VT_I4, VTS_BSTR VTS_I4)
612612
DISP_FUNCTION(CMUSHclientDoc, "UnloadPlugin", UnloadPlugin, VT_I4, VTS_BSTR)
613+
DISP_FUNCTION(CMUSHclientDoc, "Bookmark", Bookmark, VT_EMPTY, VTS_I4 VTS_BOOL)
613614
DISP_PROPERTY_PARAM(CMUSHclientDoc, "NormalColour", GetNormalColour, SetNormalColour, VT_I4, VTS_I2)
614615
DISP_PROPERTY_PARAM(CMUSHclientDoc, "BoldColour", GetBoldColour, SetBoldColour, VT_I4, VTS_I2)
615616
DISP_PROPERTY_PARAM(CMUSHclientDoc, "CustomColourText", GetCustomColourText, SetCustomColourText, VT_I4, VTS_I2)

doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,6 +2754,7 @@ class CMUSHclientDoc : public CDocument
27542754
afx_msg VARIANT DatabaseGetField(LPCTSTR Name, LPCTSTR Sql);
27552755
afx_msg long WindowSetZOrder(LPCTSTR Name, long Order);
27562756
afx_msg long UnloadPlugin(LPCTSTR PluginID);
2757+
afx_msg void Bookmark(long LineNumber, BOOL Set);
27572758
afx_msg long GetNormalColour(short WhichColour);
27582759
afx_msg void SetNormalColour(short WhichColour, long nNewValue);
27592760
afx_msg long GetBoldColour(short WhichColour);

mushclient.cnt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
3 Base64Decode=FNC_Base64Decode
198198
3 Base64Encode=FNC_Base64Encode
199199
3 BlendPixel=FNC_BlendPixel
200+
3 Bookmark=FNC_Bookmark
200201
3 BoldColour=FNC_BoldColour
201202
3 BroadcastPlugin=FNC_BroadcastPlugin
202203
3 CallPlugin=FNC_CallPlugin

mushclient.odl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ library MUSHclient
7070
[id(44)] long SetCommand(BSTR Message);
7171
[id(45)] BSTR GetNotes();
7272
[id(46)] void SetNotes(BSTR Message);
73-
[id(408), propget] long NormalColour(short WhichColour);
74-
[id(408), propput] void NormalColour(short WhichColour, long nNewValue);
75-
[id(409), propget] long BoldColour(short WhichColour);
76-
[id(409), propput] void BoldColour(short WhichColour, long nNewValue);
77-
[id(410), propget] long CustomColourText(short WhichColour);
78-
[id(410), propput] void CustomColourText(short WhichColour, long nNewValue);
79-
[id(411), propget] long CustomColourBackground(short WhichColour);
80-
[id(411), propput] void CustomColourBackground(short WhichColour, long nNewValue);
73+
[id(409), propget] long NormalColour(short WhichColour);
74+
[id(409), propput] void NormalColour(short WhichColour, long nNewValue);
75+
[id(410), propget] long BoldColour(short WhichColour);
76+
[id(410), propput] void BoldColour(short WhichColour, long nNewValue);
77+
[id(411), propget] long CustomColourText(short WhichColour);
78+
[id(411), propput] void CustomColourText(short WhichColour, long nNewValue);
79+
[id(412), propget] long CustomColourBackground(short WhichColour);
80+
[id(412), propput] void CustomColourBackground(short WhichColour, long nNewValue);
8181
[id(47)] void Redraw();
8282
[id(48)] long ResetTimer(BSTR TimerName);
8383
[id(49)] void SetOutputFont(BSTR FontName, short PointSize);
@@ -439,6 +439,7 @@ library MUSHclient
439439
[id(405)] VARIANT DatabaseGetField(BSTR Name, BSTR Sql);
440440
[id(406)] long WindowSetZOrder(BSTR Name, long Order);
441441
[id(407)] long UnloadPlugin(BSTR PluginID);
442+
[id(408)] void Bookmark(long LineNumber, BOOL Set);
442443
//}}AFX_ODL_METHOD
443444

444445
};

mushview.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4826,12 +4826,20 @@ int nNewLine = m_selstart_line,
48264826

48274827
startpos = pos;
48284828
pInitialLine = pDoc->m_LineList.GetNext (pos); // skip current position
4829+
// if we were at the end, loop back to the start
4830+
if (!pos)
4831+
{
4832+
pos = pDoc->m_LineList.GetHeadPosition ();
4833+
nNewLine = -1;
4834+
}
4835+
48294836
nInitialLine = nNewLine;
48304837

48314838
while (pos)
48324839
{
48334840
nNewLine++;
48344841
pLine = pDoc->m_LineList.GetNext (pos);
4842+
48354843
if (pLine->flags & BOOKMARK)
48364844
break;
48374845
else
@@ -4846,11 +4854,11 @@ int nNewLine = m_selstart_line,
48464854

48474855
if (startpos == pos)
48484856
break; // reached start again? don't loop forever
4849-
} // end of loop
4857+
}; // end of loop
48504858

48514859
// if we didn't find one *but* we were on one anyway, re-go to it
48524860

4853-
if (!pLine && pInitialLine->flags & BOOKMARK)
4861+
if (!pLine && (pInitialLine->flags & BOOKMARK))
48544862
{
48554863
pLine = pInitialLine;
48564864
nNewLine = nInitialLine;
@@ -4871,13 +4879,6 @@ ASSERT_VALID(pDoc);
48714879
if (pDoc->m_LineList.IsEmpty ())
48724880
return;
48734881

4874-
CRgn oldrgn;
4875-
CRgn newrgn;
4876-
4877-
// Get old selection region
4878-
4879-
get_selection (oldrgn);
4880-
48814882
// if no selection (or out of range) select last line in display
48824883
if (m_selstart_line <= 0 || m_selstart_line >= pDoc->m_LineList.GetCount ())
48834884
m_selstart_line = pDoc->GetLastLine () - 1;
@@ -4886,10 +4887,30 @@ ASSERT_VALID(pDoc);
48864887

48874888
pLine->flags ^= BOOKMARK; // toggle bookmark
48884889

4890+
BookmarkLine (m_selstart_line);
4891+
4892+
} // end of CMUSHView::OnDisplayBookmarkselection
4893+
4894+
4895+
void CMUSHView::BookmarkLine (const long iLine)
4896+
{
4897+
CMUSHclientDoc* pDoc = GetDocument();
4898+
ASSERT_VALID(pDoc);
4899+
4900+
CRgn oldrgn;
4901+
CRgn newrgn;
4902+
4903+
// Get old selection region
4904+
4905+
get_selection (oldrgn);
4906+
4907+
m_selstart_line = iLine;
48894908
m_selstart_col = 0;
48904909
m_selend_col = 0;
48914910
m_selend_line = m_selstart_line;
48924911

4912+
CLine * pLine = pDoc->m_LineList.GetAt (pDoc->GetLinePosition (m_selstart_line));
4913+
48934914
if (pLine->flags & BOOKMARK)
48944915
m_selend_col = pLine->len;
48954916

@@ -4913,8 +4934,7 @@ ASSERT_VALID(pDoc);
49134934
newrgn.DeleteObject ();
49144935
oldrgn.DeleteObject ();
49154936

4916-
4917-
} // end of CMUSHView::OnDisplayBookmarkselection
4937+
} // end of CMUSHView::BookmarkLine
49184938

49194939

49204940
void CMUSHView::doBookmark (void)

mushview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ bool GetSelection(CString & s);
158158
void SendMacro (int whichone);
159159
void SelectionChanged (void);
160160
void AutoWrapWindowWidth (CMUSHclientDoc* pDoc);
161+
void BookmarkLine (const long iLine);
161162

162163
// Overrides
163164
// ClassWizard generated virtual function overrides

resource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@
15621562
#ifdef APSTUDIO_INVOKED
15631563
#ifndef APSTUDIO_READONLY_SYMBOLS
15641564
#define _APS_3D_CONTROLS 1
1565-
#define _APS_NEXT_RESOURCE_VALUE 366
1565+
#define _APS_NEXT_RESOURCE_VALUE 367
15661566
#define _APS_NEXT_COMMAND_VALUE 33054
15671567
#define _APS_NEXT_CONTROL_VALUE 2897
15681568
#define _APS_NEXT_SYMED_VALUE 312

scripting/functionlist.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ tInternalFunctionsTable InternalFunctionsTable [] = {
5656
{ "Base64Decode" , "( Text )" } ,
5757
{ "Base64Encode" , "( Text , MultiLine )" } ,
5858
{ "BlendPixel" , "( Blend , Base , Mode , Opacity )" } ,
59+
{ "Bookmark" , "( LineNumber , Set )" } ,
5960
{ "BoldColour" , "( WhichColour , NewValue )" } ,
6061
{ "BroadcastPlugin" , "( Message , Text )" } ,
6162
{ "CallPlugin" , "( PluginID , Routine , Argument )" } ,

scripting/lua_methods.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,18 @@ static int L_SetBoldColour (lua_State *L)
943943
return 0; // number of result fields
944944
} // end of SetBoldColour
945945

946+
//----------------------------------------
947+
// world.Bookmark
948+
//----------------------------------------
949+
static int L_Bookmark (lua_State *L)
950+
{
951+
CMUSHclientDoc *pDoc = doc (L);
952+
pDoc->Bookmark (
953+
my_checknumber (L, 1), // LineNumber
954+
optboolean (L, 2, 1) // Set flag, defaults to true
955+
);
956+
return 0; // number of result fields
957+
} // end of L_Bookmark
946958

947959
//----------------------------------------
948960
// world.BroadcastPlugin
@@ -6655,6 +6667,7 @@ static const struct luaL_Reg worldlib [] =
66556667
{"Base64Decode", L_Base64Decode},
66566668
{"Base64Encode", L_Base64Encode},
66576669
{"BlendPixel", L_BlendPixel},
6670+
{"Bookmark", L_Bookmark},
66586671
{"GetBoldColour", L_GetBoldColour},
66596672
{"SetBoldColour", L_SetBoldColour},
66606673
{"BroadcastPlugin", L_BroadcastPlugin},

scripting/methods/methods_output.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
// ActivateClient
2020
// AddFont
21+
// Bookmark
2122
// DeleteLines
2223
// DeleteOutput
2324
// FlashIcon
@@ -780,3 +781,39 @@ void windowPositionHelper (CString & str, const RECT & r)
780781
} // end of windowPositionHelper
781782

782783

784+
785+
void CMUSHclientDoc::Bookmark(long LineNumber, BOOL Set)
786+
{
787+
// check line exists
788+
if (LineNumber <= 0 || LineNumber > m_LineList.GetCount ())
789+
return;
790+
791+
LineNumber--; // zero relative
792+
// get pointer to line in question
793+
794+
CLine * pLine = m_LineList.GetAt (GetLinePosition (LineNumber));
795+
796+
797+
if (Set)
798+
pLine->flags |= BOOKMARK;
799+
else
800+
pLine->flags &= ~BOOKMARK;
801+
802+
// alter appearance of all output windows
803+
804+
for(POSITION pos = GetFirstViewPosition(); pos != NULL; )
805+
{
806+
CView* pView = GetNextView(pos);
807+
808+
if (pView->IsKindOf(RUNTIME_CLASS(CMUSHView)))
809+
{
810+
CMUSHView* pmyView = (CMUSHView*)pView;
811+
812+
pmyView->BookmarkLine (LineNumber);
813+
814+
} // end of being a CMUSHView
815+
} // end of loop through views
816+
817+
} // end of CMUSHclientDoc::Bookmark
818+
819+

0 commit comments

Comments
 (0)