Compare commits

..

3 Commits

18 changed files with 167 additions and 10 deletions

View File

@@ -172,7 +172,7 @@ RegisterVariable(Int, WaitForEvents, 1);
RegisterVariable(Int, DrawLineNumbers, 1); RegisterVariable(Int, DrawLineNumbers, 1);
RegisterVariable(Int, DrawScrollbar, 1); RegisterVariable(Int, DrawScrollbar, 1);
RegisterVariable(Int, IndentSize, 4); RegisterVariable(Int, IndentSize, 4);
RegisterVariable(Int, FontSize, 15); RegisterVariable(Int, FontSize, 20);
RegisterVariable(String, PathToFont, ""); RegisterVariable(String, PathToFont, "");
RegisterVariable(Float, UndoMergeTime, 0.3); RegisterVariable(Float, UndoMergeTime, 0.3);
RegisterVariable(Float, JumpHistoryMergeTime, 0.3); RegisterVariable(Float, JumpHistoryMergeTime, 0.3);

View File

@@ -1,3 +1,4 @@
#if PLUGIN_BASIC_COMMANDS
void CMD_Redo() { void CMD_Redo() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
RedoEdit(active.buffer, &active.view->carets); RedoEdit(active.buffer, &active.view->carets);
@@ -270,4 +271,5 @@ void CMD_PlayMacro() {
} }
For (MacroPlayback) Add(&EventPlayback, it); For (MacroPlayback) Add(&EventPlayback, it);
} RegisterCommand(CMD_PlayMacro, "alt-m", "Start playing back a macro recording"); } RegisterCommand(CMD_PlayMacro, "alt-m", "Start playing back a macro recording");
#endif

View File

@@ -1,3 +1,4 @@
#if PLUGIN_BUILD_WINDOW
WindowID BuildWindowID; WindowID BuildWindowID;
ViewID BuildViewID; ViewID BuildViewID;
BufferID BuildBufferID; BufferID BuildBufferID;
@@ -90,3 +91,4 @@ void CMD_ShowBuildWindow() {
main.window->visible = false; main.window->visible = false;
} }
} RegisterCommand(CMD_ShowBuildWindow, "ctrl-grave", "Toggles visibility of the build window"); } RegisterCommand(CMD_ShowBuildWindow, "ctrl-grave", "Toggles visibility of the build window");
#endif

View File

@@ -1,3 +1,4 @@
#if PLUGIN_COMMAND_RUNNER_WINDOW
WindowID CommandRunnerWindowID; WindowID CommandRunnerWindowID;
void CMD_ShowCommandRunner() { void CMD_ShowCommandRunner() {
@@ -65,3 +66,4 @@ void InitCommandRunnerWindow() {
window->jump_history = false; window->jump_history = false;
AddCommand(&view->commands, "Open", OpenKeySet, CMD_OpenForRunnerWindow); AddCommand(&view->commands, "Open", OpenKeySet, CMD_OpenForRunnerWindow);
} }
#endif // PLUGIN_COMMAND_RUNNER_WINDOW

View File

@@ -1,3 +1,4 @@
#if PLUGIN_COMMAND_WINDOW
WindowID CommandWindowID; WindowID CommandWindowID;
void CMD_ShowCommands() { void CMD_ShowCommands() {
@@ -84,3 +85,4 @@ void InitCommandWindow() {
window->lose_focus_on_escape = true; window->lose_focus_on_escape = true;
window->jump_history = false; window->jump_history = false;
} }
#endif // PLUGIN_COMMAND_WINDOW

View File

@@ -1,3 +1,4 @@
#if PLUGIN_DEBUG_WINDOW
WindowID DebugWindowID; WindowID DebugWindowID;
ViewID DebugViewID; ViewID DebugViewID;
BufferID DebugBufferID; BufferID DebugBufferID;
@@ -65,3 +66,4 @@ void CMD_ToggleDebug() {
Window *window = GetWindow(DebugWindowID); Window *window = GetWindow(DebugWindowID);
window->visible = !window->visible; window->visible = !window->visible;
} RegisterCommand(CMD_ToggleDebug, "ctrl-0", "Open a floating window that might become useful for debugging"); } RegisterCommand(CMD_ToggleDebug, "ctrl-0", "Open a floating window that might become useful for debugging");
#endif // PLUGIN_DEBUG_WINDOW

View File

@@ -1,3 +1,4 @@
#if PLUGIN_DIRECTORY_NAVIGATION
// @todo: On save rename files, delete files it should apply the changes // @todo: On save rename files, delete files it should apply the changes
// Instead of toying with Reopen maybe it should actually detect changes in directory etc. on update // Instead of toying with Reopen maybe it should actually detect changes in directory etc. on update
@@ -203,4 +204,5 @@ void DestroyDirectoryWatcher(DirectoryWatcher *w)
} }
#endif #endif
#endif
#endif #endif

