From 55eb007f68f0c7f94b9ddda0c0f12c0db8414759 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 8 Sep 2016 18:57:37 -0400 Subject: [PATCH] fixed panel closing bug --- 4coder_API.html | 17 ++++--- 4coder_custom_api.h | 2 +- 4ed_api_implementation.cpp | 93 ++++++++++++++++---------------------- TODO.txt | 2 +- 4 files changed, 52 insertions(+), 62 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index c1ada157..2999b488 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -32,11 +32,14 @@ does not summarize an actual buffer in 4coder, or if the provided seek format is seek types are seek_pos and seek_line_char.
Description
Computes a Partial_Cursor for the given seek position with no side effects. The seek position must be one of the types supported by Partial_Cursor. Those types are absolute position and line,column position.

See Also
Buffer_Seek
Partial_Cursor

§3.3.14: buffer_batch_edit

bool32 app->buffer_batch_edit(
Application_Links *app,
Buffer_Summary *buffer,
char *str,
int32_t str_len,
Buffer_Edit *edits,
int32_t edit_count,
Buffer_Batch_Edit_Type type
)
Parameters
str
This parameter provides all of the source string for the edits in the batch.
str_len
This parameter specifies the length of the str string.
edits
This parameter provides about the source string and destination range of each edit as an array.
edit_count
This parameter specifies the number of Buffer_Edit structs in edits.
type
This prameter specifies what type of batch edit to execute.
Return
This call returns non-zero if the batch edit succeeds. This call can fail if the provided -buffer summary does not refer to an actual buffer in 4coder.
Description
TODO

See Also
Buffer_Edit
Buffer_Batch_Edit_Type

§3.3.15: buffer_set_setting

bool32 app->buffer_set_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting,
int32_t value
)
Parameters
buffer
The buffer parameter specifies the buffer on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
See Also
Buffer_Setting_ID

§3.3.16: buffer_token_count

int32_t app->buffer_token_count(
Application_Links *app,
Buffer_Summary *buffer
)
No documentation generated for this function.

§3.3.17: buffer_read_tokens

bool32 app->buffer_read_tokens(
Application_Links *app,
Buffer_Summary *buffer,
int32_t first_token,
int32_t last_token,
Cpp_Token *tokens_out
)
No documentation generated for this function.

§3.3.18: create_buffer

Buffer_Summary app->create_buffer(
Application_Links *app,
char *filename,
int32_t filename_len,
Buffer_Create_Flag flags
)
Parameters
filename
The filename parameter specifies the name of the file to be opened or created; it need not be null terminated.
filename_len
The filename_len parameter spcifies the length of the filename string.
flags
The flags parameter specifies behaviors for buffer creation.
Return
This call returns the summary of the created buffer.
Description
Tries to create a new buffer and associate it to the given filename. If such a buffer already -exists the existing buffer is returned in the Buffer_Summary and no new buffer is created. -If the buffer does not exist a new buffer is created and named after the given filename. If -the filename corresponds to a file on the disk that file is loaded and put into buffer, if -the filename does not correspond to a file on disk the buffer is created empty.

See Also
Buffer_Summary
Buffer_Create_Flag

§3.3.19: save_buffer

bool32 app->save_buffer(
Application_Links *app,
Buffer_Summary *buffer,
char *filename,
int32_t filename_len,
uint32_t flags
)
Parameters
buffer
The buffer parameter specifies the buffer to save to a file.
filename
The filename parameter specifies the name of the file to associated to the buffer; it need not be null terminated.
filename_len
The filename_len parameter specifies the length of the filename string.
flags
This parameter is not currently used and should be set to 0 for now.
Return
This call returns non-zero on success.

§3.3.20: kill_buffer

bool32 app->kill_buffer(
Application_Links *app,
Buffer_Identifier buffer,
View_ID view_id,
Buffer_Kill_Flag flags
)
Parameters
buffer
The buffer parameter specifies the buffer to try to kill.
view_id
The view_id parameter specifies the view that will contain the "are you sure" dialogue if the buffer is dirty.
flags
The flags parameter specifies behaviors for the buffer kill.
Return
This call returns non-zero if the buffer is killed.
Description
Tries to kill the idenfied buffer. If the buffer is dirty and the "are you sure" +buffer summary does not refer to an actual buffer in 4coder.
Description
TODO

See Also
Buffer_Edit
Buffer_Batch_Edit_Type

