Add context menu

pull/23/head
JuanJakobo 2021-06-04 21:23:43 +02:00
parent 0ad9c9915b
commit 41f4d4de4f
5 changed files with 141 additions and 0 deletions

View File

@ -49,6 +49,7 @@ list(APPEND PB_LINK_DIRECTORIES "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/
list(APPEND PB_INCLUDE_DIRECTORIES "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/usr/include") list(APPEND PB_INCLUDE_DIRECTORIES "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/usr/include")
set(SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp set(SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/src/handler/contextMenu.cpp
${CMAKE_SOURCE_DIR}/src/handler/eventHandler.cpp ${CMAKE_SOURCE_DIR}/src/handler/eventHandler.cpp
${CMAKE_SOURCE_DIR}/src/handler/mainMenu.cpp ${CMAKE_SOURCE_DIR}/src/handler/mainMenu.cpp
${CMAKE_SOURCE_DIR}/src/util/nextcloud.cpp ${CMAKE_SOURCE_DIR}/src/util/nextcloud.cpp

View File

@ -0,0 +1,41 @@
//------------------------------------------------------------------
// contextMenu.cpp
//
// Author: JuanJakobo
// Date: 14.06.2020
//
//-------------------------------------------------------------------
#include "inkview.h"
#include "contextMenu.h"
#include <string>
using std::string;
ContextMenu::ContextMenu()
{
}
ContextMenu::~ContextMenu()
{
free(_menu);
free(_open);
free(_sync);
free(_remove);
}
int ContextMenu::createMenu(int y, FileState itemstate, iv_menuhandler handler)
{
imenu contextMenu[] =
{
{ITEM_HEADER, 0, _menu, NULL},
{(itemstate != FileState::ICLOUD) ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 101, _open, NULL},
{ITEM_ACTIVE, 102, _sync, NULL},
{(itemstate != FileState::ICLOUD) ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 103, _remove, NULL},
{0, 0, NULL, NULL}};
OpenMenu(contextMenu, 0, ScreenWidth(),y, handler);
return 1;
}

View File

@ -0,0 +1,40 @@
//------------------------------------------------------------------
// contextMenu.h
//
// Author: JuanJakobo
// Date: 14.06.2020
// Description: Handles the menubar and the menu
//-------------------------------------------------------------------
#ifndef CONTEXT_MENU
#define CONTEXT_MENU
#include "inkview.h"
#include "item.h"
#include <string>
class ContextMenu
{
public:
ContextMenu();
~ContextMenu();
/**
* Shows the menu on the screen, lets the user choose menu options and then redirects the handler to the caller
*
* @param y y-coordinate of the item
* @param FileState status of the item for that the menu is created
* @param handler which action does the menu buttons start
* @return int returns if the event was handled
*/
int createMenu(int y, FileState itemstate, iv_menuhandler handler);
private:
char *_menu = strdup("Menu");
char *_open = strdup("Open");
char *_sync = strdup("Sync");
char *_remove = strdup("Remove");
};
#endif

View File

@ -130,6 +130,63 @@ void EventHandler::mainMenuHandler(const int index)
} }
} }
void EventHandler::contextMenuHandlerStatic(const int index)
{
_eventHandlerStatic->contextMenuHandler(index);
}
std::unique_ptr<ContextMenu> _contextMenu;
void EventHandler::contextMenuHandler(const int index)
{
//invert color
switch (index)
{
//Open
case 101:
{
if (_nextcloud.getItems().at(tempItemID).getType() == Itemtype::IFOLDER)
{
openFolder();
}
else
{
openItem();
}
break;
}
//Sync
case 102:
{
startDownload();
break;
}
//remove
case 103:
{
OpenProgressbar(1, "Removing...", "Removing Files.", 0, EventHandler::DialogHandlerStatic);
if (_nextcloud.removeItem(tempItemID))
{
_listView->drawEntry(tempItemID);
Util::updatePBLibrary();
}
else
{
Message(ICON_WARNING, "Warning", "Could not delete the file, please try again.", 1200);
}
CloseProgressbar();
break;
}
default:
{
_listView->invertEntryColor(tempItemID);
break;
}
_contextMenu.reset();
}
}
int EventHandler::pointerHandler(const int type, const int par1, const int par2) int EventHandler::pointerHandler(const int type, const int par1, const int par2)
{ {
if (type == EVT_POINTERDOWN) if (type == EVT_POINTERDOWN)

View File

@ -9,6 +9,7 @@
#ifndef EVENT_HANDLER #ifndef EVENT_HANDLER
#define EVENT_HANDLER #define EVENT_HANDLER
#include "contextMenu.h"
#include "mainMenu.h" #include "mainMenu.h"
#include "nextcloud.h" #include "nextcloud.h"
#include "listView.h" #include "listView.h"
@ -40,6 +41,7 @@ private:
static std::unique_ptr<EventHandler> _eventHandlerStatic; static std::unique_ptr<EventHandler> _eventHandlerStatic;
std::unique_ptr<ListView> _listView; std::unique_ptr<ListView> _listView;
std::unique_ptr<LoginView> _loginView; std::unique_ptr<LoginView> _loginView;
std::unique_ptr<ContextMenu> _contextMenu;
MainMenu _menu = MainMenu("Nextcloud"); MainMenu _menu = MainMenu("Nextcloud");
Nextcloud _nextcloud = Nextcloud(); Nextcloud _nextcloud = Nextcloud();
std::string _tempPath; std::string _tempPath;