Lua: Fixed keyboard shortcuts to accomodate with full path names now used. Users who had shortcuts should clear them, from the list of shortcuts in Help screen.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1762 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2011-04-02 18:45:07 +00:00
parent 04761c79c4
commit e10fe19ae6
3 changed files with 32 additions and 21 deletions

View File

@ -43,6 +43,9 @@
#include "input.h" // Is_shortcut()
#include "help.h" // Window_help()
#include "graph.h"
#include "filesel.h" // Read_list_of_drives()
#include "realpath.h"
/// Lua scripts bound to shortcut keys.
char * Bound_script[10];
@ -1295,26 +1298,24 @@ void Draw_script_name(word x, word y, word index, byte highlighted)
///
/// Displays first lines of comments from a lua script in the window.
void Draw_script_information(T_Fileselector_item * script_item)
void Draw_script_information(T_Fileselector_item * script_item, const char *full_directory)
{
FILE *script_file;
char full_name[MAX_PATH_CHARACTERS];
char text_block[3][DESC_WIDTH+1];
int x, y;
int i;
// Blank the target area
Window_rectangle(7, FILESEL_Y + 89, DESC_WIDTH*6+2, 4*8, MC_Black);
if (script_item && script_item->Full_name && script_item->Full_name[0]!='\0')
{
strcpy(full_name, Data_directory);
strcat(full_name, "scripts/");
strcat(full_name, script_item->Full_name);
char full_name[MAX_PATH_CHARACTERS];
strcpy(full_name, full_directory);
Append_path(full_name, script_item->Full_name, NULL);
x=0;
y=0;
y=0;
text_block[0][0] = text_block[1][0] = text_block[2][0] = '\0';
// Start reading
script_file = fopen(full_name, "r");
@ -1360,7 +1361,7 @@ void Draw_script_information(T_Fileselector_item * script_item)
// Display a line with the keyboard shortcut
Print_help(8, FILESEL_Y + 89+24, "Key:", 'N', 0, 0);
for (i=0; i<10; i++)
if (Bound_script[i]!=NULL && !strcmp(Bound_script[i], script_item->Full_name))
if (Bound_script[i]!=NULL && !strcmp(Bound_script[i], full_name))
break;
if (i<10)
@ -1646,20 +1647,19 @@ void Repeat_script(void)
Run_script(NULL, Last_run_script);
}
void Set_script_shortcut(T_Fileselector_item * script_item)
void Set_script_shortcut(T_Fileselector_item * script_item, const char *full_directory)
{
int i;
char full_name[MAX_PATH_CHARACTERS];
if (script_item && script_item->Full_name && script_item->Full_name[0]!='\0')
{
strcpy(full_name, Data_directory);
strcat(full_name, "scripts/");
strcat(full_name, script_item->Full_name);
strcpy(full_name, full_directory);
Append_path(full_name, script_item->Full_name, NULL);
// Find if it already has a shortcut
for (i=0; i<10; i++)
if (Bound_script[i]!=NULL && !strcmp(Bound_script[i], script_item->Full_name))
if (Bound_script[i]!=NULL && !strcmp(Bound_script[i], full_name))
break;
if (i<10)
{
@ -1676,7 +1676,7 @@ void Set_script_shortcut(T_Fileselector_item * script_item)
if (i<10)
{
free(Bound_script[i]);
Bound_script[i]=strdup(script_item->Full_name);
Bound_script[i]=strdup(full_name);
}
else
{
@ -1693,7 +1693,7 @@ void Set_script_shortcut(T_Fileselector_item * script_item)
}
// Refresh display
Hide_cursor();
Draw_script_information(script_item);
Draw_script_information(script_item, full_directory);
Display_cursor();
}
}
@ -1760,7 +1760,7 @@ void Button_Brush_Factory(void)
Window_redraw_list(scriptlist);
Draw_script_information(Get_item_by_index(&Scripts_selector,
scriptlist->List_start + scriptlist->Cursor_position));
scriptlist->List_start + scriptlist->Cursor_position), sub_directory);
Update_window_area(0, 0, Window_width, Window_height);
Display_cursor();
@ -1802,13 +1802,13 @@ void Button_Brush_Factory(void)
last_selected_item = scriptlist->List_start + scriptlist->Cursor_position;
Hide_cursor();
Draw_script_information(Get_item_by_index(&Scripts_selector,
scriptlist->List_start + scriptlist->Cursor_position));
scriptlist->List_start + scriptlist->Cursor_position), sub_directory);
Display_cursor();
break;
case 6:
Set_script_shortcut(Get_item_by_index(&Scripts_selector,
scriptlist->List_start + scriptlist->Cursor_position));
scriptlist->List_start + scriptlist->Cursor_position), sub_directory);
break;
default:

View File

@ -46,6 +46,8 @@ void Recount_files(T_Fileselector *list);
T_Fileselector_item * Get_item_by_index(T_Fileselector *list, short index);
void Read_list_of_drives(T_Fileselector *list, byte name_length);
short Find_file_in_fileselector(T_Fileselector *list, const char * fname);
void Locate_list_item(T_List_button * list, T_Fileselector * selector, short selected_item);

View File

@ -99,12 +99,21 @@ void For_each_file(const char * directory_name, void Callback(const char *));
/// Scans a directory, calls Callback for each file or directory in it,
void For_each_directory_entry(const char * directory_name, void Callback(const char *, byte is_file, byte is_directory, byte is_hidden));
///
/// Creates a fully qualified name from a directory and filename.
/// The point is simply to insert a PATH_SEPARATOR when needed.
void Get_full_filename(char * output_name, char * file_name, char * directory_name);
///
/// Appends a file or directory name to an existing directory name.
/// As a special case, when the new item is equal to PARENT_DIR, this
/// will remove the rightmost directory name.
/// reverse_path is optional, if it's non-null, the function will
/// write there :
/// - if filename is ".." : The name of eliminated directory/file
/// - else: ".."
void Append_path(char *path, const char *filename, char *reverse_path);
///
/// Creates a lock file, to check if an other instance of Grafx2 is running.
/// @return 0 on success (first instance), -1 on failure (others are running)