1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/* c_desktop.cpp
*
* Copyright (c) 2008, eFTE SF Group (see AUTHORS file)
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#define DESKTOP_VER "eFTE Desktop 2\n"
#define DESKTOP_VER1 "eFTE Desktop 1\n"
char DesktopFileName[256] = "";
int SaveDesktop(char *FileName) {
FILE *fp;
EModel *M;
fp = fopen(FileName, "w");
if (fp == 0)
return 0;
setvbuf(fp, FileBuffer, _IOFBF, sizeof(FileBuffer));
fprintf(fp, DESKTOP_VER);
M = ActiveModel;
while (M) {
switch (M->GetContext()) {
case CONTEXT_FILE:
if (M != CvsLogView) {
EBuffer *B = (EBuffer *)M;
fprintf(fp, "F|%d|%s\n", B->ModelNo, B->FileName);
}
break;
case CONTEXT_DIRECTORY: {
EDirectory *D = (EDirectory *)M;
fprintf(fp, "D|%d|%s\n", D->ModelNo, D->Path);
}
break;
}
M = M->Next;
if (M == ActiveModel)
break;
}
TagsSave(fp);
markIndex.saveToDesktop(fp);
fclose(fp);
return 1;
}
int LoadDesktop(char *FileName) {
FILE *fp;
char line[512];
char *p, *e;
int FLCount = 0;
TagClear();
fp = fopen(FileName, "r");
if (fp == 0)
return 0;
//setvbuf(fp, FileBuffer, _IOFBF, sizeof(FileBuffer));
if (fgets(line, sizeof(line), fp) == 0 ||
(strcmp(line, DESKTOP_VER) != 0 &&
(strcmp(line, DESKTOP_VER1) != 0))) {
fclose(fp);
return 0;
}
while (fgets(line, sizeof(line), fp) != 0) {
e = strchr(line, '\n');
if (e == 0)
break;
*e = 0;
if ((line[0] == 'D' || line[0] == 'F') && line[1] == '|') {
int ModelNo = -1;
p = line + 2;
if (isdigit(*p)) {
ModelNo = atoi(p);
while (isdigit(*p)) p++;
if (*p == '|')
p++;
}
if (line[0] == 'F') { // file
if (FLCount > 0)
suspendLoads = 1;
if (FileLoad(0, p, 0, ActiveView))
FLCount++;
suspendLoads = 0;
} else if (line[0] == 'D') { // directory
EModel *m = new EDirectory(0, &ActiveModel, p);
if (m == 0 || ActiveModel == 0) {
ActiveView->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K",
"Could not create directory view");
return 0;
}
}
if (ActiveModel) {
if (ModelNo != -1) {
if (FindModelID(ActiveModel, ModelNo) == 0)
ActiveModel->ModelNo = ModelNo;
}
if (ActiveModel != ActiveModel->Next) {
suspendLoads = 1;
ActiveView->SelectModel(ActiveModel->Next);
suspendLoads = 0;
}
}
} else {
if (line[0] == 'T' && line[1] == '|') { // tag file
TagsAdd(line + 2);
} else if (line[0] == 'M' && line[1] == '|') { // mark
char *name;
char *file;
EPoint P;
//long l;
char *c;
p = line + 2;
P.Row = strtol(p, &c, 10);
if (*c != '|')
break;
p = c + 1;
P.Col = strtol(p, &c, 10);
if (*c != '|')
break;
p = c + 1;
name = p;
while (*p && *p != '|')
p++;
if (*p == '|')
*p++ = 0;
else
break;
file = p;
markIndex.insert(name, file, P);
}
}
}
fclose(fp);
return 1;
}
|