Skip to content

Commit

Permalink
Merge pull request #7 from xvw/develop
Browse files Browse the repository at this point in the history
Move to version 1.2.0
  • Loading branch information
xvw committed Dec 13, 2017
2 parents 1812fe9 + 82524a6 commit 762c8a0
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install:
npm install

app: install build
./node_modules/.bin/electron-packager .
./node_modules/.bin/electron-packager . qian --overwrite --icon=icon.icns

clean:
rm -rf node_modules
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ In addition, if a feature seems interesting to implement, let's talk about it in
- `make` (a combo of `make build` and `make run`)
- `make app` to create a runnable app on OSX

## Shortcuts

- `Tab` : toggle the focus on the searchbar
- `Cmd + Alt + Enter` : Open the current folder in finder
- `Cmd + Enter` : Open the current folder in a terminal

> those shortcuts works only if the search bar does not have the focus
- `Cmd + Left` : Go on the pred view (if it exists)
- `Cmd + Right` : Go on the next view (if it exists)
- `Cmd + Up` : Go to the parent (if it exists)

## About the search bar

Using `Tab` you can toggle the search-bar activation. When you write
text into this bar, the content of the folder will be filtered using
a fuzzy-filtering. If you write `/`, Qian will open the first element
of the result of the filtering.


## Credits

Expand All @@ -47,8 +66,10 @@ In addition, if a feature seems interesting to implement, let's talk about it in
- [@xvw](https://github.com/xvw): everything else... (I think :P)

### Tools

- [Dotgrid](http://wiki.xxiivv.com/#dotgrid) (for the logo)
- [Elm](http://elm-lang.org/) (to have a nice language)
- [Electron](https://electron.atom.io/) (to have a window !)
- [Font Awesome](http://fontawesome.io/) (for the icon in the UI)
- [NoRedInk](http://package.elm-lang.org/packages/NoRedInk/elm-simple-fuzzy/latest)
- [NoRedInk Simple Fuzzy](http://package.elm-lang.org/packages/NoRedInk/elm-simple-fuzzy/latest)
(for the Fuzzy Searching)
Binary file added icon.icns
Binary file not shown.
Binary file added icon.ico
Binary file not shown.
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function createWindow() {
backgroundColor: "#000",
frame: true,
resizable: true,
autoHideMenuBar: true
autoHideMenuBar: true,
icon: __dirname + '/icon.ico'
})
mainWindow.loadURL(`file://${ __dirname }/static/index.html`)
//mainWindow.webContents.openDevTools()
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qian",
"version": "1.0.0",
"version": "1.2.0",
"description": "A small experience",
"main": "main.js",
"scripts": {
Expand Down
33 changes: 33 additions & 0 deletions src/Action.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Action
, goToSettings
, goToTree
, changeDefaultTerminal
, navigateHistoryFromMenu
, toParentFromMenu
)

{-| Provide all "action" of the application
Expand Down Expand Up @@ -175,6 +177,18 @@ changeDir model newPath =
changeHistory model (\history -> History.push history newPath)


{-| Go to the parent from Electron
-}
toParentFromMenu : Model -> ( Model, Cmd Message )
toParentFromMenu model =
case File.parent model.history.present of
Nothing ->
( model, Cmd.none )

Just parent ->
changeDir model parent


{-| Navigate in the history (pred/next)
-}
navigateHistory : Model -> History File.Path -> ( Model, Cmd Message )
Expand All @@ -187,6 +201,25 @@ navigateHistory model newHistory =
( newModel, Port.getTree (Model.now newModel) )


{-| Navigate in the history from Electron
-}
navigateHistoryFromMenu : Model -> Bool -> ( Model, Cmd Message )
navigateHistoryFromMenu model isPast =
let
f =
if isPast then
History.backward
else
History.forward
in
case f model.history of
Just x ->
navigateHistory model x

Nothing ->
( model, Cmd.none )


{-| Change the current tree
-}
changeTree : Model -> File.Tree -> ( Model, Cmd Message )
Expand Down
8 changes: 8 additions & 0 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ subscriptions model =
Sub.batch
[ Port.retreiveTree ChangeTree
, Port.treeMutation TreeMutation
, Port.historyNavigation NavigateHistoryFromMenu
, Port.jumpToParent ToParentFromMenu
]


Expand Down Expand Up @@ -62,6 +64,12 @@ update message model =
GoToTree ->
Action.goToTree model

NavigateHistoryFromMenu isPast ->
Action.navigateHistoryFromMenu model isPast

ToParentFromMenu _ ->
Action.toParentFromMenu model

ChangeDefaultTerminal ->
Action.changeDefaultTerminal model

Expand Down
2 changes: 2 additions & 0 deletions src/Message.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ type Message
| RecordConfigTerminal String -- Track the configuration changement
| GoToSettings -- Go to the user settings
| GoToTree -- Return to the treeView
| NavigateHistoryFromMenu Bool -- Navigation from Electron
| ToParentFromMenu Bool -- Go to parent from Electron
| ChangeDefaultTerminal -- Change the default terminal
12 changes: 12 additions & 0 deletions src/Port.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ port module Port
, openInFinder
, openInTerminal
, changeTerminal
, historyNavigation
, jumpToParent
)

{-| JavaScript interopt
Expand Down Expand Up @@ -41,6 +43,16 @@ port getTree : File.Path -> Cmd msg
port retreiveTree : (File.Tree -> msg) -> Sub msg


{-| Perform a modification on the history from Electron
-}
port historyNavigation : (Bool -> msg) -> Sub msg


{-| Jump to the parent from Electron
-}
port jumpToParent : (Bool -> msg) -> Sub msg


{-| Watch the TreeMutation
-}
port treeMutation : (Bool -> msg) -> Sub msg
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link rel="stylesheet" href="css/fa.css">
<link rel="stylesheet" href="css/fonts.css">
<link rel="stylesheet" href="css/default.css">
<title>Qian 1</title>
<title>qian</title>
</head>

<body>
Expand Down
83 changes: 79 additions & 4 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import * as childProcess from 'child_process'
const { shell, remote } = electron
const { app } = remote

const Menu = remote.Menu;
const MenuItem = remote.MenuItem;


// A default configuration (actually, it is supported
// only a Terminal :) )
Expand Down Expand Up @@ -43,26 +46,98 @@ function rewriteConfiguration(config) {
fs.writeFileSync(qianFile, JSON.stringify(config))
}

const configObj = getConfigObject(defaultConfig)
const homePath = path.resolve(app.getPath('home'));

// Define the flag to be passed to the Elm Program
const flags = {
current: path.resolve("."),
config: getConfigObject(defaultConfig),
home: path.resolve(app.getPath('home')),
current: homePath,
config: configObj,
home: homePath,
root: '/'
}

// Initialize the Elm behaviour
const container = document.getElementById('app');
const elmApp = elm.Main.embed(container, flags);

// Application


function openInTerminal(app, dir) {
childProcess.spawn('open', ['-a', app, dir])
}

// Ports to Elm Application

let watcher // the file Watcher
let currentTree = homePath;

const template =
[
{
label: 'qian',
submenu: [{role: 'about'}, {role: 'quit'}]
},
{
label: 'Shortcuts',
submenu: [
{
label: 'Pred',
accelerator: 'CmdOrCtrl+Left',
click: function(item, focusedWindow) {
if (focusedWindow) {
elmApp.ports.historyNavigation.send(true)
}
}
},
{
label: 'Next',
accelerator: 'CmdOrCtrl+Right',
click: function(item, focusedWindow) {
if (focusedWindow) {
elmApp.ports.historyNavigation.send(false)
}
}
},
{
label: 'Parent',
accelerator: 'CmdOrCtrl+Up',
click: function(item, focusedWindow) {
if (focusedWindow) {
elmApp.ports.jumpToParent.send(true)
}
}
},
{
label: 'Open in finder',
accelerator: 'CmdOrCtrl+Alt+enter',
click: function(item, focusedWindow) {
if (focusedWindow) {
shell.showItemInFolder(currentTree)
}
}
},
{
label: 'Open in Terminal',
accelerator: 'CmdOrCtrl+enter',
click: function(item, focusedWindow) {
if (focusedWindow) {
openInTerminal(configObj.terminal, currentTree)
}
}
}
]
}
];

const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

// Watch and get treeFile
elmApp.ports.getTree.subscribe((pwd) => {
const dir = path.resolve(pwd)
currentTree = dir;
const tree = fs.readdirSync(dir).map((entry) => {
const completePath = path.join(dir, entry)
return {
Expand Down Expand Up @@ -97,7 +172,7 @@ elmApp.ports.openInFinder.subscribe((pwd) => {

elmApp.ports.openInTerminal.subscribe((input) => {
const dir = path.resolve(input.path)
childProcess.spawn('open', ['-a', input.app, dir])
openInTerminal(input.app, dir)
});

elmApp.ports.changeTerminal.subscribe((config) => {
Expand Down

0 comments on commit 762c8a0

Please sign in to comment.