INT_PTR CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG : { ProjectPanel::initMenus(); // Create toolbar menu int style = WS_CHILD | WS_VISIBLE | CCS_ADJUSTABLE | TBSTYLE_AUTOSIZE | TBSTYLE_FLAT | TBSTYLE_LIST; _hToolbarMenu = CreateWindowEx(0,TOOLBARCLASSNAME,NULL, style, 0,0,0,0,_hSelf,(HMENU)0, _hInst, NULL); TBBUTTON tbButtons[2]; NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); generic_string workspace_entry = pNativeSpeaker->getProjectPanelLangMenuStr("Entries", 0, PM_WORKSPACEMENUENTRY); generic_string edit_entry = pNativeSpeaker->getProjectPanelLangMenuStr("Entries", 1, PM_EDITMENUENTRY); tbButtons[0].idCommand = IDB_PROJECT_BTN; tbButtons[0].iBitmap = I_IMAGENONE; tbButtons[0].fsState = TBSTATE_ENABLED; tbButtons[0].fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE; tbButtons[0].iString = (INT_PTR)workspace_entry.c_str(); tbButtons[1].idCommand = IDB_EDIT_BTN; tbButtons[1].iBitmap = I_IMAGENONE; tbButtons[1].fsState = TBSTATE_ENABLED; tbButtons[1].fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE; tbButtons[1].iString = (INT_PTR)edit_entry.c_str(); SendMessage(_hToolbarMenu, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); SendMessage(_hToolbarMenu, TB_ADDBUTTONS, (WPARAM)sizeof(tbButtons) / sizeof(TBBUTTON), (LPARAM)&tbButtons); SendMessage(_hToolbarMenu, TB_AUTOSIZE, 0, 0); ShowWindow(_hToolbarMenu, SW_SHOW); _treeView.init(_hInst, _hSelf, ID_PROJECTTREEVIEW); setImageList(IDI_PROJECT_WORKSPACE, IDI_PROJECT_WORKSPACEDIRTY, IDI_PROJECT_PROJECT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID); _treeView.addCanNotDropInList(INDEX_LEAF); _treeView.addCanNotDropInList(INDEX_LEAF_INVALID); _treeView.addCanNotDragOutList(INDEX_CLEAN_ROOT); _treeView.addCanNotDragOutList(INDEX_DIRTY_ROOT); _treeView.addCanNotDragOutList(INDEX_PROJECT); _treeView.display(); if (!openWorkSpace(_workSpaceFilePath.c_str())) newWorkSpace(); return TRUE; } case WM_MOUSEMOVE: if (_treeView.isDragging()) _treeView.dragItem(_hSelf, LOWORD(lParam), HIWORD(lParam)); break; case WM_LBUTTONUP: if (_treeView.isDragging()) if (_treeView.dropItem()) setWorkSpaceDirty(true); break; case WM_NOTIFY: { notified((LPNMHDR)lParam); } return TRUE; case WM_SIZE: { int width = LOWORD(lParam); int height = HIWORD(lParam); RECT toolbarMenuRect; ::GetClientRect(_hToolbarMenu, &toolbarMenuRect); ::MoveWindow(_hToolbarMenu, 0, 0, width, toolbarMenuRect.bottom, TRUE); HWND hwnd = _treeView.getHSelf(); if (hwnd) ::MoveWindow(hwnd, 0, toolbarMenuRect.bottom + 2, width, height - toolbarMenuRect.bottom - 2, TRUE); break; } case WM_CONTEXTMENU: if (!_treeView.isDragging()) showContextMenu(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); return TRUE; case WM_COMMAND: { popupMenuCmd(LOWORD(wParam)); break; } case WM_DESTROY: { _treeView.destroy(); destroyMenus(); ::DestroyWindow(_hToolbarMenu); break; } case WM_KEYDOWN: //if (wParam == VK_F2) { ::MessageBoxA(NULL,"vkF2","",MB_OK); } break; default : return DockingDlgInterface::run_dlgProc(message, wParam, lParam); } return DockingDlgInterface::run_dlgProc(message, wParam, lParam); }
void ProjectPanel::popupMenuCmd(int cmdID) { // get selected item handle HTREEITEM hTreeItem = _treeView.getSelection(); if (!hTreeItem) return; switch (cmdID) { // // Toolbar menu buttons // case IDB_PROJECT_BTN: { POINT p = getMenuDisplayPoint(0); TrackPopupMenu(_hWorkSpaceMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL); } break; case IDB_EDIT_BTN: { POINT p = getMenuDisplayPoint(1); HMENU hMenu = NULL; NodeType nodeType = getNodeType(hTreeItem); if (nodeType == nodeType_project) hMenu = _hProjectMenu; else if (nodeType == nodeType_folder) hMenu = _hFolderMenu; else if (nodeType == nodeType_file) hMenu = _hFileMenu; if (hMenu) TrackPopupMenu(hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL); } break; // // Toolbar menu commands // case IDM_PROJECT_NEWPROJECT : { HTREEITEM root = _treeView.getRoot(); NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); generic_string newProjectLabel = pNativeSpeaker->getAttrNameStr(PM_NEWPROJECTNAME, "ProjectManager", "NewProjectName"); HTREEITEM addedItem = _treeView.addItem(newProjectLabel.c_str(), root, INDEX_PROJECT); setWorkSpaceDirty(true); _treeView.expand(hTreeItem); TreeView_EditLabel(_treeView.getHSelf(), addedItem); } break; case IDM_PROJECT_NEWWS : { if (_isDirty) { int res = ::MessageBox(_hSelf, TEXT("The current workspace was modified. Do you want to save the current project?"), TEXT("New Workspace"), MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL); if (res == IDYES) { if (!saveWorkSpace()) return; } else if (res == IDNO) { // Don't save so do nothing here } else if (res == IDCANCEL) { // User cancels action "New Workspace" so we interrupt here return; } } _treeView.removeAllItems(); newWorkSpace(); } break; case IDM_PROJECT_RENAME : TreeView_EditLabel(_treeView.getHSelf(), hTreeItem); break; case IDM_PROJECT_NEWFOLDER : { NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); generic_string newFolderLabel = pNativeSpeaker->getAttrNameStr(PM_NEWFOLDERNAME, "ProjectManager", "NewFolderName"); addFolder(hTreeItem, newFolderLabel.c_str()); setWorkSpaceDirty(true); } break; case IDM_PROJECT_MOVEDOWN : { if (_treeView.moveDown(hTreeItem)) setWorkSpaceDirty(true); } break; case IDM_PROJECT_MOVEUP : { if (_treeView.moveUp(hTreeItem)) setWorkSpaceDirty(true); } break; case IDM_PROJECT_ADDFILES : { addFiles(hTreeItem); if (getNodeType(hTreeItem) == nodeType_folder) _treeView.setItemImage(hTreeItem, INDEX_OPEN_NODE, INDEX_OPEN_NODE); } break; case IDM_PROJECT_ADDFILESRECUSIVELY : { addFilesFromDirectory(hTreeItem); if (getNodeType(hTreeItem) == nodeType_folder) _treeView.setItemImage(hTreeItem, INDEX_OPEN_NODE, INDEX_OPEN_NODE); } break; case IDM_PROJECT_OPENWS: { if (_isDirty) { int res = ::MessageBox(_hSelf, TEXT("The current workspace was modified. Do you want to save the current project?"), TEXT("Open Workspace"), MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL); if (res == IDYES) { if (!saveWorkSpace()) return; } else if (res == IDNO) { // Don't save so do nothing here } else if (res == IDCANCEL) { // User cancels action "New Workspace" so we interrupt here return; } } FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL)); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); if (TCHAR *fn = fDlg.doOpenSingleFileDlg()) { if (!openWorkSpace(fn)) { ::MessageBox(_hSelf, TEXT("The workspace could not be opened.\rIt seems the file to open is not a valid project file."), TEXT("Open Workspace"), MB_OK); return; } } } break; case IDM_PROJECT_RELOADWS: { if (_isDirty) { int res = ::MessageBox(_hSelf, TEXT("The current workspace was modified. Reloading will discard all modifications.\rDo you want to continue?"), TEXT("Reload Workspace"), MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); if (res == IDYES) { // Do nothing } else if (res == IDNO) { return; } } if (::PathFileExists(_workSpaceFilePath.c_str())) { openWorkSpace(_workSpaceFilePath.c_str()); } else { ::MessageBox(_hSelf, TEXT("Cannot find the file to reload."), TEXT("Reload Workspace"), MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL); } } break; case IDM_PROJECT_SAVEWS: saveWorkSpace(); break; case IDM_PROJECT_SAVEACOPYASWS: case IDM_PROJECT_SAVEASWS: { saveWorkSpaceAs(cmdID == IDM_PROJECT_SAVEACOPYASWS); } break; case IDM_PROJECT_DELETEFOLDER : { HTREEITEM parent = _treeView.getParent(hTreeItem); if (_treeView.getChildFrom(hTreeItem) != NULL) { TCHAR str2display[MAX_PATH] = TEXT("All the sub-items will be removed.\rAre you sure you want to remove this folder from the project?"); if (::MessageBox(_hSelf, str2display, TEXT("Remove folder from project"), MB_YESNO) == IDYES) { _treeView.removeItem(hTreeItem); setWorkSpaceDirty(true); } } else { _treeView.removeItem(hTreeItem); setWorkSpaceDirty(true); } if (getNodeType(parent) == nodeType_folder) _treeView.setItemImage(parent, INDEX_CLOSED_NODE, INDEX_CLOSED_NODE); } break; case IDM_PROJECT_DELETEFILE : { HTREEITEM parent = _treeView.getParent(hTreeItem); TCHAR str2display[MAX_PATH] = TEXT("Are you sure you want to remove this file from the project?"); if (::MessageBox(_hSelf, str2display, TEXT("Remove file from project"), MB_YESNO) == IDYES) { _treeView.removeItem(hTreeItem); setWorkSpaceDirty(true); if (getNodeType(parent) == nodeType_folder) _treeView.setItemImage(parent, INDEX_CLOSED_NODE, INDEX_CLOSED_NODE); } } break; case IDM_PROJECT_MODIFYFILEPATH : { FileRelocalizerDlg fileRelocalizerDlg; fileRelocalizerDlg.init(_hInst, _hParent); TCHAR textBuffer[MAX_PATH]; TVITEM tvItem; tvItem.hItem = hTreeItem; tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvItem.pszText = textBuffer; tvItem.cchTextMax = MAX_PATH; SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem); if (!tvItem.lParam) return; generic_string * fn = (generic_string *)tvItem.lParam; if (fileRelocalizerDlg.doDialog(fn->c_str()) == 0) { generic_string newValue = fileRelocalizerDlg.getFullFilePath(); if (*fn == newValue) return; *fn = newValue; TCHAR *strValueLabel = ::PathFindFileName(fn->c_str()); lstrcpy(textBuffer, strValueLabel); int iImage = ::PathFileExists(fn->c_str())?INDEX_LEAF:INDEX_LEAF_INVALID; tvItem.iImage = tvItem.iSelectedImage = iImage; SendMessage(_treeView.getHSelf(), TVM_SETITEM, 0,(LPARAM)&tvItem); setWorkSpaceDirty(true); } } break; } }
Fenetre::Fenetre(QWidget *parent) : courant(0), QMainWindow(parent) { //************************* courant = NULL; folder = NULL; resize(1200, 512); //*************************** Menu *************************** QMenu* mFile = menuBar()->addMenu("&File"); QMenu* mEdit = menuBar()->addMenu("&Edit"); QMenu* mView = menuBar()->addMenu("&View"); QMenu* mNouveau = mFile->addMenu("New"); QAction* mactionAnnuler = mEdit->addAction("Annuler"); QAction* mactionRefaire = mEdit->addAction("Refaire"); QAction* mactionSupprimer = mEdit->addAction("Supprimer"); QMenu* mTag = mEdit->addMenu("Tags"); QAction* mactionSupprimerTag = mTag->addAction("Supprimer"); QMenu* mDocument = mEdit->addMenu("Documents"); QAction* mactionUp = mDocument->addAction("Monter"); QAction* mactionDown = mDocument->addAction("Descendre"); QMenu* mExport = mEdit->addMenu("Exporter"); QAction* mactionOuvrir = mFile->addAction("Ouvrir un espace de travail"); QAction* mactionNew = mFile->addAction("Nouvel espace de travail"); QAction* mactionSaveAs = mFile->addAction("Enregistrer sous..."); QAction* mactionNewArticle = mNouveau->addAction("Article"); QAction* mactionNewImage = mNouveau->addAction("Image"); QAction* mactionNewAudio = mNouveau->addAction("Audio"); QAction* mactionNewVideo = mNouveau->addAction("Video"); QAction* mactionNewDocument = mNouveau->addAction("Document"); QAction* mactionExportHTML = mExport->addAction("Html"); QAction* mactionExportTex = mExport->addAction("Tex"); QAction* mactionExportTexte = mExport->addAction("Texte"); QAction* mactionOption=mEdit->addAction("Setting"); QAction* mactionAddTag = mNouveau->addAction("Tag"); QAction* mactionSave = mFile->addAction("Sauvegarder"); mFile->addSeparator(); QMenu* ouvrirCorbeille = mFile->addMenu("Corbeille"); QAction* mactionRestaurer = ouvrirCorbeille->addAction("Restaurer"); QAction* mactionVider = ouvrirCorbeille->addAction("Vider la Corbeille"); mactionViewEdit = mView->addAction("Onglet Editeur"); mactionViewHTML = mView->addAction("Onglet Html"); mactionViewTex = mView->addAction("Onglet Tex"); mactionViewTexte = mView->addAction("Onglet Texte"); mFile->addSeparator(); QAction* actionQuitter = mFile->addAction("&Quitter"); actionQuitter->setIcon(QIcon("icon/quitter.png")); mactionNewArticle->setIcon(QIcon("icon/article.png")); mactionNewImage->setIcon(QIcon("icon/image.png")); mactionNewAudio->setIcon(QIcon("icon/audio.png")); mactionNewVideo->setIcon(QIcon("icon/video.png")); mNouveau->setIcon(QIcon("icon/plus.png")); mactionDown->setIcon(QIcon("icon/down.png")); mactionUp->setIcon(QIcon("icon/up.png")); mactionAddTag->setIcon(QIcon("icon/tag.png")); mactionSave->setIcon(QIcon("icon/save.png")); mactionExportHTML->setIcon(QIcon("icon/html.png")); mactionExportTex->setIcon(QIcon("icon/tex.png")); mactionExportTexte->setIcon(QIcon("icon/texte.png")); mactionAnnuler->setIcon(QIcon("icon/undo.png")); mactionRefaire->setIcon(QIcon("icon/redo.png")); mactionSupprimer->setIcon(QIcon("icon/cross.png")); mactionRestaurer->setIcon(QIcon("icon/corbeille.png")); mactionNewDocument->setIcon(QIcon("icon/document.png")); mactionOption->setIcon(QIcon("icon/setting.png")); mactionOuvrir->setShortcut(QKeySequence("Ctrl+O")); actionQuitter->setShortcut(QKeySequence("Ctrl+Q")); mactionSave->setShortcut(QKeySequence("Ctrl+S")); mactionAnnuler->setShortcut(QKeySequence("Ctrl+Z")); mactionRefaire->setShortcut(QKeySequence("Ctrl+Y")); mactionSupprimer->setShortcut(tr("Delete")); //** VIEW **// mactionViewEdit->setCheckable(true); mactionViewEdit->setChecked(true); mactionViewHTML->setCheckable(true); mactionViewTex->setCheckable(true); mactionViewTexte->setCheckable(true); //Bar de statue QStatusBar* statusBar = new QStatusBar; statusBar->addWidget(new QLabel("Projet Lo21 - Pauline Crouillère / Emilien Notarianni")); this->setStatusBar(statusBar); // Création de la barre d'outils QToolBar *toolBarFichier = addToolBar("Fichier"); toolBarFichier->addAction(mactionNewArticle); toolBarFichier->addAction(mactionNewImage); toolBarFichier->addAction(mactionNewAudio); toolBarFichier->addAction(mactionNewVideo); toolBarFichier->addAction(mactionNewDocument); toolBarFichier->addSeparator(); toolBarFichier->addAction(mactionAddTag); toolBarFichier->addSeparator(); toolBarFichier->addAction(mactionUp); toolBarFichier->addAction(mactionDown); toolBarFichier->addSeparator(); toolBarFichier->addAction(mactionExportHTML); toolBarFichier->addAction(mactionExportTex); toolBarFichier->addAction(mactionExportTexte); toolBarFichier->addSeparator(); toolBarFichier->addAction(mactionRestaurer); toolBarFichier->addSeparator(); toolBarFichier->addAction(mactionSupprimer); toolBarFichier->addSeparator(); toolBarFichier->addAction(actionQuitter); /*************************************************************/ couche = new QHBoxLayout(); lw = new LeftWindows(); ow = new OngletWindows(); couche->addWidget(lw); couche->addWidget(ow); couche->setMargin(0); couche->setAlignment(Qt::AlignTop); centerWindows = new QWidget(); centerWindows->setLayout(couche); setCentralWidget(centerWindows); //************************** CONNECT **************************/ QObject::connect(mactionNewArticle, SIGNAL(triggered()), this, SLOT(newArticle())); QObject::connect(mactionNewDocument, SIGNAL(triggered()), this, SLOT(newDocument())); QObject::connect(mactionNewImage, SIGNAL(triggered()), this, SLOT(newImage())); QObject::connect(mactionNewAudio, SIGNAL(triggered()), this, SLOT(newAudio())); QObject::connect(mactionNewVideo, SIGNAL(triggered()), this, SLOT(newVideo())); QObject::connect(mactionAddTag, SIGNAL(triggered()), this, SLOT(newTag())); QObject::connect(mactionOuvrir,SIGNAL(triggered()),this, SLOT(ouvrirDialogue())); QObject::connect(actionQuitter,SIGNAL(triggered()),qApp, SLOT(quit())); QObject::connect(mactionUp,SIGNAL(triggered()),this, SLOT(docUp())); QObject::connect(mactionDown,SIGNAL(triggered()),this, SLOT(docDown())); QObject::connect(mactionRestaurer, SIGNAL(triggered()), this, SLOT(ouvrirCorbeille())); QObject::connect(mactionSave, SIGNAL(triggered()), this, SLOT(asave())); QObject::connect(mactionExportHTML, SIGNAL(triggered()), this, SLOT(exportHTML())); QObject::connect(mactionExportTex, SIGNAL(triggered()), this, SLOT(exportTex())); QObject::connect(mactionExportTexte, SIGNAL(triggered()), this, SLOT(exportTexte())); QObject::connect(mactionSupprimer, SIGNAL(triggered()), this, SLOT(deleteInCorbeille())); QObject::connect(mactionVider, SIGNAL(triggered()), this, SLOT(viderLaCorbeille())); //TODO QObject::connect(mactionAnnuler, SIGNAL(triggered()), qApp, SLOT(undo())); QObject::connect(mactionRefaire, SIGNAL(triggered()), qApp, SLOT(redo())); // QObject::connect(mactionSaveAs, SIGNAL(triggered()), this, SLOT(copieWorkSpace())); QObject::connect(mactionNew, SIGNAL(triggered()), this, SLOT(newWorkSpace())); QObject::connect(mactionOption, SIGNAL(triggered()), this, SLOT(setting())); QObject::connect(mactionViewEdit, SIGNAL(triggered()), this, SLOT(changeEdit())); QObject::connect(mactionViewHTML, SIGNAL(triggered()), this, SLOT(changeHtml())); QObject::connect(mactionViewTex,SIGNAL(triggered()),this, SLOT(changeTex())); QObject::connect(mactionViewTexte,SIGNAL(triggered()),this, SLOT(changeTexte())); QObject::connect(ow, SIGNAL(currentChanged(int)), this, SLOT(changeOnglet(int))); QObject::connect(mactionSupprimerTag, SIGNAL(triggered()), this, SLOT(supprimeTag())); }