Move File/Dir Creation to edi_file.c/h

Summary: Also add options to menus

Reviewers: ajwillia.ms

Reviewed By: ajwillia.ms

Tags: #edi

Differential Revision: https://phab.enlightenment.org/D4750
This commit is contained in:
Al Poole 2017-03-27 22:03:11 +01:00 committed by Andy Williams
parent 6cf426e24a
commit 95f43adaec
5 changed files with 309 additions and 68 deletions

View File

@ -27,6 +27,7 @@ editor/edi_editor.h \
edi_content_provider.h \
screens/edi_screens.h \
edi_filepanel.h \
edi_file.h \
edi_logpanel.h \
edi_consolepanel.h \
mainview/edi_mainview_item.h \
@ -44,6 +45,7 @@ screens/edi_about.c \
screens/edi_settings_font.c \
screens/edi_settings.c \
edi_filepanel.c \
edi_file.c \
edi_logpanel.c \
edi_consolepanel.c \
mainview/edi_mainview_item.c \

191
src/bin/edi_file.c Normal file
View File

@ -0,0 +1,191 @@
#include "Edi.h"
#include "mainview/edi_mainview.h"
#include "edi_file.h"
#include "edi_private.h"
static Evas_Object *_parent_obj, *_popup, *_popup_dir, *_edi_file_message_popup;
static const char *_directory_path;
static void
_edi_file_message_close_cb(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *popup = data;
evas_object_del(popup);
}
static void
_edi_file_message_open(const char *message)
{
Evas_Object *popup, *button;
_edi_file_message_popup = popup = elm_popup_add(_parent_obj);
elm_object_part_text_set(popup, "title,text",
message);
button = elm_button_add(popup);
elm_object_text_set(button, "Ok");
elm_object_part_content_set(popup, "button1", button);
evas_object_smart_callback_add(button, "clicked",
_edi_file_message_close_cb, popup);
evas_object_show(popup);
}
static void
_edi_file_popup_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
evas_object_del((Evas_Object *)data);
eina_stringshare_del(_directory_path);
_directory_path = NULL;
}
static void
_edi_file_create_file_cb(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
const char *name;
char *path;
const char *directory = _directory_path;
FILE *f;
if (!ecore_file_is_dir(directory))
return;
name = elm_entry_entry_get((Evas_Object *) data);
if (!name || strlen(name) == 0)
{
_edi_file_message_open("Please enter a file name.");
return;
}
path = edi_path_append(directory, name);
if ((ecore_file_exists(path) && ecore_file_is_dir(path)) ||
!ecore_file_exists(path))
{
f = fopen(path, "w");
if (f)
{
fclose(f);
edi_mainview_open_path(path);
}
else
_edi_file_message_open("Unable to write file.");
}
eina_stringshare_del(_directory_path);
_directory_path = NULL;
evas_object_del(_popup);
free(path);
}
static void
_edi_file_create_dir_cb(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
const char *name;
char *path;
const char *directory = _directory_path;
if (!ecore_file_is_dir(directory)) return;
name = elm_entry_entry_get((Evas_Object *) data);
if (!name || strlen(name) == 0)
{
_edi_file_message_open("Please enter a directory name.");
return;
}
path = edi_path_append(directory, name);
mkdir(path, 0755);
eina_stringshare_del(_directory_path);
_directory_path = NULL;
evas_object_del(_popup_dir);
free(path);
}
void
edi_file_create_file(Evas_Object *parent, const char *directory)
{
Evas_Object *popup, *box, *input, *button;
_parent_obj = parent;
_popup = popup = elm_popup_add(parent);
elm_object_part_text_set(popup, "title,text",
"Enter new file name");
_directory_path = eina_stringshare_add(directory);
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
elm_object_content_set(popup, box);
input = elm_entry_add(box);
elm_entry_single_line_set(input, EINA_TRUE);
evas_object_size_hint_weight_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(input);
elm_box_pack_end(box, input);
button = elm_button_add(popup);
elm_object_text_set(button, "cancel");
elm_object_part_content_set(popup, "button1", button);
evas_object_smart_callback_add(button, "clicked",
_edi_file_popup_cancel_cb, popup);
button = elm_button_add(popup);
elm_object_text_set(button, "create");
elm_object_part_content_set(popup, "button2", button);
evas_object_smart_callback_add(button, "clicked",
_edi_file_create_file_cb, input);
evas_object_show(popup);
elm_object_focus_set(input, EINA_TRUE);
}
void
edi_file_create_dir(Evas_Object *parent, const char *directory)
{
Evas_Object *popup, *box, *input, *button;
_parent_obj = parent;
_directory_path = eina_stringshare_add(directory);
_popup_dir = popup = elm_popup_add(parent);
elm_object_part_text_set(popup, "title,text",
"Enter new directory name");
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
elm_object_content_set(popup, box);
input = elm_entry_add(box);
elm_entry_single_line_set(input, EINA_TRUE);
evas_object_size_hint_weight_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(input);
elm_box_pack_end(box, input);
button = elm_button_add(popup);
elm_object_text_set(button, "cancel");
elm_object_part_content_set(popup, "button1", button);
evas_object_smart_callback_add(button, "clicked",
_edi_file_popup_cancel_cb, popup);
button = elm_button_add(popup);
elm_object_text_set(button, "create");
elm_object_part_content_set(popup, "button2", button);
evas_object_smart_callback_add(button, "clicked",
_edi_file_create_dir_cb, input);
evas_object_show(popup);
elm_object_focus_set(input, EINA_TRUE);
}

