This repository has been archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Only for the Goobox folder only, but not its files and subfolders.
- Loading branch information
1 parent
5a4e317
commit 5cfda24
Showing
5 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
src/main/java/io/goobox/sync/storj/overlay/OverlayHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright (C) 2017 Kaloyan Raev | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.goobox.sync.storj.overlay; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.attribute.DosFileAttributeView; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.liferay.nativity.control.NativityControl; | ||
import com.liferay.nativity.control.NativityControlUtil; | ||
import com.liferay.nativity.modules.contextmenu.ContextMenuControlCallback; | ||
import com.liferay.nativity.modules.contextmenu.ContextMenuControlUtil; | ||
import com.liferay.nativity.modules.contextmenu.model.ContextMenuAction; | ||
import com.liferay.nativity.modules.contextmenu.model.ContextMenuItem; | ||
import com.liferay.nativity.modules.fileicon.FileIconControl; | ||
import com.liferay.nativity.modules.fileicon.FileIconControlCallback; | ||
import com.liferay.nativity.modules.fileicon.FileIconControlUtil; | ||
import com.liferay.nativity.util.OSDetector; | ||
|
||
import io.goobox.sync.common.Utils; | ||
|
||
public class OverlayHelper { | ||
|
||
private NativityControl nativityControl; | ||
private FileIconControl fileIconControl; | ||
|
||
private int stateIconId = 0; | ||
|
||
private static OverlayHelper instance; | ||
|
||
public static OverlayHelper getInstance() { | ||
if (instance == null) { | ||
instance = new OverlayHelper(); | ||
} | ||
return instance; | ||
} | ||
|
||
public OverlayHelper() { | ||
init(); | ||
} | ||
|
||
public void setOK() { | ||
if (!OSDetector.isWindows()) { | ||
return; | ||
} | ||
|
||
stateIconId = 1; | ||
refresh(); | ||
} | ||
|
||
public void setSynchronizing() { | ||
if (!OSDetector.isWindows()) { | ||
return; | ||
} | ||
|
||
stateIconId = 2; | ||
refresh(); | ||
} | ||
|
||
public void shutdown() { | ||
if (!OSDetector.isWindows()) { | ||
return; | ||
} | ||
|
||
stateIconId = 0; | ||
refresh(); | ||
nativityControl.disconnect(); | ||
} | ||
|
||
private void refresh() { | ||
fileIconControl.refreshIcons(new String[] { Utils.getSyncDir().toString() }); | ||
} | ||
|
||
private void init() { | ||
if (!OSDetector.isWindows()) { | ||
return; | ||
} | ||
|
||
nativityControl = NativityControlUtil.getNativityControl(); | ||
nativityControl.connect(); | ||
|
||
// Setting filter folders is required for Mac's Finder Sync plugin | ||
nativityControl.setFilterFolder(Utils.getSyncDir().toString()); | ||
|
||
DosFileAttributeView attr = Files.getFileAttributeView(Utils.getSyncDir(), DosFileAttributeView.class); | ||
try { | ||
attr.setSystem(true); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// FileIconControlCallback used by Windows and Mac | ||
FileIconControlCallback fileIconControlCallback = new FileIconControlCallback() { | ||
@Override | ||
public int getIconForFile(String path) { | ||
if (Utils.getSyncDir().toString().equals(path)) { | ||
return stateIconId; | ||
} | ||
return 0; | ||
} | ||
}; | ||
|
||
fileIconControl = FileIconControlUtil.getFileIconControl(nativityControl, fileIconControlCallback); | ||
|
||
fileIconControl.enableFileIcons(); | ||
|
||
/* Context Menus */ | ||
|
||
ContextMenuControlCallback contextMenuControlCallback = new ContextMenuControlCallback() { | ||
@Override | ||
public List<ContextMenuItem> getContextMenuItems(String[] paths) { | ||
ContextMenuItem contextMenuItem = new ContextMenuItem("Goobox"); | ||
|
||
ContextMenuAction contextMenuAction = new ContextMenuAction() { | ||
@Override | ||
public void onSelection(String[] paths) { | ||
System.out.println("Context menu selection: " + String.join("; ", paths)); | ||
} | ||
}; | ||
|
||
contextMenuItem.setContextMenuAction(contextMenuAction); | ||
|
||
List<ContextMenuItem> contextMenuItems = new ArrayList<ContextMenuItem>(); | ||
contextMenuItems.add(contextMenuItem); | ||
|
||
// Mac Finder Sync will only show the parent level of context menus | ||
return contextMenuItems; | ||
} | ||
}; | ||
|
||
ContextMenuControlUtil.getContextMenuControl(nativityControl, contextMenuControlCallback); | ||
} | ||
|
||
} |