doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PropTreeItemFileEdit.cpp
Go to the documentation of this file.
1 // PropTreeItemFileEdit.cpp : implementation file
2 
3 
4 //#include "stdafx.h"
5 #include "../../../idlib/precompiled.h"
6 #pragma hdrstop
7 
8 #include "proptree.h"
9 #include "PropTreeItemFileEdit.h"
10 
11 #include "../../../sys/win32/rc/proptree_Resource.h"
12 
13 #ifdef _DEBUG
14 #define new DEBUG_NEW
15 #undef THIS_FILE
16 static char THIS_FILE[] = __FILE__;
17 #endif
18 
20 // CPropTreeItemFileEdit
21 
23 }
24 
26 }
27 
28 
29 BEGIN_MESSAGE_MAP(CPropTreeItemFileEdit, CPropTreeItemEdit)
30  //{{AFX_MSG_MAP(CPropTreeItemFileEdit)
31  //}}AFX_MSG_MAP
32  ON_WM_CONTEXTMENU()
33  ON_WM_CREATE()
34 
35  ON_COMMAND(ID_EDITMENU_INSERTFILE, OnInsertFile)
36  ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
37  ON_COMMAND(ID_EDIT_CUT, OnEditCut)
38  ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
39  ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
40  ON_COMMAND(ID_EDIT_DELETE, OnEditDelete)
41  ON_COMMAND(ID_EDIT_SELECTALL, OnEditSelectAll)
42 
43 END_MESSAGE_MAP()
44 
45 
46 void CPropTreeItemFileEdit::OnContextMenu(CWnd* pWnd, CPoint point) {
47 
48  CMenu FloatingMenu;
49  VERIFY(FloatingMenu.LoadMenu(IDR_ME_EDIT_MENU));
50  CMenu* pPopupMenu = FloatingMenu.GetSubMenu (0);
51 
52  if(CanUndo()) {
53  pPopupMenu->EnableMenuItem(ID_EDIT_UNDO, MF_BYCOMMAND | MF_ENABLED);
54  } else {
55  pPopupMenu->EnableMenuItem(ID_EDIT_UNDO, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
56  }
57 
58  DWORD dwSel = GetSel();
59  if(HIWORD(dwSel) != LOWORD(dwSel)) {
60  pPopupMenu->EnableMenuItem(ID_EDIT_CUT, MF_BYCOMMAND | MF_ENABLED);
61  pPopupMenu->EnableMenuItem(ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
62  pPopupMenu->EnableMenuItem(ID_EDIT_DELETE, MF_BYCOMMAND | MF_ENABLED);
63  } else {
64  pPopupMenu->EnableMenuItem(ID_EDIT_CUT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
65  pPopupMenu->EnableMenuItem(ID_EDIT_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
66  pPopupMenu->EnableMenuItem(ID_EDIT_DELETE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
67  }
68 
69  pPopupMenu->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
70 }
71 
72 int CPropTreeItemFileEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
73 {
74  if (CPropTreeItemEdit::OnCreate(lpCreateStruct) == -1)
75  return -1;
76 
77  // TODO: Add your specialized creation code here
78 
79  return 0;
80 }
81 
83  CFileDialog dlg(TRUE);
84  dlg.m_ofn.Flags |= OFN_FILEMUSTEXIST;
85 
86  int startSel, endSel;
87  GetSel(startSel, endSel);
88 
89  if( dlg.DoModal()== IDOK) {
90 
91  idStr currentText = (char*)GetItemValue();
92  idStr newText = currentText.Left(startSel) + currentText.Right(currentText.Length() - endSel);
93 
94  idStr filename = fileSystem->OSPathToRelativePath(dlg.m_ofn.lpstrFile);
95  filename.BackSlashesToSlashes();
96 
97 
98  newText.Insert(filename, startSel);
99 
100  SetItemValue((LPARAM)newText.c_str());
101  m_pProp->RefreshItems(this);
102 
104 
105  }
106 }
107 
109  Undo();
110 }
111 
113  Cut();
114 }
115 
117  Copy();
118 }
119 
121  Paste();
122 }
123 
125  Clear();
126 }
127 
129  SetSel(0, -1);
130 }
int Length(void) const
Definition: Str.h:702
DWORD
Definition: win_qgl.cpp:61
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
#define PTN_ITEMCHANGED
Definition: PropTree.h:100
const char * Left(int len, idStr &result) const
Definition: Str.h:892
idStr & BackSlashesToSlashes(void)
Definition: Str.cpp:727
LRESULT SendNotify(UINT nNotifyCode, CPropTreeItem *pItem=NULL)
Definition: PropTree.cpp:860
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct)
#define ID_EDIT_DELETE
virtual LPARAM GetItemValue()
#define IDR_ME_EDIT_MENU
#define ID_EDIT_SELECTALL
CPropTree * m_pProp
Definition: PropTreeItem.h:147
virtual void SetItemValue(LPARAM lParam)
void Insert(const char a, int index)
Definition: Str.h:779
const char * Right(int len, idStr &result) const
Definition: Str.h:896
void RefreshItems(CPropTreeItem *pItem=NULL)
Definition: PropTree.cpp:816
Definition: Str.h:116
const char * c_str(void) const
Definition: Str.h:487
#define TRUE
Definition: mprintf.c:69
virtual const char * OSPathToRelativePath(const char *OSPath)=0
#define ID_EDITMENU_INSERTFILE