Skip to content

Commit eb2bf88

Browse files
Merge pull request #84 from hybridmachine/sprint/editing-power-ui-polish
Sprint: Editing Power & UI Polish (6 features)
2 parents 686a85c + 0836ff5 commit eb2bf88

17 files changed

Lines changed: 711 additions & 32 deletions

macos/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ add_executable(MacOSNotePP
346346
"${CMAKE_CURRENT_SOURCE_DIR}/platform/incremental_search.mm"
347347
"${CMAKE_CURRENT_SOURCE_DIR}/platform/find_in_files.mm"
348348
"${CMAKE_CURRENT_SOURCE_DIR}/platform/search_results_panel.mm"
349+
"${CMAKE_CURRENT_SOURCE_DIR}/platform/toolbar.mm"
350+
"${CMAKE_CURRENT_SOURCE_DIR}/platform/print_support.mm"
349351
)
350352
target_include_directories(MacOSNotePP PRIVATE
351353
"${CMAKE_CURRENT_SOURCE_DIR}/platform"

macos/platform/app_delegate.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "brace_match.h"
2525
#include "smart_highlight.h"
2626
#include "auto_indent.h"
27+
#include "toolbar.h"
2728
#include "scintilla_notify.h"
2829
#include "windows.h"
2930
#include "commctrl.h"
@@ -168,6 +169,8 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification
168169

169170
SetMenu(ctx().mainHwnd, hMenuBar);
170171

172+
setupToolbar(ctx().mainWindow);
173+
171174
NSView* contentView = ctx().mainWindow.contentView;
172175

173176
ctx().tabHwnd = CreateWindowExW(

macos/platform/brace_match.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
// Call this on every SCN_UPDATEUI notification.
55
void doBraceMatch(void* sci);
66

7+
// Jump the caret to the matching brace.
8+
void doGoToMatchingBrace(void* sci);
9+
710
// Configure brace highlight styles for light/dark mode.
811
void configureBraceStyles(void* sci, bool isDark);

macos/platform/brace_match.mm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,39 @@ void doBraceMatch(void* sci)
5050
}
5151
}
5252

53+
void doGoToMatchingBrace(void* sci)
54+
{
55+
if (!sci) return;
56+
57+
intptr_t caretPos = ScintillaBridge_sendMessage(sci, SCI_GETCURRENTPOS, 0, 0);
58+
intptr_t bracePos = -1;
59+
60+
// Reuse same before-caret / at-caret priority as doBraceMatch
61+
if (caretPos > 0)
62+
{
63+
int ch = static_cast<int>(ScintillaBridge_sendMessage(sci, SCI_GETCHARAT, caretPos - 1, 0));
64+
if (isBraceChar(ch))
65+
bracePos = caretPos - 1;
66+
}
67+
68+
if (bracePos < 0)
69+
{
70+
int ch = static_cast<int>(ScintillaBridge_sendMessage(sci, SCI_GETCHARAT, caretPos, 0));
71+
if (isBraceChar(ch))
72+
bracePos = caretPos;
73+
}
74+
75+
if (bracePos >= 0)
76+
{
77+
intptr_t matchPos = ScintillaBridge_sendMessage(sci, SCI_BRACEMATCH, bracePos, 0);
78+
if (matchPos >= 0)
79+
{
80+
ScintillaBridge_sendMessage(sci, SCI_GOTOPOS, matchPos, 0);
81+
ScintillaBridge_sendMessage(sci, SCI_CHOOSECARETX, 0, 0);
82+
}
83+
}
84+
}
85+
5386
void configureBraceStyles(void* sci, bool isDark)
5487
{
5588
if (!sci) return;

macos/platform/edit_commands.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ void doSortLines(bool ascending);
1111
void doJoinLines();
1212
void doTabsToSpaces();
1313
void doSpacesToTabs();
14+
void insertDateTimeShort();
15+
void insertDateTimeLong();

macos/platform/edit_commands.mm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// edit_commands.mm — Edit menu commands (case, line ops, comments, sort, join)
22
// Part of the Notepad++ macOS port modular refactor.
33

4+
#import <Foundation/Foundation.h>
45
#include "edit_commands.h"
56
#include "npp_constants.h"
67
#include "app_state.h"
@@ -351,3 +352,34 @@ void doSpacesToTabs()
351352
}
352353
ScintillaBridge_sendMessage(sci, SCI_ENDUNDOACTION, 0, 0);
353354
}
355+
356+
void insertDateTimeShort()
357+
{
358+
void* sci = ctx().activeScintillaView();
359+
if (!sci) return;
360+
361+
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
362+
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
363+
NSString* dateStr = [formatter stringFromDate:[NSDate date]];
364+
const char* utf8 = [dateStr UTF8String];
365+
366+
ScintillaBridge_sendMessage(sci, SCI_BEGINUNDOACTION, 0, 0);
367+
ScintillaBridge_sendMessage(sci, SCI_REPLACESEL, 0, reinterpret_cast<intptr_t>(utf8));
368+
ScintillaBridge_sendMessage(sci, SCI_ENDUNDOACTION, 0, 0);
369+
}
370+
371+
void insertDateTimeLong()
372+
{
373+
void* sci = ctx().activeScintillaView();
374+
if (!sci) return;
375+
376+
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
377+
[formatter setDateStyle:NSDateFormatterFullStyle];
378+
[formatter setTimeStyle:NSDateFormatterMediumStyle];
379+
NSString* dateStr = [formatter stringFromDate:[NSDate date]];
380+
const char* utf8 = [dateStr UTF8String];
381+
382+
ScintillaBridge_sendMessage(sci, SCI_BEGINUNDOACTION, 0, 0);
383+
ScintillaBridge_sendMessage(sci, SCI_REPLACESEL, 0, reinterpret_cast<intptr_t>(utf8));
384+
ScintillaBridge_sendMessage(sci, SCI_ENDUNDOACTION, 0, 0);
385+
}

macos/platform/language_defs.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,42 @@ struct LangDef
1414
int menuId; // Menu command ID
1515
};
1616

17+
// Named language indices for type-safe references
18+
constexpr int LANG_NORMAL_TEXT = 0;
19+
constexpr int LANG_C = 1;
20+
constexpr int LANG_CPP = 2;
21+
constexpr int LANG_JAVA = 3;
22+
constexpr int LANG_PYTHON = 4;
23+
constexpr int LANG_JAVASCRIPT = 5;
24+
constexpr int LANG_HTML = 6;
25+
constexpr int LANG_CSS = 7;
26+
constexpr int LANG_XML = 8;
27+
constexpr int LANG_JSON = 9;
28+
constexpr int LANG_MARKDOWN = 10;
29+
constexpr int LANG_SQL = 11;
30+
constexpr int LANG_SHELL = 12;
31+
constexpr int LANG_RUST = 13;
32+
constexpr int LANG_GO = 14;
33+
constexpr int LANG_OBJC = 15;
34+
constexpr int LANG_SWIFT = 16;
35+
constexpr int LANG_TYPESCRIPT = 17;
36+
constexpr int LANG_PHP = 18;
37+
constexpr int LANG_RUBY = 19;
38+
constexpr int LANG_PERL = 20;
39+
constexpr int LANG_LUA = 21;
40+
constexpr int LANG_YAML = 22;
41+
constexpr int LANG_TOML = 23;
42+
constexpr int LANG_INI = 24;
43+
constexpr int LANG_MAKEFILE = 25;
44+
constexpr int LANG_DIFF = 26;
45+
constexpr int LANG_DOCKERFILE = 27;
46+
constexpr int LANG_CMAKE = 28;
47+
constexpr int LANG_POWERSHELL = 29;
48+
constexpr int LANG_R = 30;
49+
constexpr int LANG_KOTLIN = 31;
50+
constexpr int LANG_SCALA = 32;
51+
constexpr int LANG_LATEX = 33;
52+
1753
extern const LangDef g_languages[];
1854
extern const int g_numLanguages;
1955

0 commit comments

Comments
 (0)