View File

@@ -1,3 +1,4 @@
#if PLUGIN_PROJECT_MANAGEMENT
void SetProjectFolder(String dir) { void SetProjectFolder(String dir) {
ProjectFolder = Intern(&GlobalInternTable, dir); ProjectFolder = Intern(&GlobalInternTable, dir);
Scratch scratch; Scratch scratch;
@@ -134,4 +135,5 @@ void CO_CreateProject(mco_coro *co) {
} }
CO_OpenCode(co); CO_OpenCode(co);
} RegisterCoroutineCommand(CO_CreateProject, "", "Creates a project in current buffer directory with template files and all that, asks user for input etc."); } RegisterCoroutineCommand(CO_CreateProject, "", "Creates a project in current buffer directory with template files and all that, asks user for input etc.");
#endif

View File

@@ -1 +1,3 @@
#if PLUGIN_PROJECT_MANAGEMENT
void SetProjectFolder(String name); void SetProjectFolder(String name);
#endif

View File

@@ -1,3 +1,4 @@
#if PLUGIN_RECORD_EVENTS
Buffer *EventBuffer; Buffer *EventBuffer;
void Serialize(Buffer *buffer, String name, EventKind *kind) { void Serialize(Buffer *buffer, String name, EventKind *kind) {
@@ -67,4 +68,5 @@ void Serialize(Buffer *buffer, Event *e) {
void CMD_CopyEvents() { void CMD_CopyEvents() {
SaveStringInClipboard(GetString(EventBuffer)); SaveStringInClipboard(GetString(EventBuffer));
} RegisterCommand(CMD_CopyEvents, "ctrl-shift-alt-j", "Copy all the events from the EventBuffer"); } RegisterCommand(CMD_CopyEvents, "ctrl-shift-alt-j", "Copy all the events from the EventBuffer");
#endif

View File

@@ -1 +1,3 @@
Buffer *GCInfoBuffer; #if PLUGIN_RECORD_GC
Buffer *GCInfoBuffer;
#endif

View File

@@ -1,3 +1,4 @@
#if PLUGIN_SEARCH_OPEN_BUFFERS
struct SearchOpenBuffersParams { struct SearchOpenBuffersParams {
String16 needle; String16 needle;
BufferID buffer; BufferID buffer;
@@ -127,3 +128,4 @@ void CMD_SearchOpenBuffers() {
} }
SelectRange(main.view, GetLineRangeWithoutNL(main.buffer, 0)); SelectRange(main.view, GetLineRangeWithoutNL(main.buffer, 0));
} RegisterCommand(CMD_SearchOpenBuffers, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view"); } RegisterCommand(CMD_SearchOpenBuffers, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view");
#endif

View File

@@ -1,3 +1,4 @@
#if PLUGIN_SEARCH_WINDOW
Int SearchBufferChangeID; Int SearchBufferChangeID;
void CMD_Search() { void CMD_Search() {
@@ -110,3 +111,4 @@ void UpdateSearchWindow() {
} }
} }
} }
#endif

View File

@@ -1,3 +1,4 @@
#if PLUGIN_STATUS_WINDOW
WindowID StatusWindowID; WindowID StatusWindowID;
void InitStatusWindow() { void InitStatusWindow() {
@@ -97,3 +98,4 @@ void UpdateStatusWindow() {
SelectRange(title.view, MakeRange(0)); SelectRange(title.view, MakeRange(0));
ResetHistory(title.buffer); ResetHistory(title.buffer);
} }
#endif

View File

@@ -1,6 +1,5 @@
#if PLUGIN_TESTS #if PLUGIN_TESTS
void Wait(mco_coro *co) { void Wait(mco_coro *co) {
{Event ev = {};ev.kind = EVENT_KIND_INVALID; Add(&EventPlayback, ev);} {Event ev = {};ev.kind = EVENT_KIND_INVALID; Add(&EventPlayback, ev);}
Event *event = NULL; Event *event = NULL;
@@ -120,4 +119,4 @@ Memes and stuff)FOO";
} RegisterCoroutineCommand(CO_RunTests, "", "Basic tests"); } RegisterCoroutineCommand(CO_RunTests, "", "Basic tests");
#endif #endif // PLUGIN_TESTS

118
src/plugin_tutorial.cpp Normal file
View File

@@ -0,0 +1,118 @@
#if PLUGIN_TUTORIAL
#define RegisterTutorialSection(NAME, DESC, STRING)\
String NAME##_string = STRING;\
void CMD_##NAME() {\
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectFolder, #NAME), NAME##_string.len * 4 + 4096);\
buffer->temp = true;\
RawAppend(buffer, NAME##_string);\
buffer->dirty = false;\
Open(buffer->name);\
} RegisterCommand(CMD_##NAME, "", DESC);
RegisterTutorialSection(EnterTheTutorial, "The guide to sailing the text", R"==(
Hello sailor!
--------------------------------
I see you have entered the unknown
text waters of the internet.
Before we set sail, right click:
:CoolText
...and watch the waters stir.
)==");
RegisterTutorialSection(CoolText, "Coolest text inside the coolest tutorial", R"==(
The text can lead you
into interesting places
--------------------------------
Do not be afraid. Try these too:
:MakeFontLarger
:MakeFontSmaller
Make the letters huge.
Then make them tiny again.
and then ...
--------------------------------
:GoToNextSectionOfTheTutorial!
)==");
RegisterTutorialSection(GoToNextSectionOfTheTutorial, "Yes!", R"==(
Special words listen to keys too:
Ctrl-+ Ctrl--
Even right click has a twin:
Ctrl-Q F12
Put your caret here and try:
:Prev
:New (beware, you may never return! Hint: Take a look at the bar on the bottom)
:HowToFindCommands
)==");
RegisterTutorialSection(HowToFindCommands, "Tutorial on finding the commands", R"==(
Open the map:
:ShowCommands (Ctrl-Shift-P)
Type a few letters.
Press (Enter) to choose.
These special words are not magical
You can easily find them
and use.
-------------------------------
HowToBindCommandsToKeys
-------------------------------
)==");
RegisterTutorialSection(HowToBindCommandsToKeys, "how to bind commands to keys", R"==(
We will start easy. Try selecting the entire line below and (ctrl-q / right click / F12)
:Set DrawLineNumbers 0
:Set TextColor ffaa0000
Make it normal again:
:Set DrawLineNumbers 1
:Set TextColor ff21201d
And of course this setup also works for keys:
:Set MakeFontLarger 'ctrl-t'
See the map for this:
:OpenConfigOptions
)==");
void InitTutorial() {
CMD_EnterTheTutorial();
}
#endif

View File

@@ -1,3 +1,4 @@
#if PLUGIN_WINDOW_MANAGEMENT
void CMD_JumpPrev() { void CMD_JumpPrev() {
BSet main = GetBSet(PrimaryWindowID); BSet main = GetBSet(PrimaryWindowID);
JumpToLastValidView(main.window); JumpToLastValidView(main.window);
@@ -80,3 +81,4 @@ void CMD_GotoPrevInList() {
BSet main = GetBSet(PrimaryWindowID); BSet main = GetBSet(PrimaryWindowID);
GotoNextInList(main.window, -1); GotoNextInList(main.window, -1);
} RegisterCommand(CMD_GotoPrevInList, "alt-e | shift-f8", "For example: when jumping from build panel to build error, a jump point is setup, user can click this button to go over to the previous compiler error"); } RegisterCommand(CMD_GotoPrevInList, "alt-e | shift-f8", "For example: when jumping from build panel to build error, a jump point is setup, user can click this button to go over to the previous compiler error");
#endif

View File

@@ -73,8 +73,7 @@
#include "render_opengl.cpp" #include "render_opengl.cpp"
#define PLUGIN_CONFIG 1 #define PLUGIN_CONFIG 1
#define PLUGIN_SEARCH_WINDOW 1 #define PLUGIN_TUTORIAL 1
#define PLUGIN_PROJECT_MANAGEMENT 1
#define PLUGIN_WINDOW_MANAGEMENT 1 #define PLUGIN_WINDOW_MANAGEMENT 1
#define PLUGIN_DIRECTORY_NAVIGATION 1 #define PLUGIN_DIRECTORY_NAVIGATION 1
#define PLUGIN_SEARCH_OPEN_BUFFERS 1 #define PLUGIN_SEARCH_OPEN_BUFFERS 1
@@ -88,7 +87,6 @@
#define PLUGIN_DEBUG_WINDOW 1 #define PLUGIN_DEBUG_WINDOW 1
#define PLUGIN_RECORD_GC 1 #define PLUGIN_RECORD_GC 1
#define PLUGIN_RECORD_EVENTS 1 #define PLUGIN_RECORD_EVENTS 1
#define PLUGIN_DIRECTORY_NAVIGATION 1
#define PLUGIN_LOAD_VCVARS OS_WINDOWS #define PLUGIN_LOAD_VCVARS OS_WINDOWS
#define PLUGIN_REMEDYBG OS_WINDOWS #define PLUGIN_REMEDYBG OS_WINDOWS
#define PLUGIN_FILE_COMMANDS 1 #define PLUGIN_FILE_COMMANDS 1
@@ -135,6 +133,7 @@
#include "plugin_file_commands.cpp" #include "plugin_file_commands.cpp"
#include "plugin_word_complete.cpp" #include "plugin_word_complete.cpp"
#include "plugin_tests.cpp" #include "plugin_tests.cpp"
#include "plugin_tutorial.cpp"
#if OS_WASM #if OS_WASM
EM_JS(void, JS_SetMouseCursor, (const char *cursor_str), { EM_JS(void, JS_SetMouseCursor, (const char *cursor_str), {
@@ -987,6 +986,7 @@ int main(int argc, char **argv, char **envp)
} }
#endif #endif
#if PLUGIN_TESTS
if (1) { if (1) {
RunArenaTest(); RunArenaTest();
For (TestFunctions) { For (TestFunctions) {
@@ -996,6 +996,7 @@ int main(int argc, char **argv, char **envp)
// ReportErrorf("Testing DONE\n"); // ReportErrorf("Testing DONE\n");
// return 0; // return 0;
} }
#endif
if (!SDL_Init(SDL_INIT_VIDEO)) { if (!SDL_Init(SDL_INIT_VIDEO)) {
ReportErrorf("Couldn't initialize SDL! %s", SDL_GetError()); ReportErrorf("Couldn't initialize SDL! %s", SDL_GetError());
@@ -1028,6 +1029,7 @@ int main(int argc, char **argv, char **envp)
int hhalf = 1000; int hhalf = 1000;
int xhalf = 100; int xhalf = 100;
int yhalf = 100; int yhalf = 100;
Unused(xhalf); Unused(yhalf);
#else #else
SDL_DisplayID primary_display_id = SDL_GetPrimaryDisplay(); SDL_DisplayID primary_display_id = SDL_GetPrimaryDisplay();
const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(primary_display_id); const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(primary_display_id);
@@ -1043,7 +1045,9 @@ int main(int argc, char **argv, char **envp)
ReportErrorf("Couldn't create window! %s", SDL_GetError()); ReportErrorf("Couldn't create window! %s", SDL_GetError());
return 1; return 1;
} }
#if !OS_LINUX
SDL_SetWindowPosition(SDLWindow, xhalf, yhalf); SDL_SetWindowPosition(SDLWindow, xhalf, yhalf);
#endif
SDL_WindowGLContext = SDL_GL_CreateContext(SDLWindow); SDL_WindowGLContext = SDL_GL_CreateContext(SDLWindow);
SDL_GL_MakeCurrent(SDLWindow, SDL_WindowGLContext); SDL_GL_MakeCurrent(SDLWindow, SDL_WindowGLContext);
@@ -1065,10 +1069,12 @@ int main(int argc, char **argv, char **envp)
SDL_StartTextInput(SDLWindow); SDL_StartTextInput(SDLWindow);
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, true); SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, true);
SDL_GL_SetSwapInterval(1); // vsync SDL_GL_SetSwapInterval(1); // vsync
{ {
float scale = SDL_GetWindowDisplayScale(SDLWindow); float scale = SDL_GetWindowDisplayScale(SDLWindow);
if (scale != 1.0f) DPIScale = scale; if (scale != 1.0f) DPIScale = scale;
} }
SDL_SyncWindow(SDLWindow);
// InitBuffers // InitBuffers
{ {
@@ -1137,6 +1143,12 @@ int main(int argc, char **argv, char **envp)
Open(argv[i]); Open(argv[i]);
} }
#if PLUGIN_TUTORIAL
if (argc == 1) {
InitTutorial();
}
#endif
#if PLUGIN_LOAD_VCVARS #if PLUGIN_LOAD_VCVARS
LoadVCVars(); LoadVCVars();
#endif #endif