§3.3.15: buffer_set_setting

bool32 app->buffer_set_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting,
int32_t value
)
Parameters
buffer
The buffer parameter specifies the buffer on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
See Also
Buffer_Setting_ID

§3.3.16: buffer_token_count

int32_t app->buffer_token_count(
Application_Links *app,
Buffer_Summary *buffer
)
Parameters
buffer
Specifies the buffer from which to read the token count.
Return
If tokens are available for the buffer, the number of tokens on the buffer is returned. +If the buffer does not exist or if it is not a lexed buffer, the return is zero.

§3.3.17: buffer_read_tokens

bool32 app->buffer_read_tokens(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start_token,
int32_t end_token,
Cpp_Token *tokens_out
)
Parameters
buffer
Specifies the buffer from which to read tokens.
first_token
Specifies the index of the first token to read.
end_token
Specifies the token to stop reading at.
tokens_out
The memory that will store the tokens read from the buffer.
Return
Returns non-zero on success. This call can fail if the buffer doesn't +exist or doesn't have tokens ready, or if either the first or last index is out of bounds.
Description
Puts the data for the tokens with the indices [first_token,last_token


§3.3.18: create_buffer

Buffer_Summary app->create_buffer(
Application_Links *app,
char *filename,
int32_t filename_len,
Buffer_Create_Flag flags
)
Parameters
filename
The filename parameter specifies the name of the file to be opened or created; +it need not be null terminated.
filename_len
The filename_len parameter spcifies the length of the filename string.
flags
The flags parameter specifies behaviors for buffer creation.
Return
This call returns the summary of the created buffer.
Description
Tries to create a new buffer and associate it to the given filename. If such a buffer +already exists the existing buffer is returned in the Buffer_Summary and no new buffer is +created. If the buffer does not exist a new buffer is created and named after the given +filename. If the filename corresponds to a file on the disk that file is loaded and put into +buffer, if the filename does not correspond to a file on disk the buffer is created empty.

See Also
Buffer_Summary
Buffer_Create_Flag

§3.3.19: save_buffer

bool32 app->save_buffer(
Application_Links *app,
Buffer_Summary *buffer,
char *filename,
int32_t filename_len,
uint32_t flags
)
Parameters
buffer
The buffer parameter specifies the buffer to save to a file.
filename
The filename parameter specifies the name of the file to associated to the buffer; it need not be null terminated.
filename_len
The filename_len parameter specifies the length of the filename string.
flags
This parameter is not currently used and should be set to 0 for now.
Return
This call returns non-zero on success.

§3.3.20: kill_buffer

bool32 app->kill_buffer(
Application_Links *app,
Buffer_Identifier buffer,
View_ID view_id,
Buffer_Kill_Flag flags
)
Parameters
buffer
The buffer parameter specifies the buffer to try to kill.
view_id
The view_id parameter specifies the view that will contain the "are you sure" dialogue if the buffer is dirty.
flags
The flags parameter specifies behaviors for the buffer kill.
Return
This call returns non-zero if the buffer is killed.
Description
Tries to kill the idenfied buffer. If the buffer is dirty and the "are you sure" dialogue needs to be displayed the provided view is used to show the dialogue. If the view is not open the kill fails.

See Also
Buffer_Kill_Flag
Buffer_Identifier

§3.3.21: get_view_first

View_Summary app->get_view_first(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns the summary of the first view in a view loop.
Description
This call begins a loop across all the open views.

If the View_Summary returned is a null summary, the loop is finished. @@ -46,8 +49,8 @@ Views should not be closed or opened durring a view loop.

Description
4coder is built with a limit of 16 views. If 16 views are already open when this is called the call will fail.

See Also
View_Split_Position

§3.3.26: close_view

bool32 app->close_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to close.
Return
This call returns non-zero on success.
Description
If the given view is open and is not the last view, it will be closed. If the given view is the active view, the next active view in the global -order of view will be made active. -If the given view is the last open view in the system, the call will fail.


§3.3.27: set_active_view

bool32 app->set_active_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to make active.
Return
This call returns non-zero on success.
Description
If the given view is open, it is set as the +order of view will be made active. If the given view is the last open view +in the system, the call will fail.


§3.3.27: set_active_view

bool32 app->set_active_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to make active.
Return
This call returns non-zero on success.
Description
If the given view is open, it is set as the active view, and takes subsequent commands and is returned from get_active_view.

See Also
get_active_view

§3.3.28: view_set_setting

bool32 app->view_set_setting(
Application_Links *app,
View_Summary *view,
View_Setting_ID setting,
int32_t value
)
Parameters
view
The view parameter specifies the view on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
Return
This call returns non-zero on success.
See Also
View_Setting_ID

§3.3.29: view_set_split_proportion

bool32 app->view_set_split_proportion(
Application_Links *app,
View_Summary *view,
float t
)
Parameters
view
The view parameter specifies which view shall have it's size adjusted.
t
The t parameter specifies the proportion of the containing box that the view should occupy. t should be in [0,1].
Return
This call returns non-zero on success.

§3.3.30: view_compute_cursor

bool32 app->view_compute_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
Full_Cursor *cursor_out
)
Parameters
view
The view parameter specifies the view on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success.
Description
Computes a Full_Cursor for the given seek position with no side effects.

See Also
Buffer_Seek
Full_Cursor

§3.3.31: view_set_cursor

bool32 app->view_set_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
bool32 set_preferred_x
)
Parameters
view
The view parameter specifies the view in which to set the cursor.
seek
The seek parameter specifies the target position for the seek.
set_preferred_x
If this parameter is true the preferred x is updated to match the new cursor x.
Return
This call returns non-zero on success.
Description
This call sets the the view's cursor position. set_preferred_x should usually be true unless the change in cursor position is is a vertical motion that tries to keep the diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 96b386ce..2ff4be34 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -14,7 +14,7 @@ #define BUFFER_BATCH_EDIT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type) #define BUFFER_SET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value) #define BUFFER_TOKEN_COUNT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer) -#define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t first_token, int32_t last_token, Cpp_Token *tokens_out) +#define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out) #define CREATE_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags) #define SAVE_BUFFER_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *filename, int32_t filename_len, uint32_t flags) #define KILL_BUFFER_SIG(n) bool32 n(Application_Links *app, Buffer_Identifier buffer, View_ID view_id, Buffer_Kill_Flag flags) diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 5b5a14f8..95a4d5ab 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -550,35 +550,6 @@ DOC_SEE(Access_Flag) return(buffer); } -internal i32 -seek_token_left(Cpp_Token_Array *tokens, i32 pos){ - Cpp_Get_Token_Result get = cpp_get_token(tokens, pos); - if (get.token_index == -1){ - get.token_index = 0; - } - - Cpp_Token *token = tokens->tokens + get.token_index; - if (token->start == pos && get.token_index > 0){ - --token; - } - - return token->start; -} - -internal i32 -seek_token_right(Cpp_Token_Array *tokens, i32 pos){ - Cpp_Get_Token_Result get = cpp_get_token(tokens, pos); - if (get.in_whitespace){ - ++get.token_index; - } - if (get.token_index >= tokens->count){ - get.token_index = tokens->count-1; - } - - Cpp_Token *token = tokens->tokens + get.token_index; - return token->start + token->size; -} - API_EXPORT bool32 Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *out)/* DOC_PARAM(buffer, This parameter specifies the buffer to read.) @@ -826,7 +797,11 @@ DOC_SEE(Buffer_Setting_ID) } API_EXPORT int32_t -Buffer_Token_Count(Application_Links *app, Buffer_Summary *buffer){ +Buffer_Token_Count(Application_Links *app, Buffer_Summary *buffer)/* +DOC_PARAM(buffer, Specifies the buffer from which to read the token count.) +DOC_RETURN(If tokens are available for the buffer, the number of tokens on the buffer is returned. +If the buffer does not exist or if it is not a lexed buffer, the return is zero.) +*/{ Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file = imp_get_file(cmd, buffer); @@ -840,17 +815,26 @@ Buffer_Token_Count(Application_Links *app, Buffer_Summary *buffer){ } API_EXPORT bool32 -Buffer_Read_Tokens(Application_Links *app, Buffer_Summary *buffer, int32_t first_token, int32_t last_token, Cpp_Token *tokens_out){ +Buffer_Read_Tokens(Application_Links *app, Buffer_Summary *buffer, int32_t start_token, int32_t end_token, Cpp_Token *tokens_out)/* +DOC_PARAM(buffer, Specifies the buffer from which to read tokens.) +DOC_PARAM(first_token, Specifies the index of the first token to read.) +DOC_PARAM(end_token, Specifies the token to stop reading at.) +DOC_PARAM(tokens_out, The memory that will store the tokens read from the buffer.) +DOC_RETURN(Returns non-zero on success. This call can fail if the buffer doesn't +exist or doesn't have tokens ready, or if either the first or last index is out of bounds.) +DOC(Puts the data for the tokens with the indices [first_token,last_token) into the tokens_out array. +The number of output tokens will be end_token - start_token.) +*/{ Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file = imp_get_file(cmd, buffer); + Cpp_Token_Array token_array = file->state.token_array; bool32 result = 0; - - if (file && file->state.token_array.tokens && file->state.tokens_complete){ - result = 1; - - memcpy(tokens_out, file->state.token_array.tokens + first_token, - sizeof(Cpp_Token)*(last_token - first_token)); + if (file && token_array.tokens && file->state.tokens_complete){ + if (0 <= start_token && start_token <= end_token && end_token <= token_array.count){ + result = 1; + memcpy(tokens_out, token_array.tokens + start_token, sizeof(Cpp_Token)*(end_token - start_token)); + } } return(result); @@ -858,18 +842,18 @@ Buffer_Read_Tokens(Application_Links *app, Buffer_Summary *buffer, int32_t first API_EXPORT Buffer_Summary Create_Buffer(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags)/* -DOC_PARAM(filename, The filename parameter specifies the name of the file to be opened or created; it need not be null terminated.) +DOC_PARAM(filename, The filename parameter specifies the name of the file to be opened or created; +it need not be null terminated.) DOC_PARAM(filename_len, The filename_len parameter spcifies the length of the filename string.) DOC_PARAM(flags, The flags parameter specifies behaviors for buffer creation.) DOC_RETURN(This call returns the summary of the created buffer.) -DOC -( -Tries to create a new buffer and associate it to the given filename. If such a buffer already -exists the existing buffer is returned in the Buffer_Summary and no new buffer is created. -If the buffer does not exist a new buffer is created and named after the given filename. If -the filename corresponds to a file on the disk that file is loaded and put into buffer, if -the filename does not correspond to a file on disk the buffer is created empty. -) + +DOC(Tries to create a new buffer and associate it to the given filename. If such a buffer +already exists the existing buffer is returned in the Buffer_Summary and no new buffer is +created. If the buffer does not exist a new buffer is created and named after the given +filename. If the filename corresponds to a file on the disk that file is loaded and put into +buffer, if the filename does not correspond to a file on disk the buffer is created empty.) + DOC_SEE(Buffer_Summary) DOC_SEE(Buffer_Create_Flag) */{ @@ -1233,12 +1217,12 @@ API_EXPORT bool32 Close_View(Application_Links *app, View_Summary *view)/* DOC_PARAM(view, The view parameter specifies which view to close.) DOC_RETURN(This call returns non-zero on success.) -DOC( -If the given view is open and is not the last view, it will be closed. + +DOC(If the given view is open and is not the last view, it will be closed. If the given view is the active view, the next active view in the global -order of view will be made active. -If the given view is the last open view in the system, the call will fail. -) +order of view will be made active. If the given view is the last open view +in the system, the call will fail.) + */{ Command_Data *cmd = (Command_Data*)app->cmd_context; System_Functions *system = cmd->system; @@ -1312,8 +1296,11 @@ If the given view is the last open view in the system, the call will fail. active = (i32)(panel_ptr - models->layout.panels); } - Assert(active != -1 && panel != models->layout.panels + active); - models->layout.active_panel = active; + // If the panel we're closing was previously active, we have to switch to it's sibling. + if (models->layout.active_panel == (i32)(panel - models->layout.panels)){ + Assert(active != -1 && panel != models->layout.panels + active); + models->layout.active_panel = active; + } layout_free_divider(&models->layout, div.divider); layout_free_panel(&models->layout, panel); diff --git a/TODO.txt b/TODO.txt index 673ec61c..374cd31c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -83,10 +83,10 @@ ; BEFORE I SHIP ; ; [X] tokens in the custom API +; [X] token seeking on custom side ; [X] auto indent on the custom side ; [] clean up and comment the auto indent code to allow for customizations ; [] more built in options for auto indenting -; [] token seeking on custom side ; [] expose dirty flags ; [] option to not open *messages* every startup ; [] commands for resizing panels