Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
28b54bf0
Commit
28b54bf0
authored
Apr 15, 2021
by
Krzysztof Stokop
Browse files
Project closing context menu attempt nr 1
parent
f505a340
Changes
4
Hide whitespace changes
Inline
Side-by-side
addons/project/kateprojectclosingcontextmenu.cpp
0 → 100644
View file @
28b54bf0
#include "kateprojectclosingcontextmenu.h"
#include <QApplication>
#include <QClipboard>
#include <QFileInfo>
#include <QIcon>
#include <QMenu>
#include <QMimeDatabase>
#include <QMimeType>
#include <QStandardPaths>
#include <KLocalizedString>
void
KateProjectClosingContextMenu
::
exec
(
QList
<
KateProject
*>
projectList
,
const
QPoint
&
pos
,
KateProjectPluginView
*
parent
)
{
/**
* Create context menu
*/
QMenu
menu
;
/**
* fill menu
*/
QAction
**
actions
=
new
QAction
*
[
projectList
.
size
()];
for
(
int
i
=
0
;
i
<
projectList
.
size
();
i
++
)
actions
[
i
]
=
menu
.
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"window-close"
)),
i18n
(
projectList
[
i
]
->
name
().
toLocal8Bit
().
data
()));
/**
* run menu and handle the triggered action
*/
if
(
QAction
*
const
action
=
menu
.
exec
(
pos
))
for
(
int
i
=
0
;
i
<
projectList
.
size
();
i
++
)
if
(
action
==
actions
[
i
])
parent
->
projectAboutToClose
(
projectList
[
i
]);
}
addons/project/kateprojectclosingcontextmenu.h
0 → 100644
View file @
28b54bf0
#ifndef KATEPROJECTCLOSINGCONTEXTMENU_H
#define KATEPROJECTCLOSINGCONTEXTMENU_H
#include <QObject>
#include <QString>
#include "kateproject.h"
#include "kateprojectpluginview.h"
/**
* @todo write docs
*/
class
KateProjectClosingContextMenu
:
public
QObject
{
Q_OBJECT
public:
/**
* Creating project closing menu from Qlist<KateProject*>
*/
void
exec
(
QList
<
KateProject
*>
projectList
,
const
QPoint
&
pos
,
KateProjectPluginView
*
parent
);
};
#endif // KATEPROJECTCLOSINGCONTEXTMENU_H
addons/project/kateprojectpluginview.cpp
View file @
28b54bf0
...
...
@@ -9,6 +9,7 @@
#include "fileutil.h"
#include "gitwidget.h"
#include "kateprojectinfoviewindex.h"
#include "kateprojectclosingcontextmenu.h"
#include <ktexteditor/application.h>
#include <ktexteditor/codecompletioninterface.h>
...
...
@@ -29,6 +30,7 @@
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QMenu>
#include <QContextMenuEvent>
#include <QTimer>
#include <QVBoxLayout>
...
...
@@ -112,7 +114,7 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
connect
(
m_projectsCombo
,
static_cast
<
void
(
QComboBox
::*
)(
int
)
>
(
&
QComboBox
::
currentIndexChanged
),
this
,
&
KateProjectPluginView
::
slotCurrentChanged
);
connect
(
m_reloadButton
,
&
QToolButton
::
clicked
,
this
,
&
KateProjectPluginView
::
slotProjectReload
);
connect
(
m_closeProjectButton
,
&
QToolButton
::
clicked
,
this
,
&
KateProjectPluginView
::
slotProjectAboutToClose
);
//
connect(m_closeProjectButton, &QToolButton::clicked, this, &KateProjectPluginView::
contextMenuEvent
);
connect
(
m_plugin
,
&
KateProjectPlugin
::
pluginViewProjectClosing
,
this
,
&
KateProjectPluginView
::
slotProjectClose
);
connect
(
m_gitStatusRefreshButton
,
&
QToolButton
::
clicked
,
this
,
[
this
]
{
...
...
@@ -563,13 +565,17 @@ void KateProjectPluginView::slotProjectReload()
}
}
void
KateProjectPluginView
::
slotProjectAboutToClose
(
)
void
KateProjectPluginView
::
contextMenuEvent
(
QContextMenuEvent
*
event
)
{
if
(
QWidget
*
current
=
m_stackedProjectViews
->
currentWidget
())
{
const
auto
project
=
static_cast
<
KateProjectView
*>
(
current
)
->
project
();
m_plugin
->
closeProject
(
project
);
}
KateProjectClosingContextMenu
menu
;
menu
.
exec
(
m_plugin
->
projects
(),
event
->
pos
(),
this
);
event
->
accept
();
}
void
KateProjectPluginView
::
projectAboutToClose
(
KateProject
*
project
)
{
m_plugin
->
closeProject
(
project
);
}
void
KateProjectPluginView
::
slotProjectClose
(
KateProject
*
project
)
...
...
addons/project/kateprojectpluginview.h
View file @
28b54bf0
...
...
@@ -99,6 +99,11 @@ public:
{
return
m_plugin
;
}
/**
* Getting project for others windows.
*/
void
projectAboutToClose
(
KateProject
*
project
);
public
Q_SLOTS
:
/**
...
...
@@ -150,11 +155,9 @@ private Q_SLOTS:
void
slotProjectReload
();
/**
* Getting project for others windows
* and closing project documents.
* Opening close menu
*/
void
slotProjectAboutToClose
();
void
contextMenuEvent
(
QContextMenuEvent
*
event
);
/**
* Close current project.
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment