# # # add_file "src/view/WorkspaceMenuBar.cpp" # content [ee3f28cdaaa68fbecd2ae0ce9f8e28a3adea0d07] # # add_file "src/view/WorkspaceMenuBar.h" # content [23a55063dc1efbdbc21ffd080736272426ad81de] # ============================================================ --- src/view/WorkspaceMenuBar.cpp ee3f28cdaaa68fbecd2ae0ce9f8e28a3adea0d07 +++ src/view/WorkspaceMenuBar.cpp ee3f28cdaaa68fbecd2ae0ce9f8e28a3adea0d07 @@ -0,0 +1,190 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * 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. * + ***************************************************************************/ + +#include "WorkspaceMenuBar.h" +#include "vocab.h" + +WorkspaceMenuBar::WorkspaceMenuBar() : DatabaseMenuBar() +{ + // + // The View/Show menu + // + actionAll_files = new QAction(tr("All files"), this); + actionAll_files->setCheckable(true); + actionAll_files->setChecked(true); + actionAll_files->setShortcut(tr("Alt+A")); + actionAll_changed_files = new QAction(tr("All changed files"), this); + actionAll_changed_files->setCheckable(true); + actionAll_changed_files->setShortcut(tr("Alt+C")); + actionPatched_files = new QAction(tr("Patched files"), this); + actionPatched_files->setCheckable(true); + actionPatched_files->setShortcut(tr("Alt+P")); + actionAdded_files = new QAction(tr("Added files"), this); + actionAdded_files->setCheckable(true); + actionAdded_files->setShortcut(tr("Alt+N")); + actionRemoved_files = new QAction(tr("Removed files"), this); + actionRemoved_files->setCheckable(true); + actionRemoved_files->setShortcut(tr("Alt+D")); + actionRenamed_files = new QAction(tr("Renamed files"), this); + actionRenamed_files->setCheckable(true); + actionRenamed_files->setShortcut(tr("Alt+R")); + actionMissing_files = new QAction(tr("Missing files"), this); + actionMissing_files->setCheckable(true); + actionMissing_files->setShortcut(tr("Alt+M")); + actionUnknown_files = new QAction(tr("Unknown files"), this); + actionUnknown_files->setCheckable(true); + actionUnknown_files->setShortcut(tr("Alt+U")); + actionIgnored_files = new QAction(tr("Ignored files"), this); + actionIgnored_files->setCheckable(true); + actionIgnored_files->setShortcut(tr("Alt+I")); + + menuShow = new QMenu(tr("Show"), this); + + menuShow->addAction(actionAll_files); + menuShow->addSeparator(); + menuShow->addAction(actionAll_changed_files); + menuShow->addAction(actionAdded_files); + menuShow->addAction(actionPatched_files); + menuShow->addAction(actionRemoved_files); + menuShow->addAction(actionRenamed_files); + menuShow->addAction(actionMissing_files); + menuShow->addAction(actionUnknown_files); + menuShow->addAction(actionIgnored_files); + + actionHide_ignored_files = new QAction(tr("Hide ignored files"), this); + actionHide_ignored_files->setShortcut(tr("Ctrl+H")); + actionExpand_tree = new QAction(tr("Expand tree"), this); + actionExpand_tree->setShortcut(tr("Ctrl+T")); + + menuView = new QMenu(tr("View"), this); + + menuView->addAction(actionHide_ignored_files); + menuView->addAction(actionExpand_tree); + menuView->addAction(menuShow->menuAction()); + + // + // The workspace menu + // + actionUpdate_workspace = new QAction(tr("Update workspace"), this); + actionUpdate_workspace->setShortcut(tr("Ctrl+U")); + actionCommit_revision = new QAction(tr("Commit revision"), this); + actionCommit_revision->setShortcut(tr("Ctrl+C")); + actionReload_workspace = new QAction(tr("Reload workspace"), this); + actionReload_workspace->setShortcut(tr("Ctrl+R")); + actionFind_unaccounted_renames = new QAction(tr("Find unaccounted renames"), this); + + menuWorkspace = new QMenu(tr("Workspace"), this); + + menuWorkspace->addAction(actionUpdate_workspace); + menuWorkspace->addAction(actionCommit_revision); + menuWorkspace->addAction(actionReload_workspace); + menuWorkspace->addSeparator(); + menuWorkspace->addAction(actionFind_unaccounted_renames); + + // insert the workspace menu before the database menu + insertAction(menuWorkspace->menuAction(), menuDatabase->menuAction()); + + // insert the view menu before the workspace menu + insertAction(menuView->menuAction(), menuWorkspace->menuAction()); + + // view actions + connect( + menuShow, SIGNAL(triggered(QAction *)), + this, SLOT(toggleFilterFiles(QAction *)) + ); + + connect( + actionExpand_tree, SIGNAL(triggered()), + this, SLOT(toggleExpandTree()) + ); + + connect( + actionHide_ignored_files, SIGNAL(triggered()), + this, SLOT(toggleHideIgnoredFiles()) + ); + + // workspace forwards + connect( + actionUpdate_workspace, SIGNAL(triggered()), + this, SIGNAL(showUpdateWorkspace()) + ); + + connect( + actionCommit_revision, SIGNAL(triggered()), + this, SIGNAL(showCommitRevision()) + ); + + connect( + actionReload_workspace, SIGNAL(triggered()), + this, SIGNAL(reloadWorkspace()) + ); + + connect( + actionFind_unaccounted_renames, SIGNAL(triggered()), + this, SIGNAL(showUnaccountedRenames()) + ); +} + +WorkspaceMenuBar::~WorkspaceMenuBar() {} + +void WorkspaceMenuBar::toggleFilterFiles(QAction * act) +{ + emit filterFiles(act->data().toInt()); + + // disable any previous action and check the new action entry + QList assocWidgets = act->associatedWidgets(); + I(assocWidgets.size() > 0); + + // we assume that this action is only assigned to one widget and that + // is the QMenu widget we need to find out all the other actions + QList list = assocWidgets[0]->actions(); + for (int i=0, j=list.size(); isetChecked(false); + } + act->setChecked(true); +} + +void WorkspaceMenuBar::toggleExpandTree() +{ + bool expanded = actionExpand_tree->data().toBool(); + + emit expandTree(!expanded); + + actionExpand_tree->setText( + expanded ? tr("Expand tree") : tr("Collapse tree") + ); + + actionExpand_tree->setData(QVariant(!expanded)); +} + +void WorkspaceMenuBar::toggleHideIgnoredFiles() +{ + bool hide = actionHide_ignored_files->data().toBool(); + + emit hideIgnoredFiles(!hide); + + actionHide_ignored_files->setText( + hide ? tr("Hide ignored files") : tr("Show ignored files") + ); + + actionHide_ignored_files->setData(QVariant(!hide)); +} + ============================================================ --- src/view/WorkspaceMenuBar.h 23a55063dc1efbdbc21ffd080736272426ad81de +++ src/view/WorkspaceMenuBar.h 23a55063dc1efbdbc21ffd080736272426ad81de @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * 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. * + ***************************************************************************/ + +#ifndef WORKSPACE_MENU_BAR_H +#define WORKSPACE_MENU_BAR_H + +#include "DatabaseMenuBar.h" + +class WorkspaceMenuBar : private DatabaseMenuBar +{ + Q_OBJECT +public: + WorkspaceMenuBar(); + ~WorkspaceMenuBar(); + +signals: + void hideIgnoredFiles(bool); + void expandTree(bool); + void filterFiles(int); + + void showUpdateWorkspace(); + void showCommitRevision(); + void reloadWorkspace(); + void showUnaccountedRenames(); + +protected: + QAction * actionHide_ignored_files; + QAction * actionExpand_tree; + QAction * actionAll_files; + QAction * actionAll_changed_files; + QAction * actionPatched_files; + QAction * actionAdded_files; + QAction * actionRemoved_files; + QAction * actionRenamed_files; + QAction * actionMissing_files; + QAction * actionUnknown_files; + QAction * actionIgnored_files; + + QAction * actionUpdate_workspace; + QAction * actionCommit_revision; + QAction * actionReload_workspace; + QAction * actionFind_unaccounted_renames; + + QMenu * menuView; + QMenu * menuShow; + QMenu * menuWorkspace; + +private slots: + void toggleExpandTree(); + void toggleHideIgnoredFiles(); + void toggleFilterFiles(QAction *); +}; + +#endif +