diff options
| author | Aldrik Ramaekers <aldrik.ramaekers@protonmail.com> | 2020-02-04 09:40:59 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik.ramaekers@protonmail.com> | 2020-02-04 09:40:59 +0100 |
| commit | 9e43f84427b7a79bd56d56b46fbd341e1a161cfb (patch) | |
| tree | 56964eebf95613f4c36e8f2d6fce01fb04a71767 | |
| parent | 3f1aed9d71d10f5a7430b8720c6a1e93630b4477 (diff) | |
work
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | build-linux.sh | 64 | ||||
| -rw-r--r-- | build-win.bat | 22 | ||||
| -rw-r--r-- | data/config.txt | 10 | ||||
| -rw-r--r-- | data/fonts/mono.ttf | bin | 313408 -> 0 bytes | |||
| -rw-r--r-- | data/imgs/add.png | bin | 142 -> 0 bytes | |||
| -rw-r--r-- | data/imgs/delete.png | bin | 451 -> 0 bytes | |||
| -rw-r--r-- | data/imgs/en.png | bin | 1132 -> 0 bytes | |||
| -rw-r--r-- | data/imgs/exclaim.png | bin | 201 -> 0 bytes | |||
| -rw-r--r-- | data/imgs/list.png | bin | 140 -> 0 bytes | |||
| -rw-r--r-- | data/imgs/logo_64.png | bin | 399 -> 0 bytes | |||
| -rw-r--r-- | data/imgs/nl.png | bin | 509 -> 0 bytes | |||
| -rw-r--r-- | data/imgs/set.png | bin | 304 -> 0 bytes | |||
| -rw-r--r-- | data/marketing/logo_512.psd | bin | 187259 -> 0 bytes | |||
| -rw-r--r-- | data/translations/en-English.mo | bin | 1397 -> 0 bytes | |||
| -rw-r--r-- | data/translations/nl-Dutch.mo | bin | 1463 -> 0 bytes | |||
| -rw-r--r-- | install.sh | 87 | ||||
| -rw-r--r-- | misc/icon.rc | 28 | ||||
| -rw-r--r-- | misc/icon.res | bin | 102850 -> 0 bytes | |||
| -rw-r--r-- | misc/logo_512.ico | bin | 101503 -> 0 bytes | |||
| -rw-r--r-- | src/mo_edit.c | 860 | ||||
| -rw-r--r-- | src/save.c | 282 | ||||
| -rw-r--r-- | src/save.h | 17 | ||||
| -rw-r--r-- | src/test.txt | 1 | ||||
| -rw-r--r-- | src/ui.c | 7 | ||||
| -rw-r--r-- | src/ui.h | 11 |
26 files changed, 7 insertions, 1389 deletions
diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bde577f..0000000 --- a/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -bin/ -release/ -art/ -project.4coder -src/.gitignore -generate-graph.sh -download-translations.sh
\ No newline at end of file diff --git a/build-linux.sh b/build-linux.sh deleted file mode 100644 index 2a6d2c1..0000000 --- a/build-linux.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash - -if [ $(dpkg-query -W -f='${Status}' libglu1-mesa-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; -then - if [ "$EUID" -ne 0 ] - then - echo "Missing dependency: libglu1-mesa-dev, install this package or run this script as root" - else - apt-get install libglu1-mesa-dev; - fi -fi - -if [ $(dpkg-query -W -f='${Status}' libgl1-mesa-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; -then - if [ "$EUID" -ne 0 ] - then - echo "Missing dependency: libgl1-mesa-dev, install this package or run this script as root" - else - apt-get install libgl1-mesa-dev; - fi -fi - -if [ $(dpkg-query -W -f='${Status}' libxrandr-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; -then - if [ "$EUID" -ne 0 ] - then - echo "Missing dependency: libxrandr-dev, install this package or run this script as root" - else - apt-get install libxrandr-dev; - fi -fi - -rm -rf bin -mkdir bin -cd src - -ld -r -b binary -o ../bin/data.o \ -../data/imgs/en.png \ -../data/imgs/error.png \ -../data/imgs/folder.png \ -../data/imgs/nl.png \ -../data/imgs/search.png \ -../data/imgs/logo_64.png \ -../data/fonts/mono.ttf \ -../data/translations/en-English.mo \ -../data/translations/nl-Dutch.mo \ - -gcc -Wall -g -m64 -DMODE_DEVELOPER -Wno-unused-label -rdynamic -Wno-unused-variable text_search.c ../bin/data.o -o ../bin/text-search -lX11 -lGL -lGLU -lXrandr -lm -lpthread -ldl - -rm -f ../bin/data.o - -if [ $? -ne 0 ]; then - cd ../ - exit 1 -fi - -cd ../ - -if [ "$1" == "-r" ]; then - cd bin - ./text-search -# ./text-search --directory "/home/aldrik/Projects/text-search" --filter "*.c,*.h" --text "TODO(Aldrik)" --max-file-size 200 --locale "nl" --threads 5 - cd .. -fi diff --git a/build-win.bat b/build-win.bat deleted file mode 100644 index 934cccb..0000000 --- a/build-win.bat +++ /dev/null @@ -1,22 +0,0 @@ -@echo off - -windres misc/icon.rc -O coff -o misc/icon.res - -DEL /S /Q bin -cd src - -ld -r -b binary -o ../bin/data.o ../data/imgs/en.png ../data/imgs/nl.png ../data/imgs/logo_64.png ../data/fonts/mono.ttf ../data/translations/en-English.mo ../data/translations/nl-Dutch.mo ../data/imgs/list.png ../data/imgs/delete.png ../data/imgs/exclaim.png ../data/imgs/add.png ../data/imgs/set.png - -if "%1"=="-w" (SET defs=-DMODE_DEVELOPER -DMODE_GDBDEBUG) else (SET defs=-DMODE_DEVELOPER) - -x86_64-w64-mingw32-gcc -m64 -Wall -g %defs% -Wno-unused-label -Wno-unused-variable mo_edit.c ../bin/data.o -o ../bin/moedit.exe ../misc/icon.res -lopengl32 -lkernel32 -lglu32 -lgdi32 -lcomdlg32 -lgdiplus -lole32 -lshlwapi - -DEL /Q "../bin/data.o" - -FOR %%A IN ("../bin/moedit.exe") DO set size=%%~zA -echo size = %size% - -cd ../ - -if "%1"=="-r" start bin/moedit.exe -if "%1"=="-w" start gdb -ex run bin/moedit.exe
\ No newline at end of file diff --git a/data/config.txt b/data/config.txt deleted file mode 100644 index c0d0264..0000000 --- a/data/config.txt +++ /dev/null @@ -1,10 +0,0 @@ -SEARCH_DIRECTORY = "/opt/textsearch/" -SEARCH_DIRECTORIES = "1" -SEARCH_TEXT = "*hello world*" -FILE_FILTER = "*.txt,*.c" -MAX_THEAD_COUNT = "20" -MAX_FILE_SIZE = "200" -WINDOW_WIDTH = "800" -WINDOW_HEIGHT = "600" -PARALLELIZE_SEARCH = "1" -LOCALE = "en" diff --git a/data/fonts/mono.ttf b/data/fonts/mono.ttf Binary files differdeleted file mode 100644 index 1a39bc7..0000000 --- a/data/fonts/mono.ttf +++ /dev/null diff --git a/data/imgs/add.png b/data/imgs/add.png Binary files differdeleted file mode 100644 index 5539207..0000000 --- a/data/imgs/add.png +++ /dev/null diff --git a/data/imgs/delete.png b/data/imgs/delete.png Binary files differdeleted file mode 100644 index fa0ab77..0000000 --- a/data/imgs/delete.png +++ /dev/null diff --git a/data/imgs/en.png b/data/imgs/en.png Binary files differdeleted file mode 100644 index 02fa2a1..0000000 --- a/data/imgs/en.png +++ /dev/null diff --git a/data/imgs/exclaim.png b/data/imgs/exclaim.png Binary files differdeleted file mode 100644 index 40cc4b6..0000000 --- a/data/imgs/exclaim.png +++ /dev/null diff --git a/data/imgs/list.png b/data/imgs/list.png Binary files differdeleted file mode 100644 index 14c389d..0000000 --- a/data/imgs/list.png +++ /dev/null diff --git a/data/imgs/logo_64.png b/data/imgs/logo_64.png Binary files differdeleted file mode 100644 index 78916bf..0000000 --- a/data/imgs/logo_64.png +++ /dev/null diff --git a/data/imgs/nl.png b/data/imgs/nl.png Binary files differdeleted file mode 100644 index 505b9ce..0000000 --- a/data/imgs/nl.png +++ /dev/null diff --git a/data/imgs/set.png b/data/imgs/set.png Binary files differdeleted file mode 100644 index 003a3d7..0000000 --- a/data/imgs/set.png +++ /dev/null diff --git a/data/marketing/logo_512.psd b/data/marketing/logo_512.psd Binary files differdeleted file mode 100644 index 9c9c946..0000000 --- a/data/marketing/logo_512.psd +++ /dev/null diff --git a/data/translations/en-English.mo b/data/translations/en-English.mo Binary files differdeleted file mode 100644 index 2765a46..0000000 --- a/data/translations/en-English.mo +++ /dev/null diff --git a/data/translations/nl-Dutch.mo b/data/translations/nl-Dutch.mo Binary files differdeleted file mode 100644 index b56a807..0000000 --- a/data/translations/nl-Dutch.mo +++ /dev/null diff --git a/install.sh b/install.sh deleted file mode 100644 index d615539..0000000 --- a/install.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash - -######################################################################## -######################################################################## -if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then - -if [ "$EUID" -ne 0 ] - then echo "Please run this script as root." - exit -fi - -echo "Checking if dependencies are installed.." -if [ $(dpkg-query -W -f='${Status}' libglu1-mesa-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; -then - apt-get install libglu1-mesa-dev; -fi - - -if [ $(dpkg-query -W -f='${Status}' libgl1-mesa-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; -then - apt-get install libgl1-mesa-dev; -fi -echo "Dependencies are installed" - -echo "Compiling program.." -cd src - -ld -r -b binary -o ../bin/data.o \ -../data/imgs/en.png \ -../data/imgs/error.png \ -../data/imgs/folder.png \ -../data/imgs/nl.png \ -../data/imgs/search.png \ -../data/imgs/logo_64.png \ -../data/fonts/mono.ttf \ -../data/translations/en-English.mo \ -../data/translations/nl-Dutch.mo \ - -gcc -Wall -O3 -m64 -Wno-unused-label -Wno-unused-variable text_search.c ../bin/data.o -o ../bin/text-search -lX11 -lGL -lGLU -lXrandr -lm -lpthread -ldl - -rm -f ../bin/data.o - -echo "Done compiling program" - -cp --remove-destination ../bin/text-search /usr/local/bin/text-search - -cd ../ - -######################################################################## -######################################################################## -elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then - -windres misc/icon.rc -O coff -o misc/icon.res - -echo "Compiling program.." -cd src - -ld -r -b binary -o ../bin/data.o \ -../data/imgs/en.png \ -../data/imgs/error.png \ -../data/imgs/folder.png \ -../data/imgs/nl.png \ -../data/imgs/search.png \ -../data/imgs/logo_64.png \ -../data/fonts/mono.ttf \ -../data/translations/en-English.mo \ -../data/translations/nl-Dutch.mo \ - -x86_64-w64-mingw32-gcc -Wall -m64 -O3 -Wno-unused-label -Wno-unused-variable text_search.c ../bin/data.o -o ../bin/text-search.exe ../misc/icon.res -lopengl32 -lkernel32 -lglu32 -lgdi32 -lcomdlg32 -lgdiplus -lole32 -lshlwapi - -rm -f ../bin/data.o - -echo "Done compiling program, text-search.exe is located in 'C:\Manually installed'" - -cp --remove-destination "../bin/text-search.exe" "C:\Manually installed programs\text-search.exe" - -cd ../ - -######################################################################## -######################################################################## -elif [ "$(uname)" == "Darwin" ]; then - echo "OSX Platform not supported" -######################################################################## -######################################################################## -elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then - echo "32bit Windows versions not supported" -fi
\ No newline at end of file diff --git a/misc/icon.rc b/misc/icon.rc deleted file mode 100644 index 85b2f1d..0000000 --- a/misc/icon.rc +++ /dev/null @@ -1,28 +0,0 @@ -#include <windows.h> -#include <wingdi.h> -#include <winuser.h> - -RC_LOGO ICON "logo_512.ico" -1 VERSIONINFO -FILEVERSION 0,1,0,0 -PRODUCTVERSION 0,1,0,0 -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "080904E4" - BEGIN - VALUE "CompanyName", "Aldrik Ramaekers" - VALUE "FileDescription", "Text-search" - VALUE "FileVersion", "1.0" - VALUE "InternalName", "Text-search" - VALUE "LegalCopyright", "Aldrik Ramaekers" - VALUE "OriginalFilename", "Text-search.exe" - VALUE "ProductName", "Text-search" - VALUE "ProductVersion", "1.0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x809, 1252 - END -END diff --git a/misc/icon.res b/misc/icon.res Binary files differdeleted file mode 100644 index ef35332..0000000 --- a/misc/icon.res +++ /dev/null diff --git a/misc/logo_512.ico b/misc/logo_512.ico Binary files differdeleted file mode 100644 index c014524..0000000 --- a/misc/logo_512.ico +++ /dev/null diff --git a/src/mo_edit.c b/src/mo_edit.c deleted file mode 100644 index 134da15..0000000 --- a/src/mo_edit.c +++ /dev/null @@ -1,860 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -#include "config.h" -#include "project_base.h" - -// TODO(Aldrik): option to disable menu item -// TODO(Aldrik): move the delete button for term to edit panel on the topright and put a exclamation mark at the old spot to indicate a missing translation -// TODO(Aldrik): language name validation -// TODO(Aldrik): language mo file name preview when entering name -// TODO(Aldrik): option to mark languages with colors -// TODO(Aldrik): change save icon -// TODO(Aldrik): press tab to go to next translation textbox -// TODO(Aldrik): scissor on textbox in scroll -// TODO(Aldrik): delete file of language when deleting language -// TODO(Aldrik): confirmation on deletion of term and language -// TODO(Aldrik): creating a new term when term name textbox is selected doesnt overwrite new name -// TODO(Aldrik): deleting the term selected doesnt select a valid term -// TODO(Aldrik): reset textbox vertical scroll when new term is selected -// TODO(Aldrik): ctrl+x to select+delete selection -// TODO(Aldrik): ctrl+del to delete up to space char - -s32 global_language_id = 1; -char project_path[MAX_INPUT_LENGTH]; - -#define MAX_LANGUAGE_COUNT 100 - -typedef struct t_language -{ - char *name; - s32 id; -} language; - -typedef struct t_translation -{ - s32 language_id; - char *value; -} translation; - -typedef struct t_term -{ - char *name; - array translations; -} term; - -typedef struct t_translation_project -{ - array languages; - array terms; - int selected_term_index; -} translation_project; - -translation_project *current_project = 0; - -#include "save.h" -#include "save.c" - -scroll_state term_scroll; -scroll_state lang_scroll; -scroll_state trans_scroll; -button_state btn_new_project; -button_state btn_new_language; -button_state btn_summary; -button_state btn_set_term_name; -dropdown_state dd_available_countries; -textbox_state tb_filter; -textbox_state tb_new_term; -textbox_state tb_new_language; -textbox_state tb_translation_list[MAX_LANGUAGE_COUNT]; - -image *set_img; -image *add_img; -image *list_img; -image *exclaim_img; -image *delete_img; -image *logo_small_img; - -font *font_medium; -font *font_small; -font *font_mini; -s32 scroll_y = 0; - -#include "settings.h" -#include "settings.c" - -static void load_assets() -{ - list_img = assets_load_image(_binary____data_imgs_list_png_start, - _binary____data_imgs_list_png_end, false); - exclaim_img = assets_load_image(_binary____data_imgs_exclaim_png_start, - _binary____data_imgs_exclaim_png_end, false); - logo_small_img = assets_load_image(_binary____data_imgs_logo_64_png_start, - _binary____data_imgs_logo_64_png_end, true); - delete_img = assets_load_image(_binary____data_imgs_delete_png_start, - _binary____data_imgs_delete_png_end, false); - add_img = assets_load_image(_binary____data_imgs_add_png_start, - _binary____data_imgs_add_png_end, false); - set_img = assets_load_image(_binary____data_imgs_set_png_start, - _binary____data_imgs_set_png_end, false); - - font_medium = assets_load_font(_binary____data_fonts_mono_ttf_start, - _binary____data_fonts_mono_ttf_end, 18); - font_small = assets_load_font(_binary____data_fonts_mono_ttf_start, - _binary____data_fonts_mono_ttf_end, 15); - font_mini = assets_load_font(_binary____data_fonts_mono_ttf_start, - _binary____data_fonts_mono_ttf_end, 12); -} - -bool term_has_missing_translations(term *t) -{ - for (s32 i = 0; i < t->translations.length; i++) - { - translation *tr = array_at(&t->translations, i); - if (string_equals(tr->value, "")) return true; - } - - return false; -} - -s32 get_translated_count_for_language(s32 language_id) -{ - s32 count = 0; - for (s32 i = 0; i < current_project->terms.length; i++) - { - term *t = array_at(¤t_project->terms, i); - - for (s32 x = 0; x < t->translations.length; x++) - { - translation *tr = array_at(&t->translations, x); - - if (tr->language_id == language_id && !string_equals(tr->value, "")) - { - count++; - break; - } - } - } - - return count; -} - -bool term_name_is_available(char *name) -{ - for (s32 i = 0; i < current_project->terms.length; i++) - { - term *tr = array_at(¤t_project->terms, i); - - if (string_equals(tr->name, name)) - { - return false; - } - } - - return true; -} - -language* get_language_by_id(s32 language_id) -{ - for (s32 i = 0; i < current_project->languages.length; i++) - { - language *l = array_at(¤t_project->languages, i); - if (l->id == language_id) - { - return l; - } - } - return 0; -} - -s32 add_language_to_project(char *buffer) -{ - if (string_equals(buffer, "")) - { - // TODO(Aldrik): localize - platform_show_message(main_window, "Language name cannot be empty", "Invalid info"); - return -1; - } - - char *val = mem_alloc(MAX_INPUT_LENGTH); - string_copyn(val, buffer, MAX_INPUT_LENGTH); - - language l; - l.name = val; - l.id = global_language_id++; - - s32 index = array_push(¤t_project->languages, &l); - - for (s32 x = 0; x < current_project->terms.length; x++) - { - term *t = array_at(¤t_project->terms, x); - - translation new_t; - new_t.value = mem_alloc(MAX_INPUT_LENGTH); - string_copyn(new_t.value, "", MAX_INPUT_LENGTH); - new_t.language_id = l.id; - - array_push(&t->translations, &new_t); - } - - return l.id; -} - -void set_term_name(s32 index, char *name) -{ - if (strlen(name) > 0) - { - term *t = array_at(¤t_project->terms, index); - string_copyn(t->name, name, MAX_TERM_NAME_LENGTH); - } - else - { - platform_show_message(main_window, localize("term_name_cannot_be_empty"), localize("invalid_input")); - } -} - -void remove_term_from_project(s32 index) -{ - term *t = array_at(¤t_project->terms, index); - mem_free(t->name); - for (s32 i = 0; i < t->translations.length; i++) - { - translation *tr = array_at(&t->translations, i); - mem_free(tr->value); - } - array_destroy(&t->translations); - array_remove_at(¤t_project->terms, index); -} - -void remove_language_from_project(s32 language_id) -{ - for (s32 i = 0; i < current_project->languages.length; i++) - { - language *l = array_at(¤t_project->languages, i); - if (l->id == language_id) - { - array_remove_at(¤t_project->languages, i); - break; - } - } - - for (s32 x = 0; x < current_project->terms.length; x++) - { - term *tr = array_at(¤t_project->terms, x); - - for (s32 i = 0; i < tr->translations.length; i++) - { - translation *t = array_at(&tr->translations, i); - - if (t->language_id == language_id) - { - mem_free(t->value); - array_remove_at(&tr->translations, i); - break; - } - } - } -} - -void select_term(s32 index) -{ - current_project->selected_term_index = index; - term *t = array_at(¤t_project->terms, index); - ui_set_textbox_text(&tb_new_term, t->name); - - for (s32 i = 0; i < current_project->languages.length; i++) - { - translation *tr = array_at(&t->translations, i); - textbox_state *tb = &tb_translation_list[i]; - tb->state = false; - - if (tr->value) - { - ui_set_textbox_text(tb, tr->value); - } - else - { - ui_set_textbox_text(tb, ""); - } - } -} - -s32 add_term_to_project() -{ - tb_filter.state = 0; - ui_set_textbox_text(&tb_filter, ""); - - term t; - t.name = mem_alloc(MAX_TERM_NAME_LENGTH); - - s32 count = 0; - do - { - char buffer[MAX_TERM_NAME_LENGTH]; - sprintf(buffer, "term_%d", count); - string_copyn(t.name, buffer, MAX_TERM_NAME_LENGTH); - count++; - } - while(!term_name_is_available(t.name)); - - t.translations = array_create(sizeof(translation)); - array_reserve(&t.translations, current_project->languages.length); - - for (s32 i = 0; i < current_project->languages.length; i++) - { - language *l = array_at(¤t_project->languages, i); - - translation tr; - tr.value = mem_alloc(MAX_INPUT_LENGTH); - string_copyn(tr.value, "", MAX_INPUT_LENGTH); - tr.language_id = l->id; - array_push(&t.translations, &tr); - } - - return array_push(¤t_project->terms, &t); -} - -void save_term_changes() -{ - set_term_name(current_project->selected_term_index, tb_new_term.buffer); - - term *t = array_at(¤t_project->terms, current_project->selected_term_index); - - for (s32 i = 0; i < current_project->languages.length; i++) - { - translation *tr = array_at(&t->translations, i); - textbox_state *tb = &tb_translation_list[i]; - - string_copyn(tr->value, tb->buffer, MAX_INPUT_LENGTH); - } -} - -void start_new_project() -{ - global_language_id = 1; - current_project = mem_alloc(sizeof(translation_project)); - - current_project->terms = array_create(sizeof(term)); - array_reserve(¤t_project->terms, 100); - current_project->terms.reserve_jump = 100; - - current_project->languages = array_create(sizeof(language)); - array_reserve(¤t_project->languages, 100); - current_project->languages.reserve_jump = 100; - - current_project->selected_term_index = -1; -} - -void load_config(settings_config *config) -{ - char *path = settings_config_get_string(config, "ACTIVE_PROJECT"); - char *locale_id = settings_config_get_string(config, "LOCALE"); - - if (path) - { - string_copyn(project_path, path, MAX_INPUT_LENGTH); - - if (platform_directory_exists(project_path)) - { - load_project_from_folder(project_path); - } - else - { - string_copyn(project_path, "", MAX_INPUT_LENGTH); - } - } - - if (locale_id) - set_locale(locale_id); - else - set_locale("en"); -} - -#if defined(OS_LINUX) || defined(OS_WIN) -int main(int argc, char **argv) -{ - platform_init(argc, argv); - - bool is_command_line_run = (argc > 1); - if (is_command_line_run) - { - handle_command_line_arguments(argc, argv); - return 0; - } - - char config_path_buffer[PATH_MAX]; - get_config_save_location(config_path_buffer); - - // load config - settings_config config = settings_config_load_from_file(config_path_buffer); - - s32 window_w = settings_config_get_number(&config, "WINDOW_WIDTH"); - s32 window_h = settings_config_get_number(&config, "WINDOW_HEIGHT"); - if (window_w < 800 || window_h < 600) - { - window_w = 800; - window_h = 600; - } - - platform_window window = platform_open_window("mo-edit", window_w, window_h, 0, 0, 800, 600); - main_window = &window; - - settings_page_create(); - - load_available_localizations(); - set_locale("en"); - - load_assets(); - - keyboard_input keyboard = keyboard_input_create(); - mouse_input mouse = mouse_input_create(); - - camera camera; - camera.x = 0; - camera.y = 0; - camera.rotation = 0; - - ui_create(&window, &keyboard, &mouse, &camera, font_small); - term_scroll = ui_create_scroll(1); - lang_scroll = ui_create_scroll(1); - trans_scroll = ui_create_scroll(1); - btn_summary = ui_create_button(); - btn_set_term_name = ui_create_button(); - btn_new_project = ui_create_button(); - btn_new_language = ui_create_button(); - tb_filter = ui_create_textbox(MAX_INPUT_LENGTH); - tb_new_term = ui_create_textbox(MAX_TERM_NAME_LENGTH); - tb_new_language = ui_create_textbox(MAX_INPUT_LENGTH); - - for (s32 i = 0; i < MAX_LANGUAGE_COUNT; i++) - tb_translation_list[i] = ui_create_textbox(MAX_INPUT_LENGTH); - - // asset worker - thread asset_queue_worker1 = thread_start(assets_queue_worker, NULL); - thread asset_queue_worker2 = thread_start(assets_queue_worker, NULL); - thread_detach(&asset_queue_worker1); - thread_detach(&asset_queue_worker2); - - load_config(&config); - - while(window.is_open) { - u64 last_stamp = platform_get_time(TIME_FULL, TIME_US); - platform_handle_events(&window, &mouse, &keyboard); - platform_set_cursor(&window, CURSOR_DEFAULT); - - settings_page_update_render(); - - platform_window_make_current(&window); - - static bool icon_loaded = false; - if (!icon_loaded && logo_small_img->loaded) - { - icon_loaded = true; - platform_set_icon(&window, logo_small_img); - } - - if (global_asset_collection.queue.queue.length == 0 && !global_asset_collection.done_loading_assets) - { - global_asset_collection.done_loading_assets = true; - } - - global_ui_context.layout.active_window = &window; - global_ui_context.keyboard = &keyboard; - global_ui_context.mouse = &mouse; - - render_clear(); - camera_apply_transformations(&window, &camera); - - global_ui_context.layout.width = global_ui_context.layout.active_window->width; - // begin ui - - ui_begin(1); - { - render_rectangle(0, 0, main_window->width, main_window->height, global_ui_context.style.background); - - ui_begin_menu_bar(); - { - if (ui_push_menu(localize("file"))) - { - if (ui_push_menu_item(localize("load_project"), "Ctrl + O")) - { - load_project(); - } - if (ui_push_menu_item(localize("save_project"), "Ctrl + S")) - { - if (string_equals(project_path, "")) - save_project(); - else - save_project_to_folder(project_path); - } - if (ui_push_menu_item(localize("save_project_as"), "Ctrl + E")) - { - save_project(); - } - ui_push_menu_item_separator(); - if (ui_push_menu_item(localize("quit"), "Ctrl + Q")) - { - window.is_open = false; - } - } - } - ui_end_menu_bar(); - - - // TODO(Aldrik): make this a setting, resizable panel - global_ui_context.layout.width = 300; - ui_push_vertical_dragbar(); - - if (current_project) - { - ui_block_begin(LAYOUT_HORIZONTAL); - { - if (ui_push_button_image(&btn_summary, "", list_img)) - { - current_project->selected_term_index = -1; - } - - ui_push_textf_width(font_medium, localize("terms"), global_ui_context.layout.width-150); - - if (ui_push_button_image(&btn_summary, "", add_img)) - { - select_term(add_term_to_project()); - } - - //ui_push_button_image(&btn_summary, "", delete_img); - - } - ui_block_end(); - - ui_block_begin(LAYOUT_HORIZONTAL); - { - TEXTBOX_WIDTH = 280; - ui_push_textbox(&tb_filter, localize("filter_terms")); - } - ui_block_end(); - - ui_push_separator(); - - term_scroll.height = main_window->height-global_ui_context.layout.offset_y; - ui_scroll_begin(&term_scroll); - { - for (s32 i = 0; i < current_project->terms.length; i++) - { - term *t = array_at(¤t_project->terms, i); - - if (!strlen(tb_filter.buffer) || string_contains(t->name, tb_filter.buffer)) - { - bool removed = false; - if (ui_push_button_image(&btn_summary, "", delete_img)) - { - removed = true; - } - - //ui_push_image(exclaim_img, 14, 14, 1, rgb(255,255,255)); - - if (i == current_project->selected_term_index) - { - ui_push_rect(10, global_ui_context.style.textbox_active_border); - } - else if (term_has_missing_translations(t)) - { - ui_push_rect(10, MISSING_TRANSLATION_COLOR); - } - else - { - ui_push_rect(10, global_ui_context.style.background); - } - - if (ui_push_text_width(t->name, global_ui_context.layout.width-100, true)) - { - select_term(i); - } - - ui_block_end(); - - if (removed) - { - remove_term_from_project(i); - --i; - - if (current_project->selected_term_index >= 0) - current_project->selected_term_index--; - } - } - } - } - ui_scroll_end(); - } - else - { - if (ui_push_button(&btn_new_project, localize("create_new_project"))) - { - start_new_project(); - } - } - - global_ui_context.layout.width = main_window->width - 310; - - global_ui_context.layout.offset_x = 310; - global_ui_context.layout.offset_y = MENU_BAR_HEIGHT + WIDGET_PADDING; - - if (current_project && current_project->selected_term_index >= 0) - { - if (keyboard_is_key_down(&keyboard, KEY_LEFT_CONTROL) && keyboard_is_key_pressed(&keyboard, KEY_S)) - { - save_term_changes(); - } - - term *t = array_at(¤t_project->terms, - current_project->selected_term_index); - - ui_block_begin(LAYOUT_HORIZONTAL); - { - // editor - - if (string_equals(tb_new_term.buffer, t->name)) - ui_push_rect(10, global_ui_context.style.background); - else - ui_push_rect(10, UNSAVED_CHANGES_COLOR); - - ui_push_textbox(&tb_new_term, localize("term_name")); - - if (ui_push_button_image(&btn_set_term_name, "", set_img)) - { - save_term_changes(); - } - } - ui_block_end(); - - global_ui_context.layout.offset_x = 310; - ui_push_separator(); - - trans_scroll.height = main_window->height-global_ui_context.layout.offset_y; - - ui_scroll_begin(&trans_scroll); - { - if (!current_project->languages.length) - { - ui_push_text(localize("no_languages_added")); - } - else - { - for (s32 i = 0; i < t->translations.length; i++) - { - translation *tr = array_at(&t->translations, i); - - TEXTBOX_WIDTH = global_ui_context.layout.width - 130; - - if (!strlen(tb_translation_list[i].buffer)) - { - ui_push_rect(10, MISSING_TRANSLATION_COLOR); - } - else if (string_equals(tb_translation_list[i].buffer, - tr->value)) - { - ui_push_rect(10, global_ui_context.style.background); - } - else - { - ui_push_rect(10, UNSAVED_CHANGES_COLOR); - } - - ui_push_textbox(&tb_translation_list[i], ""); - - language *l = get_language_by_id(tr->language_id); - ui_push_text(l->name); - - global_ui_context.layout.offset_y += TEXTBOX_HEIGHT + WIDGET_PADDING; - global_ui_context.layout.offset_x = 310; - } - } - } - ui_scroll_end(); - } - else if (current_project) - { - // overview - ui_block_begin(LAYOUT_HORIZONTAL); - { - ui_push_textf_width(font_medium, localize("overview"), 100); - - char info_text[60]; - sprintf(info_text, localize("info_text"), current_project->terms.length, current_project->languages.length); - - color c = global_ui_context.style.foreground; - global_ui_context.style.foreground = rgb(110,110,110); - ui_push_textf(font_small, info_text); - global_ui_context.style.foreground = c; - } - ui_block_end(); - - ui_push_separator(); - - ui_block_begin(LAYOUT_HORIZONTAL); - { - bool selected = tb_new_language.state; - ui_push_textbox(&tb_new_language, localize("add_language")); - - if (keyboard_is_key_pressed(&keyboard, KEY_ENTER) && selected) - { - add_language_to_project(tb_new_language.buffer); - ui_set_textbox_text(&tb_new_language, ""); - keyboard_set_input_text(&keyboard, ""); - tb_new_language.state = true; - } - - if (ui_push_button(&btn_new_language, localize("add"))) - { - add_language_to_project(tb_new_language.buffer); - ui_set_textbox_text(&tb_new_language, ""); - keyboard_set_input_text(&keyboard, ""); - tb_new_language.state = true; - } - } - ui_block_end(); - - if (dd_available_countries.selected_index >= 0) - ui_push_separator(); - - // languages - lang_scroll.height = main_window->height-global_ui_context.layout.offset_y; - ui_scroll_begin(&lang_scroll); - { - for (s32 i = 0; i < current_project->languages.length; i++) - { - button_state btn_remove = ui_create_button(); - - bool pressed = false; - if (ui_push_button_image(&btn_remove, "", delete_img)) - { - pressed = true; - } - - language *l = array_at(¤t_project->languages, i); - ui_push_text_width(l->name, global_ui_context.layout.width-200, false); - - color c = global_ui_context.style.foreground; - global_ui_context.style.foreground = rgb(110,110,110); - - char stats[50]; - sprintf(stats, localize("translated_stats"), get_translated_count_for_language(l->id), current_project->terms.length); - ui_push_text(stats); - - global_ui_context.style.foreground = c; - - if (pressed) - { - remove_language_from_project(l->id); - i--; - } - - ui_block_end(); - } - } - ui_scroll_end(); - } - else - { - render_text(font_medium, 330, 50, localize("create_a_new_project"), global_ui_context.style.foreground); - render_text_cutoff(font_small, 330, 70, - localize("no_project_loaded_info"), global_ui_context.style.foreground, 400); - - render_rectangle(330, 200, 10, 25, UNSAVED_CHANGES_COLOR); - render_text(font_small, 350, 208, localize("unsaved_changes"), global_ui_context.style.foreground); - - render_rectangle(330, 240, 10, 25, MISSING_TRANSLATION_COLOR); - render_text(font_small, 350, 248, localize("missing_translation"), global_ui_context.style.foreground); - } - - if (keyboard_is_key_down(&keyboard, KEY_LEFT_CONTROL) && keyboard_is_key_pressed(&keyboard, KEY_O)) - { - load_project(); - } - if (keyboard_is_key_down(&keyboard, KEY_LEFT_CONTROL) && keyboard_is_key_pressed(&keyboard, KEY_S)) - { - if (string_equals(project_path, "")) - save_project(); - else - save_project_to_folder(project_path); - } - if (keyboard_is_key_down(&keyboard, KEY_LEFT_CONTROL) && keyboard_is_key_pressed(&keyboard, KEY_E)) - { - save_project(); - } - if (keyboard_is_key_down(&keyboard, KEY_LEFT_CONTROL) && keyboard_is_key_pressed(&keyboard, KEY_Q)) - { - window.is_open = false; - } - } - ui_end(); - // end ui - - assets_do_post_process(); - platform_window_swap_buffers(&window); - - u64 current_stamp = platform_get_time(TIME_FULL, TIME_US); - u64 diff = current_stamp - last_stamp; - float diff_ms = diff / 1000.0f; - last_stamp = current_stamp; - - if (diff_ms < TARGET_FRAMERATE) - { - double time_to_wait = (TARGET_FRAMERATE) - diff_ms; - thread_sleep(time_to_wait*1000); - } - } - - settings_page_hide_without_save(); - - // write config file - if (!string_equals(project_path, "")) - settings_config_set_string(&config, "ACTIVE_PROJECT", project_path); - - vec2 win_size = platform_get_window_size(&window); - settings_config_set_number(&config, "WINDOW_WIDTH", win_size.x); - settings_config_set_number(&config, "WINDOW_HEIGHT", win_size.y); - - if (global_localization.active_localization != 0) - { - char *current_locale_id = locale_get_id(); - if (current_locale_id) - { - settings_config_set_string(&config, "LOCALE", current_locale_id); - } - } - - settings_config_write_to_file(&config, config_path_buffer); - settings_config_destroy(&config); - - settings_page_destroy(); - - destroy_available_localizations(); - -#if 0 - // cleanup ui - ui_destroy_textbox(&textbox_path); - ui_destroy_textbox(&textbox_search_text); - ui_destroy_textbox(&textbox_file_filter); -#endif - ui_destroy(); - - // delete assets - assets_destroy_image(list_img); - assets_destroy_image(logo_small_img); - assets_destroy_image(delete_img); - assets_destroy_image(add_img); - - assets_destroy_font(font_small); - assets_destroy_font(font_mini); - - keyboard_input_destroy(&keyboard); - platform_destroy_window(&window); - - platform_destroy(); - - return 0; -} -#endif
\ No newline at end of file diff --git a/src/save.c b/src/save.c deleted file mode 100644 index ded92b4..0000000 --- a/src/save.c +++ /dev/null @@ -1,282 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -void start_new_project(); -s32 add_language_to_project(char *buffer); - -s32 write_mo_file(char *buffer, s32 buffer_size, s32 language_id) -{ - s32 identifier_table_size = current_project->terms.length * 8; - s32 translation_table_size = current_project->terms.length * 8; - - s32 size_written = 0; - - mo_header header; - header.magic_number = 0x950412de; - header.file_format_revision = 0; - header.number_of_strings = current_project->terms.length; - header.identifier_table_offset = 0x40; // keep empty bytes (0x2-0x4) for format changes - header.translation_table_offset = header.identifier_table_offset + identifier_table_size; - header.hashtable_size = 0; - header.hashtable_offset = header.translation_table_offset + translation_table_size; - - s32 current_data_write_offset = header.hashtable_offset+header.hashtable_size; - - // write identifier table and data - mo_entry *identifier_table = (mo_entry*)(buffer + header.identifier_table_offset); - for (s32 i = 0; i < current_project->terms.length; i++) - { - term *t = array_at(¤t_project->terms, i); - - mo_entry new_identifier_entry; - new_identifier_entry.length = strlen(t->name); - new_identifier_entry.offset = current_data_write_offset; - - memcpy(buffer+current_data_write_offset, t->name, new_identifier_entry.length); - current_data_write_offset += new_identifier_entry.length+1; - identifier_table[i] = new_identifier_entry; - } - - // write translation table and data - mo_entry *translation_table = (mo_entry*)(buffer + header.translation_table_offset); - for (s32 i = 0; i < current_project->terms.length; i++) - { - term *t = array_at(¤t_project->terms, i); - - mo_entry new_translation_entry; - - for (s32 x = 0; x < t->translations.length; x++) - { - translation *tr = array_at(&t->translations, x); - - if (tr->language_id == language_id) - { - new_translation_entry.length = strlen(tr->value); - new_translation_entry.offset = current_data_write_offset; - - memcpy(buffer+current_data_write_offset, tr->value, new_translation_entry.length); - current_data_write_offset += new_translation_entry.length+1; - break; - } - } - - translation_table[i] = new_translation_entry; - } - - size_written = current_data_write_offset; - - memcpy(buffer, &header, sizeof(mo_header)); - return size_written; -} - -void save_project_to_folder(char *path_buf) -{ - for (s32 i = 0; i < current_project->languages.length; i++) - { - language *lang = array_at(¤t_project->languages, i); - - s32 size = ((current_project->terms.length+1)*MAX_INPUT_LENGTH)*2; - - char *buffer = mem_alloc(size); - memset(buffer, 0, size); - - s32 size_written = write_mo_file(buffer, size, lang->id); - - char complete_path_buf[MAX_INPUT_LENGTH]; -#ifdef OS_WIN - sprintf(complete_path_buf, "%s\\%s.mo", path_buf, lang->name); -#endif -#ifdef OS_LINUX - sprintf(complete_path_buf, "%s/%s.mo", path_buf, lang->name); -#endif - - platform_write_file_content(complete_path_buf, "wb", buffer, size_written); - mem_free(buffer); - } -} - -static void *save_project_d(void *arg) -{ - char path_buf[MAX_INPUT_LENGTH]; - path_buf[0] = 0; - - char start_path[MAX_INPUT_LENGTH]; - snprintf(start_path, MAX_INPUT_LENGTH, "%s%s", binary_path, ""); - - char default_save_file_extension[50]; - string_copyn(default_save_file_extension, "", 50); - - struct open_dialog_args *args = mem_alloc(sizeof(struct open_dialog_args)); - args->buffer = path_buf; - args->type = OPEN_DIRECTORY; - args->file_filter = SAVE_FILE_EXTENSION; - args->start_path = start_path; - args->default_save_file_extension = default_save_file_extension; - - platform_open_file_dialog_block(args); - - char tmp_dir_buffer[MAX_INPUT_LENGTH]; - get_directory_from_path(tmp_dir_buffer, path_buf); - - char tmp_name_buffer[MAX_INPUT_LENGTH]; - get_name_from_path(tmp_name_buffer, path_buf); - - if (string_equals(path_buf, "")) return 0; - if (string_equals(tmp_name_buffer, "")) return 0; - if (!platform_directory_exists(tmp_dir_buffer)) return 0; - - string_copyn(project_path, path_buf, MAX_INPUT_LENGTH); - save_project_to_folder(path_buf); - return 0; -} - -void save_project() -{ - thread thr; - thr.valid = false; - - while (!thr.valid) - thr = thread_start(save_project_d, 0); - - thread_detach(&thr); -} - -bool read_mo_file(char *buffer, s32 buffer_size, s32 language_id) -{ - mo_header header = *((mo_header*)buffer); - - mo_entry *identifiers = (mo_entry*)(buffer + header.identifier_table_offset); - mo_entry *translations = (mo_entry*)(buffer + header.translation_table_offset); - - if (current_project->terms.length == 0) - { - for (s32 i = 0; i < header.number_of_strings; i++) - { - term t; - t.name = mem_alloc(MAX_TERM_NAME_LENGTH); - t.translations = array_create(sizeof(translation)); - array_reserve(&t.translations, current_project->languages.length); - - string_copyn(t.name, buffer+identifiers[i].offset, MAX_INPUT_LENGTH); - array_push(¤t_project->terms, &t); - } - } - else if (current_project->terms.length != header.number_of_strings) - { - platform_show_message(main_window, localize("warning"), localize("file_is_missing_terms")); - } - - for (s32 i = 0; i < current_project->terms.length; i++) - { - term *t = array_at(¤t_project->terms, i); - - translation tr; - tr.value = mem_alloc(MAX_INPUT_LENGTH); - string_copyn(tr.value, buffer+translations[i].offset, MAX_INPUT_LENGTH); - tr.language_id = language_id; - array_push(&t->translations, &tr); - } - - return true; -} - - -void load_project_from_folder(char *path_buf) -{ - if (!platform_directory_exists(path_buf)) - { - platform_show_message(main_window, localize("error_loading_project"), localize("project_directory_does_not_exist")); - return; - } - - start_new_project(); - - array files = array_create(sizeof(found_file)); - array filters = get_filters("*.mo"); - - bool is_cancelled = false; - - char total_path[MAX_INPUT_LENGTH]; - total_path[0] = 0; - string_copyn(total_path, path_buf, MAX_INPUT_LENGTH); - -#ifdef OS_WIN - string_appendn(total_path, "\\", MAX_INPUT_LENGTH); -#endif -#ifdef OS_LINUX - string_appendn(total_path, "/", MAX_INPUT_LENGTH); -#endif - - platform_list_files_block(&files, total_path, filters, false, 0, false, &is_cancelled); - for (s32 i = 0; i < files.length; i++) - { - found_file *file = array_at(&files, i); - - file_content content = platform_read_file_content(file->path, "rb"); - if (content.content && !content.file_error) - { - char name[MAX_INPUT_LENGTH]; - get_name_from_path(name, file->path); - name[strlen(name)-3] = 0; // remove .mo extension - - language l; - l.name = mem_alloc(MAX_INPUT_LENGTH); - string_copyn(l.name, name, MAX_INPUT_LENGTH); - l.id = global_language_id++; - array_push(¤t_project->languages, &l); - - read_mo_file(content.content, content.content_length, l.id); - } - platform_destroy_file_content(&content); - } - array_destroy(&filters); - - for (s32 i = 0; i < files.length; i++) - { - found_file *match = array_at(&files, i); - mem_free(match->matched_filter); - mem_free(match->path); - } - array_destroy(&files); -} - -static void* load_project_d(void *arg) -{ - char path_buf[MAX_INPUT_LENGTH]; - path_buf[0] = 0; - - char start_path[MAX_INPUT_LENGTH]; - snprintf(start_path, MAX_INPUT_LENGTH, "%s%s", binary_path, ""); - - char default_save_file_extension[50]; - string_copyn(default_save_file_extension, "", 50); - - struct open_dialog_args *args = mem_alloc(sizeof(struct open_dialog_args)); - args->buffer = path_buf; - args->type = OPEN_DIRECTORY; - args->file_filter = SAVE_FILE_EXTENSION; - args->start_path = start_path; - args->default_save_file_extension = default_save_file_extension; - - platform_open_file_dialog_block(args); - - if (string_equals(path_buf, "")) return 0; - if (!platform_file_exists(path_buf)) return 0; - - string_copyn(project_path, path_buf, MAX_INPUT_LENGTH); - load_project_from_folder(path_buf); - return 0; -} - -void load_project() -{ - thread thr; - thr.valid = false; - - while (!thr.valid) - thr = thread_start(load_project_d, 0); - thread_detach(&thr); -}
\ No newline at end of file diff --git a/src/save.h b/src/save.h deleted file mode 100644 index afcfea5..0000000 --- a/src/save.h +++ /dev/null @@ -1,17 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -#ifndef INCLUDE_SAVE -#define INCLUDE_SAVE - -#define SAVE_FILE_EXTENSION "*.json" - -void load_project_from_folder(char *path_buf); -void load_project(); -void save_project_to_folder(char *path_buf); -void save_project(); - -#endif
\ No newline at end of file diff --git a/src/test.txt b/src/test.txt deleted file mode 100644 index 4d6a3b4..0000000 --- a/src/test.txt +++ /dev/null @@ -1 +0,0 @@ -ECHO is on. @@ -88,6 +88,11 @@ inline scroll_state ui_create_scroll(s32 scroll) void ui_set_textbox_text(textbox_state *textbox, char *text) { + if (global_ui_context.current_active_textbox == textbox) + { + keyboard_set_input_text(global_ui_context.keyboard, text); + } + string_copyn(textbox->buffer, text, textbox->max_len); } @@ -522,7 +527,7 @@ static void ui_set_active_textbox(textbox_state *state) global_ui_context.current_active_textbox = state; } -void set_active_textbox(textbox_state *textbox) +void ui_set_textbox_active(textbox_state *textbox) { ui_set_active_textbox(textbox); keyboard_set_input_text(global_ui_context.keyboard, textbox->buffer); @@ -145,16 +145,6 @@ typedef struct t_ui_context bool item_hovered; } ui_context; -///// our global ui states //// -checkbox_state checkbox_recursive; -textbox_state textbox_search_text; -textbox_state textbox_path; -textbox_state textbox_file_filter; -button_state button_select_directory; -button_state button_find_text; -button_state button_cancel; -/////////////////////////////// - ui_context global_ui_context; u32 ui_get_id(); @@ -169,6 +159,7 @@ char* name_of_month(s32 month); void ui_set_style(u16 style); void set_active_textbox(textbox_state *textbox); void ui_set_textbox_text(textbox_state *textbox, char *text); +void ui_set_textbox_active(textbox_state *textbox); // widget initialization checkbox_state ui_create_checkbox(bool selected); |
