📄 project.c
字号:
/*
Copyright 2001-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
You may contact the author at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
**********************************************************************
PROJECT.C handles the functiosn of the project window, as well as
saving and loading project files. The main window routine vectors
some of the menu commands to the window proc of the project window
as well.
**********************************************************************
*/
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <richedit.h>
#include <stdio.h>
#include "header.h"
#include <ctype.h>
extern HWND hwndToolEdit, hwndToolDebug, hwndToolBuild;
extern LOGFONT EditFont;
extern HINSTANCE hInstance;
extern HWND hwndClient, hwndStatus, hwndFrame;
extern char szProjectFilter[], szSourceFilter[], szTargetFilter[];
extern HWND hwndTab, hwndWatch;
extern HWND hwndTabCtrl;
extern int browseInfo;
extern char *findhist1[MAX_COMBO_HISTORY];
extern char *findhist2[MAX_COMBO_HISTORY];
extern char *replacehist[MAX_COMBO_HISTORY];
extern char *watchhist[MAX_COMBO_HISTORY];
extern char *fifhistory[MAX_COMBO_HISTORY];
HANDLE projectSem;
HWND hwndProject;
int changedProject;
PROJLIST *projectList;
PROJLIST *selectedProject;
char szProjectName[256];
char szProjectTitle[256];
static char szProjectClassName[] = "xccProjectClass";
static HWND treeWindow;
static HBITMAP flyellow, flred, flgreen, flwhite, flcyan, fldll, fllib, flexe;
static int ilyellow, ilred, ilgreen, ilwhite, ilcyan, ildll, illib, ilexe;
static HIMAGELIST treeIml;
static int treeViewSelected;
static char ipathbuf[2048];
static HTREEITEM targetRoot = TVI_ROOT;
static LOGFONT fontdata =
{
14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH
| FF_MODERN | FF_DONTCARE, "Arial"
};
static HFONT projFont;
#ifndef __CCDL__
#ifndef _WIN32_IE
typedef struct tagTVKEYDOWN
{
NMHDR hdr;
WORD wVKey;
UINT flags;
} NMTVKEYDOWN, FAR *LPNMTVKEYDOWN;
#endif
#endif
void RefreshDepends(HWND hTree, PROJLIST *projlist);
void FindModuleName(char *out, char *in)
{
PROJLIST *l = projectList;
int i = 0;
while (l)
{
int j = 0;
FILELIST *m = l->files;
while (m)
{
if (!xstricmpz(in, m->name))
{
strcpy(out, in);
return ;
}
if (!xstricmpz(in, m->title))
{
strcpy(out, m->name);
return ;
}
m = m->next;
}
l = l->next;
}
}
//-------------------------------------------------------------------------
void abspath(char *name)
{
char projname[256], *p, *nname = name;
if (!szProjectName[0])
return ;
if (name[0] == 0)
return ;
if (name[1] == ':')
return ;
strcpy(projname, szProjectName);
p = strrchr(projname, '\\');
if (!p)
return ;
p--;
if (!strstr(name, "..\\"))
{
if (name[0] != '\\')
{
strcpy(p + 2, name);
strcpy(nname, projname);
}
return ;
}
while (!strncmp(name, "..\\", 3))
{
while (p > projname && *p-- != '\\')
;
name += 3;
}
*++p = '\\';
p++;
strcpy(p, name);
strcpy(nname, projname);
}
//-------------------------------------------------------------------------
char *relpath(char *name)
{
static char projname[256], localname[256];
char *p = localname, *q = projname, *r, *s;
if (!szProjectName[0])
return name;
if (toupper(name[0]) != toupper(szProjectName[0]))
return name;
strcpy(localname, name);
strcpy(projname, szProjectName);
r = strrchr(localname, '\\');
if (r)
*r++ = 0;
// r has the point to the file name
else
r = localname;
s = strrchr(projname, '\\');
if (!s)
return name;
if (*s)
*s = 0;
while (*p && *q && toupper(*p) == toupper(*q))
p++, q++;
if (!(*p | *q))
return r;
else if (*(p - 1) == '\\' && *(p - 2) == ':')
return name;
else
{
int count = *q != 0;
while (*p && p > localname && *p != '\\')
p--;
while (*q && (q = strchr(q + 1, '\\')))
count++;
projname[0] = 0;
while (count--)
strcat(projname, "..\\");
if (*p)
{
strcat(projname, p + 1);
strcat(projname, "\\");
}
strcat(projname, r);
return projname;
}
}
//-------------------------------------------------------------------------
void absincludepath(char *name)
{
char *p = ipathbuf, *dest1 = name, *dest2 = name;
strcpy(ipathbuf, name);
name[0] = 0;
do
{
char *q;
if (*p == ';')
p++;
q = p;
dest1 = dest2;
p = strchr(p, ';');
if (!p)
p = ipathbuf + strlen(ipathbuf);
while (q != p)*dest2++ = *q++;
*dest2 = 0;
abspath(dest1);
dest2 = dest1 + strlen(dest1);
if (*p)
*dest2++ = ';';
}
while (*p)
;
}
//-------------------------------------------------------------------------
char *relincludepath(char *name)
{
char *p = name, *dest1 = ipathbuf, *dest2 = ipathbuf;
ipathbuf[0] = 0;
do
{
char *q;
if (*p == ';')
p++;
q = p;
dest1 = dest2;
p = strchr(p, ';');
if (!p)
p = name + strlen(name);
while (q != p)*dest2++ = *q++;
*dest2 = 0;
strcpy(dest1, relpath(dest1));
dest2 = dest1 + strlen(dest1);
if (*p)
*dest2++ = ';';
}
while (*p)
;
return ipathbuf;
}
//-------------------------------------------------------------------------
int imageof(char *name)
{
name = strrchr(name, '.');
if (!name)
return ilyellow;
if (!xstricmpz(name, ".asm"))
return ilred;
if (!xstricmpz(name, ".c") || !xstricmpz(name, ".cpp"))
return ilcyan;
if (!xstricmpz(name, ".rc"))
return ilgreen;
if (!xstricmpz(name, ".h"))
return ilyellow;
if (!xstricmpz(name, ".exe"))
return ilexe;
if (!xstricmpz(name, ".lib"))
return illib;
if (!xstricmpz(name, ".dll"))
return ildll;
return ilwhite;
}
//-------------------------------------------------------------------------
HTREEITEM TVInitInsert(HWND hTree, HTREEITEM hParent, HTREEITEM after, char
*title, int toexpand)
{
HTREEITEM rv;
TV_INSERTSTRUCT t;
memset(&t, 0, sizeof(t));
t.hParent = hParent;
t.hInsertAfter = after;
#if !defined( _WIN32_IE) && !defined(__CCDL__)
t.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
t.item.hItem = 0;
t.item.pszText = title;
t.item.cchTextMax = strlen(title);
t.item.iImage = t.item.iSelectedImage = imageof(title);
#else
t.u.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
t.u.item.hItem = 0;
t.u.item.pszText = title;
t.u.item.cchTextMax = strlen(title);
t.u.item.iImage = t.u.item.iSelectedImage = imageof(title);
#endif
rv = TreeView_InsertItem(hTree, &t);
if (toexpand)
TreeView_Expand(treeWindow, hParent, TVE_EXPAND);
return rv;
}
//-------------------------------------------------------------------------
void AddFileInternal(PROJLIST *p, int selected, char *name, char *title)
{
FILELIST *x = p->files;
while (x)
{
if (!xstricmp(x->name, name))
return ;
x = x->next;
}
x = malloc(sizeof(FILELIST));
memset(x, 0, sizeof(*x));
if (x)
{
FILELIST **y = &p->files;
int i;
HTREEITEM item = TVI_FIRST;
while (*y)
{
if (stricmp((*y)->name, name) > 0)
break;
item = (*y)->treeHandle;
y = &(*y)->next;
}
#ifdef XXXXX
for (i = 0; i < selected; i++)
{
item = (*y)->treeHandle;
y = &(*y)->next;
}
#endif
x->next = (*y);
*y = x;
strcpy(x->name, name);
strcpy(x->title, title);
x->treeHandle = TVInitInsert(treeWindow, p->sourceTreeHandle, item, x
->title, TRUE);
}
}
//-------------------------------------------------------------------------
void ProjectAddFile(PROJLIST *p, int selected)
{
if (hwndProject)
{
OPENFILENAME ofn;
if (OpenFileDialog(&ofn, 0, hwndProject, FALSE, TRUE, szSourceFilter,
"FILEDIR", "Select Source Files"))
{
char *q = ofn.lpstrFile;
char path[256];
char filename[256], *r;
changedProject = TRUE;
strcpy(path, q);
q = q + strlen(q) + 1;
if (*q)
{
while (*q)
{
sprintf(filename, "%s\\%s", path, q);
AddFileInternal(p, selected++, filename, q);
q = q + strlen(q) + 1;
}
}
else
{
r = strrchr(path, '\\');
if (!r)
r = path;
else
r++;
AddFileInternal(p, selected, path, r);
}
}
}
}
//-------------------------------------------------------------------------
void ProjectAddTarget(PROJLIST *p)
{
if (hwndProject)
{
OPENFILENAME ofn;
char buf[512], *q;
strcpy(buf, szProjectName);
q = strrchr(buf, '\\');
if (q && *(q - 1) != ':')
*q = 0;
StringToProfile("FILEDIR", buf);
if (OpenFileDialog(&ofn, 0, hwndProject, TRUE, FALSE, szTargetFilter,
"FILEDIR", "Select Target"))
{
PROJLIST *x = projectList;
while (x)
{
if (!xstricmp(x->name, ofn.lpstrFile))
return ;
x = x->next;
}
x = malloc(sizeof(PROJLIST));
memset(x, 0, sizeof(*x));
if (x)
{
int rootproj = FALSE;
changedProject = TRUE;
if (!strchr(ofn.lpstrFile, '.'))
{
strcat(ofn.lpstrFile, ".exe");
strcat(ofn.lpstrFileTitle, ".exe");
}
strcpy(x->name, ofn.lpstrFile);
strcpy(x->title, ofn.lpstrFileTitle);
if (!projectList)
{
rootproj = TRUE;
projectList = x;
x->treeHandle = TVInitInsert(treeWindow, targetRoot,
TVI_FIRST, ofn.lpstrFileTitle, FALSE);
}
else
{
if (!p)
{
p = projectList;
while (p->next)
p = p->next;
}
x->treeHandle = TVInitInsert(treeWindow, targetRoot, p
->treeHandle, ofn.lpstrFileTitle, FALSE);
x->next = p->next;
p->next = x;
}
x->sourceTreeHandle = TVInitInsert(treeWindow, x->treeHandle,
TVI_FIRST, "Source Files", FALSE);
x->includeTreeHandle = TVInitInsert(treeWindow, x->treeHandle,
x->sourceTreeHandle, "Include Files", FALSE);
if (lstrlen(x->name) > 4)
if (!xstricmpz(".dll", x->name + lstrlen(x->name) - 4))
x->buildType = BT_DLL;
else if (!xstricmpz(".lib", x->name + lstrlen(x->name) - 4))
x->buildType = BT_LIBRARY;
else
{
x->buildType = BT_CONSOLE;
x->buildFlags = BF_BREAKWINMAIN | BF_DEBUGTOOLTIPS |
BF_DEBUGINFO;
if (rootproj)
x->buildFlags |= BF_CHOSENPROJECT;
}
x->dbgview = 1 << DID_WATCHWND;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -