Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace sidebar #5189

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ mark_as_advanced(FORCE
)

# Advanced development config
set(DEV_WORKSPACE_FILE "workspaces.txt" CACHE STRING "Workspace folders list file name")
set(DEV_TOOLBAR_CONFIG "toolbar.ini" CACHE STRING "Toolbar config file name")
set(DEV_SETTINGS_XML_FILE "settings.xml" CACHE STRING "Settings file name")
set(DEV_PALETTE_FILE "palette.gpl" CACHE STRING "Color Palette")
Expand All @@ -253,7 +254,7 @@ endif ()

mark_as_advanced(FORCE
DEV_TOOLBAR_CONFIG DEV_SETTINGS_XML_FILE DEV_PRINT_CONFIG_FILE DEV_METADATA_FILE
DEV_ENABLE_GCOV DEV_CHECK_GTK3_COMPAT
DEV_ENABLE_GCOV DEV_CHECK_GTK3_COMPAT DEV_WORKSPACE_FILE
)

configure_file(
Expand Down
1 change: 1 addition & 0 deletions cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Here you can find complete list of Xournal++ CMake flags (sorted by categories).
| `DEV_METADATA_MAX_ITEMS` *[A]* | 50 | Maximal amount of metadata elements
| `DEV_PRINT_CONFIG_FILE` *[A]* | print-config.ini | Print config file name
| `DEV_SETTINGS_XML_FILE` *[A]* | settings.xml | Settings file name
| `DEV_WORKSPACE_FILE` *[A]* | workspace.txt | Workspace folders list file name
| `DEV_TOOLBAR_CONFIG` *[A]* | toolbar.ini | Toolbar config file name
| `DEV_ERRORLOG_DIR` *[A]* | errorlogs | Directory where errorlogfiles will be placed

Expand Down
4 changes: 4 additions & 0 deletions src/config-dev.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
*/
#define SETTINGS_XML_FILE "@DEV_SETTINGS_XML_FILE@"

/**
* Workspace file name
*/
#define WORKSPACE_FILE "@DEV_WORKSPACE_FILE@"
/**
* Gimp Palette File
*/
Expand Down
46 changes: 44 additions & 2 deletions src/core/control/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "gui/PdfFloatingToolbox.h" // for PdfF...
#include "gui/PopupWindowWrapper.h" // for PopupWindowWrapper
#include "gui/SearchBar.h" // for Sear...
#include "gui/Workspace.h" // for Work...
#include "gui/XournalView.h" // for Xour...
#include "gui/XournalppCursor.h" // for Xour...
#include "gui/dialog/AboutDialog.h" // for Abou...
Expand Down Expand Up @@ -99,6 +100,7 @@
#include "view/CompassView.h" // for Comp...
#include "view/SetsquareView.h" // for Sets...
#include "view/overlays/OverlayView.h" // for Over...
#include "workspace/WorkspaceHandler.h"

#include "CrashHandler.h" // for emer...
#include "LatexController.h" // for Late...
Expand All @@ -108,6 +110,7 @@
#include "config-dev.h" // for SETT...
#include "config.h" // for PROJ...


using std::string;

Control::Control(GApplication* gtkApp, GladeSearchpath* gladeSearchPath, bool disableAudio): gtkApp(gtkApp) {
Expand All @@ -124,8 +127,12 @@ Control::Control(GApplication* gtkApp, GladeSearchpath* gladeSearchPath, bool di
this->lastGroup = GROUP_NOGROUP;
this->lastEnabled = false;

auto name = Util::getConfigFile(SETTINGS_XML_FILE);
this->settings = new Settings(std::move(name));
auto workspaceFilepath = Util::getConfigFile(WORKSPACE_FILE);
this->workspaceHandler = new WorkspaceHandler(std::move(workspaceFilepath));
this->workspaceHandler->load();

auto settingsFilepath = Util::getConfigFile(SETTINGS_XML_FILE);
this->settings = new Settings(std::move(settingsFilepath));
this->settings->load();

this->applyPreferredLanguage();
Expand Down Expand Up @@ -187,6 +194,10 @@ Control::~Control() {
this->toolHandler = nullptr;
delete this->sidebar;
this->sidebar = nullptr;
delete this->workspaceHandler;
this->workspaceHandler = nullptr;
delete this->workspace;
this->workspace = nullptr;
delete this->doc;
this->doc = nullptr;
delete this->searchBar;
Expand Down Expand Up @@ -295,12 +306,14 @@ void Control::saveSettings() {
this->settings->setMainWndMaximized(this->win->isMaximized());

this->sidebar->saveSize();
this->workspace->saveSize();
}

void Control::initWindow(MainWindow* win) {
selectTool(toolHandler->getToolType());
this->win = win;
this->sidebar = new Sidebar(win, this);
this->workspace = new Workspace(win, this, this->workspaceHandler);

XojMsgBox::setDefaultWindow(getGtkWindow());

Expand Down Expand Up @@ -428,6 +441,12 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GtkToolButton*
case ACTION_OPEN:
openFile();
break;
case ACTION_OPEN_FOLDER:
openFolder();
break;
case ACTION_CLOSE_ALL_FOLDERS:
closeAllFolders();
break;
case ACTION_ANNOTATE_PDF:
clearSelectionEndText();
annotatePdf("", false, false);
Expand Down Expand Up @@ -2453,6 +2472,25 @@ auto Control::openFile(fs::path filepath, int scrollToPage, bool forceOpen) -> b
return true;
}

void Control::openFolder() {

XojOpenDlg dlg(getGtkWindow(), this->settings, "Add folder to workspace");
fs::path folderPath = dlg.showOpenFolderDialog();
g_message("%s", (_F("folder: {1}") % folderPath.string()).c_str());

if (workspaceHandler->addFolder(std::move(folderPath))) {
win->setWorkspaceVisible(true);
}
}

void Control::closeAllFolders(bool closeWorkspaceSidebar) {

workspaceHandler->closeAllFolders();

if (closeWorkspaceSidebar)
win->setWorkspaceVisible(false);
}

auto Control::loadPdf(const fs::path& filepath, int scrollToPage) -> bool {
LoadHandler loadHandler;

Expand Down Expand Up @@ -2956,6 +2994,7 @@ auto Control::loadViewMode(ViewModeId mode) -> bool {
this->win->setMenubarVisible(settings->isMenubarVisible());
this->win->setToolbarVisible(settings->isToolbarVisible());
this->win->setSidebarVisible(settings->isSidebarVisible());
this->win->setWorkspaceVisible(settings->isWorkspaceVisible());
setFullscreen(settings->isFullscreen());
return false;
}
Expand Down Expand Up @@ -3320,6 +3359,9 @@ auto Control::getMetadataManager() const -> MetadataManager* { return this->meta

auto Control::getSidebar() const -> Sidebar* { return this->sidebar; }

auto Control::getWorkspaceHandler() const -> WorkspaceHandler* { return this->workspaceHandler; }
auto Control::getWorkspace() const -> Workspace* { return this->workspace; }

auto Control::getSearchBar() const -> SearchBar* { return this->searchBar; }

auto Control::getAudioController() const -> AudioController* { return this->audioController; }
Expand Down
16 changes: 12 additions & 4 deletions src/core/control/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

#pragma once

#include <cstddef> // for size_t
#include <memory> // for unique_ptr
#include <cstddef> // for size_t
#include <memory> // for unique_ptr
#include <optional> // for optional
#include <string> // for string, allocator
#include <vector> // for vector
#include <string> // for string, allocator
#include <vector> // for vector

#include <gdk-pixbuf/gdk-pixbuf.h> // for GdkPixbuf
#include <gio/gio.h> // for GApplication
Expand All @@ -41,6 +41,8 @@
class GeometryToolController;
class AudioController;
class FullscreenHandler;
class WorkspaceHandler;
class Workspace;
class Sidebar;
class GladeSearchpath;
class MetadataManager;
Expand Down Expand Up @@ -90,6 +92,8 @@ class Control:
// Menu File
bool newFile(std::string pageTemplate = "", fs::path filepath = {});
bool openFile(fs::path filepath = "", int scrollToPage = -1, bool forceOpen = false);
void openFolder();
void closeAllFolders(bool closeWorkspaceSidebar = true);
bool annotatePdf(fs::path filepath, bool attachPdf, bool attachToDocument);
void print();
void exportAsPdf();
Expand Down Expand Up @@ -264,6 +268,7 @@ class Control:

MetadataManager* getMetadataManager() const;
Settings* getSettings() const;
WorkspaceHandler* getWorkspaceHandler() const;
ToolHandler* getToolHandler() const;
ZoomControl* getZoomControl() const;
Document* getDocument() const;
Expand All @@ -275,6 +280,7 @@ class Control:
size_t getCurrentPageNo() const;
XournalppCursor* getCursor() const;
Sidebar* getSidebar() const;
Workspace* getWorkspace() const;
SearchBar* getSearchBar() const;
AudioController* getAudioController() const;
PageTypeHandler* getPageTypes() const;
Expand Down Expand Up @@ -392,9 +398,11 @@ class Control:

Document* doc = nullptr;

Workspace* workspace = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use raw pointers for owned resources, instead use std::unique_ptr.

Suggested change
Workspace* workspace = nullptr;
std::unique_ptr<Workspace> workspace;

Sidebar* sidebar = nullptr;
SearchBar* searchBar = nullptr;

WorkspaceHandler* workspaceHandler;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same applies here, additionally, all (new) members should be initialized.

Suggested change
WorkspaceHandler* workspaceHandler;
std::unique_ptr<WorkspaceHandler> workspaceHandler;

ToolHandler* toolHandler;

ActionType lastAction;
Expand Down
34 changes: 34 additions & 0 deletions src/core/control/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ void Settings::loadDefault() {
this->sidebarWidth = 150;
this->sidebarNumberingStyle = SidebarNumberingStyle::DEFAULT;

this->workspaceWidth = 200;
this->showWorkspace = false;

this->showToolbar = true;
this->selectedToolbar = DEFAULT_TOOLBAR;

Expand Down Expand Up @@ -246,6 +249,7 @@ auto Settings::loadViewMode(ViewModeId mode) -> bool {
menubarVisible = viewMode.showMenubar;
showToolbar = viewMode.showToolbar;
showSidebar = viewMode.showSidebar;
showWorkspace = viewMode.showWorkspace;
this->activeViewMode = mode;
return true;
}
Expand Down Expand Up @@ -410,6 +414,10 @@ void Settings::parseItem(xmlDocPtr doc, xmlNodePtr cur) {
this->maximized = xmlStrcmp(value, reinterpret_cast<const xmlChar*>("true")) == 0;
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("showToolbar")) == 0) {
this->showToolbar = xmlStrcmp(value, reinterpret_cast<const xmlChar*>("true")) == 0;
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("showWorkspace")) == 0) {
this->showWorkspace = xmlStrcmp(value, reinterpret_cast<const xmlChar*>("true")) == 0;
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("workspaceWidth")) == 0) {
this->workspaceWidth = std::max<int>(g_ascii_strtoll(reinterpret_cast<const char*>(value), nullptr, 10), 50);
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("filepathShownInTitlebar")) == 0) {
this->filepathShownInTitlebar = xmlStrcmp(value, reinterpret_cast<const xmlChar*>("true")) == 0;
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("pageNumberShownInTitlebar")) == 0) {
Expand Down Expand Up @@ -972,6 +980,9 @@ void Settings::save() {

SAVE_BOOL_PROP(showToolbar);

SAVE_BOOL_PROP(showWorkspace);
SAVE_INT_PROP(workspaceWidth);

SAVE_BOOL_PROP(showSidebar);
SAVE_INT_PROP(sidebarWidth);
xmlNode = saveProperty("sidebarNumberingStyle", static_cast<int>(sidebarNumberingStyle), root);
Expand Down Expand Up @@ -1950,6 +1961,17 @@ void Settings::setSidebarVisible(bool visible) {
save();
}

auto Settings::isWorkspaceVisible() const -> bool { return this->showWorkspace; }

void Settings::setWorkspaceVisible(bool visible) {
if (this->showWorkspace == visible) {
return;
}
this->showWorkspace = visible;
save();
}


auto Settings::isToolbarVisible() const -> bool { return this->showToolbar; }

void Settings::setToolbarVisible(bool visible) {
Expand All @@ -1960,6 +1982,18 @@ void Settings::setToolbarVisible(bool visible) {
save();
}

auto Settings::getWorkspaceWidth() const -> int { return this->workspaceWidth; }

void Settings::setWorkspaceWidth(int width) {
width = std::max(width, 50);

if (this->workspaceWidth == width) {
return;
}
this->workspaceWidth = width;
save();
}

auto Settings::getSidebarWidth() const -> int { return this->sidebarWidth; }

void Settings::setSidebarWidth(int width) {
Expand Down
18 changes: 17 additions & 1 deletion src/core/control/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,15 @@ class Settings {
bool isSidebarVisible() const;
void setSidebarVisible(bool visible);

bool isWorkspaceVisible() const;
void setWorkspaceVisible(bool visible);

bool isToolbarVisible() const;
void setToolbarVisible(bool visible);

int getWorkspaceWidth() const;
void setWorkspaceWidth(int width);

int getSidebarWidth() const;
void setSidebarWidth(int width);

Expand Down Expand Up @@ -630,7 +636,17 @@ class Settings {
bool showSidebar{};

/**
* If the sidebar is visible
* If the workspace sidebar is visible
*/
bool showWorkspace{};

/**
* The Width of the Workspace
*/
int workspaceWidth{};

/**
* If the toolbar is visible
*/
bool showToolbar{};

Expand Down
23 changes: 15 additions & 8 deletions src/core/control/settings/ViewModes.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include "ViewModes.h"
#include "util/StringUtils.h"

#include <iostream>

#include "util/StringUtils.h"

auto ViewMode::operator==(const ViewMode& other) const -> bool {
return (this->goFullscreen == other.goFullscreen) && (this->showMenubar == other.showMenubar) &&
(this->showToolbar == other.showToolbar) && (this->showSidebar == other.showSidebar);
(this->showToolbar == other.showToolbar) && (this->showSidebar == other.showSidebar) &&
(this->showWorkspace == other.showWorkspace);
}

struct ViewMode settingsStringToViewMode(std::string viewModeString) {
struct ViewMode viewMode;
for (const std::string& attr : StringUtils::split(viewModeString, ',')) {
for (const std::string& attr: StringUtils::split(viewModeString, ',')) {
if (attr.compare(ATTR_GO_FULLSCREEN) == 0) {
viewMode.goFullscreen = true;
} else if (attr.compare(ATTR_SHOW_MENUBAR) == 0) {
Expand All @@ -19,17 +21,22 @@ struct ViewMode settingsStringToViewMode(std::string viewModeString) {
viewMode.showToolbar = true;
} else if (attr.compare(ATTR_SHOW_SIDEBAR) == 0) {
viewMode.showSidebar = true;
} else if (attr.compare(ATTR_SHOW_WORKSPACE) == 0) {
viewMode.showWorkspace = true;
}
}
return viewMode;
}

const std::string viewModeToSettingsString(struct ViewMode viewMode) {
if (!(viewMode.goFullscreen || viewMode.showMenubar || viewMode.showToolbar || viewMode.showSidebar)) {
if (!(viewMode.goFullscreen || viewMode.showMenubar || viewMode.showToolbar || viewMode.showSidebar ||
viewMode.showWorkspace)) {
return "";
}
return ((viewMode.goFullscreen ? "," + static_cast<std::string>(ATTR_GO_FULLSCREEN) : "")
+ (viewMode.showMenubar ? "," + static_cast<std::string>(ATTR_SHOW_MENUBAR) : "")
+ (viewMode.showToolbar ? "," + static_cast<std::string>(ATTR_SHOW_TOOLBAR) : "")
+ (viewMode.showSidebar ? "," + static_cast<std::string>(ATTR_SHOW_SIDEBAR) : "")).erase(0,1);
return ((viewMode.goFullscreen ? "," + static_cast<std::string>(ATTR_GO_FULLSCREEN) : "") +
(viewMode.showMenubar ? "," + static_cast<std::string>(ATTR_SHOW_MENUBAR) : "") +
(viewMode.showToolbar ? "," + static_cast<std::string>(ATTR_SHOW_TOOLBAR) : "") +
(viewMode.showSidebar ? "," + static_cast<std::string>(ATTR_SHOW_SIDEBAR) : "") +
(viewMode.showWorkspace ? "," + static_cast<std::string>(ATTR_SHOW_WORKSPACE) : ""))
.erase(0, 1);
}