Skip to content

Commit 4a697c9

Browse files
author
Allen Webster
committed
Clipboard now implemented as a custom layer feature; API transition mechanism established for deprecating old clipboard API without immediately breaking existing code for anyone
1 parent 4d4294f commit 4a697c9

22 files changed

+461
-450
lines changed

4ed.cpp

+3-12
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,6 @@ App_Init_Sig(app_init){
256256
global_history_init(&models->global_history);
257257
text_layout_init(tctx, &models->text_layouts);
258258

259-
// NOTE(allen): clipboard setup
260-
models->working_set.clipboard_max_size = ArrayCount(models->working_set.clipboards);
261-
models->working_set.clipboard_size = 0;
262-
models->working_set.clipboard_current = 0;
263-
264259
// NOTE(allen): style setup
265260
{
266261
Scratch_Block scratch(tctx);
@@ -328,7 +323,7 @@ App_Step_Sig(app_step){
328323
Models *models = (Models*)base_ptr;
329324

330325
Mutex_Lock file_order_lock(models->working_set.mutex);
331-
Scratch_Block scratch(tctx, Scratch_Share);
326+
Scratch_Block scratch(tctx);
332327

333328
models->next_animate_delay = max_u32;
334329
models->animate_next_frame = false;
@@ -339,11 +334,8 @@ App_Step_Sig(app_step){
339334
models->input = input;
340335

341336
// NOTE(allen): OS clipboard event handling
342-
String_Const_u8 clipboard = input->clipboard;
343-
if (clipboard.str != 0){
344-
String_Const_u8 *dest = working_set_next_clipboard_string(&models->heap, &models->working_set, clipboard.size);
345-
dest->size = eol_convert_in((char*)dest->str, (char*)clipboard.str, (i32)clipboard.size);
346-
co_send_core_event(tctx, models, CoreCode_NewClipboardContents, *dest);
337+
if (input->clipboard.str != 0){
338+
co_send_core_event(tctx, models, CoreCode_NewClipboardContents, input->clipboard);
347339
}
348340

349341
// NOTE(allen): reorganizing panels on screen
@@ -378,7 +370,6 @@ App_Step_Sig(app_step){
378370
system_cli_begin_update(cli);
379371
if (system_cli_update_step(cli, dest, max, &amount)){
380372
if (file != 0 && amount > 0){
381-
amount = eol_in_place_convert_in(dest, amount);
382373
output_file_append(tctx, models, file, SCu8(dest, amount));
383374
edited_file = true;
384375
}

4ed_api_implementation.cpp

+2-37
Original file line numberDiff line numberDiff line change
@@ -206,41 +206,6 @@ child_process_get_state(Application_Links *app, Child_Process_ID child_process_i
206206
return(child_process_get_state(&models->child_processes, child_process_id));
207207
}
208208

209-
api(custom) function b32
210-
clipboard_clear(Application_Links *app, i32 clipboard_id){
211-
Models *models = (Models*)app->cmd_context;
212-
working_set_clipboard_clear(&models->heap, &models->working_set);
213-
return(true);
214-
}
215-
216-
api(custom) function b32
217-
clipboard_post_internal_only(Application_Links *app, i32 clipboard_id, String_Const_u8 string)
218-
{
219-
Models *models = (Models*)app->cmd_context;
220-
String_Const_u8 *dest = working_set_next_clipboard_string(&models->heap, &models->working_set, (i32)string.size);
221-
block_copy(dest->str, string.str, string.size);
222-
return(true);
223-
}
224-
225-
api(custom) function i32
226-
clipboard_count(Application_Links *app, i32 clipboard_id)
227-
{
228-
Models *models = (Models*)app->cmd_context;
229-
return(models->working_set.clipboard_size);
230-
}
231-
232-
api(custom) function String_Const_u8
233-
push_clipboard_index(Application_Links *app, Arena *arena, i32 clipboard_id, i32 item_index)
234-
{
235-
Models *models = (Models*)app->cmd_context;
236-
String_Const_u8 *str = working_set_clipboard_index(&models->working_set, item_index);
237-
String_Const_u8 result = {};
238-
if (str != 0){
239-
result = push_string_copy(arena, *str);
240-
}
241-
return(result);
242-
}
243-
244209
api(custom) function b32
245210
enqueue_virtual_event(Application_Links *app, Input_Event *event){
246211
Models *models = (Models*)app->cmd_context;
@@ -2013,8 +1978,8 @@ managed_scope_get_attachment(Application_Links *app, Managed_Scope scope, Manage
20131978
}
20141979
else{
20151980
#define M \
2016-
"ERROR: scope attachment already exists with a size smaller than the requested size; no attachment pointer can be returned."
2017-
print_message(app, string_u8_litexpr(M));
1981+
"ERROR: scope attachment already exists with a size smaller than the requested size; no attachment pointer can be returned."
1982+
print_message(app, string_u8_litexpr(M));
20181983
#undef M
20191984
}
20201985
}

4ed_buffer.cpp

-90
Original file line numberDiff line numberDiff line change
@@ -172,96 +172,6 @@ buffer_update_cursors_lean_r(Cursor_With_Index *sorted_positions, i32 count,
172172

173173
//////////////////////////////////////
174174

175-
internal i32
176-
eol_convert_in(char *dest, char *src, i32 size){
177-
i32 i = 0;
178-
i32 j = 0;
179-
i32 k = 0;
180-
181-
for (; j < size && src[j] != '\r'; ++j);
182-
block_copy(dest, src, j);
183-
184-
if (j < size){
185-
k = 1;
186-
++j;
187-
for (i = j; i < size; ++i){
188-
if (src[i] == '\r'){
189-
block_copy(dest + j - k, src + j, i - j);
190-
++k;
191-
j = i+1;
192-
}
193-
}
194-
block_copy(dest + j - k, src + j, i - j);
195-
j = i - k;
196-
}
197-
198-
return(j);
199-
}
200-
201-
internal i32
202-
eol_in_place_convert_in(char *data, i32 size){
203-
i32 i = 0;
204-
i32 j = 0;
205-
i32 k = 0;
206-
207-
for (; j < size && data[j] != '\r'; ++j);
208-
209-
if (j < size){
210-
k = 1;
211-
++j;
212-
for (i = j; i < size; ++i){
213-
if (data[i] == '\r'){
214-
block_copy(data + j - k, data + j, i - j);
215-
++k;
216-
j = i+1;
217-
}
218-
}
219-
block_copy(data + j - k, data + j, i - j);
220-
j = i - k;
221-
}
222-
223-
return(j);
224-
}
225-
226-
// TODO(allen): iterative memory check?
227-
internal b32
228-
eol_convert_out(char *dest, i64 max, char *src, i64 size, i64 *size_out){
229-
i64 j = 0;
230-
for (i64 i = 0; i < size; ++i, ++j){
231-
if (src[i] == '\n'){
232-
dest[j] = '\r';
233-
++j;
234-
dest[j] = '\n';
235-
}
236-
else{
237-
dest[j] = src[i];
238-
}
239-
}
240-
*size_out = j;
241-
return(true);
242-
}
243-
244-
// TODO(allen): iterative memory check?
245-
internal i32
246-
eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){
247-
i32 result = 1;
248-
i32 i = 0;
249-
250-
for (; i < size; ++i){
251-
if (data[i] == '\n'){
252-
block_copy(data + i + 1, data + i, size - i);
253-
data[i] = '\r';
254-
++i;
255-
++size;
256-
}
257-
}
258-
259-
*size_out = size;
260-
return(result);
261-
}
262-
263-
//////////////////////////////////////
264-
265175
internal b32
266176
buffer_good(Gap_Buffer *buffer){
267177
return(buffer->data != 0);

4ed_system_api.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ define_api(Arena *arena){
120120
{
121121
API_Call *call = api_call(arena, api, "get_clipboard", "String_Const_u8");
122122
api_param(arena, call, "Arena*", "arena");
123+
api_param(arena, call, "i32", "index");
123124
}
124125
{
125126
API_Call *call = api_call(arena, api, "post_clipboard", "void");
126127
api_param(arena, call, "String_Const_u8", "str");
128+
api_param(arena, call, "i32", "index");
127129
}
128130

129131
{

4ed_working_set.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ get_file_from_identifier(Working_Set *working_set, Buffer_Identifier buffer){
206206

207207
////////////////////////////////
208208

209+
#if 0
209210
// TODO(allen): Bring the clipboard fully to the custom side.
210211
internal void
211212
working_set_clipboard_clear(Heap *heap, Working_Set *working){
@@ -257,6 +258,7 @@ working_set_clipboard_index(Working_Set *working, i32 index){
257258
}
258259
return(result);
259260
}
261+
#endif
260262

261263
////////////////////////////////
262264

4ed_working_set.h

-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ struct Working_Set{
3434
Node has_external_mod_sentinel;
3535
System_Mutex mutex;
3636
System_Thread file_change_thread;
37-
38-
// TODO(allen): do(update clipboard system to exist fully in the custom layer)
39-
// NOTE(allen): These members have nothing to do with the working set or
40-
// the mutex that gaurds the other members.
41-
String_Const_u8 clipboards[64];
42-
i32 clipboard_size;
43-
i32 clipboard_max_size;
44-
i32 clipboard_current;
4537
};
4638

4739
#endif

0 commit comments

Comments
 (0)