diff options
Diffstat (limited to 'src/mo_edit.c')
| -rw-r--r-- | src/mo_edit.c | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/src/mo_edit.c b/src/mo_edit.c index c54dae7..0c51705 100644 --- a/src/mo_edit.c +++ b/src/mo_edit.c @@ -7,8 +7,6 @@ #include "config.h"
#include "project_base.h"
-// TODO(Aldrik): delete file of language when deleting language
-
s32 global_language_id = 1;
char project_path[MAX_INPUT_LENGTH];
@@ -39,6 +37,7 @@ typedef struct t_translation_project translation_project *current_project = 0;
array tb_translation_list;
+array recent_projects_list;
#include "save.h"
#include "save.c"
@@ -57,6 +56,7 @@ dropdown_state dd_available_countries; textbox_state tb_filter;
textbox_state tb_new_term;
textbox_state tb_new_language;
+submenu_state submenu_recent_projects;
image *set_img;
image *add_img;
@@ -394,6 +394,45 @@ void load_config(settings_config *config) set_locale("en");
}
+void calculate_recent_project_path_max_len()
+{
+ submenu_recent_projects.w = 0;
+ for (s32 i = 0; i < recent_projects_list.length; i++)
+ {
+ char *rp = array_at(&recent_projects_list, i);
+
+ s32 tw = calculate_text_width(global_ui_context.font_small, rp) + (WIDGET_PADDING*2);
+
+ if (tw > submenu_recent_projects.w)
+ submenu_recent_projects.w = tw;
+ }
+
+ if (submenu_recent_projects.w == 0) submenu_recent_projects.w = MENU_ITEM_WIDTH;
+}
+
+void add_recent_project_path(char *path)
+{
+ for (s32 i = 0; i < recent_projects_list.length; i++)
+ {
+ char *rp = array_at(&recent_projects_list, i);
+
+ if (string_equals(path, rp))
+ {
+ return;
+ }
+ }
+
+ array_push(&recent_projects_list, path);
+
+ // max 5 recent projects
+ if (recent_projects_list.length >= 6)
+ {
+ array_remove_at(&recent_projects_list, 0);
+ }
+
+ calculate_recent_project_path_max_len();
+}
+
#if defined(OS_LINUX) || defined(OS_WIN)
int main(int argc, char **argv)
{
@@ -444,6 +483,8 @@ int main(int argc, char **argv) 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);
+ submenu_recent_projects = ui_create_submenu();
+ recent_projects_list = array_create(MAX_INPUT_LENGTH);
// asset worker
thread asset_queue_worker1 = thread_start(assets_queue_worker, NULL);
@@ -524,8 +565,28 @@ int main(int argc, char **argv) platform_show_message(main_window, localize("no_project_to_save"), localize("error_saving_project"));
}
}
+ // TODO(Aldrik): localize
+ calculate_recent_project_path_max_len();
+ ui_begin_menu_submenu(&submenu_recent_projects, "Recent projects");
+ {
+ for (s32 i = recent_projects_list.length-1; i >= 0; i--)
+ {
+ char *rp = array_at(&recent_projects_list, i);
+ if (ui_push_menu_item(rp, ""))
+ {
+ load_project_from_folder(rp);
+ }
+ }
+
+ }
+ ui_end_menu_submenu();
if (ui_push_menu_item(localize("close_project"), ""))
{
+ if (!string_equals(project_path, ""))
+ {
+ add_recent_project_path(project_path);
+ }
+
current_project = 0;
project_path[0] = 0;
}
|
