Launching code editor from recipe dialog now working. Removed a mess of redundant path code.
This commit is contained in:
parent
870d2822e0
commit
5dead7d66c
6 changed files with 86 additions and 67 deletions
|
@ -52,7 +52,8 @@ typedef struct WindowDataS {
|
||||||
gboolean (*closeWindow)(GtkWidget* widget, gpointer data);
|
gboolean (*closeWindow)(GtkWidget* widget, gpointer data);
|
||||||
gboolean isDirty;
|
gboolean isDirty;
|
||||||
char *title;
|
char *title;
|
||||||
char *filename;
|
char *filename; // This typically is a full absolute path.
|
||||||
|
char *path; // This will be derived from the filename.
|
||||||
} WindowDataT;
|
} WindowDataT;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ gboolean utilFileOpen(WindowDataT *self, char *extension, char *what);
|
||||||
char *utilFileRemoveExtension(char *filename);
|
char *utilFileRemoveExtension(char *filename);
|
||||||
gboolean utilFileSaveAs(WindowDataT *self, char *extension, char *what);
|
gboolean utilFileSaveAs(WindowDataT *self, char *extension, char *what);
|
||||||
gboolean utilFileSaveOtherAs(WindowDataT *self, char *extension, char *what, char **filename);
|
gboolean utilFileSaveOtherAs(WindowDataT *self, char *extension, char *what, char **filename);
|
||||||
|
GtkWidget *utilFindChildWidget(GtkWidget *parent, const gchar *name);
|
||||||
char *utilGetToken(char *input, char *delimit, char *openblock, char *closeblock);
|
char *utilGetToken(char *input, char *delimit, char *openblock, char *closeblock);
|
||||||
WindowDataT *utilGetWindowData(GtkWidget *window);
|
WindowDataT *utilGetWindowData(GtkWidget *window);
|
||||||
gboolean utilGetWidgetsFromMemory(char *resource, char *name[], GtkWidget **widgets[], gpointer userData);
|
gboolean utilGetWidgetsFromMemory(char *resource, char *name[], GtkWidget **widgets[], gpointer userData);
|
||||||
|
@ -57,6 +58,7 @@ gboolean utilMkDirP(const char *dir, const mode_t mode);
|
||||||
char *utilObfuscateASCII(char *clearText);
|
char *utilObfuscateASCII(char *clearText);
|
||||||
gboolean utilQuestionDialog(GtkWidget *parent, char *title, char *question);
|
gboolean utilQuestionDialog(GtkWidget *parent, char *title, char *question);
|
||||||
void utilSetDirty(WindowDataT *self, gboolean dirty);
|
void utilSetDirty(WindowDataT *self, gboolean dirty);
|
||||||
|
void utilUpdatePath(WindowDataT *self);
|
||||||
void utilWindowRegister(gpointer windowData);
|
void utilWindowRegister(gpointer windowData);
|
||||||
int utilWindowsCloseAll(void);
|
int utilWindowsCloseAll(void);
|
||||||
int utilWindowsOpen(void);
|
int utilWindowsOpen(void);
|
||||||
|
|
|
@ -81,7 +81,6 @@ typedef struct ProjectDataS {
|
||||||
char *buildPassword;
|
char *buildPassword;
|
||||||
TargetT **targets;
|
TargetT **targets;
|
||||||
GtkWidget *tempWidget; // Used to pass data around dialogs.
|
GtkWidget *tempWidget; // Used to pass data around dialogs.
|
||||||
char *tempString; // Used to pass data around dialogs.
|
|
||||||
} ProjectDataT;
|
} ProjectDataT;
|
||||||
|
|
||||||
typedef struct SectionDataS {
|
typedef struct SectionDataS {
|
||||||
|
@ -164,31 +163,31 @@ EVENT void buildTargetClicked(GtkButton *widget, gpointer userData) {
|
||||||
|
|
||||||
EVENT void btnEditRawClicked(GtkButton *widget, gpointer userData) {
|
EVENT void btnEditRawClicked(GtkButton *widget, gpointer userData) {
|
||||||
ProjectDataT *self = (ProjectDataT *)userData;
|
ProjectDataT *self = (ProjectDataT *)userData;
|
||||||
char *pathTemp = NULL;
|
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
int i;
|
GtkWidget *lblRaw = utilFindChildWidget(self->tempWidget, "lblRaw");
|
||||||
|
|
||||||
(void)widget;
|
(void)widget;
|
||||||
|
|
||||||
pathTemp = strdup(self->windowData.filename);
|
gtk_dialog_response(GTK_DIALOG(self->tempWidget), GTK_RESPONSE_CANCEL);
|
||||||
cwk_path_get_dirname(pathTemp, (size_t *)&i); //***TODO*** Self is getting clobbered here. WTF?
|
|
||||||
if (i > 0) pathTemp[i] = 0;
|
|
||||||
|
|
||||||
//***TODO*** Be sure this is something we can edit as text.
|
//***TODO*** Be sure this is something we can edit as text.
|
||||||
|
|
||||||
filename = utilCreateString("%s%s", pathTemp, self->tempString);
|
filename = utilCreateString("%s%s", self->windowData.path, gtk_label_get_text(GTK_LABEL(lblRaw)));
|
||||||
winEditorCreate(filename);
|
winEditorCreate(filename);
|
||||||
DEL(filename);
|
DEL(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EVENT void btnEditRecipeClicked(GtkButton *widget, gpointer userData) {
|
EVENT void btnEditRecipeClicked(GtkButton *widget, gpointer userData) {
|
||||||
ProjectDataT *self = (ProjectDataT *)userData;
|
ProjectDataT *self = (ProjectDataT *)userData;
|
||||||
char *file = NULL;
|
char *file = NULL;
|
||||||
|
GtkWidget *fileRecipe = utilFindChildWidget(self->tempWidget, "fileRecipe");
|
||||||
|
|
||||||
(void)widget;
|
(void)widget;
|
||||||
|
|
||||||
file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(self->tempWidget));
|
gtk_dialog_response(GTK_DIALOG(self->tempWidget), GTK_RESPONSE_CANCEL);
|
||||||
|
|
||||||
|
file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fileRecipe));
|
||||||
if (utilFileExists(file)) {
|
if (utilFileExists(file)) {
|
||||||
winEditorCreate(file);
|
winEditorCreate(file);
|
||||||
}
|
}
|
||||||
|
@ -201,35 +200,27 @@ EVENT void btnNewRecipeClicked(GtkButton *widget, gpointer userData) {
|
||||||
char *newFile = NULL;
|
char *newFile = NULL;
|
||||||
char *fromTemp = NULL;
|
char *fromTemp = NULL;
|
||||||
char *toTemp = NULL;
|
char *toTemp = NULL;
|
||||||
char *pathTemp = NULL;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
(void)widget;
|
(void)widget;
|
||||||
|
|
||||||
if (utilFileSaveOtherAs((WindowDataT *)userData, "*.c", "Recipe", &newFile)) {
|
if (utilFileSaveOtherAs((WindowDataT *)userData, "*.c", "Recipe", &newFile)) {
|
||||||
|
|
||||||
pathTemp = strdup(self->windowData.filename);
|
|
||||||
cwk_path_get_dirname(pathTemp, (size_t *)&i);
|
|
||||||
if (i > 0) pathTemp[i] = 0;
|
|
||||||
|
|
||||||
fromTemp = utilCreateString("%s%s", __resourcePath, "recipe.c");
|
fromTemp = utilCreateString("%s%s", __resourcePath, "recipe.c");
|
||||||
utilFileCopy(fromTemp, newFile);
|
utilFileCopy(fromTemp, newFile);
|
||||||
DEL(fromTemp);
|
DEL(fromTemp);
|
||||||
|
|
||||||
fromTemp = utilCreateString("%s%s", __resourcePath, "gitignore");
|
fromTemp = utilCreateString("%s%s", __resourcePath, "gitignore");
|
||||||
toTemp = utilCreateString("%s%s", pathTemp, ".gitignore");
|
toTemp = utilCreateString("%s%s", self->windowData.path, ".gitignore");
|
||||||
utilFileCopy(fromTemp, toTemp);
|
utilFileCopy(fromTemp, toTemp);
|
||||||
DEL(toTemp);
|
DEL(toTemp);
|
||||||
DEL(fromTemp);
|
DEL(fromTemp);
|
||||||
|
|
||||||
fromTemp = utilCreateString("%s%s", __resourcePath, "gitattributes");
|
fromTemp = utilCreateString("%s%s", __resourcePath, "gitattributes");
|
||||||
toTemp = utilCreateString("%s%s", pathTemp, ".gitattributes");
|
toTemp = utilCreateString("%s%s", self->windowData.path, ".gitattributes");
|
||||||
utilFileCopy(fromTemp, toTemp);
|
utilFileCopy(fromTemp, toTemp);
|
||||||
DEL(toTemp);
|
DEL(toTemp);
|
||||||
DEL(fromTemp);
|
DEL(fromTemp);
|
||||||
|
|
||||||
DEL(pathTemp);
|
|
||||||
|
|
||||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(self->tempWidget), newFile);
|
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(self->tempWidget), newFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,10 +246,8 @@ static void dialogCookOptions(char *filename, ProjectDataT *self) {
|
||||||
GtkWidget *btnOkay;
|
GtkWidget *btnOkay;
|
||||||
int original;
|
int original;
|
||||||
int result;
|
int result;
|
||||||
int i;
|
|
||||||
char *raw = NULL;
|
char *raw = NULL;
|
||||||
char *temp = NULL;
|
char *temp = NULL;
|
||||||
char *path = NULL;
|
|
||||||
char *widgetNames[] = {
|
char *widgetNames[] = {
|
||||||
"dialogCookSettings",
|
"dialogCookSettings",
|
||||||
"lblRaw",
|
"lblRaw",
|
||||||
|
@ -282,13 +271,7 @@ static void dialogCookOptions(char *filename, ProjectDataT *self) {
|
||||||
raw = utilFileBasename(filename);
|
raw = utilFileBasename(filename);
|
||||||
gtk_label_set_text(GTK_LABEL(lblRaw), raw);
|
gtk_label_set_text(GTK_LABEL(lblRaw), raw);
|
||||||
|
|
||||||
self->tempWidget = fileRecipe;
|
self->tempWidget = dialogCookSettings;
|
||||||
self->tempString = strdup(raw);
|
|
||||||
|
|
||||||
// Find path of project file.
|
|
||||||
path = strdup(self->windowData.filename);
|
|
||||||
cwk_path_get_dirname(path, (size_t *)&i);
|
|
||||||
if (i > 0) path[i] = 0;
|
|
||||||
|
|
||||||
original = findRecipeData(self, raw);
|
original = findRecipeData(self, raw);
|
||||||
if (original >= 0) {
|
if (original >= 0) {
|
||||||
|
@ -301,7 +284,7 @@ static void dialogCookOptions(char *filename, ProjectDataT *self) {
|
||||||
temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fileRecipe));
|
temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fileRecipe));
|
||||||
if (temp != NULL) {
|
if (temp != NULL) {
|
||||||
// Convert to relative path.
|
// Convert to relative path.
|
||||||
cwk_path_get_relative(path, temp, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
cwk_path_get_relative(self->windowData.path, temp, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
||||||
if (__utilFilenameBuffer[0] != 0) {
|
if (__utilFilenameBuffer[0] != 0) {
|
||||||
DEL(temp);
|
DEL(temp);
|
||||||
temp = strdup(__utilFilenameBuffer);
|
temp = strdup(__utilFilenameBuffer);
|
||||||
|
@ -315,11 +298,9 @@ static void dialogCookOptions(char *filename, ProjectDataT *self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEL(path);
|
|
||||||
DEL(raw);
|
DEL(raw);
|
||||||
|
|
||||||
self->tempWidget = NULL;
|
self->tempWidget = NULL;
|
||||||
DEL(self->tempString);
|
|
||||||
|
|
||||||
gtk_widget_destroy(dialogCookSettings);
|
gtk_widget_destroy(dialogCookSettings);
|
||||||
}
|
}
|
||||||
|
@ -416,7 +397,6 @@ static void loadProject(ProjectDataT *self) {
|
||||||
TargetT *t = NULL;
|
TargetT *t = NULL;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
char *path = NULL;
|
|
||||||
char *raw = NULL;
|
char *raw = NULL;
|
||||||
|
|
||||||
in = fopen(self->windowData.filename, "rt");
|
in = fopen(self->windowData.filename, "rt");
|
||||||
|
@ -427,10 +407,6 @@ static void loadProject(ProjectDataT *self) {
|
||||||
self->targets[i]->archs[j]->selected = FALSE;
|
self->targets[i]->archs[j]->selected = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Find path of project file.
|
|
||||||
path = strdup(self->windowData.filename);
|
|
||||||
cwk_path_get_dirname(path, (size_t *)&i);
|
|
||||||
if (i > 0) path[i] = 0;
|
|
||||||
// Load project.
|
// Load project.
|
||||||
utilEnsureBufferSize((unsigned char **)&line, (int *)&len, 1024); // Not technically needed, but fixes a pointer warning from memmaker.
|
utilEnsureBufferSize((unsigned char **)&line, (int *)&len, 1024); // Not technically needed, but fixes a pointer warning from memmaker.
|
||||||
while (getline(&line, &len, in) != -1) {
|
while (getline(&line, &len, in) != -1) {
|
||||||
|
@ -442,7 +418,7 @@ static void loadProject(ProjectDataT *self) {
|
||||||
if (strcasecmp(c, "source") == 0) {
|
if (strcasecmp(c, "source") == 0) {
|
||||||
c = utilGetToken(NULL, " ", "\"", "\"");
|
c = utilGetToken(NULL, " ", "\"", "\"");
|
||||||
utilDequote(c);
|
utilDequote(c);
|
||||||
cwk_path_get_relative(path, c, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
cwk_path_get_relative(self->windowData.path, c, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
||||||
if (__utilFilenameBuffer[0] == 0) {
|
if (__utilFilenameBuffer[0] == 0) {
|
||||||
projectAddToTree(self, c);
|
projectAddToTree(self, c);
|
||||||
} else {
|
} else {
|
||||||
|
@ -485,7 +461,7 @@ static void loadProject(ProjectDataT *self) {
|
||||||
raw = strdup(c);
|
raw = strdup(c);
|
||||||
c = utilGetToken(NULL, " ", "\"", "\"");
|
c = utilGetToken(NULL, " ", "\"", "\"");
|
||||||
utilDequote(c);
|
utilDequote(c);
|
||||||
cwk_path_get_relative(path, c, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
cwk_path_get_relative(self->windowData.path, c, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
||||||
if (__utilFilenameBuffer[0] == 0) {
|
if (__utilFilenameBuffer[0] == 0) {
|
||||||
addToRecipeData(self, raw, c);
|
addToRecipeData(self, raw, c);
|
||||||
} else {
|
} else {
|
||||||
|
@ -497,7 +473,6 @@ static void loadProject(ProjectDataT *self) {
|
||||||
}
|
}
|
||||||
fclose(in);
|
fclose(in);
|
||||||
DEL(line);
|
DEL(line);
|
||||||
DEL(path);
|
|
||||||
utilSetDirty((WindowDataT *)self, FALSE); // Do again - loading text marks us dirty.
|
utilSetDirty((WindowDataT *)self, FALSE); // Do again - loading text marks us dirty.
|
||||||
} else {
|
} else {
|
||||||
//***TODO*** Something bad happened.
|
//***TODO*** Something bad happened.
|
||||||
|
@ -543,6 +518,7 @@ EVENT void menuProjectFileNew(GtkWidget *object, gpointer userData) {
|
||||||
|
|
||||||
// Nuke filename & mark clean.
|
// Nuke filename & mark clean.
|
||||||
DEL(self->windowData.filename);
|
DEL(self->windowData.filename);
|
||||||
|
DEL(self->windowData.path);
|
||||||
utilSetDirty(&self->windowData, FALSE);
|
utilSetDirty(&self->windowData, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,8 +626,6 @@ EVENT void menuProjectProjectAdd(GtkWidget *object, gpointer userData) {
|
||||||
GtkFileFilter *filter;
|
GtkFileFilter *filter;
|
||||||
ProjectSectionTypeT section;
|
ProjectSectionTypeT section;
|
||||||
char *temp = NULL;
|
char *temp = NULL;
|
||||||
char *path = NULL;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
(void)object;
|
(void)object;
|
||||||
|
|
||||||
|
@ -664,10 +638,7 @@ EVENT void menuProjectProjectAdd(GtkWidget *object, gpointer userData) {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (self->windowData.filename != NULL) {
|
if (self->windowData.filename != NULL) {
|
||||||
path = strdup(self->windowData.filename);
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),self->windowData.path);
|
||||||
cwk_path_get_dirname(path, (size_t *)&x);
|
|
||||||
if (x > 0) path[x] = 0;
|
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (section=0; section<SECTION_COUNT; section++) {
|
for (section=0; section<SECTION_COUNT; section++) {
|
||||||
|
@ -685,8 +656,8 @@ EVENT void menuProjectProjectAdd(GtkWidget *object, gpointer userData) {
|
||||||
|
|
||||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||||
temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||||
if (path != NULL) {
|
if (self->windowData.path != NULL) {
|
||||||
cwk_path_get_relative(path,temp, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
cwk_path_get_relative(self->windowData.path,temp, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
||||||
DEL(temp);
|
DEL(temp);
|
||||||
temp = strdup(__utilFilenameBuffer);
|
temp = strdup(__utilFilenameBuffer);
|
||||||
}
|
}
|
||||||
|
@ -935,7 +906,6 @@ EVENT void menuProjectBuildCookRecipes(GtkWidget *object, gpointer userData) {
|
||||||
int i;
|
int i;
|
||||||
char *raw;
|
char *raw;
|
||||||
char *recipe;
|
char *recipe;
|
||||||
char *path;
|
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
// Only one cook at a time. Should not be able to happen.
|
// Only one cook at a time. Should not be able to happen.
|
||||||
|
@ -947,11 +917,6 @@ EVENT void menuProjectBuildCookRecipes(GtkWidget *object, gpointer userData) {
|
||||||
// Remember who started the cook.
|
// Remember who started the cook.
|
||||||
_cookingProjectData = self;
|
_cookingProjectData = self;
|
||||||
|
|
||||||
// Find path of project file.
|
|
||||||
path = strdup(self->windowData.filename);
|
|
||||||
cwk_path_get_dirname(path, (size_t *)&i);
|
|
||||||
if (i > 0) path[i] = 0;
|
|
||||||
|
|
||||||
for (i=0; i<arrlen(self->recipes); i++) {
|
for (i=0; i<arrlen(self->recipes); i++) {
|
||||||
// Build pathnames.
|
// Build pathnames.
|
||||||
cwk_path_change_basename(self->windowData.filename, self->recipes[i]->key, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
cwk_path_change_basename(self->windowData.filename, self->recipes[i]->key, __utilFilenameBuffer, sizeof(__utilFilenameBuffer));
|
||||||
|
@ -961,7 +926,7 @@ EVENT void menuProjectBuildCookRecipes(GtkWidget *object, gpointer userData) {
|
||||||
|
|
||||||
// Run it!
|
// Run it!
|
||||||
message(MSG_INFO, "Cooking %s", self->recipes[i]->key);
|
message(MSG_INFO, "Cooking %s", self->recipes[i]->key);
|
||||||
result = compilerRunRecipe(recipe, raw, path, self);
|
result = compilerRunRecipe(recipe, raw, self->windowData.path, self);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
//***TODO*** Not all negative returns are severe.
|
//***TODO*** Not all negative returns are severe.
|
||||||
message(result > 0 ? MSG_ERROR : MSG_SEVERE, "Recipe %s returned %d", self->recipes[i]->value, result);
|
message(result > 0 ? MSG_ERROR : MSG_SEVERE, "Recipe %s returned %d", self->recipes[i]->value, result);
|
||||||
|
@ -969,7 +934,6 @@ EVENT void menuProjectBuildCookRecipes(GtkWidget *object, gpointer userData) {
|
||||||
message(MSG_INFO, "Finished Cooking");
|
message(MSG_INFO, "Finished Cooking");
|
||||||
}
|
}
|
||||||
|
|
||||||
DEL(path);
|
|
||||||
_cookingProjectData = NULL;
|
_cookingProjectData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1070,10 +1034,8 @@ EVENT void treeProjectRowActivated(GtkTreeView *treeView, GtkTreePath *path, Gtk
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
char *pathString = NULL;
|
char *pathString = NULL;
|
||||||
char *pathTemp = NULL;
|
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
int section;
|
int section;
|
||||||
int i;
|
|
||||||
|
|
||||||
pathString = gtk_tree_path_to_string(path);
|
pathString = gtk_tree_path_to_string(path);
|
||||||
if (strstr(pathString, ":") != NULL) {
|
if (strstr(pathString, ":") != NULL) {
|
||||||
|
@ -1084,15 +1046,10 @@ EVENT void treeProjectRowActivated(GtkTreeView *treeView, GtkTreePath *path, Gtk
|
||||||
debug("Double click! [%d] [%s] [%s]\n", section, pathString, name);
|
debug("Double click! [%d] [%s] [%s]\n", section, pathString, name);
|
||||||
|
|
||||||
if (section == SECTION_CODE || section == SECTION_HEADER) {
|
if (section == SECTION_CODE || section == SECTION_HEADER) {
|
||||||
//***TODO*** We find our path way too often. Do it once and keep it.
|
filename = utilCreateString("%s%s", self->windowData.path, name);
|
||||||
pathTemp = strdup(self->windowData.filename);
|
|
||||||
cwk_path_get_dirname(pathTemp, (size_t *)&i);
|
|
||||||
if (i > 0) pathTemp[i] = 0;
|
|
||||||
filename = utilCreateString("%s%s", pathTemp, name);
|
|
||||||
// Launch code editor.
|
// Launch code editor.
|
||||||
winEditorCreate(filename);
|
winEditorCreate(filename);
|
||||||
DEL(filename);
|
DEL(filename);
|
||||||
DEL(pathTemp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section == SECTION_RAW_DATA) {
|
if (section == SECTION_RAW_DATA) {
|
||||||
|
@ -1323,6 +1280,7 @@ void winProjectCreate(void) {
|
||||||
|
|
||||||
//***DEBUG***
|
//***DEBUG***
|
||||||
self->windowData.filename = strdup("/home/scott/joeyapps/warehouse/Warehouse.joe");
|
self->windowData.filename = strdup("/home/scott/joeyapps/warehouse/Warehouse.joe");
|
||||||
|
self->windowData.path = strdup("/home/scott/joeyapps/warehouse/");
|
||||||
loadProject(self);
|
loadProject(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
57
src/utils.c
57
src/utils.c
|
@ -253,7 +253,9 @@ gboolean utilFileOpen(WindowDataT *self, char *extension, char *what) {
|
||||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||||
utilSetDirty((WindowDataT *)self, FALSE);
|
utilSetDirty((WindowDataT *)self, FALSE);
|
||||||
DEL(self->filename);
|
DEL(self->filename);
|
||||||
|
DEL(self->path);
|
||||||
self->filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
self->filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||||
|
utilUpdatePath(self);
|
||||||
} else {
|
} else {
|
||||||
result = FALSE;
|
result = FALSE;
|
||||||
}
|
}
|
||||||
|
@ -270,7 +272,7 @@ gboolean utilFileOpen(WindowDataT *self, char *extension, char *what) {
|
||||||
|
|
||||||
|
|
||||||
char *utilFileRemoveExtension(char *filename) {
|
char *utilFileRemoveExtension(char *filename) {
|
||||||
int x = strlen(filename) - 1;
|
int x = (int)strlen(filename) - 1;
|
||||||
char c = 0;
|
char c = 0;
|
||||||
char *newString = NULL;
|
char *newString = NULL;
|
||||||
|
|
||||||
|
@ -293,7 +295,12 @@ char *utilFileRemoveExtension(char *filename) {
|
||||||
|
|
||||||
|
|
||||||
gboolean utilFileSaveAs(WindowDataT *self, char *extension, char *what) {
|
gboolean utilFileSaveAs(WindowDataT *self, char *extension, char *what) {
|
||||||
return utilFileSaveOtherAs(self, extension, what, &self->filename);
|
gboolean result;
|
||||||
|
|
||||||
|
result = utilFileSaveOtherAs(self, extension, what, &self->filename);
|
||||||
|
utilUpdatePath(self);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -339,6 +346,36 @@ gboolean utilFileSaveOtherAs(WindowDataT *self, char *extension, char *what, cha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GtkWidget *utilFindChildWidget(GtkWidget *parent, const gchar *name) {
|
||||||
|
GList *children = NULL;
|
||||||
|
GtkWidget *widget = NULL;
|
||||||
|
|
||||||
|
// This works on widgets with names. If a widget is referenced by
|
||||||
|
// utilGetWidgetsFromMemory, the name will be set to the ID of the
|
||||||
|
// widget. If not, you need to assign a name yourself.
|
||||||
|
|
||||||
|
if (g_strcmp0(gtk_widget_get_name(parent), name) == 0) {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GTK_IS_CONTAINER(parent)) {
|
||||||
|
children = gtk_container_get_children(GTK_CONTAINER(parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (children != NULL) {
|
||||||
|
widget = utilFindChildWidget(children->data, name);
|
||||||
|
|
||||||
|
if (widget != NULL) {
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
children = children->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/26187037/in-c-split-char-on-spaces-with-strtok-function-except-if-between-quotes
|
// https://stackoverflow.com/questions/26187037/in-c-split-char-on-spaces-with-strtok-function-except-if-between-quotes
|
||||||
char *utilGetToken(char *input, char *delimit, char *openblock, char *closeblock) {
|
char *utilGetToken(char *input, char *delimit, char *openblock, char *closeblock) {
|
||||||
static char *token = NULL;
|
static char *token = NULL;
|
||||||
|
@ -403,6 +440,8 @@ gboolean utilGetWidgetsFromMemory(char *resource, char *name[], GtkWidget **widg
|
||||||
x = 0;
|
x = 0;
|
||||||
while (name[x] != NULL) {
|
while (name[x] != NULL) {
|
||||||
*widgets[x] = GTK_WIDGET(gtk_builder_get_object(gtkBuilder, name[x]));
|
*widgets[x] = GTK_WIDGET(gtk_builder_get_object(gtkBuilder, name[x]));
|
||||||
|
// Set the widget name property to the ID we used to find it.
|
||||||
|
gtk_widget_set_name(*widgets[x], name[x]);
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,6 +581,20 @@ void utilSetDirty(WindowDataT *self, gboolean dirty) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void utilUpdatePath(WindowDataT *self) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (self->filename) {
|
||||||
|
// Derive the path from the filename.
|
||||||
|
self->path = strdup(self->filename);
|
||||||
|
cwk_path_get_dirname(self->path, (size_t *)&i);
|
||||||
|
if (i > 0) self->path[i] = 0;
|
||||||
|
} else {
|
||||||
|
DEL(self->path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void utilWindowRegister(gpointer windowData) {
|
void utilWindowRegister(gpointer windowData) {
|
||||||
WindowDataT *w = (WindowDataT *)windowData;
|
WindowDataT *w = (WindowDataT *)windowData;
|
||||||
|
|
||||||
|
|
|
@ -735,6 +735,7 @@ EVENT void menuVectorFileNew(GtkWidget *object, gpointer userData) {
|
||||||
|
|
||||||
// Clear any filename.
|
// Clear any filename.
|
||||||
DEL(self->windowData.filename);
|
DEL(self->windowData.filename);
|
||||||
|
DEL(self->windowData.path);
|
||||||
|
|
||||||
// Refresh widget.
|
// Refresh widget.
|
||||||
gtk_widget_queue_draw(self->drawVectorImage);
|
gtk_widget_queue_draw(self->drawVectorImage);
|
||||||
|
@ -1529,6 +1530,7 @@ void winVectorCreate(char *filename) {
|
||||||
|
|
||||||
if (filename != NULL) {
|
if (filename != NULL) {
|
||||||
self->windowData.filename = strdup(filename);
|
self->windowData.filename = strdup(filename);
|
||||||
|
utilUpdatePath((WindowDataT *)self);
|
||||||
loadVectorImage(self);
|
loadVectorImage(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
<child internal-child="vbox">
|
<child internal-child="vbox">
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
|
<property name="margin-start">10</property>
|
||||||
|
<property name="margin-end">10</property>
|
||||||
|
<property name="margin-top">10</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="spacing">2</property>
|
<property name="spacing">2</property>
|
||||||
<child internal-child="action_area">
|
<child internal-child="action_area">
|
||||||
|
|
Loading…
Add table
Reference in a new issue