55
src/bin/edi_file.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef __EDI_FILE_H__
#define __EDI_FILE_H__
#include <Elementary.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file
* @brief These routines used for managing Edi file actions.
*/
/**
* @brief UI management functions.
* @defgroup UI
*
* @{
*
* Management of file/dir creation with the UI
*
*/
/**
* Create a file add dialogue and add it to the parent obj.
*
* @param parent The object into which the UI will load.
* @param directory The directory root of which file is created.
* @ingroup UI
*/
void edi_file_create_file(Evas_Object *parent, const char *directory);
/**
* Create a directory add dialogue and add it to the parent obj.
*
* @param parent The object into which the UI will load.
* @param directory The directory root of which directory is created.
* @ingroup UI
*/
void edi_file_create_dir(Evas_Object *parent, const char *directory);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@ -13,6 +13,7 @@
#include "Edi.h"
#include "edi_filepanel.h"
#include "edi_file.h"
#include "edi_content_provider.h"
#include "mainview/edi_mainview.h"
@ -203,12 +204,41 @@ _item_menu_rmdir_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
ecore_file_recursive_rm(path);
}
static void
_item_menu_create_file_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
const char *directory = _menu_cb_path;
if (!ecore_file_is_dir(directory))
return;
edi_file_create_file(win, directory);
}
static void
_item_menu_create_dir_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
const char *directory = _menu_cb_path;
if (!ecore_file_is_dir(directory))
return;
edi_file_create_dir(win, directory);
}
static void
_item_menu_dir_create(Evas_Object *win)
{
menu = elm_menu_add(win);
evas_object_smart_callback_add(menu, "dismissed", _item_menu_dismissed_cb, NULL);
elm_menu_item_add(menu, NULL, "document-new", "create file here", _item_menu_create_file_cb, win);
elm_menu_item_add(menu, NULL, "folder-new", "create directory here", _item_menu_create_dir_cb, win);
if (ecore_file_app_installed("terminology"))
elm_menu_item_add(menu, NULL, "terminal", "open terminal here", _item_menu_open_terminal_cb, NULL);
if (ecore_file_dir_is_empty(_menu_cb_path))

View File

@ -17,6 +17,7 @@
#include "Edi.h"
#include "edi_config.h"
#include "edi_filepanel.h"
#include "edi_file.h"
#include "edi_logpanel.h"
#include "edi_consolepanel.h"
#include "mainview/edi_mainview.h"
@ -41,7 +42,7 @@ static Elm_Object_Item *_edi_logpanel_item, *_edi_consolepanel_item, *_edi_testp
static Elm_Object_Item *_edi_selected_bottompanel;
static Evas_Object *_edi_filepanel, *_edi_filepanel_icon;
static Evas_Object *_edi_main_win, *_edi_main_box, *_edi_new_popup, *_edi_message_popup;
static Evas_Object *_edi_main_win, *_edi_main_box, *_edi_message_popup;
int _edi_log_dom = -1;
static void
@ -487,80 +488,19 @@ _edi_launcher_run(Edi_Project_Config_Launch *launch)
}
static void
_tb_new_create_cb(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
_tb_new_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
const char *selected, *name;
char *path;
FILE *fileid;
name = elm_entry_entry_get((Evas_Object *) data);
if (!name || strlen(name) == 0)
{
_edi_message_open("Please enter a file name.");
return;
}
const char *path, *selected;
selected = edi_filepanel_selected_path_get(_edi_filepanel);
if (selected && ecore_file_is_dir(selected))
path = edi_path_append(selected, name);
path = selected;
else
path = edi_project_file_path_get(name);
path = edi_project_get();
fileid = fopen(path, "w");
if (!fileid)
_edi_message_open("Unable to write file.");
else
edi_mainview_open_path(path);
evas_object_del(_edi_new_popup);
free((char*)path);
}
static void
_edi_file_new()
{
Evas_Object *popup, *box, *input, *button;
popup = elm_popup_add(_edi_main_win);
_edi_new_popup = popup;
elm_object_part_text_set(popup, "title,text",
"Enter new file name");
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
elm_object_content_set(popup, box);
input = elm_entry_add(box);
elm_entry_single_line_set(input, EINA_TRUE);
evas_object_size_hint_weight_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(input);
elm_box_pack_end(box, input);
button = elm_button_add(popup);
elm_object_text_set(button, "cancel");
elm_object_part_content_set(popup, "button1", button);
evas_object_smart_callback_add(button, "clicked",
_edi_popup_cancel_cb, _edi_new_popup);
button = elm_button_add(popup);
elm_object_text_set(button, "create");
elm_object_part_content_set(popup, "button2", button);
evas_object_smart_callback_add(button, "clicked",
_tb_new_create_cb, input);
evas_object_show(popup);
elm_object_focus_set(input, EINA_TRUE);
}
static void
_tb_new_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
elm_toolbar_item_selected_set(elm_toolbar_selected_item_get(obj), EINA_FALSE);
_edi_file_new();
edi_file_create_file(_edi_main_win, path);
}
static void
@ -691,7 +631,29 @@ static void
_edi_menu_new_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
_edi_file_new();
const char *path, *selected;
selected = edi_filepanel_selected_path_get(_edi_filepanel);
if (selected && ecore_file_is_dir(selected))
path = selected;
else
path = edi_project_get();
edi_file_create_file(_edi_main_win, path);
}
static void
_edi_menu_new_dir_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
const char *path, *selected;
selected = edi_filepanel_selected_path_get(_edi_filepanel);
if (selected && ecore_file_is_dir(selected))
path =selected;
else
path = edi_project_get();
edi_file_create_dir(_edi_main_win, path);
}
static void
@ -839,6 +801,7 @@ _edi_menu_setup(Evas_Object *win)
elm_menu_item_add(menu, menu_it, "folder-new", "New Project ...", _edi_menu_project_new_cb, NULL);
elm_menu_item_separator_add(menu, menu_it);
elm_menu_item_add(menu, menu_it, "document-new", "New ...", _edi_menu_new_cb, NULL);
elm_menu_item_add(menu, menu_it, "folder-new", "New Directory ...", _edi_menu_new_dir_cb, NULL);
elm_menu_item_add(menu, menu_it, "document-save", "Save", _edi_menu_save_cb, NULL);
elm_menu_item_add(menu, menu_it, "window-new", "New window", _edi_menu_open_window_cb, NULL);
elm_menu_item_add(menu, menu_it, "document-close", "Close", _edi_menu_close_cb, NULL);